aboutsummaryrefslogtreecommitdiff
path: root/src/rest/rest.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 15:15:05 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 15:15:05 +0200
commit65dbd214b80664872f6514fdd663a30e405a6ad6 (patch)
tree532c259a19cad3fe3bf7d83f0dc1ec5bd48fb170 /src/rest/rest.c
parent76299f0b66a3f8ce86df90171b450da6b9cd9b7c (diff)
downloadgnunet-65dbd214b80664872f6514fdd663a30e405a6ad6.tar.gz
gnunet-65dbd214b80664872f6514fdd663a30e405a6ad6.zip
BUILD: Move identity/rest components to service/rest-plugin
Diffstat (limited to 'src/rest/rest.c')
-rw-r--r--src/rest/rest.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/src/rest/rest.c b/src/rest/rest.c
deleted file mode 100644
index 757c0b979..000000000
--- a/src/rest/rest.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2015 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file rest/rest.c
23 * @brief helper library to create JSON REST Objects and handle REST
24 * responses/requests.
25 * @author Martin Schanzenbach
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_rest_lib.h"
30#include "microhttpd.h"
31
32/**
33 * REST Utilities
34 */
35
36int
37GNUNET_REST_namespace_match (const char *url, const char *namespace)
38{
39 return 0 == strncmp (namespace, url, strlen (namespace));
40}
41
42
43struct MHD_Response*
44GNUNET_REST_create_response (const char *data)
45{
46 struct MHD_Response *resp;
47 size_t len;
48
49 if (NULL == data)
50 {
51 len = 0;
52 data = "";
53 }
54 else
55 len = strlen (data);
56 resp = MHD_create_response_from_buffer (len,
57 (void *) data,
58 MHD_RESPMEM_MUST_COPY);
59 return resp;
60}
61
62
63int
64GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
65 const struct GNUNET_REST_RequestHandler *handlers,
66 struct GNUNET_REST_RequestHandlerError *err,
67 void *cls)
68{
69 int count;
70 int i;
71 char *url;
72
73 count = 0;
74 while (NULL != handlers[count].method)
75 count++;
76
77 GNUNET_asprintf (&url, "%s", conn->url);
78 if (url[strlen (url) - 1] == '/')
79 url[strlen (url) - 1] = '\0';
80 for (i = 0; i < count; i++)
81 {
82 if (0 != strcasecmp (conn->method, handlers[i].method))
83 continue;
84 if (strlen (url) < strlen (handlers[i].namespace))
85 continue;
86 if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace))
87 continue;
88 // Match
89 handlers[i].proc (conn, (const char *) url, cls);
90 GNUNET_free (url);
91 return GNUNET_YES;
92 }
93 GNUNET_free (url);
94 err->error_code = MHD_HTTP_BAD_REQUEST;
95 return GNUNET_NO;
96}
97
98
99/* end of rest.c */