GNUnet  0.19.2
gnunet_bio_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009 GNUnet e.V.
4 
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
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
36 #if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
37 #error "Only <gnunet_util_lib.h> can be included directly."
38 #endif
39 
40 #ifndef GNUNET_BIO_LIB_H
41 #define GNUNET_BIO_LIB_H
42 
43 
44 #include "gnunet_container_lib.h"
45 
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #if 0 /* keep Emacsens' auto-indent happy */
50 }
51 #endif
52 #endif
53 
54 /****************************** READING API *******************************/
55 
60 
61 
68 struct GNUNET_BIO_ReadHandle *
69 GNUNET_BIO_read_open_file (const char *fn);
70 
71 
79 struct GNUNET_BIO_ReadHandle *
81 
82 
91 int
93 
100 void
102 
103 
113 int
115  const char *what,
116  void *result,
117  size_t len);
118 
119 
130 int
132  const char *what,
133  char **result,
134  size_t max_length);
135 
136 
137 
145 int
147  const char *what,
148  float *f);
149 
150 
158 int
160  const char *what,
161  double *f);
162 
163 
172 int
174  const char *what,
175  int32_t *i);
176 
177 
186 int
188  const char *what,
189  int64_t *i);
190 
191 
192 /****************************** WRITING API *******************************/
193 
198 
205 struct GNUNET_BIO_WriteHandle *
206 GNUNET_BIO_write_open_file (const char *fn);
207 
208 
214 struct GNUNET_BIO_WriteHandle *
216 
217 
227 int
229 
230 
243 int
245  char **emsg,
246  void **contents,
247  size_t *size);
248 
249 
259 int
261 
262 
272 int
274  const char *what,
275  const void *buffer,
276  size_t n);
277 
278 
287 int
289  const char *what,
290  const char *s);
291 
292 
293 
301 int
303  const char *what,
304  float f);
305 
313 int
315  const char *what,
316  double f);
317 
318 
327 int
329  const char *what,
330  int32_t i);
331 
332 
341 int
343  const char *what,
344  int64_t i);
345 
346 
347 /****************************** READ SPEC API ***************************/
348 
349 
362 typedef int
363 (*GNUNET_BIO_ReadHandler)(void *cls,
364  struct GNUNET_BIO_ReadHandle *h,
365  const char *what,
366  void *target,
367  size_t target_size);
368 
369 
374 {
379 
383  void *cls;
384 
388  const char *what;
389 
394  void *target;
395 
399  size_t size;
400 };
401 
402 
406 #define GNUNET_BIO_read_spec_end() \
407  { NULL, NULL, NULL, NULL, 0 }
408 
409 
418 struct GNUNET_BIO_ReadSpec
419 GNUNET_BIO_read_spec_object (const char *what,
420  void *result,
421  size_t size);
422 
423 
433 struct GNUNET_BIO_ReadSpec
434 GNUNET_BIO_read_spec_string (const char *what,
435  char **result,
436  size_t max_length);
437 
438 
439 
447 struct GNUNET_BIO_ReadSpec
448 GNUNET_BIO_read_spec_int32 (const char *what,
449  int32_t *i);
450 
451 
459 struct GNUNET_BIO_ReadSpec
460 GNUNET_BIO_read_spec_int64 (const char *what,
461  int64_t *i);
462 
463 
470 struct GNUNET_BIO_ReadSpec
471 GNUNET_BIO_read_spec_float (const char *what, float *f);
472 
473 
480 struct GNUNET_BIO_ReadSpec
481 GNUNET_BIO_read_spec_double (const char *what, double *f);
482 
483 
492 int
494  struct GNUNET_BIO_ReadSpec *rs);
495 
496 
497 /******************************* WRITE SPEC API *****************************/
498 
499 
510 typedef int
511 (*GNUNET_BIO_WriteHandler) (void *cls,
512  struct GNUNET_BIO_WriteHandle *h,
513  const char *what,
514  void *source,
515  size_t source_size);
516 
517 
522 {
527 
531  void *cls;
532 
536  const char *what;
537 
541  void *source;
542 
547  size_t source_size;
548 };
549 
550 
554 #define GNUNET_BIO_write_spec_end() \
555  { NULL, NULL, NULL, NULL, 0 }
556 
557 
568  void *source,
569  size_t size);
570 
571 
581  const char *s);
582 
583 
592 GNUNET_BIO_write_spec_int32 (const char *what,
593  int32_t *i);
594 
595 
604 GNUNET_BIO_write_spec_int64 (const char *what,
605  int64_t *i);
606 
607 
616 GNUNET_BIO_write_spec_float (const char *what, float *f);
617 
618 
627 GNUNET_BIO_write_spec_double (const char *what, double *f);
628 
629 
638 int
640  struct GNUNET_BIO_WriteSpec *ws);
641 
642 
643 #if 0 /* keep Emacsens' auto-indent happy */
644 {
645 #endif
646 #ifdef __cplusplus
647 }
648 #endif
649 
650 /* ifndef GNUNET_BIO_LIB_H */
651 #endif
652  /* end of group bio */
654  /* end of group addition */
656 
657 /* end of gnunet_bio_lib.h */
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static GstElement * source
Appsrc instance into which we write data for the pipeline.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static int result
Global testing status.
Container classes for GNUnet.
int GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h, const char *what, float f)
Write a float.
Definition: bio.c:812
int GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, const char *what, float *f)
Read a float.
Definition: bio.c:392
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_float(const char *what, float *f)
Create the specification to read a float.
Definition: bio.c:1066
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_string(const char *what, char **result, size_t max_length)
Create the specification to read a 0-terminated string.
Definition: bio.c:956
int GNUNET_BIO_read_string(struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
Read 0-terminated string.
Definition: bio.c:330
int GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1359
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_buffer(void)
Create a handle backed by an in-memory buffer.
Definition: bio.c:535
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:427
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:114
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:752
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:449
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_object(const char *what, void *result, size_t size)
Create the specification to read a certain amount of bytes.
Definition: bio.c:908
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:789
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:556
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:847
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string(const char *what, const char *s)
Create the specification to write a 0-terminated string.
Definition: bio.c:1201
int GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1108
void GNUNET_BIO_read_set_error(struct GNUNET_BIO_ReadHandle *h, const char *emsg)
Set read error to handle.
Definition: bio.c:187
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32(const char *what, int32_t *i)
Create the specification to read an (u)int32_t.
Definition: bio.c:1001
int GNUNET_BIO_get_buffer_contents(struct GNUNET_BIO_WriteHandle *h, char **emsg, void **contents, size_t *size)
Get the IO handle's contents.
Definition: bio.c:643
int(* GNUNET_BIO_ReadHandler)(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used to deserialize data read from h and store it into target.
int GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h, const char *what, double f)
Write a double.
Definition: bio.c:829
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_buffer(void *buffer, size_t size)
Create a handle from an existing allocated buffer.
Definition: bio.c:139
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:162
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_double(const char *what, double *f)
Create the specification to write an double.
Definition: bio.c:1336
int(* GNUNET_BIO_WriteHandler)(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used to serialize data from a buffer and write it to h.
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_float(const char *what, float *f)
Create the specification to write a float.
Definition: bio.c:1314
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:867
int GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:291
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_object(const char *what, void *source, size_t size)
Create the specification to read some bytes.
Definition: bio.c:1154
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:508
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_double(const char *what, double *f)
Create the specification to read a double.
Definition: bio.c:1086
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32(const char *what, int32_t *i)
Create the specification to write an (u)int32_t.
Definition: bio.c:1246
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64(const char *what, int64_t *i)
Create the specification to read an (u)int64_t.
Definition: bio.c:1045
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:607
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64(const char *what, int64_t *i)
Create the specification to write an (u)int64_t.
Definition: bio.c:1291
int GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, const char *what, double *f)
Read a double.
Definition: bio.c:409
static unsigned int size
Size of the "table".
Definition: peer.c:68
Handle for buffered reading.
Definition: bio.c:69
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:83
char * buffer
I/O buffer.
Definition: bio.c:88
Structure specifying a reading operation on an IO handle.
void * cls
Closure for rh.
const char * what
What is being read (for error message creation)
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
void * target
Destination buffer.
size_t size
Size of target.
Handle for buffered writing.
Definition: bio.c:466
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:480
void * buffer
I/O buffer.
Definition: bio.c:487
Structure specifying a writing operation on an IO handle.
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
void * source
Source buffer.
size_t source_size
Size of source.
void * cls
Closure for rh.
const char * what
What is being read (for error message creation)