aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_bio_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_bio_lib.h')
-rw-r--r--src/include/gnunet_bio_lib.h106
1 files changed, 39 insertions, 67 deletions
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index 142f1b088..73550db7e 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -19,6 +19,10 @@
19 */ 19 */
20 20
21/** 21/**
22 * @addtogroup libgnunetutil
23 * Multi-function utilities library for GNUnet programs
24 * @{
25 *
22 * @author Christian Grothoff 26 * @author Christian Grothoff
23 * 27 *
24 * @file 28 * @file
@@ -29,9 +33,15 @@
29 * @{ 33 * @{
30 */ 34 */
31 35
36#include "gnunet_common.h"
37#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
38#error "Only <gnunet_util_lib.h> can be included directly."
39#endif
40
32#ifndef GNUNET_BIO_LIB_H 41#ifndef GNUNET_BIO_LIB_H
33#define GNUNET_BIO_LIB_H 42#define GNUNET_BIO_LIB_H
34 43
44
35#include "gnunet_container_lib.h" 45#include "gnunet_container_lib.h"
36 46
37#ifdef __cplusplus 47#ifdef __cplusplus
@@ -79,9 +89,18 @@ GNUNET_BIO_read_open_buffer (void *buffer, size_t size);
79 * @param emsg set to the error message 89 * @param emsg set to the error message
80 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 90 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
81 */ 91 */
82int 92enum GNUNET_GenericReturnValue
83GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); 93GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
84 94
95/**
96 * Set read error to handle
97 *
98 * @param h the handle
99 * @param emsg the message
100 */
101void
102GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char* emsg);
103
85 104
86/** 105/**
87 * Read some contents into a buffer. 106 * Read some contents into a buffer.
@@ -92,7 +111,7 @@ GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg);
92 * @param len the number of bytes to read 111 * @param len the number of bytes to read
93 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 112 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
94 */ 113 */
95int 114enum GNUNET_GenericReturnValue
96GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 115GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
97 const char *what, 116 const char *what,
98 void *result, 117 void *result,
@@ -109,26 +128,13 @@ GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
109 * @param max_length maximum allowed length for the string 128 * @param max_length maximum allowed length for the string
110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 129 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
111 */ 130 */
112int 131enum GNUNET_GenericReturnValue
113GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 132GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
114 const char *what, 133 const char *what,
115 char **result, 134 char **result,
116 size_t max_length); 135 size_t max_length);
117 136
118 137
119/**
120 * Read a metadata container.
121 *
122 * @param h handle to an open file
123 * @param what describes what is being read (for error message creation)
124 * @param result the buffer to store a pointer to the (allocated) metadata
125 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
126 */
127int
128GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
129 const char *what,
130 struct GNUNET_CONTAINER_MetaData **result);
131
132 138
133/** 139/**
134 * Read a float. 140 * Read a float.
@@ -137,7 +143,7 @@ GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
137 * @param what describes what is being read (for error message creation) 143 * @param what describes what is being read (for error message creation)
138 * @param f address of float to read 144 * @param f address of float to read
139 */ 145 */
140int 146enum GNUNET_GenericReturnValue
141GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, 147GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
142 const char *what, 148 const char *what,
143 float *f); 149 float *f);
@@ -150,7 +156,7 @@ GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h,
150 * @param what describes what is being read (for error message creation) 156 * @param what describes what is being read (for error message creation)
151 * @param f address of double to read 157 * @param f address of double to read
152 */ 158 */
153int 159enum GNUNET_GenericReturnValue
154GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, 160GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
155 const char *what, 161 const char *what,
156 double *f); 162 double *f);
@@ -164,7 +170,7 @@ GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h,
164 * @param i where to store the data 170 * @param i where to store the data
165 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 171 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
166 */ 172 */
167int 173enum GNUNET_GenericReturnValue
168GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, 174GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
169 const char *what, 175 const char *what,
170 int32_t *i); 176 int32_t *i);
@@ -178,7 +184,7 @@ GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h,
178 * @param i where to store the data 184 * @param i where to store the data
179 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 185 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
180 */ 186 */
181int 187enum GNUNET_GenericReturnValue
182GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, 188GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h,
183 const char *what, 189 const char *what,
184 int64_t *i); 190 int64_t *i);
@@ -219,7 +225,7 @@ GNUNET_BIO_write_open_buffer (void);
219 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned 225 * @return #GNUNET_OK upon success. Upon failure #GNUNET_SYSERR is returned
220 * and the file is closed 226 * and the file is closed
221 */ 227 */
222int 228enum GNUNET_GenericReturnValue
223GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); 229GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
224 230
225 231
@@ -235,7 +241,7 @@ GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h);
235 * @param size where to store the size of @e contents 241 * @param size where to store the size of @e contents
236 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 242 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
237 */ 243 */
238int 244enum GNUNET_GenericReturnValue
239GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, 245GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
240 char **emsg, 246 char **emsg,
241 void **contents, 247 void **contents,
@@ -251,7 +257,7 @@ GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h,
251 * if the handle has an error message, the return value is #GNUNET_SYSERR 257 * if the handle has an error message, the return value is #GNUNET_SYSERR
252 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 258 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
253 */ 259 */
254int 260enum GNUNET_GenericReturnValue
255GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg); 261GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
256 262
257 263
@@ -264,7 +270,7 @@ GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg);
264 * @param n number of bytes to write 270 * @param n number of bytes to write
265 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 271 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
266 */ 272 */
267int 273enum GNUNET_GenericReturnValue
268GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 274GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
269 const char *what, 275 const char *what,
270 const void *buffer, 276 const void *buffer,
@@ -279,25 +285,12 @@ GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
279 * @param s string to write (can be NULL) 285 * @param s string to write (can be NULL)
280 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 286 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
281 */ 287 */
282int 288enum GNUNET_GenericReturnValue
283GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, 289GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
284 const char *what, 290 const char *what,
285 const char *s); 291 const char *s);
286 292
287 293
288/**
289 * Write a metadata container.
290 *
291 * @param h the IO handle to write to
292 * @param what what is being written (for error message creation)
293 * @param m metadata to write
294 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
295 */
296int
297GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
298 const char *what,
299 const struct GNUNET_CONTAINER_MetaData *m);
300
301 294
302/** 295/**
303 * Write a float. 296 * Write a float.
@@ -306,7 +299,7 @@ GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
306 * @param what what is being written (for error message creation) 299 * @param what what is being written (for error message creation)
307 * @param f float to write (must be a variable) 300 * @param f float to write (must be a variable)
308 */ 301 */
309int 302enum GNUNET_GenericReturnValue
310GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, 303GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
311 const char *what, 304 const char *what,
312 float f); 305 float f);
@@ -318,7 +311,7 @@ GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h,
318 * @param what what is being written (for error message creation) 311 * @param what what is being written (for error message creation)
319 * @param f double to write (must be a variable) 312 * @param f double to write (must be a variable)
320 */ 313 */
321int 314enum GNUNET_GenericReturnValue
322GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, 315GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
323 const char *what, 316 const char *what,
324 double f); 317 double f);
@@ -332,7 +325,7 @@ GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h,
332 * @param i 32-bit integer to write 325 * @param i 32-bit integer to write
333 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 326 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
334 */ 327 */
335int 328enum GNUNET_GenericReturnValue
336GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 329GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
337 const char *what, 330 const char *what,
338 int32_t i); 331 int32_t i);
@@ -346,7 +339,7 @@ GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
346 * @param i 64-bit integer to write 339 * @param i 64-bit integer to write
347 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 340 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
348 */ 341 */
349int 342enum GNUNET_GenericReturnValue
350GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 343GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h,
351 const char *what, 344 const char *what,
352 int64_t i); 345 int64_t i);
@@ -444,17 +437,6 @@ GNUNET_BIO_read_spec_string (const char *what,
444 size_t max_length); 437 size_t max_length);
445 438
446 439
447/**
448 * Create the specification to read a metadata container.
449 *
450 * @param what describes what is being read (for error message creation)
451 * @param result the buffer to store a pointer to the (allocated) metadata
452 * @return the read spec
453 */
454struct GNUNET_BIO_ReadSpec
455GNUNET_BIO_read_spec_meta_data (const char *what,
456 struct GNUNET_CONTAINER_MetaData **result);
457
458 440
459/** 441/**
460 * Create the specification to read an (u)int32_t. 442 * Create the specification to read an (u)int32_t.
@@ -508,7 +490,7 @@ GNUNET_BIO_read_spec_double (const char *what, double *f);
508 * the last element must be #GNUNET_BIO_read_spec_end 490 * the last element must be #GNUNET_BIO_read_spec_end
509 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 491 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
510 */ 492 */
511int 493enum GNUNET_GenericReturnValue
512GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, 494GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h,
513 struct GNUNET_BIO_ReadSpec *rs); 495 struct GNUNET_BIO_ReadSpec *rs);
514 496
@@ -601,18 +583,6 @@ GNUNET_BIO_write_spec_string (const char *what,
601 583
602 584
603/** 585/**
604 * Create the specification to write a metadata container.
605 *
606 * @param what what is being written (for error message creation)
607 * @param m metadata to write
608 * @return the write spec
609 */
610struct GNUNET_BIO_WriteSpec
611GNUNET_BIO_write_spec_meta_data (const char *what,
612 const struct GNUNET_CONTAINER_MetaData *m);
613
614
615/**
616 * Create the specification to write an (u)int32_t. 586 * Create the specification to write an (u)int32_t.
617 * 587 *
618 * @param what describes what is being written (for error message creation) 588 * @param what describes what is being written (for error message creation)
@@ -666,7 +636,7 @@ GNUNET_BIO_write_spec_double (const char *what, double *f);
666 * the last element must be #GNUNET_BIO_write_spec_end 636 * the last element must be #GNUNET_BIO_write_spec_end
667 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 637 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
668 */ 638 */
669int 639enum GNUNET_GenericReturnValue
670GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, 640GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
671 struct GNUNET_BIO_WriteSpec *ws); 641 struct GNUNET_BIO_WriteSpec *ws);
672 642
@@ -683,4 +653,6 @@ GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h,
683 653
684/** @} */ /* end of group bio */ 654/** @} */ /* end of group bio */
685 655
656/** @} */ /* end of group addition */
657
686/* end of gnunet_bio_lib.h */ 658/* end of gnunet_bio_lib.h */