glitch in the license text detected by hyazinthe, thank you!
[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
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 /**
16  * @file jsonapi/jsonapi.c
17  * @brief functions to generate specifciations for JSONAPI parsing
18  * @author Martin Schanzenbach
19  */
20 #include "platform.h"
21 #include "gnunet_json_lib.h"
22 #include "gnunet_rest_lib.h"
23
24 /**
25  * TODO move this to jsonapi-utils
26  */
27
28 /**
29  * Check rest request for validity
30  *
31  * @param req handle to the request
32  * @return GNUNET_OK if valid
33  */
34 int
35 GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req)
36 {
37   //TODO
38   return GNUNET_OK;
39 }
40
41 /**
42  * Check rest request for validity
43  *
44  * @param req handle to the request
45  * @return GNUNET_OK if valid
46  */
47 int
48 GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req)
49 {
50   //TODO
51   return GNUNET_OK;
52 }
53
54 /**
55  * Handle jsonapi rest request. Checks request headers for jsonapi compliance
56  *
57  * @param req rest request handle
58  * @param handler rest request handlers
59  * @param cls closure
60  * @return GNUNET_OK if successful
61  */
62 int
63 GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *handle,
64                                const struct GNUNET_REST_RequestHandler *handlers,
65                                struct GNUNET_REST_RequestHandlerError *err,
66                                void *cls)
67 {
68   if (GNUNET_OK != GNUNET_JSONAPI_check_request_acceptable (handle))
69   {
70     err->error_code = MHD_HTTP_NOT_ACCEPTABLE;
71     return GNUNET_SYSERR;
72   }
73   if (GNUNET_OK != GNUNET_JSONAPI_check_request_supported (handle))
74   {
75     err->error_code = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE;
76     return GNUNET_SYSERR;
77   }
78   return GNUNET_REST_handle_request (handle, handlers, err, cls);
79 }