summaryrefslogtreecommitdiff
path: root/main/http.c
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-11-08 17:29:53 +0000
committerDavid M. Lee <dlee@digium.com>2013-11-08 17:29:53 +0000
commit97a8debd90e4d31f15803dc26e8884bf34d7650e (patch)
tree0fd89838b26a72cfb96494ef1091fe1a5642b98d /main/http.c
parent2564ed26f79d374fc92f5cf08ec6b5f32920be99 (diff)
ari: Add application/x-www-form-urlencoded parameter support
ARI POST calls only accept parameters via the URL's query string. While this works, it's atypical for HTTP API's in general, and specifically frowned upon with RESTful API's. This patch adds parsing for application/x-www-form-urlencoded request bodies if they are sent in with the request. Any variables parsed this way are prepended to the variable list supplied by the query string. (closes issue ASTERISK-22743) Review: https://reviewboard.asterisk.org/r/2986/ ........ Merged revisions 402555 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402557 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/http.c')
-rw-r--r--main/http.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/main/http.c b/main/http.c
index e687d037c..a9c8a3564 100644
--- a/main/http.c
+++ b/main/http.c
@@ -616,9 +616,13 @@ struct ast_variable *ast_http_get_post_vars(
{
int content_length = 0;
struct ast_variable *v, *post_vars=NULL, *prev = NULL;
- char *buf, *var, *val;
+ char *var, *val;
+ RAII_VAR(char *, buf, NULL, ast_free_ptr);
int res;
+ /* Use errno to distinguish errors from no params */
+ errno = 0;
+
for (v = headers; v; v = v->next) {
if (!strcasecmp(v->name, "Content-Type")) {
if (strcasecmp(v->value, "application/x-www-form-urlencoded")) {
@@ -640,22 +644,25 @@ struct ast_variable *ast_http_get_post_vars(
}
if (content_length > MAX_POST_CONTENT - 1) {
- ast_log(LOG_WARNING, "Excessively long HTTP content. %d is greater than our max of %d\n",
- content_length, MAX_POST_CONTENT);
- ast_http_send(ser, AST_HTTP_POST, 413, "Request Entity Too Large", NULL, NULL, 0, 0);
+ ast_log(LOG_WARNING,
+ "Excessively long HTTP content. (%d > %d)\n",
+ content_length, MAX_POST_CONTENT);
+ errno = EFBIG;
return NULL;
}
buf = ast_malloc(content_length + 1);
if (!buf) {
+ /* malloc sets errno to ENOMEM */
return NULL;
}
res = fread(buf, 1, content_length, ser->f);
if (res < content_length) {
/* Error, distinguishable by ferror() or feof(), but neither
- * is good. */
- goto done;
+ * is good. Treat either one as I/O error */
+ errno = EIO;
+ return NULL;
}
buf[content_length] = '\0';
@@ -677,8 +684,6 @@ struct ast_variable *ast_http_get_post_vars(
}
}
-done:
- ast_free(buf);
return post_vars;
}