From e103c61ca14d22e9507379810e980075c8323ca3 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 11 Oct 2005 17:11:37 +0000 Subject: [PATCH] - use PHP macros, so that it is obvious when to call what --- http.c | 43 +++++++++++++++++------------------ http_api.c | 2 +- http_cache_api.c | 2 +- http_exception_object.c | 4 +++- http_functions.c | 2 +- http_headers_api.c | 4 ++-- http_message_object.c | 4 +++- http_request_api.c | 5 ++-- http_request_method_api.c | 13 ++++++++++- http_request_object.c | 3 ++- http_requestpool_object.c | 3 ++- http_response_object.c | 3 ++- http_util_object.c | 3 ++- php_http.h | 2 +- php_http_api.h | 3 +-- php_http_cache_api.h | 5 ++-- php_http_encoding_api.h | 3 ++- php_http_exception_object.h | 5 ++-- php_http_headers_api.h | 3 +-- php_http_message_object.h | 4 ++-- php_http_request_api.h | 6 ++--- php_http_request_method_api.h | 6 ++--- php_http_request_object.h | 4 ++-- php_http_requestpool_object.h | 4 ++-- php_http_response_object.h | 3 +-- php_http_std_defs.h | 4 ++++ php_http_util_object.h | 3 +-- 27 files changed, 81 insertions(+), 65 deletions(-) diff --git a/http.c b/http.c index 8930b67..0f5f936 100644 --- a/http.c +++ b/http.c @@ -277,29 +277,29 @@ PHP_MINIT_FUNCTION(http) REGISTER_INI_ENTRIES(); - if ( (SUCCESS != http_support_global_init()) || - (SUCCESS != http_headers_global_init()) || - (SUCCESS != http_cache_global_init()) || - (SUCCESS != http_request_method_global_init())) { - return FAILURE; - } + if ( (SUCCESS != PHP_MINIT_CALL(http_support)) || + (SUCCESS != PHP_MINIT_CALL(http_headers)) || + (SUCCESS != PHP_MINIT_CALL(http_cache)) || #ifdef HTTP_HAVE_CURL - if (SUCCESS != http_request_global_init()) { + (SUCCESS != PHP_MINIT_CALL(http_request)) || +#endif /* HTTP_HAVE_CURL */ + (SUCCESS != PHP_MINIT_CALL(http_request_method))) { return FAILURE; } -#endif /* HTTP_HAVE_CURL */ #ifdef ZEND_ENGINE_2 - http_util_object_init(); - http_message_object_init(); + if ( (SUCCESS != PHP_MINIT_CALL(http_util_object)) || + (SUCCESS != PHP_MINIT_CALL(http_message_object)) || # ifndef WONKY - http_response_object_init(); -# endif + (SUCCESS != PHP_MINIT_CALL(http_response_object)) || +# endif /* WONKY */ # ifdef HTTP_HAVE_CURL - http_request_object_init(); - http_requestpool_object_init(); + (SUCCESS != PHP_MINIT_CALL(http_request_object)) || + (SUCCESS != PHP_MINIT_CALL(http_requestpool_object)) || # endif /* HTTP_HAVE_CURL */ - http_exception_object_init(); + (SUCCESS != PHP_MINIT_CALL(http_exception_object))) { + return FAILURE; + } #endif /* ZEND_ENGINE_2 */ return SUCCESS; @@ -311,7 +311,7 @@ PHP_MSHUTDOWN_FUNCTION(http) { UNREGISTER_INI_ENTRIES(); #ifdef HTTP_HAVE_CURL - http_request_global_cleanup(); + return PHP_MSHUTDOWN_CALL(http_request); #endif return SUCCESS; } @@ -334,15 +334,14 @@ PHP_RINIT_FUNCTION(http) /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(http) { -#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) - int i, c = zend_hash_num_elements(&HTTP_G(request).methods.custom); + STATUS status = SUCCESS; - for (i = 0; i < c; ++i) { - http_request_method_unregister(HTTP_MAX_REQUEST_METHOD + i); - } +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) + status = PHP_RSHUTDOWN_CALL(http_request_method); #endif + http_globals_free(HTTP_GLOBALS); - return SUCCESS; + return status; } /* }}} */ diff --git a/http_api.c b/http_api.c index 683da9d..d689c86 100644 --- a/http_api.c +++ b/http_api.c @@ -49,7 +49,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http); static zend_bool http_support_ssl; -STATUS _http_support_global_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_support) { http_support_ssl = http_request_supports_ssl(); diff --git a/http_cache_api.c b/http_cache_api.c index 6fa1c52..dcc833e 100644 --- a/http_cache_api.c +++ b/http_cache_api.c @@ -39,7 +39,7 @@ ZEND_EXTERN_MODULE_GLOBALS(http); -STATUS _http_cache_global_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_cache) { HTTP_LONG_CONSTANT("HTTP_ETAG_MD5", HTTP_ETAG_MD5); HTTP_LONG_CONSTANT("HTTP_ETAG_SHA1", HTTP_ETAG_SHA1); diff --git a/http_exception_object.c b/http_exception_object.c index a35eb0e..610413a 100644 --- a/http_exception_object.c +++ b/http_exception_object.c @@ -45,7 +45,7 @@ zend_class_entry *HTTP_EX_CE(socket); zend_class_entry *HTTP_EX_CE(response); zend_class_entry *HTTP_EX_CE(url); -void _http_exception_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_exception_object) { HTTP_REGISTER_EXCEPTION(HttpException, http_exception_object_ce, zend_exception_get_default()); HTTP_REGISTER_EXCEPTION(HttpRuntimeException, HTTP_EX_CE(runtime), HTTP_EX_DEF_CE); @@ -73,6 +73,8 @@ void _http_exception_object_init(INIT_FUNC_ARGS) HTTP_LONG_CONSTANT("HTTP_E_SOCKET", HTTP_E_SOCKET); HTTP_LONG_CONSTANT("HTTP_E_RESPONSE", HTTP_E_RESPONSE); HTTP_LONG_CONSTANT("HTTP_E_URL", HTTP_E_URL); + + return SUCCESS; } zend_class_entry *_http_exception_get_default() diff --git a/http_functions.c b/http_functions.c index 1f635c5..dd24050 100644 --- a/http_functions.c +++ b/http_functions.c @@ -956,7 +956,7 @@ PHP_FUNCTION(http_match_request_header) * - compress: bool, whether to allow gzip/deflate content encoding * (defaults to true) * - port: int, use another port as specified in the url - * - referer: string, the referer to sends + * - referer: string, the referer to send * - useragent: string, the user agent to send * (defaults to PECL::HTTP/version (PHP/version))) * - headers: array, list of custom headers as associative array diff --git a/http_headers_api.c b/http_headers_api.c index 2af2da0..e934180 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -37,8 +37,8 @@ ZEND_EXTERN_MODULE_GLOBALS(http); # define HTTP_DBG_NEG 0 #endif -/* {{{ STATUS http_headers_global_init() */ -STATUS _http_headers_global_init(INIT_FUNC_ARGS) +/* {{{ */ +PHP_MINIT_FUNCTION(http_headers) { HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT); HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM); diff --git a/http_message_object.c b/http_message_object.c index d588192..561b350 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -133,7 +133,7 @@ zend_function_entry http_message_object_fe[] = { }; static zend_object_handlers http_message_object_handlers; -void _http_message_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_message_object) { HTTP_REGISTER_CLASS_EX(HttpMessage, http_message_object, NULL, 0); @@ -146,6 +146,8 @@ void _http_message_object_init(INIT_FUNC_ARGS) http_message_object_handlers.write_property = http_message_object_write_prop; http_message_object_handlers.get_properties = http_message_object_get_props; http_message_object_handlers.get_property_ptr_ptr = NULL; + + return SUCCESS; } zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC) diff --git a/http_request_api.c b/http_request_api.c index c7bdcb3..615958c 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -56,7 +56,7 @@ static inline zend_bool http_ssl_init(void); static inline void http_ssl_cleanup(void); #endif -STATUS _http_request_global_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_request) { if (CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)) { return FAILURE; @@ -76,12 +76,13 @@ STATUS _http_request_global_init(INIT_FUNC_ARGS) return SUCCESS; } -void _http_request_global_cleanup(TSRMLS_D) +PHP_MSHUTDOWN_FUNCTION(http_request) { curl_global_cleanup(); #ifdef HTTP_NEED_SSL http_ssl_cleanup(); #endif + return SUCCESS; } #ifndef HAVE_CURL_EASY_STRERROR diff --git a/http_request_method_api.c b/http_request_method_api.c index 595a1de..37895d7 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -71,7 +71,7 @@ static const char *const http_request_methods[] = { }; /* }}} */ -STATUS _http_request_method_global_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_request_method) { /* HTTP/1.1 */ HTTP_LONG_CONSTANT("HTTP_METH_GET", HTTP_GET); @@ -108,6 +108,17 @@ STATUS _http_request_method_global_init(INIT_FUNC_ARGS) return SUCCESS; } +PHP_RSHUTDOWN_FUNCTION(http_request_method) +{ + int i, c = zend_hash_num_elements(&HTTP_G(request).methods.custom); + + for (i = 0; i < c; ++i) { + http_request_method_unregister(HTTP_MAX_REQUEST_METHOD + i); + } + + return SUCCESS; +} + /* {{{ char *http_request_method_name(http_request_method) */ PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC) { diff --git a/http_request_object.c b/http_request_object.c index 479e0b6..3244161 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -298,9 +298,10 @@ zend_function_entry http_request_object_fe[] = { }; static zend_object_handlers http_request_object_handlers; -void _http_request_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_request_object) { HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0); + return SUCCESS; } zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) diff --git a/http_requestpool_object.c b/http_requestpool_object.c index dfb9c60..58aec24 100644 --- a/http_requestpool_object.c +++ b/http_requestpool_object.c @@ -94,10 +94,11 @@ zend_function_entry http_requestpool_object_fe[] = { }; static zend_object_handlers http_requestpool_object_handlers; -void _http_requestpool_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_requestpool_object) { HTTP_REGISTER_CLASS_EX(HttpRequestPool, http_requestpool_object, NULL, 0); zend_class_implements(http_requestpool_object_ce TSRMLS_CC, 1, zend_ce_iterator); + return SUCCESS; } zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC) diff --git a/http_response_object.c b/http_response_object.c index 72289b6..9193590 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -214,10 +214,11 @@ zend_function_entry http_response_object_fe[] = { EMPTY_FUNCTION_ENTRY }; -void _http_response_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_response_object) { HTTP_REGISTER_CLASS(HttpResponse, http_response_object, NULL, 0); http_response_object_declare_default_properties(); + return SUCCESS; } static inline void _http_response_object_declare_default_properties(TSRMLS_D) diff --git a/http_util_object.c b/http_util_object.c index 5829c19..a97984d 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -135,9 +135,10 @@ zend_function_entry http_util_object_fe[] = { EMPTY_FUNCTION_ENTRY }; -void _http_util_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_util_object) { HTTP_REGISTER_CLASS(HttpUtil, http_util_object, NULL, 0); + return SUCCESS; } #endif /* ZEND_ENGINE_2 */ diff --git a/php_http.h b/php_http.h index e59d0c2..a11d484 100644 --- a/php_http.h +++ b/php_http.h @@ -18,7 +18,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define HTTP_PEXT_VERSION "0.15.0" +#define HTTP_PEXT_VERSION "0.15.1dev" /* make compile on Win32 */ #ifdef HTTP_HAVE_CURL diff --git a/php_http_api.h b/php_http_api.h index 7196048..dd3a4da 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -28,8 +28,7 @@ #define HTTP_SUPPORT_MHASHETAGS 0x10L #define HTTP_SUPPORT_SSLREQUESTS 0x20L -#define http_support_global_init() _http_support_global_init(INIT_FUNC_ARGS_PASSTHRU) -extern STATUS _http_support_global_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_support); #define http_support(f) _http_support(f) PHP_HTTP_API long _http_support(long feature); diff --git a/php_http_cache_api.h b/php_http_cache_api.h index f81f853..5d7731e 100644 --- a/php_http_cache_api.h +++ b/php_http_cache_api.h @@ -35,15 +35,14 @@ ZEND_EXTERN_MODULE_GLOBALS(http); -#define http_cache_global_init() _http_cache_global_init(INIT_FUNC_ARGS_PASSTHRU) -extern STATUS _http_cache_global_init(INIT_FUNC_ARGS); - typedef enum { HTTP_ETAG_CRC32 = -3, HTTP_ETAG_MD5 = -2, HTTP_ETAG_SHA1 = -1, } http_etag_mode; +extern PHP_MINIT_FUNCTION(http_cache); + #ifdef HTTP_HAVE_MHASH static void *http_etag_alloc_mhash_digest(size_t size) { diff --git a/php_http_encoding_api.h b/php_http_encoding_api.h index 92a2f9a..7e235c7 100644 --- a/php_http_encoding_api.h +++ b/php_http_encoding_api.h @@ -38,7 +38,8 @@ PHP_HTTP_API STATUS _http_encoding_compress(int level, const char *data, size_t #define http_encoding_uncompress(d, dl, r, rl) _http_encoding_uncompress((d), (dl), (r), (rl) TSRMLS_CC) PHP_HTTP_API STATUS _http_encoding_uncompress(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC); -#endif +#endif /* HTTP_HAVE_ZLIB */ + #endif /* diff --git a/php_http_exception_object.h b/php_http_exception_object.h index f309035..c3804c2 100644 --- a/php_http_exception_object.h +++ b/php_http_exception_object.h @@ -19,12 +19,11 @@ #define PHP_HTTP_EXCEPTION_OBJECT_H #ifdef ZEND_ENGINE_2 +PHP_MINIT_FUNCTION(http_exception_object); + extern zend_class_entry *http_exception_object_ce; extern zend_function_entry http_exception_object_fe[]; -#define http_exception_object_init() _http_exception_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_exception_object_init(INIT_FUNC_ARGS); - #define http_exception_get_default _http_exception_get_default extern zend_class_entry *_http_exception_get_default(); diff --git a/php_http_headers_api.h b/php_http_headers_api.h index dbf1a43..8b3b95f 100644 --- a/php_http_headers_api.h +++ b/php_http_headers_api.h @@ -32,8 +32,7 @@ typedef enum { RANGE_ERR } http_range_status; -#define http_headers_global_init() _http_headers_global_init(INIT_FUNC_ARGS_PASSTHRU) -extern STATUS _http_headers_global_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_headers); #define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC) #define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC) diff --git a/php_http_message_object.h b/php_http_message_object.h index 1e95c74..1ff1362 100644 --- a/php_http_message_object.h +++ b/php_http_message_object.h @@ -30,8 +30,8 @@ typedef struct { extern zend_class_entry *http_message_object_ce; extern zend_function_entry http_message_object_fe[]; -#define http_message_object_init() _http_message_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_message_object_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_message_object); + #define http_message_object_new _http_message_object_new extern zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC); #define http_message_object_new_ex(ce, msg) _http_message_object_new_ex(ce, msg TSRMLS_CC) diff --git a/php_http_request_api.h b/php_http_request_api.h index 5b4dc16..9a24b3c 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -34,10 +34,8 @@ extern zend_bool _http_request_supports_ssl(void); #endif #include -#define http_request_global_init() _http_request_global_init(INIT_FUNC_ARGS_PASSTHRU) -extern STATUS _http_request_global_init(INIT_FUNC_ARGS); -#define http_request_global_cleanup() _http_request_global_cleanup(TSRMLS_C) -extern void _http_request_global_cleanup(TSRMLS_D); +extern PHP_MINIT_FUNCTION(http_request); +extern PHP_MSHUTDOWN_FUNCTION(http_request); #define HTTP_REQUEST_BODY_CSTRING 1 #define HTTP_REQUEST_BODY_CURLPOST 2 diff --git a/php_http_request_method_api.h b/php_http_request_method_api.h index ed0d8a7..7275f2d 100644 --- a/php_http_request_method_api.h +++ b/php_http_request_method_api.h @@ -57,12 +57,12 @@ typedef enum { HTTP_MAX_REQUEST_METHOD = 28 } http_request_method; -#define http_request_method_global_init() _http_request_method_global_init(INIT_FUNC_ARGS_PASSTHRU) -STATUS _http_request_method_global_init(INIT_FUNC_ARGS); - #define HTTP_STD_REQUEST_METHOD(m) ((m > HTTP_NO_REQUEST_METHOD) && (m < HTTP_MAX_REQUEST_METHOD)) #define HTTP_CUSTOM_REQUEST_METHOD(m) (m - HTTP_MAX_REQUEST_METHOD) +extern PHP_MINIT_FUNCTION(http_request_method); +extern PHP_RSHUTDOWN_FUNCTION(http_request_method); + #define http_request_method_name(m) _http_request_method_name((m) TSRMLS_CC) PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC); diff --git a/php_http_request_object.h b/php_http_request_object.h index 17a9fb4..5959dbd 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -42,8 +42,8 @@ typedef struct { extern zend_class_entry *http_request_object_ce; extern zend_function_entry http_request_object_fe[]; -#define http_request_object_init() _http_request_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_request_object_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_request_object); + #define http_request_object_new _http_request_object_new extern zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC); #define http_request_object_free _http_request_object_free diff --git a/php_http_requestpool_object.h b/php_http_requestpool_object.h index 24c40e0..49bb78c 100644 --- a/php_http_requestpool_object.h +++ b/php_http_requestpool_object.h @@ -39,8 +39,8 @@ typedef struct { extern zend_class_entry *http_requestpool_object_ce; extern zend_function_entry http_requestpool_object_fe[]; -#define http_requestpool_object_init() _http_requestpool_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_requestpool_object_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_requestpool_object); + #define http_requestpool_object_new _http_requestpool_object_new extern zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC); #define http_requestpool_object_free _http_requestpool_object_free diff --git a/php_http_response_object.h b/php_http_response_object.h index 60a5be0..757bc89 100644 --- a/php_http_response_object.h +++ b/php_http_response_object.h @@ -26,8 +26,7 @@ extern zend_class_entry *http_response_object_ce; extern zend_function_entry http_response_object_fe[]; -#define http_response_object_init() _http_response_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_response_object_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_response_object); PHP_METHOD(HttpResponse, setHeader); PHP_METHOD(HttpResponse, getHeader); diff --git a/php_http_std_defs.h b/php_http_std_defs.h index 79b69ae..c13f3bd 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -406,6 +406,10 @@ typedef int STATUS; #define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; } #endif +#define PHP_MINIT_CALL(func) PHP_MINIT(func)(INIT_FUNC_ARGS_PASSTHRU) +#define PHP_RINIT_CALL(func) PHP_RINIT(func)(INIT_FUNC_ARGS_PASSTHRU) +#define PHP_MSHUTDOWN_CALL(func) PHP_MSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU) +#define PHP_RSHUTDOWN_CALL(func) PHP_RSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU) #endif /* PHP_HTTP_STD_DEFS_H */ diff --git a/php_http_util_object.h b/php_http_util_object.h index 414cc8e..53dcb5a 100644 --- a/php_http_util_object.h +++ b/php_http_util_object.h @@ -22,8 +22,7 @@ extern zend_class_entry *http_util_object_ce; extern zend_function_entry http_util_object_fe[]; -#define http_util_object_init() _http_util_object_init(INIT_FUNC_ARGS_PASSTHRU) -extern void _http_util_object_init(INIT_FUNC_ARGS); +extern PHP_MINIT_FUNCTION(http_util_object); PHP_METHOD(HttpUtil, date); PHP_METHOD(HttpUtil, absoluteUri); -- 2.30.2