GNUnet  0.11.x
Data Structures | Macros | Typedefs | Functions
BIO library

Buffered binary disk IO (with endianess conversion) More...

Data Structures

struct  GNUNET_BIO_ReadSpec
 Structure specifying a reading operation on an IO handle. More...
 
struct  GNUNET_BIO_WriteSpec
 Structure specifying a writing operation on an IO handle. More...
 

Macros

#define GNUNET_BIO_read_spec_end()   { NULL, NULL, NULL, NULL, 0 }
 End of specifications marker. More...
 
#define GNUNET_BIO_write_spec_end()   { NULL, NULL, NULL, NULL, 0 }
 End of specifications marker. More...
 

Typedefs

typedef 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. More...
 
typedef 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. More...
 

Functions

struct GNUNET_BIO_ReadHandleGNUNET_BIO_read_open_file (const char *fn)
 Open a file for reading. More...
 
struct GNUNET_BIO_ReadHandleGNUNET_BIO_read_open_buffer (void *buffer, size_t size)
 Create a handle from an existing allocated buffer. More...
 
int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
 Close an open handle. More...
 
int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
 Read some contents into a buffer. More...
 
int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
 Read 0-terminated string. More...
 
int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, struct GNUNET_CONTAINER_MetaData **result)
 Read a metadata container. More...
 
int GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, const char *what, float *f)
 Read a float. More...
 
int GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, const char *what, double *f)
 Read a double. More...
 
int GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
 Read an (u)int32_t. More...
 
int GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
 Read an (u)int64_t. More...
 
struct GNUNET_BIO_WriteHandleGNUNET_BIO_write_open_file (const char *fn)
 Open a file for writing. More...
 
struct GNUNET_BIO_WriteHandleGNUNET_BIO_write_open_buffer (void)
 Create a handle backed by an in-memory buffer. More...
 
int GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
 Force a file-based buffered writer to flush its buffer. More...
 
int GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, char **emsg, void **contents, size_t *size)
 Get the IO handle's contents. More...
 
int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
 Close an IO handle. More...
 
int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
 Write a buffer to a handle. More...
 
int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
 Write a 0-terminated string. More...
 
int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, const char *what, const struct GNUNET_CONTAINER_MetaData *m)
 Write a metadata container. More...
 
int GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, const char *what, float f)
 Write a float. More...
 
int GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, const char *what, double f)
 Write a double. More...
 
int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
 Write an (u)int32_t. More...
 
int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
 Write an (u)int64_t. More...
 
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. More...
 
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. More...
 
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. More...
 
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32 (const char *what, int32_t *i)
 Create the specification to read an (u)int32_t. More...
 
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64 (const char *what, int64_t *i)
 Create the specification to read an (u)int64_t. More...
 
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_float (const char *what, float *f)
 Create the specification to read a float. More...
 
struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_double (const char *what, double *f)
 Create the specification to read a double. More...
 
int GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs)
 Execute the read specifications in order. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_object (const char *what, void *source, size_t size)
 Create the specification to read some bytes. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string (const char *what, const char *s)
 Create the specification to write a 0-terminated string. More...
 
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. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32 (const char *what, int32_t *i)
 Create the specification to write an (u)int32_t. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64 (const char *what, int64_t *i)
 Create the specification to write an (u)int64_t. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_float (const char *what, float *f)
 Create the specification to write a float. More...
 
struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_double (const char *what, double *f)
 Create the specification to write an double. More...
 
int GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws)
 Execute the write specifications in order. More...
 

Detailed Description

Buffered binary disk IO (with endianess conversion)

Macro Definition Documentation

◆ GNUNET_BIO_read_spec_end

#define GNUNET_BIO_read_spec_end ( )    { NULL, NULL, NULL, NULL, 0 }

◆ GNUNET_BIO_write_spec_end

#define GNUNET_BIO_write_spec_end ( )    { NULL, NULL, NULL, NULL, 0 }

Typedef Documentation

◆ GNUNET_BIO_ReadHandler

typedef 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.

Parameters
clsclosure (can be NULL)
hthe IO handle to read from
whatwhat is being read (for error message creation)
targetwhere to store the data
target_sizehow many bytes can be written in target can be 0 if the size is unknown or is not fixed
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 374 of file gnunet_bio_lib.h.

◆ GNUNET_BIO_WriteHandler

typedef 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.

Parameters
clsclosure (can be NULL)
hthe IO handle to write to
whatwhat is being written (for error message creation)
sourcethe data to write
source_sizehow many bytes should be written
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 533 of file gnunet_bio_lib.h.

Function Documentation

◆ GNUNET_BIO_read_open_file()

struct GNUNET_BIO_ReadHandle* GNUNET_BIO_read_open_file ( const char *  fn)

Open a file for reading.

Parameters
fnfile name to be opened
Returns
IO handle on success, NULL on error

Definition at line 119 of file bio.c.

References BIO_BUFFER_SIZE, GNUNET_BIO_ReadHandle::buffer, GNUNET_BIO_ReadHandle::fd, GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_malloc, h, IO_FILE, GNUNET_BIO_ReadHandle::size, and GNUNET_BIO_ReadHandle::type.

Referenced by deserialize_download_file(), deserialize_publish_file(), deserialize_search_file(), deserialize_search_result(), deserialize_subdownload(), deserialize_unindex_file(), get_read_handle(), load(), load_hostlist_file(), load_state(), read_index_list(), and read_update_information_graph().

120 {
121  struct GNUNET_DISK_FileHandle *fd;
122  struct GNUNET_BIO_ReadHandle *h;
123 
125  if (NULL == fd)
126  return NULL;
127  h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
128  h->type = IO_FILE;
129  h->buffer = (char *) &h[1];
130  h->size = BIO_BUFFER_SIZE;
131  h->fd = fd;
132  return h;
133 }
Open the file for reading.
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:83
Nobody is allowed to do anything to the file.
#define BIO_BUFFER_SIZE
Size for I/O buffers.
Definition: bio.c:41
size_t size
Total size of buffer.
Definition: bio.c:103
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static char * fn
Filename of the unique file.
The handle uses a file to read/write data.
Definition: bio.c:61
char * buffer
I/O buffer.
Definition: bio.c:93
enum IOType type
The "backend" type.
Definition: bio.c:78
int fd
File handle on Unix-like systems.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1203
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for buffered reading.
Definition: bio.c:73
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_open_buffer()

struct GNUNET_BIO_ReadHandle* GNUNET_BIO_read_open_buffer ( void *  buffer,
size_t  size 
)

Create a handle from an existing allocated buffer.

Parameters
bufferthe buffer to use as source
sizethe total size in bytes of the buffer
Returns
IO handle on sucess, NULL on error

Definition at line 144 of file bio.c.

References GNUNET_BIO_ReadHandle::buffer, GNUNET_new, h, IO_BUFFER, GNUNET_BIO_ReadHandle::size, and GNUNET_BIO_ReadHandle::type.

145 {
146  struct GNUNET_BIO_ReadHandle *h;
147 
148  h = GNUNET_new (struct GNUNET_BIO_ReadHandle);
149  h->type = IO_BUFFER;
150  h->buffer = buffer;
151  h->size = size;
152  return h;
153 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
size_t size
Total size of buffer.
Definition: bio.c:103
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
char * buffer
I/O buffer.
Definition: bio.c:93
static unsigned int size
Size of the "table".
Definition: peer.c:67
enum IOType type
The "backend" type.
Definition: bio.c:78
The data is stored entirely in memory.
Definition: bio.c:66
Handle for buffered reading.
Definition: bio.c:73

◆ GNUNET_BIO_read_close()

int GNUNET_BIO_read_close ( struct GNUNET_BIO_ReadHandle h,
char **  emsg 
)

Close an open handle.

Reports if any errors reading from the file were encountered.

Parameters
hfile handle
emsgset to the error message
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Reports if any errors reading from the file were encountered.

Parameters
hfile handle
emsgset to the (allocated) error message if the handle has an error message, the return value is GNUNET_SYSERR
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 166 of file bio.c.

References GNUNET_BIO_ReadHandle::emsg, GNUNET_BIO_ReadHandle::fd, GNUNET_DISK_file_close(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, IO_BUFFER, IO_FILE, and GNUNET_BIO_ReadHandle::type.

Referenced by deserialize_download_file(), deserialize_file_information(), deserialize_publish_file(), deserialize_search_file(), deserialize_search_result(), deserialize_subdownload(), deserialize_unindex_file(), load(), load_hostlist_file(), load_state(), read_index_list(), and read_update_information_graph().

167 {
168  int err;
169 
170  err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
171  if (NULL != emsg)
172  *emsg = h->emsg;
173  else
174  GNUNET_free (h->emsg);
175  switch (h->type)
176  {
177  case IO_FILE:
179  break;
180  case IO_BUFFER:
181  break;
182  default:
183  break;
184  }
185  GNUNET_free (h);
186  return err;
187 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1280
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:83
The handle uses a file to read/write data.
Definition: bio.c:61
enum IOType type
The "backend" type.
Definition: bio.c:78
The data is stored entirely in memory.
Definition: bio.c:66
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read()

int GNUNET_BIO_read ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
void *  result,
size_t  len 
)

Read some contents into a buffer.

Parameters
hthe IO handle to read from
whatdescribes what is being read (for error message creation)
resultthe buffer to write the result to
lenthe number of bytes to read
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 287 of file bio.c.

References _, GNUNET_BIO_ReadHandle::emsg, GNUNET_asprintf(), GNUNET_OK, GNUNET_SYSERR, IO_BUFFER, IO_FILE, read_from_buffer(), read_from_file(), result, and GNUNET_BIO_ReadHandle::type.

Referenced by deserialize_fi_node(), deserialize_publish_file(), deserialize_search(), deserialize_search_result(), deserialize_unindex_file(), GNUNET_BIO_read_int32(), GNUNET_BIO_read_int64(), GNUNET_BIO_read_meta_data(), GNUNET_BIO_read_string(), load(), read_download_request(), read_index_list(), and read_spec_handler_object().

291 {
292  char *dst = result;
293 
294  if (NULL != h->emsg)
295  return GNUNET_SYSERR;
296 
297  if (0 == len)
298  return GNUNET_OK;
299 
300  switch (h->type)
301  {
302  case IO_FILE:
303  return read_from_file (h, what, dst, len);
304  case IO_BUFFER:
305  return read_from_buffer (h, what, dst, len);
306  default:
307  GNUNET_asprintf (&h->emsg,
308  _ ("Invalid handle type while reading `%s'"),
309  what);
310  return GNUNET_SYSERR;
311  }
312 }
static int read_from_file(struct GNUNET_BIO_ReadHandle *h, const char *what, char *result, size_t len)
Function used internally to read the contents of a file into a buffer.
Definition: bio.c:200
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static int read_from_buffer(struct GNUNET_BIO_ReadHandle *h, const char *what, char *result, size_t len)
Function used internally to read the content of a buffer into a buffer.
Definition: bio.c:258
The handle uses a file to read/write data.
Definition: bio.c:61
static int result
Global testing status.
enum IOType type
The "backend" type.
Definition: bio.c:78
The data is stored entirely in memory.
Definition: bio.c:66
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_string()

int GNUNET_BIO_read_string ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
char **  result,
size_t  max_length 
)

Read 0-terminated string.

Parameters
hthe IO handle to read from
whatdescribes what is being read (for error message creation)
resultwhere to store the pointer to the (allocated) string (note that *result could be set to NULL as well)
max_lengthmaximum allowed length for the string
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 326 of file bio.c.

References _, buf, GNUNET_BIO_ReadHandle::emsg, GNUNET_asprintf(), GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_free, GNUNET_malloc, GNUNET_OK, and GNUNET_SYSERR.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_search(), deserialize_search_result(), deserialize_unindex_file(), load_hostlist_file(), read_index_list(), and read_spec_handler_string().

330 {
331  char *buf;
332  uint32_t big;
333 
335  _ ("string length"),
336  (int32_t *) &big))
337  {
338  char *tmp = h->emsg;
339  if (NULL != tmp)
340  GNUNET_asprintf (&h->emsg,
341  _ ("%s (while reading `%s')"),
342  tmp,
343  what);
344  else
345  GNUNET_asprintf (&h->emsg,
346  _ ("Error reading length of string `%s'"),
347  what);
348  GNUNET_free (tmp);
349  return GNUNET_SYSERR;
350  }
351  if (0 == big)
352  {
353  *result = NULL;
354  return GNUNET_OK;
355  }
356  if (big > max_length)
357  {
358  GNUNET_asprintf (&h->emsg,
359  _ ("String `%s' longer than allowed (%u > %u)"),
360  what,
361  big,
362  max_length);
363  return GNUNET_SYSERR;
364  }
365  buf = GNUNET_malloc (big);
366  *result = buf;
367  buf[--big] = '\0';
368  if (0 == big)
369  return GNUNET_OK;
370  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
371  {
372  GNUNET_free (buf);
373  *result = NULL;
374  return GNUNET_SYSERR;
375  }
376  return GNUNET_OK;
377 }
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:477
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
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
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char buf[2048]
static int result
Global testing status.
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_meta_data()

int GNUNET_BIO_read_meta_data ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
struct GNUNET_CONTAINER_MetaData **  result 
)

Read a metadata container.

Parameters
hhandle to an open file
whatdescribes what is being read (for error message creation)
resultthe buffer to store a pointer to the (allocated) metadata
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 389 of file bio.c.

References _, buf, GNUNET_BIO_ReadHandle::emsg, GNUNET_asprintf(), GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_CONTAINER_meta_data_deserialize(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, MAX_META_DATA, meta, and GNUNET_BIO_ReadHandle::size.

Referenced by deserialize_fi_node(), deserialize_search_result(), and read_spec_handler_meta_data().

392 {
393  uint32_t size;
394  char *buf;
396 
398  _ ("metadata length"),
399  (int32_t *) &size))
400  return GNUNET_SYSERR;
401  if (0 == size)
402  {
403  *result = NULL;
404  return GNUNET_OK;
405  }
406  if (MAX_META_DATA < size)
407  {
409  &h->emsg,
410  _ ("Serialized metadata `%s' larger than allowed (%u > %u)"),
411  what,
412  size,
413  MAX_META_DATA);
414  return GNUNET_SYSERR;
415  }
416  buf = GNUNET_malloc (size);
417  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
418  {
419  GNUNET_free (buf);
420  return GNUNET_SYSERR;
421  }
422  meta = GNUNET_CONTAINER_meta_data_deserialize (buf, size);
423  if (NULL == meta)
424  {
425  GNUNET_free (buf);
426  GNUNET_asprintf (&h->emsg, _ ("Failed to deserialize metadata `%s'"), what);
427  return GNUNET_SYSERR;
428  }
429  GNUNET_free (buf);
430  *result = meta;
431  return GNUNET_OK;
432 }
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:477
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_deserialize(const char *input, size_t size)
Deserialize meta-data.
#define MAX_META_DATA
Maximum size allowed for meta data written/read from disk.
Definition: bio.c:47
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
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
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
Meta data to associate with a file, directory or namespace.
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
static struct GNUNET_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:88
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_float()

int GNUNET_BIO_read_float ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
float *  f 
)

Read a float.

Parameters
hthe IO handle to read from
whatdescribes what is being read (for error message creation)
faddress of float to read

Definition at line 442 of file bio.c.

References GNUNET_BIO_read_int32().

445 {
446  int32_t *i = (int32_t *) f;
447  return GNUNET_BIO_read_int32 (h, what, i);
448 }
int GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:477
Here is the call graph for this function:

◆ GNUNET_BIO_read_double()

int GNUNET_BIO_read_double ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
double *  f 
)

Read a double.

Parameters
hthe IO handle to read from
whatdescribes what is being read (for error message creation)
faddress of double to read

Definition at line 459 of file bio.c.

References GNUNET_BIO_read_int64().

462 {
463  int64_t *i = (int64_t *) f;
464  return GNUNET_BIO_read_int64 (h, what, i);
465 }
int GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:499
Here is the call graph for this function:

◆ GNUNET_BIO_read_int32()

int GNUNET_BIO_read_int32 ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
int32_t *  i 
)

Read an (u)int32_t.

Parameters
hthe IO handle to read from
whatdescribes what is being read (for error message creation)
iwhere to store the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 477 of file bio.c.

References GNUNET_BIO_read(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by deserialize_download(), deserialize_fi_node(), deserialize_search(), deserialize_search_result(), deserialize_unindex_file(), GNUNET_BIO_read_float(), GNUNET_BIO_read_meta_data(), GNUNET_BIO_read_string(), load_state(), read_download_request(), read_spec_handler_int32(), and read_update_information_graph().

480 {
481  int32_t big;
482 
483  if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int32_t)))
484  return GNUNET_SYSERR;
485  *i = ntohl (big);
486  return GNUNET_OK;
487 }
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_int64()

int GNUNET_BIO_read_int64 ( struct GNUNET_BIO_ReadHandle h,
const char *  what,
int64_t *  i 
)

Read an (u)int64_t.

Parameters
hthe IO handle to read from
whatdescribes what is being read (for error message creation)
iwhere to store the data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 499 of file bio.c.

References GNUNET_BIO_read(), GNUNET_ntohll(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by deserialize_fi_node(), deserialize_unindex_file(), GNUNET_BIO_read_double(), read_spec_handler_int64(), and read_start_time().

502 {
503  int64_t big;
504 
505  if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int64_t)))
506  return GNUNET_SYSERR;
507  *i = GNUNET_ntohll (big);
508  return GNUNET_OK;
509 }
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
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_open_file()

struct GNUNET_BIO_WriteHandle* GNUNET_BIO_write_open_file ( const char *  fn)

Open a file for writing.

Parameters
fnname of the file to be opened
Returns
IO handle on success, NULL on error

Definition at line 558 of file bio.c.

References BIO_BUFFER_SIZE, GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_ReadHandle::fd, GNUNET_BIO_WriteHandle::fd, GNUNET_DISK_file_open(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_malloc, h, and GNUNET_BIO_WriteHandle::size.

Referenced by get_write_handle(), get_write_handle_in_dir(), GNUNET_FS_download_sync_(), GST_stats_init(), logger_run(), run(), save(), save_hostlist_file(), save_state(), write_index_list(), and write_update_information_graph().

559 {
560  struct GNUNET_DISK_FileHandle *fd;
561  struct GNUNET_BIO_WriteHandle *h;
562 
563  fd =
570  if (NULL == fd)
571  return NULL;
573  h->buffer = &h[1];
574  h->size = BIO_BUFFER_SIZE;
575  h->fd = fd;
576  return h;
577 }
Create file if it doesn&#39;t exist.
#define BIO_BUFFER_SIZE
Size for I/O buffers.
Definition: bio.c:41
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:525
void * buffer
I/O buffer.
Definition: bio.c:537
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static char * fn
Filename of the unique file.
Truncate file if it exists.
Handle for buffered writing.
Definition: bio.c:515
Open the file for writing.
size_t size
Total size of buffer.
Definition: bio.c:547
int fd
File handle on Unix-like systems.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1203
Handle used to access files (and pipes).
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_open_buffer()

struct GNUNET_BIO_WriteHandle* GNUNET_BIO_write_open_buffer ( void  )

Create a handle backed by an in-memory buffer.

Returns
IO handle on success, NULL on error

Definition at line 586 of file bio.c.

References GNUNET_BIO_WriteHandle::buffer, GNUNET_malloc, GNUNET_new, h, IO_BUFFER, and GNUNET_BIO_WriteHandle::type.

587 {
588  struct GNUNET_BIO_WriteHandle *h;
589 
590  h = GNUNET_new (struct GNUNET_BIO_WriteHandle);
591  h->type = IO_BUFFER;
592  h->buffer = (void *) GNUNET_malloc (sizeof (struct GNUNET_Buffer));
593  return h;
594 }
enum IOType type
The "backend" type.
Definition: bio.c:520
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * buffer
I/O buffer.
Definition: bio.c:537
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Handle for buffered writing.
Definition: bio.c:515
The data is stored entirely in memory.
Definition: bio.c:66
Common buffer management functions.
#define GNUNET_malloc(size)
Wrapper around malloc.

◆ GNUNET_BIO_flush()

int GNUNET_BIO_flush ( struct GNUNET_BIO_WriteHandle h)

Force a file-based buffered writer to flush its buffer.

If the handle does not use a file, this function returs GNUNET_OK without doing anything.

Parameters
hthe IO handle
Returns
GNUNET_OK upon success. Upon failure GNUNET_SYSERR is returned and the file is closed

Definition at line 654 of file bio.c.

References _, GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_WriteHandle::emsg, GNUNET_BIO_WriteHandle::fd, GNUNET_asprintf(), GNUNET_DISK_file_close(), GNUNET_DISK_file_write(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, GNUNET_BIO_WriteHandle::have, IO_FILE, ret, and GNUNET_BIO_WriteHandle::type.

Referenced by GNUNET_BIO_write_close(), GNUNET_BIO_write_spec_commit(), and write_to_file().

655 {
656  ssize_t ret;
657 
658  if (IO_FILE != h->type)
659  return GNUNET_OK;
660 
661  ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
662  if (ret != (ssize_t) h->have)
663  {
665  h->fd = NULL;
666  GNUNET_free (h->emsg);
667  GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file"));
668  return GNUNET_SYSERR;
669  }
670  h->have = 0;
671  return GNUNET_OK;
672 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1280
enum IOType type
The "backend" type.
Definition: bio.c:520
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:525
void * buffer
I/O buffer.
Definition: bio.c:537
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:820
The handle uses a file to read/write data.
Definition: bio.c:61
size_t have
Number of bytes available in buffer.
Definition: bio.c:542
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:530
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_get_buffer_contents()

int GNUNET_BIO_get_buffer_contents ( struct GNUNET_BIO_WriteHandle h,
char **  emsg,
void **  contents,
size_t *  size 
)

Get the IO handle's contents.

If the handle doesn't use an in-memory buffer, this function returns GNUNET_SYSERR.

Parameters
hthe IO handle
emsgset to the (allocated) error message if the handle has an error message the return value is GNUNET_SYSERR
contentswhere to store the pointer to the handle's contents
sizewhere to store the size of contents
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 688 of file bio.c.

References GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_WriteHandle::emsg, GNUNET_buffer_reap(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, IO_BUFFER, ret, and GNUNET_BIO_WriteHandle::type.

692 {
693  if (IO_BUFFER != h->type)
694  return GNUNET_SYSERR;
695  if (NULL == contents || NULL == size)
696  return GNUNET_SYSERR;
697  int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK;
698  if (NULL != emsg)
699  *emsg = h->emsg;
700  else
701  GNUNET_free (h->emsg);
702  *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size);
703  return ret;
704 }
enum IOType type
The "backend" type.
Definition: bio.c:520
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
void * buffer
I/O buffer.
Definition: bio.c:537
void * GNUNET_buffer_reap(struct GNUNET_Buffer *buf, size_t *size)
Clear the buffer and return its contents.
Definition: buffer.c:148
static unsigned int size
Size of the "table".
Definition: peer.c:67
The data is stored entirely in memory.
Definition: bio.c:66
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:530
Common buffer management functions.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_BIO_write_close()

int GNUNET_BIO_write_close ( struct GNUNET_BIO_WriteHandle h,
char **  emsg 
)

Close an IO handle.

If the handle was using a file, the file will be closed.

Parameters
hfile handle
emsgset to the (allocated) error message if the handle has an error message, the return value is GNUNET_SYSERR
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 607 of file bio.c.

References GNUNET_BIO_WriteHandle::buffer, GNUNET_BIO_WriteHandle::emsg, GNUNET_BIO_WriteHandle::fd, GNUNET_BIO_flush(), GNUNET_buffer_clear(), GNUNET_DISK_file_close(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, IO_BUFFER, IO_FILE, and GNUNET_BIO_WriteHandle::type.

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), GST_stats_destroy(), save(), save_hostlist_file(), save_state(), shutdown_task(), write_index_list(), and write_update_information_graph().

608 {
609  int err;
610 
611  err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
612  if (NULL != emsg)
613  *emsg = h->emsg;
614  else
615  GNUNET_free (h->emsg);
616  switch (h->type)
617  {
618  case IO_FILE:
619  if (NULL == h->fd)
620  return GNUNET_SYSERR;
621  if (GNUNET_OK != GNUNET_BIO_flush (h))
622  {
623  if (NULL != emsg)
624  *emsg = h->emsg;
625  else
626  GNUNET_free (h->emsg);
627  err = GNUNET_SYSERR;
628  }
629  else
630  {
632  }
633  break;
634  case IO_BUFFER:
635  GNUNET_buffer_clear ((struct GNUNET_Buffer *) h->buffer);
636  GNUNET_free (h->buffer);
637  break;
638  }
639  GNUNET_free (h);
640  return err;
641 }
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1280
enum IOType type
The "backend" type.
Definition: bio.c:520
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:654
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:525
void * buffer
I/O buffer.
Definition: bio.c:537
The handle uses a file to read/write data.
Definition: bio.c:61
The data is stored entirely in memory.
Definition: bio.c:66
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:530
void GNUNET_buffer_clear(struct GNUNET_Buffer *buf)
Free the backing memory of the given buffer.
Definition: buffer.c:163
Common buffer management functions.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write()

int GNUNET_BIO_write ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
const void *  buffer,
size_t  n 
)

Write a buffer to a handle.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
bufferthe data to write
nnumber of bytes to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 794 of file bio.c.

References _, GNUNET_BIO_ReadHandle::buffer, GNUNET_BIO_WriteHandle::emsg, GNUNET_asprintf(), GNUNET_OK, GNUNET_SYSERR, IO_BUFFER, IO_FILE, GNUNET_BIO_WriteHandle::type, write_to_buffer(), and write_to_file().

Referenced by copy_from_reader(), GNUNET_BIO_write_int32(), GNUNET_BIO_write_int64(), GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_string(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), handle_log_msg(), sample_load_task(), save(), write_download_request(), write_index_list(), and write_spec_handler_object().

798 {
799  const char *src = buffer;
800 
801  if (NULL != h->emsg)
802  return GNUNET_SYSERR;
803 
804  if (0 == n)
805  return GNUNET_OK;
806 
807  switch (h->type)
808  {
809  case IO_FILE:
810  return write_to_file (h, what, src, n);
811  case IO_BUFFER:
812  return write_to_buffer (h, what, src, n);
813  default:
814  GNUNET_asprintf (&h->emsg,
815  _ ("Invalid handle type while writing `%s'"),
816  what);
817  return GNUNET_SYSERR;
818  }
819 }
enum IOType type
The "backend" type.
Definition: bio.c:520
static int write_to_file(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *source, size_t len)
Function used internally to write the contents of a buffer into a file.
Definition: bio.c:717
static int write_to_buffer(struct GNUNET_BIO_WriteHandle *h, const char *what, const char *source, size_t len)
Function used internally to write the contents of a buffer to another buffer.
Definition: bio.c:773
void * buffer
I/O buffer.
Definition: bio.c:537
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
The handle uses a file to read/write data.
Definition: bio.c:61
The data is stored entirely in memory.
Definition: bio.c:66
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:530
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_string()

int GNUNET_BIO_write_string ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
const char *  s 
)

Write a 0-terminated string.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
sstring to write (can be NULL)
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 831 of file bio.c.

References _, GNUNET_BIO_write(), GNUNET_BIO_write_int32(), GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_FS_file_information_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), write_index_list(), and write_spec_handler_string().

834 {
835  uint32_t slen;
836 
837  slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
838  if (GNUNET_OK != GNUNET_BIO_write_int32 (h, _ ("string length"), slen))
839  return GNUNET_SYSERR;
840  if (0 != slen)
841  return GNUNET_BIO_write (h, what, s, slen - 1);
842  return GNUNET_OK;
843 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:935
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:794
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_meta_data()

int GNUNET_BIO_write_meta_data ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
const struct GNUNET_CONTAINER_MetaData m 
)

Write a metadata container.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
mmetadata to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 855 of file bio.c.

References _, buf, GNUNET_BIO_WriteHandle::emsg, GNUNET_asprintf(), GNUNET_BIO_write(), GNUNET_BIO_write_int32(), GNUNET_CONTAINER_meta_data_serialize(), GNUNET_CONTAINER_META_DATA_SERIALIZE_PART, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, MAX_META_DATA, and GNUNET_BIO_ReadHandle::size.

Referenced by write_spec_handler_meta_data().

858 {
859  ssize_t size;
860  char *buf;
861 
862  if (m == NULL)
863  return GNUNET_BIO_write_int32 (h, _ ("metadata length"), 0);
864  buf = NULL;
866  m,
867  &buf,
870  if (-1 == size)
871  {
872  GNUNET_free (buf);
873  GNUNET_free (h->emsg);
874  GNUNET_asprintf (&h->emsg,
875  _ ("Failed to serialize metadata `%s'"),
876  what);
877  return GNUNET_SYSERR;
878  }
880  _ ("metadata length"),
881  (uint32_t) size))
882  || (GNUNET_OK != GNUNET_BIO_write (h, what, buf, size)))
883  {
884  GNUNET_free (buf);
885  return GNUNET_SYSERR;
886  }
887  GNUNET_free (buf);
888  return GNUNET_OK;
889 }
ssize_t GNUNET_CONTAINER_meta_data_serialize(const struct GNUNET_CONTAINER_MetaData *md, char **target, size_t max, enum GNUNET_CONTAINER_MetaDataSerializationOptions opt)
Serialize meta-data to target.
If not enough space is available, it is acceptable to only serialize some of the metadata.
#define MAX_META_DATA
Maximum size allowed for meta data written/read from disk.
Definition: bio.c:47
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:935
char * emsg
Error message, NULL if there were no errors.
Definition: bio.c:530
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:794
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_float()

int GNUNET_BIO_write_float ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
float  f 
)

Write a float.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
ffloat to write (must be a variable)
hthe IO handle to write to
whatwhat is being written (for error message creation)
ffloat to write

Definition at line 900 of file bio.c.

References removetrailingwhitespace::f, and GNUNET_BIO_write_int32().

903 {
904  int32_t i = f;
905  return GNUNET_BIO_write_int32 (h, what, i);
906 }
int GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:935
Here is the call graph for this function:

◆ GNUNET_BIO_write_double()

int GNUNET_BIO_write_double ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
double  f 
)

Write a double.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
fdouble to write (must be a variable)
hthe IO handle to write to
whatwhat is being written (for error message creation)
fdouble to write

Definition at line 917 of file bio.c.

References removetrailingwhitespace::f, and GNUNET_BIO_write_int64().

920 {
921  int64_t i = f;
922  return GNUNET_BIO_write_int64 (h, what, i);
923 }
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:955
Here is the call graph for this function:

◆ GNUNET_BIO_write_int32()

int GNUNET_BIO_write_int32 ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
int32_t  i 
)

Write an (u)int32_t.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
i32-bit integer to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 935 of file bio.c.

References GNUNET_BIO_write().

Referenced by GNUNET_BIO_write_float(), GNUNET_BIO_write_meta_data(), GNUNET_BIO_write_string(), GNUNET_FS_search_sync_(), save_state(), write_spec_handler_int32(), and write_update_information_graph().

938 {
939  int32_t big;
940 
941  big = htonl (i);
942  return GNUNET_BIO_write (h, what, &big, sizeof(int32_t));
943 }
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:794
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_int64()

int GNUNET_BIO_write_int64 ( struct GNUNET_BIO_WriteHandle h,
const char *  what,
int64_t  i 
)

Write an (u)int64_t.

Parameters
hthe IO handle to write to
whatwhat is being written (for error message creation)
i64-bit integer to write
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 955 of file bio.c.

References GNUNET_BIO_write(), and GNUNET_htonll().

Referenced by GNUNET_BIO_write_double(), GNUNET_FS_file_information_sync_(), handle_p2p_estimate(), write_spec_handler_int64(), and write_start_time().

958 {
959  int64_t big;
960 
961  big = GNUNET_htonll (i);
962  return GNUNET_BIO_write (h, what, &big, sizeof(int64_t));
963 }
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36
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:794
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_spec_object()

struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_object ( const char *  what,
void *  result,
size_t  len 
)

Create the specification to read a certain amount of bytes.

Parameters
whatdescribes what is being read (for error message creation)
resultthe buffer to write the result to
lenthe number of bytes to read
Returns
the read spec

Definition at line 996 of file bio.c.

References len, read_spec_handler_object(), result, GNUNET_BIO_ReadSpec::rh, and GNUNET_BIO_ReadSpec::what.

Referenced by load_state().

999 {
1000  struct GNUNET_BIO_ReadSpec rs = {
1002  .cls = NULL,
1003  .what = what,
1004  .target = result,
1005  .size = len,
1006  };
1007 
1008  return rs;
1009 }
const char * what
What is being read (for error message creation)
static int read_spec_handler_object(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read some bytes from within a read spec.
Definition: bio.c:977
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
static int result
Global testing status.
Structure specifying a reading operation on an IO handle.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_spec_string()

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.

Parameters
whatdescribes what is being read (for error message creation)
resultwhere to store the pointer to the (allocated) string (note that *result could be set to NULL as well)
max_lengthmaximum allowed length for the string
Returns
the read spec

Definition at line 1044 of file bio.c.

References read_spec_handler_string(), result, and GNUNET_BIO_ReadSpec::rh.

Referenced by deserialize_download(), deserialize_publish_file(), load_state(), and read_update_information_graph().

1047 {
1048  struct GNUNET_BIO_ReadSpec rs = {
1050  .cls = NULL,
1051  .target = result,
1052  .size = max_length,
1053  };
1054 
1055  return rs;
1056 }
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
static int read_spec_handler_string(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used interally to read a string from within a read spec.
Definition: bio.c:1023
static int result
Global testing status.
Structure specifying a reading operation on an IO handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_spec_meta_data()

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.

Parameters
whatdescribes what is being read (for error message creation)
resultthe buffer to store a pointer to the (allocated) metadata
Returns
the read spec

Definition at line 1090 of file bio.c.

References read_spec_handler_meta_data(), result, and GNUNET_BIO_ReadSpec::rh.

Referenced by deserialize_download(), and read_update_information_graph().

1092 {
1093  struct GNUNET_BIO_ReadSpec rs = {
1095  .cls = NULL,
1096  .target = result,
1097  .size = 0,
1098  };
1099 
1100  return rs;
1101 }
static int read_spec_handler_meta_data(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read a metadata container from within a read spec.
Definition: bio.c:1071
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
static int result
Global testing status.
Structure specifying a reading operation on an IO handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_spec_int32()

struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int32 ( const char *  what,
int32_t *  i 
)

Create the specification to read an (u)int32_t.

Parameters
whatdescribes what is being read (for error message creation)
iwhere to store the data
Returns
the read spec

Definition at line 1134 of file bio.c.

References read_spec_handler_int32(), and GNUNET_BIO_ReadSpec::rh.

Referenced by deserialize_publish_file(), load_hostlist_file(), and read_download_request().

1136 {
1137  struct GNUNET_BIO_ReadSpec rs = {
1139  .cls = NULL,
1140  .target = i,
1141  .size = 0,
1142  };
1143 
1144  return rs;
1145 }
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
Structure specifying a reading operation on an IO handle.
static int read_spec_handler_int32(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read an (u)int32_t from within a read spec.
Definition: bio.c:1115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_spec_int64()

struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_int64 ( const char *  what,
int64_t *  i 
)

Create the specification to read an (u)int64_t.

Parameters
whatdescribes what is being read (for error message creation)
iwhere to store the data
Returns
the read spec

Definition at line 1178 of file bio.c.

References read_spec_handler_int64(), and GNUNET_BIO_ReadSpec::rh.

Referenced by deserialize_download(), load_hostlist_file(), and read_download_request().

1180 {
1181  struct GNUNET_BIO_ReadSpec rs = {
1183  .cls = NULL,
1184  .target = i,
1185  .size = 0,
1186  };
1187 
1188  return rs;
1189 }
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
static int read_spec_handler_int64(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read an (u)int64_t from within a read spec.
Definition: bio.c:1159
Structure specifying a reading operation on an IO handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_spec_float()

struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_float ( const char *  what,
float *  f 
)

Create the specification to read a float.

Parameters
whatdescribes what is being read (for error message creation)
faddress of float to read

Definition at line 1199 of file bio.c.

References removetrailingwhitespace::f, read_spec_handler_int32(), GNUNET_BIO_ReadSpec::rh, and GNUNET_BIO_ReadHandle::size.

1200 {
1201  struct GNUNET_BIO_ReadSpec rs = {
1203  .cls = NULL,
1204  .target = (int32_t *) f,
1205  .size = 0,
1206  };
1207 
1208  return rs;
1209 }
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
Structure specifying a reading operation on an IO handle.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static int read_spec_handler_int32(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read an (u)int32_t from within a read spec.
Definition: bio.c:1115
Here is the call graph for this function:

◆ GNUNET_BIO_read_spec_double()

struct GNUNET_BIO_ReadSpec GNUNET_BIO_read_spec_double ( const char *  what,
double *  f 
)

Create the specification to read a double.

Parameters
whatdescribes what is being read (for error message creation)
faddress of double to read

Definition at line 1219 of file bio.c.

References removetrailingwhitespace::f, read_spec_handler_int64(), GNUNET_BIO_ReadSpec::rh, and GNUNET_BIO_ReadHandle::size.

1220 {
1221  struct GNUNET_BIO_ReadSpec rs = {
1223  .cls = NULL,
1224  .target = (int64_t *) f,
1225  .size = 0,
1226  };
1227 
1228  return rs;
1229 }
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.
static int read_spec_handler_int64(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read an (u)int64_t from within a read spec.
Definition: bio.c:1159
Structure specifying a reading operation on an IO handle.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Here is the call graph for this function:

◆ GNUNET_BIO_read_spec_commit()

int GNUNET_BIO_read_spec_commit ( struct GNUNET_BIO_ReadHandle h,
struct GNUNET_BIO_ReadSpec rs 
)

Execute the read specifications in order.

Parameters
hthe IO handle to read from
rsarray of read specs the last element must be GNUNET_BIO_read_spec_end
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1241 of file bio.c.

References GNUNET_BIO_ReadSpec::cls, GNUNET_OK, ret, GNUNET_BIO_ReadSpec::rh, GNUNET_BIO_ReadHandle::size, and GNUNET_BIO_ReadSpec::target.

Referenced by deserialize_download(), deserialize_publish_file(), load_hostlist_file(), load_state(), read_download_request(), and read_update_information_graph().

1243 {
1244  int ret = GNUNET_OK;
1245 
1246  for (size_t i=0; NULL!=rs[i].rh; ++i)
1247  {
1248  ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size);
1249  if (GNUNET_OK != ret)
1250  return ret;
1251  }
1252 
1253  return ret;
1254 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Here is the caller graph for this function:

◆ GNUNET_BIO_write_spec_object()

struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_object ( const char *  what,
void *  source,
size_t  size 
)

Create the specification to read some bytes.

Parameters
whatdescribes what is being written (for error message creation)
sourcethe data to write
sizehow many bytes should be written
Returns
the write spec

Definition at line 1287 of file bio.c.

References GNUNET_BIO_ReadHandle::size, source, GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_object().

Referenced by GNUNET_FS_file_information_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_unindex_sync_(), and write_item().

1290 {
1291  struct GNUNET_BIO_WriteSpec ws = {
1293  .cls = NULL,
1294  .what = what,
1295  .source = source,
1296  .source_size = size,
1297  };
1298 
1299  return ws;
1300 }
Structure specifying a writing operation on an IO handle.
static GstElement * source
Appsrc instance into which we write data for the pipeline.
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
static int write_spec_handler_object(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write some bytes from within a write spec.
Definition: bio.c:1268
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_spec_string()

struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_string ( const char *  what,
const char *  s 
)

Create the specification to write a 0-terminated string.

Parameters
whatdescribes what is being read (for error message creation)
sstring to write (can be NULL)
Returns
the read spec

Definition at line 1334 of file bio.c.

References GNUNET_BIO_WriteSpec::source_size, GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_string().

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_unindex_sync_(), save_hostlist_file(), write_item(), and write_update_information_graph().

1336 {
1337  struct GNUNET_BIO_WriteSpec ws = {
1339  .cls = NULL,
1340  .what = what,
1341  .source = (void *) s,
1342  .source_size = 0,
1343  };
1344 
1345  return ws;
1346 }
Structure specifying a writing operation on an IO handle.
size_t source_size
Size of source.
static int write_spec_handler_string(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write a 0-terminated string from within a write spec. ...
Definition: bio.c:1315
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_spec_meta_data()

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.

Parameters
whatwhat is being written (for error message creation)
mmetadata to write
Returns
the write spec

Definition at line 1380 of file bio.c.

References m, GNUNET_BIO_WriteSpec::source_size, GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_meta_data().

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_search_result_sync_(), and write_update_information_graph().

1382 {
1383  struct GNUNET_BIO_WriteSpec ws = {
1385  .cls = NULL,
1386  .what = what,
1387  .source = (void *) m,
1388  .source_size = 0,
1389  };
1390 
1391  return ws;
1392 }
Structure specifying a writing operation on an IO handle.
size_t source_size
Size of source.
static int write_spec_handler_meta_data(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write a metadata container from within a write spec.
Definition: bio.c:1361
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_spec_int32()

struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int32 ( const char *  what,
int32_t *  i 
)

Create the specification to write an (u)int32_t.

Parameters
whatdescribes what is being written (for error message creation)
ipointer to a 32-bit integer
Returns
the write spec

Definition at line 1425 of file bio.c.

References GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_int32().

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_unindex_sync_(), save_hostlist_file(), and write_download_request().

1427 {
1428  struct GNUNET_BIO_WriteSpec ws = {
1430  .cls = NULL,
1431  .what = what,
1432  .source = i,
1433  .source_size = 0,
1434  };
1435 
1436  return ws;
1437 }
Structure specifying a writing operation on an IO handle.
static int write_spec_handler_int32(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write an (u)int32_t from within a write spec.
Definition: bio.c:1406
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_spec_int64()

struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_int64 ( const char *  what,
int64_t *  i 
)

Create the specification to write an (u)int64_t.

Parameters
whatdescribes what is being written (for error message creation)
ipointer to a 64-bit integer
Returns
the write spec

Definition at line 1470 of file bio.c.

References GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_int64().

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_unindex_sync_(), save_hostlist_file(), and write_download_request().

1472 {
1473  struct GNUNET_BIO_WriteSpec ws = {
1475  .cls = NULL,
1476  .what = what,
1477  .source = i,
1478  .source_size = 0,
1479  };
1480 
1481  return ws;
1482 }
Structure specifying a writing operation on an IO handle.
static int write_spec_handler_int64(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write an (u)int64_t from within a write spec.
Definition: bio.c:1451
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_spec_float()

struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_float ( const char *  what,
float *  f 
)

Create the specification to write a float.

Parameters
whatdescribes what is being written (for error message creation)
fpointer to a float
Returns
the write spec

Definition at line 1493 of file bio.c.

References removetrailingwhitespace::f, GNUNET_BIO_WriteSpec::source_size, GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_int32().

1494 {
1495  struct GNUNET_BIO_WriteSpec ws = {
1497  .cls = NULL,
1498  .what = what,
1499  .source = (int32_t *) f,
1500  .source_size = 0,
1501  };
1502 
1503  return ws;
1504 }
Structure specifying a writing operation on an IO handle.
size_t source_size
Size of source.
static int write_spec_handler_int32(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write an (u)int32_t from within a write spec.
Definition: bio.c:1406
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:

◆ GNUNET_BIO_write_spec_double()

struct GNUNET_BIO_WriteSpec GNUNET_BIO_write_spec_double ( const char *  what,
double *  f 
)

Create the specification to write an double.

Parameters
whatdescribes what is being written (for error message creation)
fpointer to a double
Returns
the write spec

Definition at line 1515 of file bio.c.

References removetrailingwhitespace::f, GNUNET_BIO_WriteSpec::source_size, GNUNET_BIO_WriteSpec::wh, GNUNET_BIO_WriteSpec::what, and write_spec_handler_int64().

1516 {
1517  struct GNUNET_BIO_WriteSpec ws = {
1519  .cls = NULL,
1520  .what = what,
1521  .source = (int64_t *) f,
1522  .source_size = 0,
1523  };
1524 
1525  return ws;
1526 }
Structure specifying a writing operation on an IO handle.
size_t source_size
Size of source.
static int write_spec_handler_int64(void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size)
Function used internally to write an (u)int64_t from within a write spec.
Definition: bio.c:1451
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:

◆ GNUNET_BIO_write_spec_commit()

int GNUNET_BIO_write_spec_commit ( struct GNUNET_BIO_WriteHandle h,
struct GNUNET_BIO_WriteSpec ws 
)

Execute the write specifications in order.

Parameters
hthe IO handle to write to
wsarray of write specs the last element must be GNUNET_BIO_write_spec_end
Returns
GNUNET_OK on success, GNUNET_SYSERR otherwise

Definition at line 1538 of file bio.c.

References GNUNET_BIO_WriteSpec::cls, GNUNET_BIO_flush(), GNUNET_OK, IO_FILE, ret, source, GNUNET_BIO_WriteSpec::source_size, GNUNET_BIO_WriteHandle::type, and GNUNET_BIO_WriteSpec::wh.

Referenced by GNUNET_FS_download_sync_(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_unindex_sync_(), save_hostlist_file(), write_download_request(), write_item(), and write_update_information_graph().

1540 {
1541  int ret = GNUNET_OK;
1542 
1543  for (size_t i=0; NULL!=ws[i].wh; ++i)
1544  {
1545  ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size);
1546  if (GNUNET_OK != ret)
1547  return ret;
1548  }
1549 
1550  /* If it's a file-based handle, the flush makes sure that the data in the
1551  buffer is actualy written to the disk. */
1552  if (IO_FILE == h->type)
1553  ret = GNUNET_BIO_flush (h);
1554 
1555  return ret;
1556 }
void * cls
Closure for rh.
enum IOType type
The "backend" type.
Definition: bio.c:520
size_t source_size
Size of source.
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:654
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
The handle uses a file to read/write data.
Definition: bio.c:61
static GstElement * source
Appsrc instance into which we write data for the pipeline.
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)
Here is the call graph for this function:
Here is the caller graph for this function: