GNUnet 0.22.2
copying_plugin.c File Reference
#include "platform.h"
#include "gnunet_rest_plugin.h"
#include <gnunet_rest_lib.h>
#include "copying_plugin.h"
Include dependency graph for copying_plugin.c:

Go to the source code of this file.

Data Structures

struct  Plugin
 Handle for a plugin. More...
 
struct  RequestHandle
 The request handle. More...
 

Macros

#define GNUNET_REST_API_NS_COPYING   "/copying"
 
#define GNUNET_REST_COPYING_TEXT    "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"
 

Functions

static void cleanup_handle (struct RequestHandle *handle)
 Cleanup request handle. More...
 
static void get_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle rest request. More...
 
static void options_cont (struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
 Handle rest request. More...
 
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. More...
 
void * REST_copying_init (const struct GNUNET_CONFIGURATION_Handle *c)
 Entry point for the plugin. More...
 
void REST_copying_done (struct GNUNET_REST_Plugin *api)
 Exit point from the plugin. More...
 

Variables

static struct RequestHandlerequests_head
 DLL. More...
 
static struct RequestHandlerequests_tail
 DLL. More...
 

Macro Definition Documentation

◆ GNUNET_REST_API_NS_COPYING

#define GNUNET_REST_API_NS_COPYING   "/copying"

Definition at line 32 of file copying_plugin.c.

◆ GNUNET_REST_COPYING_TEXT

#define GNUNET_REST_COPYING_TEXT    "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"

Definition at line 34 of file copying_plugin.c.

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( struct RequestHandle handle)
static

Cleanup request handle.

Parameters
handleHandle to clean up

Definition at line 94 of file copying_plugin.c.

95{
97 "Cleaning up\n");
100 handle);
102}
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, handle, requests_head, and requests_tail.

Referenced by get_cont(), options_cont(), and REST_copying_done().

Here is the caller graph for this function:

◆ get_cont()

static void get_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Handle rest request.

Parameters
handlethe lookup handle

Definition at line 111 of file copying_plugin.c.

114{
115 struct MHD_Response *resp;
116 struct RequestHandle *handle = cls;
117
119 handle->proc (handle->proc_cls,
120 resp,
121 MHD_HTTP_OK);
123}
#define GNUNET_REST_COPYING_TEXT
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
The request handle.
Definition: config_plugin.c:47

References cleanup_handle(), GNUNET_REST_COPYING_TEXT, GNUNET_REST_create_response(), and handle.

Referenced by REST_copying_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ options_cont()

static void options_cont ( struct GNUNET_REST_RequestHandle con_handle,
const char *  url,
void *  cls 
)
static

Handle rest request.

Parameters
handlethe lookup handle

Definition at line 132 of file copying_plugin.c.

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,
145 MHD_HTTP_OK);
147}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References cleanup_handle(), GNUNET_assert, GNUNET_REST_create_response(), and handle.

Referenced by REST_copying_process_request().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REST_copying_process_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.

Parameters
methodHTTP method
urlURL of the HTTP request
databody of the HTTP request (optional)
data_sizelength of the body
proccallback function for the result
proc_clsclosure for proc
Returns
GNUNET_OK if request accepted

Definition at line 162 of file copying_plugin.c.

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}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
#define GNUNET_REST_API_NS_COPYING
static void get_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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
#define GNUNET_REST_HANDLER_END

References get_cont(), GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_REST_API_NS_COPYING, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, handle, handlers, options_cont(), requests_head, and requests_tail.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ REST_copying_init()

void * REST_copying_init ( const struct GNUNET_CONFIGURATION_Handle c)

Entry point for the plugin.

Parameters
clsthe "struct GNUNET_NAMESTORE_PluginEnvironment*"
Returns
NULL on error, otherwise the plugin context

Definition at line 195 of file copying_plugin.c.

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}
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
@ GNUNET_ERROR_TYPE_INFO
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
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

References _, GNUNET_REST_Plugin::cls, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_REST_API_NS_COPYING, GNUNET_REST_Plugin::name, and plugin.

Referenced by run().

Here is the caller graph for this function:

◆ REST_copying_done()

void REST_copying_done ( struct GNUNET_REST_Plugin api)

Exit point from the plugin.

Parameters
clsthe plugin context (as returned by "init")
Returns
always NULL

Definition at line 221 of file copying_plugin.c.

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}
void * cls
Closure for all of the callbacks.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47

References Plugin::api, cleanup_handle(), GNUNET_BLOCK_PluginFunctions::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, plugin, and requests_head.

Referenced by do_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 81 of file copying_plugin.c.

Referenced by cleanup_handle(), REST_copying_done(), and REST_copying_process_request().

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 86 of file copying_plugin.c.

Referenced by cleanup_handle(), and REST_copying_process_request().