- fix possible mem-leak in http_absolute_uri()
authorMichael Wallner <mike@php.net>
Tue, 26 Jul 2005 16:44:27 +0000 (16:44 +0000)
committerMichael Wallner <mike@php.net>
Tue, 26 Jul 2005 16:44:27 +0000 (16:44 +0000)
- make url and request method configurable through HttpRequest::setOptions()

http_request_object.c
http_url_api.c

index bef6e7f3ac2ce4a072e25fe303fc9c479a39bade..73b0319b00cd3b914bb72c651e2af658afe5d84a 100644 (file)
@@ -602,7 +602,7 @@ PHP_METHOD(HttpRequest, setOptions)
 
        old_opts = GET_PROP(obj, options);
 
-       /* headers and cookies need extra attention -- thus cannot use array_merge() directly */
+       /* some options need extra attention -- thus cannot use array_merge() directly */
        FOREACH_KEYVAL(opts, key, idx, opt) {
                if (key) {
                        if (!strcmp(key, "headers")) {
@@ -615,6 +615,16 @@ PHP_METHOD(HttpRequest, setOptions)
                                if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "cookies", sizeof("cookies"), (void **) &cookies)) {
                                        array_merge(*opt, *cookies);
                                }
+                       } else if ((!strcasecmp(key, "url")) || (!strcasecmp(key, "uri"))) {
+                               if (Z_TYPE_PP(opt) != IS_STRING) {
+                                       convert_to_string_ex(opt);
+                               }
+                               UPD_PROP(obj, string, url, Z_STRVAL_PP(opt));
+                       } else if (!strcmp(key, "method")) {
+                               if (Z_TYPE_PP(opt) != IS_LONG) {
+                                       convert_to_long_ex(opt);
+                               }
+                               UPD_PROP(obj, long, method, Z_LVAL_PP(opt));
                        } else {
                                if (!strcmp(key, "ondebug")) {
                                        SET_PROP(obj, dbg_user_cb, *opt);
index 64bc6bd08481a2f962ae9e96135e260bbe0394ad..d3f32e7aff687074b6c81e3d79dfe84e1b5be30a 100644 (file)
@@ -53,7 +53,7 @@ PHP_HTTP_API char *_http_absolute_url_ex(
        php_url *purl = NULL, furl;
        size_t full_len = 0;
        zval *zhost = NULL;
-       char *scheme = NULL, *uri, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1);
+       char *scheme = NULL, *uri, *URL;
 
        if ((!url || !url_len) && (
                        (!(url = SG(request_info).request_uri)) ||
@@ -62,6 +62,7 @@ PHP_HTTP_API char *_http_absolute_url_ex(
                return NULL;
        }
 
+       URL = ecalloc(1, HTTP_URI_MAXLEN + 1);
        uri = estrndup(url, url_len);
        if (!(purl = php_url_parse(uri))) {
                http_error_ex(E_WARNING, HTTP_E_PARSE, "Could not parse supplied URL: %s", url);