File: checks.cpp

package info (click to toggle)
bayonne 2.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 11,180 kB
  • ctags: 3,662
  • sloc: cpp: 38,791; sh: 9,323; ansic: 1,391; makefile: 485; perl: 471; java: 405; cs: 402; php: 354; python: 293
file content (777 lines) | stat: -rw-r--r-- 17,036 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
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
// Copyright (C) 2005 Open Source Telecom Corp.
//  
// 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.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "server.h"

namespace server {
using namespace ost;
using namespace std;

const char *Checks::chkSay(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	if(getMember(line))
		return "say has no members";

	if(!getOption(line, &idx))
		return "say requires at least one argument";

	if(!useKeywords(line, "=file=voice=prefix=extension"))
		return "invalid keywords for say";

	return NULL;
}		

const char *Checks::chkService(Line *line, ScriptImage *img)
{
	char buffer[80];
	unsigned idx = 0;
	const char *cp = getOption(line, &idx);

	if(getMember(line))
		return "service has no members";

	if(!cp)
		return "service requires name";

	if(getOption(line, &idx))
		return "service uses one name only";

	snprintf(buffer, sizeof(buffer), "service.%s", cp);
	line->scr.name = img->getCurrent();
	line->cmd = line->scr.name->name;
	img->setPointer(buffer, line);
	return "";
}

const char *Checks::chkParam(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "param has no members";

	if(line->argc < 1)
		return "param requires at least one keyword pair";

	if(getOption(line, &idx))
		return "param uses only keyword pairs";

	return NULL;
}

const char *Checks::chkId(Line *line, ScriptImage *img)
{
	const char *cp = getMember(line);
	unsigned idx = 0;

	if(cp)
	{
		if(!stricmp(cp, "contact"))
			goto use;
		if(!strnicmp(cp, "host", 4))
			goto use;
		if(!stricmp(cp, "uniq"))
			goto use;
		if(!strnicmp(cp, "base", 4))
			goto use;
		if(!strnicmp(cp, "dtmf", 4))
			goto use;
	
		return "id may use .contact, .base, .uniq, .dtmf, or .host only";
	}
use:
	if(!useKeywords(line, "=prefix=extension=size=id=idprefix"))
		return "id keyword invalid";

	while(NULL != (cp = getOption(line, &idx)))
	{
		if(*cp != '%' && *cp != '&')
			return "arguments must be symbol";
	}
	return NULL;
}		

const char *Checks::chkDetach(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "detach has no members";

	if(!getOption(line, &idx))
		return "detach requires at least command argument";

	return NULL;
}

const char *Checks::chkReconnect(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	if(!useKeywords(line, "=encoding=framing"))
		return "invalid keyword used for reconnect";

	if(getOption(line, &idx))
		return "no arguments for reconnect";

	return NULL;
}

const char *Checks::chkExit(Line *line, ScriptImage *img)
{
	if(getMember(line))
		return "exit has no members";

	if(line->argc > 1)
		return "exit only has one reason argument";

	return NULL;
}

const char *Checks::chkPaths(Line *line, ScriptImage *img)
{	
	unsigned idx = 0;
	const char *cp;

	if(getMember(line))
		return "paths do not use members";

	if(!strnicmp(line->cmd, "read", 4))
	{
		if(!useKeywords(line, "=prefix=voice=extension"))
			return "invalid keywords used for path";
	}	
	else if(!useKeywords(line, "=prefix=extension"))
		return "invalid keywords used for path";

	cp = getOption(line, &idx);
	if(!cp || (*cp != '%' && *cp != '&'))
		return "invalid or missing variable target";

	if(!getOption(line, &idx))
		return "missing path to evaluate";

	return NULL;
}

const char *Checks::chkTrap(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "trap uses no members";

	if(!useKeywords(line, "=id=text"))
		return "invalid keyword, use id and text";

	if(getOption(line, &idx))
		return "no options are passed for trap";	

	return NULL;
}

const char *Checks::chkChildSignal(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "signal uses no members";

	if(hasKeywords(line))
		return "signal has no keywords";

	if(getOption(line, &idx))
		return "signal has no arguments";

	return NULL;
}

const char *Checks::chkTransfer(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "transfer has no members";

	if(!useKeywords(line, "=prefix=server"))
		return "invalid keyword used";

	if(!getOption(line, &idx))
		return "transfer destination required";

	return NULL;
}

const char *Checks::chkDialer(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "dialers have no members";

	if(!useKeywords(line, "=interdigit=level=prefix"))
		return "unknown keyword for dialers";

	if(!getOption(line, &idx))
		return "no dial string argument";

	return NULL;
}

const char *Checks::chkTonegen(Line *line, ScriptImage *img)
{
	const char *cp;

	if(getMember(line))
		return "tone has no members";

	if(!useKeywords(line, "=level=freq1=freq2=frequency=duration"))
		return "unknown keyword for tone";

	cp = findKeyword(line, "frequency");
	if(!cp)
		cp = findKeyword(line, "freq1");

	if(!cp)
		return "no tone frequency specified";

	return NULL;
}	

const char *Checks::chkTone(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "tone has no members";

	if(!useKeywords(line, "=location=timeout=level=name"))
		return "unknown keyword for a tone";

	if(getOption(line, &idx))
		return "no arguments used for tones";

	return NULL;
}

const char *Checks::chkList(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	if(getMember(line))
		return "list has no members";

	if(!useKeywords(line, "=prefix=match=extension=after=prior"))
		return "invalid keyword for list";

	cp = getOption(line, &idx);
	if(!cp)
		return "list missing result argument";

	if(*cp != '&' && *cp != '%')
		return "list result argument must be a symbol";

	if(!getOption(line, &idx))
		return "list missing directory argument";

	return NULL;
}

const char *Checks::chkDir(Line *line, ScriptImage *img)
{
	unsigned count = 0;
	const char *cp;
	char path[MAX_PATHNAME];

	if(getMember(line))
		return "dir has no members";

	if(hasKeywords(line))
		return "dir has no keywords";

	if(!line->argc)
		return "dir requires at least one prefix";

	while(NULL != (cp = getOption(line, &count)))
	{
		if(!isalnum(*cp))
			return "invalid directory name used";

		if(strstr(cp, ".."))
			return "invalid directory name used";

		if(strstr(cp, "/."))
			return "invalid directory name used";

		if(strchr(cp, ':'))
			return "invalid directory name used";

		snprintf(path, sizeof(path), "%s/%s", keypaths.getLast("datafiles"), cp);
		Dir::create(path);		
	}
	return "";
}

const char *Checks::chkLang(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	if(getMember(line))
		return "lang has no members";

	if(hasKeywords(line))
		return "lang has no keywords";

	while(NULL != (cp = getOption(line, &idx)))
		BayonneTranslator::loadTranslator(cp);
		
	return "";
}

const char *Checks::chkLoad(Line *line, ScriptImage *img)
{
	unsigned count = 0;
	const char *cp;

	if(getMember(line))
		return "load has no members";

	if(hasKeywords(line))
		return "load has no keywords";

	if(!line->argc)
		return "load requires at least one module";

	while(count < line->argc)
	{ 
		cp = line->args[count++];
		if(!isalpha(*cp))
			return "an invalid module name was used";
	}	

	count = 0;
	while(count < line->argc)
	{
		cp = line->args[count++];
		loadPlugin(cp);
	}
	BayonneService::start();
	
	return "";
}	

const char *Checks::chkLibexec(Line *line, ScriptImage *img)
{
	const char *cp = getMember(line);
	unsigned idx = 0;

	if(cp && atoi(cp) < 1)
		return "libexec timeout member must be at least one second";

	if(!strnicmp(line->cmd, "exec", 4))
		goto get;

	cp = getOption(line, &idx);
	if(!cp)
		return "libexec requires command argument";

	if(*cp == '%' || *cp == '&' || *cp == '#')
		return "libexec command must be constant";

	if(strchr(cp, '/') || strchr(cp, '\\'))
		return "libexec command cannot be path";

get:
	while(NULL != (cp = getOption(line, &idx)))
	{
		if(*cp != '%' && *cp != '&' && *cp != '#')
			return "libexec arguments must be variables";
	}

	if(!useKeywords(line, "=token=results=prefix=encoding=framing=voice=extension=timeout=limit=interval"))
		return "invalid keyword used in libexec";

	cp = findKeyword(line, "results");
	if(cp && *cp != '&')
		return "results must be saved into &var reference";

	return NULL;
}

const char *Checks::chkVoicelib(Line *line, ScriptImage *img)
{
	char path[256];
	char lang[64];
	const char *cp;
	char *p;

	if(getMember(line))
		return "voice library has no members";

	if(hasKeywords(line))
		return "voice library has no keywords";

	if(line->argc != 1)
		return "voice library argument must be specified";

	cp = line->args[0];

	if(*cp == '%' || *cp == '#' || *cp == '&')
		return "voice library cannot be variable";

	if(!strchr(cp, '/'))
		return "voice library missing voice";

	if(strchr(cp, '/') != strrchr(cp, '/'))
		return "invalid voice library path";

	if(strchr(cp, '.'))
		return "invalid voice library path";		

	snprintf(path, sizeof(path), "%s/%s", 
		keypaths.getLast("prompts"), cp);

	if(!stricmp(line->cmd, "voicelib"))
	{
		setString((char *)line->cmd, 9, cp);
		p = (char *)strchr(line->cmd, '/');
		if(p)
			*p = 0;
	}

	if(isDir(path))
		return NULL;

	if(cp[2] != '_')
		return "invalid voice library";

	lang[0] = cp[0];
	lang[1] = cp[1];
	cp = strchr(cp, '/');
	snprintf(lang + 2, sizeof(lang) - 2, "%s", cp);
	snprintf(path, sizeof(path), "%s/%s",
		keypaths.getLast("prompts"), lang);

	if(!isDir(path))
		return "unknown voice library";
	
	strcpy((char *)line->args[0], lang);
	
	return NULL;
}

const char *Checks::chkErase(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "erase has no members";

	if(!useKeywords(line, "=extension=prefix"))
		return "invalid keyword for erase";

	if(!getOption(line, &idx))
		return "erase requires file argument";

	if(getOption(line, &idx))
		return "erase uses only one file argument";
	
	return NULL;
}	

const char *Checks::chkInfo(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	if(getMember(line))
		return "erase has no members";

	if(!useKeywords(line, 
"=extension=prefix=date=time=note=size=type=coding=rate=bitrate=count"))
		return "invalid keyword for info";

	cp = findKeyword(line, "date");
	if(cp && *cp != '%' && *cp != '&')
		return "info date must be symbol target";

	cp = findKeyword(line, "time");
	if(cp && *cp != '%' && *cp != '&')
		return "info time must be symbol target";

	cp = findKeyword(line, "size");
	if(cp && *cp != '%' && *cp != '&')
		return "info size must be symbol target";

	cp = findKeyword(line, "coding");
	if(cp && *cp != '%' && *cp != '&')
		return "info coding must be symbol target";

	cp = findKeyword(line, "type");
        if(cp && *cp != '%' && *cp != '&')
                return "info type must be symbol target";

        cp = findKeyword(line, "rate");
        if(cp && *cp != '%' && *cp != '&')
                return "info rate must be symbol target";  

        cp = findKeyword(line, "bitrate");
        if(cp && *cp != '%' && *cp != '&')
                return "info bitrate must be symbol target";  

        cp = findKeyword(line, "count");
        if(cp && *cp != '%' && *cp != '&')
                return "info count must be symbol target";  

        cp = findKeyword(line, "note");
        if(cp && *cp != '%' && *cp != '&')
                return "info note must be symbol target";

	if(!getOption(line, &idx))
		return "info requires file argument";

	if(getOption(line, &idx))
		return "info uses only one file argument";
	
	return NULL;
}	

const char *Checks::chkWrite(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "write has no members";

	if(!useKeywords(line, "=extension=prefix"))
		return "invalid keywords for write";

	if(!getOption(line, &idx))
		return "file missing for write";

	return NULL;
}

const char *Checks::chkMove(Line *line, ScriptImage *img)
{
	unsigned idx = 0;

	if(getMember(line))
		return "command has no members";

	if(!useKeywords(line, "=extension=prefix"))
		return "invalid keyword for this command";

	if(!getOption(line, &idx))
		return "source argument missing";

	if(!getOption(line, &idx))
		return "target argument missing";

	if(getOption(line, &idx))
		return "only two arguments used";
	
	return NULL;
}	

const char *Checks::chkBuild(Line *line, ScriptImage *img)
{
        unsigned idx = 0;

	if(getMember(line))
		return "member not used in build";

	if(!useKeywords(line, "=extension=encoding=framing=prefix=voice=note"))
		return "invalid keyword for build";


	if(!getOption(line, &idx))
		return "build destination missing";

	if(!getOption(line, &idx))
		return "build requires at least one file source";	

	return NULL;
}

const char *Checks::chkRecord(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	cp = getMember(line);
	if(cp && stricmp(cp, "vox"))
		return "use no member or .vox only";

	if(!useKeywords(line, "=extension=encoding=prefix=framing=silence=intersilence=note=position=exit=timeout=menu"))
		return "invalid keyword used";

	if(!getOption(line, &idx))
		return "requires one file argument";

	if(getOption(line, &idx) && getOption(line, &idx))
		return "uses only up to two file argument";

	return NULL;
}

const char *Checks::chkReplay(Line *line, ScriptImage *img)
{
        unsigned idx = 0;

        if(getMember(line))
		return "no member used in replay";

        if(!useKeywords(line, "=extension=encoding=prefix=framing=exit=menu=position"))
                return "invalid keyword used for replay";

        if(!getOption(line, &idx))
                return "replay requires one file argument";

        if(getOption(line, &idx))
                return "replay uses only one file argument";

        return NULL;
}

const char *Checks::chkAppend(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	cp = getMember(line);
	if(cp && stricmp(cp, "vox"))
		return "use no member or .vox only";

	if(!useKeywords(line, "=extension=encoding=prefix=framing=silence=intersilence=exit=timeout"))
		return "invalid keyword used";

	if(!getOption(line, &idx))
		return "requires one file argument";

	if(getOption(line, &idx) && getOption(line, &idx))
		return "uses up to two file argument";

	return NULL;
}

const char *Checks::chkPathname(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	
	if(!useKeywords(line, "=extension=voice=encoding=prefix"))
		return "invalid keyword used";

	if(!getOption(line, &idx))
		return "requires at least one prompt argument";

	return NULL;
}		

const char *Checks::chkCollect(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	if(!useKeywords(line, "=count=timeout=lastdigit=interdigit=ignore=exit=format"))
		return "invalid keyword for collect";

	cp = getOption(line, &idx);

	if(cp && *cp != '%' && *cp != '&')
		return "collect argument must be variable";

	return NULL;
}

const char *Checks::chkInput(Line *line, ScriptImage *img)
{
	unsigned idx = 0;
	const char *cp;

	if(getMember(line))
		return "input has no members";

	if(!useKeywords(line, "=count=timeout=interdigit=lastdigit=exit=format"))
		return "invalid keyword for input, use timeout, interdigit, count, format, and exit";

	cp = getOption(line, &idx);	
	if(!cp)
		return "input missing variable argument";

	if(*cp != '%' && *cp != '&')
		return "invalid argument for variable name";

	return NULL;
}

const char *Checks::chkKeyinput(Line *line, ScriptImage *img)
{
	const char *cp;
	unsigned idx = 0;

	if(getMember(line))
		return "inkey has no members";

	if(!useKeywords(line, "=timeout=menu"))
		return "invalid keyword for keyinput, use timeout and menu";

	cp = getOption(line, &idx);
	if(!cp)
		return NULL;

	if(*cp != '%' && *cp != '&')
		return "optional keyinput argument must be variable"; 

	return NULL;
}

const char *Checks::chkCleardigits(Line *line, ScriptImage *img)
{
	if(getMember(line))
		return "cleardigits does not use members";

	if(line->argc > 1)
		return "cleardigits uses one optional timeout";

	return NULL;
}

const char *Checks::chkRoute(Line *line, ScriptImage *img)
{
	if(hasKeywords(line))
		return "no keywords used for digits routing";

	if(!line->argc)
		return "route requires at least one route value";
	
	return NULL;
}

const char *Checks::chkSleep(Line *line, ScriptImage *img)
{
	if(getMember(line))
		return "member not used for this command";

	if(!line->argc || line->argc > 1)
		return "requires one timeout and uses no keywords";

	return NULL;
}

} // end namespace