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