Lines Matching refs:ch

92 static void _php_curl_close_ex(php_curl *ch);
108 static int php_curl_option_str(php_curl *ch, zend_long option, const char *str, const size_t len, z… in php_curl_option_str() argument
124 error = curl_easy_setopt(ch->cp, option, copystr); in php_curl_option_str()
125 zend_llist_add_element(&ch->to_free->str, &copystr); in php_curl_option_str()
128 error = curl_easy_setopt(ch->cp, option, str); in php_curl_option_str()
132 SAVE_CURL_ERROR(ch, error); in php_curl_option_str()
137 static int php_curl_option_url(php_curl *ch, const char *url, const size_t len) /* {{{ */ in php_curl_option_url() argument
142 curl_easy_setopt(ch->cp, CURLOPT_PROTOCOLS, CURLPROTO_ALL & ~CURLPROTO_FILE); in php_curl_option_url()
167 return php_curl_option_str(ch, CURLOPT_URL, _tmp, len + 1, 0); in php_curl_option_url()
171 return php_curl_option_str(ch, CURLOPT_URL, url, len, 0); in php_curl_option_url()
175 void _php_curl_verify_handlers(php_curl *ch, int reporterror) /* {{{ */ in _php_curl_verify_handlers() argument
179 ZEND_ASSERT(ch && ch->handlers); in _php_curl_verify_handlers()
181 if (!Z_ISUNDEF(ch->handlers->std_err)) { in _php_curl_verify_handlers()
182 …stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(),… in _php_curl_verify_handlers()
187 zval_ptr_dtor(&ch->handlers->std_err); in _php_curl_verify_handlers()
188 ZVAL_UNDEF(&ch->handlers->std_err); in _php_curl_verify_handlers()
190 curl_easy_setopt(ch->cp, CURLOPT_STDERR, stderr); in _php_curl_verify_handlers()
193 if (ch->handlers->read && !Z_ISUNDEF(ch->handlers->read->stream)) { in _php_curl_verify_handlers()
194 …stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->read->stream, NULL, php_file_le_stre… in _php_curl_verify_handlers()
199 zval_ptr_dtor(&ch->handlers->read->stream); in _php_curl_verify_handlers()
200 ZVAL_UNDEF(&ch->handlers->read->stream); in _php_curl_verify_handlers()
201 ch->handlers->read->res = NULL; in _php_curl_verify_handlers()
202 ch->handlers->read->fp = 0; in _php_curl_verify_handlers()
204 curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); in _php_curl_verify_handlers()
207 if (ch->handlers->write_header && !Z_ISUNDEF(ch->handlers->write_header->stream)) { in _php_curl_verify_handlers()
208 …stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->write_header->stream, NULL, php_file… in _php_curl_verify_handlers()
213 zval_ptr_dtor(&ch->handlers->write_header->stream); in _php_curl_verify_handlers()
214 ZVAL_UNDEF(&ch->handlers->write_header->stream); in _php_curl_verify_handlers()
215 ch->handlers->write_header->fp = 0; in _php_curl_verify_handlers()
217 ch->handlers->write_header->method = PHP_CURL_IGNORE; in _php_curl_verify_handlers()
218 curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); in _php_curl_verify_handlers()
221 if (ch->handlers->write && !Z_ISUNDEF(ch->handlers->write->stream)) { in _php_curl_verify_handlers()
222 …stream = (php_stream *)zend_fetch_resource2_ex(&ch->handlers->write->stream, NULL, php_file_le_str… in _php_curl_verify_handlers()
227 zval_ptr_dtor(&ch->handlers->write->stream); in _php_curl_verify_handlers()
228 ZVAL_UNDEF(&ch->handlers->write->stream); in _php_curl_verify_handlers()
229 ch->handlers->write->fp = 0; in _php_curl_verify_handlers()
231 ch->handlers->write->method = PHP_CURL_STDOUT; in _php_curl_verify_handlers()
232 curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); in _php_curl_verify_handlers()
249 ZEND_ARG_INFO(0, ch)
253 ZEND_ARG_INFO(0, ch)
259 ZEND_ARG_INFO(0, ch)
264 ZEND_ARG_INFO(0, ch)
268 ZEND_ARG_INFO(0, ch)
273 ZEND_ARG_INFO(0, ch)
277 ZEND_ARG_INFO(0, ch)
281 ZEND_ARG_INFO(0, ch)
285 ZEND_ARG_INFO(0, ch)
289 ZEND_ARG_INFO(0, ch)
294 ZEND_ARG_INFO(0, ch)
309 ZEND_ARG_INFO(0, ch)
314 ZEND_ARG_INFO(0, ch)
328 ZEND_ARG_INFO(0, ch)
375 ZEND_ARG_INFO(0, ch)
1473 php_curl *ch = (php_curl *) ctx; in curl_write() local
1474 php_curl_write *t = ch->handlers->write; in curl_write()
1499 GC_ADDREF(ch->res); in curl_write()
1500 ZVAL_RES(&argv[0], ch->res); in curl_write()
1511 ch->in_callback = 1; in curl_write()
1513 ch->in_callback = 0; in curl_write()
1518 _php_curl_verify_handlers(ch, 1); in curl_write()
1537 php_curl *ch = (php_curl *) ctx; in curl_fnmatch() local
1538 php_curl_fnmatch *t = ch->handlers->fnmatch; in curl_fnmatch()
1547 GC_ADDREF(ch->res); in curl_fnmatch()
1548 ZVAL_RES(&argv[0], ch->res); in curl_fnmatch()
1560 ch->in_callback = 1; in curl_fnmatch()
1562 ch->in_callback = 0; in curl_fnmatch()
1566 _php_curl_verify_handlers(ch, 1); in curl_fnmatch()
1584 php_curl *ch = (php_curl *)clientp; in curl_progress() local
1585 php_curl_progress *t = ch->handlers->progress; in curl_progress()
1600 GC_ADDREF(ch->res); in curl_progress()
1601 ZVAL_RES(&argv[0], ch->res); in curl_progress()
1615 ch->in_callback = 1; in curl_progress()
1617 ch->in_callback = 0; in curl_progress()
1621 _php_curl_verify_handlers(ch, 1); in curl_progress()
1638 php_curl *ch = (php_curl *)ctx; in curl_read() local
1639 php_curl_read *t = ch->handlers->read; in curl_read()
1654 GC_ADDREF(ch->res); in curl_read()
1655 ZVAL_RES(&argv[0], ch->res); in curl_read()
1672 ch->in_callback = 1; in curl_read()
1674 ch->in_callback = 0; in curl_read()
1679 _php_curl_verify_handlers(ch, 1); in curl_read()
1701 php_curl *ch = (php_curl *) ctx; in curl_write_header() local
1702 php_curl_write *t = ch->handlers->write_header; in curl_write_header()
1709 if (ch->handlers->write->method == PHP_CURL_RETURN && length > 0) { in curl_write_header()
1710 smart_str_appendl(&ch->handlers->write->buf, data, (int) length); in curl_write_header()
1723 GC_ADDREF(ch->res); in curl_write_header()
1724 ZVAL_RES(&argv[0], ch->res); in curl_write_header()
1735 ch->in_callback = 1; in curl_write_header()
1737 ch->in_callback = 0; in curl_write_header()
1742 _php_curl_verify_handlers(ch, 1); in curl_write_header()
1763 php_curl *ch = (php_curl *)ctx; in curl_debug() local
1766 if (ch->header.str) { in curl_debug()
1767 zend_string_release_ex(ch->header.str, 0); in curl_debug()
1769 ch->header.str = zend_string_init(buf, buf_len, 0); in curl_debug()
1893 php_curl *ch = ecalloc(1, sizeof(php_curl)); in alloc_curl_handle() local
1894 ch->to_free = ecalloc(1, sizeof(struct _php_curl_free)); in alloc_curl_handle()
1895 ch->handlers = ecalloc(1, sizeof(php_curl_handlers)); in alloc_curl_handle()
1896 ch->handlers->write = ecalloc(1, sizeof(php_curl_write)); in alloc_curl_handle()
1897 ch->handlers->write_header = ecalloc(1, sizeof(php_curl_write)); in alloc_curl_handle()
1898 ch->handlers->read = ecalloc(1, sizeof(php_curl_read)); in alloc_curl_handle()
1899 ch->handlers->progress = NULL; in alloc_curl_handle()
1901 ch->handlers->fnmatch = NULL; in alloc_curl_handle()
1903 ch->clone = emalloc(sizeof(uint32_t)); in alloc_curl_handle()
1904 *ch->clone = 1; in alloc_curl_handle()
1906 memset(&ch->err, 0, sizeof(struct _php_curl_error)); in alloc_curl_handle()
1908 …zend_llist_init(&ch->to_free->str, sizeof(char *), (llist_dtor_func_t)curl_free_string,… in alloc_curl_handle()
1909 …zend_llist_init(&ch->to_free->post, sizeof(struct HttpPost *), (llist_dtor_func_t)curl_free_post,… in alloc_curl_handle()
1910 …zend_llist_init(&ch->to_free->stream, sizeof(struct mime_data_cb_arg *), (llist_dtor_func_t)curl_f… in alloc_curl_handle()
1912 ch->to_free->slist = emalloc(sizeof(HashTable)); in alloc_curl_handle()
1913 zend_hash_init(ch->to_free->slist, 4, NULL, curl_free_slist, 0); in alloc_curl_handle()
1915 ZVAL_UNDEF(&ch->postfields); in alloc_curl_handle()
1917 return ch; in alloc_curl_handle()
1959 static void _php_curl_set_default_options(php_curl *ch) in _php_curl_set_default_options() argument
1963 curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1); in _php_curl_set_default_options()
1964 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); in _php_curl_set_default_options()
1965 curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); in _php_curl_set_default_options()
1966 curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write); in _php_curl_set_default_options()
1967 curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); in _php_curl_set_default_options()
1968 curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read); in _php_curl_set_default_options()
1969 curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); in _php_curl_set_default_options()
1970 curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_header); in _php_curl_set_default_options()
1971 curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); in _php_curl_set_default_options()
1973 curl_easy_setopt(ch->cp, CURLOPT_DNS_USE_GLOBAL_CACHE, 1); in _php_curl_set_default_options()
1975 curl_easy_setopt(ch->cp, CURLOPT_DNS_CACHE_TIMEOUT, 120); in _php_curl_set_default_options()
1976 curl_easy_setopt(ch->cp, CURLOPT_MAXREDIRS, 20); /* prevent infinite redirects */ in _php_curl_set_default_options()
1983 curl_easy_setopt(ch->cp, CURLOPT_CAINFO, cainfo); in _php_curl_set_default_options()
1987 curl_easy_setopt(ch->cp, CURLOPT_NOSIGNAL, 1); in _php_curl_set_default_options()
1996 php_curl *ch; in PHP_FUNCTION() local
2011 ch = alloc_curl_handle(); in PHP_FUNCTION()
2013 ch->cp = cp; in PHP_FUNCTION()
2015 ch->handlers->write->method = PHP_CURL_STDOUT; in PHP_FUNCTION()
2016 ch->handlers->read->method = PHP_CURL_DIRECT; in PHP_FUNCTION()
2017 ch->handlers->write_header->method = PHP_CURL_IGNORE; in PHP_FUNCTION()
2019 _php_curl_set_default_options(ch); in PHP_FUNCTION()
2022 if (php_curl_option_url(ch, ZSTR_VAL(url), ZSTR_LEN(url)) == FAILURE) { in PHP_FUNCTION()
2023 _php_curl_close_ex(ch); in PHP_FUNCTION()
2028 ZVAL_RES(return_value, zend_register_resource(ch, le_curl)); in PHP_FUNCTION()
2029 ch->res = Z_RES_P(return_value); in PHP_FUNCTION()
2033 void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source) in _php_setup_easy_copy_handlers() argument
2038 ch->handlers->write->stream = source->handlers->write->stream; in _php_setup_easy_copy_handlers()
2039 ch->handlers->write->method = source->handlers->write->method; in _php_setup_easy_copy_handlers()
2043 ch->handlers->read->stream = source->handlers->read->stream; in _php_setup_easy_copy_handlers()
2044 ch->handlers->read->method = source->handlers->read->method; in _php_setup_easy_copy_handlers()
2045 ch->handlers->write_header->method = source->handlers->write_header->method; in _php_setup_easy_copy_handlers()
2049 ch->handlers->write_header->stream = source->handlers->write_header->stream; in _php_setup_easy_copy_handlers()
2051 ch->handlers->write->fp = source->handlers->write->fp; in _php_setup_easy_copy_handlers()
2052 ch->handlers->write_header->fp = source->handlers->write_header->fp; in _php_setup_easy_copy_handlers()
2053 ch->handlers->read->fp = source->handlers->read->fp; in _php_setup_easy_copy_handlers()
2054 ch->handlers->read->res = source->handlers->read->res; in _php_setup_easy_copy_handlers()
2057 ZVAL_COPY(&ch->handlers->passwd, &source->handlers->passwd); in _php_setup_easy_copy_handlers()
2058 curl_easy_setopt(source->cp, CURLOPT_PASSWDDATA, (void *) ch); in _php_setup_easy_copy_handlers()
2062 ZVAL_COPY(&ch->handlers->write->func_name, &source->handlers->write->func_name); in _php_setup_easy_copy_handlers()
2065 ZVAL_COPY(&ch->handlers->read->func_name, &source->handlers->read->func_name); in _php_setup_easy_copy_handlers()
2068 ZVAL_COPY(&ch->handlers->write_header->func_name, &source->handlers->write_header->func_name); in _php_setup_easy_copy_handlers()
2071 curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); in _php_setup_easy_copy_handlers()
2072 curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); in _php_setup_easy_copy_handlers()
2073 curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); in _php_setup_easy_copy_handlers()
2074 curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); in _php_setup_easy_copy_handlers()
2075 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *) ch); in _php_setup_easy_copy_handlers()
2078 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress)); in _php_setup_easy_copy_handlers()
2080 ZVAL_COPY(&ch->handlers->progress->func_name, &source->handlers->progress->func_name); in _php_setup_easy_copy_handlers()
2082 ch->handlers->progress->method = source->handlers->progress->method; in _php_setup_easy_copy_handlers()
2083 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, (void *) ch); in _php_setup_easy_copy_handlers()
2088 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch)); in _php_setup_easy_copy_handlers()
2090 ZVAL_COPY(&ch->handlers->fnmatch->func_name, &source->handlers->fnmatch->func_name); in _php_setup_easy_copy_handlers()
2092 ch->handlers->fnmatch->method = source->handlers->fnmatch->method; in _php_setup_easy_copy_handlers()
2093 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, (void *) ch); in _php_setup_easy_copy_handlers()
2097 efree(ch->to_free->slist); in _php_setup_easy_copy_handlers()
2098 efree(ch->to_free); in _php_setup_easy_copy_handlers()
2099 ch->to_free = source->to_free; in _php_setup_easy_copy_handlers()
2100 efree(ch->clone); in _php_setup_easy_copy_handlers()
2101 ch->clone = source->clone; in _php_setup_easy_copy_handlers()
2153 static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields) /* {{{ */ in build_mime_structure_from_hash() argument
2178 mime = curl_mime_init(ch->cp); in build_mime_structure_from_hash()
2231 zval_ptr_dtor(&ch->postfields); in build_mime_structure_from_hash()
2232 ZVAL_COPY(&ch->postfields, zpostfields); in build_mime_structure_from_hash()
2257 zend_llist_add_element(&ch->to_free->stream, &cb_arg); in build_mime_structure_from_hash()
2310 SAVE_CURL_ERROR(ch, error); in build_mime_structure_from_hash()
2315 if ((*ch->clone) == 1) { in build_mime_structure_from_hash()
2316 zend_llist_clean(&ch->to_free->post); in build_mime_structure_from_hash()
2319 zend_llist_add_element(&ch->to_free->post, &mime); in build_mime_structure_from_hash()
2320 error = curl_easy_setopt(ch->cp, CURLOPT_MIMEPOST, mime); in build_mime_structure_from_hash()
2322 zend_llist_add_element(&ch->to_free->post, &first); in build_mime_structure_from_hash()
2323 error = curl_easy_setopt(ch->cp, CURLOPT_HTTPPOST, first); in build_mime_structure_from_hash()
2326 SAVE_CURL_ERROR(ch, error); in build_mime_structure_from_hash()
2337 php_curl *ch, *dupch; in PHP_FUNCTION() local
2346 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
2350 cp = curl_easy_duphandle(ch->cp); in PHP_FUNCTION()
2359 _php_setup_easy_copy_handlers(dupch, ch); in PHP_FUNCTION()
2362 postfields = &ch->postfields; in PHP_FUNCTION()
2377 static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue) /* {{{ */ in _php_curl_setopt() argument
2391 error = curl_easy_setopt(ch->cp, option, 2); in _php_curl_setopt()
2590 error = curl_easy_setopt(ch->cp, option, lval); in _php_curl_setopt()
2695 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0); in _php_curl_setopt()
2724 error = curl_easy_setopt(ch->cp, option, NULL); in _php_curl_setopt()
2728 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0); in _php_curl_setopt()
2740 int ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 1); in _php_curl_setopt()
2750 int ret = php_curl_option_url(ch, ZSTR_VAL(str), ZSTR_LEN(str)); in _php_curl_setopt()
2782 if (!Z_ISUNDEF(ch->handlers->write->stream)) { in _php_curl_setopt()
2783 zval_ptr_dtor(&ch->handlers->write->stream); in _php_curl_setopt()
2784 ZVAL_UNDEF(&ch->handlers->write->stream); in _php_curl_setopt()
2786 ch->handlers->write->fp = NULL; in _php_curl_setopt()
2787 ch->handlers->write->method = PHP_CURL_STDOUT; in _php_curl_setopt()
2789 zval_ptr_dtor(&ch->handlers->write->stream); in _php_curl_setopt()
2790 ch->handlers->write->fp = fp; in _php_curl_setopt()
2791 ch->handlers->write->method = PHP_CURL_FILE; in _php_curl_setopt()
2792 ZVAL_COPY(&ch->handlers->write->stream, zvalue); in _php_curl_setopt()
2800 if (!Z_ISUNDEF(ch->handlers->write_header->stream)) { in _php_curl_setopt()
2801 zval_ptr_dtor(&ch->handlers->write_header->stream); in _php_curl_setopt()
2802 ZVAL_UNDEF(&ch->handlers->write_header->stream); in _php_curl_setopt()
2804 ch->handlers->write_header->fp = NULL; in _php_curl_setopt()
2805 ch->handlers->write_header->method = PHP_CURL_IGNORE; in _php_curl_setopt()
2807 zval_ptr_dtor(&ch->handlers->write_header->stream); in _php_curl_setopt()
2808 ch->handlers->write_header->fp = fp; in _php_curl_setopt()
2809 ch->handlers->write_header->method = PHP_CURL_FILE; in _php_curl_setopt()
2810 ZVAL_COPY(&ch->handlers->write_header->stream, zvalue); in _php_curl_setopt()
2818 if (!Z_ISUNDEF(ch->handlers->read->stream)) { in _php_curl_setopt()
2819 zval_ptr_dtor(&ch->handlers->read->stream); in _php_curl_setopt()
2820 ZVAL_UNDEF(&ch->handlers->read->stream); in _php_curl_setopt()
2822 ch->handlers->read->fp = NULL; in _php_curl_setopt()
2823 ch->handlers->read->res = NULL; in _php_curl_setopt()
2825 zval_ptr_dtor(&ch->handlers->read->stream); in _php_curl_setopt()
2826 ch->handlers->read->fp = fp; in _php_curl_setopt()
2827 ch->handlers->read->res = Z_RES_P(zvalue); in _php_curl_setopt()
2828 ZVAL_COPY(&ch->handlers->read->stream, zvalue); in _php_curl_setopt()
2833 if (!Z_ISUNDEF(ch->handlers->std_err)) { in _php_curl_setopt()
2834 zval_ptr_dtor(&ch->handlers->std_err); in _php_curl_setopt()
2835 ZVAL_UNDEF(&ch->handlers->std_err); in _php_curl_setopt()
2838 zval_ptr_dtor(&ch->handlers->std_err); in _php_curl_setopt()
2839 ZVAL_COPY(&ch->handlers->std_err, zvalue); in _php_curl_setopt()
2846 error = curl_easy_setopt(ch->cp, option, fp); in _php_curl_setopt()
2936 if ((*ch->clone) == 1) { in _php_curl_setopt()
2937 zend_hash_index_update_ptr(ch->to_free->slist, option, slist); in _php_curl_setopt()
2939 zend_hash_next_index_insert_ptr(ch->to_free->slist, slist); in _php_curl_setopt()
2943 error = curl_easy_setopt(ch->cp, option, slist); in _php_curl_setopt()
2960 error = curl_easy_setopt(ch->cp, option, lval); in _php_curl_setopt()
2964 if (!Z_ISUNDEF(ch->handlers->write_header->func_name)) { in _php_curl_setopt()
2965 zval_ptr_dtor(&ch->handlers->write_header->func_name); in _php_curl_setopt()
2966 ch->handlers->write_header->fci_cache = empty_fcall_info_cache; in _php_curl_setopt()
2968 ZVAL_COPY(&ch->handlers->write_header->func_name, zvalue); in _php_curl_setopt()
2969 ch->handlers->write_header->method = PHP_CURL_USER; in _php_curl_setopt()
2977 curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, ""); in _php_curl_setopt()
2978 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, 0); in _php_curl_setopt()
2980 return build_mime_structure_from_hash(ch, zvalue); in _php_curl_setopt()
2987 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str)); in _php_curl_setopt()
2988 error = curl_easy_setopt(ch->cp, CURLOPT_COPYPOSTFIELDS, ZSTR_VAL(str)); in _php_curl_setopt()
2996 zend_llist_add_element(&ch->to_free->str, &post); in _php_curl_setopt()
2998 curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDS, post); in _php_curl_setopt()
2999 error = curl_easy_setopt(ch->cp, CURLOPT_POSTFIELDSIZE, ZSTR_LEN(str)); in _php_curl_setopt()
3006 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSFUNCTION, curl_progress); in _php_curl_setopt()
3007 curl_easy_setopt(ch->cp, CURLOPT_PROGRESSDATA, ch); in _php_curl_setopt()
3008 if (ch->handlers->progress == NULL) { in _php_curl_setopt()
3009 ch->handlers->progress = ecalloc(1, sizeof(php_curl_progress)); in _php_curl_setopt()
3010 } else if (!Z_ISUNDEF(ch->handlers->progress->func_name)) { in _php_curl_setopt()
3011 zval_ptr_dtor(&ch->handlers->progress->func_name); in _php_curl_setopt()
3012 ch->handlers->progress->fci_cache = empty_fcall_info_cache; in _php_curl_setopt()
3014 ZVAL_COPY(&ch->handlers->progress->func_name, zvalue); in _php_curl_setopt()
3015 ch->handlers->progress->method = PHP_CURL_USER; in _php_curl_setopt()
3019 if (!Z_ISUNDEF(ch->handlers->read->func_name)) { in _php_curl_setopt()
3020 zval_ptr_dtor(&ch->handlers->read->func_name); in _php_curl_setopt()
3021 ch->handlers->read->fci_cache = empty_fcall_info_cache; in _php_curl_setopt()
3023 ZVAL_COPY(&ch->handlers->read->func_name, zvalue); in _php_curl_setopt()
3024 ch->handlers->read->method = PHP_CURL_USER; in _php_curl_setopt()
3029 ch->handlers->write->method = PHP_CURL_RETURN; in _php_curl_setopt()
3031 ch->handlers->write->method = PHP_CURL_STDOUT; in _php_curl_setopt()
3036 if (!Z_ISUNDEF(ch->handlers->write->func_name)) { in _php_curl_setopt()
3037 zval_ptr_dtor(&ch->handlers->write->func_name); in _php_curl_setopt()
3038 ch->handlers->write->fci_cache = empty_fcall_info_cache; in _php_curl_setopt()
3040 ZVAL_COPY(&ch->handlers->write->func_name, zvalue); in _php_curl_setopt()
3041 ch->handlers->write->method = PHP_CURL_USER; in _php_curl_setopt()
3051 error = curl_easy_setopt(ch->cp, option, (curl_off_t)lval); in _php_curl_setopt()
3057 error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, lval & CURL_REDIR_POST_ALL); in _php_curl_setopt()
3090 ret = php_curl_option_str(ch, option, ZSTR_VAL(str), ZSTR_LEN(str), 0); in _php_curl_setopt()
3097 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, curl_debug); in _php_curl_setopt()
3098 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, (void *)ch); in _php_curl_setopt()
3099 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1); in _php_curl_setopt()
3101 curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, NULL); in _php_curl_setopt()
3102 curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, NULL); in _php_curl_setopt()
3103 curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); in _php_curl_setopt()
3111 curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share); in _php_curl_setopt()
3118 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_FUNCTION, curl_fnmatch); in _php_curl_setopt()
3119 curl_easy_setopt(ch->cp, CURLOPT_FNMATCH_DATA, ch); in _php_curl_setopt()
3120 if (ch->handlers->fnmatch == NULL) { in _php_curl_setopt()
3121 ch->handlers->fnmatch = ecalloc(1, sizeof(php_curl_fnmatch)); in _php_curl_setopt()
3122 } else if (!Z_ISUNDEF(ch->handlers->fnmatch->func_name)) { in _php_curl_setopt()
3123 zval_ptr_dtor(&ch->handlers->fnmatch->func_name); in _php_curl_setopt()
3124 ch->handlers->fnmatch->fci_cache = empty_fcall_info_cache; in _php_curl_setopt()
3126 ZVAL_COPY(&ch->handlers->fnmatch->func_name, zvalue); in _php_curl_setopt()
3127 ch->handlers->fnmatch->method = PHP_CURL_USER; in _php_curl_setopt()
3133 SAVE_CURL_ERROR(ch, error); in _php_curl_setopt()
3148 php_curl *ch; in PHP_FUNCTION() local
3156 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3165 if (_php_curl_setopt(ch, options, zvalue) == SUCCESS) { in PHP_FUNCTION()
3178 php_curl *ch; in PHP_FUNCTION() local
3187 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3198 if (_php_curl_setopt(ch, (zend_long) option, entry) == FAILURE) { in PHP_FUNCTION()
3209 void _php_curl_cleanup_handle(php_curl *ch) in _php_curl_cleanup_handle() argument
3211 smart_str_free(&ch->handlers->write->buf); in _php_curl_cleanup_handle()
3212 if (ch->header.str) { in _php_curl_cleanup_handle()
3213 zend_string_release_ex(ch->header.str, 0); in _php_curl_cleanup_handle()
3214 ch->header.str = NULL; in _php_curl_cleanup_handle()
3217 memset(ch->err.str, 0, CURL_ERROR_SIZE + 1); in _php_curl_cleanup_handle()
3218 ch->err.no = 0; in _php_curl_cleanup_handle()
3228 php_curl *ch; in PHP_FUNCTION() local
3234 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3238 _php_curl_verify_handlers(ch, 1); in PHP_FUNCTION()
3240 _php_curl_cleanup_handle(ch); in PHP_FUNCTION()
3242 error = curl_easy_perform(ch->cp); in PHP_FUNCTION()
3243 SAVE_CURL_ERROR(ch, error); in PHP_FUNCTION()
3246 smart_str_free(&ch->handlers->write->buf); in PHP_FUNCTION()
3250 if (!Z_ISUNDEF(ch->handlers->std_err)) { in PHP_FUNCTION()
3252 …stream = (php_stream*)zend_fetch_resource2_ex(&ch->handlers->std_err, NULL, php_file_le_stream(), … in PHP_FUNCTION()
3258 if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.s) { in PHP_FUNCTION()
3259 smart_str_0(&ch->handlers->write->buf); in PHP_FUNCTION()
3260 RETURN_STR_COPY(ch->handlers->write->buf.s); in PHP_FUNCTION()
3264 if (ch->handlers->write->method == PHP_CURL_FILE && ch->handlers->write->fp) { in PHP_FUNCTION()
3265 fflush(ch->handlers->write->fp); in PHP_FUNCTION()
3267 if (ch->handlers->write_header->method == PHP_CURL_FILE && ch->handlers->write_header->fp) { in PHP_FUNCTION()
3268 fflush(ch->handlers->write_header->fp); in PHP_FUNCTION()
3271 if (ch->handlers->write->method == PHP_CURL_RETURN) { in PHP_FUNCTION()
3284 php_curl *ch; in PHP_FUNCTION() local
3293 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3315 if (curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code) == CURLE_OK) { in PHP_FUNCTION()
3318 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code) == CURLE_OK) { in PHP_FUNCTION()
3327 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3330 if (curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3333 if (curl_easy_getinfo(ch->cp, CURLINFO_REQUEST_SIZE, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3336 if (curl_easy_getinfo(ch->cp, CURLINFO_FILETIME, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3339 if (curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3342 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3345 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3348 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3351 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3354 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3357 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_UPLOAD, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3360 if (curl_easy_getinfo(ch->cp, CURLINFO_SIZE_DOWNLOAD, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3363 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_DOWNLOAD, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3366 if (curl_easy_getinfo(ch->cp, CURLINFO_SPEED_UPLOAD, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3369 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3372 if (curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3375 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3378 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) { in PHP_FUNCTION()
3382 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_URL, &s_code) == CURLE_OK) { in PHP_FUNCTION()
3387 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_IP, &s_code) == CURLE_OK) { in PHP_FUNCTION()
3392 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) { in PHP_FUNCTION()
3399 if (curl_easy_getinfo(ch->cp, CURLINFO_PRIMARY_PORT, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3402 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_IP, &s_code) == CURLE_OK) { in PHP_FUNCTION()
3405 if (curl_easy_getinfo(ch->cp, CURLINFO_LOCAL_PORT, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3410 if (curl_easy_getinfo(ch->cp, CURLINFO_HTTP_VERSION, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3415 if (curl_easy_getinfo(ch->cp, CURLINFO_PROTOCOL, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3418 if (curl_easy_getinfo(ch->cp, CURLINFO_PROXY_SSL_VERIFYRESULT, &l_code) == CURLE_OK) { in PHP_FUNCTION()
3421 if (curl_easy_getinfo(ch->cp, CURLINFO_SCHEME, &s_code) == CURLE_OK) { in PHP_FUNCTION()
3426 if (curl_easy_getinfo(ch->cp, CURLINFO_APPCONNECT_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3429 if (curl_easy_getinfo(ch->cp, CURLINFO_CONNECT_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3432 if (curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3435 if (curl_easy_getinfo(ch->cp, CURLINFO_PRETRANSFER_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3438 if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3441 if (curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3444 if (curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME_T, &co) == CURLE_OK) { in PHP_FUNCTION()
3448 if (ch->header.str) { in PHP_FUNCTION()
3449 CAASTR("request_header", ch->header.str); in PHP_FUNCTION()
3454 if (ch->header.str) { in PHP_FUNCTION()
3455 RETURN_STR_COPY(ch->header.str); in PHP_FUNCTION()
3465 if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) { in PHP_FUNCTION()
3480 if (curl_easy_getinfo(ch->cp, option, &s_code) == CURLE_OK && s_code) { in PHP_FUNCTION()
3491 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) { in PHP_FUNCTION()
3502 if (curl_easy_getinfo(ch->cp, option, &code) == CURLE_OK) { in PHP_FUNCTION()
3512 if (curl_easy_getinfo(ch->cp, option, &slist) == CURLE_OK) { in PHP_FUNCTION()
3529 if (curl_easy_getinfo(ch->cp, option, &c_off) == CURLE_OK) { in PHP_FUNCTION()
3551 php_curl *ch; in PHP_FUNCTION() local
3557 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3561 if (ch->err.no) { in PHP_FUNCTION()
3562 ch->err.str[CURL_ERROR_SIZE] = 0; in PHP_FUNCTION()
3563 RETURN_STRING(ch->err.str); in PHP_FUNCTION()
3575 php_curl *ch; in PHP_FUNCTION() local
3581 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3585 RETURN_LONG(ch->err.no); in PHP_FUNCTION()
3594 php_curl *ch; in PHP_FUNCTION() local
3600 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3604 if (ch->in_callback) { in PHP_FUNCTION()
3615 static void _php_curl_close_ex(php_curl *ch) in _php_curl_close_ex() argument
3618 fprintf(stderr, "DTOR CALLED, ch = %x\n", ch); in _php_curl_close_ex()
3621 _php_curl_verify_handlers(ch, 0); in _php_curl_close_ex()
3634 if (ch->cp != NULL) { in _php_curl_close_ex()
3635 curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, curl_write_nothing); in _php_curl_close_ex()
3636 curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write_nothing); in _php_curl_close_ex()
3638 curl_easy_cleanup(ch->cp); in _php_curl_close_ex()
3642 if (--(*ch->clone) == 0) { in _php_curl_close_ex()
3643 zend_llist_clean(&ch->to_free->str); in _php_curl_close_ex()
3644 zend_llist_clean(&ch->to_free->post); in _php_curl_close_ex()
3645 zend_llist_clean(&ch->to_free->stream); in _php_curl_close_ex()
3646 zend_hash_destroy(ch->to_free->slist); in _php_curl_close_ex()
3647 efree(ch->to_free->slist); in _php_curl_close_ex()
3648 efree(ch->to_free); in _php_curl_close_ex()
3649 efree(ch->clone); in _php_curl_close_ex()
3652 smart_str_free(&ch->handlers->write->buf); in _php_curl_close_ex()
3653 zval_ptr_dtor(&ch->handlers->write->func_name); in _php_curl_close_ex()
3654 zval_ptr_dtor(&ch->handlers->read->func_name); in _php_curl_close_ex()
3655 zval_ptr_dtor(&ch->handlers->write_header->func_name); in _php_curl_close_ex()
3656 zval_ptr_dtor(&ch->handlers->std_err); in _php_curl_close_ex()
3657 if (ch->header.str) { in _php_curl_close_ex()
3658 zend_string_release_ex(ch->header.str, 0); in _php_curl_close_ex()
3661 zval_ptr_dtor(&ch->handlers->write_header->stream); in _php_curl_close_ex()
3662 zval_ptr_dtor(&ch->handlers->write->stream); in _php_curl_close_ex()
3663 zval_ptr_dtor(&ch->handlers->read->stream); in _php_curl_close_ex()
3665 efree(ch->handlers->write); in _php_curl_close_ex()
3666 efree(ch->handlers->write_header); in _php_curl_close_ex()
3667 efree(ch->handlers->read); in _php_curl_close_ex()
3669 if (ch->handlers->progress) { in _php_curl_close_ex()
3670 zval_ptr_dtor(&ch->handlers->progress->func_name); in _php_curl_close_ex()
3671 efree(ch->handlers->progress); in _php_curl_close_ex()
3675 if (ch->handlers->fnmatch) { in _php_curl_close_ex()
3676 zval_ptr_dtor(&ch->handlers->fnmatch->func_name); in _php_curl_close_ex()
3677 efree(ch->handlers->fnmatch); in _php_curl_close_ex()
3681 efree(ch->handlers); in _php_curl_close_ex()
3683 zval_ptr_dtor(&ch->postfields); in _php_curl_close_ex()
3685 efree(ch); in _php_curl_close_ex()
3693 php_curl *ch = (php_curl *) rsrc->ptr; in _php_curl_close() local
3694 _php_curl_close_ex(ch); in _php_curl_close()
3720 static void _php_curl_reset_handlers(php_curl *ch) in _php_curl_reset_handlers() argument
3722 if (!Z_ISUNDEF(ch->handlers->write->stream)) { in _php_curl_reset_handlers()
3723 zval_ptr_dtor(&ch->handlers->write->stream); in _php_curl_reset_handlers()
3724 ZVAL_UNDEF(&ch->handlers->write->stream); in _php_curl_reset_handlers()
3726 ch->handlers->write->fp = NULL; in _php_curl_reset_handlers()
3727 ch->handlers->write->method = PHP_CURL_STDOUT; in _php_curl_reset_handlers()
3729 if (!Z_ISUNDEF(ch->handlers->write_header->stream)) { in _php_curl_reset_handlers()
3730 zval_ptr_dtor(&ch->handlers->write_header->stream); in _php_curl_reset_handlers()
3731 ZVAL_UNDEF(&ch->handlers->write_header->stream); in _php_curl_reset_handlers()
3733 ch->handlers->write_header->fp = NULL; in _php_curl_reset_handlers()
3734 ch->handlers->write_header->method = PHP_CURL_IGNORE; in _php_curl_reset_handlers()
3736 if (!Z_ISUNDEF(ch->handlers->read->stream)) { in _php_curl_reset_handlers()
3737 zval_ptr_dtor(&ch->handlers->read->stream); in _php_curl_reset_handlers()
3738 ZVAL_UNDEF(&ch->handlers->read->stream); in _php_curl_reset_handlers()
3740 ch->handlers->read->fp = NULL; in _php_curl_reset_handlers()
3741 ch->handlers->read->res = NULL; in _php_curl_reset_handlers()
3742 ch->handlers->read->method = PHP_CURL_DIRECT; in _php_curl_reset_handlers()
3744 if (!Z_ISUNDEF(ch->handlers->std_err)) { in _php_curl_reset_handlers()
3745 zval_ptr_dtor(&ch->handlers->std_err); in _php_curl_reset_handlers()
3746 ZVAL_UNDEF(&ch->handlers->std_err); in _php_curl_reset_handlers()
3749 if (ch->handlers->progress) { in _php_curl_reset_handlers()
3750 zval_ptr_dtor(&ch->handlers->progress->func_name); in _php_curl_reset_handlers()
3751 efree(ch->handlers->progress); in _php_curl_reset_handlers()
3752 ch->handlers->progress = NULL; in _php_curl_reset_handlers()
3756 if (ch->handlers->fnmatch) { in _php_curl_reset_handlers()
3757 zval_ptr_dtor(&ch->handlers->fnmatch->func_name); in _php_curl_reset_handlers()
3758 efree(ch->handlers->fnmatch); in _php_curl_reset_handlers()
3759 ch->handlers->fnmatch = NULL; in _php_curl_reset_handlers()
3771 php_curl *ch; in PHP_FUNCTION() local
3777 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3781 if (ch->in_callback) { in PHP_FUNCTION()
3786 curl_easy_reset(ch->cp); in PHP_FUNCTION()
3787 _php_curl_reset_handlers(ch); in PHP_FUNCTION()
3788 _php_curl_set_default_options(ch); in PHP_FUNCTION()
3799 php_curl *ch; in PHP_FUNCTION() local
3806 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3814 if ((res = curl_easy_escape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str)))) { in PHP_FUNCTION()
3831 php_curl *ch; in PHP_FUNCTION() local
3838 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3846 if ((out = curl_easy_unescape(ch->cp, ZSTR_VAL(str), ZSTR_LEN(str), &out_len))) { in PHP_FUNCTION()
3862 php_curl *ch; in PHP_FUNCTION() local
3869 if ((ch = (php_curl*)zend_fetch_resource(Z_RES_P(zid), le_curl_name, le_curl)) == NULL) { in PHP_FUNCTION()
3873 RETURN_LONG(curl_easy_pause(ch->cp, bitmask)); in PHP_FUNCTION()