aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2023-01-18 10:07:43 +0100
committert3sserakt <t3ss@posteo.de>2023-01-18 10:07:43 +0100
commitde50c9a2d090008afe835b09e5697ec07e08e51c (patch)
tree22ecea674adbaaf5e777b4d6e5be951551673c95 /src
parent9d6ace0b9d6eae42eecaca542ae62ac30de589f8 (diff)
parent6b56928ab52b29e4302ce2cbcc1feaa9b0ebd126 (diff)
downloadgnunet-de50c9a2d090008afe835b09e5697ec07e08e51c.tar.gz
gnunet-de50c9a2d090008afe835b09e5697ec07e08e51c.zip
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_common.h2
-rw-r--r--src/include/gnunet_mysql_compat.h8
-rw-r--r--src/pq/pq.h5
-rw-r--r--src/pq/pq_event.c10
-rw-r--r--src/rest/gnunet-rest-server.c4
-rw-r--r--src/testing/testing_api_loop.c47
-rw-r--r--src/util/bio.c47
-rw-r--r--src/util/test_bio.c199
8 files changed, 195 insertions, 127 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index ac472d166..9b2b50f01 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -164,7 +164,6 @@ enum GNUNET_GenericReturnValue
164 * Endian operations 164 * Endian operations
165 */ 165 */
166 166
167#if __BYTE_ORDER == __LITTLE_ENDIAN
168#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64) 167#if defined(bswap_16) || defined(bswap_32) || defined(bswap_64)
169#define BYTE_SWAP_16(x) bswap_16 (x) 168#define BYTE_SWAP_16(x) bswap_16 (x)
170#define BYTE_SWAP_32(x) bswap_32 (x) 169#define BYTE_SWAP_32(x) bswap_32 (x)
@@ -184,6 +183,7 @@ enum GNUNET_GenericReturnValue
184 56)) 183 56))
185#endif 184#endif
186 185
186#if __BYTE_ORDER == __LITTLE_ENDIAN
187#define GNUNET_htobe16(x) BYTE_SWAP_16 (x) 187#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
188#define GNUNET_htole16(x) (x) 188#define GNUNET_htole16(x) (x)
189#define GNUNET_be16toh(x) BYTE_SWAP_16 (x) 189#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
diff --git a/src/include/gnunet_mysql_compat.h b/src/include/gnunet_mysql_compat.h
index bb1e8de8a..9fb9db30f 100644
--- a/src/include/gnunet_mysql_compat.h
+++ b/src/include/gnunet_mysql_compat.h
@@ -42,13 +42,13 @@ extern "C"
42#endif 42#endif
43 43
44#ifndef LIBMARIADB 44#ifndef LIBMARIADB
45#if MYSQL_VERSION_ID < 80000 45#if MYSQL_VERSION_ID >= 80000
46#define MYSQL_BOOL bool; 46#define MYSQL_BOOL bool
47#else 47#else
48#define MYSQL_BOOL my_bool; //MySQL < 8 wants this 48#define MYSQL_BOOL my_bool /* MySQL < 8 wants this */
49#endif 49#endif
50#else 50#else
51#define MYSQL_BOOL my_bool //MariaDB still uses my_bool 51#define MYSQL_BOOL my_bool /* MariaDB still uses my_bool */
52#endif 52#endif
53 53
54#if 0 /* keep Emacsens' auto-indent happy */ 54#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/pq/pq.h b/src/pq/pq.h
index 85cfcc070..f9b59e058 100644
--- a/src/pq/pq.h
+++ b/src/pq/pq.h
@@ -90,6 +90,11 @@ struct GNUNET_PQ_Context
90 struct GNUNET_NETWORK_Handle *rfd; 90 struct GNUNET_NETWORK_Handle *rfd;
91 91
92 /** 92 /**
93 * How fast should we resubscribe again?
94 */
95 struct GNUNET_TIME_Relative resubscribe_backoff;
96
97 /**
93 * Flags controlling the connection. 98 * Flags controlling the connection.
94 */ 99 */
95 enum GNUNET_PQ_Options flags; 100 enum GNUNET_PQ_Options flags;
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c
index b0ed6798a..6dbacf7ff 100644
--- a/src/pq/pq_event.c
+++ b/src/pq/pq_event.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021, 2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -283,11 +283,17 @@ do_scheduler_notify (void *cls)
283 "Resubscribing\n"); 283 "Resubscribing\n");
284 if (NULL == db->rfd) 284 if (NULL == db->rfd)
285 { 285 {
286 db->resubscribe_backoff
287 = GNUNET_TIME_relative_max (db->resubscribe_backoff,
288 GNUNET_TIME_UNIT_SECONDS);
289 db->resubscribe_backoff
290 = GNUNET_TIME_STD_BACKOFF (db->resubscribe_backoff);
286 db->event_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 291 db->event_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
287 &do_scheduler_notify, 292 &do_scheduler_notify,
288 db); 293 db);
289 return; 294 return;
290 } 295 }
296 db->resubscribe_backoff = GNUNET_TIME_UNIT_SECONDS;
291 db->event_task 297 db->event_task
292 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 298 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
293 db->rfd, 299 db->rfd,
@@ -387,7 +393,7 @@ manage_subscribe (struct GNUNET_PQ_Context *db,
387 * @param value the event handler 393 * @param value the event handler
388 * @return #GNUNET_OK to continue to iterate 394 * @return #GNUNET_OK to continue to iterate
389 */ 395 */
390static int 396static enum GNUNET_GenericReturnValue
391register_notify (void *cls, 397register_notify (void *cls,
392 const struct GNUNET_ShortHashCode *sh, 398 const struct GNUNET_ShortHashCode *sh,
393 void *value) 399 void *value)
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c
index 1ea4471d1..f9a949e61 100644
--- a/src/rest/gnunet-rest-server.c
+++ b/src/rest/gnunet-rest-server.c
@@ -132,7 +132,7 @@ static char *basic_auth_secret;
132/** 132/**
133 * User of the service 133 * User of the service
134 */ 134 */
135char cuser[LOGIN_NAME_MAX]; 135char cuser[_POSIX_LOGIN_NAME_MAX];
136 136
137/** 137/**
138 * Allowed Origins (CORS) 138 * Allowed Origins (CORS)
@@ -1207,7 +1207,7 @@ run (void *cls,
1207 GNUNET_SCHEDULER_shutdown (); 1207 GNUNET_SCHEDULER_shutdown ();
1208 return; 1208 return;
1209 } 1209 }
1210 if (0 != getlogin_r (cuser, LOGIN_NAME_MAX)) 1210 if (0 != getlogin_r (cuser, _POSIX_LOGIN_NAME_MAX))
1211 { 1211 {
1212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1213 "Unable to get user.\n"); 1213 "Unable to get user.\n");
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 5385a53d7..7d719afc0 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -25,7 +25,6 @@
25 * @author Marcello Stanisci (GNU Taler testing) 25 * @author Marcello Stanisci (GNU Taler testing)
26 * @author t3sserakt 26 * @author t3sserakt
27 */ 27 */
28#include "gnunet_common.h"
29#include "platform.h" 28#include "platform.h"
30#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
31#include "gnunet_testing_ng_lib.h" 30#include "gnunet_testing_ng_lib.h"
@@ -520,6 +519,7 @@ GNUNET_TESTING_run (const struct GNUNET_TESTING_Command *commands,
520 return is; 519 return is;
521} 520}
522 521
522
523struct GNUNET_TESTING_Command 523struct GNUNET_TESTING_Command
524GNUNET_TESTING_command_new (void *cls, 524GNUNET_TESTING_command_new (void *cls,
525 const char *label, 525 const char *label,
@@ -543,6 +543,7 @@ GNUNET_TESTING_command_new (void *cls,
543 543
544} 544}
545 545
546
546/** 547/**
547 * Closure for #loop_run(). 548 * Closure for #loop_run().
548 */ 549 */
@@ -603,6 +604,7 @@ loop_run (void *cls)
603 mp); 604 mp);
604} 605}
605 606
607
606/** 608/**
607 * Continuation function from GNUNET_HELPER_send() 609 * Continuation function from GNUNET_HELPER_send()
608 * 610 *
@@ -617,6 +619,7 @@ clear_msg (void *cls, int result)
617 GNUNET_assert (GNUNET_YES == result); 619 GNUNET_assert (GNUNET_YES == result);
618} 620}
619 621
622
620/** 623/**
621 * Adding a helper handle to the interpreter. 624 * Adding a helper handle to the interpreter.
622 * 625 *
@@ -632,7 +635,7 @@ GNUNET_TESTING_add_netjail_helper (struct GNUNET_TESTING_Interpreter *is,
632 635
633 636
634/** 637/**
635 * Send Message to netjail nodes. 638 * Send Message to netjail nodes.
636 * 639 *
637 * @param is The interpreter. 640 * @param is The interpreter.
638 * @param global_node_number The netjail node to inform. 641 * @param global_node_number The netjail node to inform.
@@ -640,8 +643,8 @@ GNUNET_TESTING_add_netjail_helper (struct GNUNET_TESTING_Interpreter *is,
640 */ 643 */
641void 644void
642send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is, 645send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is,
643 unsigned int global_node_number, 646 unsigned int global_node_number,
644 struct GNUNET_MessageHeader *header) 647 struct GNUNET_MessageHeader *header)
645{ 648{
646 const struct GNUNET_HELPER_Handle *helper; 649 const struct GNUNET_HELPER_Handle *helper;
647 650
@@ -657,10 +660,11 @@ send_message_to_netjail (struct GNUNET_TESTING_Interpreter *is,
657 NULL); 660 NULL);
658} 661}
659 662
663
660void 664void
661TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is, 665TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
662 const char *barrier_name, 666 const char *barrier_name,
663 unsigned int global_node_number) 667 unsigned int global_node_number)
664{ 668{
665 struct CommandBarrierCrossable *adm; 669 struct CommandBarrierCrossable *adm;
666 size_t msg_length; 670 size_t msg_length;
@@ -677,13 +681,12 @@ TST_interpreter_send_barrier_crossable (struct GNUNET_TESTING_Interpreter *is,
677 adm->header.size = htons ((uint16_t) msg_length); 681 adm->header.size = htons ((uint16_t) msg_length);
678 memcpy (&adm[1], barrier_name, name_len); 682 memcpy (&adm[1], barrier_name, name_len);
679 send_message_to_netjail (is, 683 send_message_to_netjail (is,
680 global_node_number, 684 global_node_number,
681 &adm->header); 685 &adm->header);
682 GNUNET_free (adm); 686 GNUNET_free (adm);
683} 687}
684 688
685 689
686
687int 690int
688free_barrier_node_cb (void *cls, 691free_barrier_node_cb (void *cls,
689 const struct GNUNET_ShortHashCode *key, 692 const struct GNUNET_ShortHashCode *key,
@@ -699,12 +702,13 @@ free_barrier_node_cb (void *cls,
699 if (GNUNET_NO == is->finishing) 702 if (GNUNET_NO == is->finishing)
700 { 703 {
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 "TST_interpreter_send_barrier_crossable\n"); 705 "TST_interpreter_send_barrier_crossable\n");
703 TST_interpreter_send_barrier_crossable (is, 706 TST_interpreter_send_barrier_crossable (is,
704 barrier->name, 707 barrier->name,
705 node->node_number); 708 node->node_number);
706 } 709 }
707 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (barrier->nodes, key, node)); 710 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (
711 barrier->nodes, key, node));
708 return GNUNET_YES; 712 return GNUNET_YES;
709} 713}
710 714
@@ -718,7 +722,7 @@ free_barrier_node_cb (void *cls,
718 */ 722 */
719struct GNUNET_TESTING_Barrier * 723struct GNUNET_TESTING_Barrier *
720TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is, 724TST_interpreter_get_barrier (struct GNUNET_TESTING_Interpreter *is,
721 const char *barrier_name) 725 const char *barrier_name)
722{ 726{
723 struct GNUNET_HashCode hc; 727 struct GNUNET_HashCode hc;
724 struct GNUNET_ShortHashCode create_key; 728 struct GNUNET_ShortHashCode create_key;
@@ -745,7 +749,7 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
745 struct CommandListEntry *pos; 749 struct CommandListEntry *pos;
746 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls; 750 struct FreeBarrierNodeCbCls *free_barrier_node_cb_cls;
747 struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is, 751 struct GNUNET_TESTING_Barrier *barrier = TST_interpreter_get_barrier (is,
748 barrier_name); 752 barrier_name);
749 753
750 while (NULL != barrier && NULL != (pos = barrier->cmds_head)) 754 while (NULL != barrier && NULL != (pos = barrier->cmds_head))
751 { 755 {
@@ -756,8 +760,8 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
756 GNUNET_NO == pos->command->asynchronous_finish) 760 GNUNET_NO == pos->command->asynchronous_finish)
757 { 761 {
758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
759 "command label %s finish\n", 763 "command label %s finish\n",
760 pos->command->label); 764 pos->command->label);
761 GNUNET_TESTING_async_finish (pos->command->ac); 765 GNUNET_TESTING_async_finish (pos->command->ac);
762 } 766 }
763 else if (GNUNET_NO == pos->command->ac->finished) 767 else if (GNUNET_NO == pos->command->ac->finished)
@@ -781,7 +785,8 @@ TST_interpreter_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is,
781 free_barrier_node_cb_cls->is = is; 785 free_barrier_node_cb_cls->is = is;
782 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
783 "freeing nodes\n"); 787 "freeing nodes\n");
784 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, free_barrier_node_cb, 788 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
789 free_barrier_node_cb,
785 free_barrier_node_cb_cls); 790 free_barrier_node_cb_cls);
786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
787 "nodes freed\n"); 792 "nodes freed\n");
@@ -807,7 +812,8 @@ free_barriers_cb (void *cls,
807 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls); 812 free_barrier_node_cb_cls = GNUNET_new (struct FreeBarrierNodeCbCls);
808 free_barrier_node_cb_cls->barrier = barrier; 813 free_barrier_node_cb_cls->barrier = barrier;
809 free_barrier_node_cb_cls->is = is; 814 free_barrier_node_cb_cls->is = is;
810 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes, free_barrier_node_cb, 815 GNUNET_CONTAINER_multishortmap_iterate (barrier->nodes,
816 free_barrier_node_cb,
811 free_barrier_node_cb_cls); 817 free_barrier_node_cb_cls);
812 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes); 818 GNUNET_CONTAINER_multishortmap_destroy (barrier->nodes);
813 barrier->nodes = NULL; 819 barrier->nodes = NULL;
@@ -824,6 +830,7 @@ free_barriers_cb (void *cls,
824 return GNUNET_YES; 830 return GNUNET_YES;
825} 831}
826 832
833
827/** 834/**
828 * Deleting all barriers create in the context of this interpreter. 835 * Deleting all barriers create in the context of this interpreter.
829 * 836 *
@@ -847,7 +854,7 @@ TST_interpreter_delete_barriers (struct GNUNET_TESTING_Interpreter *is)
847 */ 854 */
848void 855void
849TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is, 856TST_interpreter_add_barrier (struct GNUNET_TESTING_Interpreter *is,
850 struct GNUNET_TESTING_Barrier *barrier) 857 struct GNUNET_TESTING_Barrier *barrier)
851{ 858{
852 struct GNUNET_HashCode hc; 859 struct GNUNET_HashCode hc;
853 struct GNUNET_ShortHashCode create_key; 860 struct GNUNET_ShortHashCode create_key;
diff --git a/src/util/bio.c b/src/util/bio.c
index 70620aea7..7e3aa0d16 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -182,8 +182,9 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
182 return err; 182 return err;
183} 183}
184 184
185
185void 186void
186GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg) 187GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char*emsg)
187{ 188{
188 GNUNET_assert (NULL == h->emsg); 189 GNUNET_assert (NULL == h->emsg);
189 h->emsg = GNUNET_strdup (emsg); 190 h->emsg = GNUNET_strdup (emsg);
@@ -380,7 +381,6 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
380} 381}
381 382
382 383
383
384/** 384/**
385 * Read a float. 385 * Read a float.
386 * 386 *
@@ -510,13 +510,12 @@ GNUNET_BIO_write_open_file (const char *fn)
510 struct GNUNET_DISK_FileHandle *fd; 510 struct GNUNET_DISK_FileHandle *fd;
511 struct GNUNET_BIO_WriteHandle *h; 511 struct GNUNET_BIO_WriteHandle *h;
512 512
513 fd = 513 fd = GNUNET_DISK_file_open (fn,
514 GNUNET_DISK_file_open (fn, 514 GNUNET_DISK_OPEN_WRITE
515 GNUNET_DISK_OPEN_WRITE 515 | GNUNET_DISK_OPEN_TRUNCATE
516 | GNUNET_DISK_OPEN_TRUNCATE 516 | GNUNET_DISK_OPEN_CREATE,
517 | GNUNET_DISK_OPEN_CREATE, 517 GNUNET_DISK_PERM_USER_READ
518 GNUNET_DISK_PERM_USER_READ 518 | GNUNET_DISK_PERM_USER_WRITE);
519 | GNUNET_DISK_PERM_USER_WRITE);
520 if (NULL == fd) 519 if (NULL == fd)
521 return NULL; 520 return NULL;
522 h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); 521 h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
@@ -553,8 +552,9 @@ GNUNET_BIO_write_open_buffer (void)
553 * if the handle has an error message, the return value is #GNUNET_SYSERR 552 * if the handle has an error message, the return value is #GNUNET_SYSERR
554 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 553 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
555 */ 554 */
556int 555enum GNUNET_GenericReturnValue
557GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg) 556GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h,
557 char **emsg)
558{ 558{
559 int err; 559 int err;
560 560
@@ -567,7 +567,10 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
567 { 567 {
568 case IO_FILE: 568 case IO_FILE:
569 if (NULL == h->fd) 569 if (NULL == h->fd)
570 return GNUNET_SYSERR; 570 {
571 err = GNUNET_SYSERR;
572 break;
573 }
571 if (GNUNET_OK != GNUNET_BIO_flush (h)) 574 if (GNUNET_OK != GNUNET_BIO_flush (h))
572 { 575 {
573 if (NULL != emsg) 576 if (NULL != emsg)
@@ -600,21 +603,23 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
600 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned 603 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
601 * and the file is closed 604 * and the file is closed
602 */ 605 */
603int 606enum GNUNET_GenericReturnValue
604GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) 607GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
605{ 608{
606 ssize_t ret; 609 ssize_t ret;
607 610
608 if (IO_FILE != h->type) 611 if (IO_FILE != h->type)
609 return GNUNET_OK; 612 return GNUNET_OK;
610 613 ret = GNUNET_DISK_file_write (h->fd,
611 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); 614 h->buffer,
615 h->have);
612 if (ret != (ssize_t) h->have) 616 if (ret != (ssize_t) h->have)
613 { 617 {
614 GNUNET_DISK_file_close (h->fd); 618 GNUNET_DISK_file_close (h->fd);
615 h->fd = NULL; 619 h->fd = NULL;
616 GNUNET_free (h->emsg); 620 GNUNET_free (h->emsg);
617 GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file")); 621 GNUNET_asprintf (&h->emsg,
622 "Unable to flush buffer to file");
618 return GNUNET_SYSERR; 623 return GNUNET_SYSERR;
619 } 624 }
620 h->have = 0; 625 h->have = 0;
@@ -634,7 +639,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
634 * @param size where to store the size of @e contents 639 * @param size where to store the size of @e contents
635 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 640 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
636 */ 641 */
637int 642enum GNUNET_GenericReturnValue
638GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, 643GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
639 char **emsg, 644 char **emsg,
640 void **contents, 645 void **contents,
@@ -644,7 +649,10 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
644 return GNUNET_SYSERR; 649 return GNUNET_SYSERR;
645 if ((NULL == contents) || (NULL == size)) 650 if ((NULL == contents) || (NULL == size))
646 return GNUNET_SYSERR; 651 return GNUNET_SYSERR;
647 int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK; 652 enum GNUNET_GenericReturnValue ret
653 = (NULL != h->emsg)
654 ? GNUNET_SYSERR
655 : GNUNET_OK;
648 if (NULL != emsg) 656 if (NULL != emsg)
649 *emsg = h->emsg; 657 *emsg = h->emsg;
650 else 658 else
@@ -663,7 +671,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
663 * @param len the number of bytes to write 671 * @param len the number of bytes to write
664 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 672 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
665 */ 673 */
666static int 674static enum GNUNET_GenericReturnValue
667write_to_file (struct GNUNET_BIO_WriteHandle *h, 675write_to_file (struct GNUNET_BIO_WriteHandle *h,
668 const char *what, 676 const char *what,
669 const char *source, 677 const char *source,
@@ -793,7 +801,6 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
793} 801}
794 802
795 803
796
797/** 804/**
798 * Write a float. 805 * Write a float.
799 * 806 *
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index 90f0121d4..b407eccfe 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V. 3 Copyright (C) 2009, 2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -17,15 +17,11 @@
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
20
21/** 20/**
22 * @file util/test_bio.c 21 * @file util/test_bio.c
23 * @brief testcase for the buffered IO module 22 * @brief testcase for the buffered IO module
24 * @author Ji Lu 23 * @author Ji Lu
25 */ 24 */
26
27
28
29#include "platform.h" 25#include "platform.h"
30#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
31#define TESTSTRING "testString" 27#define TESTSTRING "testString"
@@ -43,53 +39,74 @@ test_normal_rw (void)
43 char *rString = NULL; 39 char *rString = NULL;
44 int64_t wNum = TESTNUMBER64; 40 int64_t wNum = TESTNUMBER64;
45 int64_t rNum = 0; 41 int64_t rNum = 0;
46
47 struct GNUNET_BIO_WriteSpec ws[] = { 42 struct GNUNET_BIO_WriteSpec ws[] = {
48 GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING), 43 GNUNET_BIO_write_spec_string ("test-normal-rw-string",
49 GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum), 44 TESTSTRING),
45 GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64",
46 &wNum),
50 GNUNET_BIO_write_spec_end (), 47 GNUNET_BIO_write_spec_end (),
51 }; 48 };
52
53 struct GNUNET_BIO_ReadSpec rs[] = { 49 struct GNUNET_BIO_ReadSpec rs[] = {
54 GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200), 50 GNUNET_BIO_read_spec_string ("test-normal-rw-string",
55 GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64", &rNum), 51 &rString,
52 200),
53 GNUNET_BIO_read_spec_int64 ("test-normal-rw-int64",
54 &rNum),
56 GNUNET_BIO_read_spec_end (), 55 GNUNET_BIO_read_spec_end (),
57 }; 56 };
58 57
59 /* I/O on file */ 58 /* I/O on file */
60 wh = GNUNET_BIO_write_open_file (filename); 59 wh = GNUNET_BIO_write_open_file (filename);
61 GNUNET_assert (NULL != wh); 60 GNUNET_assert (NULL != wh);
62 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); 61 GNUNET_assert (GNUNET_OK ==
63 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 62 GNUNET_BIO_write_spec_commit (wh, ws));
63 GNUNET_assert (GNUNET_OK ==
64 GNUNET_BIO_write_close (wh, NULL));
64 65
65 rh = GNUNET_BIO_read_open_file (filename); 66 rh = GNUNET_BIO_read_open_file (filename);
66 GNUNET_assert (NULL != rh); 67 GNUNET_assert (NULL != rh);
67 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); 68 GNUNET_assert (GNUNET_OK ==
68 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 69 GNUNET_BIO_read_spec_commit (rh,
69 GNUNET_assert (0 == strcmp (TESTSTRING, rString)); 70 rs));
71 GNUNET_assert (GNUNET_OK ==
72 GNUNET_BIO_read_close (rh,
73 NULL));
74 GNUNET_assert (0 == strcmp (TESTSTRING,
75 rString));
70 GNUNET_assert (wNum == rNum); 76 GNUNET_assert (wNum == rNum);
71 77 GNUNET_free (rString);
72 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 78 GNUNET_assert (GNUNET_OK ==
79 GNUNET_DISK_directory_remove (filename));
73 GNUNET_free (filename); 80 GNUNET_free (filename);
74 81
75 /* I/O on buffer */ 82 /* I/O on buffer */
76 wh = GNUNET_BIO_write_open_buffer (); 83 wh = GNUNET_BIO_write_open_buffer ();
77 GNUNET_assert (NULL != wh); 84 GNUNET_assert (NULL != wh);
78 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); 85 GNUNET_assert (GNUNET_OK ==
86 GNUNET_BIO_write_spec_commit (wh,
87 ws));
79 GNUNET_assert (GNUNET_OK == 88 GNUNET_assert (GNUNET_OK ==
80 GNUNET_BIO_get_buffer_contents (wh, 89 GNUNET_BIO_get_buffer_contents (wh,
81 NULL, 90 NULL,
82 &buffer, 91 &buffer,
83 &buffer_size)); 92 &buffer_size));
84 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 93 GNUNET_assert (GNUNET_OK ==
94 GNUNET_BIO_write_close (wh,
95 NULL));
85 96
86 rh = GNUNET_BIO_read_open_buffer (buffer, buffer_size); 97 rh = GNUNET_BIO_read_open_buffer (buffer,
98 buffer_size);
87 GNUNET_assert (NULL != rh); 99 GNUNET_assert (NULL != rh);
88 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); 100 GNUNET_assert (GNUNET_OK ==
89 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 101 GNUNET_BIO_read_spec_commit (rh,
90 GNUNET_assert (0 == strcmp (TESTSTRING, rString)); 102 rs));
103 GNUNET_assert (GNUNET_OK ==
104 GNUNET_BIO_read_close (rh,
105 NULL));
106 GNUNET_assert (0 == strcmp (TESTSTRING,
107 rString));
91 GNUNET_assert (wNum == rNum); 108 GNUNET_assert (wNum == rNum);
92 109 GNUNET_free (rString);
93 GNUNET_free (buffer); 110 GNUNET_free (buffer);
94 111
95 return 0; 112 return 0;
@@ -106,21 +123,26 @@ test_nullstring_rw (void)
106 123
107 wh = GNUNET_BIO_write_open_file (filename); 124 wh = GNUNET_BIO_write_open_file (filename);
108 GNUNET_assert (NULL != wh); 125 GNUNET_assert (NULL != wh);
109 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, 126 GNUNET_assert (GNUNET_OK ==
110 "test-nullstring-rw", 127 GNUNET_BIO_write_string (wh,
111 NULL)); 128 "test-nullstring-rw",
112 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 129 NULL));
113 130 GNUNET_assert (GNUNET_OK ==
131 GNUNET_BIO_write_close (wh,
132 NULL));
114 rh = GNUNET_BIO_read_open_file (filename); 133 rh = GNUNET_BIO_read_open_file (filename);
115 GNUNET_assert (NULL != rh); 134 GNUNET_assert (NULL != rh);
116 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, 135 GNUNET_assert (GNUNET_OK ==
117 "test-nullstring-rw", 136 GNUNET_BIO_read_string (rh,
118 &rString, 200)); 137 "test-nullstring-rw",
119 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 138 &rString,
120 139 200));
140 GNUNET_assert (GNUNET_OK ==
141 GNUNET_BIO_read_close (rh,
142 NULL));
121 GNUNET_assert (NULL == rString); 143 GNUNET_assert (NULL == rString);
122 144 GNUNET_assert (GNUNET_OK ==
123 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 145 GNUNET_DISK_directory_remove (filename));
124 GNUNET_free (filename); 146 GNUNET_free (filename);
125 return 0; 147 return 0;
126} 148}
@@ -136,21 +158,26 @@ test_emptystring_rw (void)
136 158
137 wh = GNUNET_BIO_write_open_file (filename); 159 wh = GNUNET_BIO_write_open_file (filename);
138 GNUNET_assert (NULL != wh); 160 GNUNET_assert (NULL != wh);
139 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, 161 GNUNET_assert (GNUNET_OK ==
140 "test-emptystring-rw", 162 GNUNET_BIO_write_string (wh,
141 "")); 163 "test-emptystring-rw",
142 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 164 ""));
165 GNUNET_assert (GNUNET_OK ==
166 GNUNET_BIO_write_close (wh,
167 NULL));
143 168
144 rh = GNUNET_BIO_read_open_file (filename); 169 rh = GNUNET_BIO_read_open_file (filename);
145 GNUNET_assert (NULL != rh); 170 GNUNET_assert (NULL != rh);
146 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, 171 GNUNET_assert (GNUNET_OK ==
147 "test-emptystring-rw", 172 GNUNET_BIO_read_string (rh,
148 &rString, 200)); 173 "test-emptystring-rw",
149 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 174 &rString, 200));
150 175 GNUNET_assert (GNUNET_OK ==
176 GNUNET_BIO_read_close (rh,
177 NULL));
151 GNUNET_free (rString); 178 GNUNET_free (rString);
152 179 GNUNET_assert (GNUNET_OK ==
153 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 180 GNUNET_DISK_directory_remove (filename));
154 GNUNET_free (filename); 181 GNUNET_free (filename);
155 return 0; 182 return 0;
156} 183}
@@ -166,21 +193,25 @@ test_bigstring_rw (void)
166 193
167 wh = GNUNET_BIO_write_open_file (filename); 194 wh = GNUNET_BIO_write_open_file (filename);
168 GNUNET_assert (NULL != wh); 195 GNUNET_assert (NULL != wh);
169 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, 196 GNUNET_assert (GNUNET_OK ==
170 "test-bigstring-rw", 197 GNUNET_BIO_write_string (wh,
171 TESTSTRING)); 198 "test-bigstring-rw",
172 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 199 TESTSTRING));
173 200 GNUNET_assert (GNUNET_OK ==
201 GNUNET_BIO_write_close (wh,
202 NULL));
174 rh = GNUNET_BIO_read_open_file (filename); 203 rh = GNUNET_BIO_read_open_file (filename);
175 GNUNET_assert (NULL != rh); 204 GNUNET_assert (NULL != rh);
176 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (rh, 205 GNUNET_assert (GNUNET_SYSERR ==
177 "test-bigstring-rw", 206 GNUNET_BIO_read_string (rh,
178 &rString, 1)); 207 "test-bigstring-rw",
179 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); 208 &rString, 1));
180 209 GNUNET_assert (GNUNET_SYSERR ==
210 GNUNET_BIO_read_close (rh,
211 NULL));
181 GNUNET_assert (NULL == rString); 212 GNUNET_assert (NULL == rString);
182 213 GNUNET_assert (GNUNET_OK ==
183 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 214 GNUNET_DISK_directory_remove (filename));
184 GNUNET_free (filename); 215 GNUNET_free (filename);
185 return 0; 216 return 0;
186} 217}
@@ -195,11 +226,14 @@ test_directory_r (void)
195 226
196 rh = GNUNET_BIO_read_open_file ("/dev"); 227 rh = GNUNET_BIO_read_open_file ("/dev");
197 GNUNET_assert (NULL != rh); 228 GNUNET_assert (NULL != rh);
198 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (rh, 229 GNUNET_assert (GNUNET_SYSERR ==
199 "test-directory-r", 230 GNUNET_BIO_read (rh,
200 rString, 231 "test-directory-r",
201 sizeof (rString))); 232 rString,
202 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); 233 sizeof (rString)));
234 GNUNET_assert (GNUNET_SYSERR ==
235 GNUNET_BIO_read_close (rh,
236 NULL));
203#endif 237#endif
204 return 0; 238 return 0;
205} 239}
@@ -260,13 +294,17 @@ test_fullfile_rw (void)
260 294
261 wh = GNUNET_BIO_write_open_file ("/dev/full"); 295 wh = GNUNET_BIO_write_open_file ("/dev/full");
262 GNUNET_assert (NULL != wh); 296 GNUNET_assert (NULL != wh);
263 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_spec_commit (wh, ws)); 297 GNUNET_assert (GNUNET_SYSERR ==
264 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (wh, NULL)); 298 GNUNET_BIO_write_spec_commit (wh, ws));
299 GNUNET_assert (GNUNET_SYSERR ==
300 GNUNET_BIO_write_close (wh, NULL));
265 301
266 rh = GNUNET_BIO_read_open_file ("/dev/null"); 302 rh = GNUNET_BIO_read_open_file ("/dev/null");
267 GNUNET_assert (NULL != rh); 303 GNUNET_assert (NULL != rh);
268 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_spec_commit (rh, rs)); 304 GNUNET_assert (GNUNET_SYSERR ==
269 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); 305 GNUNET_BIO_read_spec_commit (rh, rs));
306 GNUNET_assert (GNUNET_SYSERR ==
307 GNUNET_BIO_read_close (rh, NULL));
270 308
271 GNUNET_assert (NULL == rString); 309 GNUNET_assert (NULL == rString);
272#endif 310#endif
@@ -284,22 +322,27 @@ test_fakestring_rw (void)
284 322
285 wh = GNUNET_BIO_write_open_file (filename); 323 wh = GNUNET_BIO_write_open_file (filename);
286 GNUNET_assert (NULL != wh); 324 GNUNET_assert (NULL != wh);
287 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, 325 GNUNET_assert (GNUNET_OK ==
288 "test-fakestring-rw-int32", 326 GNUNET_BIO_write_int32 (wh,
289 2)); 327 "test-fakestring-rw-int32",
290 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 328 2));
329 GNUNET_assert (GNUNET_OK ==
330 GNUNET_BIO_write_close (wh,
331 NULL));
291 332
292 rh = GNUNET_BIO_read_open_file (filename); 333 rh = GNUNET_BIO_read_open_file (filename);
293 GNUNET_assert (NULL != rh); 334 GNUNET_assert (NULL != rh);
294 GNUNET_assert (GNUNET_SYSERR == 335 GNUNET_assert (GNUNET_SYSERR ==
295 GNUNET_BIO_read_string (rh, 336 GNUNET_BIO_read_string (rh,
296 "test-fakestring-rw-string", 337 "test-fakestring-rw-string",
297 &rString, 200)); 338 &rString,
298 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); 339 200));
299 340 GNUNET_assert (GNUNET_SYSERR ==
341 GNUNET_BIO_read_close (rh,
342 NULL));
300 GNUNET_assert (NULL == rString); 343 GNUNET_assert (NULL == rString);
301 344 GNUNET_assert (GNUNET_OK ==
302 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 345 GNUNET_DISK_directory_remove (filename));
303 GNUNET_free (filename); 346 GNUNET_free (filename);
304 return 0; 347 return 0;
305} 348}