[asterisk-commits] tilghman: trunk r144199 - /trunk/funcs/func_curl.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 24 01:43:05 CDT 2008
Author: tilghman
Date: Wed Sep 24 01:43:05 2008
New Revision: 144199
URL: http://svn.digium.com/view/asterisk?view=rev&rev=144199
Log:
Create a 'hashcompat' option that permits the results of a CURL() able to be
passed directly into the HASH() function. Requested via the -users list, and
committed at Astricon in the Code Zone.
Modified:
trunk/funcs/func_curl.c
Modified: trunk/funcs/func_curl.c
URL: http://svn.digium.com/view/asterisk/trunk/funcs/func_curl.c?view=diff&rev=144199&r1=144198&r2=144199
==============================================================================
--- trunk/funcs/func_curl.c (original)
+++ trunk/funcs/func_curl.c Wed Sep 24 01:43:05 2008
@@ -52,6 +52,8 @@
#define CURLVERSION_ATLEAST(a,b,c) \
((LIBCURL_VERSION_MAJOR > (a)) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR > (b))) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR == (b)) && (LIBCURL_VERSION_PATCH >= (c))))
+
+#define CURLOPT_SPECIAL_HASHCOMPAT -500
static void curlds_free(void *data);
@@ -146,6 +148,9 @@
} else if (!strcasecmp(name, "ftptext")) {
*key = CURLOPT_TRANSFERTEXT;
*ot = OT_BOOLEAN;
+ } else if (!strcasecmp(name, "hashcompat")) {
+ *key = CURLOPT_SPECIAL_HASHCOMPAT;
+ *ot = OT_BOOLEAN;
} else {
return -1;
}
@@ -351,7 +356,7 @@
ast_debug(3, "Called with data=%p, str=%p, realsize=%d, len=%zu, used=%zu\n", data, *pstr, realsize, (*pstr)->len, (*pstr)->used);
- if (ast_str_make_space(pstr, (((*pstr)->used + realsize + 1) / 512 + 1) * 512 + 470) == 0) {
+ if (ast_str_make_space(pstr, (((*pstr)->used + realsize + 1) / 512 + 1) * 512 + 230) == 0) {
memcpy(&((*pstr)->str[(*pstr)->used]), ptr, realsize);
(*pstr)->used += realsize;
}
@@ -399,6 +404,7 @@
CURL **curl;
struct curl_settings *cur;
struct ast_datastore *store = NULL;
+ int hashcompat = 0;
AST_LIST_HEAD(global_curl_info, curl_settings) *list = NULL;
*buf = '\0';
@@ -422,14 +428,22 @@
AST_LIST_LOCK(&global_curl_info);
AST_LIST_TRAVERSE(&global_curl_info, cur, list) {
- curl_easy_setopt(*curl, cur->key, cur->value);
+ if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
+ hashcompat = (cur->value != NULL) ? 1 : 0;
+ } else {
+ curl_easy_setopt(*curl, cur->key, cur->value);
+ }
}
if (chan && (store = ast_channel_datastore_find(chan, &curl_info, NULL))) {
list = store->data;
AST_LIST_LOCK(list);
AST_LIST_TRAVERSE(list, cur, list) {
- curl_easy_setopt(*curl, cur->key, cur->value);
+ if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
+ hashcompat = (cur->value != NULL) ? 1 : 0;
+ } else {
+ curl_easy_setopt(*curl, cur->key, cur->value);
+ }
}
}
@@ -458,7 +472,28 @@
str->str[str->used - 1] = '\0';
}
- ast_copy_string(buf, str->str, len);
+ ast_log(LOG_NOTICE, "str='%s'\n", str->str);
+ if (hashcompat) {
+ char *remainder = str->str;
+ char *piece;
+ struct ast_str *fields = ast_str_create(str->used / 2);
+ struct ast_str *values = ast_str_create(str->used / 2);
+ int rowcount = 0;
+ while ((piece = strsep(&remainder, "&"))) {
+ char *name = strsep(&piece, "=");
+ ast_uri_decode(piece);
+ ast_uri_decode(name);
+ ast_str_append(&fields, 0, "%s%s", rowcount ? "," : "", name);
+ ast_str_append(&values, 0, "%s%s", rowcount ? "," : "", piece);
+ rowcount++;
+ }
+ pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", fields->str);
+ ast_copy_string(buf, values->str, len);
+ ast_free(fields);
+ ast_free(values);
+ } else {
+ ast_copy_string(buf, str->str, len);
+ }
}
ast_free(str);
@@ -498,6 +533,7 @@
" referer - Referer URL to use for the request\n"
" useragent - UserAgent string to use\n"
" userpwd - A <user>:<pass> to use for authentication\n"
+" hashcompat - Result data will be compatible for use with HASH()\n"
"",
.read = acf_curlopt_read,
.write = acf_curlopt_write,
More information about the asterisk-commits
mailing list