From: Hartmut Holzgraefe Date: Tue, 31 Oct 2000 17:21:52 +0000 (+0000) Subject: generalization of image handling in phpinfo X-Git-Tag: php-4.0.4RC3~414 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00b8b66132788464a9ba68f88951cbdb6f7892df;p=php generalization of image handling in phpinfo --- diff --git a/ext/standard/info.c b/ext/standard/info.c index 4dabcbeb9b..770b57b806 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -175,9 +175,9 @@ PHPAPI void php_print_info(int flag) PUTS(SG(request_info).request_uri); } if ((ta->tm_mon==3) && (ta->tm_mday==1)) { - PUTS("?=PHPE9568F36-D428-11d2-A769-00AA001ACF42\" border=0 align=\"right\" alt=\"Thies!\">"); + PUTS("?="PHP_EGG_LOGO_GUID"\" border=0 align=\"right\" alt=\"Thies!\">"); } else { - PUTS("?=PHPE9568F34-D428-11d2-A769-00AA001ACF42\" border=0 align=\"right\" alt=\"PHP Logo\">"); + PUTS("?="PHP_LOGO_GUID"\" border=0 align=\"right\" alt=\"PHP Logo\">"); } } php_printf("

PHP Version %s

\n", PHP_VERSION); @@ -220,7 +220,7 @@ PHPAPI void php_print_info(int flag) if (SG(request_info).request_uri) { PUTS(SG(request_info).request_uri); } - PUTS("?=PHPE9568F35-D428-11d2-A769-00AA001ACF42\" border=\"0\" align=\"right\" alt=\"Zend logo\">\n"); + PUTS("?="ZEND_LOGO_GUID"\" border=\"0\" align=\"right\" alt=\"Zend logo\">\n"); } php_printf("This program makes use of the Zend scripting language engine:
"); zend_html_puts(zend_version, strlen(zend_version)); diff --git a/ext/standard/info.h b/ext/standard/info.h index 72beafcfdc..1a7b8250b7 100644 --- a/ext/standard/info.h +++ b/ext/standard/info.h @@ -44,9 +44,10 @@ #define PHP_CREDITS_FULLPAGE (1<<5) #define PHP_CREDITS_ALL 0xFFFFFFFF -#define PHP_LOGO_GUID "PHPE9568F34-D428-11d2-A769-00AA001ACF42" +#define PHP_LOGO_GUID "PHPE9568F34-D428-11d2-A769-00AA001ACF42" #define PHP_EGG_LOGO_GUID "PHPE9568F36-D428-11d2-A769-00AA001ACF42" #define ZEND_LOGO_GUID "PHPE9568F35-D428-11d2-A769-00AA001ACF42" +#define PHP_CREDITS_GUID "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000" PHP_FUNCTION(phpversion); PHP_FUNCTION(phpinfo); diff --git a/main/main.c b/main/main.c index 895c7e05c7..919a1c6c11 100644 --- a/main/main.c +++ b/main/main.c @@ -259,7 +259,6 @@ PHP_INI_BEGIN() PHP_INI_ENTRY("precision", "14", PHP_INI_ALL, OnSetPrecision) PHP_INI_ENTRY("sendmail_from", NULL, PHP_INI_ALL, NULL) PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL) - PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL) STD_PHP_INI_ENTRY("allow_url_fopen", "1", PHP_INI_ALL, OnUpdateBool, allow_url_fopen, php_core_globals, core_globals) @@ -875,6 +874,11 @@ int php_module_startup(sapi_module_struct *sf) return FAILURE; } + if (php_init_info_logos() == FAILURE) { + php_printf("PHP: Unable to initialize info phpinfo logos.\n"); + return FAILURE; + } + zuv.import_use_extension = ".php"; zend_set_utility_values(&zuv); php_startup_sapi_content_types(); @@ -936,6 +940,7 @@ void php_module_shutdown() global_lock_destroy(); zend_shutdown(); php_shutdown_fopen_wrappers(); + php_shutdown_info_logos(); UNREGISTER_INI_ENTRIES(); zend_ini_mshutdown(); shutdown_memory_manager(0, 1); @@ -1133,23 +1138,81 @@ static void php_build_argv(char *s, zval *track_vars_array ELS_DC PLS_DC) #include "logos.h" +typedef struct _php_info_logo { + char *mimetype; + int mimelen; + unsigned char *data; + int size; +} php_info_logo; + +HashTable phpinfo_logo_hash; + +PHPAPI int php_register_info_logo(char *logo_string, char *mimetype, unsigned char *data, int size) +{ + php_info_logo *info_logo = (php_info_logo *)malloc(sizeof(php_info_logo)); + + if(!info_logo) return FAILURE; + info_logo->mimetype = mimetype; + info_logo->mimelen = strlen(mimetype); + info_logo->data = data; + info_logo->size = size; + + return zend_hash_add(&phpinfo_logo_hash, logo_string, strlen(logo_string), info_logo, sizeof(php_info_logo), NULL); +} + +PHPAPI int php_unregister_info_logos(char *logo_string) +{ + return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string)); +} + +int php_init_info_logos(void) +{ + if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) + return FAILURE; + + php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo)); + php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo)); + php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo)); + + return SUCCESS; +} + +int php_shutdown_info_logos(void) +{ + zend_hash_destroy(&phpinfo_logo_hash); + return SUCCESS; +} + +#define CONTENT_TYPE_HEADER "Content-Type: " +static int php_info_logos(char *logo_string) +{ + php_info_logo *logo_image; + char *content_header; + int len; + + if(FAILURE==zend_hash_find(&phpinfo_logo_hash,logo_string,strlen(logo_string),(void **)&logo_image)) + return 0; + + len=strlen(CONTENT_TYPE_HEADER)+logo_image->mimelen; + content_header=malloc(len+1); + if(!content_header) return 0; + strcpy(content_header,CONTENT_TYPE_HEADER); + strcat(content_header,logo_image->mimetype); + sapi_add_header(content_header, len, 1); + free(content_header); + + PHPWRITE(logo_image->data, logo_image->size); + return 1; +} + PHPAPI int php_handle_special_queries(SLS_D PLS_DC) { if (SG(request_info).query_string && SG(request_info).query_string[0]=='=' && PG(expose_php)) { - if (!strcmp(SG(request_info).query_string+1, PHP_LOGO_GUID)) { - sapi_add_header(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1, 1); - PHPWRITE(php_logo, sizeof(php_logo)); - return 1; - } else if (!strcmp(SG(request_info).query_string+1, PHP_EGG_LOGO_GUID)) { - sapi_add_header(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1, 1); - PHPWRITE(php_egg_logo, sizeof(php_egg_logo)); - return 1; - } else if (!strcmp(SG(request_info).query_string+1, ZEND_LOGO_GUID)) { - sapi_add_header(CONTEXT_TYPE_IMAGE_GIF, sizeof(CONTEXT_TYPE_IMAGE_GIF)-1, 1); - PHPWRITE(zend_logo, sizeof(zend_logo)); - return 1; - } else if (!strcmp(SG(request_info).query_string+1, "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000")) { + if(php_info_logos(SG(request_info).query_string+1)) + { + return 1; + } else if (!strcmp(SG(request_info).query_string+1, PHP_CREDITS_GUID)) { php_print_credits(PHP_CREDITS_ALL); return 1; } @@ -1288,6 +1351,7 @@ PHPAPI void dummy_indent() } #endif + /* * Local variables: * tab-width: 4