GNUnet 0.22.1
copying_plugin.c
Go to the documentation of this file.
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 */
27#include "platform.h"
28#include "gnunet_rest_plugin.h"
29#include <gnunet_rest_lib.h>
30#include "copying_plugin.h"
31
32#define GNUNET_REST_API_NS_COPYING "/copying"
33
34#define GNUNET_REST_COPYING_TEXT \
35 "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"
36
40struct Plugin
41{
42 const struct GNUNET_CONFIGURATION_Handle *cfg;
43};
44
45struct RequestHandle
46{
50 struct RequestHandle *next;
51
55 struct RequestHandle *prev;
56
61
66
70 void *proc_cls;
71
75 int response_code;
76};
77
82
87
93static void
95{
97 "Cleaning up\n");
100 handle);
102}
103
104
110static void
112 const char*url,
113 void *cls)
114{
115 struct MHD_Response *resp;
116 struct RequestHandle *handle = cls;
117
119 handle->proc (handle->proc_cls,
120 resp,
123}
124
125
131static void
133 const char*url,
134 void *cls)
135{
136 struct MHD_Response *resp;
137 struct RequestHandle *handle = cls;
138
139 resp = GNUNET_REST_create_response (NULL);
140 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
141 "Access-Control-Allow-Methods",
142 MHD_HTTP_METHOD_GET));
143 handle->proc (handle->proc_cls,
144 resp,
147}
148
149
163 struct GNUNET_REST_RequestHandle *conndata_handle,
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 },
171 };
172 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
174
175 handle->proc_cls = proc_cls;
176 handle->proc = proc;
177 handle->rest_handle = conndata_handle;
180 handle);
181 return GNUNET_REST_handle_request (conndata_handle,
182 handlers,
183 &err,
184 handle);
185}
186
187
194void*
196{
197 static struct Plugin plugin;
198
199 struct GNUNET_REST_Plugin *api;
200
201 if (NULL != plugin.cfg)
202 return NULL; /* can only initialize once! */
203 memset (&plugin, 0, sizeof(struct Plugin));
204 plugin.cfg = c;
205 api = GNUNET_new (struct GNUNET_REST_Plugin);
206 api->cls = &plugin;
209 _ ("COPYING REST API initialized\n"));
210 return api;
211}
212
213
220void
222{
223 struct Plugin *plugin = api->cls;
224
225 while (NULL != requests_head)
227 plugin->cfg = NULL;
230 "COPYING REST plugin is finished\n");
231}
232
233
234/* end of plugin_rest_copying.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
#define GNUNET_REST_COPYING_TEXT
static struct RequestHandle * requests_head
DLL.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
enum GNUNET_GenericReturnValue REST_copying_process_request(void *plugin, struct GNUNET_REST_RequestHandle *conndata_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
void REST_copying_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
#define GNUNET_REST_API_NS_COPYING
static struct RequestHandle * requests_tail
DLL.
void * REST_copying_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void get_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
API for helper library to parse/create REST.
GNUnet service REST plugin header.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
Definition: rest.c:64
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_HANDLER_END
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
void * cls
Closure for all of the callbacks.
struct returned by the initialization function of the plugin
void * cls
The closure of the plugin.
const char * name
Plugin name.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
The request handle.
Definition: config_plugin.c:47
struct RequestHandle * prev
DLL.
Definition: config_plugin.c:56
int response_code
HTTP response code.
Definition: config_plugin.c:76
void * proc_cls
The closure of the result processor.
Definition: config_plugin.c:71
GNUNET_REST_ResultProcessor proc
The plugin result processor.
Definition: config_plugin.c:66
struct RequestHandle * next
DLL.
Definition: config_plugin.c:51
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
Definition: config_plugin.c:61
char * url
The URL.
Definition: config_plugin.c:81