- added http_get_request_body()
authorMichael Wallner <mike@php.net>
Tue, 19 Jul 2005 15:57:44 +0000 (15:57 +0000)
committerMichael Wallner <mike@php.net>
Tue, 19 Jul 2005 15:57:44 +0000 (15:57 +0000)
http.c
http_api.c
http_functions.c
http_util_object.c
php_http.h
php_http_api.h
php_http_util_object.h

diff --git a/http.c b/http.c
index 4460d69..3e7baeb 100644 (file)
--- 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_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)
        PHP_FE(http_match_request_header, NULL)
 #ifdef HTTP_HAVE_CURL
        PHP_FE(http_get, http_arg_pass_ref_3)
index 5bf3920..d943b0d 100644 (file)
@@ -24,6 +24,8 @@
 #include "php.h"
 #include "ext/standard/url.h"
 
 #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"
 #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,
 
 /* {{{ 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,
index 8e27b76..4e67be7 100644 (file)
@@ -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.
 /* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
  *
  * Match an incoming HTTP header.
index adae1b0..123c83d 100644 (file)
@@ -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(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)
 #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)
index 409bcc2..8aa524b 100644 (file)
@@ -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_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);
 PHP_FUNCTION(http_match_request_header);
 #ifdef HTTP_HAVE_CURL
 PHP_FUNCTION(http_get);
index bd229e3..472c4b9 100644 (file)
@@ -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_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);
 
 #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);
 
index 080fa8b..d89c38f 100644 (file)
@@ -42,6 +42,7 @@ PHP_METHOD(HttpUtil, chunkedDecode);
 PHP_METHOD(HttpUtil, splitResponse);
 PHP_METHOD(HttpUtil, parseHeaders);
 PHP_METHOD(HttpUtil, getRequestHeaders);
 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);
 #ifdef HTTP_HAVE_CURL
 PHP_METHOD(HttpUtil, get);
 PHP_METHOD(HttpUtil, head);