55
55
/* PHP array helpers */
56
56
#include "php_array_api.h"
57
57
58
+ /* For our stream verifications */
59
+ #include <openssl/x509.h>
60
+
58
61
/* Our Compatability header */
59
62
#include "phongo_compat.h"
60
63
@@ -206,62 +209,14 @@ static void php_phongo_log(mongoc_log_level_t log_level, const char *log_domain,
206
209
case MONGOC_LOG_LEVEL_DEBUG :
207
210
case MONGOC_LOG_LEVEL_TRACE :
208
211
{
209
- int fd = -1 ;
210
212
time_t t ;
211
213
char * dt = NULL ;
212
214
213
- if (!MONGODB_G (debug ) || !strlen (MONGODB_G (debug ))) {
214
- return ;
215
- }
216
- if (strcasecmp (MONGODB_G (debug ), "off" ) == 0 ) {
217
- return ;
218
- }
219
- if (strcasecmp (MONGODB_G (debug ), "0" ) == 0 ) {
220
- return ;
221
- }
222
-
223
- #define PHONGO_DEBUG_LOG_FORMAT "[%s] %10s: %-8s> %s\n"
224
-
225
215
time (& t );
226
216
dt = php_format_date ((char * )"Y-m-d\\TH:i:sP" , strlen ("Y-m-d\\TH:i:sP" ), t , 0 TSRMLS_CC );
227
217
228
- if (strcasecmp (MONGODB_G (debug ), "stderr" ) == 0 ) {
229
- fprintf (stderr , PHONGO_DEBUG_LOG_FORMAT , dt , log_domain , mongoc_log_level_str (log_level ), message );
230
- } else if (strcasecmp (MONGODB_G (debug ), "stdout" ) == 0 ) {
231
- php_printf (PHONGO_DEBUG_LOG_FORMAT , dt , log_domain , mongoc_log_level_str (log_level ), message );
232
- } else if (MONGODB_G (debug_filename )) {
233
- fd = VCWD_OPEN_MODE (MONGODB_G (debug_filename ), O_CREAT | O_APPEND | O_WRONLY , 0644 );
234
- } else {
235
- char * prefix ;
236
- int len ;
237
- char * filename ;
238
-
239
- len = spprintf (& prefix , 0 , "PHONGO-%ld" , t );
240
-
241
- if (strcasecmp (MONGODB_G (debug ), "on" ) == 0 || strcasecmp (MONGODB_G (debug ), "1" ) == 0 ) {
242
- fd = php_open_temporary_fd (NULL , prefix , & filename TSRMLS_CC );
243
- } else {
244
- fd = php_open_temporary_fd (MONGODB_G (debug ), prefix , & filename TSRMLS_CC );
245
- }
246
- if (fd != -1 ) {
247
- MONGODB_G (debug_filename ) = pestrdup (filename , 1 );
248
- efree (filename );
249
- }
250
- efree (prefix );
251
- }
252
-
253
- if (fd != -1 ) {
254
- char * tmp ;
255
- int len ;
256
-
257
- len = spprintf (& tmp , 0 , PHONGO_DEBUG_LOG_FORMAT , dt , log_domain , mongoc_log_level_str (log_level ), message );
258
- #ifdef PHP_WIN32
259
- php_flock (fd , 2 );
260
- #endif
261
- php_ignore_value (write (fd , tmp , len ));
262
- efree (tmp );
263
- close (fd );
264
- }
218
+ fprintf (MONGODB_G (debug_fd ), "[%s] %10s: %-8s> %s\n" , dt , log_domain , mongoc_log_level_str (log_level ), message );
219
+ fflush (MONGODB_G (debug_fd ));
265
220
efree (dt );
266
221
} break ;
267
222
}
@@ -1553,7 +1508,7 @@ void php_phongo_cursor_to_zval(zval *retval, php_phongo_cursor_t *cursor) /* {{{
1553
1508
/* }}} */
1554
1509
1555
1510
1556
- mongoc_uri_t * php_phongo_make_uri (const char * uri_string , bson_t * options TSRMLS_DC ) /* {{{ */
1511
+ mongoc_uri_t * php_phongo_make_uri (const char * uri_string , bson_t * options ) /* {{{ */
1557
1512
{
1558
1513
bson_iter_t iter ;
1559
1514
mongoc_uri_t * uri ;
@@ -2280,9 +2235,78 @@ void _phongo_debug_bson(bson_t *bson)
2280
2235
2281
2236
/* {{{ M[INIT|SHUTDOWN] R[INIT|SHUTDOWN] G[INIT|SHUTDOWN] MINFO INI */
2282
2237
2238
+ ZEND_INI_MH (OnUpdateDebug )
2239
+ {
2240
+ void * * * ctx = NULL ;
2241
+ char * tmp_dir = NULL ;
2242
+
2243
+ TSRMLS_SET_CTX (ctx );
2244
+
2245
+ /* Close any previously open log files */
2246
+ if (MONGODB_G (debug_fd )) {
2247
+ if (MONGODB_G (debug_fd ) != stderr && MONGODB_G (debug_fd ) != stdout ) {
2248
+ fclose (MONGODB_G (debug_fd ));
2249
+ }
2250
+ MONGODB_G (debug_fd ) = NULL ;
2251
+ }
2252
+
2253
+ if (!new_value_length
2254
+ || strcasecmp ("0" , new_value ) == 0
2255
+ || strcasecmp ("off" , new_value ) == 0
2256
+ || strcasecmp ("no" , new_value ) == 0
2257
+ || strcasecmp ("false" , new_value ) == 0
2258
+ ) {
2259
+ mongoc_log_trace_disable ();
2260
+ mongoc_log_set_handler (NULL , NULL );
2261
+
2262
+ return OnUpdateString (entry , new_value , new_value_length , mh_arg1 , mh_arg2 , mh_arg3 , stage TSRMLS_CC );
2263
+ }
2264
+
2265
+
2266
+ if (strcasecmp (new_value , "stderr" ) == 0 ) {
2267
+ MONGODB_G (debug_fd ) = stderr ;
2268
+ } else if (strcasecmp (new_value , "stdout" ) == 0 ) {
2269
+ MONGODB_G (debug_fd ) = stdout ;
2270
+ } else if (
2271
+ strcasecmp ("1" , new_value ) == 0
2272
+ || strcasecmp ("on" , new_value ) == 0
2273
+ || strcasecmp ("yes" , new_value ) == 0
2274
+ || strcasecmp ("true" , new_value ) == 0
2275
+ ) {
2276
+ tmp_dir = NULL ;
2277
+ } else {
2278
+ tmp_dir = new_value ;
2279
+ }
2280
+
2281
+ if (!MONGODB_G (debug_fd )) {
2282
+ time_t t ;
2283
+ int fd = -1 ;
2284
+ char * prefix ;
2285
+ int len ;
2286
+ char * filename ;
2287
+
2288
+ time (& t );
2289
+ len = spprintf (& prefix , 0 , "PHONGO-%ld" , t );
2290
+
2291
+ fd = php_open_temporary_fd (tmp_dir , prefix , & filename TSRMLS_CC );
2292
+ if (fd != -1 ) {
2293
+ MONGODB_G (debug_fd ) = VCWD_FOPEN (filename , "a" );
2294
+ }
2295
+ efree (filename );
2296
+ efree (prefix );
2297
+ close (fd );
2298
+ }
2299
+
2300
+ mongoc_log_trace_enable ();
2301
+ mongoc_log_set_handler (php_phongo_log , ctx );
2302
+
2303
+ return OnUpdateString (entry , new_value , new_value_length , mh_arg1 , mh_arg2 , mh_arg3 , stage TSRMLS_CC );
2304
+ }
2305
+
2306
+
2283
2307
/* {{{ INI entries */
2284
2308
PHP_INI_BEGIN ()
2285
- { 0 , PHP_INI_ALL , (char * )PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI ), OnUpdateString , (void * ) XtOffsetOf (zend_mongodb_globals , debug ), (void * ) & mglo , NULL , (char * )PHONGO_DEBUG_INI_DEFAULT , sizeof (PHONGO_DEBUG_INI_DEFAULT )- 1 , NULL , 0 , 0 , 0 , NULL },
2309
+ { 0 , PHP_INI_ALL , (char * )PHONGO_DEBUG_INI , sizeof (PHONGO_DEBUG_INI ), OnUpdateDebug , (void * ) XtOffsetOf (zend_mongodb_globals , debug ), (void * ) & mglo , NULL , (char * )PHONGO_DEBUG_INI_DEFAULT , sizeof (PHONGO_DEBUG_INI_DEFAULT )- 1 , NULL , 0 , 0 , 0 , NULL },
2286
2310
PHP_INI_END ()
2287
2311
/* }}} */
2288
2312
@@ -2295,8 +2319,7 @@ PHP_GINIT_FUNCTION(mongodb)
2295
2319
php_phongo_realloc ,
2296
2320
php_phongo_free ,
2297
2321
};
2298
- mongodb_globals -> debug = NULL ;
2299
- mongodb_globals -> debug_filename = NULL ;
2322
+ mongodb_globals -> debug_fd = NULL ;
2300
2323
mongodb_globals -> bsonMemVTable = bsonMemVTable ;
2301
2324
2302
2325
}
@@ -2305,8 +2328,6 @@ PHP_GINIT_FUNCTION(mongodb)
2305
2328
/* {{{ PHP_MINIT_FUNCTION */
2306
2329
PHP_MINIT_FUNCTION (mongodb )
2307
2330
{
2308
- void * * * ctx = NULL ;
2309
- TSRMLS_SET_CTX (ctx );
2310
2331
(void )type ; /* We don't care if we are loaded via dl() or extension= */
2311
2332
2312
2333
@@ -2316,7 +2337,6 @@ PHP_MINIT_FUNCTION(mongodb)
2316
2337
mongoc_init ();
2317
2338
/* Initialize libbson */
2318
2339
bson_mem_set_vtable (& MONGODB_G (bsonMemVTable ));
2319
- mongoc_log_set_handler (php_phongo_log , ctx );
2320
2340
2321
2341
/* Prep default object handlers to be used when we register the classes */
2322
2342
memcpy (& phongo_std_object_handlers , zend_get_std_object_handlers (), sizeof (zend_object_handlers ));
@@ -2399,9 +2419,9 @@ PHP_MSHUTDOWN_FUNCTION(mongodb)
2399
2419
PHP_GSHUTDOWN_FUNCTION (mongodb )
2400
2420
{
2401
2421
mongodb_globals -> debug = NULL ;
2402
- if (mongodb_globals -> debug_filename ) {
2403
- pefree (mongodb_globals -> debug_filename , 1 );
2404
- mongodb_globals -> debug_filename = NULL ;
2422
+ if (mongodb_globals -> debug_fd ) {
2423
+ fclose (mongodb_globals -> debug_fd );
2424
+ mongodb_globals -> debug_fd = NULL ;
2405
2425
}
2406
2426
}
2407
2427
/* }}} */
0 commit comments