Merge realtime_update2 branch, which adds a new realtime API call named

'update2', which permits updates which match across multiple columns, instead
of requiring all tables to have a single unique identifier.  All of the other
API calls with the exception of 'update' already had the ability to match on
multiple fields, so it was a missing and very desireable feature that an API
call implementing an update should have this, too.

This does not change any outward performance of Asterisk, but it should make
life easier for application developers who use the RealTime framework.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@148570 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2008-10-14 00:08:52 +00:00
parent db7299f4bc
commit c1351ad237
10 changed files with 942 additions and 173 deletions

View File

@@ -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,
};