diff options
Diffstat (limited to 'src/include/gnunet_bio_lib.h')
-rw-r--r-- | src/include/gnunet_bio_lib.h | 106 |
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 | */ |
82 | int | 92 | enum GNUNET_GenericReturnValue |
83 | GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); | 93 | GNUNET_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 | */ | ||
101 | void | ||
102 | GNUNET_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 | */ |
95 | int | 114 | enum GNUNET_GenericReturnValue |
96 | GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, | 115 | GNUNET_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 | */ |
112 | int | 131 | enum GNUNET_GenericReturnValue |
113 | GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, | 132 | GNUNET_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 | */ | ||
127 | int | ||
128 | GNUNET_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 | */ |
140 | int | 146 | enum GNUNET_GenericReturnValue |
141 | GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, | 147 | GNUNET_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 | */ |
153 | int | 159 | enum GNUNET_GenericReturnValue |
154 | GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, | 160 | GNUNET_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 | */ |
167 | int | 173 | enum GNUNET_GenericReturnValue |
168 | GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, | 174 | GNUNET_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 | */ |
181 | int | 187 | enum GNUNET_GenericReturnValue |
182 | GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, | 188 | GNUNET_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 | */ |
222 | int | 228 | enum GNUNET_GenericReturnValue |
223 | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h); | 229 | GNUNET_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 | */ |
238 | int | 244 | enum GNUNET_GenericReturnValue |
239 | GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, | 245 | GNUNET_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 | */ |
254 | int | 260 | enum GNUNET_GenericReturnValue |
255 | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg); | 261 | GNUNET_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 | */ |
267 | int | 273 | enum GNUNET_GenericReturnValue |
268 | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, | 274 | GNUNET_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 | */ |
282 | int | 288 | enum GNUNET_GenericReturnValue |
283 | GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, | 289 | GNUNET_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 | */ | ||
296 | int | ||
297 | GNUNET_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 | */ |
309 | int | 302 | enum GNUNET_GenericReturnValue |
310 | GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, | 303 | GNUNET_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 | */ |
321 | int | 314 | enum GNUNET_GenericReturnValue |
322 | GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, | 315 | GNUNET_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 | */ |
335 | int | 328 | enum GNUNET_GenericReturnValue |
336 | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, | 329 | GNUNET_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 | */ |
349 | int | 342 | enum GNUNET_GenericReturnValue |
350 | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, | 343 | GNUNET_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 | */ | ||
454 | struct GNUNET_BIO_ReadSpec | ||
455 | GNUNET_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 | */ |
511 | int | 493 | enum GNUNET_GenericReturnValue |
512 | GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, | 494 | GNUNET_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 | */ | ||
610 | struct GNUNET_BIO_WriteSpec | ||
611 | GNUNET_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 | */ |
669 | int | 639 | enum GNUNET_GenericReturnValue |
670 | GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, | 640 | GNUNET_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 */ |