pajoye                                   Tue, 15 Sep 2009 15:47:06 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=288348

Log:
- #49253, add support for libcurl's CERTINFO option

Bug: http://bugs.php.net/49253 (Assigned) add support for libcurl's CERTINFO 
option
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/curl/interface.c
    U   php/php-src/trunk/ext/curl/interface.c

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2009-09-15 06:52:03 UTC (rev 288347)
+++ php/php-src/branches/PHP_5_3/NEWS	2009-09-15 15:47:06 UTC (rev 288348)
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2009, PHP 5.3.2
+- Implement FR #49253 (add support for libcurl's CERTINFO option).
+  (Linus Nielsen Feltzing <li...@haxx.se>)

 ?? ??? 2009, PHP 5.3.1RC?
 - Fixed certificate validation inside php_openssl_apply_verification_policy

Modified: php/php-src/branches/PHP_5_3/ext/curl/interface.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/curl/interface.c	2009-09-15 06:52:03 UTC (rev 288347)
+++ php/php-src/branches/PHP_5_3/ext/curl/interface.c	2009-09-15 15:47:06 UTC (rev 288348)
@@ -629,6 +629,9 @@
 	REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
 	REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
 	REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
+#if LIBCURL_VERSION_NUM >  0x071202
+	REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
+#endif

 	/* cURL protocol constants (curl_version) */
 	REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
@@ -744,6 +747,9 @@
 	REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
 	REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
 #endif
+#if LIBCURL_VERSION_NUM >  0x071202
+	REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
+#endif

 /* SSH support works in 7.19.0+ using libssh2 */
 #if LIBCURL_VERSION_NUM >= 0x071300
@@ -1336,6 +1342,85 @@
 }
 /* }}} */

+#if LIBCURL_VERSION_NUM >  0x071202
+/* {{{ split_certinfo
+ */
+static void split_certinfo(char *string, zval *hash)
+{
+	int i;
+	char *org = estrdup(string);
+	char *s = org;
+	char *split;
+
+	if(org) {
+        do {
+			char *key;
+			char *val;
+			char *tmp;
+
+            split = strstr(s, "; ");
+            if(split)
+                *split = '\0';
+
+			key = s;
+			tmp = memchr(key, '=', 64);
+			if(tmp) {
+				*tmp = '\0';
+				val = tmp+1;
+				add_assoc_string(hash, key, val, 1);
+			}
+			s = split+2;
+		} while(split);
+		efree(org);
+	}
+}
+
+/* {{{ create_certinfo
+ */
+static void create_certinfo(struct curl_certinfo *ci, zval *listcode)
+{
+	int i;
+
+	if(ci) {
+		zval *certhash = NULL;
+		char *tmp;
+
+		for(i=0; i<ci->num_of_certs; i++) {
+			struct curl_slist *slist;
+
+			MAKE_STD_ZVAL(certhash);
+			array_init(certhash);
+			for(slist = ci->certinfo[i]; slist; slist = slist->next) {
+				int len;
+				char s[64];
+				char *tmp;
+				strncpy(s, slist->data, 64);
+				tmp = memchr(s, ':', 64);
+				if(tmp) {
+					*tmp = '\0';
+					len = strlen(s);
+					if(!strcmp(s, "Subject") || !strcmp(s, "Issuer")) {
+						zval *hash;
+
+						MAKE_STD_ZVAL(hash);
+						array_init(hash);
+
+						split_certinfo(&slist->data[len+1], hash);
+						add_assoc_zval(certhash, s, hash);
+					} else {
+						add_assoc_string(certhash, s, &slist->data[len+1], 1);
+					}
+				} else {
+					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info");
+				}
+			}
+			add_next_index_zval(listcode, certhash);
+		}
+	}
+}
+/* }}} */
+#endif
+
 /* {{{ proto resource curl_init([string url])
    Initialize a cURL session */
 PHP_FUNCTION(curl_init)
@@ -1561,6 +1646,9 @@
 #if LIBCURL_VERSION_NUM >= 0x070f01
 		case CURLOPT_FTP_FILEMETHOD:
 #endif
+#if LIBCURL_VERSION_NUM >  0x071202
+		case CURLOPT_CERTINFO:
+#endif
 			convert_to_long_ex(zvalue);
 #if LIBCURL_VERSION_NUM >= 0x71304
 			if (((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) && (Z_LVAL_PP(zvalue) & CURLPROTO_FILE)) {
@@ -2105,6 +2193,10 @@
 		char   *s_code;
 		long    l_code;
 		double  d_code;
+#if LIBCURL_VERSION_NUM >  0x071202
+		struct curl_certinfo *ci = NULL;
+		zval *listcode;
+#endif

 		array_init(return_value);

@@ -2175,6 +2267,14 @@
 		if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
 			CAAD("redirect_time", d_code);
 		}
+#if LIBCURL_VERSION_NUM >  0x071202
+		if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
+			MAKE_STD_ZVAL(listcode);
+			array_init(listcode);
+			create_certinfo(ci, listcode);
+			CAAZ("certinfo", listcode);
+		}
+#endif
 		if (ch->header.str_len > 0) {
 			CAAS("request_header", ch->header.str);
 		}
@@ -2234,6 +2334,20 @@
 				} else {
 					RETURN_FALSE;
 				}
+#if LIBCURL_VERSION_NUM >  0x071202
+			case CURLINFO_CERTINFO: {
+				struct curl_certinfo *ci = NULL;
+
+				array_init(return_value);
+
+				if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
+					create_certinfo(ci, return_value);
+				} else {
+					RETURN_FALSE;
+				}
+				break;
+			}
+#endif
 		}
 	}
 }

Modified: php/php-src/trunk/ext/curl/interface.c
===================================================================
--- php/php-src/trunk/ext/curl/interface.c	2009-09-15 06:52:03 UTC (rev 288347)
+++ php/php-src/trunk/ext/curl/interface.c	2009-09-15 15:47:06 UTC (rev 288348)
@@ -629,6 +629,9 @@
 	REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
 	REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
 	REGISTER_CURL_CONSTANT(CURLINFO_PRIVATE);
+#if LIBCURL_VERSION_NUM >  0x071202
+	REGISTER_CURL_CONSTANT(CURLINFO_CERTINFO);
+#endif

 	/* cURL protocol constants (curl_version) */
 	REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
@@ -744,6 +747,9 @@
 	REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL);
 	REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL);
 #endif
+#if LIBCURL_VERSION_NUM >  0x071202
+	REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO);
+#endif

 /* SSH support works in 7.19.0+ using libssh2 */
 #if LIBCURL_VERSION_NUM >= 0x071300
@@ -1339,6 +1345,85 @@
 }
 /* }}} */

+#if LIBCURL_VERSION_NUM >  0x071202
+/* {{{ split_certinfo
+ */
+static void split_certinfo(char *string, zval *hash)
+{
+	int i;
+	char *org = estrdup(string);
+	char *s = org;
+	char *split;
+
+	if(org) {
+		do {
+			char *key;
+			char *val;
+			char *tmp;
+
+			split = strstr(s, "; ");
+			if(split)
+				*split = '\0';
+
+			key = s;
+			tmp = memchr(key, '=', 64);
+			if(tmp) {
+				*tmp = '\0';
+				val = tmp+1;
+				add_assoc_string(hash, key, val, 1);
+			}
+			s = split+2;
+		} while(split);
+		efree(org);
+	}
+}
+
+/* {{{ create_certinfo
+ */
+static void create_certinfo(struct curl_certinfo *ci, zval *listcode)
+{
+	int i;
+
+	if(ci) {
+		zval *certhash = NULL;
+		char *tmp;
+
+		for(i=0; i<ci->num_of_certs; i++) {
+			struct curl_slist *slist;
+
+			MAKE_STD_ZVAL(certhash);
+			array_init(certhash);
+			for(slist = ci->certinfo[i]; slist; slist = slist->next) {
+				int len;
+				char s[64];
+				char *tmp;
+				strncpy(s, slist->data, 64);
+				tmp = memchr(s, ':', 64);
+				if(tmp) {
+					*tmp = '\0';
+					len = strlen(s);
+					if(!strcmp(s, "Subject") || !strcmp(s, "Issuer")) {
+						zval *hash;
+
+						MAKE_STD_ZVAL(hash);
+						array_init(hash);
+
+						split_certinfo(&slist->data[len+1], hash);
+						add_assoc_zval(certhash, s, hash);
+					} else {
+						add_assoc_string(certhash, s, &slist->data[len+1], 1);
+					}
+				} else {
+					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not extract hash key from certificate info");
+				}
+			}
+			add_next_index_zval(listcode, certhash);
+		}
+	}
+}
+/* }}} */
+#endif
+
 /* {{{ proto resource curl_init([string url]) U
    Initialize a cURL session */
 PHP_FUNCTION(curl_init)
@@ -1577,6 +1662,9 @@
 #if LIBCURL_VERSION_NUM >= 0x070f01
 		case CURLOPT_FTP_FILEMETHOD:
 #endif
+#if LIBCURL_VERSION_NUM >  0x071202
+		case CURLOPT_CERTINFO:
+#endif
 			convert_to_long_ex(zvalue);
 #if LIBCURL_VERSION_NUM >= 0x71304
 			if ((PG(open_basedir) && *PG(open_basedir)) && (Z_LVAL_PP(zvalue) & CURLPROTO_FILE)) {
@@ -2171,6 +2259,10 @@
 		char   *s_code;
 		long    l_code;
 		double  d_code;
+#if LIBCURL_VERSION_NUM >  0x071202
+		struct curl_certinfo *ci = NULL;
+		zval *listcode;
+#endif

 		array_init(return_value);

@@ -2241,6 +2333,14 @@
 		if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) == CURLE_OK) {
 			CAAD("redirect_time", d_code);
 		}
+#if LIBCURL_VERSION_NUM >  0x071202
+		if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
+			MAKE_STD_ZVAL(listcode);
+			array_init(listcode);
+			create_certinfo(ci, listcode);
+			CAAZ("certinfo", listcode);
+		}
+#endif
 		if (ch->header.str_len > 0) {
 			CAAS("request_header", ch->header.str);
 		}
@@ -2300,6 +2400,20 @@
 				} else {
 					RETURN_FALSE;
 				}
+#if LIBCURL_VERSION_NUM >  0x071202
+			case CURLINFO_CERTINFO: {
+				struct curl_certinfo *ci = NULL;
+
+				array_init(return_value);
+
+				if (curl_easy_getinfo(ch->cp, CURLINFO_CERTINFO, &ci) == CURLE_OK) {
+					create_certinfo(ci, return_value);
+				} else {
+					RETURN_FALSE;
+				}
+				break;
+			}
+#endif
 		}
 	}
 }
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to