aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-namestore-fcfsd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-namestore-fcfsd.c')
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c1082
1 files changed, 548 insertions, 534 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c
index 3abf1ed21..93048ca1a 100644
--- a/src/namestore/gnunet-namestore-fcfsd.c
+++ b/src/namestore/gnunet-namestore-fcfsd.c
@@ -40,22 +40,26 @@
40/** 40/**
41 * Invalid method page. 41 * Invalid method page.
42 */ 42 */
43#define METHOD_ERROR "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>" 43#define METHOD_ERROR \
44 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>"
44 45
45/** 46/**
46 * Front page. (/) 47 * Front page. (/)
47 */ 48 */
48#define MAIN_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>" 49#define MAIN_PAGE \
50 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>"
49 51
50/** 52/**
51 * Second page (/S) 53 * Second page (/S)
52 */ 54 */
53#define SUBMIT_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>" 55#define SUBMIT_PAGE \
56 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>"
54 57
55/** 58/**
56 * Fcfs zoneinfo page (/Zoneinfo) 59 * Fcfs zoneinfo page (/Zoneinfo)
57 */ 60 */
58#define ZONEINFO_PAGE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>" 61#define ZONEINFO_PAGE \
62 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>"
59 63
60#define FCFS_ZONEINFO_URL "/Zoneinfo" 64#define FCFS_ZONEINFO_URL "/Zoneinfo"
61 65
@@ -74,7 +78,8 @@
74/** 78/**
75 * Phases a request goes through. 79 * Phases a request goes through.
76 */ 80 */
77enum Phase { 81enum Phase
82{
78 /** 83 /**
79 * Start phase (parsing POST, checking). 84 * Start phase (parsing POST, checking).
80 */ 85 */
@@ -105,7 +110,8 @@ enum Phase {
105/** 110/**
106 * Data kept per request. 111 * Data kept per request.
107 */ 112 */
108struct Request { 113struct Request
114{
109 /** 115 /**
110 * Associated session. 116 * Associated session.
111 */ 117 */
@@ -163,7 +169,8 @@ struct Request {
163/** 169/**
164 * Zoneinfo request 170 * Zoneinfo request
165 */ 171 */
166struct ZoneinfoRequest { 172struct ZoneinfoRequest
173{
167 /** 174 /**
168 * List iterator 175 * List iterator
169 */ 176 */
@@ -172,7 +179,7 @@ struct ZoneinfoRequest {
172 /** 179 /**
173 * Buffer 180 * Buffer
174 */ 181 */
175 char* zoneinfo; 182 char*zoneinfo;
176 183
177 /** 184 /**
178 * Buffer length 185 * Buffer length
@@ -193,7 +200,7 @@ static struct MHD_Daemon *httpd;
193/** 200/**
194 * Main HTTP task. 201 * Main HTTP task.
195 */ 202 */
196static struct GNUNET_SCHEDULER_Task * httpd_task; 203static struct GNUNET_SCHEDULER_Task *httpd_task;
197 204
198/** 205/**
199 * Handle to the namestore. 206 * Handle to the namestore.
@@ -242,21 +249,21 @@ static char *zone;
242 * @param cls unused 249 * @param cls unused
243 */ 250 */
244static void 251static void
245do_httpd(void *cls); 252do_httpd (void *cls);
246 253
247 254
248/** 255/**
249 * Schedule task to run MHD server now. 256 * Schedule task to run MHD server now.
250 */ 257 */
251static void 258static void
252run_httpd_now() 259run_httpd_now ()
253{ 260{
254 if (NULL != httpd_task) 261 if (NULL != httpd_task)
255 { 262 {
256 GNUNET_SCHEDULER_cancel(httpd_task); 263 GNUNET_SCHEDULER_cancel (httpd_task);
257 httpd_task = NULL; 264 httpd_task = NULL;
258 } 265 }
259 httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, NULL); 266 httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, NULL);
260} 267}
261 268
262 269
@@ -264,22 +271,22 @@ run_httpd_now()
264 * Create fresh version of zone information. 271 * Create fresh version of zone information.
265 */ 272 */
266static void 273static void
267update_zoneinfo_page(void *cls); 274update_zoneinfo_page (void *cls);
268 275
269 276
270/** 277/**
271 * Function called on error in zone iteration. 278 * Function called on error in zone iteration.
272 */ 279 */
273static void 280static void
274zone_iteration_error(void *cls) 281zone_iteration_error (void *cls)
275{ 282{
276 struct ZoneinfoRequest *zr = cls; 283 struct ZoneinfoRequest *zr = cls;
277 284
278 zr->list_it = NULL; 285 zr->list_it = NULL;
279 GNUNET_free(zr->zoneinfo); 286 GNUNET_free (zr->zoneinfo);
280 GNUNET_SCHEDULER_cancel(uzp_task); 287 GNUNET_SCHEDULER_cancel (uzp_task);
281 uzp_task = GNUNET_SCHEDULER_add_now(&update_zoneinfo_page, 288 uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page,
282 NULL); 289 NULL);
283} 290}
284 291
285 292
@@ -287,28 +294,28 @@ zone_iteration_error(void *cls)
287 * Function called once the zone iteration is done. 294 * Function called once the zone iteration is done.
288 */ 295 */
289static void 296static void
290zone_iteration_end(void *cls) 297zone_iteration_end (void *cls)
291{ 298{
292 struct ZoneinfoRequest *zr = cls; 299 struct ZoneinfoRequest *zr = cls;
293 struct MHD_Response *response; 300 struct MHD_Response *response;
294 char* full_page; 301 char*full_page;
295 302
296 zr->list_it = NULL; 303 zr->list_it = NULL;
297 304
298 /* return static form */ 305 /* return static form */
299 GNUNET_asprintf(&full_page, 306 GNUNET_asprintf (&full_page,
300 ZONEINFO_PAGE, 307 ZONEINFO_PAGE,
301 zr->zoneinfo, 308 zr->zoneinfo,
302 zr->zoneinfo); 309 zr->zoneinfo);
303 response = MHD_create_response_from_buffer(strlen(full_page), 310 response = MHD_create_response_from_buffer (strlen (full_page),
304 (void *)full_page, 311 (void *) full_page,
305 MHD_RESPMEM_MUST_FREE); 312 MHD_RESPMEM_MUST_FREE);
306 MHD_add_response_header(response, 313 MHD_add_response_header (response,
307 MHD_HTTP_HEADER_CONTENT_TYPE, 314 MHD_HTTP_HEADER_CONTENT_TYPE,
308 MIME_HTML); 315 MIME_HTML);
309 MHD_destroy_response(info_page); 316 MHD_destroy_response (info_page);
310 info_page = response; 317 info_page = response;
311 GNUNET_free(zr->zoneinfo); 318 GNUNET_free (zr->zoneinfo);
312} 319}
313 320
314 321
@@ -323,59 +330,59 @@ zone_iteration_end(void *cls)
323 * @param rd array of records with data to store 330 * @param rd array of records with data to store
324 */ 331 */
325static void 332static void
326iterate_cb(void *cls, 333iterate_cb (void *cls,
327 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 334 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
328 const char *name, 335 const char *name,
329 unsigned int rd_len, 336 unsigned int rd_len,
330 const struct GNUNET_GNSRECORD_Data *rd) 337 const struct GNUNET_GNSRECORD_Data *rd)
331{ 338{
332 struct ZoneinfoRequest *zr = cls; 339 struct ZoneinfoRequest *zr = cls;
333 size_t bytes_free; 340 size_t bytes_free;
334 char* pkey; 341 char*pkey;
335 char* new_buf; 342 char*new_buf;
336 343
337 (void)zone_key; 344 (void) zone_key;
338 if (1 != rd_len) 345 if (1 != rd_len)
339 { 346 {
340 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, 347 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
341 1); 348 1);
342 return; 349 return;
343 } 350 }
344 351
345 if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type) 352 if (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)
346 { 353 {
347 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, 354 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
348 1); 355 1);
349 return; 356 return;
350 } 357 }
351 358
352 bytes_free = zr->buf_len - zr->write_offset; 359 bytes_free = zr->buf_len - zr->write_offset;
353 pkey = GNUNET_GNSRECORD_value_to_string(rd->record_type, 360 pkey = GNUNET_GNSRECORD_value_to_string (rd->record_type,
354 rd->data, 361 rd->data,
355 rd->data_size); 362 rd->data_size);
356 if (NULL == pkey) 363 if (NULL == pkey)
357 { 364 {
358 GNUNET_break(0); 365 GNUNET_break (0);
359 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, 366 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
360 1); 367 1);
361 return; 368 return;
362 } 369 }
363 if (bytes_free < (strlen(name) + strlen(pkey) + 40)) 370 if (bytes_free < (strlen (name) + strlen (pkey) + 40))
364 { 371 {
365 new_buf = GNUNET_malloc(zr->buf_len * 2); 372 new_buf = GNUNET_malloc (zr->buf_len * 2);
366 GNUNET_memcpy(new_buf, zr->zoneinfo, zr->write_offset); 373 GNUNET_memcpy (new_buf, zr->zoneinfo, zr->write_offset);
367 GNUNET_free(zr->zoneinfo); 374 GNUNET_free (zr->zoneinfo);
368 zr->zoneinfo = new_buf; 375 zr->zoneinfo = new_buf;
369 zr->buf_len *= 2; 376 zr->buf_len *= 2;
370 } 377 }
371 sprintf(zr->zoneinfo + zr->write_offset, 378 sprintf (zr->zoneinfo + zr->write_offset,
372 "<tr><td>%s</td><td>%s</td></tr>", 379 "<tr><td>%s</td><td>%s</td></tr>",
373 name, 380 name,
374 pkey); 381 pkey);
375 zr->write_offset = strlen(zr->zoneinfo); 382 zr->write_offset = strlen (zr->zoneinfo);
376 GNUNET_NAMESTORE_zone_iterator_next(zr->list_it, 383 GNUNET_NAMESTORE_zone_iterator_next (zr->list_it,
377 1); 384 1);
378 GNUNET_free(pkey); 385 GNUNET_free (pkey);
379} 386}
380 387
381 388
@@ -385,11 +392,11 @@ iterate_cb(void *cls,
385 * @param connection connection to use 392 * @param connection connection to use
386 */ 393 */
387static int 394static int
388serve_zoneinfo_page(struct MHD_Connection *connection) 395serve_zoneinfo_page (struct MHD_Connection *connection)
389{ 396{
390 return MHD_queue_response(connection, 397 return MHD_queue_response (connection,
391 MHD_HTTP_OK, 398 MHD_HTTP_OK,
392 info_page); 399 info_page);
393} 400}
394 401
395 402
@@ -397,27 +404,27 @@ serve_zoneinfo_page(struct MHD_Connection *connection)
397 * Create fresh version of zone information. 404 * Create fresh version of zone information.
398 */ 405 */
399static void 406static void
400update_zoneinfo_page(void *cls) 407update_zoneinfo_page (void *cls)
401{ 408{
402 static struct ZoneinfoRequest zr; 409 static struct ZoneinfoRequest zr;
403 410
404 (void)cls; 411 (void) cls;
405 uzp_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 412 uzp_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
406 &update_zoneinfo_page, 413 &update_zoneinfo_page,
407 NULL); 414 NULL);
408 if (NULL != zr.list_it) 415 if (NULL != zr.list_it)
409 return; 416 return;
410 zr.zoneinfo = GNUNET_malloc(DEFAULT_ZONEINFO_BUFSIZE); 417 zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE);
411 zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE; 418 zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE;
412 zr.write_offset = 0; 419 zr.write_offset = 0;
413 zr.list_it = GNUNET_NAMESTORE_zone_iteration_start(ns, 420 zr.list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
414 &fcfs_zone_pkey, 421 &fcfs_zone_pkey,
415 &zone_iteration_error, 422 &zone_iteration_error,
416 &zr, 423 &zr,
417 &iterate_cb, 424 &iterate_cb,
418 &zr, 425 &zr,
419 &zone_iteration_end, 426 &zone_iteration_end,
420 &zr); 427 &zr);
421} 428}
422 429
423 430
@@ -428,22 +435,22 @@ update_zoneinfo_page(void *cls)
428 * @return #MHD_YES on success 435 * @return #MHD_YES on success
429 */ 436 */
430static int 437static int
431serve_main_page(struct MHD_Connection *connection) 438serve_main_page (struct MHD_Connection *connection)
432{ 439{
433 int ret; 440 int ret;
434 struct MHD_Response *response; 441 struct MHD_Response *response;
435 442
436 /* return static form */ 443 /* return static form */
437 response = MHD_create_response_from_buffer(strlen(MAIN_PAGE), 444 response = MHD_create_response_from_buffer (strlen (MAIN_PAGE),
438 (void *)MAIN_PAGE, 445 (void *) MAIN_PAGE,
439 MHD_RESPMEM_PERSISTENT); 446 MHD_RESPMEM_PERSISTENT);
440 MHD_add_response_header(response, 447 MHD_add_response_header (response,
441 MHD_HTTP_HEADER_CONTENT_TYPE, 448 MHD_HTTP_HEADER_CONTENT_TYPE,
442 MIME_HTML); 449 MIME_HTML);
443 ret = MHD_queue_response(connection, 450 ret = MHD_queue_response (connection,
444 MHD_HTTP_OK, 451 MHD_HTTP_OK,
445 response); 452 response);
446 MHD_destroy_response(response); 453 MHD_destroy_response (response);
447 return ret; 454 return ret;
448} 455}
449 456
@@ -456,30 +463,30 @@ serve_main_page(struct MHD_Connection *connection)
456 * @param connection connection to use 463 * @param connection connection to use
457 */ 464 */
458static int 465static int
459fill_s_reply(const char *info, 466fill_s_reply (const char *info,
460 struct Request *request, 467 struct Request *request,
461 struct MHD_Connection *connection) 468 struct MHD_Connection *connection)
462{ 469{
463 int ret; 470 int ret;
464 char *reply; 471 char *reply;
465 struct MHD_Response *response; 472 struct MHD_Response *response;
466 473
467 (void)request; 474 (void) request;
468 GNUNET_asprintf(&reply, 475 GNUNET_asprintf (&reply,
469 SUBMIT_PAGE, 476 SUBMIT_PAGE,
470 info, 477 info,
471 info); 478 info);
472 /* return static form */ 479 /* return static form */
473 response = MHD_create_response_from_buffer(strlen(reply), 480 response = MHD_create_response_from_buffer (strlen (reply),
474 (void *)reply, 481 (void *) reply,
475 MHD_RESPMEM_MUST_FREE); 482 MHD_RESPMEM_MUST_FREE);
476 MHD_add_response_header(response, 483 MHD_add_response_header (response,
477 MHD_HTTP_HEADER_CONTENT_TYPE, 484 MHD_HTTP_HEADER_CONTENT_TYPE,
478 MIME_HTML); 485 MIME_HTML);
479 ret = MHD_queue_response(connection, 486 ret = MHD_queue_response (connection,
480 MHD_HTTP_OK, 487 MHD_HTTP_OK,
481 response); 488 response);
482 MHD_destroy_response(response); 489 MHD_destroy_response (response);
483 return ret; 490 return ret;
484} 491}
485 492
@@ -504,45 +511,45 @@ fill_s_reply(const char *info,
504 * MHD_NO to abort the iteration 511 * MHD_NO to abort the iteration
505 */ 512 */
506static int 513static int
507post_iterator(void *cls, 514post_iterator (void *cls,
508 enum MHD_ValueKind kind, 515 enum MHD_ValueKind kind,
509 const char *key, 516 const char *key,
510 const char *filename, 517 const char *filename,
511 const char *content_type, 518 const char *content_type,
512 const char *transfer_encoding, 519 const char *transfer_encoding,
513 const char *data, 520 const char *data,
514 uint64_t off, 521 uint64_t off,
515 size_t size) 522 size_t size)
516{ 523{
517 struct Request *request = cls; 524 struct Request *request = cls;
518 525
519 (void)kind; 526 (void) kind;
520 (void)filename; 527 (void) filename;
521 (void)content_type; 528 (void) content_type;
522 (void)transfer_encoding; 529 (void) transfer_encoding;
523 if (0 == strcmp("domain", key)) 530 if (0 == strcmp ("domain", key))
524 { 531 {
525 if (size + off >= sizeof(request->domain_name)) 532 if (size + off >= sizeof(request->domain_name))
526 size = sizeof(request->domain_name) - off - 1; 533 size = sizeof(request->domain_name) - off - 1;
527 GNUNET_memcpy(&request->domain_name[off], 534 GNUNET_memcpy (&request->domain_name[off],
528 data, 535 data,
529 size); 536 size);
530 request->domain_name[size + off] = '\0'; 537 request->domain_name[size + off] = '\0';
531 return MHD_YES; 538 return MHD_YES;
532 } 539 }
533 if (0 == strcmp("pkey", key)) 540 if (0 == strcmp ("pkey", key))
534 { 541 {
535 if (size + off >= sizeof(request->public_key)) 542 if (size + off >= sizeof(request->public_key))
536 size = sizeof(request->public_key) - off - 1; 543 size = sizeof(request->public_key) - off - 1;
537 GNUNET_memcpy(&request->public_key[off], 544 GNUNET_memcpy (&request->public_key[off],
538 data, 545 data,
539 size); 546 size);
540 request->public_key[size + off] = '\0'; 547 request->public_key[size + off] = '\0';
541 return MHD_YES; 548 return MHD_YES;
542 } 549 }
543 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 550 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
544 _("Unsupported form value `%s'\n"), 551 _ ("Unsupported form value `%s'\n"),
545 key); 552 key);
546 return MHD_YES; 553 return MHD_YES;
547} 554}
548 555
@@ -558,25 +565,25 @@ post_iterator(void *cls,
558 * @param emsg NULL on success, otherwise an error message 565 * @param emsg NULL on success, otherwise an error message
559 */ 566 */
560static void 567static void
561put_continuation(void *cls, 568put_continuation (void *cls,
562 int32_t success, 569 int32_t success,
563 const char *emsg) 570 const char *emsg)
564{ 571{
565 struct Request *request = cls; 572 struct Request *request = cls;
566 573
567 request->qe = NULL; 574 request->qe = NULL;
568 if (0 >= success) 575 if (0 >= success)
569 { 576 {
570 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 577 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
571 _("Failed to create record for domain `%s': %s\n"), 578 _ ("Failed to create record for domain `%s': %s\n"),
572 request->domain_name, 579 request->domain_name,
573 emsg); 580 emsg);
574 request->phase = RP_FAIL; 581 request->phase = RP_FAIL;
575 } 582 }
576 else 583 else
577 request->phase = RP_SUCCESS; 584 request->phase = RP_SUCCESS;
578 MHD_resume_connection(request->con); 585 MHD_resume_connection (request->con);
579 run_httpd_now(); 586 run_httpd_now ();
580} 587}
581 588
582 589
@@ -584,15 +591,15 @@ put_continuation(void *cls,
584 * Function called if we had an error in zone-to-name mapping. 591 * Function called if we had an error in zone-to-name mapping.
585 */ 592 */
586static void 593static void
587zone_to_name_error(void *cls) 594zone_to_name_error (void *cls)
588{ 595{
589 struct Request *request = cls; 596 struct Request *request = cls;
590 597
591 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
592 _("Error when mapping zone to name\n")); 599 _ ("Error when mapping zone to name\n"));
593 request->phase = RP_FAIL; 600 request->phase = RP_FAIL;
594 MHD_resume_connection(request->con); 601 MHD_resume_connection (request->con);
595 run_httpd_now(); 602 run_httpd_now ();
596} 603}
597 604
598 605
@@ -606,39 +613,39 @@ zone_to_name_error(void *cls)
606 * @param rd array of records with data to store 613 * @param rd array of records with data to store
607 */ 614 */
608static void 615static void
609zone_to_name_cb(void *cls, 616zone_to_name_cb (void *cls,
610 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, 617 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
611 const char *name, 618 const char *name,
612 unsigned int rd_count, 619 unsigned int rd_count,
613 const struct GNUNET_GNSRECORD_Data *rd) 620 const struct GNUNET_GNSRECORD_Data *rd)
614{ 621{
615 struct Request *request = cls; 622 struct Request *request = cls;
616 struct GNUNET_GNSRECORD_Data r; 623 struct GNUNET_GNSRECORD_Data r;
617 624
618 (void)rd; 625 (void) rd;
619 (void)zone_key; 626 (void) zone_key;
620 request->qe = NULL; 627 request->qe = NULL;
621 if (0 != rd_count) 628 if (0 != rd_count)
622 { 629 {
623 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 630 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
624 _("Found existing name `%s' for the given key\n"), 631 _ ("Found existing name `%s' for the given key\n"),
625 name); 632 name);
626 request->phase = RP_FAIL; 633 request->phase = RP_FAIL;
627 MHD_resume_connection(request->con); 634 MHD_resume_connection (request->con);
628 run_httpd_now(); 635 run_httpd_now ();
629 return; 636 return;
630 } 637 }
631 r.data = &request->pub; 638 r.data = &request->pub;
632 r.data_size = sizeof(request->pub); 639 r.data_size = sizeof(request->pub);
633 r.expiration_time = UINT64_MAX; 640 r.expiration_time = UINT64_MAX;
634 r.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 641 r.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
635 r.flags = GNUNET_GNSRECORD_RF_NONE; 642 r.flags = GNUNET_GNSRECORD_RF_NONE;
636 request->qe = GNUNET_NAMESTORE_records_store(ns, 643 request->qe = GNUNET_NAMESTORE_records_store (ns,
637 &fcfs_zone_pkey, 644 &fcfs_zone_pkey,
638 request->domain_name, 645 request->domain_name,
639 1, &r, 646 1, &r,
640 &put_continuation, 647 &put_continuation,
641 request); 648 request);
642} 649}
643 650
644 651
@@ -646,14 +653,14 @@ zone_to_name_cb(void *cls,
646 * We encountered an error in the name lookup. 653 * We encountered an error in the name lookup.
647 */ 654 */
648static void 655static void
649lookup_it_error(void *cls) 656lookup_it_error (void *cls)
650{ 657{
651 struct Request *request = cls; 658 struct Request *request = cls;
652 659
653 MHD_resume_connection(request->con); 660 MHD_resume_connection (request->con);
654 request->qe = NULL; 661 request->qe = NULL;
655 request->phase = RP_FAIL; 662 request->phase = RP_FAIL;
656 run_httpd_now(); 663 run_httpd_now ();
657} 664}
658 665
659 666
@@ -668,58 +675,58 @@ lookup_it_error(void *cls)
668 * @param rd array of records with data to store 675 * @param rd array of records with data to store
669 */ 676 */
670static void 677static void
671lookup_it_processor(void *cls, 678lookup_it_processor (void *cls,
672 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, 679 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey,
673 const char *label, 680 const char *label,
674 unsigned int rd_count, 681 unsigned int rd_count,
675 const struct GNUNET_GNSRECORD_Data *rd) 682 const struct GNUNET_GNSRECORD_Data *rd)
676{ 683{
677 struct Request *request = cls; 684 struct Request *request = cls;
678 685
679 (void)label; 686 (void) label;
680 (void)rd; 687 (void) rd;
681 (void)zonekey; 688 (void) zonekey;
682 if (0 == strcmp(label, request->domain_name)) 689 if (0 == strcmp (label, request->domain_name))
683 { 690 {
684 GNUNET_break(0 != rd_count); 691 GNUNET_break (0 != rd_count);
685 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 692 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
686 _("Found %u existing records for domain `%s'\n"), 693 _ ("Found %u existing records for domain `%s'\n"),
687 rd_count, 694 rd_count,
688 request->domain_name); 695 request->domain_name);
689 request->phase = RP_FAIL; 696 request->phase = RP_FAIL;
690 } 697 }
691 GNUNET_NAMESTORE_zone_iterator_next(request->lookup_it, 1); 698 GNUNET_NAMESTORE_zone_iterator_next (request->lookup_it, 1);
692} 699}
693 700
694static void 701static void
695lookup_it_finished(void *cls) 702lookup_it_finished (void *cls)
696{ 703{
697 struct Request *request = cls; 704 struct Request *request = cls;
698 705
699 if (RP_FAIL == request->phase) 706 if (RP_FAIL == request->phase)
700 { 707 {
701 MHD_resume_connection(request->con); 708 MHD_resume_connection (request->con);
702 run_httpd_now(); 709 run_httpd_now ();
703 return; 710 return;
704 } 711 }
705 if (GNUNET_OK != 712 if (GNUNET_OK !=
706 GNUNET_CRYPTO_ecdsa_public_key_from_string(request->public_key, 713 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
707 strlen(request->public_key), 714 strlen (request->public_key),
708 &request->pub)) 715 &request->pub))
709 { 716 {
710 GNUNET_break(0); 717 GNUNET_break (0);
711 request->phase = RP_FAIL; 718 request->phase = RP_FAIL;
712 MHD_resume_connection(request->con); 719 MHD_resume_connection (request->con);
713 run_httpd_now(); 720 run_httpd_now ();
714 return; 721 return;
715 } 722 }
716 request->qe = GNUNET_NAMESTORE_zone_to_name(ns, 723 request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
717 &fcfs_zone_pkey, 724 &fcfs_zone_pkey,
718 &request->pub, 725 &request->pub,
719 &zone_to_name_error, 726 &zone_to_name_error,
720 request, 727 request,
721 &zone_to_name_cb, 728 &zone_to_name_cb,
722 request); 729 request);
723} 730}
724 731
725/** 732/**
@@ -746,141 +753,142 @@ lookup_it_finished(void *cls)
746 * error while handling the request 753 * error while handling the request
747 */ 754 */
748static int 755static int
749create_response(void *cls, 756create_response (void *cls,
750 struct MHD_Connection *connection, 757 struct MHD_Connection *connection,
751 const char *url, 758 const char *url,
752 const char *method, 759 const char *method,
753 const char *version, 760 const char *version,
754 const char *upload_data, 761 const char *upload_data,
755 size_t *upload_data_size, 762 size_t *upload_data_size,
756 void **ptr) 763 void **ptr)
757{ 764{
758 struct MHD_Response *response; 765 struct MHD_Response *response;
759 struct Request *request; 766 struct Request *request;
760 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 767 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
761 int ret; 768 int ret;
762 769
763 (void)cls; 770 (void) cls;
764 (void)version; 771 (void) version;
765 if ((0 == strcmp(method, MHD_HTTP_METHOD_GET)) || 772 if ((0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
766 (0 == strcmp(method, MHD_HTTP_METHOD_HEAD))) 773 (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)))
774 {
775 if (0 == strcmp (url, FCFS_ZONEINFO_URL))
776 ret = serve_zoneinfo_page (connection);
777 else
778 ret = serve_main_page (connection);
779 if (ret != MHD_YES)
780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
781 _ ("Failed to create page for `%s'\n"),
782 url);
783 return ret;
784 }
785 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
786 {
787 request = *ptr;
788 if (NULL == request)
789 {
790 request = GNUNET_new (struct Request);
791 request->con = connection;
792 *ptr = request;
793 request->pp = MHD_create_post_processor (connection,
794 1024,
795 &post_iterator,
796 request);
797 if (NULL == request->pp)
798 {
799 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
800 _ ("Failed to setup post processor for `%s'\n"),
801 url);
802 return MHD_NO; /* internal error */
803 }
804 return MHD_YES;
805 }
806 if (NULL != request->pp)
767 { 807 {
768 if (0 == strcmp(url, FCFS_ZONEINFO_URL)) 808 /* evaluate POST data */
769 ret = serve_zoneinfo_page(connection); 809 MHD_post_process (request->pp,
770 else 810 upload_data,
771 ret = serve_main_page(connection); 811 *upload_data_size);
772 if (ret != MHD_YES) 812 if (0 != *upload_data_size)
773 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 813 {
774 _("Failed to create page for `%s'\n"), 814 *upload_data_size = 0;
775 url); 815 return MHD_YES;
776 return ret; 816 }
817 /* done with POST data, serve response */
818 MHD_destroy_post_processor (request->pp);
819 request->pp = NULL;
777 } 820 }
778 if (0 == strcmp(method, MHD_HTTP_METHOD_POST)) 821 if (GNUNET_OK !=
822 GNUNET_CRYPTO_ecdsa_public_key_from_string (request->public_key,
823 strlen (
824 request->public_key),
825 &pub))
779 { 826 {
780 request = *ptr; 827 /* parse error */
781 if (NULL == request) 828 return fill_s_reply ("Failed to parse given public key",
782 { 829 request, connection);
783 request = GNUNET_new(struct Request);
784 request->con = connection;
785 *ptr = request;
786 request->pp = MHD_create_post_processor(connection,
787 1024,
788 &post_iterator,
789 request);
790 if (NULL == request->pp)
791 {
792 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
793 _("Failed to setup post processor for `%s'\n"),
794 url);
795 return MHD_NO; /* internal error */
796 }
797 return MHD_YES;
798 }
799 if (NULL != request->pp)
800 {
801 /* evaluate POST data */
802 MHD_post_process(request->pp,
803 upload_data,
804 *upload_data_size);
805 if (0 != *upload_data_size)
806 {
807 *upload_data_size = 0;
808 return MHD_YES;
809 }
810 /* done with POST data, serve response */
811 MHD_destroy_post_processor(request->pp);
812 request->pp = NULL;
813 }
814 if (GNUNET_OK !=
815 GNUNET_CRYPTO_ecdsa_public_key_from_string(request->public_key,
816 strlen(request->public_key),
817 &pub))
818 {
819 /* parse error */
820 return fill_s_reply("Failed to parse given public key",
821 request, connection);
822 }
823 switch (request->phase)
824 {
825 case RP_START:
826 if (NULL != strchr(request->domain_name, (int)'.'))
827 {
828 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
829 _("Domain name must not contain `.'\n"));
830 request->phase = RP_FAIL;
831 return fill_s_reply("Domain name must not contain `.', sorry.",
832 request,
833 connection);
834 }
835 if (NULL != strchr(request->domain_name, (int)'+'))
836 {
837 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
838 _("Domain name must not contain `+'\n"));
839 request->phase = RP_FAIL;
840 return fill_s_reply("Domain name must not contain `+', sorry.",
841 request, connection);
842 }
843 request->phase = RP_LOOKUP;
844 MHD_suspend_connection(request->con);
845 request->lookup_it
846 = GNUNET_NAMESTORE_zone_iteration_start(ns,
847 &fcfs_zone_pkey,
848 &lookup_it_error,
849 request,
850 &lookup_it_processor,
851 request,
852 &lookup_it_finished,
853 request);
854 break;
855
856 case RP_LOOKUP:
857 break;
858
859 case RP_PUT:
860 break;
861
862 case RP_FAIL:
863 return fill_s_reply("Request failed, sorry.",
864 request, connection);
865
866 case RP_SUCCESS:
867 return fill_s_reply("Success.",
868 request, connection);
869
870 default:
871 GNUNET_break(0);
872 return MHD_NO;
873 }
874 return MHD_YES; /* will have a reply later... */
875 } 830 }
831 switch (request->phase)
832 {
833 case RP_START:
834 if (NULL != strchr (request->domain_name, (int) '.'))
835 {
836 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
837 _ ("Domain name must not contain `.'\n"));
838 request->phase = RP_FAIL;
839 return fill_s_reply ("Domain name must not contain `.', sorry.",
840 request,
841 connection);
842 }
843 if (NULL != strchr (request->domain_name, (int) '+'))
844 {
845 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
846 _ ("Domain name must not contain `+'\n"));
847 request->phase = RP_FAIL;
848 return fill_s_reply ("Domain name must not contain `+', sorry.",
849 request, connection);
850 }
851 request->phase = RP_LOOKUP;
852 MHD_suspend_connection (request->con);
853 request->lookup_it
854 = GNUNET_NAMESTORE_zone_iteration_start (ns,
855 &fcfs_zone_pkey,
856 &lookup_it_error,
857 request,
858 &lookup_it_processor,
859 request,
860 &lookup_it_finished,
861 request);
862 break;
863
864 case RP_LOOKUP:
865 break;
866
867 case RP_PUT:
868 break;
869
870 case RP_FAIL:
871 return fill_s_reply ("Request failed, sorry.",
872 request, connection);
873
874 case RP_SUCCESS:
875 return fill_s_reply ("Success.",
876 request, connection);
877
878 default:
879 GNUNET_break (0);
880 return MHD_NO;
881 }
882 return MHD_YES; /* will have a reply later... */
883 }
876 /* unsupported HTTP method */ 884 /* unsupported HTTP method */
877 response = MHD_create_response_from_buffer(strlen(METHOD_ERROR), 885 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
878 (void *)METHOD_ERROR, 886 (void *) METHOD_ERROR,
879 MHD_RESPMEM_PERSISTENT); 887 MHD_RESPMEM_PERSISTENT);
880 ret = MHD_queue_response(connection, 888 ret = MHD_queue_response (connection,
881 MHD_HTTP_NOT_ACCEPTABLE, 889 MHD_HTTP_NOT_ACCEPTABLE,
882 response); 890 response);
883 MHD_destroy_response(response); 891 MHD_destroy_response (response);
884 return ret; 892 return ret;
885} 893}
886 894
@@ -895,23 +903,23 @@ create_response(void *cls,
895 * @param toe status code 903 * @param toe status code
896 */ 904 */
897static void 905static void
898request_completed_callback(void *cls, 906request_completed_callback (void *cls,
899 struct MHD_Connection *connection, 907 struct MHD_Connection *connection,
900 void **con_cls, 908 void **con_cls,
901 enum MHD_RequestTerminationCode toe) 909 enum MHD_RequestTerminationCode toe)
902{ 910{
903 struct Request *request = *con_cls; 911 struct Request *request = *con_cls;
904 912
905 (void)cls; 913 (void) cls;
906 (void)connection; 914 (void) connection;
907 (void)toe; 915 (void) toe;
908 if (NULL == request) 916 if (NULL == request)
909 return; 917 return;
910 if (NULL != request->pp) 918 if (NULL != request->pp)
911 MHD_destroy_post_processor(request->pp); 919 MHD_destroy_post_processor (request->pp);
912 if (NULL != request->qe) 920 if (NULL != request->qe)
913 GNUNET_NAMESTORE_cancel(request->qe); 921 GNUNET_NAMESTORE_cancel (request->qe);
914 GNUNET_free(request); 922 GNUNET_free (request);
915} 923}
916 924
917 925
@@ -922,7 +930,7 @@ request_completed_callback(void *cls,
922 * Schedule tasks to run MHD server. 930 * Schedule tasks to run MHD server.
923 */ 931 */
924static void 932static void
925run_httpd() 933run_httpd ()
926{ 934{
927 fd_set rs; 935 fd_set rs;
928 fd_set ws; 936 fd_set ws;
@@ -935,44 +943,44 @@ run_httpd()
935 UNSIGNED_MHD_LONG_LONG timeout; 943 UNSIGNED_MHD_LONG_LONG timeout;
936 struct GNUNET_TIME_Relative tv; 944 struct GNUNET_TIME_Relative tv;
937 945
938 FD_ZERO(&rs); 946 FD_ZERO (&rs);
939 FD_ZERO(&ws); 947 FD_ZERO (&ws);
940 FD_ZERO(&es); 948 FD_ZERO (&es);
941 wrs = GNUNET_NETWORK_fdset_create(); 949 wrs = GNUNET_NETWORK_fdset_create ();
942 wes = GNUNET_NETWORK_fdset_create(); 950 wes = GNUNET_NETWORK_fdset_create ();
943 wws = GNUNET_NETWORK_fdset_create(); 951 wws = GNUNET_NETWORK_fdset_create ();
944 max = -1; 952 max = -1;
945 GNUNET_assert(MHD_YES == 953 GNUNET_assert (MHD_YES ==
946 MHD_get_fdset(httpd, 954 MHD_get_fdset (httpd,
947 &rs, 955 &rs,
948 &ws, 956 &ws,
949 &es, 957 &es,
950 &max)); 958 &max));
951 haveto = MHD_get_timeout(httpd, 959 haveto = MHD_get_timeout (httpd,
952 &timeout); 960 &timeout);
953 if (haveto == MHD_YES) 961 if (haveto == MHD_YES)
954 tv.rel_value_us = (uint64_t)timeout * 1000LL; 962 tv.rel_value_us = (uint64_t) timeout * 1000LL;
955 else 963 else
956 tv = GNUNET_TIME_UNIT_FOREVER_REL; 964 tv = GNUNET_TIME_UNIT_FOREVER_REL;
957 GNUNET_NETWORK_fdset_copy_native(wrs, 965 GNUNET_NETWORK_fdset_copy_native (wrs,
958 &rs, 966 &rs,
959 max + 1); 967 max + 1);
960 GNUNET_NETWORK_fdset_copy_native(wws, 968 GNUNET_NETWORK_fdset_copy_native (wws,
961 &ws, 969 &ws,
962 max + 1); 970 max + 1);
963 GNUNET_NETWORK_fdset_copy_native(wes, 971 GNUNET_NETWORK_fdset_copy_native (wes,
964 &es, 972 &es,
965 max + 1); 973 max + 1);
966 httpd_task = 974 httpd_task =
967 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, 975 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
968 tv, 976 tv,
969 wrs, 977 wrs,
970 wws, 978 wws,
971 &do_httpd, 979 &do_httpd,
972 NULL); 980 NULL);
973 GNUNET_NETWORK_fdset_destroy(wrs); 981 GNUNET_NETWORK_fdset_destroy (wrs);
974 GNUNET_NETWORK_fdset_destroy(wws); 982 GNUNET_NETWORK_fdset_destroy (wws);
975 GNUNET_NETWORK_fdset_destroy(wes); 983 GNUNET_NETWORK_fdset_destroy (wes);
976} 984}
977 985
978 986
@@ -982,12 +990,12 @@ run_httpd()
982 * @param cls unused 990 * @param cls unused
983 */ 991 */
984static void 992static void
985do_httpd(void *cls) 993do_httpd (void *cls)
986{ 994{
987 (void)cls; 995 (void) cls;
988 httpd_task = NULL; 996 httpd_task = NULL;
989 MHD_run(httpd); 997 MHD_run (httpd);
990 run_httpd(); 998 run_httpd ();
991} 999}
992 1000
993 1001
@@ -997,39 +1005,39 @@ do_httpd(void *cls)
997 * @param cls unused 1005 * @param cls unused
998 */ 1006 */
999static void 1007static void
1000do_shutdown(void *cls) 1008do_shutdown (void *cls)
1001{ 1009{
1002 (void)cls; 1010 (void) cls;
1003 if (NULL != httpd_task) 1011 if (NULL != httpd_task)
1004 { 1012 {
1005 GNUNET_SCHEDULER_cancel(httpd_task); 1013 GNUNET_SCHEDULER_cancel (httpd_task);
1006 httpd_task = NULL; 1014 httpd_task = NULL;
1007 } 1015 }
1008 if (NULL != uzp_task) 1016 if (NULL != uzp_task)
1009 { 1017 {
1010 GNUNET_SCHEDULER_cancel(uzp_task); 1018 GNUNET_SCHEDULER_cancel (uzp_task);
1011 uzp_task = NULL; 1019 uzp_task = NULL;
1012 } 1020 }
1013 if (NULL != ns) 1021 if (NULL != ns)
1014 { 1022 {
1015 GNUNET_NAMESTORE_disconnect(ns); 1023 GNUNET_NAMESTORE_disconnect (ns);
1016 ns = NULL; 1024 ns = NULL;
1017 } 1025 }
1018 if (NULL != httpd) 1026 if (NULL != httpd)
1019 { 1027 {
1020 MHD_stop_daemon(httpd); 1028 MHD_stop_daemon (httpd);
1021 httpd = NULL; 1029 httpd = NULL;
1022 } 1030 }
1023 if (NULL != id_op) 1031 if (NULL != id_op)
1024 { 1032 {
1025 GNUNET_IDENTITY_cancel(id_op); 1033 GNUNET_IDENTITY_cancel (id_op);
1026 id_op = NULL; 1034 id_op = NULL;
1027 } 1035 }
1028 if (NULL != identity) 1036 if (NULL != identity)
1029 { 1037 {
1030 GNUNET_IDENTITY_disconnect(identity); 1038 GNUNET_IDENTITY_disconnect (identity);
1031 identity = NULL; 1039 identity = NULL;
1032 } 1040 }
1033} 1041}
1034 1042
1035 1043
@@ -1053,55 +1061,59 @@ do_shutdown(void *cls)
1053 * must thus no longer be used 1061 * must thus no longer be used
1054 */ 1062 */
1055static void 1063static void
1056identity_cb(void *cls, 1064identity_cb (void *cls,
1057 struct GNUNET_IDENTITY_Ego *ego, 1065 struct GNUNET_IDENTITY_Ego *ego,
1058 void **ctx, 1066 void **ctx,
1059 const char *name) 1067 const char *name)
1060{ 1068{
1061 int options; 1069 int options;
1062 1070
1063 (void)cls; 1071 (void) cls;
1064 (void)ctx; 1072 (void) ctx;
1065 if (NULL == name) 1073 if (NULL == name)
1066 return; 1074 return;
1067 if (0 != strcmp(name, 1075 if (0 != strcmp (name,
1068 zone)) 1076 zone))
1069 return; 1077 return;
1070 if (NULL == ego) 1078 if (NULL == ego)
1071 { 1079 {
1072 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1080 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1073 _("No ego configured for `fcfsd` subsystem\n")); 1081 _ ("No ego configured for `fcfsd` subsystem\n"));
1074 GNUNET_SCHEDULER_shutdown(); 1082 GNUNET_SCHEDULER_shutdown ();
1075 return; 1083 return;
1076 } 1084 }
1077 fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key(ego); 1085 fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1078 1086
1079 options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME; 1087 options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
1080 do 1088 do
1081 { 1089 {
1082 httpd = MHD_start_daemon(options, 1090 httpd = MHD_start_daemon (options,
1083 (uint16_t)port, 1091 (uint16_t) port,
1084 NULL, NULL, 1092 NULL, NULL,
1085 &create_response, NULL, 1093 &create_response, NULL,
1086 MHD_OPTION_CONNECTION_LIMIT, (unsigned int)128, 1094 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128,
1087 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int)1, 1095 MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned
1088 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16, 1096 int) 1,
1089 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(4 * 1024), 1097 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
1090 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, 1098 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4
1091 MHD_OPTION_END); 1099 *
1092 if (MHD_USE_DEBUG == options) 1100 1024),
1093 break; 1101 MHD_OPTION_NOTIFY_COMPLETED,
1094 options = MHD_USE_DEBUG; 1102 &request_completed_callback, NULL,
1095 } 1103 MHD_OPTION_END);
1104 if (MHD_USE_DEBUG == options)
1105 break;
1106 options = MHD_USE_DEBUG;
1107 }
1096 while (NULL == httpd); 1108 while (NULL == httpd);
1097 if (NULL == httpd) 1109 if (NULL == httpd)
1098 { 1110 {
1099 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1100 _("Failed to start HTTP server\n")); 1112 _ ("Failed to start HTTP server\n"));
1101 GNUNET_SCHEDULER_shutdown(); 1113 GNUNET_SCHEDULER_shutdown ();
1102 return; 1114 return;
1103 } 1115 }
1104 run_httpd(); 1116 run_httpd ();
1105} 1117}
1106 1118
1107 1119
@@ -1114,44 +1126,44 @@ identity_cb(void *cls,
1114 * @param cfg configuration 1126 * @param cfg configuration
1115 */ 1127 */
1116static void 1128static void
1117run(void *cls, 1129run (void *cls,
1118 char *const *args, 1130 char *const *args,
1119 const char *cfgfile, 1131 const char *cfgfile,
1120 const struct GNUNET_CONFIGURATION_Handle *cfg) 1132 const struct GNUNET_CONFIGURATION_Handle *cfg)
1121{ 1133{
1122 (void)cls; 1134 (void) cls;
1123 (void)args; 1135 (void) args;
1124 (void)cfgfile; 1136 (void) cfgfile;
1125 if (GNUNET_OK != 1137 if (GNUNET_OK !=
1126 GNUNET_CONFIGURATION_get_value_number(cfg, 1138 GNUNET_CONFIGURATION_get_value_number (cfg,
1127 "fcfsd", 1139 "fcfsd",
1128 "HTTPPORT", 1140 "HTTPPORT",
1129 &port)) 1141 &port))
1130 { 1142 {
1131 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, 1143 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1132 "fcfsd", "HTTPPORT"); 1144 "fcfsd", "HTTPPORT");
1133 return; 1145 return;
1134 } 1146 }
1135 ns = GNUNET_NAMESTORE_connect(cfg); 1147 ns = GNUNET_NAMESTORE_connect (cfg);
1136 if (NULL == ns) 1148 if (NULL == ns)
1137 { 1149 {
1138 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1139 _("Failed to connect to namestore\n")); 1151 _ ("Failed to connect to namestore\n"));
1140 return; 1152 return;
1141 } 1153 }
1142 identity = GNUNET_IDENTITY_connect(cfg, 1154 identity = GNUNET_IDENTITY_connect (cfg,
1143 &identity_cb, 1155 &identity_cb,
1144 NULL);
1145 if (NULL == identity)
1146 {
1147 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1148 _("Failed to connect to identity\n"));
1149 return;
1150 }
1151 uzp_task = GNUNET_SCHEDULER_add_now(&update_zoneinfo_page,
1152 NULL); 1156 NULL);
1153 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 1157 if (NULL == identity)
1154 NULL); 1158 {
1159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1160 _ ("Failed to connect to identity\n"));
1161 return;
1162 }
1163 uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page,
1164 NULL);
1165 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
1166 NULL);
1155} 1167}
1156 1168
1157 1169
@@ -1163,38 +1175,40 @@ run(void *cls,
1163 * @return 0 ok, 1 on error 1175 * @return 0 ok, 1 on error
1164 */ 1176 */
1165int 1177int
1166main(int argc, 1178main (int argc,
1167 char *const *argv) 1179 char *const *argv)
1168{ 1180{
1169 struct GNUNET_GETOPT_CommandLineOption options[] = { 1181 struct GNUNET_GETOPT_CommandLineOption options[] = {
1170 GNUNET_GETOPT_option_mandatory 1182 GNUNET_GETOPT_option_mandatory
1171 (GNUNET_GETOPT_option_string('z', 1183 (GNUNET_GETOPT_option_string ('z',
1172 "zone", 1184 "zone",
1173 "EGO", 1185 "EGO",
1174 gettext_noop("name of the zone that is to be managed by FCFSD"), 1186 gettext_noop (
1175 &zone)), 1187 "name of the zone that is to be managed by FCFSD"),
1188 &zone)),
1176 GNUNET_GETOPT_OPTION_END 1189 GNUNET_GETOPT_OPTION_END
1177 }; 1190 };
1178 int ret; 1191 int ret;
1179 1192
1180 if (GNUNET_OK != 1193 if (GNUNET_OK !=
1181 GNUNET_STRINGS_get_utf8_args(argc, argv, 1194 GNUNET_STRINGS_get_utf8_args (argc, argv,
1182 &argc, &argv)) 1195 &argc, &argv))
1183 return 2; 1196 return 2;
1184 1197
1185 GNUNET_log_setup("fcfsd", 1198 GNUNET_log_setup ("fcfsd",
1186 "WARNING", 1199 "WARNING",
1187 NULL); 1200 NULL);
1188 ret = 1201 ret =
1189 (GNUNET_OK == 1202 (GNUNET_OK ==
1190 GNUNET_PROGRAM_run(argc, 1203 GNUNET_PROGRAM_run (argc,
1191 argv, 1204 argv,
1192 "gnunet-namestore-fcfsd", 1205 "gnunet-namestore-fcfsd",
1193 _("GNU Name System First Come First Serve name registration service"), 1206 _ (
1194 options, 1207 "GNU Name System First Come First Serve name registration service"),
1195 &run, NULL)) ? 0 : 1; 1208 options,
1196 GNUNET_free((void*)argv); 1209 &run, NULL)) ? 0 : 1;
1197 GNUNET_CRYPTO_ecdsa_key_clear(&fcfs_zone_pkey); 1210 GNUNET_free ((void*) argv);
1211 GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey);
1198 return ret; 1212 return ret;
1199} 1213}
1200 1214