fix build with xcode clang
[m6w6/ext-http] / php_http_client_curl.c
index a5af70dc426a96eca1aefbecf1ed5b87d7a1eb36..2dfd3d771b5f2788448da7b3da14cff16e162d1d 100644 (file)
@@ -228,7 +228,12 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
        /* catch progress */
        switch (type) {
                case CURLINFO_TEXT:
-                       if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
+                       if (data[0] == '-') {
+                       } else if (php_memnstr(data, ZEND_STRL("Adding handle:"), data + length)) {
+                               h->progress.info = "setup";
+                       } else if (php_memnstr(data, ZEND_STRL("addHandle"), data + length)) {
+                               h->progress.info = "setup";
+                       } else if (php_memnstr(data, ZEND_STRL("About to connect"), data + length)) {
                                h->progress.info = "resolve";
                        } else if (php_memnstr(data, ZEND_STRL("Trying"), data + length)) {
                                h->progress.info = "connect";
@@ -238,6 +243,10 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
                                h->progress.info = "connected";
                        } else if (php_memnstr(data, ZEND_STRL("Re-using existing connection!"), data + length)) {
                                h->progress.info = "connected";
+                       } else if (php_memnstr(data, ZEND_STRL("blacklisted"), data + length)) {
+                               h->progress.info = "blacklist check";
+                       } else if (php_memnstr(data, ZEND_STRL("SSL"), data + length)) {
+                               h->progress.info = "ssl negotiation";
                        } else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) {
                                h->progress.info = "not disconnected";
                        } else if (php_memnstr(data, ZEND_STRL("closed"), data + length)) {
@@ -247,7 +256,9 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
                        } else if (php_memnstr(data, ZEND_STRL("Operation timed out"), data + length)) {
                                h->progress.info = "timeout";
                        } else {
+#if PHP_DEBUG
                                h->progress.info = data;
+#endif
                        }
                        if (h->client->callback.progress.func) {
                                h->client->callback.progress.func(h->client->callback.progress.arg, h->client, &h->queue, &h->progress);
@@ -575,7 +586,7 @@ static void php_http_curlm_event_callback(int socket, short action, void *event_
        fprintf(stderr, "E");
 #endif
        if (curl->useevents) {
-               CURLMcode rc = CURLE_OK;
+               CURLMcode rc = CURLM_OK;
                TSRMLS_FETCH_FROM_CTX(context->ts);
 
                while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket_action(curl->handle, socket, etoca(action), &curl->unfinished)));
@@ -1054,11 +1065,9 @@ static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC)
        if ((opt = php_http_option_register(registry, ZEND_STRL("redirect"), CURLOPT_FOLLOWLOCATION, IS_LONG))) {
                opt->setter = php_http_curle_option_set_redirect;
        }
-       php_http_option_register(registry, ZEND_STRL("unrestrictedauth"), CURLOPT_UNRESTRICTED_AUTH, IS_BOOL);
+       php_http_option_register(registry, ZEND_STRL("unrestricted_auth"), CURLOPT_UNRESTRICTED_AUTH, IS_BOOL);
 #if PHP_HTTP_CURL_VERSION(7,19,1)
-       php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POSTREDIR, IS_BOOL);
-#else
-       php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POST301, IS_BOOL);
+       php_http_option_register(registry, ZEND_STRL("postredir"), CURLOPT_POSTREDIR, IS_LONG);
 #endif
 
        /* retries */
@@ -1161,7 +1170,6 @@ static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC)
                        opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
                }
                php_http_option_register(registry, ZEND_STRL("certtype"), CURLOPT_SSLCERTTYPE, IS_STRING);
-               php_http_option_register(registry, ZEND_STRL("certpasswd"), CURLOPT_SSLCERTPASSWD, IS_STRING);
 
                if ((opt = php_http_option_register(registry, ZEND_STRL("key"), CURLOPT_SSLKEY, IS_STRING))) {
                        opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
@@ -1579,7 +1587,17 @@ static php_resource_factory_t *create_rf(const char *url TSRMLS_DC)
        php_url *purl;
        php_resource_factory_t *rf = NULL;
 
-       if ((purl = php_url_parse(url))) {
+       if (!url || !*url) {
+               php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Cannot request empty URL");
+               return NULL;
+       }
+
+       purl = php_url_parse(url);
+
+       if (!purl) {
+               php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Could not parse URL '%s'", url);
+               return NULL;
+       } else {
                char *id_str = NULL;
                size_t id_len = spprintf(&id_str, 0, "%s:%d", STR_PTR(purl->host), purl->port ? purl->port : 80);
                php_persistent_handle_factory_t *pf = php_persistent_handle_concede(NULL, ZEND_STRL("http\\Client\\Curl\\Request"), id_str, id_len, NULL, NULL TSRMLS_CC);
@@ -1605,9 +1623,15 @@ static STATUS php_http_client_curl_enqueue(php_http_client_t *h, php_http_client
        php_http_client_curl_t *curl = h->ctx;
        php_http_client_curl_handler_t *handler;
        php_http_client_progress_state_t *progress;
+       php_resource_factory_t *rf;
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
-       handler = php_http_client_curl_handler_init(h, create_rf(enqueue->request->http.info.request.url TSRMLS_CC));
+       rf = create_rf(enqueue->request->http.info.request.url TSRMLS_CC);
+       if (!rf) {
+               return FAILURE;
+       }
+
+       handler = php_http_client_curl_handler_init(h, rf);
        if (!handler) {
                return FAILURE;
        }