aboutsummaryrefslogtreecommitdiff
path: root/src/rest/plugin_rest_copying.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/plugin_rest_copying.c
parent76299f0b66a3f8ce86df90171b450da6b9cd9b7c (diff)
downloadgnunet-65dbd214b80664872f6514fdd663a30e405a6ad6.tar.gz
gnunet-65dbd214b80664872f6514fdd663a30e405a6ad6.zip
BUILD: Move identity/rest components to service/rest-plugin
Diffstat (limited to 'src/rest/plugin_rest_copying.c')
-rw-r--r--src/rest/plugin_rest_copying.c238
1 files changed, 0 insertions, 238 deletions
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c
deleted file mode 100644
index 52783a81a..000000000
--- a/src/rest/plugin_rest_copying.c
+++ /dev/null
@@ -1,238 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2018 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 * @author Martin Schanzenbach
22 * @file gns/plugin_rest_copying.c
23 * @brief REST plugin that serves licensing information.
24 *
25 */
26
27#include "platform.h"
28#include "gnunet_rest_plugin.h"
29#include <gnunet_rest_lib.h>
30
31#define GNUNET_REST_API_NS_COPYING "/copying"
32
33#define GNUNET_REST_COPYING_TEXT \
34 "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"
35
36/**
37 * @brief struct returned by the initialization function of the plugin
38 */
39struct Plugin
40{
41 const struct GNUNET_CONFIGURATION_Handle *cfg;
42};
43
44const struct GNUNET_CONFIGURATION_Handle *cfg;
45
46struct RequestHandle
47{
48 /**
49 * DLL
50 */
51 struct RequestHandle *next;
52
53 /**
54 * DLL
55 */
56 struct RequestHandle *prev;
57
58 /**
59 * Handle to rest request
60 */
61 struct GNUNET_REST_RequestHandle *rest_handle;
62
63 /**
64 * The plugin result processor
65 */
66 GNUNET_REST_ResultProcessor proc;
67
68 /**
69 * The closure of the result processor
70 */
71 void *proc_cls;
72
73 /**
74 * HTTP response code
75 */
76 int response_code;
77};
78
79/**
80 * DLL
81 */
82static struct RequestHandle *requests_head;
83
84/**
85 * DLL
86 */
87static struct RequestHandle *requests_tail;
88
89/**
90 * Cleanup request handle.
91 *
92 * @param handle Handle to clean up
93 */
94static void
95cleanup_handle (struct RequestHandle *handle)
96{
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
98 "Cleaning up\n");
99 GNUNET_CONTAINER_DLL_remove (requests_head,
100 requests_tail,
101 handle);
102 GNUNET_free (handle);
103}
104
105
106/**
107 * Handle rest request
108 *
109 * @param handle the lookup handle
110 */
111static void
112get_cont (struct GNUNET_REST_RequestHandle *con_handle,
113 const char*url,
114 void *cls)
115{
116 struct MHD_Response *resp;
117 struct RequestHandle *handle = cls;
118
119 resp = GNUNET_REST_create_response (GNUNET_REST_COPYING_TEXT);
120 handle->proc (handle->proc_cls,
121 resp,
122 MHD_HTTP_OK);
123 cleanup_handle (handle);
124}
125
126
127/**
128 * Handle rest request
129 *
130 * @param handle the lookup handle
131 */
132static void
133options_cont (struct GNUNET_REST_RequestHandle *con_handle,
134 const char*url,
135 void *cls)
136{
137 struct MHD_Response *resp;
138 struct RequestHandle *handle = cls;
139
140 resp = GNUNET_REST_create_response (NULL);
141 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
142 "Access-Control-Allow-Methods",
143 MHD_HTTP_METHOD_GET));
144 handle->proc (handle->proc_cls,
145 resp,
146 MHD_HTTP_OK);
147 cleanup_handle (handle);
148}
149
150
151/**
152 * Function processing the REST call
153 *
154 * @param method HTTP method
155 * @param url URL of the HTTP request
156 * @param data body of the HTTP request (optional)
157 * @param data_size length of the body
158 * @param proc callback function for the result
159 * @param proc_cls closure for @a proc
160 * @return #GNUNET_OK if request accepted
161 */
162static enum GNUNET_GenericReturnValue
163rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
164 GNUNET_REST_ResultProcessor proc,
165 void *proc_cls)
166{
167 static const struct GNUNET_REST_RequestHandler handlers[] = {
168 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont },
169 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont },
170 GNUNET_REST_HANDLER_END
171 };
172 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
173 struct GNUNET_REST_RequestHandlerError err;
174
175 handle->proc_cls = proc_cls;
176 handle->proc = proc;
177 handle->rest_handle = conndata_handle;
178 GNUNET_CONTAINER_DLL_insert (requests_head,
179 requests_tail,
180 handle);
181 return GNUNET_REST_handle_request (conndata_handle,
182 handlers,
183 &err,
184 handle);
185}
186
187
188/**
189 * Entry point for the plugin.
190 *
191 * @param cls the "struct GNUNET_NAMESTORE_PluginEnvironment*"
192 * @return NULL on error, otherwise the plugin context
193 */
194void *
195libgnunet_plugin_rest_copying_init (void *cls)
196{
197 static struct Plugin plugin;
198
199 cfg = cls;
200 struct GNUNET_REST_Plugin *api;
201
202 if (NULL != plugin.cfg)
203 return NULL; /* can only initialize once! */
204 memset (&plugin, 0, sizeof(struct Plugin));
205 plugin.cfg = cfg;
206 api = GNUNET_new (struct GNUNET_REST_Plugin);
207 api->cls = &plugin;
208 api->name = GNUNET_REST_API_NS_COPYING;
209 api->process_request = &rest_copying_process_request;
210 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
211 _ ("COPYING REST API initialized\n"));
212 return api;
213}
214
215
216/**
217 * Exit point from the plugin.
218 *
219 * @param cls the plugin context (as returned by "init")
220 * @return always NULL
221 */
222void *
223libgnunet_plugin_rest_copying_done (void *cls)
224{
225 struct GNUNET_REST_Plugin *api = cls;
226 struct Plugin *plugin = api->cls;
227
228 while (NULL != requests_head)
229 cleanup_handle (requests_head);
230 plugin->cfg = NULL;
231 GNUNET_free (api);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "COPYING REST plugin is finished\n");
234 return NULL;
235}
236
237
238/* end of plugin_rest_copying.c */