32
32
#define syslog std_syslog
33
33
#endif
34
34
35
+ PHPAPI void php_syslog_str (int priority , const zend_string * message )
36
+ {
37
+ smart_string sbuf = {0 };
38
+
39
+ if (PG (syslog_filter ) == PHP_SYSLOG_FILTER_RAW ) {
40
+ /* Just send it directly to the syslog */
41
+ syslog (priority , "%s" , ZSTR_VAL (message ));
42
+ return ;
43
+ }
44
+
45
+ /* We use < because we don't want the final NUL byte to be converted to '\x00' */
46
+ for (size_t i = 0 ; i < ZSTR_LEN (message ); ++ i ) {
47
+ unsigned char c = ZSTR_VAL (message )[i ];
48
+
49
+ /* check for NVT ASCII only unless test disabled */
50
+ if (((0x20 <= c ) && (c <= 0x7e ))) {
51
+ smart_string_appendc (& sbuf , c );
52
+ } else if ((c >= 0x80 ) && (PG (syslog_filter ) != PHP_SYSLOG_FILTER_ASCII )) {
53
+ smart_string_appendc (& sbuf , c );
54
+ } else if (c == '\n' ) {
55
+ /* Smart string is not NUL terminated */
56
+ syslog (priority , "%.*s" , (int )sbuf .len , sbuf .c );
57
+ smart_string_reset (& sbuf );
58
+ } else if ((c < 0x20 ) && (PG (syslog_filter ) == PHP_SYSLOG_FILTER_ALL )) {
59
+ smart_string_appendc (& sbuf , c );
60
+ } else {
61
+ const char xdigits [] = "0123456789abcdef" ;
62
+
63
+ smart_string_appendl (& sbuf , "\\x" , 2 );
64
+ smart_string_appendc (& sbuf , xdigits [c >> 4 ]);
65
+ smart_string_appendc (& sbuf , xdigits [c & 0xf ]);
66
+ }
67
+ }
68
+
69
+ /* Smart string is not NUL terminated */
70
+ syslog (priority , "%.*s" , (int )sbuf .len , sbuf .c );
71
+ smart_string_free (& sbuf );
72
+ }
73
+
35
74
#ifdef PHP_WIN32
36
75
PHPAPI void php_syslog (int priority , const char * format , ...) /* {{{ */
37
76
{
@@ -54,10 +93,7 @@ PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
54
93
#else
55
94
PHPAPI void php_syslog (int priority , const char * format , ...) /* {{{ */
56
95
{
57
- const char * ptr ;
58
- unsigned char c ;
59
- smart_string fbuf = {0 };
60
- smart_string sbuf = {0 };
96
+ zend_string * fbuf = NULL ;
61
97
va_list args ;
62
98
63
99
/*
@@ -70,46 +106,12 @@ PHPAPI void php_syslog(int priority, const char *format, ...) /* {{{ */
70
106
}
71
107
72
108
va_start (args , format );
73
- zend_printf_to_smart_string (& fbuf , format , args );
74
- smart_string_0 (& fbuf );
109
+ fbuf = zend_vstrpprintf (0 , format , args );
75
110
va_end (args );
76
111
77
- if (PG (syslog_filter ) == PHP_SYSLOG_FILTER_RAW ) {
78
- /* Just send it directly to the syslog */
79
- syslog (priority , "%.*s" , (int )fbuf .len , fbuf .c );
80
- smart_string_free (& fbuf );
81
- return ;
82
- }
83
-
84
- for (ptr = fbuf .c ; ; ++ ptr ) {
85
- c = * ptr ;
86
- if (c == '\0' ) {
87
- syslog (priority , "%.*s" , (int )sbuf .len , sbuf .c );
88
- break ;
89
- }
90
-
91
- /* check for NVT ASCII only unless test disabled */
92
- if (((0x20 <= c ) && (c <= 0x7e )))
93
- smart_string_appendc (& sbuf , c );
94
- else if ((c >= 0x80 ) && (PG (syslog_filter ) != PHP_SYSLOG_FILTER_ASCII ))
95
- smart_string_appendc (& sbuf , c );
96
- else if (c == '\n' ) {
97
- syslog (priority , "%.*s" , (int )sbuf .len , sbuf .c );
98
- smart_string_reset (& sbuf );
99
- } else if ((c < 0x20 ) && (PG (syslog_filter ) == PHP_SYSLOG_FILTER_ALL ))
100
- smart_string_appendc (& sbuf , c );
101
- else {
102
- const char xdigits [] = "0123456789abcdef" ;
103
-
104
- smart_string_appendl (& sbuf , "\\x" , 2 );
105
- smart_string_appendc (& sbuf , xdigits [(c / 0x10 )]);
106
- c &= 0x0f ;
107
- smart_string_appendc (& sbuf , xdigits [c ]);
108
- }
109
- }
112
+ php_syslog_str (priority , fbuf );
110
113
111
- smart_string_free (& fbuf );
112
- smart_string_free (& sbuf );
114
+ zend_string_release (fbuf );
113
115
}
114
116
/* }}} */
115
117
#endif
0 commit comments