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