defining data structures for validation
[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 it
6       under the terms of the GNU Affero General Public License as published
7       by the Free Software Foundation, either version 3 of the License,
8       or (at your 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       Affero General Public License for more details.
14      
15       You should have received a copy of the GNU Affero General Public License
16       along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
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
37 #define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
38
39 struct GNUNET_REST_RequestHandle
40 {
41   /**
42    * Map of url parameters
43    */
44   struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
45
46   /**
47    * Map of headers
48    */
49   struct GNUNET_CONTAINER_MultiHashMap *header_param_map;
50
51   /**
52    * The HTTP method as MHD value (see microhttpd.h)
53    */
54   const char *method;
55
56   /**
57    * The url as string
58    */
59   const char *url;
60
61   /**
62    * The POST data
63    */
64   const char *data;
65
66   /**
67    * The POST data size
68    */
69   size_t data_size;
70 };
71
72 struct GNUNET_REST_RequestHandlerError
73 {
74   int error_code;
75   char* error_text;
76 };
77
78 struct GNUNET_REST_RequestHandler
79 {
80   /**
81    * Http method to handle
82    */
83   const char *method;
84
85   /**
86    * Namespace to handle
87    */
88   const char *namespace;
89
90   /**
91    * callback handler
92    */
93   void (*proc) (struct GNUNET_REST_RequestHandle *handle,
94                 const char *url,
95                 void *cls);
96
97 };
98
99
100 /**
101  * Iterator called on obtained result for a REST result.
102  *
103  * @param cls closure
104  * @param resp the response
105  * @param status status code (HTTP)
106  */
107 typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
108                                              struct MHD_Response *resp,
109                                              int status);
110
111 /**
112  * Check if namespace is in URL.
113  *
114  * @param url URL to check
115  * @param namespace namespace to check against
116  * @return GNUNET_YES if namespace matches
117  */
118 int
119 GNUNET_REST_namespace_match (const char *url, const char *namespace);
120
121 /**
122  * Create REST MHD response
123  *
124  * @param data result
125  * @return MHD response
126  */
127  struct MHD_Response*
128 GNUNET_REST_create_response (const char *data);
129
130
131 int
132 GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
133                             const struct GNUNET_REST_RequestHandler *handlers,
134                             struct GNUNET_REST_RequestHandlerError *err,
135                             void *cls);
136
137
138 #endif
139
140 /** @} */  /* end of group */