/* * We hook into zend_compile_file to abort file compilation if necessary. */ static zend_op_array* my_compile_file(zend_file_handle* h, int type TSRMLS_DC) { bool file_ok = INI_BOOL("pwxe.filter") ? file_runnable(h->filename) : true; if (file_ok) { return old_compile_file(h, type TSRMLS_CC); } else { zend_error(E_COMPILE_ERROR, "Writable (or owned) file blocked by PWXE: \"%s\".", h->filename); return FAILURE; } }
static void notifyerror_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) /* {{{ */ { va_list args_cp; char *buffer, *error_message, *header; int log_level = 0; va_copy(args_cp, args); vspprintf(&buffer, PG(log_errors_max_len), format, args); spprintf(&error_message, 0, "%s\nin %s on line %d", buffer, error_filename, error_lineno); efree(buffer); switch (type) { case E_CORE_ERROR: case E_ERROR: case E_COMPILE_ERROR: case E_USER_ERROR: header = "PHP Fatal Error"; log_level = 1; break; case E_RECOVERABLE_ERROR: header = "PHP Recoverable Fatal Error"; log_level = 2; break; case E_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: header = "PHP Warning"; log_level = 2; break; case E_PARSE: header = "PHP Parse Error"; log_level = 1; break; case E_NOTICE: case E_USER_NOTICE: header = "PHP Notice"; log_level = 2; break; case E_STRICT: header = "PHP Strict Error"; log_level = 2; break; #ifdef E_DEPRECATED case E_DEPRECATED: case E_USER_DEPRECATED: header = "PHP Deprecation"; log_level = 3; break; #endif default: header = "Unknown PHP Error"; log_level = 3; break; } zend_bool enabled = INI_BOOL("errornotify.enable"); char * email = INI_STR("errornotify.email"); int currentLogLevel = INI_INT("errornotify.loglevel"); if(enabled && email != "") { if(currentLogLevel >= log_level ) { char * subject; char hostname[1024]; hostname[1023] = '\0'; gethostname(hostname, 1023); php_sprintf(subject,"%s [%s]",hostname,header); php_mail(email,subject,error_message,NULL,NULL); //printf("\n\n Error => %s \n\n%s\n\n",subject,error_message); } efree(error_message); } orig_error_cb(type, error_filename, error_lineno, format, args); }
/* {{{ proto object ffmpeg_movie(string filename) Constructor for ffmpeg_movie objects */ FFMPEG_PHP_CONSTRUCTOR(ffmpeg_movie, __construct) { int hashkey_length = 0, filename_len; char *filename = NULL, *fullpath = NULL, *hashkey = NULL; zend_bool persistent = 0; ff_movie_context *ffmovie_ctx = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &filename_len, &persistent) != SUCCESS) { return; } if (persistent && !INI_BOOL("ffmpeg.allow_persistent")) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Persistent movies have been disabled in php.ini"); RETURN_FALSE; } if (persistent) { zend_rsrc_list_entry *le; /* resolve the fully-qualified path name to use as the hash key */ fullpath = expand_filepath(filename, NULL TSRMLS_CC); hashkey_length = sizeof("ffmpeg-php_")-1 + filename_len; hashkey = (char *) emalloc(hashkey_length+1); snprintf(hashkey, hashkey_length, "ffmpeg-php_%s", filename); /* do we have an existing persistent movie? */ if (SUCCESS == zend_hash_find(&EG(persistent_list), hashkey, hashkey_length+1, (void**)&le)) { int type; if (Z_TYPE_P(le) != le_ffmpeg_pmovie) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to retrieve persistent resource"); efree(hashkey); RETURN_FALSE; } ffmovie_ctx = (ff_movie_context*)le->ptr; /* sanity check to ensure that the resource is still a valid * regular resource number */ if (zend_list_find(ffmovie_ctx->rsrc_id, &type) == ffmovie_ctx) { /* add a reference to the persistent movie */ zend_list_addref(ffmovie_ctx->rsrc_id); } else { //php_error_docref(NULL TSRMLS_CC, E_ERROR, //"Not a valid persistent movie resource"); ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_pmovie); } } else { /* no existing persistant movie, create one */ zend_rsrc_list_entry new_le; ffmovie_ctx = _php_alloc_ffmovie_ctx(1); if (_php_open_movie_file(ffmovie_ctx, filename)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't open movie file %s", filename); ZVAL_BOOL(getThis(), 0); RETURN_FALSE; } Z_TYPE(new_le) = le_ffmpeg_pmovie; new_le.ptr = ffmovie_ctx; if (FAILURE == zend_hash_update(&EG(persistent_list), hashkey, hashkey_length+1, (void *)&new_le, sizeof(zend_rsrc_list_entry), NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to register persistent resource"); RETURN_FALSE; } ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_pmovie); } } else { ffmovie_ctx = _php_alloc_ffmovie_ctx(0); if (_php_open_movie_file(ffmovie_ctx, filename)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't open movie file %s", filename); ZVAL_BOOL(getThis(), 0); RETURN_FALSE; } /* pass NULL for resource result since we're not returning the resource directly, but adding it to the returned object. */ ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_movie); } object_init_ex(getThis(), ffmpeg_movie_class_entry_ptr); add_property_resource(getThis(), "ffmpeg_movie", ffmovie_ctx->rsrc_id); if (fullpath) { efree(fullpath); } if (hashkey) { efree(hashkey); } }
/* {{{ proto object ffmpeg_movie(string filename) Constructor for ffmpeg_movie objects */ FFMPEG_PHP_CONSTRUCTOR(ffmpeg_movie, __construct) { int persistent = 0, hashkey_length = 0; char *filename = NULL, *fullpath = NULL, *hashkey = NULL; zval ***argv; ff_movie_context *ffmovie_ctx = NULL; /* retrieve arguments */ argv = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS(), 0); if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), argv) != SUCCESS) { efree(argv); php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error parsing arguments"); } switch (ZEND_NUM_ARGS()) { case 2: convert_to_boolean_ex(argv[1]); if (! INI_BOOL("ffmpeg.allow_persistent") && Z_LVAL_PP(argv[1])) { zend_error(E_WARNING, "Persistent movies have been disabled in php.ini"); break; } persistent = Z_LVAL_PP(argv[1]); /* fallthru */ case 1: convert_to_string_ex(argv[0]); filename = Z_STRVAL_PP(argv[0]); break; default: WRONG_PARAM_COUNT; } if (persistent) { list_entry *le; /* resolve the fully-qualified path name to use as the hash key */ fullpath = expand_filepath(filename, NULL TSRMLS_CC); hashkey_length = sizeof("ffmpeg-php_")-1 + strlen(SAFE_STRING(filename)); hashkey = (char *) emalloc(hashkey_length+1); snprintf(hashkey, hashkey_length, "ffmpeg-php_%s", SAFE_STRING(filename)); /* do we have an existing persistent movie? */ if (SUCCESS == zend_hash_find(&EG(persistent_list), hashkey, hashkey_length+1, (void**)&le)) { int type; if (Z_TYPE_P(le) != le_ffmpeg_pmovie) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed to retrieve persistent resource"); } ffmovie_ctx = (ff_movie_context*)le->ptr; /* sanity check to ensure that the resource is still a valid * regular resource number */ if (zend_list_find(ffmovie_ctx->rsrc_id, &type) == ffmovie_ctx) { /* add a reference to the persistent movie */ zend_list_addref(ffmovie_ctx->rsrc_id); } else { //php_error_docref(NULL TSRMLS_CC, E_ERROR, //"Not a valid persistent movie resource"); ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_pmovie); } } else { /* no existing persistant movie, create one */ list_entry new_le; ffmovie_ctx = _php_alloc_ffmovie_ctx(1); if (_php_open_movie_file(ffmovie_ctx, filename)) { zend_error(E_WARNING, "Can't open movie file %s", filename); efree(argv); ZVAL_BOOL(getThis(), 0); RETURN_FALSE; } Z_TYPE(new_le) = le_ffmpeg_pmovie; new_le.ptr = ffmovie_ctx; if (FAILURE == zend_hash_update(&EG(persistent_list), hashkey, hashkey_length+1, (void *)&new_le, sizeof(list_entry), NULL)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to register persistent resource"); } ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_pmovie); } } else { ffmovie_ctx = _php_alloc_ffmovie_ctx(0); if (_php_open_movie_file(ffmovie_ctx, Z_STRVAL_PP(argv[0]))) { zend_error(E_WARNING, "Can't open movie file %s", Z_STRVAL_PP(argv[0])); efree(argv); ZVAL_BOOL(getThis(), 0); RETURN_FALSE; } /* pass NULL for resource result since we're not returning the resource directly, but adding it to the returned object. */ ffmovie_ctx->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ffmovie_ctx, le_ffmpeg_movie); } object_init_ex(getThis(), ffmpeg_movie_class_entry_ptr); add_property_resource(getThis(), "ffmpeg_movie", ffmovie_ctx->rsrc_id); efree(argv); if (fullpath) { efree(fullpath); } if (hashkey) { efree(hashkey); } }