/src/php-src/ext/standard/syslog.c
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright © The PHP Group and Contributors. | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to the Modified BSD License that is | |
6 | | | bundled with this package in the file LICENSE, and is available | |
7 | | | through the World Wide Web at <https://www.php.net/license/>. | |
8 | | | | |
9 | | | SPDX-License-Identifier: BSD-3-Clause | |
10 | | +----------------------------------------------------------------------+ |
11 | | | Author: Stig Sæther Bakken <ssb@php.net> | |
12 | | +----------------------------------------------------------------------+ |
13 | | */ |
14 | | |
15 | | #include "php.h" |
16 | | |
17 | | #ifdef HAVE_SYSLOG_H |
18 | | #include "php_ini.h" |
19 | | #include "zend_globals.h" |
20 | | |
21 | | #include <stdlib.h> |
22 | | #ifdef HAVE_UNISTD_H |
23 | | #include <unistd.h> |
24 | | #endif |
25 | | |
26 | | #include <string.h> |
27 | | #include <errno.h> |
28 | | |
29 | | #include <stdio.h> |
30 | | #include "basic_functions.h" |
31 | | #include "php_ext_syslog.h" |
32 | | |
33 | | /* {{{ PHP_MINIT_FUNCTION */ |
34 | | PHP_MINIT_FUNCTION(syslog) |
35 | 2 | { |
36 | 2 | return SUCCESS; |
37 | 2 | } |
38 | | /* }}} */ |
39 | | |
40 | | PHP_RSHUTDOWN_FUNCTION(syslog) |
41 | 6.77k | { |
42 | 6.77k | php_closelog(); |
43 | 6.77k | if (BG(syslog_device)) { |
44 | 0 | free(BG(syslog_device)); |
45 | 0 | BG(syslog_device) = NULL; |
46 | 0 | } |
47 | 6.77k | return SUCCESS; |
48 | 6.77k | } |
49 | | |
50 | | |
51 | | /* {{{ Open connection to system logger */ |
52 | | /* |
53 | | ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1); |
54 | | ** Syslog($LOG_EMERG, "help me!") |
55 | | ** CloseLog(); |
56 | | */ |
57 | | PHP_FUNCTION(openlog) |
58 | 0 | { |
59 | 0 | char *ident; |
60 | 0 | zend_long option, facility; |
61 | 0 | size_t ident_len; |
62 | |
|
63 | 0 | ZEND_PARSE_PARAMETERS_START(3, 3) |
64 | 0 | Z_PARAM_STRING(ident, ident_len) |
65 | 0 | Z_PARAM_LONG(option) |
66 | 0 | Z_PARAM_LONG(facility) |
67 | 0 | ZEND_PARSE_PARAMETERS_END(); |
68 | | |
69 | 0 | if (BG(syslog_device)) { |
70 | 0 | free(BG(syslog_device)); |
71 | 0 | } |
72 | 0 | BG(syslog_device) = zend_strndup(ident, ident_len); |
73 | 0 | php_openlog(BG(syslog_device), option, facility); |
74 | 0 | RETURN_TRUE; |
75 | 0 | } |
76 | | /* }}} */ |
77 | | |
78 | | /* {{{ Close connection to system logger */ |
79 | | PHP_FUNCTION(closelog) |
80 | 0 | { |
81 | 0 | ZEND_PARSE_PARAMETERS_NONE(); |
82 | | |
83 | 0 | php_closelog(); |
84 | 0 | if (BG(syslog_device)) { |
85 | 0 | free(BG(syslog_device)); |
86 | 0 | BG(syslog_device)=NULL; |
87 | 0 | } |
88 | 0 | RETURN_TRUE; |
89 | 0 | } |
90 | | /* }}} */ |
91 | | |
92 | | /* {{{ Generate a system log message */ |
93 | | PHP_FUNCTION(syslog) |
94 | 0 | { |
95 | 0 | zend_long priority; |
96 | 0 | zend_string *message; |
97 | |
|
98 | 0 | ZEND_PARSE_PARAMETERS_START(2, 2) |
99 | 0 | Z_PARAM_LONG(priority) |
100 | 0 | Z_PARAM_STR(message) |
101 | 0 | ZEND_PARSE_PARAMETERS_END(); |
102 | | |
103 | 0 | php_syslog_str(priority, message); |
104 | 0 | RETURN_TRUE; |
105 | 0 | } |
106 | | /* }}} */ |
107 | | |
108 | | #endif |