GNUnet  0.20.0
plugin_rest_copying.c File Reference
#include "platform.h"
#include "gnunet_rest_plugin.h"
#include <gnunet_rest_lib.h>
Include dependency graph for plugin_rest_copying.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...
 
static enum GNUNET_GenericReturnValue rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
 Function processing the REST call. More...
 
void * libgnunet_plugin_rest_copying_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_rest_copying_done (void *cls)
 Exit point from the plugin. More...
 

Variables

const struct GNUNET_CONFIGURATION_Handlecfg
 Handle to our configuration. More...
 
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 31 of file plugin_rest_copying.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 33 of file plugin_rest_copying.c.

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( struct RequestHandle handle)
static

Cleanup request handle.

Parameters
handleHandle to clean up

Definition at line 95 of file plugin_rest_copying.c.

96 {
98  "Cleaning up\n");
101  handle);
103 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#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.
static struct RequestHandle * requests_head
DLL.
static struct RequestHandle * requests_tail
DLL.

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

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

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 112 of file plugin_rest_copying.c.

115 {
116  struct MHD_Response *resp;
117  struct RequestHandle *handle = cls;
118 
120  handle->proc (handle->proc_cls,
121  resp,
122  MHD_HTTP_OK);
124 }
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 GNUNET_REST_COPYING_TEXT
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
The request handle.

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

Here is the call 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 133 of file plugin_rest_copying.c.

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

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

Here is the call graph for this function:

◆ rest_copying_process_request()

static enum GNUNET_GenericReturnValue rest_copying_process_request ( struct GNUNET_REST_RequestHandle conndata_handle,
GNUNET_REST_ResultProcessor  proc,
void *  proc_cls 
)
static

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 133 of file plugin_rest_copying.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 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#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
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.

Referenced by libgnunet_plugin_rest_copying_init().

Here is the caller graph for this function:

◆ libgnunet_plugin_rest_copying_init()

void* libgnunet_plugin_rest_copying_init ( void *  cls)

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 plugin_rest_copying.c.

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;
211  _ ("COPYING REST API initialized\n"));
212  return api;
213 }
struct TestcasePlugin * plugin
The process handle to the testbed service.
@ GNUNET_ERROR_TYPE_INFO
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static enum GNUNET_GenericReturnValue rest_copying_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our configuration.
struct returned by the initialization function of the plugin
char * name
Plugin name.
void * cls
The closure of the plugin.
enum GNUNET_GenericReturnValue(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
Handle for a plugin.
Definition: block.c:38

References _, cfg, GNUNET_REST_Plugin::cls, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_new, GNUNET_REST_API_NS_COPYING, GNUNET_REST_Plugin::name, plugin, GNUNET_REST_Plugin::process_request, and rest_copying_process_request().

Here is the call graph for this function:

◆ libgnunet_plugin_rest_copying_done()

void* libgnunet_plugin_rest_copying_done ( void *  cls)

Exit point from the plugin.

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

Definition at line 223 of file plugin_rest_copying.c.

224 {
225  struct GNUNET_REST_Plugin *api = cls;
226  struct Plugin *plugin = api->cls;
227 
228  while (NULL != requests_head)
230  plugin->cfg = NULL;
231  GNUNET_free (api);
233  "COPYING REST plugin is finished\n");
234  return NULL;
235 }
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_REST_Plugin::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, plugin, and requests_head.

Here is the call graph for this function:

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

Handle to our configuration.

Handle to our configuration.

Definition at line 44 of file plugin_rest_copying.c.

Referenced by libgnunet_plugin_rest_copying_init().

◆ requests_head

struct RequestHandle* requests_head
static

DLL.

Definition at line 82 of file plugin_rest_copying.c.

Referenced by cleanup_handle(), and libgnunet_plugin_rest_copying_done().

◆ requests_tail

struct RequestHandle* requests_tail
static

DLL.

Definition at line 87 of file plugin_rest_copying.c.

Referenced by cleanup_handle().