aboutsummaryrefslogtreecommitdiff
path: root/lib/req2url.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2015-01-23 12:45:51 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2015-01-23 13:08:19 +0200
commit0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2 (patch)
tree2b617611ddeb6f97d9f316750496ac13c5ce59ad /lib/req2url.c
parentb1824338b366e25756e4c64f04e535684529832d (diff)
downloadeclat-0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2.tar.gz
eclat-0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2.tar.bz2
Implement HTTP POST
* NEWS: Update. * doc/eclat.conf.5: Document http-method. Reorganize description of endpoints and regions. * lib/libeclat.h (ec2_request) <postdata>: New member (eclat_request_finalize): New proto. * lib/req2url.c (eclat_request_to_url): Remove second argument. All uses changed. (eclat_request_finalize): New function. * lib/reqfree.c: Free postdata. * lib/reqsign.c (requestsign4): Implement post. * src/config.c: New configuration statement http-method. * src/eclat.c (use_post): New variable. * src/eclat.h (use_post): New extern. * src/util.c (eclat_send_request): Implement post.
Diffstat (limited to 'lib/req2url.c')
-rw-r--r--lib/req2url.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/lib/req2url.c b/lib/req2url.c
index 25277a2..b9d7512 100644
--- a/lib/req2url.c
+++ b/lib/req2url.c
@@ -21,7 +21,7 @@
struct param_closure {
struct grecs_txtacc *acc;
- int count;
+ int delim;
};
static int
@@ -30,23 +30,22 @@ add_param(void *sym, void *data)
struct ec2_param *p = sym;
struct param_closure *pc = data;
- if (pc->count)
- grecs_txtacc_grow_char(pc->acc, '&');
- ++pc->count;
+ if (pc->delim)
+ grecs_txtacc_grow_char(pc->acc, pc->delim);
+ pc->delim = '&';
grecs_txtacc_grow_string(pc->acc, p->name);
if (p->value) {
grecs_txtacc_grow_char(pc->acc, '=');
grecs_txtacc_grow_string(pc->acc, p->value);
- }
-
+ }
return 0;
}
char *
-eclat_request_to_url(struct ec2_request *req, char **post_params)
+eclat_request_to_url(struct ec2_request *req)
{
struct grecs_txtacc *acc;
- char *ret = NULL, *p;
+ char *url = NULL;
struct param_closure pc;
acc = grecs_txtacc_create();
@@ -58,27 +57,32 @@ eclat_request_to_url(struct ec2_request *req, char **post_params)
grecs_txtacc_grow(acc, req->endpoint, strlen(req->endpoint));
grecs_txtacc_grow(acc, req->uri, strlen(req->uri));
- if (req->flags & EC2_RF_POST) {
- grecs_txtacc_grow_char(acc, 0);
- ret = grecs_txtacc_finish(acc, 1);
- } else {
- grecs_txtacc_grow_char(acc, '?');
- }
-
- /* Add other parameters */
+ /* Add parameters */
pc.acc = acc;
- pc.count = 0;
+ pc.delim = '?';
grecs_symtab_enumerate(req->params, add_param, &pc);
grecs_txtacc_grow_char(acc, 0);
-
- if (!ret)
- ret = grecs_txtacc_finish(acc, 1);
- else
- *post_params = grecs_txtacc_finish(acc, 1);
-
+ url = grecs_txtacc_finish(acc, 1);
grecs_txtacc_free(acc);
- return ret;
+ return url;
}
+void
+eclat_request_finalize(struct ec2_request *req)
+{
+ struct param_closure pc;
+
+ if (!(req->flags & EC2_RF_POST) || req->postdata)
+ return;
+
+ eclat_request_encode(req);
+ pc.acc = grecs_txtacc_create();
+ pc.delim = 0;
+ grecs_symtab_enumerate(req->params, add_param, &pc);
+ grecs_txtacc_grow_char(pc.acc, 0);
+ req->postdata = grecs_txtacc_finish(pc.acc, 1);
+ grecs_txtacc_free(pc.acc);
+ grecs_symtab_clear(req->params);
+}

Return to:

Send suggestions and report system problems to the System administrator.