Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / jsonapi / jsonapi.c
1 /*
2   This file is part of GNUnet
3   Copyright (C) 2014, 2015, 2016 GNUnet e.V.
4
5   GNUnet is free software; you can redistribute it and/or modify it under the
6   terms of the GNU General Public License as published by the Free Software
7   Foundation; either version 3, or (at your option) any later version.
8
9   GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY
10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
13   You should have received a copy of the GNU General Public License along with
14   GNUnet; see the file COPYING.  If not, If not, see <http://www.gnu.org/licenses/>
15 */
16 /**
17  * @file jsonapi/jsonapi.c
18  * @brief functions to generate specifciations for JSONAPI parsing
19  * @author Martin Schanzenbach
20  */
21 #include "platform.h"
22 #include "gnunet_json_lib.h"
23 #include "gnunet_rest_lib.h"
24
25 /**
26  * TODO move this to jsonapi-utils
27  */
28
29 /**
30  * Check rest request for validity
31  *
32  * @param req handle to the request
33  * @return GNUNET_OK if valid
34  */
35 int
36 GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req)
37 {
38   //TODO
39   return GNUNET_OK;
40 }
41
42 /**
43  * Check rest request for validity
44  *
45  * @param req handle to the request
46  * @return GNUNET_OK if valid
47  */
48 int
49 GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req)
50 {
51   //TODO
52   return GNUNET_OK;
53 }
54
55 /**
56  * Handle jsonapi rest request. Checks request headers for jsonapi compliance
57  *
58  * @param req rest request handle
59  * @param handler rest request handlers
60  * @param cls closure
61  * @return GNUNET_OK if successful
62  */
63 int
64 GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *handle,
65                                const struct GNUNET_REST_RequestHandler *handlers,
66                                struct GNUNET_REST_RequestHandlerError *err,
67                                void *cls)
68 {
69   if (GNUNET_OK != GNUNET_JSONAPI_check_request_acceptable (handle))
70   {
71     err->error_code = MHD_HTTP_NOT_ACCEPTABLE;
72     return GNUNET_SYSERR;
73   }
74   if (GNUNET_OK != GNUNET_JSONAPI_check_request_supported (handle))
75   {
76     err->error_code = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE;
77     return GNUNET_SYSERR;
78   }
79   return GNUNET_REST_handle_request (handle, handlers, err, cls);
80 }