|
|
1.1 ! root 1: /* OUTPHOTO.C */ ! 2: ! 3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */ ! 4: ! 5: /* Scans SMM database and posts any photographs into the an SMB base */ ! 6: ! 7: #define uint unsigned int ! 8: ! 9: #include <dos.h> ! 10: #include <share.h> ! 11: #include "smblib.h" ! 12: #include "smmdefs.h" ! 13: #include "crc32.h" ! 14: ! 15: #define DAYS 15L // Hatch every 15 days ! 16: ! 17: smb_t smb; ! 18: extern int daylight=0; ! 19: extern long timezone=0L; ! 20: ! 21: unsigned _stklen=16000; /* Set stack size in code, not header */ ! 22: ! 23: /****************************************************************************/ ! 24: /* Checks the disk drive for the existence of a file. Returns 1 if it */ ! 25: /* exists, 0 if it doesn't. */ ! 26: /****************************************************************************/ ! 27: char fexist(char *filespec) ! 28: { ! 29: struct ffblk f; ! 30: ! 31: if(findfirst(filespec,&f,0)==0) ! 32: return(1); ! 33: return(0); ! 34: } ! 35: ! 36: ! 37: /****************************************************************************/ ! 38: /* Updates 16-bit "rcrc" with character 'ch' */ ! 39: /****************************************************************************/ ! 40: void ucrc16(uchar ch, ushort *rcrc) { ! 41: ushort i, cy; ! 42: uchar nch=ch; ! 43: ! 44: for (i=0; i<8; i++) { ! 45: cy=*rcrc & 0x8000; ! 46: *rcrc<<=1; ! 47: if (nch & 0x80) *rcrc |= 1; ! 48: nch<<=1; ! 49: if (cy) *rcrc ^= 0x1021; } ! 50: } ! 51: ! 52: /****************************************************************************/ ! 53: /* Returns 16-crc of string (not counting terminating NULL) */ ! 54: /****************************************************************************/ ! 55: ushort crc16(char *str) ! 56: { ! 57: int i=0; ! 58: ushort crc=0; ! 59: ! 60: ucrc16(0,&crc); ! 61: while(str[i]) ! 62: ucrc16(str[i++],&crc); ! 63: ucrc16(0,&crc); ! 64: ucrc16(0,&crc); ! 65: return(crc); ! 66: } ! 67: ! 68: /****************************************************************************/ ! 69: /* Returns 32-crc of string (not counting terminating NULL) */ ! 70: /****************************************************************************/ ! 71: ulong crc32(char *str) ! 72: { ! 73: int i=0; ! 74: ulong crc=0xffffffffUL; ! 75: ! 76: while(str[i]) ! 77: crc=ucrc32(str[i++],crc); ! 78: crc=~crc; ! 79: return(crc); ! 80: } ! 81: ! 82: ! 83: char *base41(unsigned int i, char *str) ! 84: { ! 85: char c; ! 86: unsigned int j=41*41,k; ! 87: ! 88: for(c=0;c<3;c++) { ! 89: k=i/j; ! 90: str[c]='0'+k; ! 91: i-=(k*j); ! 92: j/=41; ! 93: if(str[c]>=':') ! 94: str[c]='A'+(str[c]-':'); ! 95: if(str[c]>='[') ! 96: str[c]='#'+(str[c]-'['); } ! 97: str[c]=0; ! 98: return(str); ! 99: } ! 100: ! 101: ! 102: ! 103: time_t checktime() ! 104: { ! 105: struct tm tm; ! 106: ! 107: memset(&tm,0,sizeof(tm)); ! 108: tm.tm_year=94; ! 109: tm.tm_mday=1; ! 110: return(mktime(&tm)^0x2D24BD00L); ! 111: } ! 112: ! 113: #define BUF_LEN 8192 ! 114: ! 115: int main(int argc, char **argv) ! 116: { ! 117: uchar str[128],tmp[128],buf[BUF_LEN],fname[64],path[128],*p,ch; ! 118: int i,j,file,in,linelen,all=0; ! 119: ushort xlat; ! 120: long length,l; ! 121: ulong offset,crc; ! 122: time_t now; ! 123: struct ffblk ff; ! 124: user_t user; ! 125: smbmsg_t msg; ! 126: FILE *stream; ! 127: ! 128: fprintf(stderr,"\nOUTPHOTO %s - Write SMM photos to SMB - Developed 1995-1997 " ! 129: "Rob Swindell\n\n",__DATE__); ! 130: ! 131: if(checktime()) { ! 132: printf("Time problem!\n"); ! 133: return(-1); } ! 134: ! 135: if(argc<3) { ! 136: fprintf(stderr,"usage: outphoto <smm.dab> <smb_file>\n\n"); ! 137: fprintf(stderr,"example: outphoto c:\\sbbs\\xtrn\\smm\\smm.dab " ! 138: "c:\\sbbs\\data\\subs\\syncdata\n"); ! 139: return(1); } ! 140: ! 141: for(i=3;i<argc;i++) ! 142: if(!stricmp(argv[i],"/ALL")) ! 143: all=1; ! 144: ! 145: strcpy(smb.file,argv[2]); ! 146: strupr(smb.file); ! 147: ! 148: strcpy(str,argv[1]); ! 149: strupr(str); ! 150: if((file=open(str,O_RDWR|O_BINARY|O_DENYNONE))==-1) { ! 151: printf("error opening %s\n",str); ! 152: return(1); } ! 153: if((stream=fdopen(file,"w+b"))==NULL) { ! 154: printf("error fdopening %s\n",str); ! 155: return(1); } ! 156: setvbuf(stream,NULL,_IOFBF,4096); ! 157: ! 158: sprintf(str,"%s.SHD",smb.file); ! 159: if(!fexist(str)) { ! 160: printf("%s doesn't exist\n",smb.file); ! 161: return(0); } ! 162: fprintf(stderr,"Opening %s\n",smb.file); ! 163: smb.retry_time=30; ! 164: if((i=smb_open(&smb))!=0) { ! 165: printf("smb_open returned %d\n",i); ! 166: return(1); } ! 167: ! 168: now=time(NULL); ! 169: while(!feof(stream)) { ! 170: if(!fread(&user,sizeof(user_t),1,stream)) ! 171: break; ! 172: ! 173: if(user.misc&USER_DELETED || !(user.misc&USER_PHOTO)) ! 174: continue; ! 175: ! 176: printf("Photo: %-25.25s %.24s " ! 177: ,user.name,ctime(&user.photo)); ! 178: ! 179: if(user.photo && now-user.photo<DAYS*24L*60L*60L && !all) { ! 180: printf("skipping\n"); ! 181: continue; } ! 182: printf("hatching\n"); ! 183: ! 184: for(i=0;user.system[i];i++) ! 185: if(isalnum(user.system[i])) ! 186: break; ! 187: if(!user.system[i]) ! 188: fname[0]='~'; ! 189: else ! 190: fname[0]=user.system[i]; ! 191: for(i=strlen(user.system)-1;i>0;i--) ! 192: if(isalnum(user.system[i])) ! 193: break; ! 194: if(i<=0) ! 195: fname[1]='~'; ! 196: else ! 197: fname[1]=user.system[i]; ! 198: fname[2]=0; ! 199: strcpy(str,user.system); ! 200: strupr(str); ! 201: strcat(fname,base41(crc16(str),tmp)); ! 202: strcat(fname,base41(user.number,tmp)); ! 203: strcpy(path,argv[1]); ! 204: p=strchr(path,'\\'); ! 205: if(p) *(p+1)=0; ! 206: else path[0]=0; ! 207: sprintf(str,"%sPHOTO\\%s.*",path,fname); ! 208: if(findfirst(str,&ff,0)) { ! 209: printf("%s doesn't exist!\n",str); ! 210: continue; } ! 211: strcpy(fname,ff.ff_name); ! 212: strcpy(path,argv[1]); ! 213: p=strchr(path,'\\'); ! 214: if(p) *(p+1)=0; ! 215: else path[0]=0; ! 216: sprintf(str,"%sPHOTO\\%s",path,fname); ! 217: ! 218: printf("Exporting %s",str); ! 219: if((in=open(str,O_RDONLY|O_BINARY|SH_DENYWR))==-1) { ! 220: printf("\nError opening %s\n",str); ! 221: continue; } ! 222: ! 223: memset(buf,0,BUF_LEN); ! 224: crc=0xffffffffUL; ! 225: linelen=0; ! 226: sprintf(buf,"%lx\r\n",filelength(in)^4096); ! 227: l=strlen(buf); ! 228: while(l<(BUF_LEN-128)) { ! 229: if(!read(in,&ch,1)) ! 230: break; ! 231: crc=ucrc32(ch,crc); ! 232: if(ch=='`') { ! 233: buf[l++]='`'; ! 234: buf[l++]='`'; ! 235: linelen++; } ! 236: else if(ch==0xff) ! 237: buf[l++]='\xee'; ! 238: else if(ch<0xf) ! 239: buf[l++]=ch|0xf0; ! 240: else if(ch<0x20) { ! 241: buf[l++]='`'; ! 242: buf[l++]=ch+'@'; ! 243: linelen++; } ! 244: else if(ch>=0xf0) { ! 245: sprintf(str,"`%x",ch&0xf); ! 246: buf[l++]=str[0]; ! 247: buf[l++]=str[1]; ! 248: linelen++; } ! 249: else if(ch==0xe3) { ! 250: buf[l++]='`'; ! 251: buf[l++]='g'; ! 252: linelen++; } ! 253: else if(ch==0x8d) { ! 254: buf[l++]='`'; ! 255: buf[l++]='h'; ! 256: linelen++; } ! 257: else if(ch==0xee) { ! 258: buf[l++]='`'; ! 259: buf[l++]='i'; ! 260: linelen++; } ! 261: else ! 262: buf[l++]=ch; ! 263: linelen++; ! 264: if(linelen>=70) { ! 265: buf[l++]=CR; ! 266: buf[l++]=LF; ! 267: linelen=0; } } ! 268: buf[l]=0; ! 269: crc=~crc; ! 270: sprintf(str,"%lx\r\n--- OUTPHOTO %s",time(NULL),__DATE__); ! 271: strcat(buf,str); ! 272: printf("\n"); ! 273: ! 274: length=strlen(buf); /* +2 for translation string */ ! 275: ! 276: if(smb.status.attr&SMB_HYPERALLOC) ! 277: offset=smb_hallocdat(&smb); ! 278: else { ! 279: i=smb_open_da(&smb); ! 280: if(i) { ! 281: printf("smb_open_da returned %d\n",i); ! 282: exit(1); } ! 283: offset=smb_allocdat(&smb,length+2,1); ! 284: fclose(smb.sda_fp); } ! 285: ! 286: fseek(smb.sdt_fp,offset,SEEK_SET); ! 287: xlat=XLAT_NONE; ! 288: fwrite(&xlat,2,1,smb.sdt_fp); ! 289: fwrite(buf,length,1,smb.sdt_fp); ! 290: length+=2; ! 291: ! 292: memset(&msg,0,sizeof(smbmsg_t)); ! 293: memcpy(msg.hdr.id,"SHD\x1a",4); ! 294: msg.hdr.version=SMB_VERSION; ! 295: msg.hdr.when_written.time=time(NULL); ! 296: ! 297: msg.hdr.offset=offset; ! 298: ! 299: strcpy(str,"SMM PHOTO"); ! 300: i=smb_hfield(&msg,RECIPIENT,strlen(str),str); ! 301: if(i) { ! 302: printf("smb_hfield returned %d\n",i); ! 303: smb_freemsgdat(&smb,offset,length,1); ! 304: exit(1); } ! 305: strlwr(str); ! 306: msg.idx.to=crc16(str); ! 307: ! 308: strcpy(str,"Digital Dynamics"); ! 309: i=smb_hfield(&msg,SENDER,strlen(str),str); ! 310: if(i) { ! 311: printf("smb_hfield returned %d\n",i); ! 312: smb_freemsgdat(&smb,offset,length,1); ! 313: exit(1); } ! 314: strlwr(str); ! 315: msg.idx.from=crc16(str); ! 316: ! 317: sprintf(tmp,"%.25s",user.system); ! 318: strupr(tmp); ! 319: sprintf(str,"%04lx%08lx%08lx%.3s" ! 320: ,user.number^0x191L,crc32(tmp)^0x90120e71L,crc^0x05296328L,fname+9); ! 321: i=smb_hfield(&msg,SUBJECT,strlen(str),str); ! 322: if(i) { ! 323: printf("smb_hfield returned %d\n",i); ! 324: smb_freemsgdat(&smb,offset,length,1); ! 325: exit(1); } ! 326: strlwr(str); ! 327: msg.idx.subj=crc16(str); ! 328: ! 329: i=smb_dfield(&msg,TEXT_BODY,length); ! 330: if(i) { ! 331: printf("smb_dfield returned %d\n",i); ! 332: smb_freemsgdat(&smb,offset,length,1); ! 333: exit(1); } ! 334: ! 335: i=smb_addmsghdr(&smb,&msg,smb.status.attr&SMB_HYPERALLOC); ! 336: if(i) { ! 337: printf("smb_addmsghdr returned %d\n",i); ! 338: smb_freemsgdat(&smb,offset,length,1); ! 339: exit(1); } ! 340: smb_freemsgmem(&msg); ! 341: fseek(stream,ftell(stream)-sizeof(user_t),SEEK_SET); ! 342: user.photo=time(NULL); ! 343: fwrite(&user,sizeof(user_t),1,stream); ! 344: fseek(stream,ftell(stream),SEEK_SET); } ! 345: return(0); ! 346: } ! 347:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.