Annotation of sbbs/sbbs2/data.c, revision 1.1.1.1

1.1       root        1: #line 1 "DATA.C"
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: /**************************************************************/
                      6: /* Functions that store and retrieve data from disk or memory */
                      7: /**************************************************************/
                      8: 
                      9: #include "sbbs.h"
                     10: 
                     11: /****************************************************************************/
                     12: /* Looks for a perfect match amoung all usernames (not deleted users)          */
                     13: /* Returns the number of the perfect matched username or 0 if no match         */
                     14: /* Called from functions waitforcall and newuser                                                       */
                     15: /****************************************************************************/
                     16: uint matchuser(char *str)
                     17: {
                     18:        int file;
                     19:        char str2[256],c;
                     20:        ulong l,length;
                     21:        FILE *stream;
                     22: 
                     23: sprintf(str2,"%sUSER\\NAME.DAT",data_dir);
                     24: if((stream=fnopen(&file,str2,O_RDONLY))==NULL)
                     25:        return(0);
                     26: length=filelength(file);
                     27: for(l=0;l<length;l+=LEN_ALIAS+2) {
                     28:        fread(str2,LEN_ALIAS+2,1,stream);
                     29:        for(c=0;c<LEN_ALIAS;c++)
                     30:                if(str2[c]==ETX) break;
                     31:        str2[c]=0;
                     32:        if(!stricmp(str,str2)) {
                     33:                fclose(stream);
                     34:                return((l/(LEN_ALIAS+2))+1); } }
                     35: fclose(stream);
                     36: return(0);
                     37: }
                     38: 
                     39: /****************************************************************************/
                     40: /* Looks for close or perfect matches between str and valid usernames and      */
                     41: /* numbers and prompts user for near perfect matches in names.                         */
                     42: /* Returns the number of the matched user or 0 if unsuccessful                         */
                     43: /* Called from functions main_sec, useredit and readmailw                                      */
                     44: /****************************************************************************/
                     45: uint finduser(char *instr)
                     46: {
                     47:        int file,i;
                     48:        char str[128],str2[256],str3[256],ynq[25],c,pass=1;
                     49:        ulong l,length;
                     50:        FILE *stream;
                     51: 
                     52: i=atoi(instr);
                     53: if(i>0) {
                     54:        username(i,str2);
                     55:        if(str2[0] && strcmp(str2,"DELETED USER"))
                     56:                return(i); }
                     57: strcpy(str,instr);
                     58: strupr(str);
                     59: sprintf(str3,"%sUSER\\NAME.DAT",data_dir);
                     60: if(flength(str3)<1L)
                     61:        return(0);
                     62: if((stream=fnopen(&file,str3,O_RDONLY))==NULL) {
                     63:        errormsg(WHERE,ERR_OPEN,str3,O_RDONLY);
                     64:        return(0); }
                     65: sprintf(ynq,"%.2s",text[YN]);
                     66: ynq[2]='Q';
                     67: ynq[3]=0;
                     68: length=filelength(file);
                     69: while(pass<3) {
                     70:        fseek(stream,0L,SEEK_SET);      /* seek to beginning for each pass */
                     71:        for(l=0;l<length;l+=LEN_ALIAS+2) {
                     72:                if(!online) break;
                     73:                fread(str2,LEN_ALIAS+2,1,stream);
                     74:                for(c=0;c<LEN_ALIAS;c++)
                     75:                        if(str2[c]==ETX) break;
                     76:                str2[c]=0;
                     77:                if(!c)          /* deleted user */
                     78:                        continue;
                     79:                strcpy(str3,str2);
                     80:                strupr(str2);
                     81:                if(pass==1 && !strcmp(str,str2)) {
                     82:                        fclose(stream);
                     83:                        return((l/(LEN_ALIAS+2))+1); }
                     84:                if(pass==2 && strstr(str2,str)) {
                     85:                        bprintf(text[DoYouMeanThisUserQ],str3
                     86:                                ,(uint)(l/(LEN_ALIAS+2))+1);
                     87:                        c=getkeys(ynq,0);
                     88:                        if(sys_status&SS_ABORT) {
                     89:                                fclose(stream);
                     90:                                return(0); }
                     91:                        if(c==text[YN][0]) {
                     92:                                fclose(stream);
                     93:                                return((l/(LEN_ALIAS+2))+1); }
                     94:                        if(c=='Q') {
                     95:                                fclose(stream);
                     96:                                return(0); } } }
                     97:        pass++; }
                     98: bputs(text[UnknownUser]);
                     99: fclose(stream);
                    100: return(0);
                    101: }
                    102: 
                    103: /****************************************************************************/
                    104: /* Returns the number of files in the directory 'dirnum'                    */
                    105: /****************************************************************************/
                    106: int getfiles(uint dirnum)
                    107: {
                    108:        char str[256];
                    109:        long l;
                    110: 
                    111: sprintf(str,"%s%s.IXB",dir[dirnum]->data_dir,dir[dirnum]->code);
                    112: l=flength(str);
                    113: if(l>0L)
                    114:        return(l/F_IXBSIZE);
                    115: return(0);
                    116: }
                    117: 
                    118: /****************************************************************************/
                    119: /* Returns the number of user transfers in XFER.IXT for either a dest user  */
                    120: /* source user, or filename.                                                                                           */
                    121: /****************************************************************************/
                    122: int getuserxfers(int fromuser, int destuser, char *fname)
                    123: {
                    124:        char str[256];
                    125:        int file,found=0;
                    126:        FILE *stream;
                    127: 
                    128: sprintf(str,"%sXFER.IXT",data_dir);
                    129: if(!fexist(str))
                    130:        return(0);
                    131: if(!flength(str)) {
                    132:        remove(str);
                    133:        return(0); }
                    134: if((stream=fnopen(&file,str,O_RDONLY))==NULL) {
                    135:        errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
                    136:        return(0); }
                    137: while(!ferror(stream)) {
                    138:        if(!fgets(str,81,stream))
                    139:                break;
                    140:        str[22]=0;
                    141:        if(fname!=NULL && fname[0] && !strncmp(str+5,fname,12))
                    142:                        found++;
                    143:        else if(fromuser && atoi(str+18)==fromuser)
                    144:                        found++;
                    145:        else if(destuser && atoi(str)==destuser)
                    146:                        found++; }
                    147: fclose(stream);
                    148: return(found);
                    149: }
                    150: 
                    151: /****************************************************************************/
                    152: /* Returns the number of the last user in USER.DAT (deleted ones too)          */
                    153: /* Called from function useredit                                                                                       */
                    154: /****************************************************************************/
                    155: uint lastuser()
                    156: {
                    157:        char str[256];
                    158:        long length;
                    159: 
                    160: sprintf(str,"%sUSER\\USER.DAT",data_dir);
                    161: if((length=flength(str))>0)
                    162:        return((uint)(length/U_LEN));
                    163: return(0);
                    164: }
                    165: 
                    166: /****************************************************************************/
                    167: /* Returns the number of files in the database for 'dir'                                       */
                    168: /****************************************************************************/
                    169: uint gettotalfiles(uint dirnum)
                    170: {
                    171:        char str[81];
                    172: 
                    173: sprintf(str,"%s%s.IXB",dir[dirnum]->data_dir,dir[dirnum]->code);
                    174: return((uint)(flength(str)/F_IXBSIZE));
                    175: }
                    176: 
                    177: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.