PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - syslog.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 106 109 97.2 %
Date: 2014-04-18 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2013 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$ */
      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       19341 : PHP_MINIT_FUNCTION(syslog)
      44             : {
      45             :         /* error levels */
      46       19341 :         REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
      47       19341 :         REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
      48       19341 :         REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */
      49       19341 :         REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT); 
      50       19341 :         REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
      51       19341 :         REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
      52       19341 :         REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
      53       19341 :         REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
      54             :         /* facility: type of program logging the message */
      55       19341 :         REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
      56       19341 :         REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */
      57       19341 :         REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */
      58       19341 :         REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */
      59       19341 :         REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
      60       19341 :         REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
      61       19341 :         REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
      62             : #ifdef LOG_NEWS
      63             :         /* No LOG_NEWS on HP-UX */
      64       19341 :         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       19341 :         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       19341 :         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       19341 :         REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
      77             : #endif
      78             : #ifndef PHP_WIN32
      79       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
      80       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
      81       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
      82       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
      83       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
      84       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
      85       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
      86       19341 :         REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
      87             : #endif
      88             :         /* options */
      89       19341 :         REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
      90       19341 :         REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
      91       19341 :         REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
      92       19341 :         REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
      93             : #ifdef LOG_NOWAIT
      94       19341 :         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       19341 :         REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
      99             : #endif
     100       19341 :         BG(syslog_device)=NULL;
     101             : 
     102       19341 :         return SUCCESS;
     103             : }
     104             : /* }}} */
     105             : 
     106       19327 : PHP_RINIT_FUNCTION(syslog)
     107             : {
     108       19327 :         if (INI_INT("define_syslog_variables")) {
     109           1 :                 start_syslog(TSRMLS_C);
     110             :         } else {
     111       19326 :                 BG(syslog_started)=0;
     112             :         }
     113       19327 :         BG(syslog_device) = NULL;
     114       19327 :         return SUCCESS;
     115             : }
     116             : 
     117             : 
     118             : #ifdef PHP_WIN32
     119             : PHP_RSHUTDOWN_FUNCTION(syslog)
     120             : {
     121             :         closelog();
     122             :         return SUCCESS;
     123             : }
     124             : #endif
     125             : 
     126       19376 : PHP_MSHUTDOWN_FUNCTION(syslog)
     127             : {
     128       19376 :         if (BG(syslog_device)) {
     129           0 :                 free(BG(syslog_device));
     130           0 :                 BG(syslog_device) = NULL;
     131             :         }
     132       19376 :         return SUCCESS;
     133             : }
     134             : 
     135             : /* {{{ start_syslog
     136             :  */
     137           4 : static void start_syslog(TSRMLS_D)
     138             : {
     139             :         /* error levels */
     140          12 :         SET_VAR_LONG("LOG_EMERG", LOG_EMERG); /* system unusable */
     141          12 :         SET_VAR_LONG("LOG_ALERT", LOG_ALERT); /* immediate action required */
     142          12 :         SET_VAR_LONG("LOG_CRIT", LOG_CRIT); /* critical conditions */
     143          12 :         SET_VAR_LONG("LOG_ERR", LOG_ERR); 
     144          12 :         SET_VAR_LONG("LOG_WARNING", LOG_WARNING);
     145          12 :         SET_VAR_LONG("LOG_NOTICE", LOG_NOTICE);
     146          12 :         SET_VAR_LONG("LOG_INFO", LOG_INFO);
     147          12 :         SET_VAR_LONG("LOG_DEBUG", LOG_DEBUG);
     148             :         /* facility: type of program logging the message */
     149          12 :         SET_VAR_LONG("LOG_KERN", LOG_KERN);
     150          12 :         SET_VAR_LONG("LOG_USER", LOG_USER); /* generic user level */
     151          12 :         SET_VAR_LONG("LOG_MAIL", LOG_MAIL); /* log to email */
     152          12 :         SET_VAR_LONG("LOG_DAEMON", LOG_DAEMON); /* other system daemons */
     153          12 :         SET_VAR_LONG("LOG_AUTH", LOG_AUTH);
     154             : #ifndef NETWARE
     155          12 :         SET_VAR_LONG("LOG_SYSLOG", LOG_SYSLOG);
     156             : #endif
     157          12 :         SET_VAR_LONG("LOG_LPR", LOG_LPR);
     158             : #ifdef LOG_NEWS
     159             :         /* No LOG_NEWS on HP-UX */
     160          12 :         SET_VAR_LONG("LOG_NEWS", LOG_NEWS); /* usenet new */
     161             : #endif
     162             : #ifdef LOG_UUCP
     163             :         /* No LOG_UUCP on HP-UX */
     164          12 :         SET_VAR_LONG("LOG_UUCP", LOG_UUCP);
     165             : #endif
     166             : #ifdef LOG_CRON
     167             :         /* apparently some systems don't have this one */
     168          12 :         SET_VAR_LONG("LOG_CRON", LOG_CRON);
     169             : #endif
     170             : #ifdef LOG_AUTHPRIV
     171             :         /* AIX doesn't have LOG_AUTHPRIV */
     172          12 :         SET_VAR_LONG("LOG_AUTHPRIV", LOG_AUTHPRIV);
     173             : #endif
     174             : #if !defined(PHP_WIN32) && !defined(NETWARE)
     175          12 :         SET_VAR_LONG("LOG_LOCAL0", LOG_LOCAL0);
     176          12 :         SET_VAR_LONG("LOG_LOCAL1", LOG_LOCAL1);
     177          12 :         SET_VAR_LONG("LOG_LOCAL2", LOG_LOCAL2);
     178          12 :         SET_VAR_LONG("LOG_LOCAL3", LOG_LOCAL3);
     179          12 :         SET_VAR_LONG("LOG_LOCAL4", LOG_LOCAL4);
     180          12 :         SET_VAR_LONG("LOG_LOCAL5", LOG_LOCAL5);
     181          12 :         SET_VAR_LONG("LOG_LOCAL6", LOG_LOCAL6);
     182          12 :         SET_VAR_LONG("LOG_LOCAL7", LOG_LOCAL7);
     183             : #endif
     184             :         /* options */
     185          12 :         SET_VAR_LONG("LOG_PID", LOG_PID);
     186          12 :         SET_VAR_LONG("LOG_CONS", LOG_CONS);
     187          12 :         SET_VAR_LONG("LOG_ODELAY", LOG_ODELAY);
     188          12 :         SET_VAR_LONG("LOG_NDELAY", LOG_NDELAY);
     189             : #ifdef LOG_NOWAIT
     190             :         /* BeOS doesn't have LOG_NOWAIT */
     191          12 :         SET_VAR_LONG("LOG_NOWAIT", LOG_NOWAIT);
     192             : #endif
     193             : #ifdef LOG_PERROR
     194             :         /* AIX doesn't have LOG_PERROR */
     195          12 :         SET_VAR_LONG("LOG_PERROR", LOG_PERROR); /*log to stderr*/
     196             : #endif
     197             : 
     198           4 :         BG(syslog_started)=1;
     199           4 : }
     200             : /* }}} */
     201             : 
     202             : /* {{{ proto void define_syslog_variables(void)
     203             :    Initializes all syslog-related variables */
     204           4 : PHP_FUNCTION(define_syslog_variables)
     205             : {
     206           4 :         if (zend_parse_parameters_none() == FAILURE) {
     207           1 :                 return;
     208             :         }
     209             : 
     210           3 :         if (!BG(syslog_started)) {
     211           3 :                 start_syslog(TSRMLS_C);
     212             :         }
     213             : }
     214             : /* }}} */
     215             : 
     216             : /* {{{ proto bool openlog(string ident, int option, int facility)
     217             :    Open connection to system logger */
     218             : /*
     219             :    ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
     220             :    ** Syslog($LOG_EMERG, "help me!")
     221             :    ** CloseLog();
     222             :  */
     223           3 : PHP_FUNCTION(openlog)
     224             : {
     225             :         char *ident;
     226             :         long option, facility;
     227             :         int ident_len;
     228             : 
     229           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident,
     230             :                                                           &ident_len, &option, &facility) == FAILURE) {
     231           2 :                 return;
     232             :         }
     233           1 :         if (BG(syslog_device)) {
     234           0 :                 free(BG(syslog_device));
     235             :         }
     236           1 :         BG(syslog_device) = zend_strndup(ident, ident_len);
     237           1 :         openlog(BG(syslog_device), option, facility);
     238           1 :         RETURN_TRUE;
     239             : }
     240             : /* }}} */
     241             : 
     242             : /* {{{ proto bool closelog(void)
     243             :    Close connection to system logger */
     244           4 : PHP_FUNCTION(closelog)
     245             : {
     246           4 :         if (zend_parse_parameters_none() == FAILURE) {
     247           2 :                 return;
     248             :         }
     249             : 
     250           2 :         closelog();
     251           2 :         if (BG(syslog_device)) {
     252           1 :                 free(BG(syslog_device));
     253           1 :                 BG(syslog_device)=NULL;
     254             :         }
     255           2 :         RETURN_TRUE;
     256             : }
     257             : /* }}} */
     258             : 
     259             : /* {{{ proto bool syslog(int priority, string message)
     260             :    Generate a system log message */
     261           5 : PHP_FUNCTION(syslog)
     262             : {
     263             :         long priority;
     264             :         char *message;
     265             :         int message_len;
     266             : 
     267           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority,
     268             :                                                           &message, &message_len) == FAILURE) {
     269           4 :                 return;
     270             :         }
     271             : 
     272           1 :         php_syslog(priority, "%s", message);
     273           1 :         RETURN_TRUE;
     274             : }
     275             : /* }}} */
     276             : 
     277             : #endif
     278             : 
     279             : /*
     280             :  * Local variables:
     281             :  * tab-width: 4
     282             :  * c-basic-offset: 4
     283             :  * End:
     284             :  * vim600: sw=4 ts=4 fdm=marker
     285             :  * vim<600: sw=4 ts=4
     286             :  */

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:36 +0000 (34 hours ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.