GNUnet  0.10.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 107 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 56 of file rest.c.

References len.

Referenced by build_redirect(), 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_collect_response(), handle_gns_response(), handle_verify_response(), login_cont(), login_redirect(), namestore_list_finished(), oidc_ticket_issue_cb(), options_cont(), peerinfo_list_finished(), return_response(), return_userinfo_response(), send_cred_response(), and token_endpoint().

57 {
58  struct MHD_Response *resp;
59  size_t len;
61  if (NULL == data)
62  {
63  len = 0;
64  data = "";
65  }
66  else
67  len = strlen (data);
68  resp = MHD_create_response_from_buffer (len,
69  (void*)data,
71  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 76 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 init_cont(), rest_config_process_request(), and rest_copying_process_request().

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