X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_curl_api.c;h=e2d59110b8cc9123af0613c1cbd6e9f10f60f1a0;hb=157bfa0c31f7c1c441c08f31ef3d8c90da1fb3ef;hp=1da840cdffbfbc8ecec2ea4bb22bd6aaa6cfbc77;hpb=061bf1e96c7f3fa5d50374a7170b20d4c3e4d002;p=m6w6%2Fext-http diff --git a/http_curl_api.c b/http_curl_api.c index 1da840c..e2d5911 100644 --- a/http_curl_api.c +++ b/http_curl_api.c @@ -85,8 +85,9 @@ static inline char *_http_curl_copystr(const char *str TSRMLS_DC); #define http_curl_setopts(c, u, o, r) _http_curl_setopts((c), (u), (o), (r) TSRMLS_CC) static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, phpstr *response TSRMLS_DC); -#define http_curl_getopt(o, k, t) _http_curl_getopt((o), (k), (t) TSRMLS_CC) -static inline zval *_http_curl_getopt(HashTable *options, char *key, int type TSRMLS_DC); +#define http_curl_getopt(o, k, t) _http_curl_getopt_ex((o), (k), sizeof(k), (t) TSRMLS_CC) +#define http_curl_getopt_ex(o, k, l, t) _http_curl_getopt_ex((o), (k), (l), (t) TSRMLS_CC) +static inline zval *_http_curl_getopt_ex(HashTable *options, char *key, size_t keylen, int type TSRMLS_DC); static size_t http_curl_callback(char *, size_t, size_t, void *); @@ -105,16 +106,16 @@ static inline char *_http_curl_copystr(const char *str TSRMLS_DC) /* {{{ static size_t http_curl_callback(char *, size_t, size_t, void *) */ static size_t http_curl_callback(char *buf, size_t len, size_t n, void *s) { - return phpstr_append(PHPSTR(s), buf, len *= n); + return s ? phpstr_append(PHPSTR(s), buf, len * n) : len * n; } /* }}} */ -/* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int) */ -static inline zval *_http_curl_getopt(HashTable *options, char *key, int type TSRMLS_DC) +/* {{{ static inline zval *http_curl_getopt(HashTable *, char *, size_t, int) */ +static inline zval *_http_curl_getopt_ex(HashTable *options, char *key, size_t keylen, int type TSRMLS_DC) { zval **zoption; - if (SUCCESS != zend_hash_find(options, key, strlen(key) + 1, (void **) &zoption)) { + if (!options || (SUCCESS != zend_hash_find(options, key, keylen, (void **) &zoption))) { return NULL; } @@ -145,15 +146,22 @@ static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, ph #define HTTP_CURL_OPT(OPTION, p) curl_easy_setopt(ch, CURLOPT_##OPTION, (p)) /* standard options */ - HTTP_CURL_OPT(URL, url); + if (url) { + HTTP_CURL_OPT(URL, url); + } + HTTP_CURL_OPT(HEADER, 0); HTTP_CURL_OPT(FILETIME, 1); HTTP_CURL_OPT(NOPROGRESS, 1); HTTP_CURL_OPT(AUTOREFERER, 1); HTTP_CURL_OPT(WRITEFUNCTION, http_curl_callback); HTTP_CURL_OPT(HEADERFUNCTION, http_curl_callback); - HTTP_CURL_OPT(WRITEDATA, response); - HTTP_CURL_OPT(WRITEHEADER, response); + + if (response) { + HTTP_CURL_OPT(WRITEDATA, response); + HTTP_CURL_OPT(WRITEHEADER, response); + } + #if defined(ZTS) && (LIBCURL_VERSION_NUM >= 0x070a00) HTTP_CURL_OPT(NOSIGNAL, 1); #endif @@ -203,7 +211,7 @@ static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, ph /* compress, empty string enables deflate and gzip */ if (zoption = http_curl_getopt(options, "compress", IS_BOOL)) { if (Z_LVAL_P(zoption)) { - HTTP_CURL_OPT(ENCODING, ""); + HTTP_CURL_OPT(ENCODING, http_curl_copystr("")); } } @@ -324,7 +332,7 @@ static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options, ph #define HTTP_CURL_OPT_STRING_EX(keyname, optname) \ if (!strcasecmp(key, #keyname)) { \ convert_to_string_ex(param); \ - HTTP_CURL_OPT(optname, Z_STRVAL_PP(param)); \ + HTTP_CURL_OPT(optname, http_curl_copystr(Z_STRVAL_PP(param))); \ key = NULL; \ continue; \ }