Commit | Line | Data |
8ce86de8 |
1 | #include "EXTERN.h" |
2 | #include "perl.h" |
3 | #include "XSUB.h" |
4 | |
d76d5647 |
5 | #ifdef I_SYSLOG |
6 | #include <syslog.h> |
7 | #endif |
8ce86de8 |
8 | |
9 | static double |
b193a46a |
10 | constant_LOG_NO(char *name, int len) |
8ce86de8 |
11 | { |
12 | switch (name[6 + 0]) { |
13 | case 'T': |
14 | if (strEQ(name + 6, "TICE")) { /* LOG_NO removed */ |
15 | #ifdef LOG_NOTICE |
16 | return LOG_NOTICE; |
17 | #else |
18 | goto not_there; |
19 | #endif |
20 | } |
21 | case 'W': |
22 | if (strEQ(name + 6, "WAIT")) { /* LOG_NO removed */ |
23 | #ifdef LOG_NOWAIT |
24 | return LOG_NOWAIT; |
25 | #else |
26 | goto not_there; |
27 | #endif |
28 | } |
29 | } |
30 | errno = EINVAL; |
31 | return 0; |
32 | |
33 | not_there: |
34 | errno = ENOENT; |
35 | return 0; |
36 | } |
37 | |
38 | static double |
b193a46a |
39 | constant_LOG_N(char *name, int len) |
8ce86de8 |
40 | { |
41 | switch (name[5 + 0]) { |
42 | case 'D': |
43 | if (strEQ(name + 5, "DELAY")) { /* LOG_N removed */ |
44 | #ifdef LOG_NDELAY |
45 | return LOG_NDELAY; |
46 | #else |
47 | goto not_there; |
48 | #endif |
49 | } |
50 | case 'E': |
51 | if (strEQ(name + 5, "EWS")) { /* LOG_N removed */ |
52 | #ifdef LOG_NEWS |
53 | return LOG_NEWS; |
54 | #else |
55 | goto not_there; |
56 | #endif |
57 | } |
58 | case 'F': |
59 | if (strEQ(name + 5, "FACILITIES")) { /* LOG_N removed */ |
60 | #ifdef LOG_NFACILITIES |
61 | return LOG_NFACILITIES; |
62 | #else |
63 | goto not_there; |
64 | #endif |
65 | } |
66 | case 'O': |
b193a46a |
67 | return constant_LOG_NO(name, len); |
8ce86de8 |
68 | } |
69 | errno = EINVAL; |
70 | return 0; |
71 | |
72 | not_there: |
73 | errno = ENOENT; |
74 | return 0; |
75 | } |
76 | |
77 | static double |
b193a46a |
78 | constant_LOG_P(char *name, int len) |
8ce86de8 |
79 | { |
80 | switch (name[5 + 0]) { |
81 | case 'I': |
82 | if (strEQ(name + 5, "ID")) { /* LOG_P removed */ |
83 | #ifdef LOG_PID |
84 | return LOG_PID; |
85 | #else |
86 | goto not_there; |
87 | #endif |
88 | } |
89 | case 'R': |
90 | if (strEQ(name + 5, "RIMASK")) { /* LOG_P removed */ |
91 | #ifdef LOG_PRIMASK |
92 | return LOG_PRIMASK; |
93 | #else |
94 | goto not_there; |
95 | #endif |
96 | } |
97 | } |
98 | errno = EINVAL; |
99 | return 0; |
100 | |
101 | not_there: |
102 | errno = ENOENT; |
103 | return 0; |
104 | } |
105 | |
106 | static double |
b193a46a |
107 | constant_LOG_AU(char *name, int len) |
8ce86de8 |
108 | { |
109 | if (6 + 2 >= len ) { |
110 | errno = EINVAL; |
111 | return 0; |
112 | } |
113 | switch (name[6 + 2]) { |
114 | case '\0': |
115 | if (strEQ(name + 6, "TH")) { /* LOG_AU removed */ |
116 | #ifdef LOG_AUTH |
117 | return LOG_AUTH; |
118 | #else |
119 | goto not_there; |
120 | #endif |
121 | } |
122 | case 'P': |
123 | if (strEQ(name + 6, "THPRIV")) { /* LOG_AU removed */ |
124 | #ifdef LOG_AUTHPRIV |
125 | return LOG_AUTHPRIV; |
126 | #else |
127 | goto not_there; |
128 | #endif |
129 | } |
130 | } |
131 | errno = EINVAL; |
132 | return 0; |
133 | |
134 | not_there: |
135 | errno = ENOENT; |
136 | return 0; |
137 | } |
138 | |
139 | static double |
b193a46a |
140 | constant_LOG_A(char *name, int len) |
8ce86de8 |
141 | { |
142 | switch (name[5 + 0]) { |
143 | case 'L': |
144 | if (strEQ(name + 5, "LERT")) { /* LOG_A removed */ |
145 | #ifdef LOG_ALERT |
146 | return LOG_ALERT; |
147 | #else |
148 | goto not_there; |
149 | #endif |
150 | } |
151 | case 'U': |
b193a46a |
152 | return constant_LOG_AU(name, len); |
8ce86de8 |
153 | } |
154 | errno = EINVAL; |
155 | return 0; |
156 | |
157 | not_there: |
158 | errno = ENOENT; |
159 | return 0; |
160 | } |
161 | |
162 | static double |
b193a46a |
163 | constant_LOG_CR(char *name, int len) |
8ce86de8 |
164 | { |
165 | switch (name[6 + 0]) { |
166 | case 'I': |
167 | if (strEQ(name + 6, "IT")) { /* LOG_CR removed */ |
168 | #ifdef LOG_CRIT |
169 | return LOG_CRIT; |
170 | #else |
171 | goto not_there; |
172 | #endif |
173 | } |
174 | case 'O': |
175 | if (strEQ(name + 6, "ON")) { /* LOG_CR removed */ |
176 | #ifdef LOG_CRON |
177 | return LOG_CRON; |
178 | #else |
179 | goto not_there; |
180 | #endif |
181 | } |
182 | } |
183 | errno = EINVAL; |
184 | return 0; |
185 | |
186 | not_there: |
187 | errno = ENOENT; |
188 | return 0; |
189 | } |
190 | |
191 | static double |
b193a46a |
192 | constant_LOG_C(char *name, int len) |
8ce86de8 |
193 | { |
194 | switch (name[5 + 0]) { |
195 | case 'O': |
196 | if (strEQ(name + 5, "ONS")) { /* LOG_C removed */ |
197 | #ifdef LOG_CONS |
198 | return LOG_CONS; |
199 | #else |
200 | goto not_there; |
201 | #endif |
202 | } |
203 | case 'R': |
b193a46a |
204 | return constant_LOG_CR(name, len); |
8ce86de8 |
205 | } |
206 | errno = EINVAL; |
207 | return 0; |
208 | |
209 | not_there: |
210 | errno = ENOENT; |
211 | return 0; |
212 | } |
213 | |
214 | static double |
b193a46a |
215 | constant_LOG_D(char *name, int len) |
8ce86de8 |
216 | { |
217 | switch (name[5 + 0]) { |
218 | case 'A': |
219 | if (strEQ(name + 5, "AEMON")) { /* LOG_D removed */ |
220 | #ifdef LOG_DAEMON |
221 | return LOG_DAEMON; |
222 | #else |
223 | goto not_there; |
224 | #endif |
225 | } |
226 | case 'E': |
227 | if (strEQ(name + 5, "EBUG")) { /* LOG_D removed */ |
228 | #ifdef LOG_DEBUG |
229 | return LOG_DEBUG; |
230 | #else |
231 | goto not_there; |
232 | #endif |
233 | } |
234 | } |
235 | errno = EINVAL; |
236 | return 0; |
237 | |
238 | not_there: |
239 | errno = ENOENT; |
240 | return 0; |
241 | } |
242 | |
243 | static double |
b193a46a |
244 | constant_LOG_U(char *name, int len) |
8ce86de8 |
245 | { |
246 | switch (name[5 + 0]) { |
247 | case 'S': |
248 | if (strEQ(name + 5, "SER")) { /* LOG_U removed */ |
249 | #ifdef LOG_USER |
250 | return LOG_USER; |
251 | #else |
252 | goto not_there; |
253 | #endif |
254 | } |
255 | case 'U': |
256 | if (strEQ(name + 5, "UCP")) { /* LOG_U removed */ |
257 | #ifdef LOG_UUCP |
258 | return LOG_UUCP; |
259 | #else |
260 | goto not_there; |
261 | #endif |
262 | } |
263 | } |
264 | errno = EINVAL; |
265 | return 0; |
266 | |
267 | not_there: |
268 | errno = ENOENT; |
269 | return 0; |
270 | } |
271 | |
272 | static double |
b193a46a |
273 | constant_LOG_E(char *name, int len) |
8ce86de8 |
274 | { |
275 | switch (name[5 + 0]) { |
276 | case 'M': |
277 | if (strEQ(name + 5, "MERG")) { /* LOG_E removed */ |
278 | #ifdef LOG_EMERG |
279 | return LOG_EMERG; |
280 | #else |
281 | goto not_there; |
282 | #endif |
283 | } |
284 | case 'R': |
285 | if (strEQ(name + 5, "RR")) { /* LOG_E removed */ |
286 | #ifdef LOG_ERR |
287 | return LOG_ERR; |
288 | #else |
289 | goto not_there; |
290 | #endif |
291 | } |
292 | } |
293 | errno = EINVAL; |
294 | return 0; |
295 | |
296 | not_there: |
297 | errno = ENOENT; |
298 | return 0; |
299 | } |
300 | |
301 | static double |
b193a46a |
302 | constant_LOG_F(char *name, int len) |
8ce86de8 |
303 | { |
304 | switch (name[5 + 0]) { |
305 | case 'A': |
306 | if (strEQ(name + 5, "ACMASK")) { /* LOG_F removed */ |
307 | #ifdef LOG_FACMASK |
308 | return LOG_FACMASK; |
309 | #else |
310 | goto not_there; |
311 | #endif |
312 | } |
313 | case 'T': |
314 | if (strEQ(name + 5, "TP")) { /* LOG_F removed */ |
315 | #ifdef LOG_FTP |
316 | return LOG_FTP; |
317 | #else |
318 | goto not_there; |
319 | #endif |
320 | } |
321 | } |
322 | errno = EINVAL; |
323 | return 0; |
324 | |
325 | not_there: |
326 | errno = ENOENT; |
327 | return 0; |
328 | } |
329 | |
330 | static double |
b193a46a |
331 | constant_LOG_LO(char *name, int len) |
8ce86de8 |
332 | { |
333 | if (6 + 3 >= len ) { |
334 | errno = EINVAL; |
335 | return 0; |
336 | } |
337 | switch (name[6 + 3]) { |
338 | case '0': |
339 | if (strEQ(name + 6, "CAL0")) { /* LOG_LO removed */ |
340 | #ifdef LOG_LOCAL0 |
341 | return LOG_LOCAL0; |
342 | #else |
343 | goto not_there; |
344 | #endif |
345 | } |
346 | case '1': |
347 | if (strEQ(name + 6, "CAL1")) { /* LOG_LO removed */ |
348 | #ifdef LOG_LOCAL1 |
349 | return LOG_LOCAL1; |
350 | #else |
351 | goto not_there; |
352 | #endif |
353 | } |
354 | case '2': |
355 | if (strEQ(name + 6, "CAL2")) { /* LOG_LO removed */ |
356 | #ifdef LOG_LOCAL2 |
357 | return LOG_LOCAL2; |
358 | #else |
359 | goto not_there; |
360 | #endif |
361 | } |
362 | case '3': |
363 | if (strEQ(name + 6, "CAL3")) { /* LOG_LO removed */ |
364 | #ifdef LOG_LOCAL3 |
365 | return LOG_LOCAL3; |
366 | #else |
367 | goto not_there; |
368 | #endif |
369 | } |
370 | case '4': |
371 | if (strEQ(name + 6, "CAL4")) { /* LOG_LO removed */ |
372 | #ifdef LOG_LOCAL4 |
373 | return LOG_LOCAL4; |
374 | #else |
375 | goto not_there; |
376 | #endif |
377 | } |
378 | case '5': |
379 | if (strEQ(name + 6, "CAL5")) { /* LOG_LO removed */ |
380 | #ifdef LOG_LOCAL5 |
381 | return LOG_LOCAL5; |
382 | #else |
383 | goto not_there; |
384 | #endif |
385 | } |
386 | case '6': |
387 | if (strEQ(name + 6, "CAL6")) { /* LOG_LO removed */ |
388 | #ifdef LOG_LOCAL6 |
389 | return LOG_LOCAL6; |
390 | #else |
391 | goto not_there; |
392 | #endif |
393 | } |
394 | case '7': |
395 | if (strEQ(name + 6, "CAL7")) { /* LOG_LO removed */ |
396 | #ifdef LOG_LOCAL7 |
397 | return LOG_LOCAL7; |
398 | #else |
399 | goto not_there; |
400 | #endif |
401 | } |
402 | } |
403 | errno = EINVAL; |
404 | return 0; |
405 | |
406 | not_there: |
407 | errno = ENOENT; |
408 | return 0; |
409 | } |
410 | |
411 | static double |
b193a46a |
412 | constant_LOG_L(char *name, int len) |
8ce86de8 |
413 | { |
414 | switch (name[5 + 0]) { |
415 | case 'F': |
416 | if (strEQ(name + 5, "FMT")) { /* LOG_L removed */ |
417 | #ifdef LOG_LFMT |
418 | return LOG_LFMT; |
419 | #else |
420 | goto not_there; |
421 | #endif |
422 | } |
423 | case 'O': |
b193a46a |
424 | return constant_LOG_LO(name, len); |
8ce86de8 |
425 | case 'P': |
426 | if (strEQ(name + 5, "PR")) { /* LOG_L removed */ |
427 | #ifdef LOG_LPR |
428 | return LOG_LPR; |
429 | #else |
430 | goto not_there; |
431 | #endif |
432 | } |
433 | } |
434 | errno = EINVAL; |
435 | return 0; |
436 | |
437 | not_there: |
438 | errno = ENOENT; |
439 | return 0; |
440 | } |
441 | |
442 | static double |
b193a46a |
443 | constant(char *name, int len) |
8ce86de8 |
444 | { |
445 | errno = 0; |
446 | if (0 + 4 >= len ) { |
447 | errno = EINVAL; |
448 | return 0; |
449 | } |
450 | switch (name[0 + 4]) { |
451 | case 'A': |
452 | if (!strnEQ(name + 0,"LOG_", 4)) |
453 | break; |
b193a46a |
454 | return constant_LOG_A(name, len); |
8ce86de8 |
455 | case 'C': |
456 | if (!strnEQ(name + 0,"LOG_", 4)) |
457 | break; |
b193a46a |
458 | return constant_LOG_C(name, len); |
8ce86de8 |
459 | case 'D': |
460 | if (!strnEQ(name + 0,"LOG_", 4)) |
461 | break; |
b193a46a |
462 | return constant_LOG_D(name, len); |
8ce86de8 |
463 | case 'E': |
464 | if (!strnEQ(name + 0,"LOG_", 4)) |
465 | break; |
b193a46a |
466 | return constant_LOG_E(name, len); |
8ce86de8 |
467 | case 'F': |
468 | if (!strnEQ(name + 0,"LOG_", 4)) |
469 | break; |
b193a46a |
470 | return constant_LOG_F(name, len); |
8ce86de8 |
471 | case 'I': |
472 | if (strEQ(name + 0, "LOG_INFO")) { /* removed */ |
473 | #ifdef LOG_INFO |
474 | return LOG_INFO; |
475 | #else |
476 | goto not_there; |
477 | #endif |
478 | } |
479 | case 'K': |
480 | if (strEQ(name + 0, "LOG_KERN")) { /* removed */ |
481 | #ifdef LOG_KERN |
482 | return LOG_KERN; |
483 | #else |
484 | goto not_there; |
485 | #endif |
486 | } |
487 | case 'L': |
488 | if (!strnEQ(name + 0,"LOG_", 4)) |
489 | break; |
b193a46a |
490 | return constant_LOG_L(name, len); |
8ce86de8 |
491 | case 'M': |
492 | if (strEQ(name + 0, "LOG_MAIL")) { /* removed */ |
493 | #ifdef LOG_MAIL |
494 | return LOG_MAIL; |
495 | #else |
496 | goto not_there; |
497 | #endif |
498 | } |
499 | case 'N': |
500 | if (!strnEQ(name + 0,"LOG_", 4)) |
501 | break; |
b193a46a |
502 | return constant_LOG_N(name, len); |
8ce86de8 |
503 | case 'O': |
504 | if (strEQ(name + 0, "LOG_ODELAY")) { /* removed */ |
505 | #ifdef LOG_ODELAY |
506 | return LOG_ODELAY; |
507 | #else |
508 | goto not_there; |
509 | #endif |
510 | } |
511 | case 'P': |
512 | if (!strnEQ(name + 0,"LOG_", 4)) |
513 | break; |
b193a46a |
514 | return constant_LOG_P(name, len); |
8ce86de8 |
515 | case 'S': |
516 | if (strEQ(name + 0, "LOG_SYSLOG")) { /* removed */ |
517 | #ifdef LOG_SYSLOG |
518 | return LOG_SYSLOG; |
519 | #else |
520 | goto not_there; |
521 | #endif |
522 | } |
523 | case 'U': |
524 | if (!strnEQ(name + 0,"LOG_", 4)) |
525 | break; |
b193a46a |
526 | return constant_LOG_U(name, len); |
8ce86de8 |
527 | case 'W': |
528 | if (strEQ(name + 0, "LOG_WARNING")) { /* removed */ |
529 | #ifdef LOG_WARNING |
530 | return LOG_WARNING; |
531 | #else |
532 | goto not_there; |
533 | #endif |
534 | } |
535 | } |
536 | errno = EINVAL; |
537 | return 0; |
538 | |
539 | not_there: |
540 | errno = ENOENT; |
541 | return 0; |
542 | } |
543 | |
544 | |
545 | MODULE = Sys::Syslog PACKAGE = Sys::Syslog |
546 | |
547 | char * |
548 | _PATH_LOG() |
549 | CODE: |
550 | #ifdef _PATH_LOG |
551 | RETVAL = _PATH_LOG; |
552 | #else |
150b260b |
553 | RETVAL = ""; |
8ce86de8 |
554 | #endif |
555 | OUTPUT: |
556 | RETVAL |
557 | |
558 | int |
559 | LOG_FAC(p) |
560 | INPUT: |
561 | int p |
562 | CODE: |
563 | #ifdef LOG_FAC |
564 | RETVAL = LOG_FAC(p); |
565 | #else |
566 | croak("Your vendor has not defined the Sys::Syslog macro LOG_FAC"); |
b621ec8a |
567 | RETVAL = -1; |
8ce86de8 |
568 | #endif |
569 | OUTPUT: |
570 | RETVAL |
571 | |
572 | int |
573 | LOG_PRI(p) |
574 | INPUT: |
575 | int p |
576 | CODE: |
577 | #ifdef LOG_PRI |
578 | RETVAL = LOG_PRI(p); |
579 | #else |
580 | croak("Your vendor has not defined the Sys::Syslog macro LOG_PRI"); |
b621ec8a |
581 | RETVAL = -1; |
8ce86de8 |
582 | #endif |
583 | OUTPUT: |
584 | RETVAL |
585 | |
586 | int |
587 | LOG_MAKEPRI(fac,pri) |
588 | INPUT: |
589 | int fac |
590 | int pri |
591 | CODE: |
592 | #ifdef LOG_MAKEPRI |
593 | RETVAL = LOG_MAKEPRI(fac,pri); |
594 | #else |
595 | croak("Your vendor has not defined the Sys::Syslog macro LOG_MAKEPRI"); |
b621ec8a |
596 | RETVAL = -1; |
8ce86de8 |
597 | #endif |
598 | OUTPUT: |
599 | RETVAL |
600 | |
601 | int |
602 | LOG_MASK(pri) |
603 | INPUT: |
604 | int pri |
605 | CODE: |
606 | #ifdef LOG_MASK |
607 | RETVAL = LOG_MASK(pri); |
608 | #else |
609 | croak("Your vendor has not defined the Sys::Syslog macro LOG_MASK"); |
b621ec8a |
610 | RETVAL = -1; |
8ce86de8 |
611 | #endif |
612 | OUTPUT: |
613 | RETVAL |
614 | |
615 | int |
616 | LOG_UPTO(pri) |
617 | INPUT: |
618 | int pri |
619 | CODE: |
620 | #ifdef LOG_UPTO |
621 | RETVAL = LOG_UPTO(pri); |
622 | #else |
623 | croak("Your vendor has not defined the Sys::Syslog macro LOG_UPTO"); |
b621ec8a |
624 | RETVAL = -1; |
8ce86de8 |
625 | #endif |
626 | OUTPUT: |
627 | RETVAL |
628 | |
629 | |
630 | double |
b193a46a |
631 | constant(sv) |
8ce86de8 |
632 | PREINIT: |
633 | STRLEN len; |
634 | INPUT: |
635 | SV * sv |
636 | char * s = SvPV(sv, len); |
8ce86de8 |
637 | CODE: |
b193a46a |
638 | RETVAL = constant(s,len); |
8ce86de8 |
639 | OUTPUT: |
640 | RETVAL |
641 | |