From b3afcfc70bf06c062115f4994cc04fc8c6e4aa67 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 23 Nov 2006 15:33:43 +0000 Subject: [PATCH] - ditch usage of clunky HTTP_GSC/HTTP_GSP macros - shrink protos - add factory methods --- http.c | 3 +- http_api.c | 26 +- http_cache_api.c | 8 +- http_deflatestream_object.c | 55 ++- http_functions.c | 756 ++--------------------------- http_headers_api.c | 13 +- http_inflatestream_object.c | 55 ++- http_message_object.c | 293 +++-------- http_querystring_object.c | 105 ++-- http_request_object.c | 528 ++++---------------- http_requestdatashare_object.c | 38 +- http_requestpool_object.c | 160 +----- http_url_api.c | 6 +- package.xml | 40 +- package2.xml | 4 +- php_http.h | 1 - php_http_api.h | 20 +- php_http_deflatestream_object.h | 1 + php_http_inflatestream_object.h | 1 + php_http_message_object.h | 2 +- php_http_querystring_object.h | 5 +- php_http_request_object.h | 1 + php_http_requestdatashare_object.h | 1 + 23 files changed, 415 insertions(+), 1707 deletions(-) diff --git a/http.c b/http.c index 05f448f..521f2b5 100644 --- a/http.c +++ b/http.c @@ -68,7 +68,6 @@ ZEND_GET_MODULE(http) /* {{{ http_functions[] */ zend_function_entry http_functions[] = { - PHP_FE(http_test, NULL) PHP_FE(http_date, NULL) PHP_FE(http_build_url, http_arg_pass_ref_4) PHP_FE(http_build_str, NULL) @@ -187,7 +186,7 @@ static void http_globals_init_once(zend_http_globals *G) static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC) { #ifdef HTTP_HAVE_SAPI_RTIME - G->request.time = Z_LVAL_P(http_get_server_var("REQUEST_TIME")); + G->request.time = sapi_get_request_time(TSRMLS_C); #else G->request.time = time(NULL); #endif diff --git a/http_api.c b/http_api.c index 4e304af..ab59457 100644 --- a/http_api.c +++ b/http_api.c @@ -173,6 +173,26 @@ zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend_class_ return new_exception; } /* }}} */ + +/* {{{ STATUS http_object_new(zend_object_value *, const char *, uint, http_object_new_t, zend_class_entry *, void *, void **) */ +STATUS _http_object_new(zend_object_value *ov, const char *cname_str, uint cname_len, http_object_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC) +{ + zend_class_entry *ce = parent_ce; + + if (cname_str && cname_len) { + if (!(ce = zend_fetch_class((char *) cname_str, cname_len, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC))) { + return FAILURE; + } + if (!instanceof_function(ce, parent_ce TSRMLS_CC)) { + http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Class %s does not extend %s", cname_str, parent_ce->name); + return FAILURE; + } + } + + *ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC); + return SUCCESS; +} +/* }}} */ #endif /* ZEND_ENGINE_2 */ /* {{{ void http_log(char *, char *, char *) */ @@ -265,14 +285,14 @@ STATUS _http_check_method_ex(const char *method, const char *methods) /* }}} */ /* {{{ zval *http_get_server_var_ex(char *, size_t) */ -PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC) +PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_len, zend_bool check TSRMLS_DC) { zval **hsv, **var; char *env; /* if available, this is a lot faster than accessing $_SERVER */ if (sapi_module.getenv) { - if ((!(env = sapi_module.getenv((char *) key, key_size TSRMLS_CC))) || (check && !*env)) { + if ((!(env = sapi_module.getenv((char *) key, key_len TSRMLS_CC))) || (check && !*env)) { return NULL; } if (HTTP_G->server_var) { @@ -290,7 +310,7 @@ PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zen if ((SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) { return NULL; } - if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void *) &var))) { + if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_len + 1, (void *) &var))) { return NULL; } if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) { diff --git a/http_cache_api.c b/http_cache_api.c index adba374..f7f0c81 100644 --- a/http_cache_api.c +++ b/http_cache_api.c @@ -78,7 +78,9 @@ PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zval *zmodified; char *modified, *chr_ptr; - HTTP_GSC(zmodified, entry, !enforce_presence); + if (!(zmodified = http_get_server_var(entry, 1))) { + return !enforce_presence; + } modified = estrndup(Z_STRVAL_P(zmodified), Z_STRLEN_P(zmodified)); if ((chr_ptr = strrchr(modified, ';'))) { @@ -98,7 +100,9 @@ PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, char *quoted_etag; zend_bool result; - HTTP_GSC(zetag, entry, !enforce_presence); + if (!(zetag = http_get_server_var_ex(entry, strlen(entry)+1, 1))) { + return !enforce_presence; + } if (NULL != strchr(Z_STRVAL_P(zetag), '*')) { return 1; diff --git a/http_deflatestream_object.c b/http_deflatestream_object.c index 9d99bc9..d1e0d6f 100644 --- a/http_deflatestream_object.c +++ b/http_deflatestream_object.c @@ -30,6 +30,11 @@ HTTP_BEGIN_ARGS(__construct, 0) HTTP_ARG_VAL(flags, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(factory, 0) + HTTP_ARG_VAL(flags, 0) + HTTP_ARG_VAL(class_name, 0) +HTTP_END_ARGS; + HTTP_BEGIN_ARGS(update, 1) HTTP_ARG_VAL(data, 0) HTTP_END_ARGS; @@ -50,6 +55,8 @@ zend_function_entry http_deflatestream_object_fe[] = { HTTP_DEFLATE_ME(flush, ZEND_ACC_PUBLIC) HTTP_DEFLATE_ME(finish, ZEND_ACC_PUBLIC) + HTTP_DEFLATE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + EMPTY_FUNCTION_ENTRY }; static zend_object_handlers http_deflatestream_object_handlers; @@ -139,11 +146,7 @@ void _http_deflatestream_object_free(zend_object *object TSRMLS_DC) } /* {{{ proto void HttpDeflateStream::__construct([int flags = 0]) - * - * Creates a new HttpDeflateStream object instance. - * - * Accepts an optional int parameter specifying how to initialize the deflate stream. - */ + Creates a new HttpDeflateStream object instance. */ PHP_METHOD(HttpDeflateStream, __construct) { long flags = 0; @@ -162,14 +165,29 @@ PHP_METHOD(HttpDeflateStream, __construct) } /* }}} */ +/* {{{ proto HttpDeflateStream HttpDeflateStream::factory([int flags[, string class = "HttpDeflateStream"]]) + Creates a new HttpDeflateStream object instance. */ +PHP_METHOD(HttpDeflateStream, factory) +{ + long flags = 0; + char *cn = NULL; + int cl = 0; + + SET_EH_THROW_HTTP(); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &flags, &cn, &cl)) { + zend_object_value ov; + http_encoding_stream *s = http_encoding_deflate_stream_init(NULL, flags & 0x0fffffff); + + if (SUCCESS == http_object_new(&ov, cn, cl, _http_deflatestream_object_new_ex, http_deflatestream_object_ce, s, NULL)) { + RETVAL_OBJVAL(ov, 0); + } + } + SET_EH_NORMAL(); +} +/* }}} */ + /* {{{ proto string HttpDeflateStream::update(string data) - * - * Passes more data through the deflate stream. - * - * Expects a string parameter containing (a part of) the data to deflate. - * - * Returns deflated data on success or FALSE on failure. - */ + Passes more data through the deflate stream. */ PHP_METHOD(HttpDeflateStream, update) { int data_len; @@ -194,11 +212,7 @@ PHP_METHOD(HttpDeflateStream, update) /* }}} */ /* {{{ proto string HttpDeflateStream::flush([string data]) - * - * Flushes the deflate stream. - * - * Returns some deflated data as string on success or FALSE on failure. - */ + Flushes the deflate stream. */ PHP_METHOD(HttpDeflateStream, flush) { int data_len = 0; @@ -239,11 +253,7 @@ PHP_METHOD(HttpDeflateStream, flush) /* }}} */ /* {{{ proto string HttpDeflateStream::finish([string data]) - * - * Finalizes the deflate stream. The deflate stream can be reused after finalizing. - * - * Returns the final part of deflated data. - */ + Finalizes the deflate stream. The deflate stream can be reused after finalizing. */ PHP_METHOD(HttpDeflateStream, finish) { int data_len = 0; @@ -287,7 +297,6 @@ PHP_METHOD(HttpDeflateStream, finish) } /* }}} */ - #endif /* ZEND_ENGINE_2 && HTTP_HAVE_ZLIB*/ /* diff --git a/http_functions.c b/http_functions.c index 869442d..c156c8a 100644 --- a/http_functions.c +++ b/http_functions.c @@ -38,14 +38,7 @@ #include "php_http_url_api.h" /* {{{ proto string http_date([int timestamp]) - * - * Compose a valid HTTP date regarding RFC 1123 - * looking like: "Wed, 22 Dec 2004 11:34:47 GMT" - * - * Accepts an optional unix timestamp as parameter. - * - * Returns the HTTP date as string. - */ + Compose a valid HTTP date regarding RFC 1123 looking like: "Wed, 22 Dec 2004 11:34:47 GMT" */ PHP_FUNCTION(http_date) { long t = -1; @@ -67,47 +60,7 @@ PHP_FUNCTION(http_date) #endif /* {{{ proto string http_build_url([mixed url[, mixed parts[, int flags = HTTP_URL_REPLACE[, array &new_url]]]]) - * - * Build an URL. - * - * Expexts (part(s) of) an URL as first parameter in form of a string or assoziative array - * like parse_url() returns. Accepts an optional second parameter in the same way as the - * first argument. Accepts an optional third integer parameter, which is a bitmask of - * binary or'ed HTTP_URL_* constants. The optional fourth parameter will be filled - * with the results as associative array like parse_url() would return. - * - * The parts of the second URL will be merged into the first according to the flags argument. - * The following flags are recognized: - *
- *	- HTTP_URL_REPLACE:        (default) set parts of the second url will replace the parts in the first
- *	- HTTP_URL_JOIN_PATH:      the path of the second url will be merged into the one of the first
- *	- HTTP_URL_JOIN_QUERY:     the two querystrings will be merged recursively
- *	- HTTP_URL_STRIP_USER:     the user part will not appear in the result
- *	- HTTP_URL_STRIP_PASS:     the password part will not appear in the result
- *	- HTTP_URL_STRIP_AUTH:     neither the user nor the password part will appear in the result
- *	- HTTP_URL_STRIP_PORT:     no explicit port will be set in the result
- *	- HTTP_URL_STRIP_PATH:     the path part will not appear in the result
- *	- HTTP_URL_STRIP_QUERY:    no query string will be present in the result
- *	- HTTP_URL_STRIP_FRAGMENT: no fragment will be present in the result
- * 
- * - * Example: - *
- *  "ftp",
- * 				"host"   => "ftp.example.com",
- * 				"path"   => "files/current/",
- * 				"query"  => "a=c"
- * 			),
- * 			HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
- * 		);
- * ?>
- * 
- * Returns the new URL as string on success or FALSE on failure. - */ + Build an URL. */ PHP_FUNCTION(http_build_url) { char *url_str = NULL; @@ -167,16 +120,7 @@ PHP_FUNCTION(http_build_url) /* }}} */ /* {{{ proto string http_build_str(array query [, string prefix[, string arg_separator]]) - * - * Opponent to parse_str(). - * - * Expects an array as first argument which represents the parts of the query string to build. - * Accepts a string as optional second parameter containing a top-level prefix to use. - * The optional third parameter should specify an argument separator to use (by default the - * INI setting arg_separator.output will be used, or "&" if neither is set). - * - * Returns the built query as string on success or FALSE on failure. - */ + Opponent to parse_str(). */ PHP_FUNCTION(http_build_str) { zval *formdata; @@ -250,40 +194,8 @@ PHP_FUNCTION(http_build_str) } \ } - /* {{{ proto string http_negotiate_language(array supported[, array &result]) - * - * This function negotiates the clients preferred language based on its - * Accept-Language HTTP header. The qualifier is recognized and languages - * without qualifier are rated highest. The qualifier will be decreased by - * 10% for partial matches (i.e. matching primary language). - * - * Expects an array as parameter containing the supported languages as values. - * If the optional second parameter is supplied, it will be filled with an - * array containing the negotiation results. - * - * Returns the negotiated language or the default language (i.e. first array entry) - * if none match. - * - * Example: - *
- * 
- * 
- */ + Negotiate the clients preferred language. */ PHP_FUNCTION(http_negotiate_language) { zval *supported, *rs_array = NULL; @@ -302,40 +214,7 @@ PHP_FUNCTION(http_negotiate_language) /* }}} */ /* {{{ proto string http_negotiate_charset(array supported[, array &result]) - * - * This function negotiates the clients preferred charset based on its - * Accept-Charset HTTP header. The qualifier is recognized and charsets - * without qualifier are rated highest. - * - * Expects an array as parameter containing the supported charsets as values. - * If the optional second parameter is supplied, it will be filled with an - * array containing the negotiation results. - * - * Returns the negotiated charset or the default charset (i.e. first array entry) - * if none match. - * - * Example: - *
- * 
- * 
- */ + Negotiate the clients preferred charset. */ PHP_FUNCTION(http_negotiate_charset) { zval *supported, *rs_array = NULL; @@ -354,26 +233,7 @@ PHP_FUNCTION(http_negotiate_charset) /* }}} */ /* {{{ proto string http_negotiate_ctype(array supported[, array &result]) - * - * This function negotiates the clients preferred content type based on its - * Accept HTTP header. The qualifier is recognized and content types - * without qualifier are rated highest. - * - * Expects an array as parameter containing the supported content types as values. - * If the optional second parameter is supplied, it will be filled with an - * array containing the negotiation results. - * - * Returns the negotiated content type or the default content type - * (i.e. first array entry) if none match. - * - * Example: - *
- * 
- * 
- */ + Negotiate the clients preferred content type. */ PHP_FUNCTION(http_negotiate_content_type) { zval *supported, *rs_array = NULL; @@ -392,13 +252,7 @@ PHP_FUNCTION(http_negotiate_content_type) /* }}} */ /* {{{ proto bool http_send_status(int status) - * - * Send HTTP status code. - * - * Expects an HTTP status code as parameter. - * - * Returns TRUE on success or FALSE on failure. - */ + Send HTTP status code. */ PHP_FUNCTION(http_send_status) { int status = 0; @@ -416,15 +270,7 @@ PHP_FUNCTION(http_send_status) /* }}} */ /* {{{ proto bool http_send_last_modified([int timestamp]) - * - * Send a "Last-Modified" header with a valid HTTP date. - * - * Accepts a unix timestamp, converts it to a valid HTTP date and - * sends it as "Last-Modified" HTTP header. If timestamp is - * omitted, the current time will be sent. - * - * Returns TRUE on success or FALSE on failure. - */ + Send a "Last-Modified" header with a valid HTTP date. */ PHP_FUNCTION(http_send_last_modified) { long t = -1; @@ -442,15 +288,7 @@ PHP_FUNCTION(http_send_last_modified) /* }}} */ /* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream']) - * - * Send the Content-Type of the sent entity. This is particularly important - * if you use the http_send() API. - * - * Accepts an optional string parameter containing the desired content type - * (primary/secondary). - * - * Returns TRUE on success or FALSE on failure. - */ + Send the Content-Type of the sent entity. This is particularly important if you use the http_send() API. */ PHP_FUNCTION(http_send_content_type) { char *ct = "application/x-octetstream"; @@ -465,18 +303,7 @@ PHP_FUNCTION(http_send_content_type) /* }}} */ /* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false]) - * - * Send the Content-Disposition. The Content-Disposition header is very useful - * if the data actually sent came from a file or something similar, that should - * be "saved" by the client/user (i.e. by browsers "Save as..." popup window). - * - * Expects a string parameter specifying the file name the "Save as..." dialog - * should display. Optionally accepts a bool parameter, which, if set to true - * and the user agent knows how to handle the content type, will probably not - * cause the popup window to be shown. - * - * Returns TRUE on success or FALSE on failure. - */ + Send the Content-Disposition. */ PHP_FUNCTION(http_send_content_disposition) { char *filename; @@ -491,18 +318,7 @@ PHP_FUNCTION(http_send_content_disposition) /* }}} */ /* {{{ proto bool http_match_modified([int timestamp[, bool for_range = false]]) - * - * Matches the given unix timestamp against the clients "If-Modified-Since" - * resp. "If-Unmodified-Since" HTTP headers. - * - * Accepts a unix timestamp which should be matched. Optionally accepts an - * additional bool parameter, which if set to true will check the header - * usually used to validate HTTP ranges. If timestamp is omitted, the - * current time will be used. - * - * Returns TRUE if timestamp represents an earlier date than the header, - * else FALSE. - */ + Matches the given unix timestamp against the clients "If-Modified-Since" resp. "If-Unmodified-Since" HTTP headers. */ PHP_FUNCTION(http_match_modified) { long t = -1; @@ -525,17 +341,7 @@ PHP_FUNCTION(http_match_modified) /* }}} */ /* {{{ proto bool http_match_etag(string etag[, bool for_range = false]) - * - * Matches the given ETag against the clients "If-Match" resp. - * "If-None-Match" HTTP headers. - * - * Expects a string parameter containing the ETag to compare. Optionally - * accepts a bool parameter, which, if set to true, will check the header - * usually used to validate HTTP ranges. - * - * Returns TRUE if ETag matches or the header contained the asterisk ("*"), - * else FALSE. - */ + Matches the given ETag against the clients "If-Match" resp. "If-None-Match" HTTP headers. */ PHP_FUNCTION(http_match_etag) { int etag_len; @@ -554,23 +360,7 @@ PHP_FUNCTION(http_match_etag) /* }}} */ /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]]) - * - * Attempts to cache the sent entity by its last modification date. - * - * Accepts a unix timestamp as parameter which is handled as follows: - * - * If timestamp_or_expires is greater than 0, it is handled as timestamp - * and will be sent as date of last modification. If it is 0 or omitted, - * the current time will be sent as Last-Modified date. If it's negative, - * it is handled as expiration time in seconds, which means that if the - * requested last modification date is not between the calculated timespan, - * the Last-Modified header is updated and the actual body will be sent. - * - * Returns FALSE on failure, or *exits* with "304 Not Modified" if the entity is cached. - * - * A log entry will be written to the cache log if the INI entry - * http.log.cache is set and the cache attempt was successful. - */ + Attempts to cache the sent entity by its last modification date. */ PHP_FUNCTION(http_cache_last_modified) { long last_modified = 0, send_modified = 0, t; @@ -587,7 +377,7 @@ PHP_FUNCTION(http_cache_last_modified) /* 0 or omitted */ if (!last_modified) { /* does the client have? (att: caching "forever") */ - if ((zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE"))) { + if ((zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE", 1))) { last_modified = send_modified = http_parse_date(Z_STRVAL_P(zlm)); /* send current time */ } else { @@ -607,19 +397,7 @@ PHP_FUNCTION(http_cache_last_modified) /* }}} */ /* {{{ proto bool http_cache_etag([string etag]) - * - * Attempts to cache the sent entity by its ETag, either supplied or generated - * by the hash algorithm specified by the INI setting "http.etag.mode". - * - * If the clients "If-None-Match" header matches the supplied/calculated - * ETag, the body is considered cached on the clients side and - * a "304 Not Modified" status code is issued. - * - * Returns FALSE on failure, or *exits* with "304 Not Modified" if the entity is cached. - * - * A log entry is written to the cache log if the INI entry - * "http.log.cache" is set and the cache attempt was successful. - */ + Attempts to cache the sent entity by its ETag, either supplied or generated by the hash algorithm specified by the INI setting "http.etag.mode". */ PHP_FUNCTION(http_cache_etag) { char *etag = NULL; @@ -636,10 +414,7 @@ PHP_FUNCTION(http_cache_etag) /* }}} */ /* {{{ proto string ob_etaghandler(string data, int mode) - * - * For use with ob_start(). Output buffer handler generating an ETag with - * the hash algorithm specified with the INI setting "http.etag.mode". - */ + For use with ob_start(). Output buffer handler generating an ETag with the hash algorithm specified with the INI setting "http.etag.mode". */ PHP_FUNCTION(ob_etaghandler) { char *data; @@ -656,26 +431,7 @@ PHP_FUNCTION(ob_etaghandler) /* }}} */ /* {{{ proto void http_throttle(double sec[, int bytes = 40960]) - * - * Sets the throttle delay and send buffer size for use with http_send() API. - * Provides a basic throttling mechanism, which will yield the current process - * resp. thread until the entity has been completely sent, though. - * - * Expects a double parameter specifying the seconds too sleep() after - * each chunk sent. Additionally accepts an optional int parameter - * representing the chunk size in bytes. - * - * Example: - *
- * 
- * 
- */ + Sets the throttle delay and send buffer size for use with http_send() API. */ PHP_FUNCTION(http_throttle) { long chunk_size = HTTP_SENDBUF_SIZE; @@ -691,34 +447,7 @@ PHP_FUNCTION(http_throttle) /* }}} */ /* {{{ proto void http_redirect([string url[, array params[, bool session = false[, int status = 302]]]]) - * - * Redirect to the given url. - * - * The supplied url will be expanded with http_build_url(), the params array will - * be treated with http_build_query() and the session identification will be appended - * if session is true. - * - * The HTTP response code will be set according to status. - * You can use one of the following constants for convenience: - * - HTTP_REDIRECT 302 Found for GET/HEAD, else 303 See Other - * - HTTP_REDIRECT_PERM 301 Moved Permanently - * - HTTP_REDIRECT_FOUND 302 Found - * - HTTP_REDIRECT_POST 303 See Other - * - HTTP_REDIRECT_PROXY 305 Use Proxy - * - HTTP_REDIRECT_TEMP 307 Temporary Redirect - * - * Please see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3 - * for which redirect response code to use in which situation. - * - * To be RFC compliant, "Redirecting to URL." will be displayed, - * if the client doesn't redirect immediately, and the request method was - * another one than HEAD. - * - * Returns FALSE on failure, or *exits* on success. - * - * A log entry will be written to the redirect log, if the INI entry - * "http.log.redirect" is set and the redirect attempt was successful. - */ + Redirect to the given url. */ PHP_FUNCTION(http_redirect) { int url_len = 0; @@ -817,11 +546,7 @@ PHP_FUNCTION(http_redirect) /* }}} */ /* {{{ proto bool http_send_data(string data) - * - * Sends raw data with support for (multiple) range requests. - * - * Returns TRUE on success, or FALSE on failure. - */ + Sends raw data with support for (multiple) range requests. */ PHP_FUNCTION(http_send_data) { int data_len; @@ -836,13 +561,7 @@ PHP_FUNCTION(http_send_data) /* }}} */ /* {{{ proto bool http_send_file(string file) - * - * Sends a file with support for (multiple) range requests. - * - * Expects a string parameter referencing the file to send. - * - * Returns TRUE on success, or FALSE on failure. - */ + Sends a file with support for (multiple) range requests. */ PHP_FUNCTION(http_send_file) { char *file; @@ -860,13 +579,7 @@ PHP_FUNCTION(http_send_file) /* }}} */ /* {{{ proto bool http_send_stream(resource stream) - * - * Sends an already opened stream with support for (multiple) range requests. - * - * Expects a resource parameter referencing the stream to read from. - * - * Returns TRUE on success, or FALSE on failure. - */ + Sends an already opened stream with support for (multiple) range requests. */ PHP_FUNCTION(http_send_stream) { zval *zstream; @@ -882,13 +595,7 @@ PHP_FUNCTION(http_send_stream) /* }}} */ /* {{{ proto string http_chunked_decode(string encoded) - * - * Decodes a string that was HTTP-chunked encoded. - * - * Expects a chunked encoded string as parameter. - * - * Returns the decoded string on success or FALSE on failure. - */ + Decodes a string that was HTTP-chunked encoded. */ PHP_FUNCTION(http_chunked_decode) { char *encoded = NULL, *decoded = NULL; @@ -908,47 +615,7 @@ PHP_FUNCTION(http_chunked_decode) /* }}} */ /* {{{ proto object http_parse_message(string message) - * - * Parses (a) http_message(s) into a simple recursive object structure. - * - * Expects a string parameter containing a single HTTP message or - * several consecutive HTTP messages. - * - * Returns an hierarchical object structure of the parsed messages. - * - * Example: - *
- *  3)));
- * 
- * stdClass object
- * (
- *     [type] => 2
- *     [httpVersion] => 1.1
- *     [responseCode] => 200
- *     [headers] => Array 
- *         (
- *             [Content-Length] => 3
- *             [Server] => Apache
- *         )
- *     [body]  => Hi!
- *     [parentMessage] => stdClass object
- *     (
- *         [type] => 2
- *         [httpVersion] => 1.1
- *         [responseCode] => 302
- *         [headers] => Array 
- *             (
- *                 [Content-Length] => 0
- *                 [Location] => ...
- *             )
- *         [body]  => 
- *         [parentMessage] => ...
- *     )
- * )
- * ?>
- * 
- */ + Parses (a) http_message(s) into a simple recursive object structure. */ PHP_FUNCTION(http_parse_message) { char *message; @@ -970,38 +637,7 @@ PHP_FUNCTION(http_parse_message) /* }}} */ /* {{{ proto array http_parse_headers(string header) - * - * Parses HTTP headers into an associative array. - * - * Expects a string parameter containing HTTP headers. - * - * Returns an array on success, or FALSE on failure. - * - * Example: - *
- *  text/html; chatset=UTF-8
- *     [Server] => Funky/1.0
- *     [Set-Cookie] => Array
- *         (
- *             [0] => foo=bar
- *             [1] => baz=quux
- *         )
- *     [Folded] => works
- *         too 
- * ) 
- * ?>
- * 
- */ + Parses HTTP headers into an associative array. */ PHP_FUNCTION(http_parse_headers) { char *header; @@ -1021,39 +657,7 @@ PHP_FUNCTION(http_parse_headers) /* }}}*/ /* {{{ proto object http_parse_cookie(string cookie[, int flags[, array allowed_extras]]) - * - * Parses HTTP cookies like sent in a response into a struct. - * - * Expects a string as parameter containing the value of a Set-Cookie response header. - * - * Returns an stdClass olike shown in the example on success or FALSE on failure. - * - * Example: - *
- *  Array
- *         (
- *             [foo] => bar
- *             [bar] => baz
- *         )
- * 
- *     [extras] => Array
- *         (
- *             [comment] =>
- *         )
- * 
- *     [flags] => 16
- *     [expires] => 0
- *     [path] => /
- *     [domain] => example.com
- * )
- * ?>
- * 
- */ + Parses HTTP cookies like sent in a response into a struct. */ PHP_FUNCTION(http_parse_cookie) { char *cookie, **allowed_extras = NULL; @@ -1095,9 +699,7 @@ PHP_FUNCTION(http_parse_cookie) /* }}} */ /* {{{ proto string http_build_cookie(array cookie) - * - * Build a cookie string from an array/object like returned by http_parse_cookie(). - */ + Build a cookie string from an array/object like returned by http_parse_cookie(). */ PHP_FUNCTION(http_build_cookie) { char *str = NULL; @@ -1118,9 +720,7 @@ PHP_FUNCTION(http_build_cookie) /* }}} */ /* {{{ proto object http_parse_params(string param[, int flags = HTTP_PARAMS_DEFAULT]) - * - * Parse parameter list. - */ + Parse parameter list. */ PHP_FUNCTION(http_parse_params) { char *param; @@ -1145,11 +745,7 @@ PHP_FUNCTION(http_parse_params) /* }}} */ /* {{{ proto array http_get_request_headers(void) - * - * Get a list of incoming HTTP headers. - * - * Returns an associative array of incoming request headers. - */ + Get a list of incoming HTTP headers. */ PHP_FUNCTION(http_get_request_headers) { NO_ARGS; @@ -1160,14 +756,7 @@ PHP_FUNCTION(http_get_request_headers) /* }}} */ /* {{{ proto string http_get_request_body(void) - * - * Get the raw request body (e.g. POST or PUT data). - * - * This function can not be used after http_get_request_body_stream() - * if the request method was another than POST. - * - * Returns the raw request body as string on success or NULL on failure. - */ + Get the raw request body (e.g. POST or PUT data). */ PHP_FUNCTION(http_get_request_body) { char *body; @@ -1184,13 +773,7 @@ PHP_FUNCTION(http_get_request_body) /* }}} */ /* {{{ proto resource http_get_request_body_stream(void) - * - * Create a stream to read the raw request body (e.g. POST or PUT data). - * - * This function can only be used once if the request method was another than POST. - * - * Returns the raw request body as stream on success or NULL on failure. - */ + Create a stream to read the raw request body (e.g. POST or PUT data). This function can only be used once if the request method was another than POST. */ PHP_FUNCTION(http_get_request_body_stream) { php_stream *s; @@ -1207,15 +790,7 @@ PHP_FUNCTION(http_get_request_body_stream) /* }}} */ /* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false]) - * - * Match an incoming HTTP header. - * - * Expects two string parameters representing the header name (case-insensitive) - * and the header value that should be compared. The case sensitivity of the - * header value depends on the additional optional bool parameter accepted. - * - * Returns TRUE if header value matches, else FALSE. - */ + Match an incoming HTTP header. */ PHP_FUNCTION(http_match_request_header) { char *header, *value; @@ -1251,115 +826,7 @@ PHP_FUNCTION(http_match_request_header) } /* {{{ proto string http_get(string url[, array options[, array &info]]) - * - * Performs an HTTP GET request on the supplied url. - * - * The second parameter, if set, is expected to be an associative - * array where the following keys will be recognized: - *
- *  - redirect:         int, whether and how many redirects to follow
- *  - unrestrictedauth: bool, whether to continue sending credentials on
- *                      redirects to a different host
- *  - proxyhost:        string, proxy host in "host[:port]" format
- *  - proxyport:        int, use another proxy port as specified in proxyhost
- *  - proxytype:        int, HTTP_PROXY_HTTP, SOCKS4 or SOCKS5
- *  - proxyauth:        string, proxy credentials in "user:pass" format
- *  - proxyauthtype:    int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
- *  - httpauth:         string, http credentials in "user:pass" format
- *  - httpauthtype:     int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
- *  - compress:         bool, whether to allow gzip/deflate content encoding
- *  - port:             int, use another port as specified in the url
- *  - 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
- *                      like array("header" => "value")
- *  - cookies:          array, list of cookies as associative array
- *                      like array("cookie" => "value")
- *  - encodecookies:    bool, whether to urlencode the cookies (default: true)
- *  - cookiestore:      string, path to a file where cookies are/will be stored
- *  - cookiesession:    bool, don't load session cookies from cookiestore if TRUE
- *  - resume:           int, byte offset to start the download from;
- *                      if the server supports ranges
- *  - range:            array, array of arrays, each containing two integers,
- *                      specifying the ranges to download if server support is
- *                      given; only recognized if the resume option is empty
- *  - maxfilesize:      int, maximum file size that should be downloaded;
- *                      has no effect, if the size of the requested entity is not known
- *  - lastmodified:     int, timestamp for If-(Un)Modified-Since header
- *  - etag:             string, quoted etag for If-(None-)Match header
- *  - timeout:          int, seconds the request may take
- *  - connecttimeout:   int, seconds the connect may take
- *  - onprogress:       mixed, progress callback
- *  - interface:        string, outgoing network interface (ifname, ip or hostname)
- *  - portrange:        array, 2 integers specifying outgoing portrange to try
- *  - ssl:              array, with the following options:
- *                      cert:        string, path to certificate
- *                      certtype:    string, type of certificate
- *                      certpasswd:  string, password for certificate
- *                      key:         string, path to key
- *                      keytype:     string, type of key
- *                      keypasswd:   string, pasword for key
- *                      engine:      string, ssl engine to use
- *                      version:     int, ssl version to use
- *                      verifypeer:  bool, whether to verify the peer
- *                      verifyhost:  bool whether to verify the host
- *                      cipher_list: string, list of allowed ciphers
- *                      cainfo:      string
- *                      capath:      string
- *                      random_file: string
- *                      egdsocket:   string
- * 
- * - * The optional third parameter will be filled with some additional information - * in form of an associative array, if supplied, like the following example: - *
- *  'http://www.example.com/',
- *    'response_code' => 302,
- *    'connect_code' => 0,
- *    'filetime' => -1,
- *    'total_time' => 0.212348,
- *    'namelookup_time' => 0.038296,
- *    'connect_time' => 0.104144,
- *    'pretransfer_time' => 0.104307,
- *    'starttransfer_time' => 0.212077,
- *    'redirect_time' => 0,
- *    'redirect_count' => 0,
- *    'size_upload' => 0,
- *    'size_download' => 218,
- *    'speed_download' => 1026,
- *    'speed_upload' => 0,
- *    'header_size' => 307,
- *    'request_size' => 103,
- *    'ssl_verifyresult' => 0,
- *    'ssl_engines' =>
- *    array (
- *      0 => 'dynamic',
- *      1 => 'cswift',
- *      2 => 'chil',
- *      3 => 'atalla',
- *      4 => 'nuron',
- *      5 => 'ubsec',
- *      6 => 'aep',
- *      7 => 'sureware',
- *      8 => '4758cca',
- *    ),
- *    'content_length_download' => 218,
- *    'content_length_upload' => 0,
- *    'content_type' => 'text/html',
- *    'httpauth_avail' => 0,
- *    'proxyauth_avail' => 0,
- *    'num_connects' => 1,
- *    'os_errno' => 0,
- *    'error' => '',
- *  )
- * ?>
- * 
- * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs an HTTP GET request on the supplied url. */ PHP_FUNCTION(http_get) { zval *options = NULL, *info = NULL; @@ -1391,13 +858,7 @@ PHP_FUNCTION(http_get) /* }}} */ /* {{{ proto string http_head(string url[, array options[, array &info]]) - * - * Performs an HTTP HEAD request on the supplied url. - * - * See http_get() for a full list of available parameters and options. - * - * Returns the HTTP response as string on success, or FALSE on failure. - */ + Performs an HTTP HEAD request on the supplied url. */ PHP_FUNCTION(http_head) { zval *options = NULL, *info = NULL; @@ -1429,14 +890,7 @@ PHP_FUNCTION(http_head) /* }}} */ /* {{{ proto string http_post_data(string url, string data[, array options[, array &info]]) - * - * Performs an HTTP POST request on the supplied url. - * - * Expects a string as second parameter containing the pre-encoded post data. - * See http_get() for a full list of available parameters and options. - * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs an HTTP POST request on the supplied url. */ PHP_FUNCTION(http_post_data) { zval *options = NULL, *info = NULL; @@ -1470,14 +924,7 @@ PHP_FUNCTION(http_post_data) /* }}} */ /* {{{ proto string http_post_fields(string url, array data[, array files[, array options[, array &info]]]) - * - * Performs an HTTP POST request on the supplied url. - * - * Expects an associative array as second parameter, which will be - * www-form-urlencoded. See http_get() for a full list of available options. - * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs an HTTP POST request on the supplied url. */ PHP_FUNCTION(http_post_fields) { zval *options = NULL, *info = NULL, *fields = NULL, *files = NULL; @@ -1515,14 +962,7 @@ PHP_FUNCTION(http_post_fields) /* }}} */ /* {{{ proto string http_put_file(string url, string file[, array options[, array &info]]) - * - * Performs an HTTP PUT request on the supplied url. - * - * Expects the second parameter to be a string referencing the file to upload. - * See http_get() for a full list of available options. - * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs an HTTP PUT request on the supplied url. */ PHP_FUNCTION(http_put_file) { char *URL, *file; @@ -1566,15 +1006,7 @@ PHP_FUNCTION(http_put_file) /* }}} */ /* {{{ proto string http_put_stream(string url, resource stream[, array options[, array &info]]) - * - * Performs an HTTP PUT request on the supplied url. - * - * Expects the second parameter to be a resource referencing an already - * opened stream, from which the data to upload should be read. - * See http_get() for a full list of available options. - * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs an HTTP PUT request on the supplied url. */ PHP_FUNCTION(http_put_stream) { zval *resource, *options = NULL, *info = NULL; @@ -1615,14 +1047,7 @@ PHP_FUNCTION(http_put_stream) /* }}} */ /* {{{ proto string http_put_data(string url, string data[, array options[, array &info]]) - * - * Performs an HTTP PUT request on the supplied url. - * - * Expects the second parameter to be a string containing the data to upload. - * See http_get() for a full list of available options. - * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs an HTTP PUT request on the supplied url. */ PHP_FUNCTION(http_put_data) { char *URL, *data; @@ -1656,15 +1081,7 @@ PHP_FUNCTION(http_put_data) /* }}} */ /* {{{ proto string http_request(int method, string url[, string body[, array options[, array &info]]]) - * - * Performs a custom HTTP request on the supplied url. - * - * Expects the first parameter to be an integer specifying the request method to use. - * Accepts an optional third string parameter containing the raw request body. - * See http_get() for a full list of available options. - * - * Returns the HTTP response(s) as string on success, or FALSE on failure. - */ + Performs a custom HTTP request on the supplied url. */ PHP_FUNCTION(http_request) { long meth; @@ -1699,11 +1116,7 @@ PHP_FUNCTION(http_request) /* }}} */ /* {{{ proto string http_request_body_encode(array fields, array files) - * - * Generate x-www-form-urlencoded resp. form-data encoded request body. - * - * Returns encoded string on success, or FALSE on failure. - */ + Generate x-www-form-urlencoded resp. form-data encoded request body. */ PHP_FUNCTION(http_request_body_encode) { zval *fields = NULL, *files = NULL; @@ -1730,13 +1143,7 @@ PHP_FUNCTION(http_request_body_encode) /* }}} HAVE_CURL */ /* {{{ proto int http_request_method_register(string method) - * - * Register a custom request method. - * - * Expects a string parameter containing the request method name to register. - * - * Returns the ID of the request method on success, or FALSE on failure. - */ + Register a custom request method. */ PHP_FUNCTION(http_request_method_register) { char *method; @@ -1755,13 +1162,7 @@ PHP_FUNCTION(http_request_method_register) /* }}} */ /* {{{ proto bool http_request_method_unregister(mixed method) - * - * Unregister a previously registered custom request method. - * - * Expects either the request method name or ID. - * - * Returns TRUE on success, or FALSE on failure. - */ + Unregister a previously registered custom request method. */ PHP_FUNCTION(http_request_method_unregister) { zval *method; @@ -1793,13 +1194,7 @@ PHP_FUNCTION(http_request_method_unregister) /* }}} */ /* {{{ proto int http_request_method_exists(mixed method) - * - * Check if a request method is registered (or available by default). - * - * Expects either the request method name or ID as parameter. - * - * Returns TRUE if the request method is known, else FALSE. - */ + Check if a request method is registered (or available by default). */ PHP_FUNCTION(http_request_method_exists) { if (return_value_used) { @@ -1828,13 +1223,7 @@ PHP_FUNCTION(http_request_method_exists) /* }}} */ /* {{{ proto string http_request_method_name(int method) - * - * Get the literal string representation of a standard or registered request method. - * - * Expects the request method ID as parameter. - * - * Returns the request method name as string on success, or FALSE on failure. - */ + Get the literal string representation of a standard or registered request method. */ PHP_FUNCTION(http_request_method_name) { if (return_value_used) { @@ -1853,14 +1242,7 @@ PHP_FUNCTION(http_request_method_name) #ifdef HTTP_HAVE_ZLIB /* {{{ proto string http_deflate(string data[, int flags = 0]) - * - * Compress data with gzip, zlib AKA deflate or raw deflate encoding. - * - * Expects the first parameter to be a string containing the data that should - * be encoded. - * - * Returns the encoded string on success, or NULL on failure. - */ + Compress data with gzip, zlib AKA deflate or raw deflate encoding. */ PHP_FUNCTION(http_deflate) { char *data; @@ -1881,14 +1263,7 @@ PHP_FUNCTION(http_deflate) /* }}} */ /* {{{ proto string http_inflate(string data) - * - * Decompress data compressed with either gzip, deflate AKA zlib or raw - * deflate encoding. - * - * Expects a string as parameter containing the compressed data. - * - * Returns the decoded string on success, or NULL on failure. - */ + Decompress data compressed with either gzip, deflate AKA zlib or raw deflate encoding. */ PHP_FUNCTION(http_inflate) { char *data; @@ -1908,12 +1283,7 @@ PHP_FUNCTION(http_inflate) /* }}} */ /* {{{ proto string ob_deflatehandler(string data, int mode) - * - * For use with ob_start(). The deflate output buffer handler can only be used once. - * It conflicts with ob_gzhandler and zlib.output_compression as well and should - * not be used after ext/mbstrings mb_output_handler and ext/sessions URL-Rewriter (AKA - * session.use_trans_sid). - */ + For use with ob_start(). The deflate output buffer handler can only be used once. */ PHP_FUNCTION(ob_deflatehandler) { char *data; @@ -1930,9 +1300,7 @@ PHP_FUNCTION(ob_deflatehandler) /* }}} */ /* {{{ proto string ob_inflatehandler(string data, int mode) - * - * For use with ob_start(). Same restrictions as with ob_deflatehandler apply. - */ + For use with ob_start(). Same restrictions as with ob_deflatehandler apply. */ PHP_FUNCTION(ob_inflatehandler) { char *data; @@ -1952,29 +1320,7 @@ PHP_FUNCTION(ob_inflatehandler) /* }}} */ /* {{{ proto int http_support([int feature = 0]) - * - * Check for feature that require external libraries. - * - * Accepts an optional in parameter specifying which feature to probe for. - * If the parameter is 0 or omitted, the return value contains a bitmask of - * all supported features that depend on external libraries. - * - * Available features to probe for are: - * - * - * Returns int, whether requested feature is supported, or a bitmask with - * all supported features. - */ + Check for feature that require external libraries. */ PHP_FUNCTION(http_support) { long feature = 0; @@ -1987,10 +1333,6 @@ PHP_FUNCTION(http_support) } /* }}} */ -PHP_FUNCTION(http_test) -{ -} - /* * Local variables: * tab-width: 4 diff --git a/http_headers_api.c b/http_headers_api.c index ef5099f..95fbdec 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -107,7 +107,9 @@ PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *support #if HTTP_DBG_NEG fprintf(stderr, "Reading header %s: ", header); #endif - HTTP_GSC(accept, header, NULL); + if (!(accept = http_get_server_var(header, 1))) { + return NULL; + } #if HTTP_DBG_NEG fprintf(stderr, "%s\n", Z_STRVAL_P(accept)); #endif @@ -189,15 +191,12 @@ PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_ char *range, c; long begin = -1, end = -1, *ptr; - HTTP_GSC(zrange, "HTTP_RANGE", RANGE_NO); - range = Z_STRVAL_P(zrange); - - if (strncmp(range, "bytes=", sizeof("bytes=") - 1)) { + if ( !(zrange = http_get_server_var("HTTP_RANGE", 1)) || + Z_STRLEN_P(zrange) < lenof("bytes=") || strncmp(Z_STRVAL_P(zrange), "bytes=", lenof("bytes="))) { return RANGE_NO; } - + range = Z_STRVAL_P(zrange) + lenof("bytes="); ptr = &begin; - range += sizeof("bytes=") - 1; do { switch (c = *(range++)) { diff --git a/http_inflatestream_object.c b/http_inflatestream_object.c index 131d718..9b16dfc 100644 --- a/http_inflatestream_object.c +++ b/http_inflatestream_object.c @@ -30,6 +30,11 @@ HTTP_BEGIN_ARGS(__construct, 0) HTTP_ARG_VAL(flags, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(factory, 0) + HTTP_ARG_VAL(flags, 0) + HTTP_ARG_VAL(class_name, 0) +HTTP_END_ARGS; + HTTP_BEGIN_ARGS(update, 1) HTTP_ARG_VAL(data, 0) HTTP_END_ARGS; @@ -50,6 +55,8 @@ zend_function_entry http_inflatestream_object_fe[] = { HTTP_INFLATE_ME(flush, ZEND_ACC_PUBLIC) HTTP_INFLATE_ME(finish, ZEND_ACC_PUBLIC) + HTTP_INFLATE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + EMPTY_FUNCTION_ENTRY }; static zend_object_handlers http_inflatestream_object_handlers; @@ -128,11 +135,7 @@ void _http_inflatestream_object_free(zend_object *object TSRMLS_DC) } /* {{{ proto void HttpInflateStream::__construct([int flags = 0]) - * - * Creates a new HttpInflateStream object instance. - * - * Accepts an optional int parameter specifying how to initialize the inflate stream. - */ + Creates a new HttpInflateStream object instance. */ PHP_METHOD(HttpInflateStream, __construct) { long flags = 0; @@ -151,14 +154,29 @@ PHP_METHOD(HttpInflateStream, __construct) } /* }}} */ +/* {{{ proto HttpInflateStream HttpInflateStream::factory([int flags[, string class = "HttpInflateStream"]]) + Creates a new HttpInflateStream object instance. */ +PHP_METHOD(HttpInflateStream, factory) +{ + long flags = 0; + char *cn = NULL; + int cl = 0; + + SET_EH_THROW_HTTP(); + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &flags, &cn, &cl)) { + zend_object_value ov; + http_encoding_stream *s = http_encoding_inflate_stream_init(NULL, flags & 0x0fffffff); + + if (SUCCESS == http_object_new(&ov, cn, cl, _http_inflatestream_object_new_ex, http_inflatestream_object_ce, s, NULL)) { + RETVAL_OBJVAL(ov, 0); + } + } + SET_EH_NORMAL(); +} +/* }}} */ + /* {{{ proto string HttpInflateStream::update(string data) - * - * Passes more data through the inflate stream. - * - * Expects a string parameter containing (a part of) the data to inflate. - * - * Returns inflated data on success or FALSE on failure. - */ + Passes more data through the inflate stream. */ PHP_METHOD(HttpInflateStream, update) { int data_len; @@ -187,11 +205,7 @@ PHP_METHOD(HttpInflateStream, update) /* }}} */ /* {{{ proto string HttpInflateStream::flush([string data]) - * - * Flush the inflate stream. - * - * Returns some inflated data as string on success or FALSE on failure. - */ + Flush the inflate stream. */ PHP_METHOD(HttpInflateStream, flush) { int data_len = 0; @@ -219,11 +233,7 @@ PHP_METHOD(HttpInflateStream, flush) /* }}} */ /* {{{ proto string HttpInflateStream::finish([string data]) - * - * Finalizes the inflate stream. The inflate stream can be reused after finalizing. - * - * Returns the final part of inflated data. - */ + Finalizes the inflate stream. The inflate stream can be reused after finalizing. */ PHP_METHOD(HttpInflateStream, finish) { int data_len = 0; @@ -267,7 +277,6 @@ PHP_METHOD(HttpInflateStream, finish) } /* }}} */ - #endif /* ZEND_ENGINE_2 && HTTP_HAVE_ZLIB*/ /* diff --git a/http_message_object.c b/http_message_object.c index 495cd28..3adbb27 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -46,8 +46,9 @@ HTTP_BEGIN_ARGS(__construct, 0) HTTP_ARG_VAL(message, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(fromString, 1) +HTTP_BEGIN_ARGS(factory, 0) HTTP_ARG_VAL(message, 0) + HTTP_ARG_VAL(class_name, 0) HTTP_END_ARGS; HTTP_EMPTY_ARGS(getBody); @@ -182,7 +183,8 @@ zend_function_entry http_message_object_fe[] = { ZEND_MALIAS(HttpMessage, __toString, toString, HTTP_ARGS(HttpMessage, toString), ZEND_ACC_PUBLIC) - HTTP_MESSAGE_ME(fromString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + HTTP_MESSAGE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_MALIAS(HttpMessage, fromString, factory, HTTP_ARGS(HttpMessage, factory), ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) HTTP_MESSAGE_ME(detach, ZEND_ACC_PUBLIC) HTTP_MESSAGE_ME(prepend, ZEND_ACC_PUBLIC) @@ -677,16 +679,7 @@ static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) /* ### USERLAND ### */ /* {{{ proto void HttpMessage::__construct([string message]) - * - * Instantiate a new HttpMessage object. - * - * Accepts an optional string parameter containing a single or several - * consecutive HTTP messages. The constructed object will actually - * represent the *last* message of the passed string. If there were - * prior messages, those can be accessed by HttpMessage::getParentMessage(). - * - * Throws HttpMalformedHeaderException. - */ + Create a new HttpMessage object instance. */ PHP_METHOD(HttpMessage, __construct) { int length = 0; @@ -714,40 +707,28 @@ PHP_METHOD(HttpMessage, __construct) } /* }}} */ -/* {{{ proto static HttpMessage HttpMessage::fromString(string raw_message[, string class_name = "HttpMessage"]) - * - * Create an HttpMessage object from a string. Kind of a static constructor. - * - * Expects a string parameter containing a single or several consecutive - * HTTP messages. Accepts an optional string parameter specifying the class to use. - * - * Returns an HttpMessage object on success or NULL on failure. - * - * Throws HttpMalformedHeadersException. - */ -PHP_METHOD(HttpMessage, fromString) +/* {{{ proto static HttpMessage HttpMessage::factory([string raw_message[, string class_name = "HttpMessage"]]) + Create a new HttpMessage object instance. */ +PHP_METHOD(HttpMessage, factory) { - char *string = NULL, *class_name = NULL; - int length = 0, class_length = 0; + char *string = NULL, *cn = NULL; + int length = 0, cl = 0; http_message *msg = NULL; + zend_object_value ov; + http_message_object *obj = NULL; RETVAL_NULL(); SET_EH_THROW_HTTP(); - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &string, &length, &class_name, &class_length)) { - if ((msg = http_message_parse(string, length))) { - zend_class_entry *ce = http_message_object_ce; - - if (class_name && *class_name) { - ce = zend_fetch_class(class_name, class_length, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC); - if (ce && !instanceof_function(ce, http_message_object_ce TSRMLS_CC)) { - http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Class %s does not extend HttpMessage", class_name); - ce = NULL; - } - } - if (ce) { - RETVAL_OBJVAL(http_message_object_new_ex(ce, msg, NULL), 0); - } + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &string, &length, &cn, &cl)) { + if (length) { + msg = http_message_parse(string, length); + } + if ((msg || !length) && SUCCESS == http_object_new(&ov, cn, cl, _http_message_object_new_ex, http_message_object_ce, msg, &obj)) { + RETVAL_OBJVAL(ov, 0); + } + if (obj && !obj->message) { + obj->message = http_message_new(); } } SET_EH_NORMAL(); @@ -755,11 +736,7 @@ PHP_METHOD(HttpMessage, fromString) /* }}} */ /* {{{ proto string HttpMessage::getBody() - * - * Get the body of the parsed HttpMessage. - * - * Returns the message body as string. - */ + Get the body of the parsed HttpMessage. */ PHP_METHOD(HttpMessage, getBody) { NO_ARGS; @@ -772,12 +749,7 @@ PHP_METHOD(HttpMessage, getBody) /* }}} */ /* {{{ proto void HttpMessage::setBody(string body) - * - * Set the body of the HttpMessage. - * NOTE: Don't forget to update any headers accordingly. - * - * Expects a string parameter containing the new body of the message. - */ + Set the body of the HttpMessage. NOTE: Don't forget to update any headers accordingly. */ PHP_METHOD(HttpMessage, setBody) { char *body; @@ -792,11 +764,7 @@ PHP_METHOD(HttpMessage, setBody) /* }}} */ /* {{{ proto string HttpMessage::getHeader(string header) - * - * Get message header. - * - * Returns the header value on success or NULL if the header does not exist. - */ + Get message header. */ PHP_METHOD(HttpMessage, getHeader) { zval *header; @@ -817,11 +785,7 @@ PHP_METHOD(HttpMessage, getHeader) /* }}} */ /* {{{ proto array HttpMessage::getHeaders() - * - * Get Message Headers. - * - * Returns an associative array containing the messages HTTP headers. - */ + Get Message Headers. */ PHP_METHOD(HttpMessage, getHeaders) { NO_ARGS; @@ -836,12 +800,7 @@ PHP_METHOD(HttpMessage, getHeaders) /* }}} */ /* {{{ proto void HttpMessage::setHeaders(array headers) - * - * Sets new headers. - * - * Expects an associative array as parameter containing the new HTTP headers, - * which will replace *all* previous HTTP headers of the message. - */ + Sets new headers. */ PHP_METHOD(HttpMessage, setHeaders) { zval *new_headers = NULL; @@ -859,15 +818,7 @@ PHP_METHOD(HttpMessage, setHeaders) /* }}} */ /* {{{ proto void HttpMessage::addHeaders(array headers[, bool append = false]) - * - * Add headers. If append is true, headers with the same name will be separated, else overwritten. - * - * Expects an associative array as parameter containing the additional HTTP headers - * to add to the messages existing headers. If the optional bool parameter is true, - * and a header with the same name of one to add exists already, this respective - * header will be converted to an array containing both header values, otherwise - * it will be overwritten with the new header value. - */ + Add headers. If append is true, headers with the same name will be separated, else overwritten. */ PHP_METHOD(HttpMessage, addHeaders) { zval *new_headers; @@ -883,11 +834,7 @@ PHP_METHOD(HttpMessage, addHeaders) /* }}} */ /* {{{ proto int HttpMessage::getType() - * - * Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) - * - * Returns the HttpMessage::TYPE. - */ + Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) */ PHP_METHOD(HttpMessage, getType) { NO_ARGS; @@ -900,11 +847,7 @@ PHP_METHOD(HttpMessage, getType) /* }}} */ /* {{{ proto void HttpMessage::setType(int type) - * - * Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) - * - * Expects an int parameter, the HttpMessage::TYPE. - */ + Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) */ PHP_METHOD(HttpMessage, setType) { long type; @@ -918,12 +861,7 @@ PHP_METHOD(HttpMessage, setType) /* }}} */ /* {{{ proto int HttpMessage::getResponseCode() - * - * Get the Response Code of the Message. - * - * Returns the HTTP response code if the message is of type - * HttpMessage::TYPE_RESPONSE, else FALSE. - */ + Get the Response Code of the Message. */ PHP_METHOD(HttpMessage, getResponseCode) { NO_ARGS; @@ -937,14 +875,7 @@ PHP_METHOD(HttpMessage, getResponseCode) /* }}} */ /* {{{ proto bool HttpMessage::setResponseCode(int code) - * - * Set the response code of an HTTP Response Message. - * - * Expects an int parameter with the HTTP response code. - * - * Returns TRUE on success, or FALSE if the message is not of type - * HttpMessage::TYPE_RESPONSE or the response code is out of range (100-510). - */ + Set the response code of an HTTP Response Message. */ PHP_METHOD(HttpMessage, setResponseCode) { long code; @@ -966,12 +897,7 @@ PHP_METHOD(HttpMessage, setResponseCode) /* }}} */ /* {{{ proto string HttpMessage::getResponseStatus() - * - * Get the Response Status of the message (i.e. the string following the response code). - * - * Returns the HTTP response status string if the message is of type - * HttpMessage::TYPE_RESPONSE, else FALSE. - */ + Get the Response Status of the message (i.e. the string following the response code). */ PHP_METHOD(HttpMessage, getResponseStatus) { NO_ARGS; @@ -985,14 +911,7 @@ PHP_METHOD(HttpMessage, getResponseStatus) /* }}} */ /* {{{ proto bool HttpMessage::setResponseStatus(string status) - * - * Set the Response Status of the HTTP message (i.e. the string following the response code). - * - * Expects a string parameter containing the response status text. - * - * Returns TRUE on success or FALSE if the message is not of type - * HttpMessage::TYPE_RESPONSE. - */ + Set the Response Status of the HTTP message (i.e. the string following the response code). */ PHP_METHOD(HttpMessage, setResponseStatus) { char *status; @@ -1010,12 +929,7 @@ PHP_METHOD(HttpMessage, setResponseStatus) /* }}} */ /* {{{ proto string HttpMessage::getRequestMethod() - * - * Get the Request Method of the Message. - * - * Returns the request method name on success, or FALSE if the message is - * not of type HttpMessage::TYPE_REQUEST. - */ + Get the Request Method of the Message. */ PHP_METHOD(HttpMessage, getRequestMethod) { NO_ARGS; @@ -1029,14 +943,7 @@ PHP_METHOD(HttpMessage, getRequestMethod) /* }}} */ /* {{{ proto bool HttpMessage::setRequestMethod(string method) - * - * Set the Request Method of the HTTP Message. - * - * Expects a string parameter containing the request method name. - * - * Returns TRUE on success, or FALSE if the message is not of type - * HttpMessage::TYPE_REQUEST or an invalid request method was supplied. - */ + Set the Request Method of the HTTP Message. */ PHP_METHOD(HttpMessage, setRequestMethod) { char *method; @@ -1063,12 +970,7 @@ PHP_METHOD(HttpMessage, setRequestMethod) /* }}} */ /* {{{ proto string HttpMessage::getRequestUrl() - * - * Get the Request URL of the Message. - * - * Returns the request url as string on success, or FALSE if the message - * is not of type HttpMessage::TYPE_REQUEST. - */ + Get the Request URL of the Message. */ PHP_METHOD(HttpMessage, getRequestUrl) { NO_ARGS; @@ -1082,14 +984,7 @@ PHP_METHOD(HttpMessage, getRequestUrl) /* }}} */ /* {{{ proto bool HttpMessage::setRequestUrl(string url) - * - * Set the Request URL of the HTTP Message. - * - * Expects a string parameters containing the request url. - * - * Returns TRUE on success, or FALSE if the message is not of type - * HttpMessage::TYPE_REQUEST or supplied URL was empty. - */ + Set the Request URL of the HTTP Message. */ PHP_METHOD(HttpMessage, setRequestUrl) { char *URI; @@ -1111,11 +1006,7 @@ PHP_METHOD(HttpMessage, setRequestUrl) /* }}} */ /* {{{ proto string HttpMessage::getHttpVersion() - * - * Get the HTTP Protocol Version of the Message. - * - * Returns the HTTP protocol version as string. - */ + Get the HTTP Protocol Version of the Message. */ PHP_METHOD(HttpMessage, getHttpVersion) { NO_ARGS; @@ -1131,13 +1022,7 @@ PHP_METHOD(HttpMessage, getHttpVersion) /* }}} */ /* {{{ proto bool HttpMessage::setHttpVersion(string version) - * - * Set the HTTP Protocol version of the Message. - * - * Expects a string parameter containing the HTTP protocol version. - * - * Returns TRUE on success, or FALSE if supplied version is out of range (1.0/1.1). - */ + Set the HTTP Protocol version of the Message. */ PHP_METHOD(HttpMessage, setHttpVersion) { char v[4]; @@ -1161,17 +1046,7 @@ PHP_METHOD(HttpMessage, setHttpVersion) /* }}} */ /* {{{ proto string HttpMessage::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME]) - * - * Attempts to guess the content type of supplied payload through libmagic. - * - * Expects a string parameter specifying the magic.mime database to use. - * Additionally accepts an optional int parameter, being flags for libmagic. - * - * Returns the guessed content type on success, or FALSE on failure. - * - * Throws HttpRuntimeException, HttpInvalidParamException - * if http.only_exceptions is TRUE. - */ + Attempts to guess the content type of supplied payload through libmagic. */ PHP_METHOD(HttpMessage, guessContentType) { #ifdef HTTP_HAVE_MAGIC @@ -1196,13 +1071,7 @@ PHP_METHOD(HttpMessage, guessContentType) /* }}} */ /* {{{ proto HttpMessage HttpMessage::getParentMessage() - * - * Get parent Message. - * - * Returns the parent HttpMessage on success, or NULL if there's none. - * - * Throws HttpRuntimeException. - */ + Get parent Message. */ PHP_METHOD(HttpMessage, getParentMessage) { SET_EH_THROW_HTTP(); @@ -1220,12 +1089,7 @@ PHP_METHOD(HttpMessage, getParentMessage) /* }}} */ /* {{{ proto bool HttpMessage::send() - * - * Send the Message according to its type as Response or Request. - * This provides limited functionality compared to HttpRequest and HttpResponse. - * - * Returns TRUE on success, or FALSE on failure. - */ + Send the Message according to its type as Response or Request. */ PHP_METHOD(HttpMessage, send) { getObject(http_message_object, obj); @@ -1237,14 +1101,7 @@ PHP_METHOD(HttpMessage, send) /* }}} */ /* {{{ proto string HttpMessage::toString([bool include_parent = false]) - * - * Get the string representation of the Message. - * - * Accepts a bool parameter which specifies whether the returned string - * should also contain any parent messages. - * - * Returns the full message as string. - */ + Get the string representation of the Message. */ PHP_METHOD(HttpMessage, toString) { if (return_value_used) { @@ -1268,13 +1125,7 @@ PHP_METHOD(HttpMessage, toString) /* }}} */ /* {{{ proto HttpRequest|HttpResponse HttpMessage::toMessageTypeObject(void) - * - * Creates an object regarding to the type of the message. - * - * Returns either an HttpRequest or HttpResponse object on success, or NULL on failure. - * - * Throws HttpRuntimeException, HttpMessageTypeException, HttpHeaderException. - */ + Creates an object regarding to the type of the message. Returns either an HttpRequest or HttpResponse object on success, or NULL on failure. */ PHP_METHOD(HttpMessage, toMessageTypeObject) { SET_EH_THROW_HTTP(); @@ -1390,11 +1241,7 @@ PHP_METHOD(HttpMessage, toMessageTypeObject) /* }}} */ /* {{{ proto int HttpMessage::count() - * - * Implements Countable. - * - * Returns the number of parent messages + 1. - */ + Implements Countable::count(). Returns the number of parent messages + 1. */ PHP_METHOD(HttpMessage, count) { NO_ARGS { @@ -1408,11 +1255,7 @@ PHP_METHOD(HttpMessage, count) /* }}} */ /* {{{ proto string HttpMessage::serialize() - * - * Implements Serializable. - * - * Returns the serialized representation of the HttpMessage. - */ + Implements Serializable::serialize(). Returns the serialized representation of the HttpMessage. */ PHP_METHOD(HttpMessage, serialize) { NO_ARGS { @@ -1427,11 +1270,7 @@ PHP_METHOD(HttpMessage, serialize) /* }}} */ /* {{{ proto void HttpMessage::unserialize(string serialized) - * - * Implements Serializable. - * - * Re-constructs the HttpMessage based upon the serialized string. - */ + Implements Serializable::unserialize(). Re-constructs the HttpMessage based upon the serialized string. */ PHP_METHOD(HttpMessage, unserialize) { int length; @@ -1449,9 +1288,7 @@ PHP_METHOD(HttpMessage, unserialize) /* }}} */ /* {{{ proto HttpMessage HttpMessage::detach(void) - * - * Returns a clone of an HttpMessage object detached from any parent messages. - */ + Returns a clone of an HttpMessage object detached from any parent messages. */ PHP_METHOD(HttpMessage, detach) { http_info info; @@ -1474,13 +1311,7 @@ PHP_METHOD(HttpMessage, detach) /* }}} */ /* {{{ proto void HttpMessage::prepend(HttpMessage message[, bool top = true]) - * - * Prepends message(s) to the HTTP message. - * - * Expects an HttpMessage object as parameter. - * - * Throws HttpInvalidParamException if the message is located within the same message chain. - */ + Prepends message(s) to the HTTP message. Throws HttpInvalidParamException if the message is located within the same message chain. */ PHP_METHOD(HttpMessage, prepend) { zval *prepend; @@ -1507,11 +1338,7 @@ PHP_METHOD(HttpMessage, prepend) /* }}} */ /* {{{ proto HttpMessage HttpMessage::reverse() - * - * Reorders the message chain in reverse order. - * - * Returns the most parent HttpMessage object. - */ + Reorders the message chain in reverse order. Returns the most parent HttpMessage object. */ PHP_METHOD(HttpMessage, reverse) { NO_ARGS { @@ -1521,9 +1348,7 @@ PHP_METHOD(HttpMessage, reverse) /* }}} */ /* {{{ proto void HttpMessage::rewind(void) - * - * Implements Iterator. - */ + Implements Iterator::rewind(). */ PHP_METHOD(HttpMessage, rewind) { NO_ARGS { @@ -1539,9 +1364,7 @@ PHP_METHOD(HttpMessage, rewind) /* }}} */ /* {{{ proto bool HttpMessage::valid(void) - * - * Implements Iterator. - */ + Implements Iterator::valid(). */ PHP_METHOD(HttpMessage, valid) { NO_ARGS { @@ -1553,9 +1376,7 @@ PHP_METHOD(HttpMessage, valid) /* }}} */ /* {{{ proto void HttpMessage::next(void) - * - * Implements Iterator. - */ + Implements Iterator::next(). */ PHP_METHOD(HttpMessage, next) { NO_ARGS { @@ -1576,9 +1397,7 @@ PHP_METHOD(HttpMessage, next) /* }}} */ /* {{{ proto int HttpMessage::key(void) - * - * Implements Iterator. - */ + Implements Iterator::key(). */ PHP_METHOD(HttpMessage, key) { NO_ARGS { @@ -1590,9 +1409,7 @@ PHP_METHOD(HttpMessage, key) /* }}} */ /* {{{ proto HttpMessage HttpMessage::current(void) - * - * Implements Iterator. - */ + Implements Iterator::current(). */ PHP_METHOD(HttpMessage, current) { NO_ARGS { diff --git a/http_querystring_object.c b/http_querystring_object.c index 68d6e27..8bea12e 100644 --- a/http_querystring_object.c +++ b/http_querystring_object.c @@ -41,6 +41,12 @@ HTTP_BEGIN_ARGS(singleton, 0) HTTP_END_ARGS; #endif +HTTP_BEGIN_ARGS(factory, 0) + HTTP_ARG_VAL(global, 0) + HTTP_ARG_VAL(params, 0) + HTTP_ARG_VAL(class_name, 0) +HTTP_END_ARGS; + HTTP_EMPTY_ARGS(toArray); HTTP_EMPTY_ARGS(toString); @@ -115,6 +121,7 @@ zend_function_entry http_querystring_object_fe[] = { HTTP_QUERYSTRING_GME(getArray, ZEND_ACC_PUBLIC) HTTP_QUERYSTRING_GME(getObject, ZEND_ACC_PUBLIC) + HTTP_QUERYSTRING_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #ifndef WONKY HTTP_QUERYSTRING_ME(singleton, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #endif @@ -169,10 +176,10 @@ PHP_MINIT_FUNCTION(http_querystring_object) zend_object_value _http_querystring_object_new(zend_class_entry *ce TSRMLS_DC) { - return http_querystring_object_new_ex(ce, NULL); + return http_querystring_object_new_ex(ce, NULL, NULL); } -zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, http_querystring_object **ptr TSRMLS_DC) +zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, void *nothing, http_querystring_object **ptr TSRMLS_DC) { zend_object_value ov; http_querystring_object *o; @@ -205,7 +212,7 @@ void _http_querystring_object_free(zend_object *object TSRMLS_DC) #define http_querystring_instantiate(t, g, p, u) _http_querystring_instantiate((t), (g), (p), (u) TSRMLS_CC) static inline zval *_http_querystring_instantiate(zval *this_ptr, zend_bool global, zval *params, zend_bool defer_update TSRMLS_DC) { - zval *qarray, *qstring, **_SERVER = NULL, **_GET = NULL, **QUERY_STRING = NULL;; + zval *qarray = NULL, *qstring = NULL, **_SERVER = NULL, **_GET = NULL, **QUERY_STRING = NULL;; if (!this_ptr) { MAKE_STD_ZVAL(this_ptr); @@ -287,10 +294,7 @@ static inline void _http_querystring_get(zval *this_ptr, int type, char *name, u /* }}} */ /* {{{ proto final void HttpQueryString::__construct([bool global = true[, mixed add]) - * - * Creates a new HttpQueryString object instance. - * Operates on and modifies $_GET and $_SERVER['QUERY_STRING'] if global is TRUE. - */ + Creates a new HttpQueryString object instance. Operates on and modifies $_GET and $_SERVER['QUERY_STRING'] if global is TRUE. */ PHP_METHOD(HttpQueryString, __construct) { zend_bool global = 1; @@ -306,10 +310,30 @@ PHP_METHOD(HttpQueryString, __construct) } /* }}} */ +/* {{{ proto HttpQueryString HttpQueryString::factory([bool global = TRUE[, mixed params[, string class_name = "HttpQueryString"]) + Creates a new HttpQueryString object instance. */ +PHP_METHOD(HttpQueryString, factory) +{ + zend_bool global = 1; + zval *params = NULL; + char *cn = NULL; + int cl = 0; + zend_object_value ov; + + SET_EH_THROW_HTTP(); + if (!sapi_module.treat_data) { + http_error(HE_ERROR, HTTP_E_QUERYSTRING, "The SAPI does not have a treat_data function registered"); + } else if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bzs", &global, ¶ms, &cn, &cl) && + SUCCESS == http_object_new(&ov, cn, cl, _http_querystring_object_new_ex, http_querystring_object_ce, NULL, NULL)) { + RETVAL_OBJVAL(ov, 0); + http_querystring_instantiate(return_value, global, params, 0); + } + SET_EH_NORMAL(); +} +/* }}} */ + /* {{{ proto string HttpQueryString::toString() - * - * Returns the string representation. - */ + Returns the string representation. */ PHP_METHOD(HttpQueryString, toString) { NO_ARGS; @@ -318,9 +342,7 @@ PHP_METHOD(HttpQueryString, toString) /* }}} */ /* {{{ proto array HttpQueryString::toArray() - * - * Returns the array representation. - */ + Returns the array representation. */ PHP_METHOD(HttpQueryString, toArray) { NO_ARGS; @@ -329,12 +351,7 @@ PHP_METHOD(HttpQueryString, toArray) /* }}} */ /* {{{ proto mixed HttpQueryString::get([string key[, mixed type = 0[, mixed defval = NULL[, bool delete = false]]]]) - * - * Get (part of) the query string. - * - * The type parameter is either one of the HttpQueryString::TYPE_* constants or a type abbreviation like - * "b" for bool, "i" for int, "f" for float, "s" for string, "a" for array and "o" for a stdClass object. - */ + Get (part of) the query string. The type parameter is either one of the HttpQueryString::TYPE_* constants or a type abbreviation like "b" for bool, "i" for int, "f" for float, "s" for string, "a" for array and "o" for a stdClass object. */ PHP_METHOD(HttpQueryString, get) { char *name = NULL; @@ -374,9 +391,7 @@ PHP_METHOD(HttpQueryString, get) /* }}} */ /* {{{ proto string HttpQueryString::set(mixed params) - * - * Set query string entry/entries. NULL values will unset the variable. - */ + Set query string entry/entries. NULL values will unset the variable. */ PHP_METHOD(HttpQueryString, set) { zval *params; @@ -395,16 +410,7 @@ PHP_METHOD(HttpQueryString, set) /* }}} */ /* {{{ proto HttpQueryString HttpQueryString::mod(mixed params) - * - * Copies the query string object and sets provided params at the clone. - * This is basically shorthand for: - *
- * set($other_params);
- * ?>
- * 
- */ + Copies the query string object and sets provided params at the clone. */ PHP_METHOD(HttpQueryString, mod) { zval *zobj, *qarr, *qstr, *params; @@ -424,9 +430,7 @@ PHP_METHOD(HttpQueryString, mod) #ifndef WONKY /* {{{ proto static HttpQueryString HttpQueryString::singleton([bool global = true]) - * - * Get a single instance (differentiates between the global setting). - */ + Get a single instance (differentiates between the global setting). */ PHP_METHOD(HttpQueryString, singleton) { zend_bool global = 1; @@ -483,12 +487,7 @@ HTTP_QUERYSTRING_GETTER(getObject, IS_OBJECT); #ifdef HTTP_HAVE_ICONV /* {{{ proto bool HttpQueryString::xlate(string ie, string oe) - * - * Converts the query string from the source encoding ie to the target encoding oe. - * WARNING: Don't use any character set that can contain NUL bytes like UTF-16. - * - * Returns TRUE on success or FALSE on failure. - */ + Converts the query string from the source encoding ie to the target encoding oe. WARNING: Don't use any character set that can contain NUL bytes like UTF-16. */ PHP_METHOD(HttpQueryString, xlate) { char *ie, *oe; @@ -518,9 +517,7 @@ PHP_METHOD(HttpQueryString, xlate) #endif /* HAVE_ICONV */ /* {{{ proto string HttpQueryString::serialize() - * - * Implements Serializable. - */ + Implements Serializable::serialize(). */ PHP_METHOD(HttpQueryString, serialize) { NO_ARGS; @@ -529,9 +526,7 @@ PHP_METHOD(HttpQueryString, serialize) /* }}} */ /* {{{ proto void HttpQueryString::unserialize(string serialized) - * - * Implements Serializable. - */ + Implements Serializable::unserialize(). */ PHP_METHOD(HttpQueryString, unserialize) { zval *serialized; @@ -549,9 +544,7 @@ PHP_METHOD(HttpQueryString, unserialize) /* }}} */ /* {{{ proto mixed HttpQueryString::offsetGet(string offset) - * - * Implements ArrayAccess. - */ + Implements ArrayAccess::offsetGet(). */ PHP_METHOD(HttpQueryString, offsetGet) { char *offset_str; @@ -566,9 +559,7 @@ PHP_METHOD(HttpQueryString, offsetGet) /* }}} */ /* {{{ proto void HttpQueryString::offsetSet(string offset, mixed value) - * - * Implements ArrayAccess. - */ + Implements ArrayAccess::offsetGet(). */ PHP_METHOD(HttpQueryString, offsetSet) { char *offset_str; @@ -586,9 +577,7 @@ PHP_METHOD(HttpQueryString, offsetSet) /* }}} */ /* {{{ proto bool HttpQueryString::offsetExists(string offset) - * - * Implements ArrayAccess. - */ + Implements ArrayAccess::offsetExists(). */ PHP_METHOD(HttpQueryString, offsetExists) { char *offset_str; @@ -602,9 +591,7 @@ PHP_METHOD(HttpQueryString, offsetExists) /* }}} */ /* {{{ proto void HttpQueryString::offsetUnset(string offset) - * - * Implements ArrayAccess. - */ + Implements ArrayAccess::offsetUnset(). */ PHP_METHOD(HttpQueryString, offsetUnset) { char *offset_str; diff --git a/http_request_object.c b/http_request_object.c index c56562a..3f37f46 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -40,6 +40,13 @@ HTTP_BEGIN_ARGS(__construct, 0) HTTP_ARG_VAL(options, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(factory, 0) + HTTP_ARG_VAL(url, 0) + HTTP_ARG_VAL(method, 0) + HTTP_ARG_VAL(options, 0) + HTTP_ARG_VAL(class_name, 0) +HTTP_END_ARGS; + HTTP_EMPTY_ARGS(getOptions); HTTP_BEGIN_ARGS(setOptions, 0) HTTP_ARG_VAL(options, 0) @@ -313,6 +320,8 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ME(getHistory, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(clearHistory, ZEND_ACC_PUBLIC) + HTTP_REQUEST_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + HTTP_REQUEST_ALIAS(get, http_get) HTTP_REQUEST_ALIAS(head, http_head) HTTP_REQUEST_ALIAS(postData, http_post_data) @@ -799,16 +808,7 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, /* ### USERLAND ### */ /* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET[, array options]]]) - * - * Instantiate a new HttpRequest object. - * - * Accepts a string as optional parameter containing the target request url. - * Additionally accepts an optional int parameter specifying the request method - * to use and an associative array as optional third parameter which will be - * passed to HttpRequest::setOptions(). - * - * Throws HttpException. - */ + Create a new HttpRequest object instance. */ PHP_METHOD(HttpRequest, __construct) { char *URL = NULL; @@ -832,16 +832,37 @@ PHP_METHOD(HttpRequest, __construct) } /* }}} */ +/* {{{ proto HttpRequest HttpRequest::factory([string url[, int request_method HTTP_METH_GET[, array options[, string class_name = "HttpRequest"]]]]) + Create a new HttpRequest object instance. */ +PHP_METHOD(HttpRequest, factory) +{ + char *cn = NULL, *URL = NULL; + int cl = 0, URL_len = 0; + long meth = -1; + zval *options = NULL; + zend_object_value ov; + + SET_EH_THROW_HTTP(); + if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!s", &URL, &URL_len, &meth, &options, &cn, &cl) && + SUCCESS == http_object_new(&ov, cn, cl, _http_request_object_new_ex, http_request_object_ce, NULL, NULL)) { + RETVAL_OBJVAL(ov, 0); + getThis() = return_value; + if (URL) { + UPD_STRL(url, URL, URL_len); + } + if (meth > -1) { + UPD_PROP(long, method, meth); + } + if (options) { + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options); + } + } + SET_EH_NORMAL(); +} +/* }}} */ + /* {{{ proto bool HttpRequest::setOptions([array options]) - * - * Set the request options to use. See http_get() for a full list of available options. - * - * Accepts an array as optional parameters, which values will overwrite the - * currently set request options. If the parameter is empty or omitted, - * the options of the HttpRequest object will be reset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set the request options to use. See http_get() for a full list of available options. */ PHP_METHOD(HttpRequest, setOptions) { HashKey key = initHashKey(0); @@ -907,11 +928,7 @@ PHP_METHOD(HttpRequest, setOptions) /* }}} */ /* {{{ proto array HttpRequest::getOptions() - * - * Get currently set options. - * - * Returns an associative array containing currently set options. - */ + Get currently set options. */ PHP_METHOD(HttpRequest, getOptions) { NO_ARGS; @@ -923,14 +940,7 @@ PHP_METHOD(HttpRequest, getOptions) /* }}} */ /* {{{ proto bool HttpRequest::setSslOptions([array options]) - * - * Set SSL options. - * - * Accepts an associative array as parameter containing any SSL specific options. - * If the parameter is empty or omitted, the SSL options will be reset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set SSL options. */ PHP_METHOD(HttpRequest, setSslOptions) { http_request_object_set_options_subr("ssl", 1, 0); @@ -938,13 +948,7 @@ PHP_METHOD(HttpRequest, setSslOptions) /* }}} */ /* {{{ proto bool HttpRequest::addSslOptions(array options) - * - * Set additional SSL options. - * - * Expects an associative array as parameter containing additional SSL specific options. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set additional SSL options. */ PHP_METHOD(HttpRequest, addSslOptions) { http_request_object_set_options_subr("ssl", 0, 0); @@ -952,11 +956,7 @@ PHP_METHOD(HttpRequest, addSslOptions) /* }}} */ /* {{{ proto array HttpRequest::getSslOtpions() - * - * Get previously set SSL options. - * - * Returns an associative array containing any previously set SSL options. - */ + Get previously set SSL options. */ PHP_METHOD(HttpRequest, getSslOptions) { http_request_object_get_options_subr("ssl"); @@ -964,28 +964,14 @@ PHP_METHOD(HttpRequest, getSslOptions) /* }}} */ /* {{{ proto bool HttpRequest::addHeaders(array headers) - * - * Add request header name/value pairs. - * - * Expects an associative array as parameter containing additional header - * name/value pairs. - * - * Returns TRUE on success, or FALSE on failure. - */ + Add request header name/value pairs. */ PHP_METHOD(HttpRequest, addHeaders) { http_request_object_set_options_subr("headers", 0, 1); } /* {{{ proto bool HttpRequest::setHeaders([array headers]) - * - * Set request header name/value pairs. - * - * Accepts an associative array as parameter containing header name/value pairs. - * If the parameter is empty or omitted, all previously set headers will be unset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set request header name/value pairs. */ PHP_METHOD(HttpRequest, setHeaders) { http_request_object_set_options_subr("headers", 1, 1); @@ -993,11 +979,7 @@ PHP_METHOD(HttpRequest, setHeaders) /* }}} */ /* {{{ proto array HttpRequest::getHeaders() - * - * Get previously set request headers. - * - * Returns an associative array containing all currently set headers. - */ + Get previously set request headers. */ PHP_METHOD(HttpRequest, getHeaders) { http_request_object_get_options_subr("headers"); @@ -1005,14 +987,7 @@ PHP_METHOD(HttpRequest, getHeaders) /* }}} */ /* {{{ proto bool HttpRequest::setCookies([array cookies]) - * - * Set cookies. - * - * Accepts an associative array as parameter containing cookie name/value pairs. - * If the parameter is empty or omitted, all previously set cookies will be unset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set cookies. */ PHP_METHOD(HttpRequest, setCookies) { http_request_object_set_options_subr("cookies", 1, 0); @@ -1020,14 +995,7 @@ PHP_METHOD(HttpRequest, setCookies) /* }}} */ /* {{{ proto bool HttpRequest::addCookies(array cookies) - * - * Add cookies. - * - * Expects an associative array as parameter containing any cookie name/value - * pairs to add. - * - * Returns TRUE on success, or FALSE on failure. - */ + Add cookies. */ PHP_METHOD(HttpRequest, addCookies) { http_request_object_set_options_subr("cookies", 0, 0); @@ -1035,11 +1003,7 @@ PHP_METHOD(HttpRequest, addCookies) /* }}} */ /* {{{ proto array HttpRequest::getCookies() - * - * Get previously set cookies. - * - * Returns an associative array containing any previously set cookies. - */ + Get previously set cookies. */ PHP_METHOD(HttpRequest, getCookies) { http_request_object_get_options_subr("cookies"); @@ -1047,10 +1011,7 @@ PHP_METHOD(HttpRequest, getCookies) /* }}} */ /* {{{ proto bool HttpRequest::enableCookies() - * - * Enable automatic sending of received cookies. - * Note that cuutomly set cookies will be sent anyway. - */ + Enable automatic sending of received cookies. Note that customly set cookies will be sent anyway. */ PHP_METHOD(HttpRequest, enableCookies) { NO_ARGS { @@ -1062,16 +1023,7 @@ PHP_METHOD(HttpRequest, enableCookies) /* }}} */ /* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE]) - * - * Reset all automatically received/sent cookies. - * Note that customly set cookies are not affected. - * - * Accepts an optional bool parameter specifying - * whether only session cookies should be reset - * (needs libcurl >= v7.15.4, else libcurl >= v7.14.1). - * - * Returns TRUE on success, or FALSE on failure. - */ + Reset all automatically received/sent cookies. Note that customly set cookies are not affected. */ PHP_METHOD(HttpRequest, resetCookies) { zend_bool session_only = 0; @@ -1085,13 +1037,7 @@ PHP_METHOD(HttpRequest, resetCookies) /* }}} */ /* {{{ proto bool HttpRequest::setUrl(string url) - * - * Set the request URL. - * - * Expects a string as parameter specifying the request url. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set the request URL. */ PHP_METHOD(HttpRequest, setUrl) { char *URL = NULL; @@ -1107,11 +1053,7 @@ PHP_METHOD(HttpRequest, setUrl) /* }}} */ /* {{{ proto string HttpRequest::getUrl() - * - * Get the previously set request URL. - * - * Returns the currently set request url as string. - */ + Get the previously set request URL. */ PHP_METHOD(HttpRequest, getUrl) { NO_ARGS; @@ -1123,14 +1065,7 @@ PHP_METHOD(HttpRequest, getUrl) /* }}} */ /* {{{ proto bool HttpRequest::setMethod(int request_method) - * - * Set the request method. - * - * Expects an int as parameter specifying the request method to use. - * In PHP 5.1+ HttpRequest::METH_*, otherwise the HTTP_METH_* constants can be used. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set the request method. */ PHP_METHOD(HttpRequest, setMethod) { long meth; @@ -1145,11 +1080,7 @@ PHP_METHOD(HttpRequest, setMethod) /* }}} */ /* {{{ proto int HttpRequest::getMethod() - * - * Get the previously set request method. - * - * Returns the currently set request method. - */ + Get the previously set request method. */ PHP_METHOD(HttpRequest, getMethod) { NO_ARGS; @@ -1161,15 +1092,7 @@ PHP_METHOD(HttpRequest, getMethod) /* }}} */ /* {{{ proto bool HttpRequest::setContentType(string content_type) - * - * Set the content type the post request should have. - * - * Expects a string as parameters containing the content type of the request - * (primary/secondary). - * - * Returns TRUE on success, or FALSE if the content type does not seem to - * contain a primary and a secondary part. - */ + Set the content type the post request should have. */ PHP_METHOD(HttpRequest, setContentType) { char *ctype; @@ -1188,11 +1111,7 @@ PHP_METHOD(HttpRequest, setContentType) /* }}} */ /* {{{ proto string HttpRequest::getContentType() - * - * Get the previously content type. - * - * Returns the previously set content type as string. - */ + Get the previously content type. */ PHP_METHOD(HttpRequest, getContentType) { NO_ARGS; @@ -1204,16 +1123,7 @@ PHP_METHOD(HttpRequest, getContentType) /* }}} */ /* {{{ proto bool HttpRequest::setQueryData([mixed query_data]) - * - * Set the URL query parameters to use, overwriting previously set query parameters. - * Affects any request types. - * - * Accepts a string or associative array parameter containing the pre-encoded - * query string or to be encoded query fields. If the parameter is empty or - * omitted, the query data will be unset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set the URL query parameters to use, overwriting previously set query parameters. */ PHP_METHOD(HttpRequest, setQueryData) { zval *qdata = NULL; @@ -1247,11 +1157,7 @@ PHP_METHOD(HttpRequest, setQueryData) /* }}} */ /* {{{ proto string HttpRequest::getQueryData() - * - * Get the current query data in form of an urlencoded query string. - * - * Returns a string containing the urlencoded query. - */ + Get the current query data in form of an urlencoded query string. */ PHP_METHOD(HttpRequest, getQueryData) { NO_ARGS; @@ -1263,14 +1169,7 @@ PHP_METHOD(HttpRequest, getQueryData) /* }}} */ /* {{{ proto bool HttpRequest::addQueryData(array query_params) - * - * Add parameters to the query parameter list, leaving previously set unchanged. - * Affects any request type. - * - * Expects an associative array as parameter containing the query fields to add. - * - * Returns TRUE on success, or FALSE on failure. - */ + Add parameters to the query parameter list, leaving previously set unchanged. */ PHP_METHOD(HttpRequest, addQueryData) { zval *qdata, *old_qdata; @@ -1295,15 +1194,7 @@ PHP_METHOD(HttpRequest, addQueryData) /* }}} */ /* {{{ proto bool HttpRequest::addPostFields(array post_data) - * - * Adds POST data entries, leaving previously set unchanged, unless a - * post entry with the same name already exists. - * Affects only POST and custom requests. - * - * Expects an associative array as parameter containing the post fields. - * - * Returns TRUE on success, or FALSE on failure. - */ + Adds POST data entries, leaving previously set unchanged, unless a post entry with the same name already exists. */ PHP_METHOD(HttpRequest, addPostFields) { zval *post_data, *old_post, *new_post; @@ -1329,15 +1220,7 @@ PHP_METHOD(HttpRequest, addPostFields) /* }}} */ /* {{{ proto bool HttpRequest::setPostFields([array post_data]) - * - * Set the POST data entries, overwriting previously set POST data. - * Affects only POST and custom requests. - * - * Accepts an associative array as parameter containing the post fields. - * If the parameter is empty or omitted, the post data will be unset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set the POST data entries, overwriting previously set POST data. */ PHP_METHOD(HttpRequest, setPostFields) { zval *post, *post_data = NULL; @@ -1359,11 +1242,7 @@ PHP_METHOD(HttpRequest, setPostFields) /* }}}*/ /* {{{ proto array HttpRequest::getPostFields() - * - * Get previously set POST data. - * - * Returns the currently set post fields as associative array. - */ + Get previously set POST data. */ PHP_METHOD(HttpRequest, getPostFields) { NO_ARGS; @@ -1375,17 +1254,7 @@ PHP_METHOD(HttpRequest, getPostFields) /* }}} */ /* {{{ proto bool HttpRequest::setRawPostData([string raw_post_data]) - * - * Set raw post data to send, overwriting previously set raw post data. Don't - * forget to specify a content type. Affects only POST and custom requests. - * Only either post fields or raw post data can be used for each request. - * Raw post data has higher precedence and will be used even if post fields - * are set. - * - * Accepts a string as parameter containing the *raw* post data. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set raw post data to send, overwriting previously set raw post data. Don't forget to specify a content type. */ PHP_METHOD(HttpRequest, setRawPostData) { char *raw_data = NULL; @@ -1405,14 +1274,7 @@ PHP_METHOD(HttpRequest, setRawPostData) /* }}} */ /* {{{ proto bool HttpRequest::addRawPostData(string raw_post_data) - * - * Add raw post data, leaving previously set raw post data unchanged. - * Affects only POST and custom requests. - * - * Expects a string as parameter containing the raw post data to concatenate. - * - * Returns TRUE on success, or FALSE on failure. - */ + Add raw post data, leaving previously set raw post data unchanged. */ PHP_METHOD(HttpRequest, addRawPostData) { char *raw_data; @@ -1439,11 +1301,7 @@ PHP_METHOD(HttpRequest, addRawPostData) /* }}} */ /* {{{ proto string HttpRequest::getRawPostData() - * - * Get previously set raw post data. - * - * Returns a string containing the currently set raw post data. - */ + Get previously set raw post data. */ PHP_METHOD(HttpRequest, getRawPostData) { NO_ARGS; @@ -1455,18 +1313,7 @@ PHP_METHOD(HttpRequest, getRawPostData) /* }}} */ /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"]) - * - * Add a file to the POST request, leaving previously set files unchanged. - * Affects only POST and custom requests. Cannot be used with raw post data. - * - * Expects a string parameter containing the form element name, and a string - * paremeter containing the path to the file which should be uploaded. - * Additionally accepts an optional string parameter which should contain - * the content type of the file. - * - * Returns TRUE on success, or FALSE if the content type seems not to contain a - * primary and a secondary content type part. - */ + Add a file to the POST request, leaving previously set files unchanged. */ PHP_METHOD(HttpRequest, addPostFile) { zval *entry, *old_post, *new_post; @@ -1506,16 +1353,7 @@ PHP_METHOD(HttpRequest, addPostFile) /* }}} */ /* {{{ proto bool HttpRequest::setPostFiles([array post_files]) - * - * Set files to post, overwriting previously set post files. - * Affects only POST and requests. Cannot be used with raw post data. - * - * Accepts an array containing the files to post. Each entry should be an - * associative array with "name", "file" and "type" keys. If the parameter - * is empty or omitted the post files will be unset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set files to post, overwriting previously set post files. */ PHP_METHOD(HttpRequest, setPostFiles) { zval *files = NULL, *post; @@ -1537,11 +1375,7 @@ PHP_METHOD(HttpRequest, setPostFiles) /* }}} */ /* {{{ proto array HttpRequest::getPostFiles() - * - * Get all previously added POST files. - * - * Returns an array containing currently set post files. - */ + Get all previously added POST files. */ PHP_METHOD(HttpRequest, getPostFiles) { NO_ARGS; @@ -1553,14 +1387,7 @@ PHP_METHOD(HttpRequest, getPostFiles) /* }}} */ /* {{{ proto bool HttpRequest::setPutFile([string file]) - * - * Set file to put. Affects only PUT requests. - * - * Accepts a string as parameter referencing the path to file. - * If the parameter is empty or omitted the put file will be unset. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set file to put. Affects only PUT requests. */ PHP_METHOD(HttpRequest, setPutFile) { char *file = ""; @@ -1576,11 +1403,7 @@ PHP_METHOD(HttpRequest, setPutFile) /* }}} */ /* {{{ proto string HttpRequest::getPutFile() - * - * Get previously set put file. - * - * Returns a string containing the path to the currently set put file. - */ + Get previously set put file. */ PHP_METHOD(HttpRequest, getPutFile) { NO_ARGS; @@ -1592,17 +1415,7 @@ PHP_METHOD(HttpRequest, getPutFile) /* }}} */ /* {{{ proto bool HttpRequest::setPutData([string put_data]) - * - * Set PUT data to send, overwriting previously set PUT data. - * Affects only PUT requests. - * Only either PUT data or PUT file can be used for each request. - * PUT data has higher precedence and will be used even if a PUT - * file is set. - * - * Accepts a string as parameter containing the data to upload. - * - * Returns TRUE on success, or FALSE on failure. - */ + Set PUT data to send, overwriting previously set PUT data. */ PHP_METHOD(HttpRequest, setPutData) { char *put_data = NULL; @@ -1622,14 +1435,7 @@ PHP_METHOD(HttpRequest, setPutData) /* }}} */ /* {{{ proto bool HttpRequest::addPutData(string put_data) - * - * Add PUT data, leaving previously set PUT data unchanged. - * Affects only PUT requests. - * - * Expects a string as parameter containing the data to concatenate. - * - * Returns TRUE on success, or FALSE on failure. - */ + Add PUT data, leaving previously set PUT data unchanged. */ PHP_METHOD(HttpRequest, addPutData) { char *put_data; @@ -1656,11 +1462,7 @@ PHP_METHOD(HttpRequest, addPutData) /* }}} */ /* {{{ proto string HttpRequest::getPutData() - * - * Get previously set PUT data. - * - * Returns a string containing the currently set raw post data. - */ + Get previously set PUT data. */ PHP_METHOD(HttpRequest, getPutData) { NO_ARGS; @@ -1672,16 +1474,7 @@ PHP_METHOD(HttpRequest, getPutData) /* }}} */ /* {{{ proto array HttpRequest::getResponseData() - * - * Get all response data after the request has been sent. - * - * Returns an associative array with the key "headers" containing an associative - * array holding all response headers, as well as the key "body" containing a - * string with the response body. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. - */ + Get all response data after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseData) { NO_ARGS; @@ -1709,18 +1502,7 @@ PHP_METHOD(HttpRequest, getResponseData) /* }}} */ /* {{{ proto mixed HttpRequest::getResponseHeader([string name]) - * - * Get response header(s) after the request has been sent. - * - * Accepts an string as optional parameter specifying a certain header to read. - * If the parameter is empty or omitted all response headers will be returned. - * - * Returns either a string with the value of the header matching name if requested, - * FALSE on failure, or an associative array containing all response headers. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. - */ + Get response header(s) after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseHeader) { if (return_value_used) { @@ -1751,14 +1533,7 @@ PHP_METHOD(HttpRequest, getResponseHeader) /* }}} */ /* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]]) - * - * Get response cookie(s) after the request has been sent. - * - * Returns an array of stdClass objects like http_parse_cookie would return. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. - */ + Get response cookie(s) after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseCookies) { if (return_value_used) { @@ -1841,14 +1616,7 @@ PHP_METHOD(HttpRequest, getResponseCookies) /* }}} */ /* {{{ proto string HttpRequest::getResponseBody() - * - * Get the response body after the request has been sent. - * - * Returns a string containing the response body. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. - */ + Get the response body after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseBody) { NO_ARGS; @@ -1867,14 +1635,7 @@ PHP_METHOD(HttpRequest, getResponseBody) /* }}} */ /* {{{ proto int HttpRequest::getResponseCode() - * - * Get the response code after the request has been sent. - * - * Returns an int representing the response code. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. - */ + Get the response code after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseCode) { NO_ARGS; @@ -1886,11 +1647,7 @@ PHP_METHOD(HttpRequest, getResponseCode) /* }}} */ /* {{{ proto string HttpRequest::getResponseStatus() - * - * Get the response status (i.e. the string after the response code) after the message has been sent. - * - * Returns a string containing the response status text. - */ + Get the response status (i.e. the string after the response code) after the message has been sent. */ PHP_METHOD(HttpRequest, getResponseStatus) { NO_ARGS; @@ -1902,21 +1659,7 @@ PHP_METHOD(HttpRequest, getResponseStatus) /* }}} */ /* {{{ proto mixed HttpRequest::getResponseInfo([string name]) - * - * Get response info after the request has been sent. - * See http_get() for a full list of returned info. - * - * Accepts a string as optional parameter specifying the info to read. - * If the parameter is empty or omitted, an associative array containing - * all available info will be returned. - * - * Returns either a scalar containing the value of the info matching name if - * requested, FALSE on failure, or an associative array containing all - * available info. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. - */ + Get response info after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseInfo) { if (return_value_used) { @@ -1949,18 +1692,7 @@ PHP_METHOD(HttpRequest, getResponseInfo) /* }}}*/ /* {{{ proto HttpMessage HttpRequest::getResponseMessage() - * - * Get the full response as HttpMessage object after the request has been sent. - * - * Returns an HttpMessage object of the response. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. Use HttpMessage::getParentMessage() - * to access the data of previously received responses within this request - * cycle. - * - * Throws HttpException, HttpRuntimeException. - */ + Get the full response as HttpMessage object after the request has been sent. */ PHP_METHOD(HttpRequest, getResponseMessage) { NO_ARGS { @@ -1979,23 +1711,7 @@ PHP_METHOD(HttpRequest, getResponseMessage) /* }}} */ /* {{{ proto HttpMessage HttpRequest::getRequestMessage() - * - * Get sent HTTP message. - * - * Returns an HttpMessage object representing the sent request. - * - * If redirects were allowed and several responses were received, the data - * references the last received response. Use HttpMessage::getParentMessage() - * to access the data of previously sent requests within this request - * cycle. - * - * Note that the internal request message is immutable, that means that the - * request message received through HttpRequest::getRequestMessage() will - * always look the same for the same request, regardless of any changes you - * may have made to the returned object. - * - * Throws HttpMalformedHeadersException, HttpEncodingException. - */ + Get sent HTTP message. */ PHP_METHOD(HttpRequest, getRequestMessage) { NO_ARGS; @@ -2014,11 +1730,7 @@ PHP_METHOD(HttpRequest, getRequestMessage) /* }}} */ /* {{{ proto string HttpRequest::getRawRequestMessage() - * - * Get sent HTTP message. - * - * Returns an HttpMessage in a form of a string - */ + Get sent HTTP message. */ PHP_METHOD(HttpRequest, getRawRequestMessage) { NO_ARGS; @@ -2032,11 +1744,7 @@ PHP_METHOD(HttpRequest, getRawRequestMessage) /* }}} */ /* {{{ proto string HttpRequest::getRawResponseMessage() - * - * Get the entire HTTP response. - * - * Returns the complete web server response, including the headers in a form of a string. - */ + Get the entire HTTP response. */ PHP_METHOD(HttpRequest, getRawResponseMessage) { NO_ARGS; @@ -2050,20 +1758,7 @@ PHP_METHOD(HttpRequest, getRawResponseMessage) /* }}} */ /* {{{ proto HttpMessage HttpRequest::getHistory() - * - * Get all sent requests and received responses as an HttpMessage object. - * - * If you want to record history, set the instance variable - * HttpRequest::$recordHistory to TRUE. - * - * Returns an HttpMessage object representing the complete request/response - * history. - * - * The object references the last received response, use HttpMessage::getParentMessage() - * to access the data of previously sent requests and received responses. - * - * Throws HttpRuntimeException. - */ + Get all sent requests and received responses as an HttpMessage object. */ PHP_METHOD(HttpRequest, getHistory) { NO_ARGS; @@ -2084,9 +1779,7 @@ PHP_METHOD(HttpRequest, getHistory) /* }}} */ /* {{{ proto void HttpRequest::clearHistory() - * - * Clear the history. - */ + Clear the history. */ PHP_METHOD(HttpRequest, clearHistory) { NO_ARGS { @@ -2101,50 +1794,7 @@ PHP_METHOD(HttpRequest, clearHistory) /* }}} */ /* {{{ proto HttpMessage HttpRequest::send() - * - * Send the HTTP request. - * - * Returns the received response as HttpMessage object. - * - * NOTE: While an exception may be thrown, the transfer could have succeeded - * at least partially, so you might want to check the return values of various - * HttpRequest::getResponse*() methods. - * - * Throws HttpRuntimeException, HttpRequestException, - * HttpMalformedHeaderException, HttpEncodingException. - * - * GET example: - *
- * setOptions(array('lastmodified' => filemtime('local.rss')));
- * $r->addQueryData(array('category' => 3));
- * try {
- *     $r->send();
- *     if ($r->getResponseCode() == 200) {
- *         file_put_contents('local.rss', $r->getResponseBody());
- *    }
- * } catch (HttpException $ex) {
- *     echo $ex;
- * }
- * ?>
- * 
- * - * POST example: - *
- * setOptions(array('cookies' => array('lang' => 'de')));
- * $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
- * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
- * try {
- *     echo $r->send()->getBody();
- * } catch (HttpException $ex) {
- *     echo $ex;
- * }
- * ?>
- * 
- */ + Send the HTTP request. */ PHP_METHOD(HttpRequest, send) { getObject(http_request_object, obj); diff --git a/http_requestdatashare_object.c b/http_requestdatashare_object.c index 46299e6..103581e 100644 --- a/http_requestdatashare_object.c +++ b/http_requestdatashare_object.c @@ -47,6 +47,11 @@ HTTP_END_ARGS; HTTP_EMPTY_ARGS(reset); +HTTP_BEGIN_ARGS(factory, 0) + HTTP_ARG_VAL(global, 0) + HTTP_ARG_VAL(class_name, 0) +HTTP_END_ARGS; + #ifndef WONKY HTTP_BEGIN_ARGS(singleton, 0) HTTP_ARG_VAL(global, 0) @@ -69,6 +74,7 @@ zend_function_entry http_requestdatashare_object_fe[] = { HTTP_RSHARE_ME(attach, ZEND_ACC_PUBLIC) HTTP_RSHARE_ME(detach, ZEND_ACC_PUBLIC) HTTP_RSHARE_ME(reset, ZEND_ACC_PUBLIC) + HTTP_RSHARE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #ifndef WONKY HTTP_RSHARE_ME(singleton, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) #endif @@ -171,9 +177,7 @@ static void _http_requestdatashare_object_write_prop(zval *object, zval *member, } /* {{{ proto void HttpRequestDataShare::__destruct() - * - * Clean up HttpRequestDataShare object. - */ + Clean up HttpRequestDataShare object. */ PHP_METHOD(HttpRequestDataShare, __destruct) { NO_ARGS { @@ -184,9 +188,7 @@ PHP_METHOD(HttpRequestDataShare, __destruct) /* }}} */ /* {{{ proto int HttpRequestDataShare::count() - * - * Implements Countable::count(). - */ + Implements Countable::count(). */ PHP_METHOD(HttpRequestDataShare, count) { getObject(http_requestdatashare_object, obj); @@ -229,11 +231,25 @@ PHP_METHOD(HttpRequestDataShare, reset) } } +PHP_METHOD(HttpRequestDataShare, factory) +{ + zend_bool global = 0; + char *cn = NULL; + int cl = 0; + zend_object_value ov; + + SET_EH_THROW_HTTP(); + if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", &global, &cn, &cl) && + SUCCESS == http_object_new(&ov, cn, cl, _http_requestdatashare_object_new_ex, http_requestdatashare_object_ce, NULL, NULL)) { + RETVAL_OBJVAL(ov, 0); + http_requestdatashare_instantiate(return_value, global); + } + SET_EH_NORMAL(); +} + #ifndef WONKY /* {{{ proto static HttpRequestDataShare HttpRequestDataShare::singleton([bool global = false]) - * - * Get a single instance (differentiates between the global setting). - */ + Get a single instance (differentiates between the global setting). */ PHP_METHOD(HttpRequestDataShare, singleton) { zend_bool global = 0; @@ -290,9 +306,7 @@ static inline zval *_http_requestdatashare_instantiate(zval *this_ptr, zend_bool } return this_ptr; } -#endif - - +#endif /* !WONKY */ #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */ diff --git a/http_requestpool_object.c b/http_requestpool_object.c index ff8f75d..3a203ef 100644 --- a/http_requestpool_object.c +++ b/http_requestpool_object.c @@ -154,40 +154,7 @@ static void _http_requestpool_object_llist2array(zval **req, zval *array TSRMLS_ /* ### USERLAND ### */ /* {{{ proto void HttpRequestPool::__construct([HttpRequest request[, ...]]) - * - * Instantiate a new HttpRequestPool object. An HttpRequestPool is - * able to send several HttpRequests in parallel. - * - * WARNING: Don't attach/detach HttpRequest objects to the HttpRequestPool - * object while you're using the implemented Iterator interface. - * - * Accepts virtual infinite optional parameters each referencing an - * HttpRequest object. - * - * Throws HttpRequestPoolException (HttpRequestException, HttpInvalidParamException). - * - * Example: - *
- * send();
- *     foreach($pool as $request) {
- *         printf("%s is %s (%d)\n",
- *             $request->getUrl(),
- *             $request->getResponseCode() ? 'alive' : 'not alive',
- *             $request->getResponseCode()
- *         );
- *     }
- * } catch (HttpException $e) {
- *     echo $e;
- * }
- * ?>
- * 
- */ + Creates a new HttpRequestPool object instance. */ PHP_METHOD(HttpRequestPool, __construct) { int argc = ZEND_NUM_ARGS(); @@ -211,9 +178,7 @@ PHP_METHOD(HttpRequestPool, __construct) /* }}} */ /* {{{ proto void HttpRequestPool::__destruct() - * - * Clean up HttpRequestPool object. - */ + Clean up HttpRequestPool object. */ PHP_METHOD(HttpRequestPool, __destruct) { getObject(http_requestpool_object, obj); @@ -225,9 +190,7 @@ PHP_METHOD(HttpRequestPool, __destruct) /* }}} */ /* {{{ proto void HttpRequestPool::reset() - * - * Detach all attached HttpRequest objects. - */ + Detach all attached HttpRequest objects. */ PHP_METHOD(HttpRequestPool, reset) { getObject(http_requestpool_object, obj); @@ -239,18 +202,7 @@ PHP_METHOD(HttpRequestPool, reset) } /* {{{ proto bool HttpRequestPool::attach(HttpRequest request) - * - * Attach an HttpRequest object to this HttpRequestPool. - * WARNING: set all options prior attaching! - * - * Expects the parameter to be an HttpRequest object not already attached to - * antother HttpRequestPool object. - * - * Returns TRUE on success, or FALSE on failure. - * - * Throws HttpInvalidParamException, HttpRequestException, - * HttpRequestPoolException, HttpEncodingException. - */ + Attach an HttpRequest object to this HttpRequestPool. WARNING: set all options prior attaching! */ PHP_METHOD(HttpRequestPool, attach) { zval *request; @@ -271,16 +223,7 @@ PHP_METHOD(HttpRequestPool, attach) /* }}} */ /* {{{ proto bool HttpRequestPool::detach(HttpRequest request) - * - * Detach an HttpRequest object from this HttpRequestPool. - * - * Expects the parameter to be an HttpRequest object attached to this - * HttpRequestPool object. - * - * Returns TRUE on success, or FALSE on failure. - * - * Throws HttpInvalidParamException, HttpRequestPoolException. - */ + Detach an HttpRequest object from this HttpRequestPool. */ PHP_METHOD(HttpRequestPool, detach) { zval *request; @@ -298,13 +241,7 @@ PHP_METHOD(HttpRequestPool, detach) /* }}} */ /* {{{ proto bool HttpRequestPool::send() - * - * Send all attached HttpRequest objects in parallel. - * - * Returns TRUE on success, or FALSE on failure. - * - * Throws HttpRequestPoolException (HttpSocketException, HttpRequestException, HttpMalformedHeaderException). - */ + Send all attached HttpRequest objects in parallel. */ PHP_METHOD(HttpRequestPool, send) { STATUS status; @@ -324,36 +261,7 @@ PHP_METHOD(HttpRequestPool, send) /* }}} */ /* {{{ proto protected bool HttpRequestPool::socketPerform() - * - * Returns TRUE until each request has finished its transaction. - * - * Usage: - *
- * socketPerform()) {
- *             if (!$this->socketSelect()) {
- *                 throw new HttpSocketExcpetion;
- *             }
- *         }
- *     }
- *     
- *     protected final function socketPerform()
- *     {
- *         $result = parent::socketPerform();
- *         foreach ($this->getFinishedRequests() as $r) {
- *             $this->detach($r);
- *             // handle response of finished request
- *         }
- *         return $result;
- *     }
- * } 
- * ?>
- * 
- */ + Returns TRUE until each request has finished its transaction. */ PHP_METHOD(HttpRequestPool, socketPerform) { getObject(http_requestpool_object, obj); @@ -368,12 +276,7 @@ PHP_METHOD(HttpRequestPool, socketPerform) } /* }}} */ -/* {{{ proto protected bool HttpRequestPool::socketSelect() - * - * See HttpRequestPool::socketPerform(). - * - * Returns TRUE on success, or FALSE on failure. - */ +/* {{{ proto protected bool HttpRequestPool::socketSelect() */ PHP_METHOD(HttpRequestPool, socketSelect) { getObject(http_requestpool_object, obj); @@ -384,12 +287,8 @@ PHP_METHOD(HttpRequestPool, socketSelect) } /* }}} */ -/* implements Iterator */ - /* {{{ proto bool HttpRequestPool::valid() - * - * Implements Iterator::valid(). - */ + Implements Iterator::valid(). */ PHP_METHOD(HttpRequestPool, valid) { NO_ARGS; @@ -402,9 +301,7 @@ PHP_METHOD(HttpRequestPool, valid) /* }}} */ /* {{{ proto HttpRequest HttpRequestPool::current() - * - * Implements Iterator::current(). - */ + Implements Iterator::current(). */ PHP_METHOD(HttpRequestPool, current) { NO_ARGS; @@ -429,9 +326,7 @@ PHP_METHOD(HttpRequestPool, current) /* }}} */ /* {{{ proto int HttpRequestPool::key() - * - * Implements Iterator::key(). - */ + Implements Iterator::key(). */ PHP_METHOD(HttpRequestPool, key) { NO_ARGS; @@ -444,9 +339,7 @@ PHP_METHOD(HttpRequestPool, key) /* }}} */ /* {{{ proto void HttpRequestPool::next() - * - * Implements Iterator::next(). - */ + Implements Iterator::next(). */ PHP_METHOD(HttpRequestPool, next) { NO_ARGS { @@ -457,9 +350,7 @@ PHP_METHOD(HttpRequestPool, next) /* }}} */ /* {{{ proto void HttpRequestPool::rewind() - * - * Implements Iterator::rewind(). - */ + Implements Iterator::rewind(). */ PHP_METHOD(HttpRequestPool, rewind) { NO_ARGS { @@ -470,11 +361,7 @@ PHP_METHOD(HttpRequestPool, rewind) /* }}} */ /* {{{ proto int HttpRequestPool::count() - * - * Implements Countable. - * - * Returns the number of attached HttpRequest objects. - */ + Implements Countable::count(). */ PHP_METHOD(HttpRequestPool, count) { NO_ARGS { @@ -485,11 +372,7 @@ PHP_METHOD(HttpRequestPool, count) /* }}} */ /* {{{ proto array HttpRequestPool::getAttachedRequests() - * - * Get attached HttpRequest objects. - * - * Returns an array containing all currently attached HttpRequest objects. - */ + Get attached HttpRequest objects. */ PHP_METHOD(HttpRequestPool, getAttachedRequests) { getObject(http_requestpool_object, obj); @@ -504,12 +387,7 @@ PHP_METHOD(HttpRequestPool, getAttachedRequests) /* }}} */ /* {{{ proto array HttpRequestPool::getFinishedRequests() - * - * Get attached HttpRequest objects that already have finished their work. - * - * Returns an array containing all attached HttpRequest objects that - * already have finished their work. - */ + Get attached HttpRequest objects that already have finished their work. */ PHP_METHOD(HttpRequestPool, getFinishedRequests) { getObject(http_requestpool_object, obj); @@ -524,11 +402,7 @@ PHP_METHOD(HttpRequestPool, getFinishedRequests) /* }}} */ /* {{{ proto bool HttpRequest::enablePiplelinig([bool enable = true]) - * - * Enables pipelining support for all attached requests if support in libcurl is given. - * - * Returns TRUE on success, or FALSE on failure. - */ + Enables pipelining support for all attached requests if support in libcurl is given. */ PHP_METHOD(HttpRequestPool, enablePipelining) { zend_bool enable = 1; diff --git a/http_url_api.c b/http_url_api.c index fe1d834..37c23cd 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -161,7 +161,7 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u } if (!url->scheme) { - zval *https = http_get_server_var("HTTPS"); + zval *https = http_get_server_var("HTTPS", 1); if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) { url->scheme = estrndup("https", lenof("https")); } else switch (url->port) { @@ -191,8 +191,8 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u if (!url->host) { zval *zhost; - if ((((zhost = http_get_server_var("HTTP_HOST")) || - (zhost = http_get_server_var("SERVER_NAME")))) && Z_STRLEN_P(zhost)) { + if ((((zhost = http_get_server_var("HTTP_HOST", 1)) || + (zhost = http_get_server_var("SERVER_NAME", 1)))) && Z_STRLEN_P(zhost)) { url->host = estrndup(Z_STRVAL_P(zhost), Z_STRLEN_P(zhost)); } else { url->host = localhostname(); diff --git a/package.xml b/package.xml index ce57cf9..7eb44a4 100644 --- a/package.xml +++ b/package.xml @@ -24,15 +24,19 @@ support. Parallel requests are available for PHP 5 and greater. 1.4.0dev - 2006-11-06 + 2006-11-23 BSD, revised stable - + Added "ipresolve" request option + * Improved response performance ++ Added "ipresolve" request option + Added HTTP_IPRESOLVE_{ANY|V4|V6}, HttpRequest::IPRESOLVE_{ANY|V4|V6} constants + Added missing HTTP_SSL_VERSION_{ANY|TLSv1|SSLv2|SSLv3}, HttpRequest::SSL_VERSION_{ANY|TLSv1|SSLv2|SSLv3} constants ++ Added factory methods to HttpMessage, HttpQueryString, HttpRequest, HttpRequestDataShare, HttpDeflateStream, HttpInflateStream * Fixed aborted PUT request when empty put data was set with HttpRequest::setPutData() * Fixed crash when using non-associative arrays as request headers * Fixed crash when serializing incomplete HttpMessage objects +* Fixed bug #9282: libcurl version error in configure (keith at iveys dot org) +- Removed obsolete HTML function reference @@ -49,7 +53,6 @@ support. Parallel requests are available for PHP 5 and greater. - @@ -64,8 +67,6 @@ support. Parallel requests are available for PHP 5 and greater. - - @@ -83,14 +84,6 @@ support. Parallel requests are available for PHP 5 and greater. - - - - - - - - @@ -111,6 +104,7 @@ support. Parallel requests are available for PHP 5 and greater. + @@ -148,12 +142,6 @@ support. Parallel requests are available for PHP 5 and greater. - - - - - - @@ -171,31 +159,23 @@ support. Parallel requests are available for PHP 5 and greater. - - - - - - - + - - + + - - diff --git a/package2.xml b/package2.xml index eb56ce6..d830cf1 100644 --- a/package2.xml +++ b/package2.xml @@ -43,10 +43,12 @@ support. Parallel requests are available for PHP 5 and greater. + Added "ipresolve" request option + Added HTTP_IPRESOLVE_{ANY|V4|V6}, HttpRequest::IPRESOLVE_{ANY|V4|V6} constants + Added missing HTTP_SSL_VERSION_{ANY|TLSv1|SSLv2|SSLv3}, HttpRequest::SSL_VERSION_{ANY|TLSv1|SSLv2|SSLv3} constants ++ Added factory methods to HttpMessage, HttpQueryString, HttpRequest, HttpRequestDataShare, HttpDeflateStream, HttpInflateStream * Fixed aborted PUT request when empty put data was set with HttpRequest::setPutData() * Fixed crash when using non-associative arrays as request headers * Fixed crash when serializing incomplete HttpMessage objects * Fixed bug #9282: libcurl version error in configure (keith at iveys dot org) +- Removed obsolete HTML function reference ]]> @@ -54,7 +56,6 @@ support. Parallel requests are available for PHP 5 and greater. - @@ -296,7 +297,6 @@ support. Parallel requests are available for PHP 5 and greater. /> - diff --git a/php_http.h b/php_http.h index f77755a..59a2024 100644 --- a/php_http.h +++ b/php_http.h @@ -173,7 +173,6 @@ ZEND_EXTERN_MODULE_GLOBALS(http); # define HTTP_HAVE_SPL #endif -PHP_FUNCTION(http_test); PHP_FUNCTION(http_date); PHP_FUNCTION(http_build_url); PHP_FUNCTION(http_build_str); diff --git a/php_http_api.h b/php_http_api.h index f2c5312..190db23 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -56,6 +56,11 @@ extern zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend if (EG(exception)) { \ EG(exception) = http_exception_wrap(EG(exception), NULL, ex_ce); \ } + +typedef zend_object_value (*http_object_new_t)(zend_class_entry *ce, void *, void ** TSRMLS_DC); + +#define http_object_new(ov, cn, cl, co, ce, i, pp) _http_object_new((ov), (cn), (cl), (http_object_new_t) (co), (ce), (i), (void *) (pp) TSRMLS_CC) +extern STATUS _http_object_new(zend_object_value *ov, const char *cname_str, uint cname_len, http_object_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC); #endif /* ZEND_ENGINE_2 */ @@ -118,7 +123,7 @@ extern zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend } #define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC) -extern void http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC); +extern void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC); #define http_exit(s, h) http_exit_ex((s), (h), NULL, 1) #define http_exit_ex(s, h, b, e) _http_exit_ex((s), (h), (b), (e) TSRMLS_CC) @@ -128,15 +133,10 @@ extern STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send #define http_check_method_ex(m, a) _http_check_method_ex((m), (a)) extern STATUS _http_check_method_ex(const char *method, const char *methods); -#define HTTP_GSC(var, name, ret) HTTP_GSP(var, name, return ret) -#define HTTP_GSP(var, name, ret) \ - if (!(var = _http_get_server_var_ex(name, strlen(name)+1, 1 TSRMLS_CC))) { \ - ret; \ - } -#define http_got_server_var(v) (NULL != _http_get_server_var_ex((v), sizeof(v), 1 TSRMLS_CC)) -#define http_get_server_var(v) http_get_server_var_ex((v), sizeof(v)) -#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_got_server_var(v) (NULL != http_get_server_var_ex((v), strlen(v), 1)) +#define http_get_server_var(v, c) http_get_server_var_ex((v), strlen(v), (c)) +#define http_get_server_var_ex(v, l, c) _http_get_server_var_ex((v), (l), (c) TSRMLS_CC) +PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_len, 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) diff --git a/php_http_deflatestream_object.h b/php_http_deflatestream_object.h index 7af1011..0ce94d5 100644 --- a/php_http_deflatestream_object.h +++ b/php_http_deflatestream_object.h @@ -36,6 +36,7 @@ extern zend_object_value _http_deflatestream_object_clone_obj(zval *object TSRML extern void _http_deflatestream_object_free(zend_object *object TSRMLS_DC); PHP_METHOD(HttpDeflateStream, __construct); +PHP_METHOD(HttpDeflateStream, factory); PHP_METHOD(HttpDeflateStream, update); PHP_METHOD(HttpDeflateStream, flush); PHP_METHOD(HttpDeflateStream, finish); diff --git a/php_http_inflatestream_object.h b/php_http_inflatestream_object.h index bc08afe..783cf8b 100644 --- a/php_http_inflatestream_object.h +++ b/php_http_inflatestream_object.h @@ -36,6 +36,7 @@ extern zend_object_value _http_inflatestream_object_clone_obj(zval *object TSRML extern void _http_inflatestream_object_free(zend_object *object TSRMLS_DC); PHP_METHOD(HttpInflateStream, __construct); +PHP_METHOD(HttpInflateStream, factory); PHP_METHOD(HttpInflateStream, update); PHP_METHOD(HttpInflateStream, flush); PHP_METHOD(HttpInflateStream, finish); diff --git a/php_http_message_object.h b/php_http_message_object.h index 7f47167..2d9fcb1 100644 --- a/php_http_message_object.h +++ b/php_http_message_object.h @@ -111,7 +111,7 @@ PHP_METHOD(HttpMessage, current); PHP_METHOD(HttpMessage, key); PHP_METHOD(HttpMessage, next); -PHP_METHOD(HttpMessage, fromString); +PHP_METHOD(HttpMessage, factory); PHP_METHOD(HttpMessage, detach); PHP_METHOD(HttpMessage, prepend); diff --git a/php_http_querystring_object.h b/php_http_querystring_object.h index 56e1a0f..03531df 100644 --- a/php_http_querystring_object.h +++ b/php_http_querystring_object.h @@ -34,8 +34,8 @@ extern PHP_MINIT_FUNCTION(http_querystring_object); #define http_querystring_object_new(ce) _http_querystring_object_new((ce) TSRMLS_CC) extern zend_object_value _http_querystring_object_new(zend_class_entry *ce TSRMLS_DC); -#define http_querystring_object_new_ex(ce, ptr) _http_querystring_object_new_ex((ce), (ptr) TSRMLS_CC) -extern zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, http_querystring_object **ptr TSRMLS_DC); +#define http_querystring_object_new_ex(ce, n, ptr) _http_querystring_object_new_ex((ce), (n), (ptr) TSRMLS_CC) +extern zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, void *nothing, http_querystring_object **ptr TSRMLS_DC); #define http_querystring_object_free(o) _http_querystring_object_free((o) TSRMLS_CC) extern void _http_querystring_object_free(zend_object *object TSRMLS_DC); @@ -54,6 +54,7 @@ PHP_METHOD(HttpQueryString, getObject); #ifdef HTTP_HAVE_ICONV PHP_METHOD(HttpQueryString, xlate); #endif +PHP_METHOD(HttpQueryString, factory); #ifndef WONKY PHP_METHOD(HttpQueryString, singleton); #endif diff --git a/php_http_request_object.h b/php_http_request_object.h index 884f8b4..6e2eaaa 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -97,6 +97,7 @@ PHP_METHOD(HttpRequest, getRequestMessage); PHP_METHOD(HttpRequest, getRawRequestMessage); PHP_METHOD(HttpRequest, getHistory); PHP_METHOD(HttpRequest, clearHistory); +PHP_METHOD(HttpRequest, factory); #endif #endif diff --git a/php_http_requestdatashare_object.h b/php_http_requestdatashare_object.h index b6f43bf..304b2da 100644 --- a/php_http_requestdatashare_object.h +++ b/php_http_requestdatashare_object.h @@ -38,6 +38,7 @@ PHP_METHOD(HttpRequestDataShare, count); PHP_METHOD(HttpRequestDataShare, attach); PHP_METHOD(HttpRequestDataShare, detach); PHP_METHOD(HttpRequestDataShare, reset); +PHP_METHOD(HttpRequestDataShare, factory); #ifndef WONKY PHP_METHOD(HttpRequestDataShare, singleton); #endif -- 2.30.2