diff options
Diffstat (limited to 'src/rest/rest.c')
-rw-r--r-- | src/rest/rest.c | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/src/rest/rest.c b/src/rest/rest.c index b0c2da6c2..44af5f2e0 100644 --- a/src/rest/rest.c +++ b/src/rest/rest.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -33,17 +33,17 @@ | |||
33 | * REST Utilities | 33 | * REST Utilities |
34 | */ | 34 | */ |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Check if namespace is in URL. | 37 | * Check if namespace is in URL. |
38 | * | 38 | * |
39 | * @param url URL to check | 39 | * @param url URL to check |
40 | * @param namespace namespace to check against | 40 | * @param namespace namespace to check against |
41 | * @retun GNUNET_YES if namespace matches | 41 | * @retun GNUNET_YES if namespace matches |
42 | */ | 42 | */ |
43 | int | 43 | int |
44 | GNUNET_REST_namespace_match (const char *url, const char *namespace) | 44 | GNUNET_REST_namespace_match(const char *url, const char *namespace) |
45 | { | 45 | { |
46 | return 0 == strncmp (namespace, url, strlen (namespace)); | 46 | return 0 == strncmp(namespace, url, strlen(namespace)); |
47 | } | 47 | } |
48 | 48 | ||
49 | /** | 49 | /** |
@@ -53,30 +53,29 @@ GNUNET_REST_namespace_match (const char *url, const char *namespace) | |||
53 | * @retun MHD response | 53 | * @retun MHD response |
54 | */ | 54 | */ |
55 | struct MHD_Response* | 55 | struct MHD_Response* |
56 | GNUNET_REST_create_response (const char *data) | 56 | GNUNET_REST_create_response(const char *data) |
57 | { | 57 | { |
58 | struct MHD_Response *resp; | 58 | struct MHD_Response *resp; |
59 | size_t len; | 59 | size_t len; |
60 | 60 | ||
61 | if (NULL == data) | 61 | if (NULL == data) |
62 | { | 62 | { |
63 | len = 0; | 63 | len = 0; |
64 | data = ""; | 64 | data = ""; |
65 | } | 65 | } |
66 | else | 66 | else |
67 | len = strlen (data); | 67 | len = strlen(data); |
68 | resp = MHD_create_response_from_buffer (len, | 68 | resp = MHD_create_response_from_buffer(len, |
69 | (void*)data, | 69 | (void*)data, |
70 | MHD_RESPMEM_MUST_COPY); | 70 | MHD_RESPMEM_MUST_COPY); |
71 | return resp; | 71 | return resp; |
72 | |||
73 | } | 72 | } |
74 | 73 | ||
75 | int | 74 | int |
76 | GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn, | 75 | GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, |
77 | const struct GNUNET_REST_RequestHandler *handlers, | 76 | const struct GNUNET_REST_RequestHandler *handlers, |
78 | struct GNUNET_REST_RequestHandlerError *err, | 77 | struct GNUNET_REST_RequestHandlerError *err, |
79 | void *cls) | 78 | void *cls) |
80 | { | 79 | { |
81 | int count; | 80 | int count; |
82 | int i; | 81 | int i; |
@@ -86,23 +85,23 @@ GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn, | |||
86 | while (NULL != handlers[count].method) | 85 | while (NULL != handlers[count].method) |
87 | count++; | 86 | count++; |
88 | 87 | ||
89 | GNUNET_asprintf (&url, "%s", conn->url); | 88 | GNUNET_asprintf(&url, "%s", conn->url); |
90 | if (url[strlen (url)-1] == '/') | 89 | if (url[strlen(url) - 1] == '/') |
91 | url[strlen (url)-1] = '\0'; | 90 | url[strlen(url) - 1] = '\0'; |
92 | for (i = 0; i < count; i++) | 91 | for (i = 0; i < count; i++) |
93 | { | 92 | { |
94 | if (0 != strcasecmp (conn->method, handlers[i].method)) | 93 | if (0 != strcasecmp(conn->method, handlers[i].method)) |
95 | continue; | 94 | continue; |
96 | if (strlen (url) < strlen (handlers[i].namespace)) | 95 | if (strlen(url) < strlen(handlers[i].namespace)) |
97 | continue; | 96 | continue; |
98 | if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace)) | 97 | if (GNUNET_NO == GNUNET_REST_namespace_match(url, handlers[i].namespace)) |
99 | continue; | 98 | continue; |
100 | //Match | 99 | //Match |
101 | handlers[i].proc (conn, (const char*)url, cls); | 100 | handlers[i].proc(conn, (const char*)url, cls); |
102 | GNUNET_free (url); | 101 | GNUNET_free(url); |
103 | return GNUNET_YES; | 102 | return GNUNET_YES; |
104 | } | 103 | } |
105 | GNUNET_free (url); | 104 | GNUNET_free(url); |
106 | err->error_code = MHD_HTTP_BAD_REQUEST; | 105 | err->error_code = MHD_HTTP_BAD_REQUEST; |
107 | return GNUNET_NO; | 106 | return GNUNET_NO; |
108 | } | 107 | } |