2 This file is part of GNUnet
3 Copyright (C) 2014, 2015, 2016 GNUnet e.V.
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.
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.
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/>
17 * @file json/jsonapi.c
18 * @brief functions to generate specifciations for JSONAPI parsing
19 * @author Martin Schanzenbach
22 #include "gnunet_json_lib.h"
23 #include "gnunet_rest_lib.h"
26 * TODO move this to jsonapi-utils
30 * Check rest request for validity
32 * @param req handle to the request
33 * @return GNUNET_OK if valid
36 GNUNET_JSONAPI_check_request_acceptable (struct GNUNET_REST_RequestHandle *req)
43 * Check rest request for validity
45 * @param req handle to the request
46 * @return GNUNET_OK if valid
49 GNUNET_JSONAPI_check_request_supported (struct GNUNET_REST_RequestHandle *req)
56 * Handle jsonapi rest request. Checks request headers for jsonapi compliance
58 * @param req rest request handle
59 * @param handler rest request handlers
61 * @return GNUNET_OK if successful
64 GNUNET_JSONAPI_handle_request (struct GNUNET_REST_RequestHandle *handle,
65 const struct GNUNET_REST_RequestHandler *handlers,
66 struct GNUNET_REST_RequestHandlerError *err,
69 if (GNUNET_OK != GNUNET_JSONAPI_check_request_acceptable (handle))
71 err->error_code = MHD_HTTP_NOT_ACCEPTABLE;
74 if (GNUNET_OK != GNUNET_JSONAPI_check_request_supported (handle))
76 err->error_code = MHD_HTTP_UNSUPPORTED_MEDIA_TYPE;
79 return GNUNET_REST_handle_request (handle, handlers, err, cls);