Newer
Older
/* ars.c */
/* Synchronet Access Requirement String (ARS) functions */
/* $Id$ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 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 *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
#include "sbbs.h"
const uchar* nular=(uchar*)""; /* AR_NULL */
/* Converts ASCII ARS string into binary ARS buffer */
#ifdef __BORLANDC__ /* Eliminate warning when buildling Baja */
#pragma argsused
#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;
for(i=j=0;str[i];i++) {
continue;
if(str[i]=='(') {
if(not)
ar[j++]=AR_NOT;
not=equal=0;
ar[j++]=AR_BEGNEST;
continue; }
if(str[i]==')') {
ar[j++]=AR_ENDNEST;
continue; }
if(str[i]=='|') {
ar[j++]=AR_OR;
continue; }
if(str[i]=='!') {
not=1;
continue; }
if(str[i]=='=') {
equal=1;
continue; }
if(str[i]=='&')
continue;
if(isalpha(str[i])) {
ar[j++]=AR_OR;
i++;
continue; }
if(!strnicmp(str+i,"AND",3)) { /* AND is ignored */
not=1;
i+=2;
continue; }
equal=1;
i+=7;
continue; }
equal=1;
i+=4;
continue; }
equal=1;
i+=5;
continue; } }
if(str[i]=='$') {
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
case 'A':
artype=AR_AGE;
break;
case 'B':
artype=AR_BPS;
break;
case 'C':
artype=AR_CREDIT;
break;
case 'D':
artype=AR_UDFR;
break;
case 'E':
artype=AR_EXPIRE;
break;
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;
case 'I':
artype=AR_LIB;
break;
case 'J':
artype=AR_DIR;
break;
case 'K':
artype=AR_UDR;
break;
case 'L':
artype=AR_LEVEL;
break;
case 'M':
artype=AR_GROUP;
break;
case 'N':
artype=AR_NODE;
break;
case 'O':
artype=AR_TUSED;
break;
case 'P':
artype=AR_PCR;
break;
case 'Q':
artype=AR_RANDOM;
break;
case 'R':
artype=AR_TLEFT;
break;
case 'S':
artype=AR_SEX;
break;
case 'T':
artype=AR_TIME;
break;
case 'U':
artype=AR_USER;
break;
case 'V':
artype=AR_LOGONS;
break;
case 'W':
artype=AR_DAY;
break;
case 'X':
artype=AR_EXEMPT;
break;
case 'Y': /* Days since last on */
artype=AR_LASTON;
break;
case 'Z':
artype=AR_REST;
break;
case '[':
artype=AR_ANSI;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
break;
case '0':
artype=AR_NULL;
break;
case '*':
artype=AR_RIP;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
break;
}
i++;
continue; }
if(isalpha(str[i])) {
n=i;
artype=AR_RIP;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=2; }
artype=AR_WIP;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=2; }
artype=AR_OS2;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=2; }
artype=AR_DOS;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
artype=AR_WIN32;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
artype=AR_UNIX;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
artype=AR_LINUX;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
else if(!strnicmp(str+i,"PROT",4)) {
artype=AR_PROT;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
artype=AR_SUBCODE;
i+=6; }
artype=AR_DIRCODE;
i+=6; }
artype=AR_ANSI;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=3; }
artype=AR_LOCAL;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=4; }
artype=AR_EXPERT;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=5; }
artype=AR_SYSOP;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
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; }
else if(!strnicmp(str+i,"QNODE",5)) {
artype=AR_QNODE;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=4; }
artype=AR_QUIET;
if(not)
ar[j++]=AR_NOT;
not=0;
ar[j++]=artype;
i+=4; }
artype=AR_MAIN_CMDS;
i+=8; }
artype=AR_FILE_CMDS;
i+=8; }
else if(!strnicmp(str+i,"SHELL",5)) {
artype=AR_SHELL;
i+=4; }
if(n!=i) /* one of the above */
continue;
}
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
if(not)
ar[j++]=AR_NOT;
if(equal)
ar[j++]=AR_EQUAL;
not=equal=0;
if(artype==AR_FLAG1 && isdigit(str[i])) { /* flag set specified */
switch(str[i]) {
case '2':
artype=AR_FLAG2;
break;
case '3':
artype=AR_FLAG3;
break;
case '4':
artype=AR_FLAG4;
break; }
continue; }
if(artype==AR_SUB && !isdigit(str[i]))
artype=AR_SUBCODE;
if(artype==AR_DIR && !isdigit(str[i]))
artype=AR_DIRCODE;
ar[j++]=artype;
if(isdigit(str[i])) {
if(artype==AR_TIME) {
n=atoi(str+i)*60;
p=strchr(str+i,':');
if(p)
n+=atoi(p+1);
*((short *)(ar+j))=n;
j+=2;
while(isdigit(str[i+1]) || str[i+1]==':') i++;
continue; }
n=atoi(str+i);
switch(artype) {
case AR_DAY:
if(n>6) /* not past saturday */
n=6;
case AR_AGE: /* byte operands */
case AR_PCR:
case AR_UDR:
case AR_UDFR:
case AR_NODE:
case AR_LEVEL:
case AR_TLEFT:
case AR_TUSED:
ar[j++]=n;
break;
case AR_BPS: /* int operands */
if(n<300)
n*=100;
case AR_MAIN_CMDS:
case AR_FILE_CMDS:
case AR_EXPIRE:
case AR_CREDIT:
case AR_USER:
case AR_RANDOM:
case AR_LASTON:
case AR_LOGONS:
*((short *)(ar+j))=n;
j+=2;
break;
case AR_GROUP:
case AR_LIB:
case AR_DIR:
case AR_SUB:
if(n) n--; /* convert to 0 base */
*((short *)(ar+j))=n;
j+=2;
break;
default: /* invalid numeric AR type */
j--;
break; }
while(isdigit(str[i+1])) i++;
continue; }
if(artype==AR_SUBCODE || artype==AR_DIRCODE || artype==AR_SHELL) {
&& str[i]!='('
&& str[i]!=')'
&& str[i]!='='
&& str[i]!='|'
;n++)
switch(artype) {
case AR_FLAG1:
case AR_FLAG2:
case AR_FLAG3:
case AR_FLAG4:
case AR_EXEMPT:
case AR_SEX:
case AR_REST:
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
break;
#ifdef SBBS
case AR_SUB:
for(n=0;n<cfg->total_subs;n++)
if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code)))
break;
if(n<cfg->total_subs) {
*((short *)(ar+j))=n;
j+=2; }
else /* Unknown sub-board */
j--;
while(isalpha(str[i+1])) i++;
break;
case AR_DIR:
for(n=0;n<cfg->total_dirs;n++)
if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code)))
break;
if(n<cfg->total_dirs) {
*((short *)(ar+j))=n;
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 */
else if(toupper(str[i])=='T'
&& toupper(str[i+1])=='U') /* Tuesday */
else if(toupper(str[i])=='T'
&& toupper(str[i+1])=='H') /* Thursday */
ar[j++]=5;
else ar[j++]=6; /* Saturday */
while(isalpha(str[i+1])) i++;
break;
default: /* Badly formed ARS, digit expected */
j--;
break;
}
}
if(!j)
return((uchar*)nular); /* Save memory */
ar[j++]=AR_NULL;
/** DEBUG stuff
for(i=0;i<j;i++)
lprintf("%02X ",(uint)ar[i]);
lputs("\r\n");
***/
if((ar_buf=(uchar *)calloc(j+4,1))==NULL) /* Padded for ushort dereferencing */
return(NULL);
memcpy(ar_buf,ar,j);
if(count)
(*count)=j;
return(ar_buf);
}