GNUnet 0.22.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#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
41#ifndef GNUNET_BIO_LIB_H
42#define GNUNET_BIO_LIB_H
43
44
46
47#ifdef __cplusplus
48extern "C"
49{
50#if 0 /* keep Emacsens' auto-indent happy */
51}
52#endif
53#endif
54
55/****************************** READING API *******************************/
56
61
62
70GNUNET_BIO_read_open_file (const char *fn);
71
72
82
83
94
101void
103
104
116 const char *what,
117 void *result,
118 size_t len);
119
120
133 const char *what,
134 char **result,
135 size_t max_length);
136
137
138
148 const char *what,
149 float *f);
150
151
161 const char *what,
162 double *f);
163
164
175 const char *what,
176 int32_t *i);
177
178
189 const char *what,
190 int64_t *i);
191
192
193/****************************** WRITING API *******************************/
194
199
207GNUNET_BIO_write_open_file (const char *fn);
208
209
217
218
230
231
246 char **emsg,
247 void **contents,
248 size_t *size);
249
250
262
263
275 const char *what,
276 const void *buffer,
277 size_t n);
278
279
290 const char *what,
291 const char *s);
292
293
294
304 const char *what,
305 float f);
306
316 const char *what,
317 double f);
318
319
330 const char *what,
331 int32_t i);
332
333
344 const char *what,
345 int64_t i);
346
347
348/****************************** READ SPEC API ***************************/
349
350
363typedef int
364(*GNUNET_BIO_ReadHandler)(void *cls,
365 struct GNUNET_BIO_ReadHandle *h,
366 const char *what,
367 void *target,
368 size_t target_size);
369
370
375{
380
384 void *cls;
385
389 const char *what;
390
395 void *target;
396
400 size_t size;
401};
402
403
407#define GNUNET_BIO_read_spec_end() \
408 { NULL, NULL, NULL, NULL, 0 }
409
410
421 void *result,
422 size_t size);
423
424
436 char **result,
437 size_t max_length);
438
439
440
450 int32_t *i);
451
452
462 int64_t *i);
463
464
472GNUNET_BIO_read_spec_float (const char *what, float *f);
473
474
482GNUNET_BIO_read_spec_double (const char *what, double *f);
483
484
495 struct GNUNET_BIO_ReadSpec *rs);
496
497
498/******************************* WRITE SPEC API *****************************/
499
500
511typedef int
514 const char *what,
515 void *source,
516 size_t source_size);
517
518
523{
528
532 void *cls;
533
537 const char *what;
538
542 void *source;
543
549};
550
551
555#define GNUNET_BIO_write_spec_end() \
556 { NULL, NULL, NULL, NULL, 0 }
557
558
569 void *source,
570 size_t size);
571
572
582 const char *s);
583
584
594 int32_t *i);
595
596
606 int64_t *i);
607
608
617GNUNET_BIO_write_spec_float (const char *what, float *f);
618
619
628GNUNET_BIO_write_spec_double (const char *what, double *f);
629
630
641 struct GNUNET_BIO_WriteSpec *ws);
642
643
644#if 0 /* keep Emacsens' auto-indent happy */
645{
646#endif
647#ifdef __cplusplus
648}
649#endif
650
651/* ifndef GNUNET_BIO_LIB_H */
652#endif
653 /* end of group bio */
655 /* end of group addition */
657
658/* end of gnunet_bio_lib.h */
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static GstElement * source
Appsrc instance into which we write data for the pipeline.
static int result
Global testing status.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
Container classes for GNUnet.
enum GNUNET_GenericReturnValue 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
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h, char **emsg)
Close an IO handle.
Definition: bio.c:556
enum GNUNET_GenericReturnValue GNUNET_BIO_write_double(struct GNUNET_BIO_WriteHandle *h, const char *what, double f)
Write a double.
Definition: bio.c:827
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_float(const char *what, float *f)
Create the specification to read a float.
Definition: bio.c:1064
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:954
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_file(const char *fn)
Open a file for writing.
Definition: bio.c:508
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:845
enum GNUNET_GenericReturnValue GNUNET_BIO_read_spec_commit(struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
Execute the read specifications in order.
Definition: bio.c:1106
enum GNUNET_GenericReturnValue 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_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:906
enum GNUNET_GenericReturnValue 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:750
enum GNUNET_GenericReturnValue 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
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:1199
enum GNUNET_GenericReturnValue 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
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open_buffer(void)
Create a handle backed by an in-memory buffer.
Definition: bio.c:535
void GNUNET_BIO_read_set_error(struct GNUNET_BIO_ReadHandle *h, const char *emsg)
Set read error to handle.
Definition: bio.c:187
enum GNUNET_GenericReturnValue GNUNET_BIO_write_string(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
Write a 0-terminated string.
Definition: bio.c:787
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:999
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.
enum GNUNET_GenericReturnValue GNUNET_BIO_read_float(struct GNUNET_BIO_ReadHandle *h, const char *what, float *f)
Read a float.
Definition: bio.c:392
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_double(const char *what, double *f)
Create the specification to write an double.
Definition: bio.c:1334
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:1312
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:1152
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_double(const char *what, double *f)
Create the specification to read a double.
Definition: bio.c:1084
enum GNUNET_GenericReturnValue GNUNET_BIO_write_spec_commit(struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
Execute the write specifications in order.
Definition: bio.c:1357
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close(struct GNUNET_BIO_ReadHandle *h, char **emsg)
Close an open handle.
Definition: bio.c:162
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:449
enum GNUNET_GenericReturnValue GNUNET_BIO_write_float(struct GNUNET_BIO_WriteHandle *h, const char *what, float f)
Write a float.
Definition: bio.c:810
enum GNUNET_GenericReturnValue 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_WriteSpec GNUNET_BIO_write_spec_int32(const char *what, int32_t *i)
Create the specification to write an (u)int32_t.
Definition: bio.c:1244
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:1043
enum GNUNET_GenericReturnValue GNUNET_BIO_read_double(struct GNUNET_BIO_ReadHandle *h, const char *what, double *f)
Read a double.
Definition: bio.c:409
struct GNUNET_BIO_ReadHandle * GNUNET_BIO_read_open_file(const char *fn)
Open a file for reading.
Definition: bio.c:114
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:865
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
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:1289
GNUNET_GenericReturnValue
Named constants for return values.
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)