summaryrefslogtreecommitdiff
path: root/res/res_config_curl.c
diff options
context:
space:
mode:
authorMatthew Nicholson <mnicholson@digium.com>2011-01-24 18:59:22 +0000
committerMatthew Nicholson <mnicholson@digium.com>2011-01-24 18:59:22 +0000
commite706b5706e1ed503569c28c7a374a31063bf4244 (patch)
tree9e6c6ce3c4de14d886a8c131a7621a792d457728 /res/res_config_curl.c
parent54f6c31a27319d768da73afa966423e1083bb486 (diff)
According to section 19.1.2 of RFC 3261:
For each component, the set of valid BNF expansions defines exactly which characters may appear unescaped. All other characters MUST be escaped. This patch modifies ast_uri_encode() to encode strings in line with this recommendation. This patch also adds an ast_escape_quoted() function which escapes '"' and '\' characters in quoted strings in accordance with section 25.1 of RFC 3261. The ast_uri_encode() function has also been modified to take an ast_flags struct describing the set of rules it should use when escaping characters to allow for it to escape SIP URIs in addition to HTTP URIs and other types of URIs or variations of those two URI types in the future. The ast_uri_decode() function has also been modified to accept an ast_flags struct describing the set of rules to use when decoding to enable decoding '+' as ' ' in legacy http URLs. The unit tests for these functions have also been updated. ABE-2705 Review: https://reviewboard.asterisk.org/r/1081/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@303509 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_config_curl.c')
-rw-r--r--res/res_config_curl.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/res/res_config_curl.c b/res/res_config_curl.c
index 0ff6694dc..f80998e36 100644
--- a/res/res_config_curl.c
+++ b/res/res_config_curl.c
@@ -65,7 +65,6 @@ static struct ast_variable *realtime_curl(const char *url, const char *unused, v
char *stringp, *pair, *key;
int i;
struct ast_variable *var = NULL, *prev = NULL;
- const int EncodeSpecialChars = 1;
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");
@@ -84,8 +83,8 @@ static struct ast_variable *realtime_curl(const char *url, const char *unused, v
for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
newval = va_arg(ap, const char *);
- ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
}
va_end(ap);
@@ -101,9 +100,9 @@ static struct ast_variable *realtime_curl(const char *url, const char *unused, v
stringp = ast_str_buffer(buffer);
while ((pair = strsep(&stringp, "&"))) {
key = strsep(&pair, "=");
- ast_uri_decode(key);
+ ast_uri_decode(key, ast_uri_http);
if (pair) {
- ast_uri_decode(pair);
+ ast_uri_decode(pair, ast_uri_http);
}
if (!ast_strlen_zero(key)) {
@@ -137,7 +136,6 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
const char *newparam, *newval;
char *stringp, *line, *pair, *key, *initfield = NULL;
int i;
- const int EncodeSpecialChars = 1;
struct ast_variable *var = NULL;
struct ast_config *cfg = NULL;
struct ast_category *cat = NULL;
@@ -165,8 +163,8 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
if ((op = strchr(initfield, ' ')))
*op = '\0';
}
- ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
}
va_end(ap);
@@ -193,9 +191,9 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
while ((pair = strsep(&line, "&"))) {
key = strsep(&pair, "=");
- ast_uri_decode(key);
+ ast_uri_decode(key, ast_uri_http);
if (pair) {
- ast_uri_decode(pair);
+ ast_uri_decode(pair, ast_uri_http);
}
if (!strcasecmp(key, initfield) && pair) {
@@ -235,7 +233,6 @@ static int update_curl(const char *url, const char *unused, const char *keyfield
const char *newparam, *newval;
char *stringp;
int i, rowcount = -1;
- const int EncodeSpecialChars = 1;
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");
@@ -250,14 +247,14 @@ static int update_curl(const char *url, const char *unused, const char *keyfield
return -1;
}
- ast_uri_encode(keyfield, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(lookup, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
ast_str_set(&query, 0, "${CURL(%s/update?%s=%s,", url, buf1, buf2);
for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
newval = va_arg(ap, const char *);
- ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
}
va_end(ap);
@@ -286,7 +283,6 @@ static int update2_curl(const char *url, const char *unused, va_list ap)
const char *newparam, *newval;
char *stringp;
int rowcount = -1, lookup = 1, first = 1;
- const int EncodeSpecialChars = 1;
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");
@@ -315,8 +311,8 @@ static int update2_curl(const char *url, const char *unused, va_list ap)
}
}
newval = va_arg(ap, const char *);
- ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
ast_str_append(&query, 0, "%s%s=%s", first ? "" : "&", buf1, buf2);
first = 0;
}
@@ -363,7 +359,6 @@ static int store_curl(const char *url, const char *unused, va_list ap)
const char *newparam, *newval;
char *stringp;
int i, rowcount = -1;
- const int EncodeSpecialChars = 1;
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");
@@ -382,8 +377,8 @@ static int store_curl(const char *url, const char *unused, va_list ap)
for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
newval = va_arg(ap, const char *);
- ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
}
va_end(ap);
@@ -426,7 +421,6 @@ static int destroy_curl(const char *url, const char *unused, const char *keyfiel
const char *newparam, *newval;
char *stringp;
int i, rowcount = -1;
- const int EncodeSpecialChars = 1;
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");
@@ -441,14 +435,14 @@ static int destroy_curl(const char *url, const char *unused, const char *keyfiel
return -1;
}
- ast_uri_encode(keyfield, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(lookup, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
ast_str_set(&query, 0, "${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
newval = va_arg(ap, const char *);
- ast_uri_encode(newparam, buf1, sizeof(buf1), EncodeSpecialChars);
- ast_uri_encode(newval, buf2, sizeof(buf2), EncodeSpecialChars);
+ ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
+ ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
}
va_end(ap);
@@ -475,7 +469,6 @@ static int require_curl(const char *url, const char *unused, va_list ap)
struct ast_str *query, *buffer;
char *elm, field[256];
int type, size;
- const int EncodeSpecialChars = 1;
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");
@@ -495,7 +488,7 @@ static int require_curl(const char *url, const char *unused, va_list ap)
while ((elm = va_arg(ap, char *))) {
type = va_arg(ap, require_type);
size = va_arg(ap, int);
- ast_uri_encode(elm, field, sizeof(field), EncodeSpecialChars);
+ ast_uri_encode(elm, field, sizeof(field), ast_uri_http);
ast_str_append(&query, 0, "%s=%s%%3A%d", field,
type == RQ_CHAR ? "char" :
type == RQ_INTEGER1 ? "integer1" :
@@ -525,7 +518,6 @@ static struct ast_config *config_curl(const char *url, const char *unused, const
struct ast_str *query, *buffer;
char buf1[200];
char *stringp, *line, *pair, *key;
- const int EncodeSpecialChars = 1;
int last_cat_metric = -1, cat_metric = -1;
struct ast_category *cat = NULL;
char *cur_cat = "";
@@ -545,7 +537,7 @@ static struct ast_config *config_curl(const char *url, const char *unused, const
return NULL;
}
- ast_uri_encode(file, buf1, sizeof(buf1), EncodeSpecialChars);
+ ast_uri_encode(file, buf1, sizeof(buf1), ast_uri_http);
ast_str_set(&query, 0, "${CURL(%s/static?file=%s)}", url, buf1);
/* Do the CURL query */
@@ -562,9 +554,9 @@ static struct ast_config *config_curl(const char *url, const char *unused, const
while ((pair = strsep(&line, "&"))) {
key = strsep(&pair, "=");
- ast_uri_decode(key);
+ ast_uri_decode(key, ast_uri_http);
if (pair) {
- ast_uri_decode(pair);
+ ast_uri_decode(pair, ast_uri_http);
}
if (!strcasecmp(key, "category")) {