Commit | Line | Data |
---|---|---|
06fd9d7a CBW |
1 | /* |
2 | * Syslog.xs | |
3 | * | |
4 | * XS wrapper for the syslog(3) facility. | |
5 | * | |
6 | */ | |
7 | ||
df6b13ce AT |
8 | #if defined(_WIN32) |
9 | # include <windows.h> | |
10 | #endif | |
11 | ||
8ce86de8 GS |
12 | #include "EXTERN.h" |
13 | #include "perl.h" | |
14 | #include "XSUB.h" | |
1307ca85 JH |
15 | #ifdef USE_PPPORT_H |
16 | # include "ppport.h" | |
17 | #endif | |
8ce86de8 | 18 | |
a650b841 AT |
19 | #ifndef HAVE_SYSLOG |
20 | #define HAVE_SYSLOG 1 | |
21 | #endif | |
22 | ||
a650b841 | 23 | #if defined(_WIN32) && !defined(__CYGWIN__) |
f93f88eb AT |
24 | # undef HAVE_SYSLOG |
25 | # include "fallback/syslog.h" | |
26 | #else | |
27 | # if defined(I_SYSLOG) || PATCHLEVEL < 6 | |
28 | # include <syslog.h> | |
29 | # endif | |
a650b841 AT |
30 | #endif |
31 | ||
89c3c464 AT |
32 | static SV *ident_svptr; |
33 | ||
06fd9d7a CBW |
34 | |
35 | #ifndef LOG_FAC | |
36 | #define LOG_FACMASK 0x03f8 | |
37 | #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) | |
38 | #endif | |
39 | ||
33f804f6 SH |
40 | #ifndef LOG_PRIMASK |
41 | #define LOG_PRIMASK 0x07 | |
42 | #endif | |
43 | ||
06fd9d7a CBW |
44 | #ifndef LOG_PRI |
45 | #define LOG_PRI(p) ((p) & LOG_PRIMASK) | |
46 | #endif | |
47 | ||
48 | #ifndef LOG_MAKEPRI | |
49 | #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) | |
50 | #endif | |
51 | ||
52 | #ifndef LOG_MASK | |
53 | #define LOG_MASK(pri) (1 << (pri)) | |
54 | #endif | |
55 | ||
56 | #ifndef LOG_UPTO | |
57 | #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) | |
58 | #endif | |
59 | ||
33f804f6 SH |
60 | #include "const-c.inc" |
61 | ||
06fd9d7a | 62 | |
8ce86de8 GS |
63 | MODULE = Sys::Syslog PACKAGE = Sys::Syslog |
64 | ||
1cb0fb50 | 65 | INCLUDE: const-xs.inc |
8ce86de8 GS |
66 | |
67 | int | |
68 | LOG_FAC(p) | |
69 | INPUT: | |
70 | int p | |
8ce86de8 GS |
71 | |
72 | int | |
73 | LOG_PRI(p) | |
74 | INPUT: | |
75 | int p | |
8ce86de8 GS |
76 | |
77 | int | |
78 | LOG_MAKEPRI(fac,pri) | |
79 | INPUT: | |
80 | int fac | |
81 | int pri | |
8ce86de8 GS |
82 | |
83 | int | |
84 | LOG_MASK(pri) | |
85 | INPUT: | |
86 | int pri | |
8ce86de8 GS |
87 | |
88 | int | |
89 | LOG_UPTO(pri) | |
90 | INPUT: | |
91 | int pri | |
89c3c464 | 92 | |
a650b841 | 93 | #ifdef HAVE_SYSLOG |
89c3c464 AT |
94 | |
95 | void | |
96 | openlog_xs(ident, option, facility) | |
97 | INPUT: | |
98 | SV* ident | |
99 | int option | |
100 | int facility | |
101 | PREINIT: | |
102 | STRLEN len; | |
103 | char* ident_pv; | |
104 | CODE: | |
105 | ident_svptr = newSVsv(ident); | |
106 | ident_pv = SvPV(ident_svptr, len); | |
107 | openlog(ident_pv, option, facility); | |
108 | ||
109 | void | |
110 | syslog_xs(priority, message) | |
111 | INPUT: | |
112 | int priority | |
113 | const char * message | |
114 | CODE: | |
115 | syslog(priority, "%s", message); | |
116 | ||
117 | int | |
118 | setlogmask_xs(mask) | |
119 | INPUT: | |
120 | int mask | |
121 | CODE: | |
f93f88eb AT |
122 | RETVAL = setlogmask(mask); |
123 | OUTPUT: | |
124 | RETVAL | |
89c3c464 AT |
125 | |
126 | void | |
127 | closelog_xs() | |
06fd9d7a CBW |
128 | PREINIT: |
129 | U32 refcnt; | |
89c3c464 | 130 | CODE: |
06fd9d7a CBW |
131 | if (!ident_svptr) |
132 | return; | |
89c3c464 | 133 | closelog(); |
06fd9d7a CBW |
134 | refcnt = SvREFCNT(ident_svptr); |
135 | if (refcnt) { | |
89c3c464 | 136 | SvREFCNT_dec(ident_svptr); |
06fd9d7a CBW |
137 | if (refcnt == 1) |
138 | ident_svptr = NULL; | |
139 | } | |
89c3c464 | 140 | |
df6b13ce AT |
141 | #else /* HAVE_SYSLOG */ |
142 | ||
143 | void | |
144 | openlog_xs(ident, option, facility) | |
145 | INPUT: | |
146 | SV* ident | |
147 | int option | |
148 | int facility | |
149 | CODE: | |
150 | ||
151 | void | |
152 | syslog_xs(priority, message) | |
153 | INPUT: | |
154 | int priority | |
155 | const char * message | |
156 | CODE: | |
157 | ||
158 | int | |
159 | setlogmask_xs(mask) | |
160 | INPUT: | |
161 | int mask | |
162 | CODE: | |
163 | ||
164 | void | |
165 | closelog_xs() | |
166 | CODE: | |
167 | ||
a650b841 | 168 | #endif /* HAVE_SYSLOG */ |