X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http.c;h=d766e42cf32f667588e5a0cd5d9368881e71f6dd;hp=9aa6878561b580a09a9111250246b8d363f52d22;hb=2214902cf967c3aaf8e8493295f1ac43831ed015;hpb=80fd11fc5b72c8fadea499aec6e617d415334c2d diff --git a/http.c b/http.c index 9aa6878..d766e42 100644 --- a/http.c +++ b/http.c @@ -27,6 +27,8 @@ # include #endif +#include + #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" @@ -35,6 +37,7 @@ #include "php_http.h" #include "php_http_std_defs.h" +#include "php_http_api.h" #include "php_http_send_api.h" #ifdef ZEND_ENGINE_2 @@ -44,6 +47,7 @@ # ifdef HTTP_HAVE_CURL # include "php_http_request_object.h" # endif +# include "php_http_exception_object.h" #endif #include "phpstr/phpstr.h" @@ -64,9 +68,19 @@ ZEND_BEGIN_ARG_INFO(http_request_info_ref_4, 0) ZEND_ARG_PASS_INFO(0) ZEND_ARG_PASS_INFO(1) ZEND_END_ARG_INFO(); + +static +ZEND_BEGIN_ARG_INFO(http_request_info_ref_5, 0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(0) + ZEND_ARG_PASS_INFO(1) +ZEND_END_ARG_INFO(); #else static unsigned char http_request_info_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; static unsigned char http_request_info_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; +static unsigned char http_request_info_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; #endif /* ZEND_ENGINE_2 */ #endif /* HTTP_HAVE_CURL */ @@ -103,14 +117,14 @@ function_entry http_functions[] = { PHP_FE(http_get, http_request_info_ref_3) PHP_FE(http_head, http_request_info_ref_3) PHP_FE(http_post_data, http_request_info_ref_4) - PHP_FE(http_post_array, http_request_info_ref_4) + PHP_FE(http_post_fields, http_request_info_ref_5) #endif PHP_FE(http_auth_basic, NULL) PHP_FE(http_auth_basic_cb, NULL) #ifndef ZEND_ENGINE_2 PHP_FE(http_build_query, NULL) #endif - PHP_FE(ob_httpetaghandler, NULL) + PHP_FE(ob_etaghandler, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -140,60 +154,77 @@ static void free_to_free(void *s) efree(*(char **)s); } -/* {{{ php_http_init_globals(zend_http_globals *) */ -static void php_http_init_globals(zend_http_globals *http_globals) +/* {{{ void http_globals_ctor(zend_http_globals *) */ +#define http_globals_ctor _http_globals_ctor +static inline void _http_globals_ctor(zend_http_globals *http_globals) { http_globals->etag_started = 0; http_globals->ctype = NULL; http_globals->etag = NULL; http_globals->lmod = 0; #ifdef HTTP_HAVE_CURL - phpstr_init_ex(&http_globals->curlbuf, HTTP_CURLBUF_SIZE, 0); # if LIBCURL_VERSION_NUM < 0x070c00 memset(&http_globals->curlerr, 0, sizeof(http_globals->curlerr)); # endif zend_llist_init(&http_globals->to_free, sizeof(char *), free_to_free, 0); #endif http_globals->allowed_methods = NULL; + http_globals->cache_log = NULL; } /* }}} */ -/* {{{ static inline STATUS http_check_allowed_methods(char *, int) */ +/* {{{ void http_globals_dtor() */ +#define http_globals_dtor() _http_globals_dtor(TSRMLS_C) +static inline void _http_globals_dtor(TSRMLS_D) +{ + HTTP_G(etag_started) = 0; + HTTP_G(lmod) = 0; + + if (HTTP_G(etag)) { + efree(HTTP_G(etag)); + HTTP_G(etag) = NULL; + } + + if (HTTP_G(ctype)) { + efree(HTTP_G(ctype)); + HTTP_G(ctype) = NULL; + } + +#ifdef HTTP_HAVE_CURL +# if LIBCURL_VERSION_NUM < 0x070c00 + memset(&HTTP_G(curlerr), 0, sizeof(HTTP_G(curlerr))); +# endif +#endif + +} +/* }}} */ + +/* {{{ static inline void http_check_allowed_methods(char *, int) */ #define http_check_allowed_methods(m, l) _http_check_allowed_methods((m), (l) TSRMLS_CC) static inline void _http_check_allowed_methods(char *methods, int length TSRMLS_DC) { - if (length && SG(request_info).request_method && (!strstr(methods, SG(request_info).request_method))) { - char *allow_header = emalloc(length + sizeof("Allow: ")); - sprintf(allow_header, "Allow: %s", methods); - http_send_header(allow_header); - efree(allow_header); - http_send_status(405); - zend_bailout(); + if (length && SG(request_info).request_method) { + if (SUCCESS != http_check_method_ex(SG(request_info).request_method, methods)) { + char *header = emalloc(length + sizeof("Allow: ")); + sprintf(header, "Allow: %s", methods); + http_exit(405, header); + } } } /* }}} */ /* {{{ PHP_INI */ -PHP_INI_MH(update_allowed_methods) +PHP_INI_MH(http_update_allowed_methods) { http_check_allowed_methods(new_value, new_value_length); return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); } +#define http_update_cache_log OnUpdateString + PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("http.allowed_methods", - /* HTTP 1.1 */ - "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " - /* WebDAV - RFC 2518 * / - "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " - /* WebDAV Versioning - RFC 3253 * / - "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " - "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " - /* WebDAV Access Control - RFC 3744 * / - "ACL, " - /* END */ - , - PHP_INI_ALL, update_allowed_methods, allowed_methods, zend_http_globals, http_globals) + HTTP_INI_ENTRY("http.allowed_methods", HTTP_KNOWN_METHODS, PHP_INI_ALL, allowed_methods) + HTTP_INI_ENTRY("http.cache_log", NULL, PHP_INI_ALL, cache_log) PHP_INI_END() /* }}} */ @@ -210,7 +241,7 @@ static void *http_curl_calloc(size_t n, size_t s) { return ecalloc(n, s); } /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(http) { - ZEND_INIT_MODULE_GLOBALS(http, php_http_init_globals, NULL); + ZEND_INIT_MODULE_GLOBALS(http, http_globals_ctor, NULL); REGISTER_INI_ENTRIES(); #ifdef HTTP_HAVE_CURL @@ -233,6 +264,7 @@ PHP_MINIT_FUNCTION(http) # ifdef HTTP_HAVE_CURL http_request_object_init(INIT_FUNC_ARGS_PASSTHRU); # endif /* HTTP_HAVE_CURL */ + http_exception_object_init(INIT_FUNC_ARGS_PASSTHRU); #endif /* ZEND_ENGINE_2 */ return SUCCESS; @@ -244,7 +276,6 @@ PHP_MSHUTDOWN_FUNCTION(http) { UNREGISTER_INI_ENTRIES(); #ifdef HTTP_HAVE_CURL - phpstr_dtor(&HTTP_G(curlbuf)); curl_global_cleanup(); #endif return SUCCESS; @@ -263,28 +294,7 @@ PHP_RINIT_FUNCTION(http) /* {{{ PHP_RSHUTDOWN_FUNCTION */ PHP_RSHUTDOWN_FUNCTION(http) { - HTTP_G(etag_started) = 0; - HTTP_G(lmod) = 0; - - if (HTTP_G(etag)) { - efree(HTTP_G(etag)); - HTTP_G(etag) = NULL; - } - - if (HTTP_G(ctype)) { - efree(HTTP_G(ctype)); - HTTP_G(ctype) = NULL; - } - -#ifdef HTTP_HAVE_CURL -# if LIBCURL_VERSION_NUM < 0x070c00 - memset(&HTTP_G(curlerr), 0, sizeof(HTTP_G(curlerr))); -# endif - phpstr_dtor(&HTTP_G(curlbuf)); -#endif - - zval_dtor(&HTTP_G(message_object_tmp_property)); - + http_globals_dtor(); return SUCCESS; } /* }}} */ @@ -293,7 +303,7 @@ PHP_RSHUTDOWN_FUNCTION(http) PHP_MINFO_FUNCTION(http) { #ifdef ZEND_ENGINE_2 -# define HTTP_FUNC_AVAIL(CLASS) "procedural, object oriented (class " CLASS ")" +# define HTTP_FUNC_AVAIL(CLASS) "procedural, object oriented (" CLASS ")" #else # define HTTP_FUNC_AVAIL(CLASS) "procedural" #endif @@ -301,7 +311,7 @@ PHP_MINFO_FUNCTION(http) #ifdef HTTP_HAVE_CURL # define HTTP_CURL_VERSION curl_version() # ifdef ZEND_ENGINE_2 -# define HTTP_CURL_AVAIL(CLASS) "procedural, object oriented (class " CLASS ")" +# define HTTP_CURL_AVAIL(CLASS) "procedural, object oriented (" CLASS ")" # else # define HTTP_CURL_AVAIL(CLASS) "procedural" # endif @@ -320,7 +330,7 @@ PHP_MINFO_FUNCTION(http) php_info_print_table_start(); php_info_print_table_header(2, "Functionality", "Availability"); - php_info_print_table_row(2, "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil")); + php_info_print_table_row(2, "Miscellaneous Utilities:", HTTP_FUNC_AVAIL("HttpUtil, HttpMessage")); php_info_print_table_row(2, "Extended HTTP Responses:", HTTP_FUNC_AVAIL("HttpResponse")); php_info_print_table_row(2, "Extended HTTP Requests:", HTTP_CURL_AVAIL("HttpRequest")); php_info_print_table_end();