123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #include "php.h"
- #ifdef HAVE_SYSLOG_H
- #include "php_ini.h"
- #include "zend_globals.h"
- #include <stdlib.h>
- #if HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #include <string.h>
- #include <errno.h>
- #include <stdio.h>
- #include "basic_functions.h"
- #include "php_ext_syslog.h"
- PHP_MINIT_FUNCTION(syslog)
- {
-
- REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
- #ifdef LOG_NEWS
-
- REGISTER_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT);
- #endif
- #ifdef LOG_UUCP
-
- REGISTER_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT);
- #endif
- #ifdef LOG_CRON
-
- REGISTER_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT);
- #endif
- #ifdef LOG_AUTHPRIV
-
- REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
- #endif
- #ifndef PHP_WIN32
- REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
- #endif
-
- REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
- #ifdef LOG_NOWAIT
- REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT);
- #endif
- #ifdef LOG_PERROR
-
- REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT);
- #endif
- BG(syslog_device)=NULL;
- return SUCCESS;
- }
- PHP_RINIT_FUNCTION(syslog)
- {
- BG(syslog_device) = NULL;
- return SUCCESS;
- }
- #ifdef PHP_WIN32
- PHP_RSHUTDOWN_FUNCTION(syslog)
- {
- closelog();
- return SUCCESS;
- }
- #endif
- PHP_MSHUTDOWN_FUNCTION(syslog)
- {
- if (BG(syslog_device)) {
- free(BG(syslog_device));
- BG(syslog_device) = NULL;
- }
- return SUCCESS;
- }
- PHP_FUNCTION(openlog)
- {
- char *ident;
- long option, facility;
- int ident_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident,
- &ident_len, &option, &facility) == FAILURE) {
- return;
- }
- if (BG(syslog_device)) {
- free(BG(syslog_device));
- }
- BG(syslog_device) = zend_strndup(ident, ident_len);
- if(BG(syslog_device) == NULL) {
- RETURN_FALSE;
- }
- openlog(BG(syslog_device), option, facility);
- RETURN_TRUE;
- }
- PHP_FUNCTION(closelog)
- {
- if (zend_parse_parameters_none() == FAILURE) {
- return;
- }
- closelog();
- if (BG(syslog_device)) {
- free(BG(syslog_device));
- BG(syslog_device)=NULL;
- }
- RETURN_TRUE;
- }
- PHP_FUNCTION(syslog)
- {
- long priority;
- char *message;
- int message_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority,
- &message, &message_len) == FAILURE) {
- return;
- }
- php_syslog(priority, "%s", message);
- RETURN_TRUE;
- }
- #endif
|