--- sbbs/src/sbbs3/ars.c 2018/04/24 16:41:24 1.1 +++ sbbs/src/sbbs3/ars.c 2018/04/24 16:43:52 1.1.1.2 @@ -2,13 +2,13 @@ /* Synchronet Access Requirement String (ARS) functions */ -/* $Id: ars.c,v 1.1 2018/04/24 16:41:24 root Exp $ */ +/* $Id: ars.c,v 1.1.1.2 2018/04/24 16:43:52 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -39,6 +39,20 @@ const uchar* nular=(uchar*)""; /* AR_NULL */ +static BOOL ar_string_arg(int artype) +{ + switch(artype) { + case AR_SUBCODE: + case AR_DIRCODE: + case AR_SHELL: + case AR_PROT: + case AR_HOST: + case AR_IP: + return TRUE; /* These ARS Keywords expect a string argument */ + } + return FALSE; +} + /* Converts ASCII ARS string into binary ARS buffer */ #ifdef __BORLANDC__ /* Eliminate warning when buildling Baja */ @@ -46,9 +60,14 @@ const uchar* nular=(uchar*)""; /* AR_NUL #endif uchar* arstr(ushort* count, char* str, scfg_t* cfg) { - char *p; - uchar ar[256],*ar_buf; - uint i,j,n,artype=AR_LEVEL,not=0,equal=0; + char* p; + char* np; + char ch; + uchar ar[1024],*ar_buf; + int artype=AR_INVALID; + uint i,j,n,not=0,equal=0; + uint maxlen; + BOOL arg_expected=FALSE; for(i=j=0;str[i];i++) { if(str[i]==' ') @@ -59,59 +78,74 @@ uchar* arstr(ushort* count, char* str, s ar[j++]=AR_NOT; not=equal=0; ar[j++]=AR_BEGNEST; - continue; } + continue; + } if(str[i]==')') { ar[j++]=AR_ENDNEST; - continue; } + continue; + } if(str[i]=='|') { ar[j++]=AR_OR; - continue; } + continue; + } if(str[i]=='!') { not=1; - continue; } + continue; + } if(str[i]=='=') { equal=1; - continue; } + continue; + } if(str[i]=='&') continue; if(isalpha(str[i])) { - if(!strnicmp(str+i,"OR",2)) { + p=np=str+i; + SKIP_ALPHA(np); + n=np-p; + if(n==2 && !strnicmp(p,"OR",2)) { ar[j++]=AR_OR; i++; - continue; } + continue; + } - if(!strnicmp(str+i,"AND",3)) { /* AND is ignored */ + if(n==3 && !strnicmp(p,"AND",3)) { /* AND is ignored */ i+=2; - continue; } + continue; + } - if(!strnicmp(str+i,"NOT",3)) { + if(n==3 && !strnicmp(p,"NOT",3)) { not=1; i+=2; - continue; } + continue; + } - if(!strnicmp(str+i,"EQUAL TO",8)) { - equal=1; - i+=7; - continue; } + if(n==2 && equal && !strnicmp(p,"TO",2)) { /* EQUAL TO */ + i++; + continue; + } - if(!strnicmp(str+i,"EQUAL",5)) { + if(n==5 && !strnicmp(p,"EQUAL",5)) { equal=1; i+=4; - continue; } + continue; + } - if(!strnicmp(str+i,"EQUALS",6)) { + if(n==6 && !strnicmp(p,"EQUALS",6)) { equal=1; i+=5; - continue; } } + continue; + } + } if(str[i]=='$') { - switch(toupper(str[i+1])) { + arg_expected=TRUE; + switch((ch=toupper(str[++i]))) { case 'A': artype=AR_AGE; break; @@ -130,13 +164,6 @@ uchar* arstr(ushort* count, char* str, s case 'F': artype=AR_FLAG1; break; - case 'G': - artype=AR_LOCAL; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - break; case 'H': artype=AR_SUB; break; @@ -193,257 +220,303 @@ uchar* arstr(ushort* count, char* str, s break; case 'Z': artype=AR_REST; - break; - case '[': - artype=AR_ANSI; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - break; + /* Boolean (no argument) symbols */ case '0': - artype=AR_NULL; - break; + case 'G': case '*': - artype=AR_RIP; + case '[': + switch(ch) { + case '0': + artype=AR_NULL; + break; + case 'G': + artype=AR_LOCAL; + break; + case '*': + artype=AR_RIP; + break; + case '[': + artype=AR_ANSI; + break; + } if(not) ar[j++]=AR_NOT; not=0; ar[j++]=artype; + artype=AR_INVALID; + arg_expected=FALSE; break; + } + continue; + } - } - i++; - continue; } - - if(isalpha(str[i])) { + if(!arg_expected && isalpha(str[i])) { n=i; if(!strnicmp(str+i,"AGE",3)) { artype=AR_AGE; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"BPS",3)) { artype=AR_BPS; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"PCR",3)) { artype=AR_PCR; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"SEX",3)) { artype=AR_SEX; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"UDR",3)) { artype=AR_UDR; - i+=2; } + i+=2; + } + else if(!strnicmp(str+i,"ULS",3)) { + artype=AR_ULS; + i+=2; + } + else if(!strnicmp(str+i,"ULK",3)) { + artype=AR_ULK; + i+=2; + } + else if(!strnicmp(str+i,"ULM",3)) { + artype=AR_ULM; + i+=2; + } + else if(!strnicmp(str+i,"DLS",3)) { + artype=AR_DLS; + i+=2; + } + else if(!strnicmp(str+i,"DLK",3)) { + artype=AR_DLK; + i+=2; + } + else if(!strnicmp(str+i,"DLM",3)) { + artype=AR_DLM; + i+=2; + } else if(!strnicmp(str+i,"DAY",3)) { artype=AR_DAY; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"RIP",3)) { artype=AR_RIP; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"WIP",3)) { artype=AR_WIP; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"OS2",3)) { artype=AR_OS2; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"DOS",3)) { artype=AR_DOS; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"WIN32",5)) { artype=AR_WIN32; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"UNIX",4)) { artype=AR_UNIX; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"LINUX",5)) { artype=AR_LINUX; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"PROT",4)) { artype=AR_PROT; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=3; } + i+=3; + } + else if(!strnicmp(str+i,"HOST",4)) { + artype=AR_HOST; + i+=3; + } + else if(!strnicmp(str+i,"IP",2)) { + artype=AR_IP; + i++; + } else if(!strnicmp(str+i,"SUBCODE",7)) { artype=AR_SUBCODE; - i+=6; } + i+=6; + } else if(!strnicmp(str+i,"SUB",3)) { artype=AR_SUB; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"LIB",3)) { artype=AR_LIB; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"DIRCODE",7)) { artype=AR_DIRCODE; - i+=6; } + i+=6; + } else if(!strnicmp(str+i,"DIR",3)) { artype=AR_DIR; - i+=2; } + i+=2; + } else if(!strnicmp(str+i,"ANSI",4)) { artype=AR_ANSI; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"UDFR",4)) { artype=AR_UDFR; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"FLAG",4)) { artype=AR_FLAG1; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"NODE",4)) { artype=AR_NODE; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"NULL",4)) { artype=AR_NULL; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"USER",4)) { artype=AR_USER; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"TIME",4)) { artype=AR_TIME; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"REST",4)) { artype=AR_REST; - i+=3; } + i+=3; + } else if(!strnicmp(str+i,"LEVEL",5)) { artype=AR_LEVEL; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"TLEFT",5)) { artype=AR_TLEFT; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"TUSED",5)) { artype=AR_TUSED; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"LOCAL",5)) { artype=AR_LOCAL; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"GROUP",5)) { artype=AR_GROUP; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"EXPIRE",6)) { artype=AR_EXPIRE; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"ACTIVE",6)) { artype=AR_ACTIVE; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"INACTIVE",8)) { artype=AR_INACTIVE; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=7; } + i+=7; + } else if(!strnicmp(str+i,"DELETED",7)) { artype=AR_DELETED; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=6; } + i+=6; + } else if(!strnicmp(str+i,"EXPERT",6)) { artype=AR_EXPERT; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"SYSOP",5)) { artype=AR_SYSOP; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"GUEST",5)) { artype=AR_GUEST; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"QNODE",5)) { artype=AR_QNODE; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"QUIET",5)) { artype=AR_QUIET; - if(not) - ar[j++]=AR_NOT; - not=0; - ar[j++]=artype; - i+=4; } + i+=4; + } else if(!strnicmp(str+i,"EXEMPT",6)) { artype=AR_EXEMPT; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"RANDOM",6)) { artype=AR_RANDOM; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"LASTON",6)) { artype=AR_LASTON; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"LOGONS",6)) { artype=AR_LOGONS; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"CREDIT",6)) { artype=AR_CREDIT; - i+=5; } + i+=5; + } else if(!strnicmp(str+i,"MAIN_CMDS",9)) { artype=AR_MAIN_CMDS; - i+=8; } + i+=8; + } else if(!strnicmp(str+i,"FILE_CMDS",9)) { artype=AR_FILE_CMDS; - i+=8; } + i+=8; + } else if(!strnicmp(str+i,"SHELL",5)) { artype=AR_SHELL; - i+=4; } - if(n!=i) /* one of the above */ + i+=4; + } + + if(n!=i) /* one of the above */ + { + arg_expected=TRUE; + switch(artype) { + case AR_RIP: + case AR_WIP: + case AR_ANSI: + case AR_DOS: + case AR_OS2: + case AR_UNIX: + case AR_LINUX: + case AR_WIN32: + case AR_LOCAL: + case AR_ACTIVE: + case AR_INACTIVE: + case AR_DELETED: + case AR_EXPERT: + case AR_SYSOP: + case AR_GUEST: + case AR_QNODE: + case AR_QUIET: + /* Boolean (No arguments) */ + if(not) + ar[j++]=AR_NOT; + not=0; + ar[j++]=artype; + artype=AR_INVALID; + arg_expected=FALSE; + break; + } continue; + } } - if(not) ar[j++]=AR_NOT; - if(equal) + if(equal && !ar_string_arg(artype)) ar[j++]=AR_EQUAL; not=equal=0; @@ -457,16 +530,22 @@ uchar* arstr(ushort* count, char* str, s break; case '4': artype=AR_FLAG4; - break; } - continue; } + break; + } + continue; + } + + arg_expected=FALSE; if(artype==AR_SUB && !isdigit(str[i])) artype=AR_SUBCODE; if(artype==AR_DIR && !isdigit(str[i])) artype=AR_DIRCODE; + if(artype==AR_INVALID) + artype=AR_LEVEL; ar[j++]=artype; - if(isdigit(str[i])) { + if(isdigit(str[i]) && !ar_string_arg(artype)) { if(artype==AR_TIME) { n=atoi(str+i)*60; p=strchr(str+i,':'); @@ -475,7 +554,8 @@ uchar* arstr(ushort* count, char* str, s *((short *)(ar+j))=n; j+=2; while(isdigit(str[i+1]) || str[i+1]==':') i++; - continue; } + continue; + } n=atoi(str+i); switch(artype) { case AR_DAY: @@ -502,8 +582,14 @@ uchar* arstr(ushort* count, char* str, s case AR_RANDOM: case AR_LASTON: case AR_LOGONS: + case AR_ULS: + case AR_ULK: + case AR_ULM: + case AR_DLS: + case AR_DLK: + case AR_DLM: *((short *)(ar+j))=n; - j+=2; + j+=sizeof(short); break; case AR_GROUP: case AR_LIB: @@ -515,24 +601,34 @@ uchar* arstr(ushort* count, char* str, s break; default: /* invalid numeric AR type */ j--; - break; } + break; + } while(isdigit(str[i+1])) i++; - continue; } - if(artype==AR_SUBCODE || artype==AR_DIRCODE || artype==AR_SHELL) { - for(n=0;ntotal_subs;n++) + for(n=0;n<(uint)cfg->total_subs;n++) if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code))) break; - if(ntotal_subs) { + if(n<(uint)cfg->total_subs) { *((short *)(ar+j))=n; - j+=2; } + j+=2; + } else /* Unknown sub-board */ j--; while(isalpha(str[i+1])) i++; break; case AR_DIR: - for(n=0;ntotal_dirs;n++) + for(n=0;n<(uint)cfg->total_dirs;n++) if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code))) break; - if(ntotal_dirs) { + if(n<(uint)cfg->total_dirs) { *((short *)(ar+j))=n; - j+=2; } + j+=2; + } else /* Unknown directory */ j--; while(isalpha(str[i+1])) i++; break; - #endif case AR_DAY: if(toupper(str[i])=='S' && toupper(str[i+1])=='U') /* Sunday */ @@ -596,7 +692,7 @@ uchar* arstr(ushort* count, char* str, s ar[j++]=AR_NULL; /** DEBUG stuff for(i=0;i