GNUnet  0.18.1

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

Collaboration diagram for REST library:

Data Structures

struct  GNUNET_REST_RequestHandle
 
struct  GNUNET_REST_RequestHandlerError
 
struct  GNUNET_REST_RequestHandler
 

Macros

#define GNUNET_REST_HANDLER_END   { NULL, NULL, NULL }
 

Typedefs

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

Functions

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

◆ GNUNET_REST_HANDLER_END

#define GNUNET_REST_HANDLER_END   { NULL, NULL, NULL }

Definition at line 41 of file gnunet_rest_lib.h.

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.

Parameters
clsclosure
respthe response
statusstatus code (HTTP)

Definition at line 110 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.

Parameters
urlURL to check
namespacenamespace to check against
Returns
GNUNET_YES if namespace matches

Check if namespace is in URL.

Definition at line 37 of file rest.c.

38 {
39  return 0 == strncmp (namespace, url, strlen (namespace));
40 }

Referenced by GNUNET_REST_handle_request().

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.

Parameters
dataresult
Returns
MHD response

Definition at line 44 of file rest.c.

45 {
46  struct MHD_Response *resp;
47  size_t len;
48 
49  if (NULL == data)
50  {
51  len = 0;
52  data = "";
53  }
54  else
55  len = strlen (data);
56  resp = MHD_create_response_from_buffer (len,
57  (void *) data,
58  MHD_RESPMEM_MUST_COPY);
59  return resp;
60 }
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...

References data, and len.

Referenced by build_redirect(), bulk_tx_commit_cb(), consume_fail(), consume_ticket(), create_finished(), del_finished(), delete_finished_cb(), do_error(), do_finished(), do_redirect_error(), do_userinfo_error(), ego_get_all(), ego_get_response(), ego_sign_data_cb(), finished_cont(), get_cont(), handle_gns_response(), jwks_endpoint(), 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().

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 64 of file rest.c.

68 {
69  int count;
70  int i;
71  char *url;
72 
73  count = 0;
74  while (NULL != handlers[count].method)
75  count++;
76 
77  GNUNET_asprintf (&url, "%s", conn->url);
78  if (url[strlen (url) - 1] == '/')
79  url[strlen (url) - 1] = '\0';
80  for (i = 0; i < count; i++)
81  {
82  if (0 != strcasecmp (conn->method, handlers[i].method))
83  continue;
84  if (strlen (url) < strlen (handlers[i].namespace))
85  continue;
86  if (GNUNET_NO == GNUNET_REST_namespace_match (url, handlers[i].namespace))
87  continue;
88  // Match
89  handlers[i].proc (conn, (const char *) url, cls);
90  GNUNET_free (url);
91  return GNUNET_YES;
92  }
93  GNUNET_free (url);
95  return GNUNET_NO;
96 }
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
@ GNUNET_YES
@ GNUNET_NO
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_REST_namespace_match(const char *url, const char *namespace)
REST Utilities.
Definition: rest.c:37
@ MHD_HTTP_BAD_REQUEST
Bad Request [RFC7231, Section 6.5.1].
const char * url
The url as string.
const char * method
The HTTP method as MHD value (see microhttpd.h)

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

Here is the call graph for this function: