home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* XBBS SOURCE CODE copyright (c) 1990 by M. Kimes */
- /* All Rights Reserved */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the in the file LICENSE.XBS. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* XBBS LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES */
- /* AT THE ADDRESS LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO USE */
- /* THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING */
- /* AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH */
- /* M. KIMES */
- /* */
- /* */
- /* You can contact M. Kimes at the following address: */
- /* */
- /* M. Kimes 1:380/16.0@FidoNet */
- /* 542 Merrick (318)222-3455 data */
- /* Shreveport, LA 71104 */
- /* */
- /* */
- /* Please feel free to contact me at any time to share your comments about */
- /* my software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
- /*======================================================================*/
- /* XBBS Bulletin Board System.....Msg reading low-level functions */
- /*======================================================================*/
-
- #include "msg.h"
- #include "xext.h"
-
- extern struct _mboard far *marea;
- extern struct _fboard holdboard;
- extern struct _mboard holdmboard;
- extern char exporting;
- extern word maxareas;
- extern word higharea;
-
-
- int pascal get_mess (word messno) {
-
- int handle;
- register word x=0;
-
- sprintf(buffer,"%sXDATA.%03x",messpath,mboard.number);
-
- while ((handle=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- x++;
- if(x>2) {
- say_prompt(418);
- return -1;
- }
- say_prompt(57);
- sleep(1);
- }
- else {
- say_prompt(59);
- return -1;
- }
- }
- if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || (_read(handle,&msg,sizeof(struct _xmsg))<1)) {
- if (eof(handle)==(-1)) lprint("\n\04Seek error\n");
- cclose(handle);
- return -1;
- }
- cclose(handle);
- return 0;
- }
-
-
-
-
- int pascal put_mess (word messno) {
-
- int handle;
- register word x=0;
-
- sprintf(buffer,"%sXDATA.%03x",messpath,mboard.number);
-
- while ((handle=oopen(buffer,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- x++;
- if(x>2) {
- say_prompt(50);
- return -1;
- }
- say_prompt(57);
- sleep(1);
- }
- else {
- if((handle=ccreat(buffer,S_IWRITE))==-1) {
- say_prompt(59);
- return -1;
- }
- break;
- }
- }
- if (conf.share) {
- x=0;
- while (lock(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),(long)sizeof(struct _xmsg))){
- x++;
- if(x>2) {
- say_prompt(50);
- return -1;
- }
- say_prompt(57);
- sleep(1);
- }
- }
- if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || (_write(handle,&msg,sizeof(struct _xmsg))<1)) {
- if (eof(handle)==(-1)) {
- lprint(" SEEK ERROR ");
- if(conf.share)unlock(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),(long)sizeof(struct _xmsg));
- cclose(handle);
- return -1;
- }
- }
- if (conf.share)unlock(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),(long)sizeof(struct _xmsg));
- cclose(handle);
- return 0;
- }
-
-
-
- char far * pascal get_text (word messno) {
-
- char once;
- char reduced=0;
- char *hold;
- char *tempo;
- word temp=0;
- int handle;
-
- sprintf(buffer,"%sXTEXT.%03x",messpath,mboard.number);
- while ((handle=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- temp++;
- if (temp>2) {
- say_prompt(50);
- return NULL;
- }
- say_prompt(57);
- sleep(1);
- }
- else {
- say_prompt(58);
- return NULL;
- }
- }
- once=0;
- TryThatAgain:
- if (lseek(handle,msg.start,SEEK_SET)) {
- if (eof(handle)) {
- if (!once) {
- once++;
- goto TryThatAgain;
- }
- else lprint("\n\04Text Seek error\n");
- cclose(handle);
- return NULL;
- }
- }
- temp=msg.length;
- ReTry:
- hold=(char far*)mmalloc(msg.length+1);
- if (hold==NULL) {
- if (msg.length>1024 && !(msg.m_attr & MSGPACKED)) {
- msg.length-=256;
- reduced=1;
- goto ReTry;
- }
- else {
- say_prompt(41);
- msg.length=temp;
- cclose(handle);
- return NULL;
- }
- }
- memset(hold,0,msg.length);
- if(_read(handle,hold,msg.length)<msg.length)reduced=1;
- cclose(handle);
- hold[msg.length-1]=0;
- hold[msg.length]=0;
- tempo=hold;
- if(!(msg.m_attr & MSGTREATED) && !(mboard.attr & ANSI) && !(msg.m_attr & MSGPACKED)) {
- while (*tempo) {
- if(*tempo=='\x8d' || *tempo=='\n') {
- if(*tempo=='\n') memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)hold));
- else {
- if(*(tempo-1)==' ' && tempo>hold) memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)hold));
- else {
- *tempo=' ';
- tempo++;
- }
- }
- }
- else tempo++;
- }
- if(*(tempo-1)!='\r' && tempo>hold) {
- *tempo='\r';
- tempo[1]=0;
- }
- if(!reduced && temp>(word)strlen(hold)+1) {
- msg.length=(word)strlen(hold)+1;
- sprintf(buffer,"%sXTEXT.%03x",messpath,mboard.number);
- if ((handle=oopen(buffer,O_RDWR | O_BINARY | O_DENYWRITE))==-1) goto OkayThenDont;
- once=0;
- TryThatAgain2:
- if (lseek(handle,msg.start,SEEK_SET)==-1) {
- if (eof(handle)==-1) {
- if (!once) {
- once++;
- goto TryThatAgain;
- }
- else {
- cclose(handle);
- goto OkayThenDont;
- }
- }
- }
- if(_write(handle,hold,(word)strlen(hold))==strlen(hold)) {
- _write(handle,"\0",1);
- if(eof(handle)==-1) {
- cclose(handle);
- goto OkayThenDont;
- }
- cclose(handle);
- msg.m_attr=(msg.m_attr | MSGTREATED);
- if(messno)put_mess(messno);
- temp=msg.length;
- }
- }
- }
- if(msg.m_attr & MSGPACKED) {
- if(unpack_msg(&hold)==NULL) {
- /* gprintf(LOCALONLY,"\nCame back null: Hold=%p\n",hold); */
- if(hold)ffree(hold);
- msg.length=0;
- return NULL;
- }
- /* gprintf(LOCALONLY,"\nCame back ok: Hold=%p\n",hold); */
- }
-
- OkayThenDont:
- msg.length=temp;
- return hold;
- }
-
-
- word pascal get_abunch (word messno,char type,int direction,char *str) {
-
- register word x=0;
- register int y;
- int handle;
- int handle2;
- char finished=0;
- word temp;
- static struct _xmsg msgs[5];
- char once;
-
- if(type==1) {
- rstrip(str);
- if(!strnicmp(str,"RE: ",4)) memmove(str,&str[4],strlen(&str[4])+1);
- if(!*str || !str) return 0;
- }
- if(direction>=0) {
- messno++;
- direction=1;
- }
- else direction=(-1);
- sprintf(buffer,"%sXDATA.%03x",messpath,mboard.number);
- while ((handle=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- x++;
- if(x>2) {
- say_prompt(418);
- return 0;
- }
- say_prompt(57);
- sleep(1);
- }
- else {
- say_prompt(59);
- return 0;
- }
- }
- if(direction<0) {
- if(messno>6){
- x=5;
- messno-=5;
- }
- else {
- x=messno-1;
- messno=1;
- }
- }
- Loop:
- if(toupper(inkey())=='S') {
- cclose(handle);
- return 0;
- }
- if(direction>0) {
- x=(word)(filelength(handle)/(long)sizeof(struct _xmsg));
- if(messno>x || finished) {
- cclose(handle);
- return 0;
- }
- if((x-messno)<6)x-=(messno-1);
- else x=5;
- }
- Skip:
- if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || ((temp=(_read(handle,&msgs,(int)(x * sizeof(struct _xmsg)))))<1)) {
- if (eof(handle)==(-1)) lprint("\n\04Seek or Read error\n");
- cclose(handle);
- return 0;
- }
- if((temp/sizeof(struct _xmsg))<x)x=temp/sizeof(struct _xmsg);
- if(direction<0)y=x-1;
- else y=0;
- if(type==0) { /* Personal mail check */
- while(1) {
- if ((msgs[y].attr & MSGREAD) || (msgs[y].m_attr & MSGDELETED)) goto NotGot;
- if((stricmp(msgs[y].to,user.name)==0) || (stricmp(msgs[y].to,user.handle)==0)) {
- cclose(handle);
- return (messno+y);
- }
- if(userno==1) {
- if (!stricmp(msgs[y].to,"SYSOP")) {
- cclose(handle);
- return (messno+y);
- }
- }
- NotGot:
- y+=(direction);
- if(direction<0) {
- if(y<0) break;
- }
- else if(y>=x) break;
- }
- }
- else if (type==1) { /* Subject check */
- temp=(word)strlen(str);
- while(1) {
- if (msgs[y].m_attr & MSGDELETED) goto NoGot;
- rstrip(msgs[y].subj);
- if(!strnicmp(msgs[y].subj,"RE: ",4)) memmove(msgs[y].subj,&msgs[y].subj[4],strlen(&msgs[y].subj[4])+1);
- handle2=(int)temp;
- if(temp>24) {
- if(strlen(msgs[y].subj)<(int)temp) handle2=strlen(msgs[y].subj);
- if(handle2<24) handle2=temp;
- }
- if(!strnicmp(msgs[y].subj,str,handle2)) {
-
- cclose(handle);
- return (messno+y);
- }
- NoGot:
- y+=(direction);
- if(direction<0) {
- if(y<0) break;
- }
- else if(y>=x) break;
- }
- }
- else if (type==2) { /* Body check */
- sprintf(buffer,"%sXTEXT.%03x",messpath,mboard.number);
- temp=0;
- while ((handle2=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- if (errno==EACCES) {
- temp++;
- if (temp>2) {
- say_prompt(50);
- cclose(handle);
- return 0;
- }
- say_prompt(57);
- sleep(1);
- }
- else {
- say_prompt(58);
- cclose(handle);
- return 0;
- }
- }
- while(1) {
- if(!msgs[y].length) goto NoGot2;
- if ((msgs[y].m_attr & MSGDELETED)) goto NoGot2;
- once=0;
- TryThatAgain:
- if (lseek(handle2,msgs[y].start,SEEK_SET)) {
- if (eof(handle2)) {
- if (once<2) {
- once++;
- goto TryThatAgain;
- }
- lprint("\nText Seek error\n");
- goto NoGot2;
- }
- }
- *buffer=0;
- temp=510;
- if(temp>(msgs[y].length-1)) temp=msgs[y].length-1;
- temp=_read(handle2,buffer,temp);
- buffer[temp+1]=0;
- if(stristr(buffer,str)) {
- cclose(handle);
- cclose(handle2);
- return (messno+y);
- }
- NoGot2:
- y+=(direction);
- if(direction<0) {
- if(y<0) break;
- }
- else if(y>=x) break;
- }
- cclose(handle2);
- }
- if(direction>0) {
- if((long)(messno+x)>65535L) finished++;
- else messno+=x;
- }
- else {
- if((long)(messno-x)<=0L) {
- cclose(handle);
- return 0;
- }
- else messno-=x;
- if (messno>5) x=5;
- }
- goto Loop;
- }
-
-
- int pascal do_all_msg_areas (char *msgareas,char type,char newonly,char abortok,word startat) {
-
- register word x;
- char temp=0;
- struct ffblk f;
- char filename[133];
-
- /* gprintf(LOCALONLY,"\nMA: %s\ntype: %hu\nnew: %hu\nabort: %hu\nstart: %u\n",msgareas,type,newonly,abortok,startat); */
-
- load_areas(msgareas);
- if (!maxareas) {
- if(marea)ffree(marea);
- return 1;
- }
- memcpy(&holdboard,&fboard,sizeof(struct _fboard));
- memcpy(&holdmboard,&mboard,sizeof(struct _mboard));
- for (x=startat;x<(higharea+1);x++) {
- if (find_area(x,1+(type & 2))) {
- if(newonly) {
- if(x<(conf.nolmrs+1)) {
- if(temp && abortok) {
- sprintf(filename,"%sXDATA.%03x",messpath,x);
- if (findfirst(filename,&f,0)) f.ff_fsize=0;
- if (!f.ff_fsize) continue;
- say_prompt(292);
- temp=*genin(1,0,1,1,ALPHA);
- printm("\n");
- switch((int)temp) {
- case 'S': goto Loop;
- case 'I': if(x<(conf.nolmrs+1)) lastread[x-1]=(word)(f.ff_fsize/(long)sizeof(struct _xmsg));
- goto Loop;
- case 'A': goto BreakOut;
- default: temp='R';
- }
- }
- readamessage(type,lastread[x-1]+1);
- temp=1;
- }
- }
- else {
- if(temp && abortok) {
- sprintf(filename,"%sXDATA.%03x",messpath,x);
- if (findfirst(filename,&f,0)) f.ff_fsize=0;
- if (!f.ff_fsize) continue;
- say_prompt(292);
- temp=*genin(1,0,1,1,ALPHA);
- printm("\n");
- switch((int)temp) {
- case 'S': goto Loop;
- case 'I': if(x<(conf.nolmrs+1)) lastread[x-1]=(word)(f.ff_fsize/(long)sizeof(struct _xmsg));
- goto Loop;
- case 'A': goto BreakOut;
- default: temp='R';
- }
- }
- readamessage(type,0);
- temp=1;
- }
- }
- Loop:
- ;
- }
- BreakOut:
- if (marea) ffree(marea);
- maxareas=0;
- memcpy(&fboard,&holdboard,sizeof(struct _fboard));
- memcpy(&mboard,&holdmboard,sizeof(struct _mboard));
- return 0;
- }
-