summaryrefslogtreecommitdiffstats
path: root/contrib/perl5/ext/Sys/Syslog/Syslog.xs
blob: 31c0e845a2de6ad1a25799409614a1545b82deab (plain)
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
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#ifdef I_SYSLOG
#include <syslog.h>
#endif

static double
constant_LOG_NO(char *name, int len)
{
    switch (name[6 + 0]) {
    case 'T':
	if (strEQ(name + 6, "TICE")) {	/* LOG_NO removed */
#ifdef LOG_NOTICE
	    return LOG_NOTICE;
#else
	    goto not_there;
#endif
	}
    case 'W':
	if (strEQ(name + 6, "WAIT")) {	/* LOG_NO removed */
#ifdef LOG_NOWAIT
	    return LOG_NOWAIT;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_N(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'D':
	if (strEQ(name + 5, "DELAY")) {	/* LOG_N removed */
#ifdef LOG_NDELAY
	    return LOG_NDELAY;
#else
	    goto not_there;
#endif
	}
    case 'E':
	if (strEQ(name + 5, "EWS")) {	/* LOG_N removed */
#ifdef LOG_NEWS
	    return LOG_NEWS;
#else
	    goto not_there;
#endif
	}
    case 'F':
	if (strEQ(name + 5, "FACILITIES")) {	/* LOG_N removed */
#ifdef LOG_NFACILITIES
	    return LOG_NFACILITIES;
#else
	    goto not_there;
#endif
	}
    case 'O':
	return constant_LOG_NO(name, len);
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_P(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'I':
	if (strEQ(name + 5, "ID")) {	/* LOG_P removed */
#ifdef LOG_PID
	    return LOG_PID;
#else
	    goto not_there;
#endif
	}
    case 'R':
	if (strEQ(name + 5, "RIMASK")) {	/* LOG_P removed */
#ifdef LOG_PRIMASK
	    return LOG_PRIMASK;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_AU(char *name, int len)
{
    if (6 + 2 >= len ) {
	errno = EINVAL;
	return 0;
    }
    switch (name[6 + 2]) {
    case '\0':
	if (strEQ(name + 6, "TH")) {	/* LOG_AU removed */
#ifdef LOG_AUTH
	    return LOG_AUTH;
#else
	    goto not_there;
#endif
	}
    case 'P':
	if (strEQ(name + 6, "THPRIV")) {	/* LOG_AU removed */
#ifdef LOG_AUTHPRIV
	    return LOG_AUTHPRIV;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_A(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'L':
	if (strEQ(name + 5, "LERT")) {	/* LOG_A removed */
#ifdef LOG_ALERT
	    return LOG_ALERT;
#else
	    goto not_there;
#endif
	}
    case 'U':
	return constant_LOG_AU(name, len);
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_CR(char *name, int len)
{
    switch (name[6 + 0]) {
    case 'I':
	if (strEQ(name + 6, "IT")) {	/* LOG_CR removed */
#ifdef LOG_CRIT
	    return LOG_CRIT;
#else
	    goto not_there;
#endif
	}
    case 'O':
	if (strEQ(name + 6, "ON")) {	/* LOG_CR removed */
#ifdef LOG_CRON
	    return LOG_CRON;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_C(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'O':
	if (strEQ(name + 5, "ONS")) {	/* LOG_C removed */
#ifdef LOG_CONS
	    return LOG_CONS;
#else
	    goto not_there;
#endif
	}
    case 'R':
	return constant_LOG_CR(name, len);
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_D(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'A':
	if (strEQ(name + 5, "AEMON")) {	/* LOG_D removed */
#ifdef LOG_DAEMON
	    return LOG_DAEMON;
#else
	    goto not_there;
#endif
	}
    case 'E':
	if (strEQ(name + 5, "EBUG")) {	/* LOG_D removed */
#ifdef LOG_DEBUG
	    return LOG_DEBUG;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_U(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'S':
	if (strEQ(name + 5, "SER")) {	/* LOG_U removed */
#ifdef LOG_USER
	    return LOG_USER;
#else
	    goto not_there;
#endif
	}
    case 'U':
	if (strEQ(name + 5, "UCP")) {	/* LOG_U removed */
#ifdef LOG_UUCP
	    return LOG_UUCP;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_E(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'M':
	if (strEQ(name + 5, "MERG")) {	/* LOG_E removed */
#ifdef LOG_EMERG
	    return LOG_EMERG;
#else
	    goto not_there;
#endif
	}
    case 'R':
	if (strEQ(name + 5, "RR")) {	/* LOG_E removed */
#ifdef LOG_ERR
	    return LOG_ERR;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_F(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'A':
	if (strEQ(name + 5, "ACMASK")) {	/* LOG_F removed */
#ifdef LOG_FACMASK
	    return LOG_FACMASK;
#else
	    goto not_there;
#endif
	}
    case 'T':
	if (strEQ(name + 5, "TP")) {	/* LOG_F removed */
#ifdef LOG_FTP
	    return LOG_FTP;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_LO(char *name, int len)
{
    if (6 + 3 >= len ) {
	errno = EINVAL;
	return 0;
    }
    switch (name[6 + 3]) {
    case '0':
	if (strEQ(name + 6, "CAL0")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL0
	    return LOG_LOCAL0;
#else
	    goto not_there;
#endif
	}
    case '1':
	if (strEQ(name + 6, "CAL1")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL1
	    return LOG_LOCAL1;
#else
	    goto not_there;
#endif
	}
    case '2':
	if (strEQ(name + 6, "CAL2")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL2
	    return LOG_LOCAL2;
#else
	    goto not_there;
#endif
	}
    case '3':
	if (strEQ(name + 6, "CAL3")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL3
	    return LOG_LOCAL3;
#else
	    goto not_there;
#endif
	}
    case '4':
	if (strEQ(name + 6, "CAL4")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL4
	    return LOG_LOCAL4;
#else
	    goto not_there;
#endif
	}
    case '5':
	if (strEQ(name + 6, "CAL5")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL5
	    return LOG_LOCAL5;
#else
	    goto not_there;
#endif
	}
    case '6':
	if (strEQ(name + 6, "CAL6")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL6
	    return LOG_LOCAL6;
#else
	    goto not_there;
#endif
	}
    case '7':
	if (strEQ(name + 6, "CAL7")) {	/* LOG_LO removed */
#ifdef LOG_LOCAL7
	    return LOG_LOCAL7;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant_LOG_L(char *name, int len)
{
    switch (name[5 + 0]) {
    case 'F':
	if (strEQ(name + 5, "FMT")) {	/* LOG_L removed */
#ifdef LOG_LFMT
	    return LOG_LFMT;
#else
	    goto not_there;
#endif
	}
    case 'O':
	return constant_LOG_LO(name, len);
    case 'P':
	if (strEQ(name + 5, "PR")) {	/* LOG_L removed */
#ifdef LOG_LPR
	    return LOG_LPR;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}

static double
constant(char *name, int len)
{
    errno = 0;
    if (0 + 4 >= len ) {
	errno = EINVAL;
	return 0;
    }
    switch (name[0 + 4]) {
    case 'A':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_A(name, len);
    case 'C':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_C(name, len);
    case 'D':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_D(name, len);
    case 'E':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_E(name, len);
    case 'F':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_F(name, len);
    case 'I':
	if (strEQ(name + 0, "LOG_INFO")) {	/*  removed */
#ifdef LOG_INFO
	    return LOG_INFO;
#else
	    goto not_there;
#endif
	}
    case 'K':
	if (strEQ(name + 0, "LOG_KERN")) {	/*  removed */
#ifdef LOG_KERN
	    return LOG_KERN;
#else
	    goto not_there;
#endif
	}
    case 'L':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_L(name, len);
    case 'M':
	if (strEQ(name + 0, "LOG_MAIL")) {	/*  removed */
#ifdef LOG_MAIL
	    return LOG_MAIL;
#else
	    goto not_there;
#endif
	}
    case 'N':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_N(name, len);
    case 'O':
	if (strEQ(name + 0, "LOG_ODELAY")) {	/*  removed */
#ifdef LOG_ODELAY
	    return LOG_ODELAY;
#else
	    goto not_there;
#endif
	}
    case 'P':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_P(name, len);
    case 'S':
	if (strEQ(name + 0, "LOG_SYSLOG")) {	/*  removed */
#ifdef LOG_SYSLOG
	    return LOG_SYSLOG;
#else
	    goto not_there;
#endif
	}
    case 'U':
	if (!strnEQ(name + 0,"LOG_", 4))
	    break;
	return constant_LOG_U(name, len);
    case 'W':
	if (strEQ(name + 0, "LOG_WARNING")) {	/*  removed */
#ifdef LOG_WARNING
	    return LOG_WARNING;
#else
	    goto not_there;
#endif
	}
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}


MODULE = Sys::Syslog		PACKAGE = Sys::Syslog		

char *
_PATH_LOG()
    CODE:
#ifdef _PATH_LOG
	RETVAL = _PATH_LOG;
#else
	RETVAL = "";
#endif
    OUTPUT:
	RETVAL

int
LOG_FAC(p)
    INPUT:
	int		p
    CODE:
#ifdef LOG_FAC
	RETVAL = LOG_FAC(p);
#else
	croak("Your vendor has not defined the Sys::Syslog macro LOG_FAC");
	RETVAL = -1;
#endif
    OUTPUT:
	RETVAL

int
LOG_PRI(p)
    INPUT:
	int		p
    CODE:
#ifdef LOG_PRI
	RETVAL = LOG_PRI(p);
#else
	croak("Your vendor has not defined the Sys::Syslog macro LOG_PRI");
	RETVAL = -1;
#endif
    OUTPUT:
	RETVAL

int
LOG_MAKEPRI(fac,pri)
    INPUT:
	int		fac
	int		pri
    CODE:
#ifdef LOG_MAKEPRI
	RETVAL = LOG_MAKEPRI(fac,pri);
#else
	croak("Your vendor has not defined the Sys::Syslog macro LOG_MAKEPRI");
	RETVAL = -1;
#endif
    OUTPUT:
	RETVAL

int
LOG_MASK(pri)
    INPUT:
	int		pri
    CODE:
#ifdef LOG_MASK
	RETVAL = LOG_MASK(pri);
#else
	croak("Your vendor has not defined the Sys::Syslog macro LOG_MASK");
	RETVAL = -1;
#endif
    OUTPUT:
	RETVAL

int
LOG_UPTO(pri)
    INPUT:
	int		pri
    CODE:
#ifdef LOG_UPTO
	RETVAL = LOG_UPTO(pri);
#else
	croak("Your vendor has not defined the Sys::Syslog macro LOG_UPTO");
	RETVAL = -1;
#endif
    OUTPUT:
	RETVAL


double
constant(sv)
    PREINIT:
	STRLEN		len;
    INPUT:
	SV *		sv
	char *		s = SvPV(sv, len);
    CODE:
	RETVAL = constant(s,len);
    OUTPUT:
	RETVAL

OpenPOWER on IntegriCloud