Annotation of embedaddon/php/main/php_logos.c, revision 1.1
1.1 ! misho 1: /*
! 2: +----------------------------------------------------------------------+
! 3: | PHP Version 5 |
! 4: +----------------------------------------------------------------------+
! 5: | Copyright (c) 1997-2012 The PHP Group |
! 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:
! 19: /* $Id: php_logos.c 321634 2012-01-01 13:15:04Z felipe $ */
! 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: #if SUHOSIN_PATCH
! 54: #include "suhosin_logo.h"
! 55: #endif
! 56:
! 57: int php_init_info_logos(void)
! 58: {
! 59: if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE)
! 60: return FAILURE;
! 61:
! 62: php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo));
! 63: php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo));
! 64: php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo));
! 65: #if SUHOSIN_PATCH
! 66: php_register_info_logo(SUHOSIN_LOGO_GUID, "image/jpeg", suhosin_logo , sizeof(suhosin_logo));
! 67: #endif
! 68: return SUCCESS;
! 69: }
! 70:
! 71: int php_shutdown_info_logos(void)
! 72: {
! 73: zend_hash_destroy(&phpinfo_logo_hash);
! 74: return SUCCESS;
! 75: }
! 76:
! 77: #define CONTENT_TYPE_HEADER "Content-Type: "
! 78: int php_info_logos(const char *logo_string TSRMLS_DC)
! 79: {
! 80: php_info_logo *logo_image;
! 81: char *content_header;
! 82: int len;
! 83:
! 84: if(FAILURE==zend_hash_find(&phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&logo_image))
! 85: return 0;
! 86:
! 87: len = sizeof(CONTENT_TYPE_HEADER) - 1 + logo_image->mimelen;
! 88: content_header = emalloc(len + 1);
! 89: memcpy(content_header, CONTENT_TYPE_HEADER, sizeof(CONTENT_TYPE_HEADER) - 1);
! 90: memcpy(content_header + sizeof(CONTENT_TYPE_HEADER) - 1 , logo_image->mimetype, logo_image->mimelen);
! 91: content_header[len] = '\0';
! 92: sapi_add_header(content_header, len, 0);
! 93:
! 94: PHPWRITE(logo_image->data, logo_image->size);
! 95: return 1;
! 96: }
! 97:
! 98: /*
! 99: * Local variables:
! 100: * tab-width: 4
! 101: * c-basic-offset: 4
! 102: * End:
! 103: * vim600: sw=4 ts=4 fdm=marker
! 104: * vim<600: sw=4 ts=4
! 105: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>