From: Michael Wallner Date: Tue, 19 Jul 2005 15:57:44 +0000 (+0000) Subject: - added http_get_request_body() X-Git-Tag: RELEASE_0_10_0~40 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e47ee304be6758fbbfd238476f8a6bda9090fe12;p=m6w6%2Fext-http - added http_get_request_body() --- diff --git a/http.c b/http.c index 4460d69..3e7baeb 100644 --- a/http.c +++ b/http.c @@ -85,6 +85,7 @@ function_entry http_functions[] = { PHP_FE(http_split_response, NULL) PHP_FE(http_parse_headers, NULL) PHP_FE(http_get_request_headers, NULL) + PHP_FE(http_get_request_body, NULL) PHP_FE(http_match_request_header, NULL) #ifdef HTTP_HAVE_CURL PHP_FE(http_get, http_arg_pass_ref_3) diff --git a/http_api.c b/http_api.c index 5bf3920..d943b0d 100644 --- a/http_api.c +++ b/http_api.c @@ -24,6 +24,8 @@ #include "php.h" #include "ext/standard/url.h" +#include "SAPI.h" + #include "php_http.h" #include "php_http_std_defs.h" #include "php_http_api.h" @@ -226,6 +228,20 @@ PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zen } /* }}} */ +/* {{{ zend_bool http_get_request_body(char **, size_t *) */ +PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC) +{ + *length = 0; + *body = NULL; + + if (SG(request_info).raw_post_data) { + *length = SG(request_info).raw_post_data_length; + *body = (char *) (dup ? estrndup(SG(request_info).raw_post_data, *length) : SG(request_info).raw_post_data); + return SUCCESS; + } + return FAILURE; +} +/* }}} */ /* {{{ char *http_chunked_decode(char *, size_t, char **, size_t *) */ PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len, diff --git a/http_functions.c b/http_functions.c index 8e27b76..4e67be7 100644 --- a/http_functions.c +++ b/http_functions.c @@ -663,6 +663,25 @@ PHP_FUNCTION(http_get_request_headers) } /* }}} */ +/* {{{ proto string http_get_request_body(void) + * + * Get the raw request body (e.g. POST or PUT data). + */ +PHP_FUNCTION(http_get_request_body) +{ + char *body; + size_t length; + + NO_ARGS; + + if (SUCCESS == http_get_request_body(&body, &length)) { + RETURN_STRING(body, (int) length, 0); + } else { + RETURN_NULL(); + } +} +/* }}} */ + /* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false]) * * Match an incoming HTTP header. diff --git a/http_util_object.c b/http_util_object.c index adae1b0..123c83d 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -48,6 +48,7 @@ zend_function_entry http_util_object_fe[] = { HTTP_STATIC_ME_ALIAS(splitResponse, http_split_response, NULL) HTTP_STATIC_ME_ALIAS(parseHeaders, http_parse_headers, NULL) HTTP_STATIC_ME_ALIAS(getRequestHeaders, http_get_request_headers, NULL) + HTTP_STATIC_ME_ALIAS(getRequestBody, http_get_request_body, NULL) #ifdef HTTP_HAVE_CURL HTTP_STATIC_ME_ALIAS(get, http_get, http_arg_pass_ref_3) HTTP_STATIC_ME_ALIAS(head, http_head, http_arg_pass_ref_3) diff --git a/php_http.h b/php_http.h index 409bcc2..8aa524b 100644 --- a/php_http.h +++ b/php_http.h @@ -106,6 +106,7 @@ PHP_FUNCTION(http_chunked_decode); PHP_FUNCTION(http_split_response); PHP_FUNCTION(http_parse_headers); PHP_FUNCTION(http_get_request_headers); +PHP_FUNCTION(http_get_request_body); PHP_FUNCTION(http_match_request_header); #ifdef HTTP_HAVE_CURL PHP_FUNCTION(http_get); diff --git a/php_http_api.h b/php_http_api.h index bd229e3..472c4b9 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -53,6 +53,10 @@ extern STATUS _http_check_method_ex(const char *method, const char *methods); #define http_get_server_var_ex(v, s) _http_get_server_var_ex((v), (s), 0 TSRMLS_CC) PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC); +#define http_get_request_body(b, l) _http_get_request_body_ex((b), (l), 1 TSRMLS_CC) +#define http_get_Request_body_ex(b, l, d) _http_get_request_body_ex((b), (l), (d) TSRMLS_CC) +PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC); + #define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC) PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC); diff --git a/php_http_util_object.h b/php_http_util_object.h index 080fa8b..d89c38f 100644 --- a/php_http_util_object.h +++ b/php_http_util_object.h @@ -42,6 +42,7 @@ PHP_METHOD(HttpUtil, chunkedDecode); PHP_METHOD(HttpUtil, splitResponse); PHP_METHOD(HttpUtil, parseHeaders); PHP_METHOD(HttpUtil, getRequestHeaders); +PHP_METHOD(HttpUtil, getRequestBody); #ifdef HTTP_HAVE_CURL PHP_METHOD(HttpUtil, get); PHP_METHOD(HttpUtil, head);