GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
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 do_error (void *cls)
 Task run on shutdown. 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 void 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...
 

Macro Definition Documentation

◆ GNUNET_REST_API_NS_COPYING

#define GNUNET_REST_API_NS_COPYING   "/copying"

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

Referenced by get_cont().

Function Documentation

◆ cleanup_handle()

static void cleanup_handle ( struct RequestHandle handle)
static

Cleanup request handle.

Parameters
handleHandle to clean up

Definition at line 73 of file plugin_rest_copying.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, and GNUNET_log.

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

74 {
76  "Cleaning up\n");
77  GNUNET_free(handle);
78 }
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ do_error()

static void do_error ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused
tcscheduler context

Definition at line 88 of file plugin_rest_copying.c.

References cleanup_handle(), GNUNET_REST_create_response(), handle, RequestHandle::proc, RequestHandle::proc_cls, and RequestHandle::response_code.

Referenced by rest_copying_process_request().

89 {
90  struct RequestHandle *handle = cls;
91  struct MHD_Response *resp;
92 
93  resp = GNUNET_REST_create_response(NULL);
94  handle->proc(handle->proc_cls, resp, handle->response_code);
95  cleanup_handle(handle);
96 }
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
int response_code
HTTP response code.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
Here is the call graph for this function:
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 105 of file plugin_rest_copying.c.

References cleanup_handle(), GNUNET_REST_COPYING_TEXT, GNUNET_REST_create_response(), handle, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by rest_copying_process_request().

108 {
109  struct MHD_Response *resp;
110  struct RequestHandle *handle = cls;
111 
113  handle->proc(handle->proc_cls,
114  resp,
115  MHD_HTTP_OK);
116  cleanup_handle(handle);
117 }
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
#define GNUNET_REST_COPYING_TEXT
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
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 127 of file plugin_rest_copying.c.

References cleanup_handle(), GNUNET_REST_create_response(), handle, RequestHandle::proc, and RequestHandle::proc_cls.

Referenced by rest_copying_process_request().

130 {
131  struct MHD_Response *resp;
132  struct RequestHandle *handle = cls;
133 
134  resp = GNUNET_REST_create_response(NULL);
135  MHD_add_response_header(resp,
136  "Access-Control-Allow-Methods",
137  MHD_HTTP_METHOD_GET);
138  handle->proc(handle->proc_cls,
139  resp,
140  MHD_HTTP_OK);
141  cleanup_handle(handle);
142 }
static void cleanup_handle(struct RequestHandle *handle)
Cleanup request handle.
GNUNET_REST_ResultProcessor proc
The plugin result processor.
void * proc_cls
The closure of the result processor.
The request handle.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rest_copying_process_request()

static void 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 157 of file plugin_rest_copying.c.

References do_error(), GNUNET_REST_RequestHandlerError::error_code, get_cont(), GNUNET_new, GNUNET_NO, GNUNET_REST_API_NS_COPYING, GNUNET_REST_handle_request(), GNUNET_REST_HANDLER_END, GNUNET_SCHEDULER_add_now(), handle, options_cont(), RequestHandle::proc, RequestHandle::proc_cls, RequestHandle::response_code, and RequestHandle::rest_handle.

Referenced by libgnunet_plugin_rest_copying_init().

160 {
161  static const struct GNUNET_REST_RequestHandler handlers[] = {
162  { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont },
163  { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont },
165  };
166  struct RequestHandle *handle = GNUNET_new(struct RequestHandle);
168 
169  handle->proc_cls = proc_cls;
170  handle->proc = proc;
171  handle->rest_handle = conndata_handle;
172 
173  if (GNUNET_NO == GNUNET_REST_handle_request(conndata_handle,
174  handlers,
175  &err,
176  handle))
177  {
178  handle->response_code = err.error_code;
180  }
181 }
#define GNUNET_REST_API_NS_COPYING
GNUNET_REST_ResultProcessor proc
The plugin result processor.
#define GNUNET_NO
Definition: gnunet_common.h:78
static void do_error(void *cls)
Task run on shutdown.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * proc_cls
The closure of the result processor.
#define GNUNET_REST_HANDLER_END
The request handle.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
static void get_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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:75
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
int response_code
HTTP response code.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle rest request.
Here is the call graph for this function:
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 191 of file plugin_rest_copying.c.

References _, Plugin::api, Plugin::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().

192 {
193  static struct Plugin plugin;
194 
195  cfg = cls;
196  struct GNUNET_REST_Plugin *api;
197 
198  if (NULL != plugin.cfg)
199  return NULL; /* can only initialize once! */
200  memset(&plugin, 0, sizeof(struct Plugin));
201  plugin.cfg = cfg;
202  api = GNUNET_new(struct GNUNET_REST_Plugin);
203  api->cls = &plugin;
207  _("COPYING REST API initialized\n"));
208  return api;
209 }
const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our configuration.
#define GNUNET_REST_API_NS_COPYING
void * cls
The closure of the plugin.
struct returned by the initialization function of the plugin
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void(* process_request)(struct GNUNET_REST_RequestHandle *handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function to process a REST call.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static void rest_copying_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
char * name
Plugin name.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
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 219 of file plugin_rest_copying.c.

References Plugin::api, Plugin::cfg, GNUNET_REST_Plugin::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, and plugin.

220 {
221  struct GNUNET_REST_Plugin *api = cls;
222  struct Plugin *plugin = api->cls;
223 
224  plugin->cfg = NULL;
225  GNUNET_free(api);
227  "COPYING REST plugin is finished\n");
228  return NULL;
229 }
void * cls
The closure of the plugin.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct returned by the initialization function of the plugin
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Handle for a plugin.
Definition: block.c:37
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg

Handle to our configuration.

Handle to our configuration.

Definition at line 42 of file plugin_rest_copying.c.