aboutsummaryrefslogtreecommitdiff
path: root/src/rest
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-13 09:59:43 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-13 09:59:43 +0000
commit74f9b73e5592424165236164fbb8e65d03399614 (patch)
treee2c293500d6dc565ee3635b43cf974a4a976c243 /src/rest
parent0bcb81843084f1b2cde5af408adcddebfb4c5875 (diff)
downloadgnunet-74f9b73e5592424165236164fbb8e65d03399614.tar.gz
gnunet-74f9b73e5592424165236164fbb8e65d03399614.zip
-bugfixes, change plugin call
Diffstat (limited to 'src/rest')
-rw-r--r--src/rest/gnunet-rest-server.c102
1 files changed, 78 insertions, 24 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index e2f1f5c57..4af7c458b 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -56,8 +56,7 @@
56#define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 56#define MHD_CACHE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
57 57
58#define GN_REST_STATE_INIT 0 58#define GN_REST_STATE_INIT 0
59#define GN_REST_STATE_UPLOAD 1 59#define GN_REST_STATE_PROCESSING 1
60#define GN_REST_STATE_RECV 2
61 60
62/** 61/**
63 * The task ID 62 * The task ID
@@ -125,6 +124,8 @@ struct MhdConnectionHandle
125 124
126 struct GNUNET_REST_Plugin *plugin; 125 struct GNUNET_REST_Plugin *plugin;
127 126
127 struct RestConnectionDataHandle *data_handle;
128
128 int status; 129 int status;
129 130
130 int state; 131 int state;
@@ -181,6 +182,64 @@ plugin_callback (void *cls,
181 run_mhd_now(); 182 run_mhd_now();
182} 183}
183 184
185int
186cleanup_url_map (void *cls,
187 const struct GNUNET_HashCode *key,
188 void *value)
189{
190 GNUNET_free_non_null (value);
191 return GNUNET_YES;
192}
193
194void
195cleanup_handle (struct MhdConnectionHandle *handle)
196{
197 if (NULL != handle->response)
198 MHD_destroy_response (handle->response);
199 if (NULL != handle->data_handle)
200 {
201 if (NULL != handle->data_handle->url_param_map)
202 {
203 GNUNET_CONTAINER_multihashmap_iterate (handle->data_handle->url_param_map,
204 &cleanup_url_map,
205 NULL);
206 GNUNET_CONTAINER_multihashmap_destroy (handle->data_handle->url_param_map);
207 }
208 GNUNET_free (handle->data_handle);
209 }
210 GNUNET_free (handle);
211
212}
213
214int
215url_iterator (void *cls,
216 enum MHD_ValueKind kind,
217 const char *key,
218 const char *value)
219{
220 struct RestConnectionDataHandle *handle = cls;
221 struct GNUNET_HashCode hkey;
222 char *val;
223 if (NULL == handle->url_param_map)
224 {
225 handle->url_param_map = GNUNET_CONTAINER_multihashmap_create (16,
226 GNUNET_NO);
227 }
228 GNUNET_CRYPTO_hash (key, strlen (key), &hkey);
229 GNUNET_asprintf (&val, "%s", value);
230 if (GNUNET_OK !=
231 GNUNET_CONTAINER_multihashmap_put (handle->url_param_map,
232 &hkey,
233 val,
234 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
235 {
236 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
237 "Could not load add url param `%s'=%s\n",
238 key, value);
239 }
240 return MHD_YES;
241}
242
184/* ********************************* MHD response generation ******************* */ 243/* ********************************* MHD response generation ******************* */
185 244
186/** 245/**
@@ -219,6 +278,7 @@ create_response (void *cls,
219 char *plugin_name; 278 char *plugin_name;
220 struct GNUNET_HashCode key; 279 struct GNUNET_HashCode key;
221 struct MhdConnectionHandle *con_handle; 280 struct MhdConnectionHandle *con_handle;
281 struct RestConnectionDataHandle *rest_conndata_handle;
222 282
223 con_handle = *con_cls; 283 con_handle = *con_cls;
224 284
@@ -258,29 +318,22 @@ create_response (void *cls,
258 } 318 }
259 if (GN_REST_STATE_INIT == con_handle->state) 319 if (GN_REST_STATE_INIT == con_handle->state)
260 { 320 {
261 if (0 != *upload_data_size) 321 rest_conndata_handle = GNUNET_new (struct RestConnectionDataHandle);
262 { 322 rest_conndata_handle->method = meth;
263 con_handle->state = GN_REST_STATE_UPLOAD; 323 rest_conndata_handle->url = url;
264 324 rest_conndata_handle->data = upload_data;
265 con_handle->plugin->process_request (meth, 325 rest_conndata_handle->data_size = *upload_data_size;
266 url, 326 con_handle->data_handle = rest_conndata_handle;
267 upload_data, 327 MHD_get_connection_values (con,
268 *upload_data_size, 328 MHD_GET_ARGUMENT_KIND,
269 &plugin_callback, 329 &url_iterator,
270 con_handle); 330 rest_conndata_handle);
271 *upload_data_size = 0; 331 con_handle->state = GN_REST_STATE_PROCESSING;
332 con_handle->plugin->process_request (rest_conndata_handle,
333 &plugin_callback,
334 con_handle);
335 *upload_data_size = 0;
272 336
273 }
274 else
275 {
276 con_handle->state = GN_REST_STATE_RECV;
277 con_handle->plugin->process_request (meth,
278 url,
279 NULL,
280 0,
281 &plugin_callback,
282 con_handle);
283 }
284 } 337 }
285 if (NULL != con_handle->response) 338 if (NULL != con_handle->response)
286 { 339 {
@@ -296,6 +349,7 @@ create_response (void *cls,
296 MHD_HTTP_BAD_REQUEST, 349 MHD_HTTP_BAD_REQUEST,
297 con_handle->response); 350 con_handle->response);
298 } 351 }
352 cleanup_handle (con_handle);
299 } 353 }
300 return MHD_YES; 354 return MHD_YES;
301} 355}