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