GNUnet  0.11.x
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 
32 #ifndef GNUNET_BIO_LIB_H
33 #define GNUNET_BIO_LIB_H
34 
35 #include "gnunet_container_lib.h"
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0 /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44 
45 /****************************** READING API *******************************/
46 
51 
52 
59 struct GNUNET_BIO_ReadHandle *
60 GNUNET_BIO_read_open_file (const char *fn);
61 
62 
70 struct GNUNET_BIO_ReadHandle *
72 
73 
82 int
84 
85 
95 int
97  const char *what,
98  void *result,
99  size_t len);
100 
101 
112 int
114  const char *what,
115  char **result,
116  size_t max_length);
117 
118 
127 int
129  const char *what,
131 
132 
140 int
142  const char *what,
143  float *f);
144 
145 
153 int
155  const char *what,
156  double *f);
157 
158 
167 int
169  const char *what,
170  int32_t *i);
171 
172 
181 int
183  const char *what,
184  int64_t *i);
185 
186 
187 /****************************** WRITING API *******************************/
188 
193 
200 struct GNUNET_BIO_WriteHandle *
201 GNUNET_BIO_write_open_file (const char *fn);
202 
203 
209 struct GNUNET_BIO_WriteHandle *
211 
212 
222 int
224 
225 
238 int
240  char **emsg,
241  void **contents,
242  size_t *size);
243 
244 
254 int
256 
257 
267 int
269  const char *what,
270  const void *buffer,
271  size_t n);
272 
273 
282 int
284  const char *what,
285  const char *s);
286 
287 
296 int
298  const char *what,
299  const struct GNUNET_CONTAINER_MetaData *m);
300 
301 
309 int
311  const char *what,
312  float f);
313 
321 int
323  const char *what,
324  double f);
325 
326 
335 int
337  const char *what,
338  int32_t i);
339 
340 
349 int
351  const char *what,
352  int64_t i);
353 
354 
355 /****************************** READ SPEC API ***************************/
356 
357 
370 typedef int
372  struct GNUNET_BIO_ReadHandle *h,
373  const char *what,
374  void *target,
375  size_t target_size);
376 
377 
382 {
387 
391  void *cls;
392 
396  const char *what;
397 
402  void *target;
403 
407  size_t size;
408 };
409 
410 
414 #define GNUNET_BIO_read_spec_end() \
415  { NULL, NULL, NULL, NULL, 0 }
416 
417 
426 struct GNUNET_BIO_ReadSpec
427 GNUNET_BIO_read_spec_object (const char *what,
428  void *result,
429  size_t size);
430 
431 
441 struct GNUNET_BIO_ReadSpec
442 GNUNET_BIO_read_spec_string (const char *what,
443  char **result,
444  size_t max_length);
445 
446 
454 struct GNUNET_BIO_ReadSpec
457 
458 
466 struct GNUNET_BIO_ReadSpec
467 GNUNET_BIO_read_spec_int32 (const char *what,
468  int32_t *i);
469 
470 
478 struct GNUNET_BIO_ReadSpec
479 GNUNET_BIO_read_spec_int64 (const char *what,
480  int64_t *i);
481 
482 
489 struct GNUNET_BIO_ReadSpec
490 GNUNET_BIO_read_spec_float (const char *what, float *f);
491 
492 
499 struct GNUNET_BIO_ReadSpec
500 GNUNET_BIO_read_spec_double (const char *what, double *f);
501 
502 
511 int
513  struct GNUNET_BIO_ReadSpec *rs);
514 
515 
516 /******************************* WRITE SPEC API *****************************/
517 
518 
529 typedef int
531  struct GNUNET_BIO_WriteHandle *h,
532  const char *what,
533  void *source,
534  size_t source_size);
535 
536 
541 {
546 
550  void *cls;
551 
555  const char *what;
556 
560  void *source;
561 
566  size_t source_size;
567 };
568 
569 
573 #define GNUNET_BIO_write_spec_end() \
574  { NULL, NULL, NULL, NULL, 0 }
575 
576 
587  void *source,
588  size_t size);
589 
590 
600  const char *s);
601 
602 
612  const struct GNUNET_CONTAINER_MetaData *m);
613 
614 
623 GNUNET_BIO_write_spec_int32 (const char *what,
624  int32_t *i);
625 
626 
635 GNUNET_BIO_write_spec_int64 (const char *what,
636  int64_t *i);
637 
638 
647 GNUNET_BIO_write_spec_float (const char *what, float *f);
648 
649 
658 GNUNET_BIO_write_spec_double (const char *what, double *f);
659 
660 
669 int
671  struct GNUNET_BIO_WriteSpec *ws);
672 
673 
674 #if 0 /* keep Emacsens' auto-indent happy */
675 {
676 #endif
677 #ifdef __cplusplus
678 }
679 #endif
680 
681 /* ifndef GNUNET_BIO_LIB_H */
682 #endif
683  /* end of group bio */
685 
686 /* end of gnunet_bio_lib.h */
void * cls
Closure for rh.
int GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, const char *what, float *f)
Read a float.
Definition: bio.c:443
Structure specifying a writing operation on an IO handle.
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_buffer(void)
Create a handle backed by an in-memory buffer.
Definition: bio.c:587
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:478
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:997
int GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h, const char *what, double f)
Write a double.
Definition: bio.c:918
size_t source_size
Size of source.
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_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:956
size_t size
Size of target.
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:655
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.
void * cls
Closure for rh.
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:1242
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
const char * what
What is being read (for error message creation)
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:1179
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:1288
void * buffer
I/O buffer.
Definition: bio.c:538
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
int GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:166
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
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:287
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:1335
void * target
Destination buffer.
Meta data to associate with a file, directory or namespace.
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:1091
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.
static char * fn
Filename of the unique file.
static int result
Global testing status.
Structure specifying a reading operation on an IO handle.
int GNUNET_BIO_get_buffer_contents(struct GNUNET_BIO_WriteHandle *h, char **emsg, void **contents, size_t *size)
Get the IO handle&#39;s contents.
Definition: bio.c:689
Handle for buffered writing.
Definition: bio.c:516
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_double(const char *what, double *f)
Create the specification to write an double.
Definition: bio.c:1516
char * buffer
I/O buffer.
Definition: bio.c:93
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:326
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:1045
static GstElement * source
Appsrc instance into which we write data for the pipeline.
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:1381
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:559
static unsigned int size
Size of the "table".
Definition: peer.c:67
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:608
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_float(const char *what, float *f)
Create the specification to read a float.
Definition: bio.c:1200
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:936
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:1135
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:531
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:1539
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:1426
int GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:832
void * source
Source buffer.
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:856
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_float(const char *what, float *f)
Create the specification to write a float.
Definition: bio.c:1494
int GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, const char *what, double *f)
Read a double.
Definition: bio.c:460
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:389
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:1471
const char * what
What is being read (for error message creation)
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:795
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:500
Handle for buffered reading.
Definition: bio.c:73
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
int GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h, const char *what, float f)
Write a float.
Definition: bio.c:901
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_double(const char *what, double *f)
Create the specification to read a double.
Definition: bio.c:1220