aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-25 15:58:38 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-03-25 15:58:38 +0000
commit08cd39e74d35cec73f54de9826961a97d8a8ea0d (patch)
treef85511b479dc9480427dffaaaa5425ebc221c87c /src/include
parent00f87691363acaf94f533793654e610e46bf4e1d (diff)
downloadgnunet-08cd39e74d35cec73f54de9826961a97d8a8ea0d.tar.gz
gnunet-08cd39e74d35cec73f54de9826961a97d8a8ea0d.zip
-start a lib for REST and json:api
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_rest_lib.h156
-rw-r--r--src/include/gnunet_rest_plugin.h1
2 files changed, 157 insertions, 0 deletions
diff --git a/src/include/gnunet_rest_lib.h b/src/include/gnunet_rest_lib.h
new file mode 100644
index 000000000..19a0168e5
--- /dev/null
+++ b/src/include/gnunet_rest_lib.h
@@ -0,0 +1,156 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2010-2015 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file include/gnunet_rest_lib.h
23 * @brief API for helper library to parse/create REST
24 * @author Martin Schanzenbach
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#include <jansson.h>
32
33#define GNUNET_REST_JSONAPI_KEY_DATA "data"
34
35#define GNUNET_REST_JSONAPI_KEY_ID "id"
36
37#define GNUNET_REST_JSONAPI_KEY_TYPE "type"
38
39/**
40 * Resource structs for JSON API
41 */
42struct JsonApiResource;
43
44/**
45 * Responses for JSON API
46 */
47struct JsonApiResponse;
48
49/**
50 * Create a JSON API resource
51 *
52 * @param type the JSON API resource type
53 * @param id the JSON API resource id
54 * @return a new JSON API resource or NULL on error.
55 */
56struct JsonApiResource*
57GNUNET_REST_jsonapi_resource_new (const char *type, const char *id);
58
59/**
60 * Delete a JSON API resource
61 *
62 * @param res the JSON resource
63 * @param result Pointer where the resource should be stored
64 */
65void
66GNUNET_REST_jsonapi_resource_delete (struct JsonApiResource *resource);
67
68/**
69 * Add a JSON API attribute
70 *
71 * @param res the JSON resource
72 * @param key the key for the attribute
73 * @param json the json_t attribute to add
74 * @return #GNUNET_OK if added successfully
75 * #GNUNET_SYSERR if not
76 */
77int
78GNUNET_REST_jsonapi_resource_add_attr (const struct JsonApiResource *resource,
79 const char* key,
80 json_t *json);
81
82/**
83 * Create a JSON API primary data
84 *
85 * @param type the JSON API resource type
86 * @param id the JSON API resource id
87 * @return a new JSON API resource or NULL on error.
88 */
89struct JsonApiResponse*
90GNUNET_REST_jsonapi_response_new ();
91
92/**
93 * Delete a JSON API primary data
94 *
95 * @param type the JSON API resource type
96 * @param id the JSON API resource id
97 * @return a new JSON API resource or NULL on error.
98 */
99void
100GNUNET_REST_jsonapi_response_delete (struct JsonApiResponse *resp);
101
102/**
103 * Add a JSON API resource to primary data
104 *
105 * @param data The JSON API data to add to
106 * @param res the JSON API resource to add
107 * @return the new number of resources
108 */
109void
110GNUNET_REST_jsonapi_response_resource_add (struct JsonApiResponse *resp,
111 struct JsonApiResource *res);
112
113/**
114 * Add a JSON API resource to primary data
115 *
116 * @param resp The JSON API data to add to
117 * @param res the JSON API resource to add
118 * @return the new number of resources
119 */
120void
121GNUNET_REST_jsonapi_data_resource_remove (struct JsonApiResponse *resp,
122 struct JsonApiResource *res);
123
124/**
125 * String serialze jsonapi primary data
126 *
127 * @param data the JSON API primary data
128 * @param result where to store the result
129 * @return GNUNET_SYSERR on error else GNUNET_OK
130 */
131int
132GNUNET_REST_jsonapi_data_serialize (const struct JsonApiResponse *resp,
133 char **result);
134
135/**
136 * Check if namespace is in URL.
137 *
138 * @param url URL to check
139 * @param namespace namespace to check against
140 * @retun GNUNET_YES if namespace matches
141 */
142int
143GNUNET_REST_namespace_match (const char *url, const char *namespace);
144
145/**
146 * Create JSON API MHD response
147 *
148 * @param data JSON result
149 * @retun MHD response
150 */
151 struct MHD_Response*
152GNUNET_REST_create_json_response (const char *data);
153
154
155
156#endif
diff --git a/src/include/gnunet_rest_plugin.h b/src/include/gnunet_rest_plugin.h
index 1d5a2db59..e085ccf32 100644
--- a/src/include/gnunet_rest_plugin.h
+++ b/src/include/gnunet_rest_plugin.h
@@ -37,6 +37,7 @@ extern "C"
37#endif 37#endif
38#endif 38#endif
39 39
40
40/** 41/**
41 * Iterator called on obtained result for a REST result. 42 * Iterator called on obtained result for a REST result.
42 * 43 *