[Asterisk-cvs] asterisk/apps app_curl.c,1.1,1.2
markster at lists.digium.com
markster at lists.digium.com
Wed Jan 5 00:33:37 CST 2005
Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv15825/apps
Modified Files:
app_curl.c
Log Message:
Allow post data, too (bug #3151)
Index: app_curl.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_curl.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- app_curl.c 23 Dec 2004 02:55:53 -0000 1.1
+++ app_curl.c 5 Jan 2005 06:38:39 -0000 1.2
@@ -6,6 +6,7 @@
* Copyright (C) 2004, Tilghman Lesher
*
* Tilghman Lesher <curl-20041222 at the-tilghman.com>
+ * and Brian Wilkins <bwilkins at cfl.rr.com> (Added POST option)
*
* app_curl.c is distributed with no restrictions on usage or
* redistribution.
@@ -30,9 +31,10 @@
static char *synopsis = "Load an external URL";
static char *descrip =
-" Curl(URL): Requests the URL. Mainly used for signalling external\n"
-"applications of an event. Returns 0 or -1 on fatal error. Also sets\n"
-"CURL variable with the resulting page.\n";
+" Curl(URL[|postdata]): Requests the URL. Mainly used for signalling\n"
+"external applications of an event. Returns 0 or -1 on fatal error.\n"
+"Argument specified treated as POST data. Also sets CURL variable with the\n"
+"resulting page.\n";
STANDARD_LOCAL_USER;
@@ -74,12 +76,21 @@
int res = 0;
struct localuser *u;
CURL *curl;
+ char *info, *post_data=NULL, *url;
if (!data || !strlen((char *)data)) {
ast_log(LOG_WARNING, "Curl requires an argument (URL)\n");
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);
curl_global_init(CURL_GLOBAL_ALL);
@@ -91,11 +102,16 @@
chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
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_WRITEDATA, (void *)&chunk);
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_cleanup(curl);
More information about the svn-commits
mailing list