ars.c 23.5 KB
Newer Older
1 2 3 4 5 6
/* Synchronet Access Requirement String (ARS) functions */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *																			*
 * 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										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

22
#include "ars_defs.h"
23

24 25 26 27 28 29 30 31 32 33 34 35 36 37
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;
}

38 39
/* Converts ASCII ARS string into binary ARS buffer */

40 41 42
#ifdef __BORLANDC__	/* Eliminate warning when buildling Baja */
#pragma argsused
#endif
43
uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf)
44
{
45 46
	const char*	p;
	const char*	np;
47
	char	ch;
48
	uchar	ar[1024];
49 50 51 52
	int		artype=AR_INVALID;
	uint	i,j,n,not=0,equal=0;
	uint	maxlen;
	BOOL	arg_expected=FALSE;
53 54

	for(i=j=0;str[i];i++) {
55
		if(str[i]==' ')
56 57 58 59 60 61 62
			continue;

		if(str[i]=='(') {
			if(not)
				ar[j++]=AR_NOT;
			not=equal=0;
			ar[j++]=AR_BEGNEST;
63 64
			continue; 
		}
65 66 67

		if(str[i]==')') {
			ar[j++]=AR_ENDNEST;
68 69
			continue; 
		}
70 71 72

		if(str[i]=='|') {
			ar[j++]=AR_OR;
73 74
			continue; 
		}
75 76 77
    
		if(str[i]=='!') {
			not=1;
78 79
			continue; 
		}
80 81 82

		if(str[i]=='=') {
			equal=1;
83 84
			continue; 
		}
85 86 87 88

		if(str[i]=='&')
			continue;

89
		if(IS_ALPHA(str[i])) {
90 91 92 93
			p=np=str+i;
			SKIP_ALPHA(np);
			n=np-p;
			if(n==2 && !strnicmp(p,"OR",2)) {
94 95
				ar[j++]=AR_OR;
				i++;
96 97
				continue; 
			}
98

99
			if(n==3 && !strnicmp(p,"AND",3)) {    /* AND is ignored */
100
				i+=2;
101 102
				continue; 
			}
103

104
			if(n==3 && !strnicmp(p,"NOT",3)) {
105 106
				not=1;
				i+=2;
107 108
				continue; 
			}
109

110 111
			if(n==2 && equal && !strnicmp(p,"TO",2)) {	/* EQUAL TO */
				i++;
112 113
				continue; 
			}
114

115
			if(n==5 && !strnicmp(p,"EQUAL",5)) {
116 117
				equal=1;
				i+=4;
118 119
				continue; 
			}
120

121
			if(n==6 && !strnicmp(p,"EQUALS",6)) {
122 123
				equal=1;
				i+=5;
124 125 126
				continue; 
			} 
		}
127 128

		if(str[i]=='$') {
129 130
			arg_expected=TRUE;
			switch((ch=toupper(str[++i]))) {
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
				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 '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;
205
				/* Boolean (no argument) symbols */
206
				case '0':
207
				case 'G':
208
				case '*':
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
				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;
					}
224 225 226 227
					if(not)
						ar[j++]=AR_NOT;
					not=0;
					ar[j++]=artype;
228 229
					artype=AR_INVALID;
					arg_expected=FALSE;
230
					break;
231 232 233
			}
			continue; 
		}
234

235
		if(!arg_expected && IS_ALPHA(str[i])) {
236
			n=i;
rswindell's avatar
rswindell committed
237
			if(!strnicmp(str+i,"AGE",3)) {
238
				artype=AR_AGE;
239 240
				i+=2; 
			}
rswindell's avatar
rswindell committed
241
			else if(!strnicmp(str+i,"BPS",3)) {
242
				artype=AR_BPS;
243 244
				i+=2; 
			}
rswindell's avatar
rswindell committed
245
			else if(!strnicmp(str+i,"PCR",3)) {
246
				artype=AR_PCR;
247 248
				i+=2; 
			}
rswindell's avatar
rswindell committed
249
			else if(!strnicmp(str+i,"SEX",3)) {
250
				artype=AR_SEX;
251 252
				i+=2; 
			}
rswindell's avatar
rswindell committed
253
			else if(!strnicmp(str+i,"UDR",3)) {
254
				artype=AR_UDR;
255 256
				i+=2; 
			}
rswindell's avatar
rswindell committed
257 258
			else if(!strnicmp(str+i,"ULS",3)) {
				artype=AR_ULS;
259 260
				i+=2; 
			}
261 262
			else if(!strnicmp(str+i,"ULK",3)) {
				artype=AR_ULK;
263 264
				i+=2; 
			}
265 266
			else if(!strnicmp(str+i,"ULM",3)) {
				artype=AR_ULM;
267 268
				i+=2; 
			}
rswindell's avatar
rswindell committed
269 270
			else if(!strnicmp(str+i,"DLS",3)) {
				artype=AR_DLS;
271 272
				i+=2; 
			}
273 274
			else if(!strnicmp(str+i,"DLK",3)) {
				artype=AR_DLK;
275 276
				i+=2; 
			}
277 278
			else if(!strnicmp(str+i,"DLM",3)) {
				artype=AR_DLM;
279 280
				i+=2; 
			}
rswindell's avatar
rswindell committed
281
			else if(!strnicmp(str+i,"DAY",3)) {
282
				artype=AR_DAY;
283 284
				i+=2; 
			}
rswindell's avatar
rswindell committed
285
			else if(!strnicmp(str+i,"RIP",3)) {
286
				artype=AR_RIP;
287 288
				i+=2; 
			}
rswindell's avatar
rswindell committed
289
			else if(!strnicmp(str+i,"WIP",3)) {
290
				artype=AR_WIP;
291 292
				i+=2; 
			}
rswindell's avatar
rswindell committed
293
			else if(!strnicmp(str+i,"OS2",3)) {
294
				artype=AR_OS2;
295 296
				i+=2; 
			}
rswindell's avatar
rswindell committed
297
			else if(!strnicmp(str+i,"DOS",3)) {
298
				artype=AR_DOS;
299 300
				i+=2; 
			}
rswindell's avatar
rswindell committed
301
			else if(!strnicmp(str+i,"WIN32",5)) {
302
				artype=AR_WIN32;
303 304
				i+=4; 
			}
rswindell's avatar
rswindell committed
305
			else if(!strnicmp(str+i,"UNIX",4)) {
306
				artype=AR_UNIX;
307 308
				i+=3; 
			}
rswindell's avatar
rswindell committed
309
			else if(!strnicmp(str+i,"LINUX",5)) {
310
				artype=AR_LINUX;
311 312
				i+=4; 
			}
313 314
			else if(!strnicmp(str+i,"PROT",4)) {
				artype=AR_PROT;
315 316
				i+=3; 
			}
rswindell's avatar
rswindell committed
317 318 319 320 321 322 323 324
			else if(!strnicmp(str+i,"HOST",4)) {
				artype=AR_HOST;
				i+=3; 
			}
			else if(!strnicmp(str+i,"IP",2)) {
				artype=AR_IP;
				i++; 
			}
rswindell's avatar
rswindell committed
325
			else if(!strnicmp(str+i,"SUBCODE",7)) {
326
				artype=AR_SUBCODE;
327 328
				i+=6; 
			}
rswindell's avatar
rswindell committed
329
			else if(!strnicmp(str+i,"SUB",3)) {
330
				artype=AR_SUB;
331 332
				i+=2; 
			}
rswindell's avatar
rswindell committed
333
			else if(!strnicmp(str+i,"LIB",3)) {
334
				artype=AR_LIB;
335 336
				i+=2; 
			}
rswindell's avatar
rswindell committed
337
			else if(!strnicmp(str+i,"DIRCODE",7)) {
338
				artype=AR_DIRCODE;
339 340
				i+=6; 
			}
rswindell's avatar
rswindell committed
341
			else if(!strnicmp(str+i,"DIR",3)) {
342
				artype=AR_DIR;
343 344
				i+=2; 
			}
rswindell's avatar
rswindell committed
345
			else if(!strnicmp(str+i,"ANSI",4)) {
346
				artype=AR_ANSI;
347 348
				i+=3; 
			}
rswindell's avatar
rswindell committed
349 350 351 352
			else if(!strnicmp(str+i,"PETSCII",7)) {
				artype=AR_PETSCII;
				i+=6; 
			}
353 354 355 356 357 358 359 360 361 362 363 364
			else if(!strnicmp(str+i,"ASCII",5)) {
				artype=AR_ASCII;
				i+=4; 
			}
			else if(!strnicmp(str+i,"UTF8",4)) {
				artype=AR_UTF8;
				i+=3; 
			}
			else if(!strnicmp(str+i,"CP437",5)) {
				artype=AR_CP437;
				i+=4; 
			}
rswindell's avatar
rswindell committed
365 366 367 368 369 370 371 372 373 374 375 376
			else if(!strnicmp(str+i,"TERM",4)) {
				artype=AR_TERM;
				i+=3; 
			}
			else if(!strnicmp(str+i,"COLS",4)) {
				artype=AR_COLS;
				i+=3; 
			}
			else if(!strnicmp(str+i,"ROWS",4)) {
				artype=AR_ROWS;
				i+=3; 
			}
rswindell's avatar
rswindell committed
377
			else if(!strnicmp(str+i,"UDFR",4)) {
378
				artype=AR_UDFR;
379 380
				i+=3; 
			}
rswindell's avatar
rswindell committed
381
			else if(!strnicmp(str+i,"FLAG",4)) {
382
				artype=AR_FLAG1;
383 384
				i+=3; 
			}
rswindell's avatar
rswindell committed
385
			else if(!strnicmp(str+i,"NODE",4)) {
386
				artype=AR_NODE;
387 388
				i+=3; 
			}
rswindell's avatar
rswindell committed
389
			else if(!strnicmp(str+i,"NULL",4)) {
390
				artype=AR_NULL;
391 392
				i+=3; 
			}
rswindell's avatar
rswindell committed
393
			else if(!strnicmp(str+i,"USER",4)) {
394
				artype=AR_USER;
395 396
				i+=3; 
			}
rswindell's avatar
rswindell committed
397
			else if(!strnicmp(str+i,"TIME",4)) {
398
				artype=AR_TIME;
399 400
				i+=3; 
			}
rswindell's avatar
rswindell committed
401
			else if(!strnicmp(str+i,"REST",4)) {
402
				artype=AR_REST;
403 404
				i+=3; 
			}
rswindell's avatar
rswindell committed
405
			else if(!strnicmp(str+i,"LEVEL",5)) {
406
				artype=AR_LEVEL;
407 408
				i+=4; 
			}
rswindell's avatar
rswindell committed
409
			else if(!strnicmp(str+i,"TLEFT",5)) {
410
				artype=AR_TLEFT;
411 412
				i+=4; 
			}
rswindell's avatar
rswindell committed
413
			else if(!strnicmp(str+i,"TUSED",5)) {
414
				artype=AR_TUSED;
415 416
				i+=4; 
			}
rswindell's avatar
rswindell committed
417
			else if(!strnicmp(str+i,"LOCAL",5)) {
418
				artype=AR_LOCAL;
419 420
				i+=4; 
			}
rswindell's avatar
rswindell committed
421
			else if(!strnicmp(str+i,"GROUP",5)) {
422
				artype=AR_GROUP;
423 424
				i+=4; 
			}
rswindell's avatar
rswindell committed
425
			else if(!strnicmp(str+i,"EXPIRE",6)) {
426
				artype=AR_EXPIRE;
427 428
				i+=5; 
			}
429 430
			else if(!strnicmp(str+i,"ACTIVE",6)) {
				artype=AR_ACTIVE;
431 432
				i+=5; 
			}
433 434
			else if(!strnicmp(str+i,"INACTIVE",8)) {
				artype=AR_INACTIVE;
435 436
				i+=7; 
			}
437 438
			else if(!strnicmp(str+i,"DELETED",7)) {
				artype=AR_DELETED;
439 440
				i+=6; 
			}
rswindell's avatar
rswindell committed
441
			else if(!strnicmp(str+i,"EXPERT",6)) {
442
				artype=AR_EXPERT;
443 444
				i+=5; 
			}
rswindell's avatar
rswindell committed
445
			else if(!strnicmp(str+i,"SYSOP",5)) {
446
				artype=AR_SYSOP;
447 448
				i+=4; 
			}
449 450
			else if(!strnicmp(str+i,"GUEST",5)) {
				artype=AR_GUEST;
451 452
				i+=4; 
			}
453 454
			else if(!strnicmp(str+i,"QNODE",5)) {
				artype=AR_QNODE;
455 456
				i+=4; 
			}
rswindell's avatar
rswindell committed
457
			else if(!strnicmp(str+i,"QUIET",5)) {
458
				artype=AR_QUIET;
459 460
				i+=4; 
			}
rswindell's avatar
rswindell committed
461
			else if(!strnicmp(str+i,"EXEMPT",6)) {
462
				artype=AR_EXEMPT;
463 464
				i+=5; 
			}
rswindell's avatar
rswindell committed
465
			else if(!strnicmp(str+i,"RANDOM",6)) {
466
				artype=AR_RANDOM;
467 468
				i+=5; 
			}
rswindell's avatar
rswindell committed
469
			else if(!strnicmp(str+i,"LASTON",6)) {
470
				artype=AR_LASTON;
471 472
				i+=5; 
			}
rswindell's avatar
rswindell committed
473
			else if(!strnicmp(str+i,"LOGONS",6)) {
474
				artype=AR_LOGONS;
475 476
				i+=5; 
			}
rswindell's avatar
rswindell committed
477
			else if(!strnicmp(str+i,"CREDIT",6)) {
478
				artype=AR_CREDIT;
479 480
				i+=5; 
			}
rswindell's avatar
rswindell committed
481
			else if(!strnicmp(str+i,"MAIN_CMDS",9)) {
482
				artype=AR_MAIN_CMDS;
483 484
				i+=8; 
			}
rswindell's avatar
rswindell committed
485
			else if(!strnicmp(str+i,"FILE_CMDS",9)) {
486
				artype=AR_FILE_CMDS;
487 488
				i+=8; 
			}
489 490
			else if(!strnicmp(str+i,"SHELL",5)) {
				artype=AR_SHELL;
491 492
				i+=4; 
			}
493 494 495 496 497 498 499 500

			if(n!=i)		/* one of the above */
			{
				arg_expected=TRUE;
				switch(artype) {
					case AR_RIP:
					case AR_WIP:
					case AR_ANSI:
rswindell's avatar
rswindell committed
501
					case AR_PETSCII:
502 503 504
					case AR_ASCII:
					case AR_UTF8:
					case AR_CP437:
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
					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;
				}
528
				continue; 
529
			}
530
		}
531 532
		if(not)
			ar[j++]=AR_NOT;
533
		if(equal && !ar_string_arg(artype))
534 535 536
			ar[j++]=AR_EQUAL;
		not=equal=0;

537
		if(artype==AR_FLAG1 && IS_DIGIT(str[i])) {   /* flag set specified */
538 539 540 541 542 543 544 545 546
			switch(str[i]) {
				case '2':
					artype=AR_FLAG2;
					break;
				case '3':
					artype=AR_FLAG3;
					break;
				case '4':
					artype=AR_FLAG4;
547 548 549 550
					break; 
			}
			continue; 
		}
551

552 553
		arg_expected=FALSE;

554
		if(artype==AR_SUB && !IS_DIGIT(str[i]))
555
			artype=AR_SUBCODE;
556
		if(artype==AR_DIR && !IS_DIGIT(str[i]))
557 558
			artype=AR_DIRCODE;

559 560
		if(artype==AR_INVALID)
			artype=AR_LEVEL;
561
		ar[j++]=artype;
562
		if(IS_DIGIT(str[i]) && !ar_string_arg(artype)) {
563 564 565 566 567 568 569
			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;
570
				while(IS_DIGIT(str[i+1]) || str[i+1]==':') i++;
571 572
				continue; 
			}
573 574 575 576 577
			n=atoi(str+i);
			switch(artype) {
				case AR_DAY:
					if(n>6)     /* not past saturday */
						n=6;
578
					// fall-through
579 580 581 582
				case AR_AGE:    /* byte operands */
				case AR_PCR:
				case AR_UDR:
				case AR_UDFR:
rswindell's avatar
rswindell committed
583 584
				case AR_ROWS:
				case AR_COLS:
585 586 587 588 589 590 591 592 593
				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;
594
					// fall-through
595 596 597 598 599 600 601 602
				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:
rswindell's avatar
rswindell committed
603
				case AR_ULS:
604 605
				case AR_ULK:
				case AR_ULM:
rswindell's avatar
rswindell committed
606
				case AR_DLS:
607 608
				case AR_DLK:
				case AR_DLM:
609
					*((short *)(ar+j))=n;
610
					j+=sizeof(short);
611 612 613 614 615 616 617 618 619 620 621
					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--;
622 623
					break; 
			}
624
			while(IS_DIGIT(str[i+1])) i++;
625 626
			continue; 
		}
627
		maxlen=128;
628
		switch(artype) {
629 630 631 632
			case AR_SUBCODE:
			case AR_DIRCODE:
			case AR_SHELL:
				maxlen=LEN_EXTCODE;
633
				// fall-through
634 635 636
			case AR_PROT:
			case AR_HOST:
			case AR_IP:
rswindell's avatar
rswindell committed
637
			case AR_TERM:
638 639 640 641 642 643 644 645 646 647 648 649 650 651
				/* String argument */
				for(n=0;n<maxlen
					&& str[i]
					&& str[i]!=' '
					&& str[i]!='('
					&& str[i]!=')'
					&& str[i]!='='
					&& str[i]!='|'
					&& str[i]!='&'
					;n++)
					ar[j++]=toupper(str[i++]);
				ar[j++]=0;
				i--;
				break;
652 653 654 655 656 657 658
			case AR_FLAG1:
			case AR_FLAG2:
			case AR_FLAG3:
			case AR_FLAG4:
			case AR_EXEMPT:
			case AR_SEX:
			case AR_REST:
rswindell's avatar
rswindell committed
659
				ar[j++]=toupper(str[i]);
660 661
				break;
			case AR_SUB:
662
				for(n=0;n<(uint)cfg->total_subs;n++)
663 664
					if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code)))
						break;
665
				if(n<(uint)cfg->total_subs) {
666
					*((short *)(ar+j))=n;
667 668
					j+=2; 
				}
669 670
				else        /* Unknown sub-board */
					j--;
671
				while(IS_ALPHA(str[i+1])) i++;
672 673
				break;
			case AR_DIR:
674
				for(n=0;n<(uint)cfg->total_dirs;n++)
675 676
					if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code)))
						break;
677
				if(n<(uint)cfg->total_dirs) {
678
					*((short *)(ar+j))=n;
679 680
					j+=2; 
				}
681 682
				else        /* Unknown directory */
					j--;
683
				while(IS_ALPHA(str[i+1])) i++;
684 685
				break;
			case AR_DAY:
rswindell's avatar
rswindell committed
686 687
				if(toupper(str[i])=='S' 
					&& toupper(str[i+1])=='U')				/* Sunday */
688
					ar[j++]=0;
rswindell's avatar
rswindell committed
689
				else if(toupper(str[i])=='M')               /* Monday */
690
					ar[j++]=1;
rswindell's avatar
rswindell committed
691 692
				else if(toupper(str[i])=='T' 
					&& toupper(str[i+1])=='U')				/* Tuesday */
693
					ar[j++]=2;
rswindell's avatar
rswindell committed
694
				else if(toupper(str[i])=='W')               /* Wednesday */
695
					ar[j++]=3;
rswindell's avatar
rswindell committed
696 697
				else if(toupper(str[i])=='T' 
					&& toupper(str[i+1])=='H')				/* Thursday */
698
					ar[j++]=4;
rswindell's avatar
rswindell committed
699
				else if(toupper(str[i])=='F')               /* Friday */
700 701
					ar[j++]=5;
				else ar[j++]=6;                             /* Saturday */
702
				while(IS_ALPHA(str[i+1])) i++;
703 704 705 706 707 708 709 710
				break;
			default:	/* Badly formed ARS, digit expected */
				j--;
				break;
		} 
	}

	ar[j++]=AR_NULL;
711 712 713 714 715 716
	if(ar_buf == NULL) {
		if((ar_buf=(uchar *)calloc(j+4,1))==NULL) {	/* Padded for ushort dereferencing */
			if(count)
				(*count)=0;
			return(NULL);
		}
717
	}
718 719 720 721 722 723
	memcpy(ar_buf,ar,j);
	if(count)
		(*count)=j;
	return(ar_buf);
}

724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
#ifdef ARS_VERIFY	/* Verification for arstr() */

char *decompile_ars(uchar *ars, int len)
{
	static char	buf[1024];
	char	*out;
	uchar	*in;
	uint	n;
	int		equals=0;
	int		not=0;

	out=buf;
	buf[0]=0;
	for(in=ars;in<ars+len;in++) {
		switch(*in) {
			case AR_NULL:
				break;
			case AR_OR:
				*(out++)='|';
				
				break;
			case AR_NOT:
				not=1;
				break;
			case AR_EQUAL:
				equals=1;
				break;
			case AR_BEGNEST:
				if(not)
					*(out++)='!';
				not=0;
				*(out++)='(';
				
				break;
			case AR_ENDNEST:
				*(out++)=')';
				
				break;
			case AR_LEVEL:
				*(out++)='$';
				*(out++)='L';
				
				break;
			case AR_AGE:
				*(out++)='$';
				*(out++)='A';
				
				break;
			case AR_BPS:
				*(out++)='$';
				*(out++)='B';
				
				break;
			case AR_NODE:
				*(out++)='$';
				*(out++)='N';
				
				break;
			case AR_TLEFT:
				*(out++)='$';
				*(out++)='R';
				
				break;
			case AR_TUSED:
				*(out++)='$';
				*(out++)='O';
				
				break;
			case AR_USER:
				*(out++)='$';
				*(out++)='U';
				
				break;
			case AR_TIME:
				*(out++)='$';
				*(out++)='T';
				
				break;
			case AR_PCR:
				*(out++)='$';
				*(out++)='P';
				
				break;
			case AR_FLAG1:
				*(out++)='$';
				*(out++)='F';
				*(out++)='1';
				
				break;
			case AR_FLAG2:
				*(out++)='$';
				*(out++)='F';
				*(out++)='2';
				
				break;
			case AR_FLAG3:
				*(out++)='$';
				*(out++)='F';
				*(out++)='3';
				
				break;
			case AR_FLAG4:
				*(out++)='$';
				*(out++)='F';
				*(out++)='4';
				
				break;
			case AR_EXEMPT:
				*(out++)='$';
				*(out++)='X';
				
				break;
			case AR_REST:
				*(out++)='$';
				*(out++)='Z';
				
				break;
			case AR_SEX:
				*(out++)='$';
				*(out++)='S';
				
				break;
			case AR_UDR:
				*(out++)='$';
				*(out++)='K';
				
				break;
			case AR_UDFR:
				*(out++)='$';
				*(out++)='D';
				
				break;
			case AR_EXPIRE:
				*(out++)='$';
				*(out++)='E';
				
				break;
			case AR_CREDIT:
				*(out++)='$';
				*(out++)='C';
				
				break;
			case AR_DAY:
				*(out++)='$';
				*(out++)='W';
				
				break;
			case AR_ANSI:
				if(not)
					*(out++)='!';
				not=0;
				*(out++)='$';
				*(out++)='[';
				
				break;
			case AR_RIP:
				if(not)
					*(out++)='!';
				not=0;
				*(out++)='$';
				*(out++)='*';
				
				break;
			case AR_LOCAL:
				if(not)
					*(out++)='!';
				not=0;
				*(out++)='$';
				*(out++)='G';
				
				break;
			case AR_GROUP:
				*(out++)='$';
				*(out++)='M';
				
				break;
			case AR_SUB:
				*(out++)='$';
				*(out++)='H';
				
				break;
			case AR_LIB:
				*(out++)='$';
				*(out++)='I';
				
				break;
			case AR_DIR:
				*(out++)='$';
				*(out++)='J';
				
				break;
			case AR_EXPERT :
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"EXPERT");
				out=strchr(out,0);
				
				break;
			case AR_SYSOP:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"SYSOP");
				out=strchr(out,0);
				
				break;
			case AR_QUIET:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"QUIET");
				out=strchr(out,0);
				
				break;
			case AR_MAIN_CMDS:
				*out=0;
				strcat(out,"MAIN_CMDS");
				out=strchr(out,0);
				
				break;
			case AR_FILE_CMDS:
				*out=0;
				strcat(out,"FILE_CMDS");
				out=strchr(out,0);
				
				break;
			case AR_RANDOM:
				*(out++)='$';
				*(out++)='Q';
				
				break;
			case AR_LASTON:
				*(out++)='$';
				*(out++)='Y';
				
				break;
			case AR_LOGONS:
				*(out++)='$';
				*(out++)='V';
				
				break;
			case AR_WIP:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"WIP");
				out=strchr(out,0);
				
				break;
			case AR_SUBCODE:
				*out=0;
				strcat(out,"SUB ");
				out=strchr(out,0);
				
				break;
			case AR_DIRCODE:
				*out=0;
				strcat(out,"DIR ");
				out=strchr(out,0);
				
				break;
			case AR_OS2:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"OS2");
				out=strchr(out,0);
				
				break;
			case AR_DOS:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"DOS");
				out=strchr(out,0);
				
				break;
			case AR_WIN32:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"WIN32");
				out=strchr(out,0);
				
				break;
			case AR_UNIX:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"UNIX");
				out=strchr(out,0);
				
				break;
			case AR_LINUX :
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"LINUX");
				out=strchr(out,0);
				
				break;
			case AR_SHELL:
				*out=0;
				strcat(out,"SHELL ");
				out=strchr(out,0);
				
				break;
			case AR_PROT:
				*out=0;
				strcat(out,"PROT ");
				out=strchr(out,0);
				
				break;
			case AR_HOST:
				*out=0;
				strcat(out,"HOST ");
				out=strchr(out,0);
				
				break;
			case AR_IP:
				*out=0;
				strcat(out,"IP ");
				out=strchr(out,0);
				
				break;
			case AR_GUEST:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"GUEST");
				out=strchr(out,0);
				
				break;
			case AR_QNODE:
				if(not)
					*(out++)='!';
				not=0;
				*out=0;
				strcat(out,"QNODE");
				out=strchr(out,0);
				
				break;
			default:
				printf("Error decoding AR: %02Xh, offset: %u\n", *in, in-ars);
				return("Unknown ARS String");
		}
		switch(*in) {
			case AR_TIME:
				if(not)
					*(out++)='!';
				if(equals)
					*(out++)='=';
				not=equals=0;
				in++;
				n=*((short *)in);
				in++;
				out+=sprintf(out,"%02d:%02d",n/60,n%60);
				break;
			case AR_AGE:    /* byte operands */
			case AR_PCR:
			case AR_UDR:
			case AR_UDFR:
			case AR_NODE:
rswindell's avatar
rswindell committed
1098 1099
			case AR_ROWS:
			case AR_COLS:
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
			case AR_LEVEL:
			case AR_TLEFT:
			case AR_TUSED:
				if(not)
					*(out++)='!';
				if(equals)
					*(out++)='=';
				not=equals=0;
				in++;
				out+=sprintf(out,"%d",*in);
				break;
			case AR_BPS:    /* int operands */
			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:
				if(not)
					*(out++)='!';
				if(equals)
					*(out++)='=';
				not=equals=0;
				in++;
    			n=*((short *)in);
				in++;
				out+=sprintf(out,"%d",n);
    			break;
			case AR_GROUP:
			case AR_LIB:
			case AR_DIR:
			case AR_SUB:
				if(not)
					*(out++)='!';
				if(equals)
					*(out++)='=';
				not=equals=0;
				in++;
    			n=*((short *)in);
				n++;              /* convert from to 0 base */
				in++;
				out+=sprintf(out,"%d",n);
    			break;
			case AR_SUBCODE:
			case AR_DIRCODE:
			case AR_SHELL:
			case AR_PROT:
			case AR_HOST:
			case AR_IP:
rswindell's avatar
rswindell committed
1151
			case AR_TERM:
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 <