summaryrefslogtreecommitdiff
path: root/funcs
diff options
context:
space:
mode:
authorWalter Doekes <walter+asterisk@wjd.nu>2013-03-20 20:27:37 +0000
committerWalter Doekes <walter+asterisk@wjd.nu>2013-03-20 20:27:37 +0000
commit220cc9b9afe0965dc9ac7f24de72755bd48da866 (patch)
tree46c291cc331f344e4f86a8b925cf418ce9a031be /funcs
parent0b1e78cace32b7c4cedab9b36e79c8cc15fc4ac2 (diff)
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 ........ Merged revisions 383461 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@383462 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'funcs')
-rw-r--r--funcs/func_curl.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index 7291fa019..b8f8c1218 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -581,6 +581,7 @@ static int acf_curl_helper(struct ast_channel *chan, const char *cmd, char *info
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 @@ static int acf_curl_helper(struct ast_channel *chan, const char *cmd, char *info
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);