summaryrefslogtreecommitdiff
path: root/main/http.c
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2013-12-13 17:19:23 +0000
committerKevin Harwell <kharwell@digium.com>2013-12-13 17:19:23 +0000
commitf425c4a086526d8f4da91d62a5e02121c09609b8 (patch)
tree9c7c9ca6947d63c5037287e7bbbe4d074c7e777e /main/http.c
parentce18946de46a6f16463391a9c07af02b8ee4e925 (diff)
ARI: Allow specifying channel variables during a POST /channels
Added the ability to specify channel variables when creating/originating a channel in ARI. The variables are sent in the body of the request and should be formatted as a single level JSON object. No nested objects allowed. For example: {"variable1": "foo", "variable2": "bar"}. (closes issue ASTERISK-22872) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/3052/ ........ Merged revisions 403752 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/http.c')
-rw-r--r--main/http.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/main/http.c b/main/http.c
index 0c9b09a90..ebe0a636a 100644
--- a/main/http.c
+++ b/main/http.c
@@ -608,18 +608,30 @@ void ast_http_uri_unlink_all_with_key(const char *key)
#define MAX_POST_CONTENT 1025
-static const char *get_content_type(struct ast_variable *headers)
+/*!
+ * \brief Retrieves the content type specified in the "Content-Type" header.
+ *
+ * This function only returns the "type/subtype" and any trailing parameter is
+ * not included.
+ *
+ * \note the return value is an allocated string that needs to be freed.
+ *
+ * \retval the content type/subtype or NULL if the header is not found.
+ */
+static char *get_content_type(struct ast_variable *headers)
{
struct ast_variable *v;
for (v = headers; v; v = v->next) {
if (strcasecmp(v->name, "Content-Type") == 0) {
- return v->value;
+ const char *param = strchr(v->value, ';');
+ size_t size = (param ? param - v->value :
+ strlen(v->value)) + 1;
+ return ast_strndup(v->value, size);
}
}
- /* Missing content type; assume empty string */
- return "";
+ return NULL;
}
static int get_content_length(struct ast_variable *headers)
@@ -643,11 +655,12 @@ struct ast_json *ast_http_get_json(
int res;
struct ast_json *body;
RAII_VAR(char *, buf, NULL, ast_free);
+ RAII_VAR(char *, type, get_content_type(headers), ast_free);
/* Use errno to distinguish errors from no body */
errno = 0;
- if (strcasecmp(get_content_type(headers), "application/json") != 0) {
+ if (ast_strlen_zero(type) || strcasecmp(type, "application/json")) {
/* Content type is not JSON */
return NULL;
}
@@ -704,12 +717,14 @@ struct ast_variable *ast_http_get_post_vars(
struct ast_variable *v, *post_vars=NULL, *prev = NULL;
char *var, *val;
RAII_VAR(char *, buf, NULL, ast_free_ptr);
+ RAII_VAR(char *, type, get_content_type(headers), ast_free);
int res;
/* Use errno to distinguish errors from no params */
errno = 0;
- if (strcasecmp(get_content_type(headers), "application/x-www-form-urlencoded") != 0) {
+ if (ast_strlen_zero(type) ||
+ strcasecmp(type, "application/x-www-form-urlencoded")) {
/* Content type is not form data */
return NULL;
}