LTP GCOV extension - code coverage report
Current view: directory - ext/standard - syslog.c
Test: PHP Code Coverage
Date: 2007-04-10 Instrumented lines: 109
Code covered: 41.3 % Executed lines: 45
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2007 The PHP Group                                |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 3.01 of the PHP license,      |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.php.net/license/3_01.txt                                  |
      11                 :    | If you did not receive a copy of the PHP license and are unable to   |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@php.net so we can mail you a copy immediately.               |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Author: Stig Sæther Bakken <ssb@php.net>                             |
      16                 :    +----------------------------------------------------------------------+
      17                 :  */
      18                 : 
      19                 : /* $Id: syslog.c,v 1.49.2.3.2.1 2007/01/01 09:36:09 sebastian Exp $ */
      20                 : 
      21                 : #include "php.h"
      22                 : 
      23                 : #ifdef HAVE_SYSLOG_H
      24                 : #include "php_ini.h"
      25                 : #include "zend_globals.h"
      26                 : 
      27                 : #include <stdlib.h>
      28                 : #if HAVE_UNISTD_H
      29                 : #include <unistd.h>
      30                 : #endif
      31                 : 
      32                 : #include <string.h>
      33                 : #include <errno.h>
      34                 : 
      35                 : #include <stdio.h>
      36                 : #include "basic_functions.h"
      37                 : #include "php_ext_syslog.h"
      38                 : 
      39                 : static void start_syslog(TSRMLS_D);
      40                 : 
      41                 : /* {{{ PHP_MINIT_FUNCTION
      42                 :  */
      43                 : PHP_MINIT_FUNCTION(syslog)
      44             220 : {
      45                 :         /* error levels */
      46             220 :         REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
      47             220 :         REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
      48             220 :         REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */
      49             220 :         REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT); 
      50             220 :         REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
      51             220 :         REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
      52             220 :         REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
      53             220 :         REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
      54                 :         /* facility: type of program logging the message */
      55             220 :         REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
      56             220 :         REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */
      57             220 :         REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */
      58             220 :         REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */
      59             220 :         REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
      60             220 :         REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
      61             220 :         REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
      62                 : #ifdef LOG_NEWS
      63                 :         /* No LOG_NEWS on HP-UX */
      64             220 :         REGISTER_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */
      65                 : #endif
      66                 : #ifdef LOG_UUCP
      67                 :         /* No LOG_UUCP on HP-UX */
      68             220 :         REGISTER_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT);
      69                 : #endif
      70                 : #ifdef LOG_CRON
      71                 :         /* apparently some systems don't have this one */
      72             220 :         REGISTER_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT);
      73                 : #endif
      74                 : #ifdef LOG_AUTHPRIV
      75                 :         /* AIX doesn't have LOG_AUTHPRIV */
      76             220 :         REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
      77                 : #endif
      78                 : #ifndef PHP_WIN32
      79             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
      80             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
      81             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
      82             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
      83             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
      84             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
      85             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
      86             220 :         REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
      87                 : #endif
      88                 :         /* options */
      89             220 :         REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
      90             220 :         REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
      91             220 :         REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
      92             220 :         REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
      93                 : #ifdef LOG_NOWAIT
      94             220 :         REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT);
      95                 : #endif
      96                 : #ifdef LOG_PERROR
      97                 :         /* AIX doesn't have LOG_PERROR */
      98             220 :         REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
      99                 : #endif
     100             220 :         BG(syslog_device)=NULL;
     101                 : 
     102             220 :         return SUCCESS;
     103                 : }
     104                 : /* }}} */
     105                 : 
     106                 : PHP_RINIT_FUNCTION(syslog)
     107             219 : {
     108             219 :         if (INI_INT("define_syslog_variables")) {
     109               0 :                 start_syslog(TSRMLS_C);
     110                 :         } else {
     111             219 :                 BG(syslog_started)=0;
     112                 :         }
     113             219 :         return SUCCESS;
     114                 : }
     115                 : 
     116                 : 
     117                 : PHP_RSHUTDOWN_FUNCTION(syslog)
     118             219 : {
     119                 : #ifdef PHP_WIN32
     120                 :         closelog();
     121                 : #endif
     122             219 :         return SUCCESS;
     123                 : }
     124                 : 
     125                 : PHP_MSHUTDOWN_FUNCTION(syslog)
     126             219 : {
     127             219 :         if (BG(syslog_device)) {
     128               0 :                 free(BG(syslog_device));
     129                 :         }
     130             219 :         return SUCCESS;
     131                 : }
     132                 : 
     133                 : /* {{{ start_syslog
     134                 :  */
     135                 : static void start_syslog(TSRMLS_D)
     136               0 : {
     137                 :         /* error levels */
     138               0 :         SET_VAR_LONG("LOG_EMERG", LOG_EMERG); /* system unusable */
     139               0 :         SET_VAR_LONG("LOG_ALERT", LOG_ALERT); /* immediate action required */
     140               0 :         SET_VAR_LONG("LOG_CRIT", LOG_CRIT); /* critical conditions */
     141               0 :         SET_VAR_LONG("LOG_ERR", LOG_ERR); 
     142               0 :         SET_VAR_LONG("LOG_WARNING", LOG_WARNING);
     143               0 :         SET_VAR_LONG("LOG_NOTICE", LOG_NOTICE);
     144               0 :         SET_VAR_LONG("LOG_INFO", LOG_INFO);
     145               0 :         SET_VAR_LONG("LOG_DEBUG", LOG_DEBUG);
     146                 :         /* facility: type of program logging the message */
     147               0 :         SET_VAR_LONG("LOG_KERN", LOG_KERN);
     148               0 :         SET_VAR_LONG("LOG_USER", LOG_USER); /* generic user level */
     149               0 :         SET_VAR_LONG("LOG_MAIL", LOG_MAIL); /* log to email */
     150               0 :         SET_VAR_LONG("LOG_DAEMON", LOG_DAEMON); /* other system daemons */
     151               0 :         SET_VAR_LONG("LOG_AUTH", LOG_AUTH);
     152                 : #ifndef NETWARE
     153               0 :         SET_VAR_LONG("LOG_SYSLOG", LOG_SYSLOG);
     154                 : #endif
     155               0 :         SET_VAR_LONG("LOG_LPR", LOG_LPR);
     156                 : #ifdef LOG_NEWS
     157                 :         /* No LOG_NEWS on HP-UX */
     158               0 :         SET_VAR_LONG("LOG_NEWS", LOG_NEWS); /* usenet new */
     159                 : #endif
     160                 : #ifdef LOG_UUCP
     161                 :         /* No LOG_UUCP on HP-UX */
     162               0 :         SET_VAR_LONG("LOG_UUCP", LOG_UUCP);
     163                 : #endif
     164                 : #ifdef LOG_CRON
     165                 :         /* apparently some systems don't have this one */
     166               0 :         SET_VAR_LONG("LOG_CRON", LOG_CRON);
     167                 : #endif
     168                 : #ifdef LOG_AUTHPRIV
     169                 :         /* AIX doesn't have LOG_AUTHPRIV */
     170               0 :         SET_VAR_LONG("LOG_AUTHPRIV", LOG_AUTHPRIV);
     171                 : #endif
     172                 : #if !defined(PHP_WIN32) && !defined(NETWARE)
     173               0 :         SET_VAR_LONG("LOG_LOCAL0", LOG_LOCAL0);
     174               0 :         SET_VAR_LONG("LOG_LOCAL1", LOG_LOCAL1);
     175               0 :         SET_VAR_LONG("LOG_LOCAL2", LOG_LOCAL2);
     176               0 :         SET_VAR_LONG("LOG_LOCAL3", LOG_LOCAL3);
     177               0 :         SET_VAR_LONG("LOG_LOCAL4", LOG_LOCAL4);
     178               0 :         SET_VAR_LONG("LOG_LOCAL5", LOG_LOCAL5);
     179               0 :         SET_VAR_LONG("LOG_LOCAL6", LOG_LOCAL6);
     180               0 :         SET_VAR_LONG("LOG_LOCAL7", LOG_LOCAL7);
     181                 : #endif
     182                 :         /* options */
     183               0 :         SET_VAR_LONG("LOG_PID", LOG_PID);
     184               0 :         SET_VAR_LONG("LOG_CONS", LOG_CONS);
     185               0 :         SET_VAR_LONG("LOG_ODELAY", LOG_ODELAY);
     186               0 :         SET_VAR_LONG("LOG_NDELAY", LOG_NDELAY);
     187                 : #ifdef LOG_NOWAIT
     188                 :         /* BeOS doesn't have LOG_NOWAIT */
     189               0 :         SET_VAR_LONG("LOG_NOWAIT", LOG_NOWAIT);
     190                 : #endif
     191                 : #ifdef LOG_PERROR
     192                 :         /* AIX doesn't have LOG_PERROR */
     193               0 :         SET_VAR_LONG("LOG_PERROR", LOG_PERROR); /*log to stderr*/
     194                 : #endif
     195                 : 
     196               0 :         BG(syslog_started)=1;
     197               0 : }
     198                 : /* }}} */
     199                 : 
     200                 : /* {{{ proto void define_syslog_variables(void)
     201                 :    Initializes all syslog-related variables */
     202                 : PHP_FUNCTION(define_syslog_variables)
     203               0 : {
     204               0 :         if (ZEND_NUM_ARGS() != 0) {
     205               0 :                 WRONG_PARAM_COUNT;
     206                 :         }
     207                 : 
     208               0 :         if (!BG(syslog_started)) {
     209               0 :                 start_syslog(TSRMLS_C);
     210                 :         }
     211                 : }
     212                 : /* }}} */
     213                 : 
     214                 : /* {{{ proto bool openlog(string ident, int option, int facility)
     215                 :    Open connection to system logger */
     216                 : /*
     217                 :    ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
     218                 :    ** Syslog($LOG_EMERG, "help me!")
     219                 :    ** CloseLog();
     220                 :  */
     221                 : PHP_FUNCTION(openlog)
     222               0 : {
     223                 :         char *ident;
     224                 :         long option, facility;
     225                 :         int ident_len;
     226                 : 
     227               0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident,
     228                 :                                                           &ident_len, &option, &facility) == FAILURE) {
     229               0 :                 return;
     230                 :         }
     231               0 :         if (BG(syslog_device)) {
     232               0 :                 free(BG(syslog_device));
     233                 :         }
     234               0 :         BG(syslog_device) = zend_strndup(ident, ident_len);
     235               0 :         openlog(BG(syslog_device), option, facility);
     236               0 :         RETURN_TRUE;
     237                 : }
     238                 : /* }}} */
     239                 : 
     240                 : /* {{{ proto bool closelog(void)
     241                 :    Close connection to system logger */
     242                 : PHP_FUNCTION(closelog)
     243               0 : {
     244               0 :         if (ZEND_NUM_ARGS() != 0) {
     245               0 :                 WRONG_PARAM_COUNT;
     246                 :         }
     247                 : 
     248               0 :         closelog();
     249               0 :         if (BG(syslog_device)) {
     250               0 :                 free(BG(syslog_device));
     251               0 :                 BG(syslog_device)=NULL;
     252                 :         }
     253               0 :         RETURN_TRUE;
     254                 : }
     255                 : /* }}} */
     256                 : 
     257                 : /* {{{ proto bool syslog(int priority, string message)
     258                 :    Generate a system log message */
     259                 : PHP_FUNCTION(syslog)
     260               0 : {
     261                 :         long priority;
     262                 :         char *message;
     263                 :         int message_len;
     264                 : 
     265               0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority,
     266                 :                                                           &message, &message_len) == FAILURE) {
     267               0 :                 return;
     268                 :         }
     269                 : 
     270               0 :         php_syslog(priority, "%s", message);
     271               0 :         RETURN_TRUE;
     272                 : }
     273                 : /* }}} */
     274                 : 
     275                 : #endif
     276                 : 
     277                 : /*
     278                 :  * Local variables:
     279                 :  * tab-width: 4
     280                 :  * c-basic-offset: 4
     281                 :  * End:
     282                 :  * vim600: sw=4 ts=4 fdm=marker
     283                 :  * vim<600: sw=4 ts=4
     284                 :  */

Generated by: LTP GCOV extension version 1.5