]> granicus.if.org Git - php/commitdiff
post handler registration done right
authorHartmut Holzgraefe <hholzgra@php.net>
Fri, 13 Oct 2000 12:13:35 +0000 (12:13 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Fri, 13 Oct 2000 12:13:35 +0000 (12:13 +0000)
(never use emalloc in an extension MINIT function)

ext/fdf/fdf.c
main/SAPI.c
main/SAPI.h

index 4ddc9c643765e88d6ba26d79ae9864f1d906fb1b..bb1e9f751aa167406eb56b84d15c9e978fc745df 100644 (file)
@@ -112,32 +112,6 @@ static sapi_post_entry supported_post_entries[] = {
 };
 
 
-SAPI_API int sapi_add_post_entry(char *content_type, void (*post_reader)(SLS_D),
-                                                                void (*post_handler)(char *content_type_dup, void *arg SLS_DC)) {
-
-       sapi_post_entry *post_entry = (sapi_post_entry *)emalloc(sizeof(sapi_post_entry));
-       if(!post_entry) return 0;
-
-       post_entry->content_type     = estrdup(content_type);
-       if(post_entry->content_type == NULL) return 0;
-       post_entry->content_type_len = strlen(content_type);
-       post_entry->post_reader      = post_reader;
-       post_entry->post_handler     = post_handler;
-
-       return sapi_register_post_entry(post_entry);
-}
-
-SAPI_API void sapi_remove_post_entry(char *content_type) {
-       sapi_post_entry *post_entry = (sapi_post_entry *)emalloc(sizeof(sapi_post_entry));
-       if(!post_entry) return;
-
-       post_entry->content_type     = estrdup(content_type);
-       if(post_entry->content_type == NULL) return;
-
-       sapi_unregister_post_entry(post_entry);
-
-       efree(post_entry);
-}
 
 PHP_MINIT_FUNCTION(fdf)
 {
@@ -198,7 +172,7 @@ PHP_MSHUTDOWN_FUNCTION(fdf)
        FDFErc err;
 
        /* remove handler for Acrobat FDF form post requests */
-       sapi_remove_post_entry("application/vnd.fdf");
+       sapi_remove_post_entry("application/vnd.fdf"); 
 
 #ifdef PHP_WIN32
        return SUCCESS;
index a45e5d31fd603c5a1cf60a90e9fd1db0d2c3031e..c2c532f83f62905f5fb63f0127ecc9f94e891c38 100644 (file)
@@ -532,6 +532,50 @@ SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry)
        zend_hash_del(&known_post_content_types, post_entry->content_type, post_entry->content_type_len+1);
 }
 
+SAPI_API int sapi_add_post_entry(char *content_type
+                                                                , void (*post_reader)(SLS_D)
+                                                                , void (*post_handler)(char *content_type_dup
+                                                                , void *arg SLS_DC)) {
+
+       sapi_post_entry *post_entry = (sapi_post_entry *)malloc(sizeof(sapi_post_entry));
+       if(!post_entry) return 0;
+
+       post_entry->content_type     = strdup(content_type);
+       if(post_entry->content_type == NULL) return 0;
+       post_entry->content_type_len = strlen(content_type);
+       post_entry->post_reader      = post_reader;
+       post_entry->post_handler     = post_handler;
+
+       return zend_hash_add(&known_post_content_types
+                                                , post_entry->content_type
+                                                , post_entry->content_type_len+1
+                                                , (void *) post_entry
+                                                , sizeof(sapi_post_entry)
+                                                , NULL
+                                                );
+}
+
+SAPI_API void sapi_remove_post_entry(char *content_type) {
+       sapi_post_entry *post_entry;
+
+       zend_hash_find(&known_post_content_types
+                                  ,content_type
+                                  ,strlen(content_type)+1
+                                  ,(void **)&post_entry
+                                  );
+       
+       if(post_entry != NULL) {
+               zend_hash_del(&known_post_content_types
+                                         ,content_type
+                                         ,strlen(content_type)+1
+                                         );
+               free(post_entry->content_type);
+               free(post_entry);
+       } else {
+               php_error(E_WARNING,"unregister post handler failed in fdf");
+       }
+}
+
 SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(SLS_D))
 {
        sapi_module.default_post_reader = default_post_reader;
index cb8c7df6839c24d332a54a034be3b0a7d5b1b151..918912b717070d2a598d5cbe2fb9b5bd5e607759 100644 (file)
@@ -137,6 +137,10 @@ SAPI_API void sapi_handle_post(void *arg SLS_DC);
 
 SAPI_API int sapi_register_post_entries(sapi_post_entry *post_entry);
 SAPI_API int sapi_register_post_entry(sapi_post_entry *post_entry);
+SAPI_API int sapi_add_post_entry(char *content_type
+                                                                , void (*post_reader)(SLS_D)
+                                                                , void (*post_handler)(char *content_type_dup, void *arg SLS_DC));
+SAPI_API void sapi_remove_post_entry(char *content_type);
 SAPI_API void sapi_unregister_post_entry(sapi_post_entry *post_entry);
 SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(SLS_D));