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: 63 67 94.0 %
Date: 2014-12-13 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 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             : /* {{{ PHP_MINIT_FUNCTION
      40             :  */
      41       20622 : PHP_MINIT_FUNCTION(syslog)
      42             : {
      43             :         /* error levels */
      44       20622 :         REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
      45       20622 :         REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
      46       20622 :         REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */
      47       20622 :         REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT); 
      48       20622 :         REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
      49       20622 :         REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
      50       20622 :         REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
      51       20622 :         REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
      52             :         /* facility: type of program logging the message */
      53       20622 :         REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
      54       20622 :         REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */
      55       20622 :         REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */
      56       20622 :         REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */
      57       20622 :         REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
      58       20622 :         REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
      59       20622 :         REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
      60             : #ifdef LOG_NEWS
      61             :         /* No LOG_NEWS on HP-UX */
      62       20622 :         REGISTER_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */
      63             : #endif
      64             : #ifdef LOG_UUCP
      65             :         /* No LOG_UUCP on HP-UX */
      66       20622 :         REGISTER_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT);
      67             : #endif
      68             : #ifdef LOG_CRON
      69             :         /* apparently some systems don't have this one */
      70       20622 :         REGISTER_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT);
      71             : #endif
      72             : #ifdef LOG_AUTHPRIV
      73             :         /* AIX doesn't have LOG_AUTHPRIV */
      74       20622 :         REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
      75             : #endif
      76             : #ifndef PHP_WIN32
      77       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
      78       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
      79       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
      80       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
      81       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
      82       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
      83       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
      84       20622 :         REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
      85             : #endif
      86             :         /* options */
      87       20622 :         REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
      88       20622 :         REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
      89       20622 :         REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
      90       20622 :         REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
      91             : #ifdef LOG_NOWAIT
      92       20622 :         REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT);
      93             : #endif
      94             : #ifdef LOG_PERROR
      95             :         /* AIX doesn't have LOG_PERROR */
      96       20622 :         REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
      97             : #endif
      98       20622 :         BG(syslog_device)=NULL;
      99             : 
     100       20622 :         return SUCCESS;
     101             : }
     102             : /* }}} */
     103             : 
     104       20579 : PHP_RINIT_FUNCTION(syslog)
     105             : {
     106       20579 :         BG(syslog_device) = NULL;
     107       20579 :         return SUCCESS;
     108             : }
     109             : 
     110             : 
     111             : #ifdef PHP_WIN32
     112             : PHP_RSHUTDOWN_FUNCTION(syslog)
     113             : {
     114             :         closelog();
     115             :         return SUCCESS;
     116             : }
     117             : #endif
     118             : 
     119       20656 : PHP_MSHUTDOWN_FUNCTION(syslog)
     120             : {
     121       20656 :         if (BG(syslog_device)) {
     122           0 :                 free(BG(syslog_device));
     123           0 :                 BG(syslog_device) = NULL;
     124             :         }
     125       20656 :         return SUCCESS;
     126             : }
     127             : 
     128             : /* {{{ proto bool openlog(string ident, int option, int facility)
     129             :    Open connection to system logger */
     130             : /*
     131             :    ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
     132             :    ** Syslog($LOG_EMERG, "help me!")
     133             :    ** CloseLog();
     134             :  */
     135           3 : PHP_FUNCTION(openlog)
     136             : {
     137             :         char *ident;
     138             :         zend_long option, facility;
     139             :         size_t ident_len;
     140             : 
     141           3 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident,
     142             :                                                           &ident_len, &option, &facility) == FAILURE) {
     143           2 :                 return;
     144             :         }
     145           1 :         if (BG(syslog_device)) {
     146           0 :                 free(BG(syslog_device));
     147             :         }
     148           1 :         BG(syslog_device) = zend_strndup(ident, ident_len);
     149           1 :         if(BG(syslog_device) == NULL) {
     150           0 :                 RETURN_FALSE;
     151             :         }
     152           1 :         openlog(BG(syslog_device), option, facility);
     153           1 :         RETURN_TRUE;
     154             : }
     155             : /* }}} */
     156             : 
     157             : /* {{{ proto bool closelog(void)
     158             :    Close connection to system logger */
     159           4 : PHP_FUNCTION(closelog)
     160             : {
     161           4 :         if (zend_parse_parameters_none() == FAILURE) {
     162           2 :                 return;
     163             :         }
     164             : 
     165           2 :         closelog();
     166           2 :         if (BG(syslog_device)) {
     167           1 :                 free(BG(syslog_device));
     168           1 :                 BG(syslog_device)=NULL;
     169             :         }
     170           2 :         RETURN_TRUE;
     171             : }
     172             : /* }}} */
     173             : 
     174             : /* {{{ proto bool syslog(int priority, string message)
     175             :    Generate a system log message */
     176           5 : PHP_FUNCTION(syslog)
     177             : {
     178             :         zend_long priority;
     179             :         char *message;
     180             :         size_t message_len;
     181             : 
     182           5 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority,
     183             :                                                           &message, &message_len) == FAILURE) {
     184           4 :                 return;
     185             :         }
     186             : 
     187           1 :         php_syslog(priority, "%s", message);
     188           1 :         RETURN_TRUE;
     189             : }
     190             : /* }}} */
     191             : 
     192             : #endif
     193             : 
     194             : /*
     195             :  * Local variables:
     196             :  * tab-width: 4
     197             :  * c-basic-offset: 4
     198             :  * End:
     199             :  * vim600: sw=4 ts=4 fdm=marker
     200             :  * vim<600: sw=4 ts=4
     201             :  */

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:22 +0000 (6 days ago)

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