GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
REST library

Helper library to parse/create REST. More...

Data Structures

struct  GNUNET_REST_RequestHandle
struct  GNUNET_REST_RequestHandlerError
struct  GNUNET_REST_RequestHandler




typedef void(* GNUNET_REST_ResultProcessor) (void *cls, struct MHD_Response *resp, int status)
 Iterator called on obtained result for a REST result. More...


int GNUNET_REST_namespace_match (const char *url, const char *namespace)
 Check if namespace is in URL. More...
struct MHD_Response * GNUNET_REST_create_response (const char *data)
 Create REST MHD response. More...
int GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)

Detailed Description

Helper library to parse/create REST.

Macro Definition Documentation



Typedef Documentation

◆ GNUNET_REST_ResultProcessor

typedef void(* GNUNET_REST_ResultProcessor) (void *cls, struct MHD_Response *resp, int status)

Iterator called on obtained result for a REST result.

respthe response
statusstatus code (HTTP)

Definition at line 106 of file gnunet_rest_lib.h.

Function Documentation

◆ GNUNET_REST_namespace_match()

int GNUNET_REST_namespace_match ( const char *  url,
const char *  namespace 

Check if namespace is in URL.

urlURL to check
namespacenamespace to check against
GNUNET_YES if namespace matches

Check if namespace is in URL.

Check if namespace is in URL.

urlURL to check
namespacenamespace to check against GNUNET_YES if namespace matches

Definition at line 44 of file rest.c.

Referenced by GNUNET_REST_handle_request().

45 {
46  return 0 == strncmp (namespace, url, strlen (namespace));
47 }
Here is the caller graph for this function:

◆ GNUNET_REST_create_response()

struct MHD_Response* GNUNET_REST_create_response ( const char *  data)

Create REST MHD response.

MHD response

Create REST MHD response.

dataresult MHD response

Definition at line 57 of file rest.c.

References len.

Referenced by build_redirect(), consume_ticket(), consume_timeout(), create_finished(), del_finished(), delete_finished_cb(), do_error(), do_finished(), do_redirect_error(), do_userinfo_error(), ego_create(), ego_edit(), ego_get_all(), ego_get_for_subsystem(), ego_get_response(), finished_cont(), get_cont(), handle_gns_response(), login_cont(), login_redirect(), namestore_list_finished(), oidc_config_cors(), oidc_config_endpoint(), oidc_ticket_issue_cb(), options_cont(), peerinfo_list_finished(), return_response(), set_cont(), and token_endpoint().

58 {
59  struct MHD_Response *resp;
60  size_t len;
62  if (NULL == data)
63  {
64  len = 0;
65  data = "";
66  }
67  else
68  len = strlen (data);
69  resp = MHD_create_response_from_buffer (len,
70  (void *) data,
72  return resp;
73 }
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_REST_handle_request()

int GNUNET_REST_handle_request ( struct GNUNET_REST_RequestHandle conn,
const struct GNUNET_REST_RequestHandler handlers,
struct GNUNET_REST_RequestHandlerError err,
void *  cls 

Definition at line 77 of file rest.c.

References GNUNET_REST_RequestHandlerError::error_code, GNUNET_asprintf(), GNUNET_free, GNUNET_NO, GNUNET_REST_namespace_match(), GNUNET_YES, GNUNET_REST_RequestHandle::method, GNUNET_REST_RequestHandler::method, GNUNET_REST_RequestHandler::proc, and GNUNET_REST_RequestHandle::url.

Referenced by rest_config_process_request(), rest_copying_process_request(), rest_identity_process_request(), and rest_process_request().

81 {
82  int count;
83  int i;
84  char *url;
86  count = 0;
87  while (NULL != handlers[count].method)
88  count++;
90  GNUNET_asprintf (&url, "%s", conn->url);
91  if (url[strlen (url) - 1] == '/')
92  url[strlen (url) - 1] = '\0';
93  for (i = 0; i < count; i++)
94  {
95  if (0 != strcasecmp (conn->method, handlers[i].method))
96  continue;
97  if (strlen (url) < strlen (handlers[i].namespace))
98  continue;
99  if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace))
100  continue;
101  // Match
102  handlers[i].proc (conn, (const char *) url, cls);
103  GNUNET_free (url);
104  return GNUNET_YES;
105  }
106  GNUNET_free (url);
107  err->error_code = MHD_HTTP_BAD_REQUEST;
108  return GNUNET_NO;
109 }
const char * method
Http method to handle.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
int GNUNET_REST_namespace_match(const char *url, const char *namespace)
REST Utilities.
Definition: rest.c:44
const char * url
The url as string.
const char * method
The HTTP method as MHD value (see microhttpd.h)
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: