summaryrefslogtreecommitdiff
path: root/res/res_config_curl.c
diff options
context:
space:
mode:
Diffstat (limited to 'res/res_config_curl.c')
-rw-r--r--res/res_config_curl.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/res/res_config_curl.c b/res/res_config_curl.c
index 37079adea..b159c768d 100644
--- a/res/res_config_curl.c
+++ b/res/res_config_curl.c
@@ -275,6 +275,69 @@ static int update_curl(const char *url, const char *unused, const char *keyfield
return -1;
}
+static int update2_curl(const char *url, const char *unused, va_list ap)
+{
+ struct ast_str *query;
+ char buf1[200], buf2[200];
+ const char *newparam, *newval;
+ char *stringp;
+ int rowcount = -1, lookup = 1, first = 1;
+ const int EncodeSpecialChars = 1, bufsize = 100;
+ char *buffer;
+
+ if (!ast_custom_function_find("CURL")) {
+ ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
+ return -1;
+ }
+
+ if (!(query = ast_str_create(1000)))
+ return -1;
+
+ if (!(buffer = ast_malloc(bufsize))) {
+ ast_free(query);
+ return -1;
+ }
+
+ ast_str_set(&query, 0, "${CURL(%s/update?", url);
+
+ for (;;) {
+ if ((newparam = va_arg(ap, const char *)) == SENTINEL) {
+ if (lookup) {
+ lookup = 0;
+ ast_str_append(&query, 0, ",");
+ /* Back to the first parameter; we don't need a starting '&' */
+ first = 1;
+ continue;
+ } else {
+ break;
+ }
+ }
+ newval = va_arg(ap, const char *);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
+ ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_str_append(&query, 0, "%s%s=%s", first ? "" : "&", buf1, buf2);
+ }
+ va_end(ap);
+
+ ast_str_append(&query, 0, ")}");
+ /* TODO: Make proxies work */
+ pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+
+ /* Line oriented output */
+ stringp = buffer;
+ while (*stringp <= ' ')
+ stringp++;
+ sscanf(stringp, "%d", &rowcount);
+
+ ast_free(buffer);
+ ast_free(query);
+
+ if (rowcount >= 0)
+ return (int)rowcount;
+
+ return -1;
+}
+
/*!
* \brief Execute an INSERT query
* \param url
@@ -535,6 +598,7 @@ static struct ast_config_engine curl_engine = {
.store_func = store_curl,
.destroy_func = destroy_curl,
.update_func = update_curl,
+ .update2_func = update2_curl,
.require_func = require_curl,
};