aboutsummaryrefslogtreecommitdiff
path: root/lib/req2url.c
diff options
context:
space:
mode:
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.