fix certinfo
authorMichael Wallner <mike@php.net>
Fri, 12 Dec 2008 10:50:23 +0000 (10:50 +0000)
committerMichael Wallner <mike@php.net>
Fri, 12 Dec 2008 10:50:23 +0000 (10:50 +0000)
http_request_info.c
scripts/gen_curlinfo.php

index db72fac7a3050cdd6e54cc6e375691531d78ffa9..33694e716c8b08617f2644a60a39ec7e53afbe6c 100644 (file)
@@ -108,7 +108,9 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
                MAKE_STD_ZVAL(subarray);
                array_init(subarray);
                for (p = s; p; p = p->next) {
-                       add_next_index_string(subarray, p->data, 1);
+                       if (p->data) {
+                               add_next_index_string(subarray, p->data, 1);
+                       }
                }
                add_assoc_zval_ex(&array, "ssl_engines", sizeof("ssl_engines"), subarray);
                curl_slist_free_all(s);
@@ -118,7 +120,9 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
                MAKE_STD_ZVAL(subarray);
                array_init(subarray);
                for (p = s; p; p = p->next) {
-                       add_next_index_string(subarray, p->data, 1);
+                       if (p->data) {
+                               add_next_index_string(subarray, p->data, 1);
+                       }
                }
                add_assoc_zval_ex(&array, "cookies", sizeof("cookies"), subarray);
                curl_slist_free_all(s);
@@ -139,18 +143,41 @@ PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
                add_assoc_double_ex(&array, "appconnect_time", sizeof("appconnect_time"), d);
        }
 #endif
+/* END */
 #if HTTP_CURL_VERSION(7,19,1) && defined(HTTP_HAVE_OPENSSL)
-       if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CERTINFO, &s)) {
-               MAKE_STD_ZVAL(subarray);
-               array_init(subarray);
-               for (p = s; p; p = p->next) {
-                       add_next_index_string(subarray, p->data, 1);
+       {
+               int i;
+               zval *ci_array;
+               struct curl_certinfo *ci;
+               char *colon, *keyname;
+               
+               if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CERTINFO, &ci)) {
+                       MAKE_STD_ZVAL(ci_array);
+                       array_init(ci_array);
+                       
+                       for (i = 0; i < ci->num_of_certs; ++i) {
+                               s = ci->certinfo[i];
+                               
+                               MAKE_STD_ZVAL(subarray);
+                               array_init(subarray);
+                               for (p = s; p; p = p->next) {
+                                       if (p->data) {
+                                               if ((colon = strchr(p->data, ':'))) {
+                                                       keyname = estrndup(p->data, colon - p->data);
+                                                       add_assoc_string_ex(subarray, keyname, colon - p->data + 1, colon + 1, 1);
+                                                       efree(keyname);
+                                               } else {
+                                                       add_next_index_string(subarray, p->data, 1);
+                                               }
+                                       }
+                               }
+                               add_next_index_zval(ci_array, subarray);
+                               curl_slist_free_all(s);
+                       }
+                       add_assoc_zval_ex(&array, "certinfo", sizeof("certinfo"), ci_array);
                }
-               add_assoc_zval_ex(&array, "certinfo", sizeof("certinfo"), subarray);
-               curl_slist_free_all(s);
        }
 #endif
-/* END */
        add_assoc_string_ex(&array, "error", sizeof("error"), http_request_storage_get(request->ch)->errorbuffer, 1);
 }
 /* }}} */
index 54137ba2c9e3b528aa1f1a5b09d8fe0b59a22cb1..52afecbadb020d3715b2a09dd99dea82a22bfbff 100644 (file)
@@ -36,10 +36,9 @@ $ifdefs = array(
        'PRIMARY_IP' => 'HTTP_CURL_VERSION(7,19,0)',
        'APPCONNECT_TIME' => 'HTTP_CURL_VERSION(7,19,0)',
        'REDIRECT_URL' => 'HTTP_CURL_VERSION(7,18,2)',
-       'CERTINFO' => 'HTTP_CURL_VERSION(7,19,1) && defined(HTTP_HAVE_OPENSSL)'
 );
 $exclude = array(
-       'PRIVATE', 'LASTSOCKET', 'FTP_ENTRY_PATH'
+       'PRIVATE', 'LASTSOCKET', 'FTP_ENTRY_PATH', 'CERTINFO',
 );
 $translate = array(
        'HTTP_CONNECTCODE' => "connect_code",
@@ -62,17 +61,19 @@ $templates = array(
                add_assoc_long_ex(&array, "%s", sizeof("%2$s"), l);
        }
 ',
-'SLIST' => 
+'SLIST' =>
 '      if (CURLE_OK == curl_easy_getinfo(request->ch, %s, &s)) {
                MAKE_STD_ZVAL(subarray);
                array_init(subarray);
                for (p = s; p; p = p->next) {
-                       add_next_index_string(subarray, p->data, 1);
+                       if (p->data) {
+                               add_next_index_string(subarray, p->data, 1);
+                       }
                }
                add_assoc_zval_ex(&array, "%s", sizeof("%2$s"), subarray);
                curl_slist_free_all(s);
        }
-'
+',
 );
 
 $infos = file_re('curl.h', '/^\s*(CURLINFO_(\w+))\s*=\s*CURLINFO_(STRING|LONG|DOUBLE|SLIST)\s*\+\s*\d+\s*,?\s*$/m');