aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-01-18 13:53:27 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2023-01-18 13:53:27 +0900
commit426ae19f975557a3c38d0a284f8eaece826796ee (patch)
tree2bd8398efd4cf0825bab7fb3b10d1c34f961d83f
parent884eb205f14fb1c021fb80a7207ce66373f453fc (diff)
parentf9773ea41aa676f8900f7133f8bf061d202c0a5a (diff)
downloadgnunet-426ae19f975557a3c38d0a284f8eaece826796ee.tar.gz
gnunet-426ae19f975557a3c38d0a284f8eaece826796ee.zip
Merge branch 'master' of git+ssh://git.gnunet.org/gnunet
-rw-r--r--debian/changelog12
-rw-r--r--src/util/bio.c30
-rw-r--r--src/util/test_bio.c185
3 files changed, 141 insertions, 86 deletions
diff --git a/debian/changelog b/debian/changelog
index 38e91e31a..e08fd4712 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
1gnunet (0.19.2-1) unstable; urgency=low
2
3 * Importing minor post-release fixes from upstream for Debian package.
4
5 -- Christian Grothoff <grothoff@gnu.org> Tue, 17 Jan 2023 22:14:18 +0200
6
7gnunet (0.19.2) unstable; urgency=low
8
9 * New upstream release, bumping version.
10
11 -- Christian Grothoff <grothoff@gnu.org> Tue, 17 Jan 2023 21:14:18 +0200
12
1gnunet (0.18.1) unstable; urgency=low 13gnunet (0.18.1) unstable; urgency=low
2 14
3 * Packaging latest release. 15 * Packaging latest release.
diff --git a/src/util/bio.c b/src/util/bio.c
index 71d0ef7fc..7e3aa0d16 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -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);
@@ -611,14 +610,16 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
611 610
612 if (IO_FILE != h->type) 611 if (IO_FILE != h->type)
613 return GNUNET_OK; 612 return GNUNET_OK;
614 613 ret = GNUNET_DISK_file_write (h->fd,
615 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); 614 h->buffer,
615 h->have);
616 if (ret != (ssize_t) h->have) 616 if (ret != (ssize_t) h->have)
617 { 617 {
618 GNUNET_DISK_file_close (h->fd); 618 GNUNET_DISK_file_close (h->fd);
619 h->fd = NULL; 619 h->fd = NULL;
620 GNUNET_free (h->emsg); 620 GNUNET_free (h->emsg);
621 GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file")); 621 GNUNET_asprintf (&h->emsg,
622 "Unable to flush buffer to file");
622 return GNUNET_SYSERR; 623 return GNUNET_SYSERR;
623 } 624 }
624 h->have = 0; 625 h->have = 0;
@@ -638,7 +639,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
638 * @param size where to store the size of @e contents 639 * @param size where to store the size of @e contents
639 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 640 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
640 */ 641 */
641int 642enum GNUNET_GenericReturnValue
642GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, 643GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
643 char **emsg, 644 char **emsg,
644 void **contents, 645 void **contents,
@@ -648,7 +649,10 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
648 return GNUNET_SYSERR; 649 return GNUNET_SYSERR;
649 if ((NULL == contents) || (NULL == size)) 650 if ((NULL == contents) || (NULL == size))
650 return GNUNET_SYSERR; 651 return GNUNET_SYSERR;
651 int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK; 652 enum GNUNET_GenericReturnValue ret
653 = (NULL != h->emsg)
654 ? GNUNET_SYSERR
655 : GNUNET_OK;
652 if (NULL != emsg) 656 if (NULL != emsg)
653 *emsg = h->emsg; 657 *emsg = h->emsg;
654 else 658 else
@@ -667,7 +671,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
667 * @param len the number of bytes to write 671 * @param len the number of bytes to write
668 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 672 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
669 */ 673 */
670static int 674static enum GNUNET_GenericReturnValue
671write_to_file (struct GNUNET_BIO_WriteHandle *h, 675write_to_file (struct GNUNET_BIO_WriteHandle *h,
672 const char *what, 676 const char *what,
673 const char *source, 677 const char *source,
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index 950dd1142..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,14 +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#include "platform.h" 25#include "platform.h"
29#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
30#define TESTSTRING "testString" 27#define TESTSTRING "testString"
@@ -42,24 +39,29 @@ test_normal_rw (void)
42 char *rString = NULL; 39 char *rString = NULL;
43 int64_t wNum = TESTNUMBER64; 40 int64_t wNum = TESTNUMBER64;
44 int64_t rNum = 0; 41 int64_t rNum = 0;
45
46 struct GNUNET_BIO_WriteSpec ws[] = { 42 struct GNUNET_BIO_WriteSpec ws[] = {
47 GNUNET_BIO_write_spec_string ("test-normal-rw-string", TESTSTRING), 43 GNUNET_BIO_write_spec_string ("test-normal-rw-string",
48 GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64", &wNum), 44 TESTSTRING),
45 GNUNET_BIO_write_spec_int64 ("test-normal-rw-int64",
46 &wNum),
49 GNUNET_BIO_write_spec_end (), 47 GNUNET_BIO_write_spec_end (),
50 }; 48 };
51
52 struct GNUNET_BIO_ReadSpec rs[] = { 49 struct GNUNET_BIO_ReadSpec rs[] = {
53 GNUNET_BIO_read_spec_string ("test-normal-rw-string", &rString, 200), 50 GNUNET_BIO_read_spec_string ("test-normal-rw-string",
54 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),
55 GNUNET_BIO_read_spec_end (), 55 GNUNET_BIO_read_spec_end (),
56 }; 56 };
57 57
58 /* I/O on file */ 58 /* I/O on file */
59 wh = GNUNET_BIO_write_open_file (filename); 59 wh = GNUNET_BIO_write_open_file (filename);
60 GNUNET_assert (NULL != wh); 60 GNUNET_assert (NULL != wh);
61 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_spec_commit (wh, ws)); 61 GNUNET_assert (GNUNET_OK ==
62 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));
63 65
64 rh = GNUNET_BIO_read_open_file (filename); 66 rh = GNUNET_BIO_read_open_file (filename);
65 GNUNET_assert (NULL != rh); 67 GNUNET_assert (NULL != rh);
@@ -72,26 +74,37 @@ test_normal_rw (void)
72 GNUNET_assert (0 == strcmp (TESTSTRING, 74 GNUNET_assert (0 == strcmp (TESTSTRING,
73 rString)); 75 rString));
74 GNUNET_assert (wNum == rNum); 76 GNUNET_assert (wNum == rNum);
75 77 GNUNET_free (rString);
76 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 78 GNUNET_assert (GNUNET_OK ==
79 GNUNET_DISK_directory_remove (filename));
77 GNUNET_free (filename); 80 GNUNET_free (filename);
78 81
79 /* I/O on buffer */ 82 /* I/O on buffer */
80 wh = GNUNET_BIO_write_open_buffer (); 83 wh = GNUNET_BIO_write_open_buffer ();
81 GNUNET_assert (NULL != wh); 84 GNUNET_assert (NULL != wh);
82 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));
83 GNUNET_assert (GNUNET_OK == 88 GNUNET_assert (GNUNET_OK ==
84 GNUNET_BIO_get_buffer_contents (wh, 89 GNUNET_BIO_get_buffer_contents (wh,
85 NULL, 90 NULL,
86 &buffer, 91 &buffer,
87 &buffer_size)); 92 &buffer_size));
88 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 93 GNUNET_assert (GNUNET_OK ==
94 GNUNET_BIO_write_close (wh,
95 NULL));
89 96
90 rh = GNUNET_BIO_read_open_buffer (buffer, buffer_size); 97 rh = GNUNET_BIO_read_open_buffer (buffer,
98 buffer_size);
91 GNUNET_assert (NULL != rh); 99 GNUNET_assert (NULL != rh);
92 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_spec_commit (rh, rs)); 100 GNUNET_assert (GNUNET_OK ==
93 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 101 GNUNET_BIO_read_spec_commit (rh,
94 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));
95 GNUNET_assert (wNum == rNum); 108 GNUNET_assert (wNum == rNum);
96 GNUNET_free (rString); 109 GNUNET_free (rString);
97 GNUNET_free (buffer); 110 GNUNET_free (buffer);
@@ -110,21 +123,26 @@ test_nullstring_rw (void)
110 123
111 wh = GNUNET_BIO_write_open_file (filename); 124 wh = GNUNET_BIO_write_open_file (filename);
112 GNUNET_assert (NULL != wh); 125 GNUNET_assert (NULL != wh);
113 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, 126 GNUNET_assert (GNUNET_OK ==
114 "test-nullstring-rw", 127 GNUNET_BIO_write_string (wh,
115 NULL)); 128 "test-nullstring-rw",
116 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 129 NULL));
117 130 GNUNET_assert (GNUNET_OK ==
131 GNUNET_BIO_write_close (wh,
132 NULL));
118 rh = GNUNET_BIO_read_open_file (filename); 133 rh = GNUNET_BIO_read_open_file (filename);
119 GNUNET_assert (NULL != rh); 134 GNUNET_assert (NULL != rh);
120 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, 135 GNUNET_assert (GNUNET_OK ==
121 "test-nullstring-rw", 136 GNUNET_BIO_read_string (rh,
122 &rString, 200)); 137 "test-nullstring-rw",
123 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 138 &rString,
124 139 200));
140 GNUNET_assert (GNUNET_OK ==
141 GNUNET_BIO_read_close (rh,
142 NULL));
125 GNUNET_assert (NULL == rString); 143 GNUNET_assert (NULL == rString);
126 144 GNUNET_assert (GNUNET_OK ==
127 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 145 GNUNET_DISK_directory_remove (filename));
128 GNUNET_free (filename); 146 GNUNET_free (filename);
129 return 0; 147 return 0;
130} 148}
@@ -140,21 +158,26 @@ test_emptystring_rw (void)
140 158
141 wh = GNUNET_BIO_write_open_file (filename); 159 wh = GNUNET_BIO_write_open_file (filename);
142 GNUNET_assert (NULL != wh); 160 GNUNET_assert (NULL != wh);
143 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, 161 GNUNET_assert (GNUNET_OK ==
144 "test-emptystring-rw", 162 GNUNET_BIO_write_string (wh,
145 "")); 163 "test-emptystring-rw",
146 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 164 ""));
165 GNUNET_assert (GNUNET_OK ==
166 GNUNET_BIO_write_close (wh,
167 NULL));
147 168
148 rh = GNUNET_BIO_read_open_file (filename); 169 rh = GNUNET_BIO_read_open_file (filename);
149 GNUNET_assert (NULL != rh); 170 GNUNET_assert (NULL != rh);
150 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string (rh, 171 GNUNET_assert (GNUNET_OK ==
151 "test-emptystring-rw", 172 GNUNET_BIO_read_string (rh,
152 &rString, 200)); 173 "test-emptystring-rw",
153 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_close (rh, NULL)); 174 &rString, 200));
154 175 GNUNET_assert (GNUNET_OK ==
176 GNUNET_BIO_read_close (rh,
177 NULL));
155 GNUNET_free (rString); 178 GNUNET_free (rString);
156 179 GNUNET_assert (GNUNET_OK ==
157 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 180 GNUNET_DISK_directory_remove (filename));
158 GNUNET_free (filename); 181 GNUNET_free (filename);
159 return 0; 182 return 0;
160} 183}
@@ -170,21 +193,25 @@ test_bigstring_rw (void)
170 193
171 wh = GNUNET_BIO_write_open_file (filename); 194 wh = GNUNET_BIO_write_open_file (filename);
172 GNUNET_assert (NULL != wh); 195 GNUNET_assert (NULL != wh);
173 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (wh, 196 GNUNET_assert (GNUNET_OK ==
174 "test-bigstring-rw", 197 GNUNET_BIO_write_string (wh,
175 TESTSTRING)); 198 "test-bigstring-rw",
176 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (wh, NULL)); 199 TESTSTRING));
177 200 GNUNET_assert (GNUNET_OK ==
201 GNUNET_BIO_write_close (wh,
202 NULL));
178 rh = GNUNET_BIO_read_open_file (filename); 203 rh = GNUNET_BIO_read_open_file (filename);
179 GNUNET_assert (NULL != rh); 204 GNUNET_assert (NULL != rh);
180 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_string (rh, 205 GNUNET_assert (GNUNET_SYSERR ==
181 "test-bigstring-rw", 206 GNUNET_BIO_read_string (rh,
182 &rString, 1)); 207 "test-bigstring-rw",
183 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); 208 &rString, 1));
184 209 GNUNET_assert (GNUNET_SYSERR ==
210 GNUNET_BIO_read_close (rh,
211 NULL));
185 GNUNET_assert (NULL == rString); 212 GNUNET_assert (NULL == rString);
186 213 GNUNET_assert (GNUNET_OK ==
187 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 214 GNUNET_DISK_directory_remove (filename));
188 GNUNET_free (filename); 215 GNUNET_free (filename);
189 return 0; 216 return 0;
190} 217}
@@ -199,11 +226,14 @@ test_directory_r (void)
199 226
200 rh = GNUNET_BIO_read_open_file ("/dev"); 227 rh = GNUNET_BIO_read_open_file ("/dev");
201 GNUNET_assert (NULL != rh); 228 GNUNET_assert (NULL != rh);
202 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read (rh, 229 GNUNET_assert (GNUNET_SYSERR ==
203 "test-directory-r", 230 GNUNET_BIO_read (rh,
204 rString, 231 "test-directory-r",
205 sizeof (rString))); 232 rString,
206 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));
207#endif 237#endif
208 return 0; 238 return 0;
209} 239}
@@ -264,13 +294,17 @@ test_fullfile_rw (void)
264 294
265 wh = GNUNET_BIO_write_open_file ("/dev/full"); 295 wh = GNUNET_BIO_write_open_file ("/dev/full");
266 GNUNET_assert (NULL != wh); 296 GNUNET_assert (NULL != wh);
267 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_spec_commit (wh, ws)); 297 GNUNET_assert (GNUNET_SYSERR ==
268 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));
269 301
270 rh = GNUNET_BIO_read_open_file ("/dev/null"); 302 rh = GNUNET_BIO_read_open_file ("/dev/null");
271 GNUNET_assert (NULL != rh); 303 GNUNET_assert (NULL != rh);
272 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_spec_commit (rh, rs)); 304 GNUNET_assert (GNUNET_SYSERR ==
273 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));
274 308
275 GNUNET_assert (NULL == rString); 309 GNUNET_assert (NULL == rString);
276#endif 310#endif
@@ -288,22 +322,27 @@ test_fakestring_rw (void)
288 322
289 wh = GNUNET_BIO_write_open_file (filename); 323 wh = GNUNET_BIO_write_open_file (filename);
290 GNUNET_assert (NULL != wh); 324 GNUNET_assert (NULL != wh);
291 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32 (wh, 325 GNUNET_assert (GNUNET_OK ==
292 "test-fakestring-rw-int32", 326 GNUNET_BIO_write_int32 (wh,
293 2)); 327 "test-fakestring-rw-int32",
294 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));
295 332
296 rh = GNUNET_BIO_read_open_file (filename); 333 rh = GNUNET_BIO_read_open_file (filename);
297 GNUNET_assert (NULL != rh); 334 GNUNET_assert (NULL != rh);
298 GNUNET_assert (GNUNET_SYSERR == 335 GNUNET_assert (GNUNET_SYSERR ==
299 GNUNET_BIO_read_string (rh, 336 GNUNET_BIO_read_string (rh,
300 "test-fakestring-rw-string", 337 "test-fakestring-rw-string",
301 &rString, 200)); 338 &rString,
302 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_close (rh, NULL)); 339 200));
303 340 GNUNET_assert (GNUNET_SYSERR ==
341 GNUNET_BIO_read_close (rh,
342 NULL));
304 GNUNET_assert (NULL == rString); 343 GNUNET_assert (NULL == rString);
305 344 GNUNET_assert (GNUNET_OK ==
306 GNUNET_assert (GNUNET_OK == GNUNET_DISK_directory_remove (filename)); 345 GNUNET_DISK_directory_remove (filename));
307 GNUNET_free (filename); 346 GNUNET_free (filename);
308 return 0; 347 return 0;
309} 348}