X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http.c;h=be06ac5aa002f0b43abdc0ceb11f64f75bbc98f0;hp=991e84e8fc031ff4c30fb487cf0f8bee8f051739;hb=8cdf77bbae1974a94d69ab757cbda38b88299e5f;hpb=4a881fb37338bfeacd40c42a97f334c9faed299a diff --git a/http.c b/http.c index 991e84e..be06ac5 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,13 +37,17 @@ #include "php_http.h" #include "php_http_std_defs.h" - #include "php_http_send_api.h" -#include "php_http_util_object.h" -#include "php_http_message_object.h" -#include "php_http_response_object.h" -#include "php_http_request_object.h" +#ifdef ZEND_ENGINE_2 +# include "php_http_util_object.h" +# include "php_http_message_object.h" +# include "php_http_response_object.h" +# ifdef HTTP_HAVE_CURL +# include "php_http_request_object.h" +# endif +# include "php_http_exception_object.h" +#endif #include "phpstr/phpstr.h" @@ -159,14 +165,24 @@ static void php_http_init_globals(zend_http_globals *http_globals) #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(); + char *found, *header; + + if (!length || !SG(request_info).request_method) { + return; } + + if ( (found = strstr(methods, SG(request_info).request_method)) && + (found == SG(request_info).request_method || !isalpha(found[-1])) && + (!isalpha(found[strlen(SG(request_info).request_method) + 1]))) { + return; + } + + header = emalloc(length + sizeof("Allow: ")); + sprintf(header, "Allow: %s", methods); + http_send_header(header); + efree(header); + http_send_status(405); + zend_bailout(); } /* }}} */ @@ -230,6 +246,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; @@ -288,7 +305,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 @@ -296,7 +313,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 @@ -315,7 +332,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();