Back to index

php5  5.3.10
php_logos.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author: Hartmut Holzgraefe <hholzgra@php.net>                        |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_logos.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 #include "logos.h"
00023 #include "php_logos.h"
00024 #include "ext/standard/info.h"
00025 #include "SAPI.h"
00026 
00027 typedef struct _php_info_logo { 
00028        const char *mimetype;
00029        int mimelen;
00030        const unsigned char *data; 
00031        int size; 
00032 } php_info_logo;
00033 
00034 static HashTable phpinfo_logo_hash;
00035 
00036 PHPAPI int php_register_info_logo(char *logo_string, const char *mimetype, const unsigned char *data, int size)
00037 {
00038        php_info_logo info_logo;
00039 
00040        info_logo.mimetype = mimetype;
00041        info_logo.mimelen  = strlen(mimetype);
00042        info_logo.data     = data;
00043        info_logo.size     = size;
00044 
00045        return zend_hash_add(&phpinfo_logo_hash, logo_string, strlen(logo_string), &info_logo, sizeof(php_info_logo), NULL);
00046 }
00047 
00048 PHPAPI int php_unregister_info_logo(char *logo_string)
00049 {
00050        return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string));
00051 }
00052 
00053 int php_init_info_logos(void)
00054 {
00055        if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) 
00056               return FAILURE;
00057 
00058        php_register_info_logo(PHP_LOGO_GUID    , "image/gif", php_logo    , sizeof(php_logo));
00059        php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo));
00060        php_register_info_logo(ZEND_LOGO_GUID   , "image/gif", zend_logo   , sizeof(zend_logo));
00061 
00062        return SUCCESS;
00063 }
00064 
00065 int php_shutdown_info_logos(void)
00066 {
00067        zend_hash_destroy(&phpinfo_logo_hash);
00068        return SUCCESS;
00069 }
00070 
00071 #define CONTENT_TYPE_HEADER "Content-Type: "
00072 int php_info_logos(const char *logo_string TSRMLS_DC)
00073 {
00074        php_info_logo *logo_image;
00075        char *content_header;
00076        int len;
00077 
00078        if(FAILURE==zend_hash_find(&phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&logo_image))
00079               return 0;
00080 
00081        len = sizeof(CONTENT_TYPE_HEADER) - 1 + logo_image->mimelen;
00082        content_header = emalloc(len + 1);
00083        memcpy(content_header, CONTENT_TYPE_HEADER, sizeof(CONTENT_TYPE_HEADER) - 1);
00084        memcpy(content_header + sizeof(CONTENT_TYPE_HEADER) - 1 , logo_image->mimetype, logo_image->mimelen);
00085        content_header[len] = '\0';
00086        sapi_add_header(content_header, len, 0);
00087 
00088        PHPWRITE(logo_image->data, logo_image->size);
00089        return 1;
00090 }
00091 
00092 /*
00093  * Local variables:
00094  * tab-width: 4
00095  * c-basic-offset: 4
00096  * End:
00097  * vim600: sw=4 ts=4 fdm=marker
00098  * vim<600: sw=4 ts=4
00099  */