Annotation of embedaddon/php/main/php_logos.c, revision 1.1.1.3

1.1       misho       1: /*
                      2:    +----------------------------------------------------------------------+
                      3:    | PHP Version 5                                                        |
                      4:    +----------------------------------------------------------------------+
1.1.1.3 ! misho       5:    | Copyright (c) 1997-2013 The PHP Group                                |
1.1       misho       6:    +----------------------------------------------------------------------+
                      7:    | This source file is subject to version 3.01 of the PHP license,      |
                      8:    | that is bundled with this package in the file LICENSE, and is        |
                      9:    | available through the world-wide-web at the following url:           |
                     10:    | http://www.php.net/license/3_01.txt                                  |
                     11:    | If you did not receive a copy of the PHP license and are unable to   |
                     12:    | obtain it through the world-wide-web, please send a note to          |
                     13:    | license@php.net so we can mail you a copy immediately.               |
                     14:    +----------------------------------------------------------------------+
                     15:    | Author: Hartmut Holzgraefe <hholzgra@php.net>                        |
                     16:    +----------------------------------------------------------------------+
                     17: */
                     18: 
1.1.1.2   misho      19: /* $Id$ */
1.1       misho      20: 
                     21: #include "php.h"
                     22: #include "logos.h"
                     23: #include "php_logos.h"
                     24: #include "ext/standard/info.h"
                     25: #include "SAPI.h"
                     26: 
                     27: typedef struct _php_info_logo { 
                     28:        const char *mimetype;
                     29:        int mimelen;
                     30:        const unsigned char *data; 
                     31:        int size; 
                     32: } php_info_logo;
                     33: 
                     34: static HashTable phpinfo_logo_hash;
                     35: 
                     36: PHPAPI int php_register_info_logo(char *logo_string, const char *mimetype, const unsigned char *data, int size)
                     37: {
                     38:        php_info_logo info_logo;
                     39: 
                     40:        info_logo.mimetype = mimetype;
                     41:        info_logo.mimelen  = strlen(mimetype);
                     42:        info_logo.data     = data;
                     43:        info_logo.size     = size;
                     44: 
                     45:        return zend_hash_add(&phpinfo_logo_hash, logo_string, strlen(logo_string), &info_logo, sizeof(php_info_logo), NULL);
                     46: }
                     47: 
                     48: PHPAPI int php_unregister_info_logo(char *logo_string)
                     49: {
                     50:        return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string));
                     51: }
                     52: 
                     53: int php_init_info_logos(void)
                     54: {
                     55:        if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) 
                     56:                return FAILURE;
                     57: 
                     58:        php_register_info_logo(PHP_LOGO_GUID    , "image/gif", php_logo    , sizeof(php_logo));
                     59:        php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo));
                     60:        php_register_info_logo(ZEND_LOGO_GUID   , "image/gif", zend_logo   , sizeof(zend_logo));
1.1.1.2   misho      61: 
1.1       misho      62:        return SUCCESS;
                     63: }
                     64: 
                     65: int php_shutdown_info_logos(void)
                     66: {
                     67:        zend_hash_destroy(&phpinfo_logo_hash);
                     68:        return SUCCESS;
                     69: }
                     70: 
                     71: #define CONTENT_TYPE_HEADER "Content-Type: "
                     72: int php_info_logos(const char *logo_string TSRMLS_DC)
                     73: {
                     74:        php_info_logo *logo_image;
                     75:        char *content_header;
                     76:        int len;
                     77: 
                     78:        if(FAILURE==zend_hash_find(&phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&logo_image))
                     79:                return 0;
                     80: 
                     81:        len = sizeof(CONTENT_TYPE_HEADER) - 1 + logo_image->mimelen;
                     82:        content_header = emalloc(len + 1);
                     83:        memcpy(content_header, CONTENT_TYPE_HEADER, sizeof(CONTENT_TYPE_HEADER) - 1);
                     84:        memcpy(content_header + sizeof(CONTENT_TYPE_HEADER) - 1 , logo_image->mimetype, logo_image->mimelen);
                     85:        content_header[len] = '\0';
                     86:        sapi_add_header(content_header, len, 0);
                     87: 
1.1.1.2   misho      88:        PHPWRITE((char*)logo_image->data, logo_image->size);
1.1       misho      89:        return 1;
                     90: }
                     91: 
                     92: /*
                     93:  * Local variables:
                     94:  * tab-width: 4
                     95:  * c-basic-offset: 4
                     96:  * End:
                     97:  * vim600: sw=4 ts=4 fdm=marker
                     98:  * vim<600: sw=4 ts=4
                     99:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>