You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.1 KiB

26 years ago
26 years ago
26 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2006 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. /* $Id$ */
  19. #include "php.h"
  20. #include "logos.h"
  21. #include "php_logos.h"
  22. #include "ext/standard/info.h"
  23. #include "SAPI.h"
  24. typedef struct _php_info_logo {
  25. char *mimetype;
  26. int mimelen;
  27. unsigned char *data;
  28. int size;
  29. } php_info_logo;
  30. HashTable phpinfo_logo_hash;
  31. PHPAPI int php_register_info_logo(char *logo_string, char *mimetype, unsigned char *data, int size)
  32. {
  33. php_info_logo info_logo;
  34. info_logo.mimetype = mimetype;
  35. info_logo.mimelen = strlen(mimetype);
  36. info_logo.data = data;
  37. info_logo.size = size;
  38. return zend_hash_add(&phpinfo_logo_hash, logo_string, strlen(logo_string), &info_logo, sizeof(php_info_logo), NULL);
  39. }
  40. PHPAPI int php_unregister_info_logo(char *logo_string)
  41. {
  42. return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string));
  43. }
  44. int php_init_info_logos(void)
  45. {
  46. if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE)
  47. return FAILURE;
  48. php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo));
  49. php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo));
  50. php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo));
  51. return SUCCESS;
  52. }
  53. int php_shutdown_info_logos(void)
  54. {
  55. zend_hash_destroy(&phpinfo_logo_hash);
  56. return SUCCESS;
  57. }
  58. #define CONTENT_TYPE_HEADER "Content-Type: "
  59. int php_info_logos(const char *logo_string TSRMLS_DC)
  60. {
  61. php_info_logo *logo_image;
  62. char *content_header;
  63. int len;
  64. if(FAILURE==zend_hash_find(&phpinfo_logo_hash, (char *) logo_string, strlen(logo_string), (void **)&logo_image))
  65. return 0;
  66. len=strlen(CONTENT_TYPE_HEADER)+logo_image->mimelen;
  67. content_header=malloc(len+1);
  68. if(!content_header) return 0;
  69. strcpy(content_header, CONTENT_TYPE_HEADER);
  70. strcat(content_header, logo_image->mimetype);
  71. sapi_add_header(content_header, len, 1);
  72. free(content_header);
  73. PHPWRITE((char*)logo_image->data, logo_image->size);
  74. return 1;
  75. }
  76. /*
  77. * Local variables:
  78. * tab-width: 4
  79. * c-basic-offset: 4
  80. * End:
  81. * vim600: sw=4 ts=4 fdm=marker
  82. * vim<600: sw=4 ts=4
  83. */