summaryrefslogtreecommitdiff
path: root/src/rest/plugin_rest_copying.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest/plugin_rest_copying.c')
-rw-r--r--src/rest/plugin_rest_copying.c105
1 files changed, 54 insertions, 51 deletions
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c
index 4ebf032a7..eabe96c63 100644
--- a/src/rest/plugin_rest_copying.c
+++ b/src/rest/plugin_rest_copying.c
@@ -30,18 +30,21 @@
30 30
31#define GNUNET_REST_API_NS_COPYING "/copying" 31#define GNUNET_REST_API_NS_COPYING "/copying"
32 32
33#define GNUNET_REST_COPYING_TEXT "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>" 33#define GNUNET_REST_COPYING_TEXT \
34 "GNU Affero General Public License version 3 or later. See also: <http://www.gnu.org/licenses/>"
34 35
35/** 36/**
36 * @brief struct returned by the initialization function of the plugin 37 * @brief struct returned by the initialization function of the plugin
37 */ 38 */
38struct Plugin { 39struct Plugin
40{
39 const struct GNUNET_CONFIGURATION_Handle *cfg; 41 const struct GNUNET_CONFIGURATION_Handle *cfg;
40}; 42};
41 43
42const struct GNUNET_CONFIGURATION_Handle *cfg; 44const struct GNUNET_CONFIGURATION_Handle *cfg;
43 45
44struct RequestHandle { 46struct RequestHandle
47{
45 /** 48 /**
46 * Handle to rest request 49 * Handle to rest request
47 */ 50 */
@@ -70,11 +73,11 @@ struct RequestHandle {
70 * @param handle Handle to clean up 73 * @param handle Handle to clean up
71 */ 74 */
72static void 75static void
73cleanup_handle(struct RequestHandle *handle) 76cleanup_handle (struct RequestHandle *handle)
74{ 77{
75 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
76 "Cleaning up\n"); 79 "Cleaning up\n");
77 GNUNET_free(handle); 80 GNUNET_free (handle);
78} 81}
79 82
80 83
@@ -85,14 +88,14 @@ cleanup_handle(struct RequestHandle *handle)
85 * @param tc scheduler context 88 * @param tc scheduler context
86 */ 89 */
87static void 90static void
88do_error(void *cls) 91do_error (void *cls)
89{ 92{
90 struct RequestHandle *handle = cls; 93 struct RequestHandle *handle = cls;
91 struct MHD_Response *resp; 94 struct MHD_Response *resp;
92 95
93 resp = GNUNET_REST_create_response(NULL); 96 resp = GNUNET_REST_create_response (NULL);
94 handle->proc(handle->proc_cls, resp, handle->response_code); 97 handle->proc (handle->proc_cls, resp, handle->response_code);
95 cleanup_handle(handle); 98 cleanup_handle (handle);
96} 99}
97 100
98 101
@@ -102,18 +105,18 @@ do_error(void *cls)
102 * @param handle the lookup handle 105 * @param handle the lookup handle
103 */ 106 */
104static void 107static void
105get_cont(struct GNUNET_REST_RequestHandle *con_handle, 108get_cont (struct GNUNET_REST_RequestHandle *con_handle,
106 const char* url, 109 const char*url,
107 void *cls) 110 void *cls)
108{ 111{
109 struct MHD_Response *resp; 112 struct MHD_Response *resp;
110 struct RequestHandle *handle = cls; 113 struct RequestHandle *handle = cls;
111 114
112 resp = GNUNET_REST_create_response(GNUNET_REST_COPYING_TEXT); 115 resp = GNUNET_REST_create_response (GNUNET_REST_COPYING_TEXT);
113 handle->proc(handle->proc_cls, 116 handle->proc (handle->proc_cls,
114 resp, 117 resp,
115 MHD_HTTP_OK); 118 MHD_HTTP_OK);
116 cleanup_handle(handle); 119 cleanup_handle (handle);
117} 120}
118 121
119 122
@@ -124,21 +127,21 @@ get_cont(struct GNUNET_REST_RequestHandle *con_handle,
124 * @param handle the lookup handle 127 * @param handle the lookup handle
125 */ 128 */
126static void 129static void
127options_cont(struct GNUNET_REST_RequestHandle *con_handle, 130options_cont (struct GNUNET_REST_RequestHandle *con_handle,
128 const char* url, 131 const char*url,
129 void *cls) 132 void *cls)
130{ 133{
131 struct MHD_Response *resp; 134 struct MHD_Response *resp;
132 struct RequestHandle *handle = cls; 135 struct RequestHandle *handle = cls;
133 136
134 resp = GNUNET_REST_create_response(NULL); 137 resp = GNUNET_REST_create_response (NULL);
135 MHD_add_response_header(resp, 138 MHD_add_response_header (resp,
136 "Access-Control-Allow-Methods", 139 "Access-Control-Allow-Methods",
137 MHD_HTTP_METHOD_GET); 140 MHD_HTTP_METHOD_GET);
138 handle->proc(handle->proc_cls, 141 handle->proc (handle->proc_cls,
139 resp, 142 resp,
140 MHD_HTTP_OK); 143 MHD_HTTP_OK);
141 cleanup_handle(handle); 144 cleanup_handle (handle);
142} 145}
143 146
144 147
@@ -154,30 +157,30 @@ options_cont(struct GNUNET_REST_RequestHandle *con_handle,
154 * @return #GNUNET_OK if request accepted 157 * @return #GNUNET_OK if request accepted
155 */ 158 */
156static void 159static void
157rest_copying_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, 160rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
158 GNUNET_REST_ResultProcessor proc, 161 GNUNET_REST_ResultProcessor proc,
159 void *proc_cls) 162 void *proc_cls)
160{ 163{
161 static const struct GNUNET_REST_RequestHandler handlers[] = { 164 static const struct GNUNET_REST_RequestHandler handlers[] = {
162 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont }, 165 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont },
163 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont }, 166 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont },
164 GNUNET_REST_HANDLER_END 167 GNUNET_REST_HANDLER_END
165 }; 168 };
166 struct RequestHandle *handle = GNUNET_new(struct RequestHandle); 169 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
167 struct GNUNET_REST_RequestHandlerError err; 170 struct GNUNET_REST_RequestHandlerError err;
168 171
169 handle->proc_cls = proc_cls; 172 handle->proc_cls = proc_cls;
170 handle->proc = proc; 173 handle->proc = proc;
171 handle->rest_handle = conndata_handle; 174 handle->rest_handle = conndata_handle;
172 175
173 if (GNUNET_NO == GNUNET_REST_handle_request(conndata_handle, 176 if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle,
174 handlers, 177 handlers,
175 &err, 178 &err,
176 handle)) 179 handle))
177 { 180 {
178 handle->response_code = err.error_code; 181 handle->response_code = err.error_code;
179 GNUNET_SCHEDULER_add_now(&do_error, handle); 182 GNUNET_SCHEDULER_add_now (&do_error, handle);
180 } 183 }
181} 184}
182 185
183 186
@@ -188,7 +191,7 @@ rest_copying_process_request(struct GNUNET_REST_RequestHandle *conndata_handle,
188 * @return NULL on error, otherwise the plugin context 191 * @return NULL on error, otherwise the plugin context
189 */ 192 */
190void * 193void *
191libgnunet_plugin_rest_copying_init(void *cls) 194libgnunet_plugin_rest_copying_init (void *cls)
192{ 195{
193 static struct Plugin plugin; 196 static struct Plugin plugin;
194 197
@@ -197,14 +200,14 @@ libgnunet_plugin_rest_copying_init(void *cls)
197 200
198 if (NULL != plugin.cfg) 201 if (NULL != plugin.cfg)
199 return NULL; /* can only initialize once! */ 202 return NULL; /* can only initialize once! */
200 memset(&plugin, 0, sizeof(struct Plugin)); 203 memset (&plugin, 0, sizeof(struct Plugin));
201 plugin.cfg = cfg; 204 plugin.cfg = cfg;
202 api = GNUNET_new(struct GNUNET_REST_Plugin); 205 api = GNUNET_new (struct GNUNET_REST_Plugin);
203 api->cls = &plugin; 206 api->cls = &plugin;
204 api->name = GNUNET_REST_API_NS_COPYING; 207 api->name = GNUNET_REST_API_NS_COPYING;
205 api->process_request = &rest_copying_process_request; 208 api->process_request = &rest_copying_process_request;
206 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 209 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
207 _("COPYING REST API initialized\n")); 210 _ ("COPYING REST API initialized\n"));
208 return api; 211 return api;
209} 212}
210 213
@@ -216,15 +219,15 @@ libgnunet_plugin_rest_copying_init(void *cls)
216 * @return always NULL 219 * @return always NULL
217 */ 220 */
218void * 221void *
219libgnunet_plugin_rest_copying_done(void *cls) 222libgnunet_plugin_rest_copying_done (void *cls)
220{ 223{
221 struct GNUNET_REST_Plugin *api = cls; 224 struct GNUNET_REST_Plugin *api = cls;
222 struct Plugin *plugin = api->cls; 225 struct Plugin *plugin = api->cls;
223 226
224 plugin->cfg = NULL; 227 plugin->cfg = NULL;
225 GNUNET_free(api); 228 GNUNET_free (api);
226 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "COPYING REST plugin is finished\n"); 230 "COPYING REST plugin is finished\n");
228 return NULL; 231 return NULL;
229} 232}
230 233