-rps: logging
[oweals/gnunet.git] / src / include / gnunet_rest_lib.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2010-2015 GNUnet e.V.
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @author Martin Schanzenbach
23  *
24  * @file
25  * API for helper library to parse/create REST
26  *
27  * @defgroup rest  REST library
28  * Helper library to parse/create REST
29  * @{
30  */
31 #ifndef GNUNET_REST_LIB_H
32 #define GNUNET_REST_LIB_H
33
34 #include "gnunet_util_lib.h"
35 #include "microhttpd.h"
36 #include <jansson.h>
37
38 #define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
39
40 struct GNUNET_REST_RequestHandle
41 {
42   struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
43   const char *method;
44   const char *url;
45   const char *data;
46   size_t data_size;
47 };
48
49 struct GNUNET_REST_RequestHandlerError
50 {
51   int error_code;
52   char* error_text;
53 };
54
55 struct GNUNET_REST_RequestHandler
56 {
57   /**
58    * Http method to handle
59    */
60   const char *method;
61
62   /**
63    * Namespace to handle
64    */
65   const char *namespace;
66
67   /**
68    * callback handler
69    */
70   void (*proc) (struct GNUNET_REST_RequestHandle *handle,
71                 const char *url,
72                 void *cls);
73
74 };
75
76
77 /**
78  * Iterator called on obtained result for a REST result.
79  *
80  * @param cls closure
81  * @param resp the response
82  * @param status status code (HTTP)
83  */
84 typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
85                                              struct MHD_Response *resp,
86                                              int status);
87
88 /**
89  * Check if namespace is in URL.
90  *
91  * @param url URL to check
92  * @param namespace namespace to check against
93  * @retun GNUNET_YES if namespace matches
94  */
95 int
96 GNUNET_REST_namespace_match (const char *url, const char *namespace);
97
98 /**
99  * Create JSON API MHD response
100  *
101  * @param data JSON result
102  * @retun MHD response
103  */
104  struct MHD_Response*
105 GNUNET_REST_create_json_response (const char *data);
106
107
108 int
109 GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
110                             const struct GNUNET_REST_RequestHandler *handlers,
111                             struct GNUNET_REST_RequestHandlerError *err,
112                             void *cls);
113
114
115 #endif
116
117 /** @} */  /* end of group */