|
|
1.1 ! root 1: /* ars.c */ ! 2: ! 3: /* Synchronet Access Requirement String (ARS) functions */ ! 4: ! 5: /* $Id: ars.c,v 1.3 2000/11/08 09:19:30 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include "sbbs.h" ! 39: ! 40: /* Converts ASCII ARS string into binary ARS buffer */ ! 41: ! 42: #ifdef __BORLANDC__ /* Eliminate warning when buildling Baja */ ! 43: #pragma argsused ! 44: #endif ! 45: uchar* arstr(ushort* count, char* str, scfg_t* cfg) ! 46: { ! 47: static uchar nular[2]={0}; ! 48: char *p; ! 49: uchar ar[256],*ar_buf; ! 50: uint i,j,n,artype=AR_LEVEL,not=0,equal=0; ! 51: ! 52: for(i=j=0;str[i];i++) { ! 53: if(str[i]==SP) ! 54: continue; ! 55: ! 56: if(str[i]=='(') { ! 57: if(not) ! 58: ar[j++]=AR_NOT; ! 59: not=equal=0; ! 60: ar[j++]=AR_BEGNEST; ! 61: continue; } ! 62: ! 63: if(str[i]==')') { ! 64: ar[j++]=AR_ENDNEST; ! 65: continue; } ! 66: ! 67: if(str[i]=='|') { ! 68: ar[j++]=AR_OR; ! 69: continue; } ! 70: ! 71: if(str[i]=='!') { ! 72: not=1; ! 73: continue; } ! 74: ! 75: if(str[i]=='=') { ! 76: equal=1; ! 77: continue; } ! 78: ! 79: if(str[i]=='&') ! 80: continue; ! 81: ! 82: if(isalpha(str[i])) { ! 83: if(!strncmp(str+i,"OR",2)) { ! 84: ar[j++]=AR_OR; ! 85: i++; ! 86: continue; } ! 87: ! 88: if(!strncmp(str+i,"AND",3)) { /* AND is ignored */ ! 89: i+=2; ! 90: continue; } ! 91: ! 92: if(!strncmp(str+i,"NOT",3)) { ! 93: not=1; ! 94: i+=2; ! 95: continue; } ! 96: ! 97: if(!strncmp(str+i,"EQUAL TO",8)) { ! 98: equal=1; ! 99: i+=7; ! 100: continue; } ! 101: ! 102: if(!strncmp(str+i,"EQUAL",5)) { ! 103: equal=1; ! 104: i+=4; ! 105: continue; } ! 106: ! 107: if(!strncmp(str+i,"EQUALS",6)) { ! 108: equal=1; ! 109: i+=5; ! 110: continue; } } ! 111: ! 112: if(str[i]=='$') { ! 113: switch(str[i+1]) { ! 114: case 'A': ! 115: artype=AR_AGE; ! 116: break; ! 117: case 'B': ! 118: artype=AR_BPS; ! 119: break; ! 120: case 'C': ! 121: artype=AR_CREDIT; ! 122: break; ! 123: case 'D': ! 124: artype=AR_UDFR; ! 125: break; ! 126: case 'E': ! 127: artype=AR_EXPIRE; ! 128: break; ! 129: case 'F': ! 130: artype=AR_FLAG1; ! 131: break; ! 132: case 'G': ! 133: artype=AR_LOCAL; ! 134: if(not) ! 135: ar[j++]=AR_NOT; ! 136: not=0; ! 137: ar[j++]=artype; ! 138: break; ! 139: case 'H': ! 140: artype=AR_SUB; ! 141: break; ! 142: case 'I': ! 143: artype=AR_LIB; ! 144: break; ! 145: case 'J': ! 146: artype=AR_DIR; ! 147: break; ! 148: case 'K': ! 149: artype=AR_UDR; ! 150: break; ! 151: case 'L': ! 152: artype=AR_LEVEL; ! 153: break; ! 154: case 'M': ! 155: artype=AR_GROUP; ! 156: break; ! 157: case 'N': ! 158: artype=AR_NODE; ! 159: break; ! 160: case 'O': ! 161: artype=AR_TUSED; ! 162: break; ! 163: case 'P': ! 164: artype=AR_PCR; ! 165: break; ! 166: case 'Q': ! 167: artype=AR_RANDOM; ! 168: break; ! 169: case 'R': ! 170: artype=AR_TLEFT; ! 171: break; ! 172: case 'S': ! 173: artype=AR_SEX; ! 174: break; ! 175: case 'T': ! 176: artype=AR_TIME; ! 177: break; ! 178: case 'U': ! 179: artype=AR_USER; ! 180: break; ! 181: case 'V': ! 182: artype=AR_LOGONS; ! 183: break; ! 184: case 'W': ! 185: artype=AR_DAY; ! 186: break; ! 187: case 'X': ! 188: artype=AR_EXEMPT; ! 189: break; ! 190: case 'Y': /* Days since last on */ ! 191: artype=AR_LASTON; ! 192: break; ! 193: case 'Z': ! 194: artype=AR_REST; ! 195: break; ! 196: case '[': ! 197: artype=AR_ANSI; ! 198: if(not) ! 199: ar[j++]=AR_NOT; ! 200: not=0; ! 201: ar[j++]=artype; ! 202: break; ! 203: case '0': ! 204: artype=AR_NULL; ! 205: break; ! 206: case '*': ! 207: artype=AR_RIP; ! 208: if(not) ! 209: ar[j++]=AR_NOT; ! 210: not=0; ! 211: ar[j++]=artype; ! 212: break; ! 213: ! 214: } ! 215: i++; ! 216: continue; } ! 217: ! 218: if(isalpha(str[i])) { ! 219: n=i; ! 220: if(!strncmp(str+i,"AGE",3)) { ! 221: artype=AR_AGE; ! 222: i+=2; } ! 223: else if(!strncmp(str+i,"BPS",3)) { ! 224: artype=AR_BPS; ! 225: i+=2; } ! 226: else if(!strncmp(str+i,"PCR",3)) { ! 227: artype=AR_PCR; ! 228: i+=2; } ! 229: else if(!strncmp(str+i,"SEX",3)) { ! 230: artype=AR_SEX; ! 231: i+=2; } ! 232: else if(!strncmp(str+i,"UDR",3)) { ! 233: artype=AR_UDR; ! 234: i+=2; } ! 235: else if(!strncmp(str+i,"DAY",3)) { ! 236: artype=AR_DAY; ! 237: i+=2; } ! 238: else if(!strncmp(str+i,"RIP",3)) { ! 239: artype=AR_RIP; ! 240: if(not) ! 241: ar[j++]=AR_NOT; ! 242: not=0; ! 243: ar[j++]=artype; ! 244: i+=2; } ! 245: else if(!strncmp(str+i,"WIP",3)) { ! 246: artype=AR_WIP; ! 247: if(not) ! 248: ar[j++]=AR_NOT; ! 249: not=0; ! 250: ar[j++]=artype; ! 251: i+=2; } ! 252: else if(!strncmp(str+i,"OS2",3)) { ! 253: artype=AR_OS2; ! 254: if(not) ! 255: ar[j++]=AR_NOT; ! 256: not=0; ! 257: ar[j++]=artype; ! 258: i+=2; } ! 259: else if(!strncmp(str+i,"DOS",3)) { ! 260: artype=AR_DOS; ! 261: if(not) ! 262: ar[j++]=AR_NOT; ! 263: not=0; ! 264: ar[j++]=artype; ! 265: i+=2; } ! 266: else if(!strncmp(str+i,"WIN32",5)) { ! 267: artype=AR_WIN32; ! 268: if(not) ! 269: ar[j++]=AR_NOT; ! 270: not=0; ! 271: ar[j++]=artype; ! 272: i+=2; } ! 273: else if(!strncmp(str+i,"UNIX",4)) { ! 274: artype=AR_UNIX; ! 275: if(not) ! 276: ar[j++]=AR_NOT; ! 277: not=0; ! 278: ar[j++]=artype; ! 279: i+=2; } ! 280: else if(!strncmp(str+i,"LINUX",5)) { ! 281: artype=AR_LINUX; ! 282: if(not) ! 283: ar[j++]=AR_NOT; ! 284: not=0; ! 285: ar[j++]=artype; ! 286: i+=2; } ! 287: else if(!strncmp(str+i,"SUBCODE",7)) { ! 288: artype=AR_SUBCODE; ! 289: i+=6; } ! 290: else if(!strncmp(str+i,"SUB",3)) { ! 291: artype=AR_SUB; ! 292: i+=2; } ! 293: else if(!strncmp(str+i,"LIB",3)) { ! 294: artype=AR_LIB; ! 295: i+=2; } ! 296: else if(!strncmp(str+i,"DIRCODE",7)) { ! 297: artype=AR_DIRCODE; ! 298: i+=6; } ! 299: else if(!strncmp(str+i,"DIR",3)) { ! 300: artype=AR_DIR; ! 301: i+=2; } ! 302: else if(!strncmp(str+i,"ANSI",4)) { ! 303: artype=AR_ANSI; ! 304: if(not) ! 305: ar[j++]=AR_NOT; ! 306: not=0; ! 307: ar[j++]=artype; ! 308: i+=3; } ! 309: else if(!strncmp(str+i,"UDFR",4)) { ! 310: artype=AR_UDFR; ! 311: i+=3; } ! 312: else if(!strncmp(str+i,"FLAG",4)) { ! 313: artype=AR_FLAG1; ! 314: i+=3; } ! 315: else if(!strncmp(str+i,"NODE",4)) { ! 316: artype=AR_NODE; ! 317: i+=3; } ! 318: else if(!strncmp(str+i,"NULL",4)) { ! 319: artype=AR_NULL; ! 320: i+=3; } ! 321: else if(!strncmp(str+i,"USER",4)) { ! 322: artype=AR_USER; ! 323: i+=3; } ! 324: else if(!strncmp(str+i,"TIME",4)) { ! 325: artype=AR_TIME; ! 326: i+=3; } ! 327: else if(!strncmp(str+i,"REST",4)) { ! 328: artype=AR_REST; ! 329: i+=3; } ! 330: else if(!strncmp(str+i,"LEVEL",5)) { ! 331: artype=AR_LEVEL; ! 332: i+=4; } ! 333: else if(!strncmp(str+i,"TLEFT",5)) { ! 334: artype=AR_TLEFT; ! 335: i+=4; } ! 336: else if(!strncmp(str+i,"TUSED",5)) { ! 337: artype=AR_TUSED; ! 338: i+=4; } ! 339: else if(!strncmp(str+i,"LOCAL",5)) { ! 340: artype=AR_LOCAL; ! 341: if(not) ! 342: ar[j++]=AR_NOT; ! 343: not=0; ! 344: ar[j++]=artype; ! 345: i+=4; } ! 346: else if(!strncmp(str+i,"GROUP",5)) { ! 347: artype=AR_GROUP; ! 348: i+=4; } ! 349: else if(!strncmp(str+i,"EXPIRE",6)) { ! 350: artype=AR_EXPIRE; ! 351: i+=5; } ! 352: else if(!strncmp(str+i,"EXPERT",6)) { ! 353: artype=AR_EXPERT; ! 354: if(not) ! 355: ar[j++]=AR_NOT; ! 356: not=0; ! 357: ar[j++]=artype; ! 358: i+=5; } ! 359: else if(!strncmp(str+i,"SYSOP",5)) { ! 360: artype=AR_SYSOP; ! 361: if(not) ! 362: ar[j++]=AR_NOT; ! 363: not=0; ! 364: ar[j++]=artype; ! 365: i+=4; } ! 366: else if(!strncmp(str+i,"QUIET",5)) { ! 367: artype=AR_QUIET; ! 368: if(not) ! 369: ar[j++]=AR_NOT; ! 370: not=0; ! 371: ar[j++]=artype; ! 372: i+=4; } ! 373: else if(!strncmp(str+i,"EXEMPT",6)) { ! 374: artype=AR_EXEMPT; ! 375: i+=5; } ! 376: else if(!strncmp(str+i,"RANDOM",6)) { ! 377: artype=AR_RANDOM; ! 378: i+=5; } ! 379: else if(!strncmp(str+i,"LASTON",6)) { ! 380: artype=AR_LASTON; ! 381: i+=5; } ! 382: else if(!strncmp(str+i,"LOGONS",6)) { ! 383: artype=AR_LOGONS; ! 384: i+=5; } ! 385: else if(!strncmp(str+i,"CREDIT",6)) { ! 386: artype=AR_CREDIT; ! 387: i+=5; } ! 388: else if(!strncmp(str+i,"MAIN_CMDS",9)) { ! 389: artype=AR_MAIN_CMDS; ! 390: i+=8; } ! 391: else if(!strncmp(str+i,"FILE_CMDS",9)) { ! 392: artype=AR_FILE_CMDS; ! 393: i+=8; } ! 394: if(n!=i) /* one of the above */ ! 395: continue; } ! 396: ! 397: if(not) ! 398: ar[j++]=AR_NOT; ! 399: if(equal) ! 400: ar[j++]=AR_EQUAL; ! 401: not=equal=0; ! 402: ! 403: if(artype==AR_FLAG1 && isdigit(str[i])) { /* flag set specified */ ! 404: switch(str[i]) { ! 405: case '2': ! 406: artype=AR_FLAG2; ! 407: break; ! 408: case '3': ! 409: artype=AR_FLAG3; ! 410: break; ! 411: case '4': ! 412: artype=AR_FLAG4; ! 413: break; } ! 414: continue; } ! 415: ! 416: if(artype==AR_SUB && !isdigit(str[i])) ! 417: artype=AR_SUBCODE; ! 418: if(artype==AR_DIR && !isdigit(str[i])) ! 419: artype=AR_DIRCODE; ! 420: ! 421: ar[j++]=artype; ! 422: if(isdigit(str[i])) { ! 423: if(artype==AR_TIME) { ! 424: n=atoi(str+i)*60; ! 425: p=strchr(str+i,':'); ! 426: if(p) ! 427: n+=atoi(p+1); ! 428: *((short *)(ar+j))=n; ! 429: j+=2; ! 430: while(isdigit(str[i+1]) || str[i+1]==':') i++; ! 431: continue; } ! 432: n=atoi(str+i); ! 433: switch(artype) { ! 434: case AR_DAY: ! 435: if(n>6) /* not past saturday */ ! 436: n=6; ! 437: case AR_AGE: /* byte operands */ ! 438: case AR_PCR: ! 439: case AR_UDR: ! 440: case AR_UDFR: ! 441: case AR_NODE: ! 442: case AR_LEVEL: ! 443: case AR_TLEFT: ! 444: case AR_TUSED: ! 445: ar[j++]=n; ! 446: break; ! 447: case AR_BPS: /* int operands */ ! 448: if(n<300) ! 449: n*=100; ! 450: case AR_MAIN_CMDS: ! 451: case AR_FILE_CMDS: ! 452: case AR_EXPIRE: ! 453: case AR_CREDIT: ! 454: case AR_USER: ! 455: case AR_RANDOM: ! 456: case AR_LASTON: ! 457: case AR_LOGONS: ! 458: *((short *)(ar+j))=n; ! 459: j+=2; ! 460: break; ! 461: case AR_GROUP: ! 462: case AR_LIB: ! 463: case AR_DIR: ! 464: case AR_SUB: ! 465: if(n) n--; /* convert to 0 base */ ! 466: *((short *)(ar+j))=n; ! 467: j+=2; ! 468: break; ! 469: default: /* invalid numeric AR type */ ! 470: j--; ! 471: break; } ! 472: while(isdigit(str[i+1])) i++; ! 473: continue; } ! 474: if(artype==AR_SUBCODE || artype==AR_DIRCODE) { ! 475: for(n=0;n<8 ! 476: && str[i] ! 477: && str[i]!=SP ! 478: && str[i]!='(' ! 479: && str[i]!=')' ! 480: && str[i]!='=' ! 481: && str[i]!='|' ! 482: ;n++) ! 483: ar[j++]=str[i++]; ! 484: ar[j++]=0; ! 485: continue; } ! 486: switch(artype) { ! 487: case AR_FLAG1: ! 488: case AR_FLAG2: ! 489: case AR_FLAG3: ! 490: case AR_FLAG4: ! 491: case AR_EXEMPT: ! 492: case AR_SEX: ! 493: case AR_REST: ! 494: ar[j++]=str[i]; ! 495: break; ! 496: #ifdef SBBS ! 497: case AR_SUB: ! 498: for(n=0;n<cfg->total_subs;n++) ! 499: if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code))) ! 500: break; ! 501: if(n<cfg->total_subs) { ! 502: *((short *)(ar+j))=n; ! 503: j+=2; } ! 504: else /* Unknown sub-board */ ! 505: j--; ! 506: while(isalpha(str[i+1])) i++; ! 507: break; ! 508: case AR_DIR: ! 509: for(n=0;n<cfg->total_dirs;n++) ! 510: if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code))) ! 511: break; ! 512: if(n<cfg->total_dirs) { ! 513: *((short *)(ar+j))=n; ! 514: j+=2; } ! 515: else /* Unknown directory */ ! 516: j--; ! 517: while(isalpha(str[i+1])) i++; ! 518: break; ! 519: #endif ! 520: case AR_DAY: ! 521: if(str[i]=='S' && str[i+1]=='U') /* Sunday */ ! 522: ar[j++]=0; ! 523: else if(str[i]=='M') /* Monday */ ! 524: ar[j++]=1; ! 525: else if(str[i]=='T' && str[i+1]=='U') /* Tuesday */ ! 526: ar[j++]=2; ! 527: else if(str[i]=='W') /* Wednesday */ ! 528: ar[j++]=3; ! 529: else if(str[i]=='T' && str[i+1]=='H') /* Thursday */ ! 530: ar[j++]=4; ! 531: else if(str[i]=='F') /* Friday */ ! 532: ar[j++]=5; ! 533: else ar[j++]=6; /* Saturday */ ! 534: while(isalpha(str[i+1])) i++; ! 535: break; ! 536: default: /* Badly formed ARS, digit expected */ ! 537: j--; ! 538: break; ! 539: } ! 540: } ! 541: if(!j) ! 542: return(nular); /* Save memory */ ! 543: ! 544: ar[j++]=AR_NULL; ! 545: /** DEBUG stuff ! 546: for(i=0;i<j;i++) ! 547: lprintf("%02X ",(uint)ar[i]); ! 548: lputs("\r\n"); ! 549: ***/ ! 550: if((ar_buf=(uchar *)calloc(j+4,1))==NULL) /* Padded for ushort dereferencing */ ! 551: return(NULL); ! 552: memcpy(ar_buf,ar,j); ! 553: if(count) ! 554: (*count)=j; ! 555: return(ar_buf); ! 556: } ! 557:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.