source: trunk/server/common/oursrc/php_scripts/php_scripts.c @ 1294

Last change on this file since 1294 was 1137, checked in by quentin, 15 years ago
Import scripts PHP module
File size: 2.1 KB
Line 
1/***
2 * scripts.mit.edu PHP enhancement extension
3 *
4 * Joe Presbrey <presbrey@mit.edu>
5 * 2008-06-19
6 *
7 ***/
8
9#include "php.h"
10#include "zend_extensions.h"
11
12#include "php_scripts.h"
13
14#ifndef ZEND_EXT_API
15#define ZEND_EXT_API    ZEND_DLEXPORT
16#endif
17ZEND_EXTENSION();
18
19ZEND_MODULE_STARTUP_D(scripts)
20{
21        return SUCCESS;
22}
23
24ZEND_MODULE_SHUTDOWN_D(scripts)
25{
26}
27
28ZEND_MODULE_ACTIVATE_D(scripts)
29{
30    // replace error handler callback with our own
31    old_error_cb = zend_error_cb;
32    new_error_cb = scripts_error_cb;
33    zend_error_cb = new_error_cb;
34
35        return SUCCESS;
36}
37
38ZEND_MODULE_DEACTIVATE_D(scripts)
39{
40    // restore original error handler callback
41    zend_error_cb = old_error_cb;
42}
43
44void scripts_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
45{
46    char *buffer;
47    const char *user = php_get_current_user();
48
49    // enhance the log message
50    spprintf(&buffer, 0, "(%s) %s", user, format);
51
52    // pass through to builtin error callback
53    if (strncmp(format, "Module '%s' already loaded", 26)==0) {
54        // demote from E_CORE_WARNING
55        old_error_cb(E_NOTICE, error_filename, error_lineno, buffer, args);
56    } else {
57        old_error_cb(type, error_filename, error_lineno, buffer, args);
58    }
59
60    efree(buffer);
61}
62
63ZEND_DLEXPORT zend_extension zend_extension_entry = {
64    PHP_SCRIPTS_EXTNAME,
65    PHP_SCRIPTS_VERSION,
66    PHP_SCRIPTS_AUTHOR,
67    PHP_SCRIPTS_URL,
68    PHP_SCRIPTS_YEAR,
69    ZEND_MODULE_STARTUP_N(scripts),             /* startup_func_t */
70    ZEND_MODULE_SHUTDOWN_N(scripts),    /* shutdown_func_t */
71    ZEND_MODULE_ACTIVATE_N(scripts),    /* activate_func_t */
72    ZEND_MODULE_DEACTIVATE_N(scripts),  /* deactivate_func_t */
73    NULL,                                               /* message_handler_func_t */
74    NULL,                                               /* op_array_handler_func_t */
75    NULL,                                               /* statement_handler_func_t */
76    NULL,                                               /* fcall_begin_handler_func_t */
77    NULL,                                               /* fcall_end_handler_func_t */
78    NULL,                                               /* op_array_ctor_func_t */
79    NULL,                                               /* op_array_dtor_func_t */
80    STANDARD_ZEND_EXTENSION_PROPERTIES
81};
82
83#ifdef COMPILE_DL_SCRIPTS
84ZEND_GET_MODULE(scripts)
85#endif
Note: See TracBrowser for help on using the repository browser.