]> granicus.if.org Git - php/commitdiff
Migrate curl to new parameters API
authorSara Golemon <pollita@php.net>
Wed, 28 Dec 2016 16:38:01 +0000 (08:38 -0800)
committerSara Golemon <pollita@php.net>
Wed, 28 Dec 2016 17:06:41 +0000 (09:06 -0800)
Plus a handful of char*->zend_string* conversions

ext/curl/curl_file.c
ext/curl/interface.c
ext/curl/multi.c
ext/curl/share.c

index 10a5ae55e721c4008970b5183dab0d3c38251122..888b88413843cd5674107c71bd1d2643607edcc1 100644 (file)
@@ -31,24 +31,24 @@ PHP_CURL_API zend_class_entry *curl_CURLFile_class;
 
 static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
 {
-       char *fname = NULL, *mime = NULL, *postname = NULL;
-       size_t fname_len, mime_len, postname_len;
+       zend_string *fname, *mime = NULL, *postname = NULL;
        zval *cf = return_value;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,3)
+               Z_PARAM_STR(fname)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_STR(mime)
+               Z_PARAM_STR(postname)
+       ZEND_PARSE_PARAMETERS_END();
 
-       if (fname) {
-               zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname);
-       }
+       zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, ZSTR_VAL(fname));
 
        if (mime) {
-               zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime);
+               zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, ZSTR_VAL(mime));
        }
 
        if (postname) {
-               zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname);
+               zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, ZSTR_VAL(postname));
        }
 }
 
@@ -84,13 +84,13 @@ static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION
 
 static void curlfile_set_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
 {
-       char *arg = NULL;
-       size_t arg_len;
+       zend_string *arg;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) {
-               return;
-       }
-       zend_update_property_string(curl_CURLFile_class, getThis(), name, name_len, arg);
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_STR(arg)
+       ZEND_PARSE_PARAMETERS_END();
+
+       zend_update_property_string(curl_CURLFile_class, getThis(), name, name_len, ZSTR_VAL(arg));
 }
 
 /* {{{ proto string CURLFile::getFilename()
index 4595f64064b670d84d425f6e3c46b3f36c87c836..e5d6d432a2e6778f7c9cd3887f3920172365485d 100644 (file)
@@ -1964,12 +1964,12 @@ PHP_FUNCTION(curl_init)
 {
        php_curl *ch;
        CURL     *cp;
-       char     *url = NULL;
-       size_t            url_len = 0;
+       zend_string *url = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &url, &url_len) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(0,1)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_STR(url)
+       ZEND_PARSE_PARAMETERS_END();
 
        cp = curl_easy_init();
        if (!cp) {
@@ -1988,7 +1988,7 @@ PHP_FUNCTION(curl_init)
        _php_curl_set_default_options(ch);
 
        if (url) {
-               if (php_curl_option_url(ch, url, url_len) == FAILURE) {
+               if (php_curl_option_url(ch, ZSTR_VAL(url), ZSTR_LEN(url)) == FAILURE) {
                        _php_curl_close_ex(ch);
                        RETURN_FALSE;
                }
@@ -2080,9 +2080,9 @@ PHP_FUNCTION(curl_copy_handle)
        zval            *zid;
        php_curl        *ch, *dupch;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(zid)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
                RETURN_FALSE;
@@ -3311,9 +3311,9 @@ PHP_FUNCTION(curl_errno)
        zval            *zid;
        php_curl        *ch;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zid) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(zid)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
                RETURN_FALSE;
@@ -3534,24 +3534,25 @@ PHP_FUNCTION(curl_reset)
    URL encodes the given string */
 PHP_FUNCTION(curl_escape)
 {
-       char       *str = NULL, *res = NULL;
-       size_t     str_len = 0;
-       zval       *zid;
-       php_curl   *ch;
+       zend_string *str;
+       char        *res;
+       zval        *zid;
+       php_curl    *ch;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &zid, &str, &str_len) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(2,2)
+               Z_PARAM_RESOURCE(zid)
+               Z_PARAM_STR(str)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
                RETURN_FALSE;
        }
 
-       if (ZEND_SIZE_T_INT_OVFL(str_len)) {
+       if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
                RETURN_FALSE;
        }
 
-       if ((res = curl_easy_escape(ch->cp, str, str_len))) {
+       if ((res = curl_easy_escape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str)))) {
                RETVAL_STRING(res);
                curl_free(res);
        } else {
@@ -3564,25 +3565,26 @@ PHP_FUNCTION(curl_escape)
    URL decodes the given string */
 PHP_FUNCTION(curl_unescape)
 {
-       char       *str = NULL, *out = NULL;
-       size_t     str_len = 0;
-       int        out_len;
-       zval       *zid;
-       php_curl   *ch;
+       char        *out = NULL;
+       int          out_len;
+       zval        *zid;
+       zend_string *str;
+       php_curl    *ch;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &zid, &str, &str_len) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(2,2)
+               Z_PARAM_RESOURCE(zid)
+               Z_PARAM_STR(str)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
                RETURN_FALSE;
        }
 
-       if (ZEND_SIZE_T_INT_OVFL(str_len)) {
+       if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(str))) {
                RETURN_FALSE;
        }
 
-       if ((out = curl_easy_unescape(ch->cp, str, str_len, &out_len))) {
+       if ((out = curl_easy_unescape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str), &out_len))) {
                RETVAL_STRINGL(out, out_len);
                curl_free(out);
        } else {
@@ -3601,9 +3603,10 @@ PHP_FUNCTION(curl_pause)
        zval       *zid;
        php_curl   *ch;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &zid, &bitmask) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(2,2)
+               Z_PARAM_RESOURCE(zid)
+               Z_PARAM_LONG(bitmask)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) {
                RETURN_FALSE;
index c802edf46ddb84f409707de26fc491c3fe1ac335..43202a980b5a53071f5d52c4062dfc7dcf52e3df 100644 (file)
@@ -82,9 +82,10 @@ PHP_FUNCTION(curl_multi_add_handle)
        zval tmp_val;
        CURLMcode error = CURLM_OK;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &z_mh, &z_ch) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(2,2)
+               Z_PARAM_RESOURCE(z_mh)
+               Z_PARAM_RESOURCE(z_ch)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -169,9 +170,10 @@ PHP_FUNCTION(curl_multi_remove_handle)
        php_curl  *ch;
        CURLMcode error = CURLM_OK;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &z_mh, &z_ch) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(2,2)
+               Z_PARAM_RESOURCE(z_mh)
+               Z_PARAM_RESOURCE(z_ch)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -214,9 +216,11 @@ PHP_FUNCTION(curl_multi_select)
        struct timeval  to;
        CURLMcode error = CURLM_OK;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|d", &z_mh, &timeout) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,2)
+               Z_PARAM_RESOURCE(z_mh)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_DOUBLE(timeout)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -248,9 +252,10 @@ PHP_FUNCTION(curl_multi_exec)
        int        still_running;
        CURLMcode error = CURLM_OK;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/", &z_mh, &z_still_running) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(2, 2)
+               Z_PARAM_RESOURCE(z_mh)
+               Z_PARAM_ZVAL_DEREF_EX(z_still_running, 0, 1)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -289,9 +294,9 @@ PHP_FUNCTION(curl_multi_getcontent)
        zval     *z_ch;
        php_curl *ch;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_ch) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(z_ch)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((ch = (php_curl *)zend_fetch_resource(Z_RES_P(z_ch), le_curl_name, le_curl)) == NULL) {
                RETURN_FALSE;
@@ -319,9 +324,11 @@ PHP_FUNCTION(curl_multi_info_read)
        int        queued_msgs;
        zval      *zmsgs_in_queue = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|z/", &z_mh, &zmsgs_in_queue) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1, 2)
+               Z_PARAM_RESOURCE(z_mh)
+               Z_PARAM_OPTIONAL
+               Z_PARAM_ZVAL_DEREF_EX(zmsgs_in_queue, 0, 1)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -369,9 +376,9 @@ PHP_FUNCTION(curl_multi_close)
        zval      *z_mh;
        php_curlm *mh;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_mh) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(z_mh)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -420,9 +427,9 @@ PHP_FUNCTION(curl_multi_errno)
        zval        *z_mh;
        php_curlm   *mh;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_mh) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(z_mh)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
@@ -440,9 +447,9 @@ PHP_FUNCTION(curl_multi_strerror)
        zend_long code;
        const char *str;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_LONG(code)
+       ZEND_PARSE_PARAMETERS_END();
 
        str = curl_multi_strerror(code);
        if (str) {
@@ -598,9 +605,11 @@ PHP_FUNCTION(curl_multi_setopt)
        zend_long        options;
        php_curlm *mh;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &z_mh, &options, &zvalue) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(3,3)
+               Z_PARAM_RESOURCE(z_mh)
+               Z_PARAM_LONG(options)
+               Z_PARAM_ZVAL_DEREF(zvalue)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((mh = (php_curlm *)zend_fetch_resource(Z_RES_P(z_mh), le_curl_multi_handle_name, le_curl_multi_handle)) == NULL) {
                RETURN_FALSE;
index 983cc2750e23feb4bf046eb4698772a5612bbe6a..88a1f4e40e783f5a0bc0204876f64285ede0eefb 100644 (file)
@@ -59,9 +59,9 @@ PHP_FUNCTION(curl_share_close)
        zval *z_sh;
        php_curlsh *sh;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(z_sh)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
                RETURN_FALSE;
@@ -104,9 +104,11 @@ PHP_FUNCTION(curl_share_setopt)
        zend_long        options;
        php_curlsh *sh;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &zid, &options, &zvalue) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(3,3)
+               Z_PARAM_RESOURCE(zid)
+               Z_PARAM_LONG(options)
+               Z_PARAM_ZVAL_DEREF(zvalue)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(zid), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
                RETURN_FALSE;
@@ -138,9 +140,9 @@ PHP_FUNCTION(curl_share_errno)
        zval        *z_sh;
        php_curlsh  *sh;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &z_sh) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_RESOURCE(z_sh)
+       ZEND_PARSE_PARAMETERS_END();
 
        if ((sh = (php_curlsh *)zend_fetch_resource(Z_RES_P(z_sh), le_curl_share_handle_name, le_curl_share_handle)) == NULL) {
                RETURN_FALSE;
@@ -159,9 +161,9 @@ PHP_FUNCTION(curl_share_strerror)
        zend_long code;
        const char *str;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &code) == FAILURE) {
-               return;
-       }
+       ZEND_PARSE_PARAMETERS_START(1,1)
+               Z_PARAM_LONG(code)
+       ZEND_PARSE_PARAMETERS_END();
 
        str = curl_share_strerror(code);
        if (str) {