GNUnet  0.17.5
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 #ifndef GNUNET_BIO_LIB_H
37 #define GNUNET_BIO_LIB_H
38 
39 #include "gnunet_container_lib.h"
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #if 0 /* keep Emacsens' auto-indent happy */
45 }
46 #endif
47 #endif
48 
49 /****************************** READING API *******************************/
50 
55 
56 
63 struct GNUNET_BIO_ReadHandle *
64 GNUNET_BIO_read_open_file (const char *fn);
65 
66 
74 struct GNUNET_BIO_ReadHandle *
76 
77 
86 int
88 
89 
99 int
101  const char *what,
102  void *result,
103  size_t len);
104 
105 
116 int
118  const char *what,
119  char **result,
120  size_t max_length);
121 
122 
131 int
133  const char *what,
135 
136 
144 int
146  const char *what,
147  float *f);
148 
149 
157 int
159  const char *what,
160  double *f);
161 
162 
171 int
173  const char *what,
174  int32_t *i);
175 
176 
185 int
187  const char *what,
188  int64_t *i);
189 
190 
191 /****************************** WRITING API *******************************/
192 
197 
204 struct GNUNET_BIO_WriteHandle *
205 GNUNET_BIO_write_open_file (const char *fn);
206 
207 
213 struct GNUNET_BIO_WriteHandle *
215 
216 
226 int
228 
229 
242 int
244  char **emsg,
245  void **contents,
246  size_t *size);
247 
248 
258 int
260 
261 
271 int
273  const char *what,
274  const void *buffer,
275  size_t n);
276 
277 
286 int
288  const char *what,
289  const char *s);
290 
291 
300 int
302  const char *what,
303  const struct GNUNET_CONTAINER_MetaData *m);
304 
305 
313 int
315  const char *what,
316  float f);
317 
325 int
327  const char *what,
328  double f);
329 
330 
339 int
341  const char *what,
342  int32_t i);
343 
344 
353 int
355  const char *what,
356  int64_t i);
357 
358 
359 /****************************** READ SPEC API ***************************/
360 
361 
374 typedef int
375 (*GNUNET_BIO_ReadHandler)(void *cls,
376  struct GNUNET_BIO_ReadHandle *h,
377  const char *what,
378  void *target,
379  size_t target_size);
380 
381 
386 {
391 
395  void *cls;
396 
400  const char *what;
401 
406  void *target;
407 
411  size_t size;
412 };
413 
414 
418 #define GNUNET_BIO_read_spec_end() \
419  { NULL, NULL, NULL, NULL, 0 }
420 
421 
430 struct GNUNET_BIO_ReadSpec
431 GNUNET_BIO_read_spec_object (const char *what,
432  void *result,
433  size_t size);
434 
435 
445 struct GNUNET_BIO_ReadSpec
446 GNUNET_BIO_read_spec_string (const char *what,
447  char **result,
448  size_t max_length);
449 
450 
458 struct GNUNET_BIO_ReadSpec
461 
462 
470 struct GNUNET_BIO_ReadSpec
471 GNUNET_BIO_read_spec_int32 (const char *what,
472  int32_t *i);
473 
474 
482 struct GNUNET_BIO_ReadSpec
483 GNUNET_BIO_read_spec_int64 (const char *what,
484  int64_t *i);
485 
486 
493 struct GNUNET_BIO_ReadSpec
494 GNUNET_BIO_read_spec_float (const char *what, float *f);
495 
496 
503 struct GNUNET_BIO_ReadSpec
504 GNUNET_BIO_read_spec_double (const char *what, double *f);
505 
506 
515 int
517  struct GNUNET_BIO_ReadSpec *rs);
518 
519 
520 /******************************* WRITE SPEC API *****************************/
521 
522 
533 typedef int
534 (*GNUNET_BIO_WriteHandler) (void *cls,
535  struct GNUNET_BIO_WriteHandle *h,
536  const char *what,
537  void *source,
538  size_t source_size);
539 
540 
545 {
550 
554  void *cls;
555 
559  const char *what;
560 
564  void *source;
565 
570  size_t source_size;
571 };
572 
573 
577 #define GNUNET_BIO_write_spec_end() \
578  { NULL, NULL, NULL, NULL, 0 }
579 
580 
591  void *source,
592  size_t size);
593 
594 
604  const char *s);
605 
606 
616  const struct GNUNET_CONTAINER_MetaData *m);
617 
618 
627 GNUNET_BIO_write_spec_int32 (const char *what,
628  int32_t *i);
629 
630 
639 GNUNET_BIO_write_spec_int64 (const char *what,
640  int64_t *i);
641 
642 
651 GNUNET_BIO_write_spec_float (const char *what, float *f);
652 
653 
662 GNUNET_BIO_write_spec_double (const char *what, double *f);
663 
664 
673 int
675  struct GNUNET_BIO_WriteSpec *ws);
676 
677 
678 #if 0 /* keep Emacsens' auto-indent happy */
679 {
680 #endif
681 #ifdef __cplusplus
682 }
683 #endif
684 
685 /* ifndef GNUNET_BIO_LIB_H */
686 #endif
687  /* end of group bio */
689  /* end of group addition */
691 
692 /* end of gnunet_bio_lib.h */
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
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:902
int GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, const char *what, float *f)
Read a float.
Definition: bio.c:444
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_float(const char *what, float *f)
Create the specification to read a float.
Definition: bio.c:1201
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:1046
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:327
int GNUNET_BIO_read_meta_data(struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_CONTAINER_MetaData **result)
Read a metadata container.
Definition: bio.c:390
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:1540
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_buffer(void)
Create a handle backed by an in-memory buffer.
Definition: bio.c:588
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:479
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:119
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:796
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:501
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:998
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:833
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:609
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:937
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:1336
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:1243
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:1136
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:690
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:919
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:144
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:167
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_double(const char *what, double *f)
Create the specification to write an double.
Definition: bio.c:1517
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:1495
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:957
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:288
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:1289
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:560
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_double(const char *what, double *f)
Create the specification to read a double.
Definition: bio.c:1221
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_meta_data(const char *what, const struct GNUNET_CONTAINER_MetaData *m)
Create the specification to write a metadata container.
Definition: bio.c:1382
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_meta_data(const char *what, struct GNUNET_CONTAINER_MetaData **result)
Create the specification to read a metadata container.
Definition: bio.c:1092
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:1427
int GNUNET_BIO_write_meta_data(struct GNUNET_BIO_WriteHandle *h, const char *what, const struct GNUNET_CONTAINER_MetaData *m)
Write a metadata container.
Definition: bio.c:857
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:1180
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:656
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:1472
int GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, const char *what, double *f)
Read a double.
Definition: bio.c:461
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle for buffered reading.
Definition: bio.c:74
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
char * buffer
I/O buffer.
Definition: bio.c:93
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:518
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:532
void * buffer
I/O buffer.
Definition: bio.c:539
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)
Meta data to associate with a file, directory or namespace.