1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2007 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,v 1.19.2.1.2.5 2007/01/06 20:44:51 nlopess Exp $ */
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 660 : {
38 : php_info_logo info_logo;
39 :
40 660 : info_logo.mimetype = mimetype;
41 660 : info_logo.mimelen = strlen(mimetype);
42 660 : info_logo.data = data;
43 660 : info_logo.size = size;
44 :
45 660 : 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 0 : {
50 0 : return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string));
51 : }
52 :
53 : int php_init_info_logos(void)
54 220 : {
55 220 : if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE)
56 0 : return FAILURE;
57 :
58 220 : php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo));
59 220 : php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo));
60 220 : php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo));
61 :
62 220 : return SUCCESS;
63 : }
64 :
65 : int php_shutdown_info_logos(void)
66 219 : {
67 219 : zend_hash_destroy(&phpinfo_logo_hash);
68 219 : return SUCCESS;
69 : }
70 :
71 : #define CONTENT_TYPE_HEADER "Content-Type: "
72 : int php_info_logos(const char *logo_string TSRMLS_DC)
73 0 : {
74 : php_info_logo *logo_image;
75 : char *content_header;
76 : int len;
77 :
78 0 : if(FAILURE==zend_hash_find(&phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&logo_image))
79 0 : return 0;
80 :
81 0 : len = sizeof(CONTENT_TYPE_HEADER) - 1 + logo_image->mimelen;
82 0 : content_header = emalloc(len + 1);
83 0 : memcpy(content_header, CONTENT_TYPE_HEADER, sizeof(CONTENT_TYPE_HEADER) - 1);
84 0 : memcpy(content_header + sizeof(CONTENT_TYPE_HEADER) - 1 , logo_image->mimetype, logo_image->mimelen);
85 0 : content_header[len] = '\0';
86 0 : sapi_add_header(content_header, len, 0);
87 :
88 0 : PHPWRITE(logo_image->data, logo_image->size);
89 0 : 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 : */
|