diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-01-23 12:45:51 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-01-23 13:08:19 +0200 |
commit | 0ed8a2275a3a6cda553b82e9e0222b9d3b8b3ff2 (patch) | |
tree | 2b617611ddeb6f97d9f316750496ac13c5ce59ad /lib | |
parent | b1824338b366e25756e4c64f04e535684529832d (diff) | |
download | eclat-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')
-rw-r--r-- | lib/libeclat.h | 12 | ||||
-rw-r--r-- | lib/req2url.c | 52 | ||||
-rw-r--r-- | lib/reqfree.c | 1 | ||||
-rw-r--r-- | lib/reqsign.c | 4 |
4 files changed, 37 insertions, 32 deletions
diff --git a/lib/libeclat.h b/lib/libeclat.h index a5c8c79..b33f0a2 100644 --- a/lib/libeclat.h +++ b/lib/libeclat.h | |||
@@ -94,6 +94,7 @@ struct ec2_request { | |||
94 | char *uri; /* URI without parameters */ | 94 | char *uri; /* URI without parameters */ |
95 | struct grecs_symtab *params; /* Query parameters */ | 95 | struct grecs_symtab *params; /* Query parameters */ |
96 | struct grecs_list *headers; /* Query headers */ | 96 | struct grecs_list *headers; /* Query headers */ |
97 | char *postdata; | ||
97 | char *region; | 98 | char *region; |
98 | char *access_key; | 99 | char *access_key; |
99 | char *token; | 100 | char *token; |
@@ -104,18 +105,19 @@ struct ec2_request *eclat_request_create(int flags, const char *endpoint, | |||
104 | const char *uri, char const *region, | 105 | const char *uri, char const *region, |
105 | char const *access_key, char const *token); | 106 | char const *access_key, char const *token); |
106 | void eclat_request_free(struct ec2_request *); | 107 | void eclat_request_free(struct ec2_request *); |
107 | void eclat_request_add_param(struct ec2_request *q, const char *name, | 108 | void eclat_request_add_param(struct ec2_request *req, const char *name, |
108 | const char *value); | 109 | const char *value); |
109 | void eclat_request_add_param_encoded(struct ec2_request *q, const char *name, | 110 | void eclat_request_add_param_encoded(struct ec2_request *req, const char *name, |
110 | const char *value); | 111 | const char *value); |
111 | void eclat_request_add_header(struct ec2_request *q, const char *name, | 112 | void eclat_request_add_header(struct ec2_request *req, const char *name, |
112 | const char *value); | 113 | const char *value); |
113 | 114 | ||
114 | void eclat_request_sign(struct ec2_request *req, char *secret, char *version); | 115 | void eclat_request_sign(struct ec2_request *req, char *secret, char *version); |
115 | 116 | ||
116 | char *eclat_request_to_url(struct ec2_request *req, char **post_params); | 117 | char *eclat_request_to_url(struct ec2_request *req); |
117 | 118 | ||
118 | void eclat_request_encode(struct ec2_request *q); | 119 | void eclat_request_encode(struct ec2_request *req); |
120 | void eclat_request_finalize(struct ec2_request *req); | ||
119 | 121 | ||
120 | 122 | ||
121 | typedef struct eclat_partial_tree *eclat_partial_tree_t; | 123 | typedef struct eclat_partial_tree *eclat_partial_tree_t; |
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 @@ | |||
21 | 21 | ||
22 | struct param_closure { | 22 | struct param_closure { |
23 | struct grecs_txtacc *acc; | 23 | struct grecs_txtacc *acc; |
24 | int count; | 24 | int delim; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | static int | 27 | static int |
@@ -30,23 +30,22 @@ add_param(void *sym, void *data) | |||
30 | struct ec2_param *p = sym; | 30 | struct ec2_param *p = sym; |
31 | struct param_closure *pc = data; | 31 | struct param_closure *pc = data; |
32 | 32 | ||
33 | if (pc->count) | 33 | if (pc->delim) |
34 | grecs_txtacc_grow_char(pc->acc, '&'); | 34 | grecs_txtacc_grow_char(pc->acc, pc->delim); |
35 | ++pc->count; | 35 | pc->delim = '&'; |
36 | grecs_txtacc_grow_string(pc->acc, p->name); | 36 | grecs_txtacc_grow_string(pc->acc, p->name); |
37 | if (p->value) { | 37 | if (p->value) { |
38 | grecs_txtacc_grow_char(pc->acc, '='); | 38 | grecs_txtacc_grow_char(pc->acc, '='); |
39 | grecs_txtacc_grow_string(pc->acc, p->value); | 39 | grecs_txtacc_grow_string(pc->acc, p->value); |
40 | } | 40 | } |
41 | |||
42 | return 0; | 41 | return 0; |
43 | } | 42 | } |
44 | 43 | ||
45 | char * | 44 | char * |
46 | eclat_request_to_url(struct ec2_request *req, char **post_params) | 45 | eclat_request_to_url(struct ec2_request *req) |
47 | { | 46 | { |
48 | struct grecs_txtacc *acc; | 47 | struct grecs_txtacc *acc; |
49 | char *ret = NULL, *p; | 48 | char *url = NULL; |
50 | struct param_closure pc; | 49 | struct param_closure pc; |
51 | 50 | ||
52 | acc = grecs_txtacc_create(); | 51 | acc = grecs_txtacc_create(); |
@@ -58,27 +57,32 @@ eclat_request_to_url(struct ec2_request *req, char **post_params) | |||
58 | grecs_txtacc_grow(acc, req->endpoint, strlen(req->endpoint)); | 57 | grecs_txtacc_grow(acc, req->endpoint, strlen(req->endpoint)); |
59 | grecs_txtacc_grow(acc, req->uri, strlen(req->uri)); | 58 | grecs_txtacc_grow(acc, req->uri, strlen(req->uri)); |
60 | 59 | ||
61 | if (req->flags & EC2_RF_POST) { | 60 | /* Add parameters */ |
62 | grecs_txtacc_grow_char(acc, 0); | ||
63 | ret = grecs_txtacc_finish(acc, 1); | ||
64 | } else { | ||
65 | grecs_txtacc_grow_char(acc, '?'); | ||
66 | } | ||
67 | |||
68 | /* Add other parameters */ | ||
69 | pc.acc = acc; | 61 | pc.acc = acc; |
70 | pc.count = 0; | 62 | pc.delim = '?'; |
71 | grecs_symtab_enumerate(req->params, add_param, &pc); | 63 | grecs_symtab_enumerate(req->params, add_param, &pc); |
72 | 64 | ||
73 | grecs_txtacc_grow_char(acc, 0); | 65 | grecs_txtacc_grow_char(acc, 0); |
74 | 66 | url = grecs_txtacc_finish(acc, 1); | |
75 | if (!ret) | ||
76 | ret = grecs_txtacc_finish(acc, 1); | ||
77 | else | ||
78 | *post_params = grecs_txtacc_finish(acc, 1); | ||
79 | |||
80 | grecs_txtacc_free(acc); | 67 | grecs_txtacc_free(acc); |
81 | 68 | ||
82 | return ret; | 69 | return url; |
83 | } | 70 | } |
84 | 71 | ||
72 | void | ||
73 | eclat_request_finalize(struct ec2_request *req) | ||
74 | { | ||
75 | struct param_closure pc; | ||
76 | |||
77 | if (!(req->flags & EC2_RF_POST) || req->postdata) | ||
78 | return; | ||
79 | |||
80 | eclat_request_encode(req); | ||
81 | pc.acc = grecs_txtacc_create(); | ||
82 | pc.delim = 0; | ||
83 | grecs_symtab_enumerate(req->params, add_param, &pc); | ||
84 | grecs_txtacc_grow_char(pc.acc, 0); | ||
85 | req->postdata = grecs_txtacc_finish(pc.acc, 1); | ||
86 | grecs_txtacc_free(pc.acc); | ||
87 | grecs_symtab_clear(req->params); | ||
88 | } | ||
diff --git a/lib/reqfree.c b/lib/reqfree.c index f5145a4..ee0611e 100644 --- a/lib/reqfree.c +++ b/lib/reqfree.c | |||
@@ -23,6 +23,7 @@ eclat_request_free(struct ec2_request *req) | |||
23 | { | 23 | { |
24 | free(req->endpoint); | 24 | free(req->endpoint); |
25 | free(req->uri); | 25 | free(req->uri); |
26 | free(req->postdata); | ||
26 | grecs_symtab_free(req->params); | 27 | grecs_symtab_free(req->params); |
27 | free(req); | 28 | free(req); |
28 | } | 29 | } |
diff --git a/lib/reqsign.c b/lib/reqsign.c index f3083c6..9572961 100644 --- a/lib/reqsign.c +++ b/lib/reqsign.c | |||
@@ -252,9 +252,7 @@ requestsign4(struct ec2_request *req, char *secret) | |||
252 | grecs_txtacc_grow_char(acc, '\n'); | 252 | grecs_txtacc_grow_char(acc, '\n'); |
253 | /* Payload hash */ | 253 | /* Payload hash */ |
254 | if (req->flags & EC2_RF_POST) { | 254 | if (req->flags & EC2_RF_POST) { |
255 | /* FIXME: payload = req->request */ | 255 | payload = req->postdata; |
256 | err("%s:%d: POST is not yet implemented", __FILE__, __LINE__); | ||
257 | abort(); | ||
258 | } else | 256 | } else |
259 | payload = ""; | 257 | payload = ""; |
260 | 258 | ||