From 19c380f237708910a12f14e98960919e9fe6d865 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Wed, 25 Mar 2015 17:19:54 +0000 Subject: -more rest handling --- src/rest/rest.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/rest/rest.c') diff --git a/src/rest/rest.c b/src/rest/rest.c index 0b843ec61..ec46e1273 100644 --- a/src/rest/rest.c +++ b/src/rest/rest.c @@ -68,6 +68,7 @@ struct JsonApiResponse int res_count; }; + /** * JSON API */ @@ -296,4 +297,39 @@ GNUNET_REST_create_json_response (const char *data) } +int +GNUNET_REST_handle_request (struct RestConnectionDataHandle *conn, + const struct GNUNET_REST_RestConnectionHandler *handlers, + void *cls) +{ + int count; + int i; + char *url; + + count = 0; + + while (NULL != handlers[count].method) + count++; + + GNUNET_asprintf (&url, "%s", conn->url); + if (url[strlen (url)-1] == '/') + url[strlen (url)-1] = '\0'; + + for (i = 0; i < count; i++) + { + if (0 != strcasecmp (conn->method, handlers[count].method)) + break; + if (strlen (url) < strlen (handlers[count].namespace)) + break; + if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[count].namespace)) + break; + //Match + handlers[count].proc (conn, (const char*)url, cls); + GNUNET_free (url); + return GNUNET_YES; + } + GNUNET_free (url); + return GNUNET_NO; +} + /* end of rest.c */ -- cgit v1.2.3