fix zombie-fest
[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
37 #define GNUNET_REST_HANDLER_END {NULL, NULL, NULL}
38
39 struct GNUNET_REST_RequestHandle
40 {
41   struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
42   const char *method;
43   const char *url;
44   const char *data;
45   size_t data_size;
46 };
47
48 struct GNUNET_REST_RequestHandlerError
49 {
50   int error_code;
51   char* error_text;
52 };
53
54 struct GNUNET_REST_RequestHandler
55 {
56   /**
57    * Http method to handle
58    */
59   const char *method;
60
61   /**
62    * Namespace to handle
63    */
64   const char *namespace;
65
66   /**
67    * callback handler
68    */
69   void (*proc) (struct GNUNET_REST_RequestHandle *handle,
70                 const char *url,
71                 void *cls);
72
73 };
74
75
76 /**
77  * Iterator called on obtained result for a REST result.
78  *
79  * @param cls closure
80  * @param resp the response
81  * @param status status code (HTTP)
82  */
83 typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
84                                              struct MHD_Response *resp,
85                                              int status);
86
87 /**
88  * Check if namespace is in URL.
89  *
90  * @param url URL to check
91  * @param namespace namespace to check against
92  * @retun GNUNET_YES if namespace matches
93  */
94 int
95 GNUNET_REST_namespace_match (const char *url, const char *namespace);
96
97 /**
98  * Create REST MHD response
99  *
100  * @param data result
101  * @retun MHD response
102  */
103  struct MHD_Response*
104 GNUNET_REST_create_response (const char *data);
105
106
107 int
108 GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
109                             const struct GNUNET_REST_RequestHandler *handlers,
110                             struct GNUNET_REST_RequestHandlerError *err,
111                             void *cls);
112
113
114 #endif
115
116 /** @} */  /* end of group */