aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-bcd.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/gns/gnunet-bcd.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/gns/gnunet-bcd.c')
-rw-r--r--src/gns/gnunet-bcd.c629
1 files changed, 314 insertions, 315 deletions
diff --git a/src/gns/gnunet-bcd.c b/src/gns/gnunet-bcd.c
index 368afbbf5..181c30d8d 100644
--- a/src/gns/gnunet-bcd.c
+++ b/src/gns/gnunet-bcd.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file gns/gnunet-bcd.c 22 * @file gns/gnunet-bcd.c
@@ -81,8 +81,7 @@ static char *resfile;
81static uint16_t port = 8888; 81static uint16_t port = 8888;
82 82
83 83
84struct Entry 84struct Entry {
85{
86 const char *formname; 85 const char *formname;
87 const char *texname; 86 const char *texname;
88}; 87};
@@ -92,175 +91,175 @@ struct Entry
92 * Main request handler. 91 * Main request handler.
93 */ 92 */
94static int 93static int
95access_handler_callback (void *cls, 94access_handler_callback(void *cls,
96 struct MHD_Connection *connection, 95 struct MHD_Connection *connection,
97 const char *url, 96 const char *url,
98 const char *method, 97 const char *method,
99 const char *version, 98 const char *version,
100 const char *upload_data, 99 const char *upload_data,
101 size_t *upload_data_size, 100 size_t *upload_data_size,
102 void **con_cls) 101 void **con_cls)
103{ 102{
104 static int dummy; 103 static int dummy;
105 static const struct Entry map[] = {{"prefix", "prefix"}, 104 static const struct Entry map[] = { { "prefix", "prefix" },
106 {"name", "name"}, 105 { "name", "name" },
107 {"suffix", "suffix"}, 106 { "suffix", "suffix" },
108 {"street", "street"}, 107 { "street", "street" },
109 {"city", "city"}, 108 { "city", "city" },
110 {"phone", "phone"}, 109 { "phone", "phone" },
111 {"fax", "fax"}, 110 { "fax", "fax" },
112 {"email", "email"}, 111 { "email", "email" },
113 {"homepage", "homepage"}, 112 { "homepage", "homepage" },
114 {"orga", "orga"}, 113 { "orga", "orga" },
115 {"departmenti18n", "departmentde"}, 114 { "departmenti18n", "departmentde" },
116 {"departmenten", "departmenten"}, 115 { "departmenten", "departmenten" },
117 {"subdepartmenti18n", "subdepartmentde"}, 116 { "subdepartmenti18n", "subdepartmentde" },
118 {"subdepartmenten", "subdepartmenten"}, 117 { "subdepartmenten", "subdepartmenten" },
119 {"jobtitlei18n", "jobtitlegerman"}, 118 { "jobtitlei18n", "jobtitlegerman" },
120 {"jobtitleen", "jobtitleenglish"}, 119 { "jobtitleen", "jobtitleenglish" },
121 {"subdepartmenten", "subdepartmenten"}, 120 { "subdepartmenten", "subdepartmenten" },
122 {NULL, NULL}}; 121 { NULL, NULL } };
123 122
124 (void) cls; 123 (void)cls;
125 (void) version; 124 (void)version;
126 (void) upload_data; 125 (void)upload_data;
127 (void) upload_data_size; 126 (void)upload_data_size;
128 if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) 127 if (0 != strcmp(method, MHD_HTTP_METHOD_GET))
129 {
130 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
131 _ ("Refusing `%s' request to HTTP server\n"),
132 method);
133 return MHD_NO;
134 }
135 if (NULL == *con_cls)
136 {
137 (*con_cls) = &dummy;
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n");
139 return MHD_YES; /* send 100 continue */
140 }
141 if (0 == strcasecmp (url, "/"))
142 return MHD_queue_response (connection, MHD_HTTP_OK, main_response);
143 if (0 == strcasecmp (url, "/submit.pdf"))
144 {
145 unsigned int i;
146 char *p;
147 char *tmp;
148 char *deffile;
149 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
150 size_t slen;
151 FILE *f;
152 struct stat st;
153 struct MHD_Response *response;
154 int fd;
155 int ret;
156
157 const char *gpg_fp = MHD_lookup_connection_value (connection,
158 MHD_GET_ARGUMENT_KIND,
159 "gpgfingerprint");
160 const char *gns_nick = MHD_lookup_connection_value (connection,
161 MHD_GET_ARGUMENT_KIND,
162 "gnsnick");
163 const char *gnskey =
164 MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "gnskey");
165 if ((NULL == gnskey) ||
166 (GNUNET_OK !=
167 GNUNET_CRYPTO_ecdsa_public_key_from_string (gnskey,
168 strlen (gnskey),
169 &pub)))
170 {
171 return MHD_queue_response (connection,
172 MHD_HTTP_OK,
173 invalid_gnskey_response);
174 }
175 tmp = GNUNET_DISK_mkdtemp (gnskey);
176 if (NULL == tmp)
177 {
178 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mktemp", gnskey);
179 return MHD_NO;
180 }
181 GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex");
182 f = fopen (deffile, "w");
183 if (NULL == f)
184 { 128 {
185 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile); 129 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
186 GNUNET_free (deffile); 130 _("Refusing `%s' request to HTTP server\n"),
187 GNUNET_DISK_directory_remove (tmp); 131 method);
188 GNUNET_free (tmp);
189 return MHD_NO; 132 return MHD_NO;
190 } 133 }
191 for (i = 0; NULL != map[i].formname; i++) 134 if (NULL == *con_cls)
192 {
193 const char *val = MHD_lookup_connection_value (connection,
194 MHD_GET_ARGUMENT_KIND,
195 map[i].formname);
196 if (NULL != val)
197 fprintf (f, "\\def\\%s{%s}\n", map[i].texname, val);
198 else
199 fprintf (f, "\\def\\%s{}\n", map[i].texname);
200 }
201 if (NULL != gpg_fp)
202 {
203 char *gpg1;
204 char *gpg2;
205
206 slen = strlen (gpg_fp);
207 gpg1 = GNUNET_strndup (gpg_fp, slen / 2);
208 gpg2 = GNUNET_strdup (&gpg_fp[slen / 2]);
209 fprintf (f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
210 GNUNET_free (gpg2);
211 GNUNET_free (gpg1);
212 }
213 fprintf (f,
214 "\\def\\gns{%s/%s}\n",
215 gnskey,
216 (NULL == gns_nick) ? "" : gns_nick);
217 fclose (f);
218 GNUNET_asprintf (
219 &p,
220 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
221 tmp,
222 resfile);
223 GNUNET_free (deffile);
224 ret = system (p);
225 if (WIFSIGNALED (ret) || (0 != WEXITSTATUS (ret)))
226 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "system", p);
227 GNUNET_asprintf (&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "gns-bcd.pdf");
228 fd = open (deffile, O_RDONLY);
229 if (-1 == fd)
230 { 135 {
231 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", deffile); 136 (*con_cls) = &dummy;
232 GNUNET_free (deffile); 137 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n");
233 GNUNET_free (p); 138 return MHD_YES; /* send 100 continue */
234 GNUNET_DISK_directory_remove (tmp);
235 GNUNET_free (tmp);
236 return MHD_NO;
237 } 139 }
238 GNUNET_break (0 == STAT (deffile, &st)); 140 if (0 == strcasecmp(url, "/"))
239 if (NULL == 141 return MHD_queue_response(connection, MHD_HTTP_OK, main_response);
240 (response = MHD_create_response_from_fd ((size_t) st.st_size, fd))) 142 if (0 == strcasecmp(url, "/submit.pdf"))
241 { 143 {
242 GNUNET_break (0); 144 unsigned int i;
243 GNUNET_break (0 == CLOSE (fd)); 145 char *p;
244 GNUNET_free (deffile); 146 char *tmp;
245 GNUNET_free (p); 147 char *deffile;
246 GNUNET_DISK_directory_remove (tmp); 148 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
247 GNUNET_free (tmp); 149 size_t slen;
248 return MHD_NO; 150 FILE *f;
249 } 151 struct stat st;
250 (void) MHD_add_response_header (response, 152 struct MHD_Response *response;
153 int fd;
154 int ret;
155
156 const char *gpg_fp = MHD_lookup_connection_value(connection,
157 MHD_GET_ARGUMENT_KIND,
158 "gpgfingerprint");
159 const char *gns_nick = MHD_lookup_connection_value(connection,
160 MHD_GET_ARGUMENT_KIND,
161 "gnsnick");
162 const char *gnskey =
163 MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "gnskey");
164 if ((NULL == gnskey) ||
165 (GNUNET_OK !=
166 GNUNET_CRYPTO_ecdsa_public_key_from_string(gnskey,
167 strlen(gnskey),
168 &pub)))
169 {
170 return MHD_queue_response(connection,
171 MHD_HTTP_OK,
172 invalid_gnskey_response);
173 }
174 tmp = GNUNET_DISK_mkdtemp(gnskey);
175 if (NULL == tmp)
176 {
177 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mktemp", gnskey);
178 return MHD_NO;
179 }
180 GNUNET_asprintf(&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "def.tex");
181 f = fopen(deffile, "w");
182 if (NULL == f)
183 {
184 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", deffile);
185 GNUNET_free(deffile);
186 GNUNET_DISK_directory_remove(tmp);
187 GNUNET_free(tmp);
188 return MHD_NO;
189 }
190 for (i = 0; NULL != map[i].formname; i++)
191 {
192 const char *val = MHD_lookup_connection_value(connection,
193 MHD_GET_ARGUMENT_KIND,
194 map[i].formname);
195 if (NULL != val)
196 fprintf(f, "\\def\\%s{%s}\n", map[i].texname, val);
197 else
198 fprintf(f, "\\def\\%s{}\n", map[i].texname);
199 }
200 if (NULL != gpg_fp)
201 {
202 char *gpg1;
203 char *gpg2;
204
205 slen = strlen(gpg_fp);
206 gpg1 = GNUNET_strndup(gpg_fp, slen / 2);
207 gpg2 = GNUNET_strdup(&gpg_fp[slen / 2]);
208 fprintf(f, "\\def\\gpglineone{%s}\n\\def\\gpglinetwo{%s}\n", gpg1, gpg2);
209 GNUNET_free(gpg2);
210 GNUNET_free(gpg1);
211 }
212 fprintf(f,
213 "\\def\\gns{%s/%s}\n",
214 gnskey,
215 (NULL == gns_nick) ? "" : gns_nick);
216 fclose(f);
217 GNUNET_asprintf(
218 &p,
219 "cd %s; cp %s gns-bcd.tex | pdflatex --enable-write18 gns-bcd.tex > /dev/null 2> /dev/null",
220 tmp,
221 resfile);
222 GNUNET_free(deffile);
223 ret = system(p);
224 if (WIFSIGNALED(ret) || (0 != WEXITSTATUS(ret)))
225 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "system", p);
226 GNUNET_asprintf(&deffile, "%s%s%s", tmp, DIR_SEPARATOR_STR, "gns-bcd.pdf");
227 fd = open(deffile, O_RDONLY);
228 if (-1 == fd)
229 {
230 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", deffile);
231 GNUNET_free(deffile);
232 GNUNET_free(p);
233 GNUNET_DISK_directory_remove(tmp);
234 GNUNET_free(tmp);
235 return MHD_NO;
236 }
237 GNUNET_break(0 == STAT(deffile, &st));
238 if (NULL ==
239 (response = MHD_create_response_from_fd((size_t)st.st_size, fd)))
240 {
241 GNUNET_break(0);
242 GNUNET_break(0 == CLOSE(fd));
243 GNUNET_free(deffile);
244 GNUNET_free(p);
245 GNUNET_DISK_directory_remove(tmp);
246 GNUNET_free(tmp);
247 return MHD_NO;
248 }
249 (void)MHD_add_response_header(response,
251 MHD_HTTP_HEADER_CONTENT_TYPE, 250 MHD_HTTP_HEADER_CONTENT_TYPE,
252 "application/pdf"); 251 "application/pdf");
253 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 252 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
254 MHD_destroy_response (response); 253 MHD_destroy_response(response);
255 GNUNET_free (deffile); 254 GNUNET_free(deffile);
256 GNUNET_free (p); 255 GNUNET_free(p);
257 GNUNET_DISK_directory_remove (tmp); 256 GNUNET_DISK_directory_remove(tmp);
258 GNUNET_free (tmp); 257 GNUNET_free(tmp);
259 return ret; 258 return ret;
260 } 259 }
261 return MHD_queue_response (connection, 260 return MHD_queue_response(connection,
262 MHD_HTTP_NOT_FOUND, 261 MHD_HTTP_NOT_FOUND,
263 not_found_response); 262 not_found_response);
264} 263}
265 264
266 265
@@ -269,7 +268,7 @@ access_handler_callback (void *cls,
269 * starts the task waiting for them. 268 * starts the task waiting for them.
270 */ 269 */
271static struct GNUNET_SCHEDULER_Task * 270static struct GNUNET_SCHEDULER_Task *
272prepare_daemon (struct MHD_Daemon *daemon_handle); 271prepare_daemon(struct MHD_Daemon *daemon_handle);
273 272
274 273
275/** 274/**
@@ -277,13 +276,13 @@ prepare_daemon (struct MHD_Daemon *daemon_handle);
277 * and schedule the next run. 276 * and schedule the next run.
278 */ 277 */
279static void 278static void
280run_daemon (void *cls) 279run_daemon(void *cls)
281{ 280{
282 struct MHD_Daemon *daemon_handle = cls; 281 struct MHD_Daemon *daemon_handle = cls;
283 282
284 http_task = NULL; 283 http_task = NULL;
285 GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); 284 GNUNET_assert(MHD_YES == MHD_run(daemon_handle));
286 http_task = prepare_daemon (daemon_handle); 285 http_task = prepare_daemon(daemon_handle);
287} 286}
288 287
289 288
@@ -292,7 +291,7 @@ run_daemon (void *cls)
292 * starts the task waiting for them. 291 * starts the task waiting for them.
293 */ 292 */
294static struct GNUNET_SCHEDULER_Task * 293static struct GNUNET_SCHEDULER_Task *
295prepare_daemon (struct MHD_Daemon *daemon_handle) 294prepare_daemon(struct MHD_Daemon *daemon_handle)
296{ 295{
297 struct GNUNET_SCHEDULER_Task *ret; 296 struct GNUNET_SCHEDULER_Task *ret;
298 fd_set rs; 297 fd_set rs;
@@ -305,28 +304,28 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
305 int haveto; 304 int haveto;
306 struct GNUNET_TIME_Relative tv; 305 struct GNUNET_TIME_Relative tv;
307 306
308 FD_ZERO (&rs); 307 FD_ZERO(&rs);
309 FD_ZERO (&ws); 308 FD_ZERO(&ws);
310 FD_ZERO (&es); 309 FD_ZERO(&es);
311 wrs = GNUNET_NETWORK_fdset_create (); 310 wrs = GNUNET_NETWORK_fdset_create();
312 wws = GNUNET_NETWORK_fdset_create (); 311 wws = GNUNET_NETWORK_fdset_create();
313 max = -1; 312 max = -1;
314 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); 313 GNUNET_assert(MHD_YES == MHD_get_fdset(daemon_handle, &rs, &ws, &es, &max));
315 haveto = MHD_get_timeout (daemon_handle, &timeout); 314 haveto = MHD_get_timeout(daemon_handle, &timeout);
316 if (haveto == MHD_YES) 315 if (haveto == MHD_YES)
317 tv.rel_value_us = (uint64_t) timeout * 1000LL; 316 tv.rel_value_us = (uint64_t)timeout * 1000LL;
318 else 317 else
319 tv = GNUNET_TIME_UNIT_FOREVER_REL; 318 tv = GNUNET_TIME_UNIT_FOREVER_REL;
320 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); 319 GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1);
321 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 320 GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1);
322 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 321 ret = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH,
323 tv, 322 tv,
324 wrs, 323 wrs,
325 wws, 324 wws,
326 &run_daemon, 325 &run_daemon,
327 daemon_handle); 326 daemon_handle);
328 GNUNET_NETWORK_fdset_destroy (wrs); 327 GNUNET_NETWORK_fdset_destroy(wrs);
329 GNUNET_NETWORK_fdset_destroy (wws); 328 GNUNET_NETWORK_fdset_destroy(wws);
330 return ret; 329 return ret;
331} 330}
332 331
@@ -337,41 +336,41 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
337 * @return #GNUNET_OK on success 336 * @return #GNUNET_OK on success
338 */ 337 */
339static int 338static int
340server_start () 339server_start()
341{ 340{
342 if (0 == port) 341 if (0 == port)
343 { 342 {
344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
345 _ ("Invalid port number %u. Exiting.\n"), 344 _("Invalid port number %u. Exiting.\n"),
346 port); 345 port);
347 return GNUNET_SYSERR; 346 return GNUNET_SYSERR;
348 } 347 }
349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 348 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
350 _ ("Businesscard HTTP server starts on %u\n"), 349 _("Businesscard HTTP server starts on %u\n"),
351 port); 350 port);
352 daemon_handle = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG, 351 daemon_handle = MHD_start_daemon(MHD_USE_DUAL_STACK | MHD_USE_DEBUG,
353 port, 352 port,
354 NULL /* accept_policy_callback */, 353 NULL /* accept_policy_callback */,
355 NULL, 354 NULL,
356 &access_handler_callback, 355 &access_handler_callback,
357 NULL, 356 NULL,
358 MHD_OPTION_CONNECTION_LIMIT, 357 MHD_OPTION_CONNECTION_LIMIT,
359 (unsigned int) 512, 358 (unsigned int)512,
360 MHD_OPTION_PER_IP_CONNECTION_LIMIT, 359 MHD_OPTION_PER_IP_CONNECTION_LIMIT,
361 (unsigned int) 2, 360 (unsigned int)2,
362 MHD_OPTION_CONNECTION_TIMEOUT, 361 MHD_OPTION_CONNECTION_TIMEOUT,
363 (unsigned int) 60, 362 (unsigned int)60,
364 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 363 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
365 (size_t) (16 * 1024), 364 (size_t)(16 * 1024),
366 MHD_OPTION_END); 365 MHD_OPTION_END);
367 if (NULL == daemon_handle) 366 if (NULL == daemon_handle)
368 { 367 {
369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 368 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
370 _ ("Could not start businesscard HTTP server on port %u\n"), 369 _("Could not start businesscard HTTP server on port %u\n"),
371 (unsigned int) port); 370 (unsigned int)port);
372 return GNUNET_SYSERR; 371 return GNUNET_SYSERR;
373 } 372 }
374 http_task = prepare_daemon (daemon_handle); 373 http_task = prepare_daemon(daemon_handle);
375 return GNUNET_OK; 374 return GNUNET_OK;
376} 375}
377 376
@@ -380,40 +379,40 @@ server_start ()
380 * Stop HTTP server. 379 * Stop HTTP server.
381 */ 380 */
382static void 381static void
383server_stop (void *cls) 382server_stop(void *cls)
384{ 383{
385 (void) cls; 384 (void)cls;
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n"); 385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "HTTP server shutdown\n");
387 if (NULL != http_task) 386 if (NULL != http_task)
388 { 387 {
389 GNUNET_SCHEDULER_cancel (http_task); 388 GNUNET_SCHEDULER_cancel(http_task);
390 http_task = NULL; 389 http_task = NULL;
391 } 390 }
392 if (NULL != daemon_handle) 391 if (NULL != daemon_handle)
393 { 392 {
394 MHD_stop_daemon (daemon_handle); 393 MHD_stop_daemon(daemon_handle);
395 daemon_handle = NULL; 394 daemon_handle = NULL;
396 } 395 }
397 if (NULL != main_response) 396 if (NULL != main_response)
398 { 397 {
399 MHD_destroy_response (main_response); 398 MHD_destroy_response(main_response);
400 main_response = NULL; 399 main_response = NULL;
401 } 400 }
402 if (NULL != invalid_gnskey_response) 401 if (NULL != invalid_gnskey_response)
403 { 402 {
404 MHD_destroy_response (invalid_gnskey_response); 403 MHD_destroy_response(invalid_gnskey_response);
405 invalid_gnskey_response = NULL; 404 invalid_gnskey_response = NULL;
406 } 405 }
407 if (NULL != not_found_response) 406 if (NULL != not_found_response)
408 { 407 {
409 MHD_destroy_response (not_found_response); 408 MHD_destroy_response(not_found_response);
410 not_found_response = NULL; 409 not_found_response = NULL;
411 } 410 }
412 if (NULL != resfile) 411 if (NULL != resfile)
413 { 412 {
414 GNUNET_free (resfile); 413 GNUNET_free(resfile);
415 resfile = NULL; 414 resfile = NULL;
416 } 415 }
417} 416}
418 417
419 418
@@ -426,66 +425,66 @@ server_stop (void *cls)
426 * @param c configuration 425 * @param c configuration
427 */ 426 */
428static void 427static void
429run (void *cls, 428run(void *cls,
430 char *const *args, 429 char *const *args,
431 const char *cfgfile, 430 const char *cfgfile,
432 const struct GNUNET_CONFIGURATION_Handle *c) 431 const struct GNUNET_CONFIGURATION_Handle *c)
433{ 432{
434 struct stat st; 433 struct stat st;
435 char *dir; 434 char *dir;
436 char *fn; 435 char *fn;
437 int fd; 436 int fd;
438 437
439 (void) cls; 438 (void)cls;
440 (void) args; 439 (void)args;
441 (void) cfgfile; 440 (void)cfgfile;
442 cfg = c; 441 cfg = c;
443 dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 442 dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR);
444 GNUNET_assert (NULL != dir); 443 GNUNET_assert(NULL != dir);
445 GNUNET_asprintf (&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html"); 444 GNUNET_asprintf(&fn, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.html");
446 GNUNET_asprintf (&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex"); 445 GNUNET_asprintf(&resfile, "%s%s%s", dir, DIR_SEPARATOR_STR, "gns-bcd.tex");
447 GNUNET_free (dir); 446 GNUNET_free(dir);
448 fd = open (fn, O_RDONLY); 447 fd = open(fn, O_RDONLY);
449 if (-1 == fd) 448 if (-1 == fd)
450 { 449 {
451 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); 450 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn);
452 GNUNET_free (fn); 451 GNUNET_free(fn);
453 return; 452 return;
454 } 453 }
455 if (0 != STAT (fn, &st)) 454 if (0 != STAT(fn, &st))
456 { 455 {
457 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn); 456 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", fn);
458 GNUNET_free (fn); 457 GNUNET_free(fn);
459 GNUNET_break (0 == CLOSE (fd)); 458 GNUNET_break(0 == CLOSE(fd));
460 return; 459 return;
461 } 460 }
462 GNUNET_free (fn); 461 GNUNET_free(fn);
463 if (NULL == 462 if (NULL ==
464 (main_response = MHD_create_response_from_fd ((size_t) st.st_size, fd))) 463 (main_response = MHD_create_response_from_fd((size_t)st.st_size, fd)))
465 { 464 {
466 GNUNET_break (0); 465 GNUNET_break(0);
467 GNUNET_break (0 == CLOSE (fd)); 466 GNUNET_break(0 == CLOSE(fd));
468 return; 467 return;
469 } 468 }
470 (void) MHD_add_response_header (main_response, 469 (void)MHD_add_response_header(main_response,
471 MHD_HTTP_HEADER_CONTENT_TYPE, 470 MHD_HTTP_HEADER_CONTENT_TYPE,
472 "text/html"); 471 "text/html");
473 invalid_gnskey_response = 472 invalid_gnskey_response =
474 MHD_create_response_from_buffer (strlen (INVALID_GNSKEY), 473 MHD_create_response_from_buffer(strlen(INVALID_GNSKEY),
475 INVALID_GNSKEY, 474 INVALID_GNSKEY,
476 MHD_RESPMEM_PERSISTENT); 475 MHD_RESPMEM_PERSISTENT);
477 (void) MHD_add_response_header (invalid_gnskey_response, 476 (void)MHD_add_response_header(invalid_gnskey_response,
478 MHD_HTTP_HEADER_CONTENT_TYPE, 477 MHD_HTTP_HEADER_CONTENT_TYPE,
479 "text/html"); 478 "text/html");
480 not_found_response = MHD_create_response_from_buffer (strlen (NOT_FOUND), 479 not_found_response = MHD_create_response_from_buffer(strlen(NOT_FOUND),
481 NOT_FOUND, 480 NOT_FOUND,
482 MHD_RESPMEM_PERSISTENT); 481 MHD_RESPMEM_PERSISTENT);
483 (void) MHD_add_response_header (not_found_response, 482 (void)MHD_add_response_header(not_found_response,
484 MHD_HTTP_HEADER_CONTENT_TYPE, 483 MHD_HTTP_HEADER_CONTENT_TYPE,
485 "text/html"); 484 "text/html");
486 if (GNUNET_OK != server_start ()) 485 if (GNUNET_OK != server_start())
487 return; 486 return;
488 GNUNET_SCHEDULER_add_shutdown (&server_stop, NULL); 487 GNUNET_SCHEDULER_add_shutdown(&server_stop, NULL);
489} 488}
490 489
491 490
@@ -497,33 +496,33 @@ run (void *cls,
497 * @return 0 ok, 1 on error 496 * @return 0 ok, 1 on error
498 */ 497 */
499int 498int
500main (int argc, char *const *argv) 499main(int argc, char *const *argv)
501{ 500{
502 struct GNUNET_GETOPT_CommandLineOption options[] = { 501 struct GNUNET_GETOPT_CommandLineOption options[] = {
503 502 GNUNET_GETOPT_option_uint16('p',
504 GNUNET_GETOPT_option_uint16 ('p', 503 "port",
505 "port", 504 "PORT",
506 "PORT", 505 gettext_noop(
507 gettext_noop ( 506 "Run HTTP serve on port PORT (default is 8888)"),
508 "Run HTTP serve on port PORT (default is 8888)"), 507 &port),
509 &port), 508 GNUNET_GETOPT_OPTION_END
510 GNUNET_GETOPT_OPTION_END}; 509 };
511 int ret; 510 int ret;
512 511
513 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 512 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
514 return 2; 513 return 2;
515 GNUNET_log_setup ("gnunet-bcd", "WARNING", NULL); 514 GNUNET_log_setup("gnunet-bcd", "WARNING", NULL);
516 ret = (GNUNET_OK == 515 ret = (GNUNET_OK ==
517 GNUNET_PROGRAM_run (argc, 516 GNUNET_PROGRAM_run(argc,
518 argv, 517 argv,
519 "gnunet-bcd", 518 "gnunet-bcd",
520 _ ("GNUnet HTTP server to create business cards"), 519 _("GNUnet HTTP server to create business cards"),
521 options, 520 options,
522 &run, 521 &run,
523 NULL)) 522 NULL))
524 ? 0 523 ? 0
525 : 1; 524 : 1;
526 GNUNET_free ((void *) argv); 525 GNUNET_free((void *)argv);
527 return ret; 526 return ret;
528} 527}
529 528