first batch of license fixes (boring)
[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 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
16 /**
17  * @author Martin Schanzenbach
18  *
19  * @file
20  * API for helper library to parse/create REST
21  *
22  * @defgroup rest  REST library
23  * Helper library to parse/create REST
24  * @{
25  */
26 #ifndef GNUNET_REST_LIB_H
27 #define GNUNET_REST_LIB_H
28
29 #include "gnunet_util_lib.h"
30 #include <microhttpd.h>
31
32 #define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
33
34 struct GNUNET_REST_RequestHandle
35 {
36   /**
37    * Map of url parameters
38    */
39   struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
40
41   /**
42    * Map of headers
43    */
44   struct GNUNET_CONTAINER_MultiHashMap *header_param_map;
45
46   /**
47    * The HTTP method as MHD value (see microhttpd.h)
48    */
49   const char *method;
50
51   /**
52    * The url as string
53    */
54   const char *url;
55
56   /**
57    * The POST data
58    */
59   const char *data;
60
61   /**
62    * The POST data size
63    */
64   size_t data_size;
65 };
66
67 struct GNUNET_REST_RequestHandlerError
68 {
69   int error_code;
70   char* error_text;
71 };
72
73 struct GNUNET_REST_RequestHandler
74 {
75   /**
76    * Http method to handle
77    */
78   const char *method;
79
80   /**
81    * Namespace to handle
82    */
83   const char *namespace;
84
85   /**
86    * callback handler
87    */
88   void (*proc) (struct GNUNET_REST_RequestHandle *handle,
89                 const char *url,
90                 void *cls);
91
92 };
93
94
95 /**
96  * Iterator called on obtained result for a REST result.
97  *
98  * @param cls closure
99  * @param resp the response
100  * @param status status code (HTTP)
101  */
102 typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
103                                              struct MHD_Response *resp,
104                                              int status);
105
106 /**
107  * Check if namespace is in URL.
108  *
109  * @param url URL to check
110  * @param namespace namespace to check against
111  * @return GNUNET_YES if namespace matches
112  */
113 int
114 GNUNET_REST_namespace_match (const char *url, const char *namespace);
115
116 /**
117  * Create REST MHD response
118  *
119  * @param data result
120  * @return MHD response
121  */
122  struct MHD_Response*
123 GNUNET_REST_create_response (const char *data);
124
125
126 int
127 GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
128                             const struct GNUNET_REST_RequestHandler *handlers,
129                             struct GNUNET_REST_RequestHandlerError *err,
130                             void *cls);
131
132
133 #endif
134
135 /** @} */  /* end of group */