[asterisk-commits] wdoekes: branch 11 r383461 - in /branches/11: ./ funcs/func_curl.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 20 15:25:53 CDT 2013


Author: wdoekes
Date: Wed Mar 20 15:25:50 2013
New Revision: 383461

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383461
Log:
Have func_curl log a warning when a curl request fails.

Review: https://reviewboard.asterisk.org/r/2403/
........

Merged revisions 383460 from http://svn.asterisk.org/svn/asterisk/branches/1.8

Modified:
    branches/11/   (props changed)
    branches/11/funcs/func_curl.c

Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: branches/11/funcs/func_curl.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/funcs/func_curl.c?view=diff&rev=383461&r1=383460&r2=383461
==============================================================================
--- branches/11/funcs/func_curl.c (original)
+++ branches/11/funcs/func_curl.c Wed Mar 20 15:25:50 2013
@@ -581,6 +581,7 @@
 	struct ast_datastore *store = NULL;
 	int hashcompat = 0;
 	AST_LIST_HEAD(global_curl_info, curl_settings) *list = NULL;
+	char curl_errbuf[CURL_ERROR_SIZE + 1]; /* add one to be safe */
 
 	if (buf) {
 		*buf = '\0';
@@ -642,7 +643,19 @@
 		curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, args.postdata);
 	}
 
-	curl_easy_perform(*curl);
+	/* Temporarily assign a buffer for curl to write errors to. */
+	curl_errbuf[0] = curl_errbuf[CURL_ERROR_SIZE] = '\0';
+	curl_easy_setopt(*curl, CURLOPT_ERRORBUFFER, curl_errbuf);
+
+	if (curl_easy_perform(*curl) != 0) {
+		ast_log(LOG_WARNING, "%s ('%s')\n", curl_errbuf, args.url);
+	}
+
+	/* Reset buffer to NULL so curl doesn't try to write to it when the
+	 * buffer is deallocated. Documentation is vague about allowing NULL
+	 * here, but the source allows it. See: "typecheck: allow NULL to unset
+	 * CURLOPT_ERRORBUFFER" (62bcf005f4678a93158358265ba905bace33b834). */
+	curl_easy_setopt(*curl, CURLOPT_ERRORBUFFER, (char*)NULL);
 
 	if (store) {
 		AST_LIST_UNLOCK(list);




More information about the asterisk-commits mailing list