Skip to content
Snippets Groups Projects
Commit 5db0b8e3 authored by Mark Spencer's avatar Mark Spencer
Browse files

Allow post data, too (bug #3151)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4673 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 8ddb3aba
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Copyright (C) 2004, Tilghman Lesher * Copyright (C) 2004, Tilghman Lesher
* *
* Tilghman Lesher <curl-20041222@the-tilghman.com> * Tilghman Lesher <curl-20041222@the-tilghman.com>
* and Brian Wilkins <bwilkins@cfl.rr.com> (Added POST option)
* *
* app_curl.c is distributed with no restrictions on usage or * app_curl.c is distributed with no restrictions on usage or
* redistribution. * redistribution.
...@@ -30,9 +31,10 @@ static char *app = "Curl"; ...@@ -30,9 +31,10 @@ static char *app = "Curl";
static char *synopsis = "Load an external URL"; static char *synopsis = "Load an external URL";
static char *descrip = static char *descrip =
" Curl(URL): Requests the URL. Mainly used for signalling external\n" " Curl(URL[|postdata]): Requests the URL. Mainly used for signalling\n"
"applications of an event. Returns 0 or -1 on fatal error. Also sets\n" "external applications of an event. Returns 0 or -1 on fatal error.\n"
"CURL variable with the resulting page.\n"; "Argument specified treated as POST data. Also sets CURL variable with the\n"
"resulting page.\n";
STANDARD_LOCAL_USER; STANDARD_LOCAL_USER;
...@@ -74,12 +76,21 @@ static int curl_exec(struct ast_channel *chan, void *data) ...@@ -74,12 +76,21 @@ static int curl_exec(struct ast_channel *chan, void *data)
int res = 0; int res = 0;
struct localuser *u; struct localuser *u;
CURL *curl; CURL *curl;
char *info, *post_data=NULL, *url;
if (!data || !strlen((char *)data)) { if (!data || !strlen((char *)data)) {
ast_log(LOG_WARNING, "Curl requires an argument (URL)\n"); ast_log(LOG_WARNING, "Curl requires an argument (URL)\n");
return -1; return -1;
} }
if ((info = ast_strdupa((char *)data))) {
url = strsep(&info, "|");
post_data = info;
} else {
ast_log(LOG_ERROR, "Out of memory\n");
return -1;
}
LOCAL_USER_ADD(u); LOCAL_USER_ADD(u);
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
...@@ -91,11 +102,16 @@ static int curl_exec(struct ast_channel *chan, void *data) ...@@ -91,11 +102,16 @@ static int curl_exec(struct ast_channel *chan, void *data)
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
chunk.size = 0; /* no data at this point */ chunk.size = 0; /* no data at this point */
curl_easy_setopt(curl, CURLOPT_URL, (char *)data); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "asterisk-libcurl-agent/1.0"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "asterisk-libcurl-agent/1.0");
if (post_data) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data);
}
curl_easy_perform(curl); curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment