onphp.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU Lesser General Public License as        *
00006  *   published by the Free Software Foundation; either version 3 of the    *
00007  *   License, or (at your option) any later version.                       *
00008  *                                                                         *
00009  ***************************************************************************/
00010 /* $Id: onphp.c 4687 2007-12-09 18:57:18Z voxus $ */
00011 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 #include "php.h"
00017 #include "SAPI.h"
00018 #include "zend_ini.h" // zend_ini_long
00019 #include "php_logos.h" // php_register_info_logo
00020 #include "ext/standard/info.h"
00021 
00022 #include "onphp.h"
00023 #include "onphp_core.h"
00024 #include "onphp_main.h"
00025 
00026 void onphp_empty_object_free_storage(void *object TSRMLS_DC)
00027 {
00028     onphp_empty_object *empty = (onphp_empty_object *) object;
00029 
00030     zend_object_std_dtor(empty TSRMLS_CC);
00031 
00032     efree(object);
00033 }
00034 
00035 zend_object_value onphp_empty_object_spawn(
00036     zend_class_entry *class_type,
00037     onphp_empty_object **object TSRMLS_DC
00038 )
00039 {
00040     zend_object_value objval;
00041     onphp_empty_object *intern;
00042     zval *tmp;
00043 
00044     intern = emalloc(sizeof(onphp_empty_object));
00045     memset(intern, 0, sizeof(onphp_empty_object));
00046 
00047     if (object)
00048         *object = intern;
00049 
00050     zend_object_std_init(intern, class_type TSRMLS_CC);
00051 
00052     zend_hash_copy(
00053         intern->properties,
00054         &class_type->default_properties,
00055         (copy_ctor_func_t) zval_add_ref,
00056         (void *) &tmp,
00057         sizeof(zval *)
00058     );
00059 
00060     objval.handle = zend_objects_store_put(
00061         intern,
00062         (zend_objects_store_dtor_t) zend_objects_destroy_object,
00063         (zend_objects_free_object_storage_t) onphp_empty_object_free_storage,
00064         NULL TSRMLS_CC
00065     );
00066     
00067     objval.handlers = zend_get_std_object_handlers();
00068 
00069     return objval;
00070 }
00071 
00072 zend_object_value onphp_empty_object_new(zend_class_entry *class_type TSRMLS_DC)
00073 {
00074     return onphp_empty_object_spawn(class_type, NULL TSRMLS_CC);
00075 }
00076 
00077 #include "onphp_logo.c"
00078 
00079 static unsigned char onphp_enable_logo = 0;
00080 
00081 PHP_MINFO_FUNCTION(onphp)
00082 {
00083     php_info_print_table_start();
00084     if (onphp_enable_logo) {
00085         PUTS("<tr><td rowspan=\"6\" width=\"202\" style=\"vertical-align: middle;\">");
00086         PUTS("<a href=\"http://onphp.org/\"><img border=\"0\" src=\"");
00087         if (SG(request_info).request_uri) {
00088             char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC);
00089             PUTS(elem_esc);
00090             efree(elem_esc);
00091         }
00092         PUTS("?="ONPHP_LOGO_GUID"\" alt=\"onPHP Logo\" ");
00093         PUTS("width=\"202\" height=\"93\" /></a>");
00094         PUTS("</td></tr>\n");
00095     }
00096     php_info_print_table_header(2, "onPHP support", "enabled");
00097     php_info_print_table_row(2, "Version", ONPHP_VERSION);
00098     php_info_print_table_row(2, "Exceptions", ONPHP_EXCEPTIONS_LIST);
00099     php_info_print_table_row(2, "Interfaces", ONPHP_INTERFACES_LIST);
00100     php_info_print_table_row(2, "Classes", ONPHP_CLASSES_LIST);
00101     php_info_print_table_end();
00102 }
00103 
00104 PHP_MINIT_FUNCTION(onphp)
00105 {
00106     onphp_enable_logo = (
00107         !sapi_module.phpinfo_as_text
00108         && zend_ini_long("expose_php", sizeof("expose_php"), 0)
00109         && !EG(in_execution)
00110     );
00111     
00112     if (onphp_enable_logo) {
00113         php_register_info_logo(
00114             ONPHP_LOGO_GUID,
00115             "image/png",
00116             (unsigned char *) onphp_logo,
00117             sizeof(onphp_logo)
00118         );
00119     }
00120 
00121     return
00122         PHP_MINIT(onphp_core)(INIT_FUNC_ARGS_PASSTHRU)
00123         & PHP_MINIT(onphp_main)(INIT_FUNC_ARGS_PASSTHRU);
00124 }
00125 
00126 PHP_MSHUTDOWN_FUNCTION(onphp)
00127 {
00128     php_unregister_info_logo(ONPHP_LOGO_GUID);
00129     
00130     return SUCCESS;
00131 }
00132 
00133 PHP_RINIT_FUNCTION(onphp)
00134 {
00135     return PHP_RINIT(onphp_core)(INIT_FUNC_ARGS_PASSTHRU);
00136 }
00137 
00138 PHP_RSHUTDOWN_FUNCTION(onphp)
00139 {
00140     return PHP_RSHUTDOWN(onphp_core)(INIT_FUNC_ARGS_PASSTHRU);
00141 }
00142 
00143 static zend_module_dep onphp_deps[] = {
00144     ZEND_MOD_REQUIRED("spl")
00145     {NULL, NULL, NULL}
00146 };
00147 
00148 
00149 zend_module_entry onphp_module_entry = {
00150     STANDARD_MODULE_HEADER_EX, NULL,
00151     onphp_deps,
00152     ONPHP_MODULE_NAME,
00153     NULL,
00154     PHP_MINIT(onphp),
00155     PHP_MSHUTDOWN(onphp),
00156     PHP_RINIT(onphp),
00157     PHP_RSHUTDOWN(onphp),
00158     PHP_MINFO(onphp),
00159     ONPHP_VERSION,
00160     STANDARD_MODULE_PROPERTIES
00161 };
00162 
00163 #ifdef COMPILE_DL_ONPHP
00164 ZEND_GET_MODULE(onphp);
00165 #endif

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4