|
|
1.1 root 1: /* ars.c */
2:
3: /* Synchronet Access Requirement String (ARS) functions */
4:
5: /* $Id: ars.c,v 1.13 2006/12/29 09:00:59 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 2006 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: const uchar* nular=(uchar*)""; /* AR_NULL */
41:
42: /* Converts ASCII ARS string into binary ARS buffer */
43:
44: #ifdef __BORLANDC__ /* Eliminate warning when buildling Baja */
45: #pragma argsused
46: #endif
47: uchar* arstr(ushort* count, char* str, scfg_t* cfg)
48: {
49: char *p;
50: uchar ar[256],*ar_buf;
51: uint i,j,n,artype=AR_LEVEL,not=0,equal=0;
52:
53: for(i=j=0;str[i];i++) {
54: if(str[i]==' ')
55: continue;
56:
57: if(str[i]=='(') {
58: if(not)
59: ar[j++]=AR_NOT;
60: not=equal=0;
61: ar[j++]=AR_BEGNEST;
62: continue; }
63:
64: if(str[i]==')') {
65: ar[j++]=AR_ENDNEST;
66: continue; }
67:
68: if(str[i]=='|') {
69: ar[j++]=AR_OR;
70: continue; }
71:
72: if(str[i]=='!') {
73: not=1;
74: continue; }
75:
76: if(str[i]=='=') {
77: equal=1;
78: continue; }
79:
80: if(str[i]=='&')
81: continue;
82:
83: if(isalpha(str[i])) {
84: if(!strnicmp(str+i,"OR",2)) {
85: ar[j++]=AR_OR;
86: i++;
87: continue; }
88:
89: if(!strnicmp(str+i,"AND",3)) { /* AND is ignored */
90: i+=2;
91: continue; }
92:
93: if(!strnicmp(str+i,"NOT",3)) {
94: not=1;
95: i+=2;
96: continue; }
97:
98: if(!strnicmp(str+i,"EQUAL TO",8)) {
99: equal=1;
100: i+=7;
101: continue; }
102:
103: if(!strnicmp(str+i,"EQUAL",5)) {
104: equal=1;
105: i+=4;
106: continue; }
107:
108: if(!strnicmp(str+i,"EQUALS",6)) {
109: equal=1;
110: i+=5;
111: continue; } }
112:
113: if(str[i]=='$') {
114: switch(toupper(str[i+1])) {
115: case 'A':
116: artype=AR_AGE;
117: break;
118: case 'B':
119: artype=AR_BPS;
120: break;
121: case 'C':
122: artype=AR_CREDIT;
123: break;
124: case 'D':
125: artype=AR_UDFR;
126: break;
127: case 'E':
128: artype=AR_EXPIRE;
129: break;
130: case 'F':
131: artype=AR_FLAG1;
132: break;
133: case 'G':
134: artype=AR_LOCAL;
135: if(not)
136: ar[j++]=AR_NOT;
137: not=0;
138: ar[j++]=artype;
139: break;
140: case 'H':
141: artype=AR_SUB;
142: break;
143: case 'I':
144: artype=AR_LIB;
145: break;
146: case 'J':
147: artype=AR_DIR;
148: break;
149: case 'K':
150: artype=AR_UDR;
151: break;
152: case 'L':
153: artype=AR_LEVEL;
154: break;
155: case 'M':
156: artype=AR_GROUP;
157: break;
158: case 'N':
159: artype=AR_NODE;
160: break;
161: case 'O':
162: artype=AR_TUSED;
163: break;
164: case 'P':
165: artype=AR_PCR;
166: break;
167: case 'Q':
168: artype=AR_RANDOM;
169: break;
170: case 'R':
171: artype=AR_TLEFT;
172: break;
173: case 'S':
174: artype=AR_SEX;
175: break;
176: case 'T':
177: artype=AR_TIME;
178: break;
179: case 'U':
180: artype=AR_USER;
181: break;
182: case 'V':
183: artype=AR_LOGONS;
184: break;
185: case 'W':
186: artype=AR_DAY;
187: break;
188: case 'X':
189: artype=AR_EXEMPT;
190: break;
191: case 'Y': /* Days since last on */
192: artype=AR_LASTON;
193: break;
194: case 'Z':
195: artype=AR_REST;
196: break;
197: case '[':
198: artype=AR_ANSI;
199: if(not)
200: ar[j++]=AR_NOT;
201: not=0;
202: ar[j++]=artype;
203: break;
204: case '0':
205: artype=AR_NULL;
206: break;
207: case '*':
208: artype=AR_RIP;
209: if(not)
210: ar[j++]=AR_NOT;
211: not=0;
212: ar[j++]=artype;
213: break;
214:
215: }
216: i++;
217: continue; }
218:
219: if(isalpha(str[i])) {
220: n=i;
221: if(!strnicmp(str+i,"AGE",3)) {
222: artype=AR_AGE;
223: i+=2; }
224: else if(!strnicmp(str+i,"BPS",3)) {
225: artype=AR_BPS;
226: i+=2; }
227: else if(!strnicmp(str+i,"PCR",3)) {
228: artype=AR_PCR;
229: i+=2; }
230: else if(!strnicmp(str+i,"SEX",3)) {
231: artype=AR_SEX;
232: i+=2; }
233: else if(!strnicmp(str+i,"UDR",3)) {
234: artype=AR_UDR;
235: i+=2; }
236: else if(!strnicmp(str+i,"DAY",3)) {
237: artype=AR_DAY;
238: i+=2; }
239: else if(!strnicmp(str+i,"RIP",3)) {
240: artype=AR_RIP;
241: if(not)
242: ar[j++]=AR_NOT;
243: not=0;
244: ar[j++]=artype;
245: i+=2; }
246: else if(!strnicmp(str+i,"WIP",3)) {
247: artype=AR_WIP;
248: if(not)
249: ar[j++]=AR_NOT;
250: not=0;
251: ar[j++]=artype;
252: i+=2; }
253: else if(!strnicmp(str+i,"OS2",3)) {
254: artype=AR_OS2;
255: if(not)
256: ar[j++]=AR_NOT;
257: not=0;
258: ar[j++]=artype;
259: i+=2; }
260: else if(!strnicmp(str+i,"DOS",3)) {
261: artype=AR_DOS;
262: if(not)
263: ar[j++]=AR_NOT;
264: not=0;
265: ar[j++]=artype;
266: i+=2; }
267: else if(!strnicmp(str+i,"WIN32",5)) {
268: artype=AR_WIN32;
269: if(not)
270: ar[j++]=AR_NOT;
271: not=0;
272: ar[j++]=artype;
273: i+=4; }
274: else if(!strnicmp(str+i,"UNIX",4)) {
275: artype=AR_UNIX;
276: if(not)
277: ar[j++]=AR_NOT;
278: not=0;
279: ar[j++]=artype;
280: i+=3; }
281: else if(!strnicmp(str+i,"LINUX",5)) {
282: artype=AR_LINUX;
283: if(not)
284: ar[j++]=AR_NOT;
285: not=0;
286: ar[j++]=artype;
287: i+=4; }
288: else if(!strnicmp(str+i,"PROT",4)) {
289: artype=AR_PROT;
290: if(not)
291: ar[j++]=AR_NOT;
292: not=0;
293: ar[j++]=artype;
294: i+=3; }
295: else if(!strnicmp(str+i,"SUBCODE",7)) {
296: artype=AR_SUBCODE;
297: i+=6; }
298: else if(!strnicmp(str+i,"SUB",3)) {
299: artype=AR_SUB;
300: i+=2; }
301: else if(!strnicmp(str+i,"LIB",3)) {
302: artype=AR_LIB;
303: i+=2; }
304: else if(!strnicmp(str+i,"DIRCODE",7)) {
305: artype=AR_DIRCODE;
306: i+=6; }
307: else if(!strnicmp(str+i,"DIR",3)) {
308: artype=AR_DIR;
309: i+=2; }
310: else if(!strnicmp(str+i,"ANSI",4)) {
311: artype=AR_ANSI;
312: if(not)
313: ar[j++]=AR_NOT;
314: not=0;
315: ar[j++]=artype;
316: i+=3; }
317: else if(!strnicmp(str+i,"UDFR",4)) {
318: artype=AR_UDFR;
319: i+=3; }
320: else if(!strnicmp(str+i,"FLAG",4)) {
321: artype=AR_FLAG1;
322: i+=3; }
323: else if(!strnicmp(str+i,"NODE",4)) {
324: artype=AR_NODE;
325: i+=3; }
326: else if(!strnicmp(str+i,"NULL",4)) {
327: artype=AR_NULL;
328: i+=3; }
329: else if(!strnicmp(str+i,"USER",4)) {
330: artype=AR_USER;
331: i+=3; }
332: else if(!strnicmp(str+i,"TIME",4)) {
333: artype=AR_TIME;
334: i+=3; }
335: else if(!strnicmp(str+i,"REST",4)) {
336: artype=AR_REST;
337: i+=3; }
338: else if(!strnicmp(str+i,"LEVEL",5)) {
339: artype=AR_LEVEL;
340: i+=4; }
341: else if(!strnicmp(str+i,"TLEFT",5)) {
342: artype=AR_TLEFT;
343: i+=4; }
344: else if(!strnicmp(str+i,"TUSED",5)) {
345: artype=AR_TUSED;
346: i+=4; }
347: else if(!strnicmp(str+i,"LOCAL",5)) {
348: artype=AR_LOCAL;
349: if(not)
350: ar[j++]=AR_NOT;
351: not=0;
352: ar[j++]=artype;
353: i+=4; }
354: else if(!strnicmp(str+i,"GROUP",5)) {
355: artype=AR_GROUP;
356: i+=4; }
357: else if(!strnicmp(str+i,"EXPIRE",6)) {
358: artype=AR_EXPIRE;
359: i+=5; }
360: else if(!strnicmp(str+i,"ACTIVE",6)) {
361: artype=AR_ACTIVE;
362: if(not)
363: ar[j++]=AR_NOT;
364: not=0;
365: ar[j++]=artype;
366: i+=5; }
367: else if(!strnicmp(str+i,"INACTIVE",8)) {
368: artype=AR_INACTIVE;
369: if(not)
370: ar[j++]=AR_NOT;
371: not=0;
372: ar[j++]=artype;
373: i+=7; }
374: else if(!strnicmp(str+i,"DELETED",7)) {
375: artype=AR_DELETED;
376: if(not)
377: ar[j++]=AR_NOT;
378: not=0;
379: ar[j++]=artype;
380: i+=6; }
381: else if(!strnicmp(str+i,"EXPERT",6)) {
382: artype=AR_EXPERT;
383: if(not)
384: ar[j++]=AR_NOT;
385: not=0;
386: ar[j++]=artype;
387: i+=5; }
388: else if(!strnicmp(str+i,"SYSOP",5)) {
389: artype=AR_SYSOP;
390: if(not)
391: ar[j++]=AR_NOT;
392: not=0;
393: ar[j++]=artype;
394: i+=4; }
395: else if(!strnicmp(str+i,"GUEST",5)) {
396: artype=AR_GUEST;
397: if(not)
398: ar[j++]=AR_NOT;
399: not=0;
400: ar[j++]=artype;
401: i+=4; }
402: else if(!strnicmp(str+i,"QNODE",5)) {
403: artype=AR_QNODE;
404: if(not)
405: ar[j++]=AR_NOT;
406: not=0;
407: ar[j++]=artype;
408: i+=4; }
409: else if(!strnicmp(str+i,"QUIET",5)) {
410: artype=AR_QUIET;
411: if(not)
412: ar[j++]=AR_NOT;
413: not=0;
414: ar[j++]=artype;
415: i+=4; }
416: else if(!strnicmp(str+i,"EXEMPT",6)) {
417: artype=AR_EXEMPT;
418: i+=5; }
419: else if(!strnicmp(str+i,"RANDOM",6)) {
420: artype=AR_RANDOM;
421: i+=5; }
422: else if(!strnicmp(str+i,"LASTON",6)) {
423: artype=AR_LASTON;
424: i+=5; }
425: else if(!strnicmp(str+i,"LOGONS",6)) {
426: artype=AR_LOGONS;
427: i+=5; }
428: else if(!strnicmp(str+i,"CREDIT",6)) {
429: artype=AR_CREDIT;
430: i+=5; }
431: else if(!strnicmp(str+i,"MAIN_CMDS",9)) {
432: artype=AR_MAIN_CMDS;
433: i+=8; }
434: else if(!strnicmp(str+i,"FILE_CMDS",9)) {
435: artype=AR_FILE_CMDS;
436: i+=8; }
437: else if(!strnicmp(str+i,"SHELL",5)) {
438: artype=AR_SHELL;
439: i+=4; }
440: if(n!=i) /* one of the above */
441: continue;
442: }
443:
444: if(not)
445: ar[j++]=AR_NOT;
446: if(equal)
447: ar[j++]=AR_EQUAL;
448: not=equal=0;
449:
450: if(artype==AR_FLAG1 && isdigit(str[i])) { /* flag set specified */
451: switch(str[i]) {
452: case '2':
453: artype=AR_FLAG2;
454: break;
455: case '3':
456: artype=AR_FLAG3;
457: break;
458: case '4':
459: artype=AR_FLAG4;
460: break; }
461: continue; }
462:
463: if(artype==AR_SUB && !isdigit(str[i]))
464: artype=AR_SUBCODE;
465: if(artype==AR_DIR && !isdigit(str[i]))
466: artype=AR_DIRCODE;
467:
468: ar[j++]=artype;
469: if(isdigit(str[i])) {
470: if(artype==AR_TIME) {
471: n=atoi(str+i)*60;
472: p=strchr(str+i,':');
473: if(p)
474: n+=atoi(p+1);
475: *((short *)(ar+j))=n;
476: j+=2;
477: while(isdigit(str[i+1]) || str[i+1]==':') i++;
478: continue; }
479: n=atoi(str+i);
480: switch(artype) {
481: case AR_DAY:
482: if(n>6) /* not past saturday */
483: n=6;
484: case AR_AGE: /* byte operands */
485: case AR_PCR:
486: case AR_UDR:
487: case AR_UDFR:
488: case AR_NODE:
489: case AR_LEVEL:
490: case AR_TLEFT:
491: case AR_TUSED:
492: ar[j++]=n;
493: break;
494: case AR_BPS: /* int operands */
495: if(n<300)
496: n*=100;
497: case AR_MAIN_CMDS:
498: case AR_FILE_CMDS:
499: case AR_EXPIRE:
500: case AR_CREDIT:
501: case AR_USER:
502: case AR_RANDOM:
503: case AR_LASTON:
504: case AR_LOGONS:
505: *((short *)(ar+j))=n;
506: j+=2;
507: break;
508: case AR_GROUP:
509: case AR_LIB:
510: case AR_DIR:
511: case AR_SUB:
512: if(n) n--; /* convert to 0 base */
513: *((short *)(ar+j))=n;
514: j+=2;
515: break;
516: default: /* invalid numeric AR type */
517: j--;
518: break; }
519: while(isdigit(str[i+1])) i++;
520: continue; }
521: if(artype==AR_SUBCODE || artype==AR_DIRCODE || artype==AR_SHELL) {
522: for(n=0;n<LEN_EXTCODE
523: && str[i]
524: && str[i]!=' '
525: && str[i]!='('
526: && str[i]!=')'
527: && str[i]!='='
528: && str[i]!='|'
529: ;n++)
530: ar[j++]=toupper(str[i++]);
531: ar[j++]=0;
532: i--;
533: continue;
534: }
535: switch(artype) {
536: case AR_FLAG1:
537: case AR_FLAG2:
538: case AR_FLAG3:
539: case AR_FLAG4:
540: case AR_EXEMPT:
541: case AR_SEX:
542: case AR_REST:
543: ar[j++]=toupper(str[i]);
544: break;
545: #ifdef SBBS
546: case AR_SUB:
547: for(n=0;n<cfg->total_subs;n++)
548: if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code)))
549: break;
550: if(n<cfg->total_subs) {
551: *((short *)(ar+j))=n;
552: j+=2; }
553: else /* Unknown sub-board */
554: j--;
555: while(isalpha(str[i+1])) i++;
556: break;
557: case AR_DIR:
558: for(n=0;n<cfg->total_dirs;n++)
559: if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code)))
560: break;
561: if(n<cfg->total_dirs) {
562: *((short *)(ar+j))=n;
563: j+=2; }
564: else /* Unknown directory */
565: j--;
566: while(isalpha(str[i+1])) i++;
567: break;
568: #endif
569: case AR_DAY:
570: if(toupper(str[i])=='S'
571: && toupper(str[i+1])=='U') /* Sunday */
572: ar[j++]=0;
573: else if(toupper(str[i])=='M') /* Monday */
574: ar[j++]=1;
575: else if(toupper(str[i])=='T'
576: && toupper(str[i+1])=='U') /* Tuesday */
577: ar[j++]=2;
578: else if(toupper(str[i])=='W') /* Wednesday */
579: ar[j++]=3;
580: else if(toupper(str[i])=='T'
581: && toupper(str[i+1])=='H') /* Thursday */
582: ar[j++]=4;
583: else if(toupper(str[i])=='F') /* Friday */
584: ar[j++]=5;
585: else ar[j++]=6; /* Saturday */
586: while(isalpha(str[i+1])) i++;
587: break;
588: default: /* Badly formed ARS, digit expected */
589: j--;
590: break;
591: }
592: }
593: if(!j)
594: return((uchar*)nular); /* Save memory */
595:
596: ar[j++]=AR_NULL;
597: /** DEBUG stuff
598: for(i=0;i<j;i++)
599: lprintf("%02X ",(uint)ar[i]);
600: lputs("\r\n");
601: ***/
602: if((ar_buf=(uchar *)calloc(j+4,1))==NULL) /* Padded for ushort dereferencing */
603: return(NULL);
604: memcpy(ar_buf,ar,j);
605: if(count)
606: (*count)=j;
607: return(ar_buf);
608: }
609:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.