GNUnet  0.18.1
BIO library

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

Collaboration diagram for BIO library:

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 endianness conversion)

Macro Definition Documentation

◆ GNUNET_BIO_read_spec_end

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

End of specifications marker.

Definition at line 418 of file gnunet_bio_lib.h.

◆ GNUNET_BIO_write_spec_end

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

End of specifications marker.

Definition at line 577 of file gnunet_bio_lib.h.

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.

120 {
121  struct GNUNET_DISK_FileHandle *fd;
122  struct GNUNET_BIO_ReadHandle *h;
123 
125  if (NULL == fd)
126  return NULL;
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 }
#define BIO_BUFFER_SIZE
Size for I/O buffers.
Definition: bio.c:41
@ IO_FILE
The handle uses a file to read/write data.
Definition: bio.c:61
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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:1235
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
#define GNUNET_malloc(size)
Wrapper around malloc.
Handle for buffered reading.
Definition: bio.c:74
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:83
Handle used to access files (and pipes).
int fd
File handle on Unix-like systems.

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

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().

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 success, NULL on error

Definition at line 144 of file bio.c.

145 {
146  struct GNUNET_BIO_ReadHandle *h;
147 
149  h->type = IO_BUFFER;
150  h->buffer = buffer;
151  h->size = size;
152  return h;
153 }
@ IO_BUFFER
The data is stored entirely in memory.
Definition: bio.c:66
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int size
Size of the "table".
Definition: peer.c:67
char * buffer
I/O buffer.
Definition: bio.c:93

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

◆ 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 167 of file bio.c.

168 {
169  int err;
170 
171  err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
172  if (NULL != emsg)
173  *emsg = h->emsg;
174  else
175  GNUNET_free (h->emsg);
176  switch (h->type)
177  {
178  case IO_FILE:
180  break;
181  case IO_BUFFER:
182  break;
183  default:
184  break;
185  }
186  GNUNET_free (h);
187  return err;
188 }
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#define GNUNET_free(ptr)
Wrapper around free.

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

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().

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 288 of file bio.c.

292 {
293  char *dst = result;
294 
295  if (NULL != h->emsg)
296  return GNUNET_SYSERR;
297 
298  if (0 == len)
299  return GNUNET_OK;
300 
301  switch (h->type)
302  {
303  case IO_FILE:
304  return read_from_file (h, what, dst, len);
305  case IO_BUFFER:
306  return read_from_buffer (h, what, dst, len);
307  default:
308  GNUNET_asprintf (&h->emsg,
309  _ ("Invalid handle type while reading `%s'"),
310  what);
311  return GNUNET_SYSERR;
312  }
313 }
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:259
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:201
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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

References _, GNUNET_asprintf(), GNUNET_OK, GNUNET_SYSERR, h, IO_BUFFER, IO_FILE, len, read_from_buffer(), read_from_file(), and result.

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_spec_object(), GNUNET_BIO_read_string(), load(), read_download_request(), and read_index_list().

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 327 of file bio.c.

331 {
332  char *buf;
333  uint32_t big;
334 
336  _ ("string length"),
337  (int32_t *) &big))
338  {
339  char *tmp = h->emsg;
340  if (NULL != tmp)
341  GNUNET_asprintf (&h->emsg,
342  _ ("%s (while reading `%s')"),
343  tmp,
344  what);
345  else
346  GNUNET_asprintf (&h->emsg,
347  _ ("Error reading length of string `%s'"),
348  what);
349  GNUNET_free (tmp);
350  return GNUNET_SYSERR;
351  }
352  if (0 == big)
353  {
354  *result = NULL;
355  return GNUNET_OK;
356  }
357  if (big > max_length)
358  {
359  GNUNET_asprintf (&h->emsg,
360  _ ("String `%s' longer than allowed (%u > %lu)"),
361  what,
362  big,
363  (unsigned long) max_length);
364  return GNUNET_SYSERR;
365  }
366  buf = GNUNET_malloc (big);
367  *result = buf;
368  buf[--big] = '\0';
369  if (0 == big)
370  return GNUNET_OK;
371  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
372  {
373  GNUNET_free (buf);
374  *result = NULL;
375  return GNUNET_SYSERR;
376  }
377  return GNUNET_OK;
378 }
static char buf[2048]
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
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

References _, buf, GNUNET_asprintf(), GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, h, and result.

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

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 390 of file bio.c.

393 {
394  uint32_t size;
395  char *buf;
397 
399  _ ("metadata length"),
400  (int32_t *) &size))
401  return GNUNET_SYSERR;
402  if (0 == size)
403  {
404  *result = NULL;
405  return GNUNET_OK;
406  }
407  if (MAX_META_DATA < size)
408  {
410  &h->emsg,
411  _ ("Serialized metadata `%s' larger than allowed (%u > %u)"),
412  what,
413  size,
414  MAX_META_DATA);
415  return GNUNET_SYSERR;
416  }
417  buf = GNUNET_malloc (size);
418  if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
419  {
420  GNUNET_free (buf);
421  return GNUNET_SYSERR;
422  }
424  if (NULL == meta)
425  {
426  GNUNET_free (buf);
427  GNUNET_asprintf (&h->emsg, _ ("Failed to deserialize metadata `%s'"), what);
428  return GNUNET_SYSERR;
429  }
430  GNUNET_free (buf);
431  *result = meta;
432  return GNUNET_OK;
433 }
#define MAX_META_DATA
Maximum size allowed for meta data written/read from disk.
Definition: bio.c:47
static struct GNUNET_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
struct GNUNET_CONTAINER_MetaData * GNUNET_CONTAINER_meta_data_deserialize(const char *input, size_t size)
Deserialize meta-data.
Meta data to associate with a file, directory or namespace.

References _, buf, GNUNET_asprintf(), GNUNET_BIO_read(), GNUNET_BIO_read_int32(), GNUNET_CONTAINER_meta_data_deserialize(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_SYSERR, h, MAX_META_DATA, meta, result, and size.

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

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 444 of file bio.c.

447 {
448  int32_t *i = (int32_t *) f;
449  return GNUNET_BIO_read_int32 (h, what, i);
450 }

References removetrailingwhitespace::f, GNUNET_BIO_read_int32(), and h.

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 461 of file bio.c.

464 {
465  int64_t *i = (int64_t *) f;
466  return GNUNET_BIO_read_int64 (h, what, i);
467 }
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

References removetrailingwhitespace::f, GNUNET_BIO_read_int64(), and h.

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 479 of file bio.c.

482 {
483  int32_t big;
484 
485  if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int32_t)))
486  return GNUNET_SYSERR;
487  *i = ntohl (big);
488  return GNUNET_OK;
489 }

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

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_spec_int32(), GNUNET_BIO_read_string(), load_state(), read_download_request(), and read_update_information_graph().

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 501 of file bio.c.

504 {
505  int64_t big;
506 
507  if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int64_t)))
508  return GNUNET_SYSERR;
509  *i = GNUNET_ntohll (big);
510  return GNUNET_OK;
511 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53

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

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

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 560 of file bio.c.

561 {
562  struct GNUNET_DISK_FileHandle *fd;
563  struct GNUNET_BIO_WriteHandle *h;
564 
565  fd =
572  if (NULL == fd)
573  return NULL;
575  h->buffer = &h[1];
576  h->size = BIO_BUFFER_SIZE;
577  h->fd = fd;
578  return h;
579 }
@ GNUNET_DISK_OPEN_WRITE
Open the file for writing.
@ GNUNET_DISK_OPEN_TRUNCATE
Truncate file if it exists.
@ GNUNET_DISK_OPEN_CREATE
Create file if it doesn't exist.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
Handle for buffered writing.
Definition: bio.c:518
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:527

References BIO_BUFFER_SIZE, GNUNET_DISK_FileHandle::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, and h.

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().

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 588 of file bio.c.

589 {
590  struct GNUNET_BIO_WriteHandle *h;
591 
593  h->type = IO_BUFFER;
594  h->buffer = (void *) GNUNET_malloc (sizeof (struct GNUNET_Buffer));
595  return h;
596 }
Dynamically growing buffer.

References GNUNET_malloc, GNUNET_new, h, and IO_BUFFER.

◆ 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 returns 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 656 of file bio.c.

657 {
658  ssize_t ret;
659 
660  if (IO_FILE != h->type)
661  return GNUNET_OK;
662 
663  ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
664  if (ret != (ssize_t) h->have)
665  {
667  h->fd = NULL;
668  GNUNET_free (h->emsg);
669  GNUNET_asprintf (&h->emsg, _ ("Unable to flush buffer to file"));
670  return GNUNET_SYSERR;
671  }
672  h->have = 0;
673  return GNUNET_OK;
674 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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:686

References _, GNUNET_asprintf(), GNUNET_DISK_file_close(), GNUNET_DISK_file_write(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, h, IO_FILE, and ret.

Referenced by GNUNET_BIO_write_close(), and write_to_file().

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 690 of file bio.c.

694 {
695  if (IO_BUFFER != h->type)
696  return GNUNET_SYSERR;
697  if ((NULL == contents) || (NULL == size))
698  return GNUNET_SYSERR;
699  int ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK;
700  if (NULL != emsg)
701  *emsg = h->emsg;
702  else
703  GNUNET_free (h->emsg);
704  *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size);
705  return ret;
706 }
void * GNUNET_buffer_reap(struct GNUNET_Buffer *buf, size_t *size)
Clear the buffer and return its contents.
Definition: buffer.c:149

References GNUNET_BIO_WriteHandle::emsg, GNUNET_buffer_reap(), GNUNET_free, GNUNET_OK, GNUNET_SYSERR, h, IO_BUFFER, ret, and size.

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 609 of file bio.c.

610 {
611  int err;
612 
613  err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
614  if (NULL != emsg)
615  *emsg = h->emsg;
616  else
617  GNUNET_free (h->emsg);
618  switch (h->type)
619  {
620  case IO_FILE:
621  if (NULL == h->fd)
622  return GNUNET_SYSERR;
623  if (GNUNET_OK != GNUNET_BIO_flush (h))
624  {
625  if (NULL != emsg)
626  *emsg = h->emsg;
627  else
628  GNUNET_free (h->emsg);
629  err = GNUNET_SYSERR;
630  }
631  else
632  {
634  }
635  break;
636  case IO_BUFFER:
637  GNUNET_buffer_clear ((struct GNUNET_Buffer *) h->buffer);
638  GNUNET_free (h->buffer);
639  break;
640  }
641  GNUNET_free (h);
642  return err;
643 }
int GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:656
void GNUNET_buffer_clear(struct GNUNET_Buffer *buf)
Free the backing memory of the given buffer.
Definition: buffer.c:164

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

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().

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 796 of file bio.c.

800 {
801  const char *src = buffer;
802 
803  if (NULL != h->emsg)
804  return GNUNET_SYSERR;
805 
806  if (0 == n)
807  return GNUNET_OK;
808 
809  switch (h->type)
810  {
811  case IO_FILE:
812  return write_to_file (h, what, src, n);
813  case IO_BUFFER:
814  return write_to_buffer (h, what, src, n);
815  default:
816  GNUNET_asprintf (&h->emsg,
817  _ ("Invalid handle type while writing `%s'"),
818  what);
819  return GNUNET_SYSERR;
820  }
821 }
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:719
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:775

References _, GNUNET_BIO_WriteHandle::buffer, GNUNET_asprintf(), GNUNET_OK, GNUNET_SYSERR, h, IO_BUFFER, IO_FILE, 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_spec_object(), 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(), and write_index_list().

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 833 of file bio.c.

836 {
837  uint32_t slen;
838 
839  slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
840  if (GNUNET_OK != GNUNET_BIO_write_int32 (h, _ ("string length"), slen))
841  return GNUNET_SYSERR;
842  if (0 != slen)
843  return GNUNET_BIO_write (h, what, s, slen - 1);
844  return GNUNET_OK;
845 }
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_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:937

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

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

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 857 of file bio.c.

860 {
861  ssize_t size;
862  char *buf;
863 
864  if (m == NULL)
865  return GNUNET_BIO_write_int32 (h, _ ("metadata length"), 0);
866  buf = NULL;
868  m,
869  &buf,
872  if (-1 == size)
873  {
874  GNUNET_free (buf);
875  GNUNET_free (h->emsg);
876  GNUNET_asprintf (&h->emsg,
877  _ ("Failed to serialize metadata `%s'"),
878  what);
879  return GNUNET_SYSERR;
880  }
882  _ ("metadata length"),
883  (uint32_t) size))
884  || (GNUNET_OK != GNUNET_BIO_write (h, what, buf, size)))
885  {
886  GNUNET_free (buf);
887  return GNUNET_SYSERR;
888  }
889  GNUNET_free (buf);
890  return GNUNET_OK;
891 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
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.
@ GNUNET_CONTAINER_META_DATA_SERIALIZE_PART
If not enough space is available, it is acceptable to only serialize some of the metadata.

References _, buf, 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, h, m, MAX_META_DATA, and size.

Referenced by GNUNET_BIO_write_spec_meta_data().

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 902 of file bio.c.

905 {
906  int32_t i = f;
907  return GNUNET_BIO_write_int32 (h, what, i);
908 }

References removetrailingwhitespace::f, GNUNET_BIO_write_int32(), and h.

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 919 of file bio.c.

922 {
923  int64_t i = f;
924  return GNUNET_BIO_write_int64 (h, what, i);
925 }
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

References removetrailingwhitespace::f, GNUNET_BIO_write_int64(), and h.

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 937 of file bio.c.

940 {
941  int32_t big;
942 
943  big = htonl (i);
944  return GNUNET_BIO_write (h, what, &big, sizeof(int32_t));
945 }

References GNUNET_BIO_write(), and h.

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

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 957 of file bio.c.

960 {
961  int64_t big;
962 
963  big = GNUNET_htonll (i);
964  return GNUNET_BIO_write (h, what, &big, sizeof(int64_t));
965 }
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:36

References GNUNET_BIO_write(), GNUNET_htonll(), and h.

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

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 979 of file bio.c.

1001 {
1002  struct GNUNET_BIO_ReadSpec rs = {
1004  .cls = NULL,
1005  .what = what,
1006  .target = result,
1007  .size = len,
1008  };
1009 
1010  return rs;
1011 }
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:979
Structure specifying a reading operation on an IO handle.
const char * what
What is being read (for error message creation)
GNUNET_BIO_ReadHandler rh
Function performing data deserialization.

References GNUNET_BIO_read(), and h.

Referenced by load_state().

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 1025 of file bio.c.

1049 {
1050  struct GNUNET_BIO_ReadSpec rs = {
1052  .cls = NULL,
1053  .target = result,
1054  .size = max_length,
1055  };
1056 
1057  return rs;
1058 }
static int read_spec_handler_string(void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size)
Function used internally to read a string from within a read spec.
Definition: bio.c:1025

References GNUNET_BIO_read_string(), h, result, GNUNET_BIO_ReadSpec::target, and GNUNET_BIO_ReadSpec::what.

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

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 1073 of file bio.c.

1094 {
1095  struct GNUNET_BIO_ReadSpec rs = {
1097  .cls = NULL,
1098  .target = result,
1099  .size = 0,
1100  };
1101 
1102  return rs;
1103 }
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:1073

References GNUNET_BIO_read_meta_data(), h, and result.

Referenced by deserialize_download(), and read_update_information_graph().

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 1117 of file bio.c.

1138 {
1139  struct GNUNET_BIO_ReadSpec rs = {
1141  .cls = NULL,
1142  .target = i,
1143  .size = 0,
1144  };
1145 
1146  return rs;
1147 }
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:1117

References GNUNET_BIO_read_int32(), h, result, GNUNET_BIO_ReadSpec::target, and GNUNET_BIO_ReadSpec::what.

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

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 1161 of file bio.c.

1182 {
1183  struct GNUNET_BIO_ReadSpec rs = {
1185  .cls = NULL,
1186  .target = i,
1187  .size = 0,
1188  };
1189 
1190  return rs;
1191 }
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:1161

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

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 1161 of file bio.c.

1202 {
1203  struct GNUNET_BIO_ReadSpec rs = {
1205  .cls = NULL,
1206  .target = (int32_t *) f,
1207  .size = 0,
1208  };
1209 
1210  return rs;
1211 }

◆ 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 1161 of file bio.c.

1222 {
1223  struct GNUNET_BIO_ReadSpec rs = {
1225  .cls = NULL,
1226  .target = (int64_t *) f,
1227  .size = 0,
1228  };
1229 
1230  return rs;
1231 }

References GNUNET_BIO_read_int64(), h, result, GNUNET_BIO_ReadSpec::target, and GNUNET_BIO_ReadSpec::what.

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 1243 of file bio.c.

1245 {
1246  int ret = GNUNET_OK;
1247 
1248  for (size_t i = 0; NULL!=rs[i].rh; ++i)
1249  {
1250  ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size);
1251  if (GNUNET_OK != ret)
1252  return ret;
1253  }
1254 
1255  return ret;
1256 }

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

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

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 1270 of file bio.c.

1292 {
1293  struct GNUNET_BIO_WriteSpec ws = {
1295  .cls = NULL,
1296  .what = what,
1297  .source = source,
1298  .source_size = size,
1299  };
1300 
1301  return ws;
1302 }
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:1270
static GstElement * source
Appsrc instance into which we write data for the pipeline.
Structure specifying a writing operation on an IO handle.
GNUNET_BIO_WriteHandler wh
Function performing data serialization.
const char * what
What is being read (for error message creation)

References GNUNET_BIO_write(), h, source, and GNUNET_BIO_ReadSpec::what.

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

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 1317 of file bio.c.

1338 {
1339  struct GNUNET_BIO_WriteSpec ws = {
1341  .cls = NULL,
1342  .what = what,
1343  .source = (void *) s,
1344  .source_size = 0,
1345  };
1346 
1347  return ws;
1348 }
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:1317
size_t source_size
Size of source.

References GNUNET_BIO_write_string(), h, source, and GNUNET_BIO_WriteSpec::what.

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().

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 1363 of file bio.c.

1384 {
1385  struct GNUNET_BIO_WriteSpec ws = {
1387  .cls = NULL,
1388  .what = what,
1389  .source = (void *) m,
1390  .source_size = 0,
1391  };
1392 
1393  return ws;
1394 }
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:1363

References GNUNET_BIO_write_meta_data(), h, m, and source.

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

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 1408 of file bio.c.

1429 {
1430  struct GNUNET_BIO_WriteSpec ws = {
1432  .cls = NULL,
1433  .what = what,
1434  .source = i,
1435  .source_size = 0,
1436  };
1437 
1438  return ws;
1439 }
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:1408

References GNUNET_BIO_write_int32(), h, source, and GNUNET_BIO_WriteSpec::what.

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().

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 1453 of file bio.c.

1474 {
1475  struct GNUNET_BIO_WriteSpec ws = {
1477  .cls = NULL,
1478  .what = what,
1479  .source = i,
1480  .source_size = 0,
1481  };
1482 
1483  return ws;
1484 }
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:1453

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

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 1453 of file bio.c.

1496 {
1497  struct GNUNET_BIO_WriteSpec ws = {
1499  .cls = NULL,
1500  .what = what,
1501  .source = (int32_t *) f,
1502  .source_size = 0,
1503  };
1504 
1505  return ws;
1506 }

◆ 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 1453 of file bio.c.

1518 {
1519  struct GNUNET_BIO_WriteSpec ws = {
1521  .cls = NULL,
1522  .what = what,
1523  .source = (int64_t *) f,
1524  .source_size = 0,
1525  };
1526 
1527  return ws;
1528 }

References GNUNET_BIO_write_int64(), h, source, and GNUNET_BIO_WriteSpec::what.

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 1540 of file bio.c.

1542 {
1543  int ret = GNUNET_OK;
1544 
1545  for (size_t i = 0; NULL!=ws[i].wh; ++i)
1546  {
1547  ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size);
1548  if (GNUNET_OK != ret)
1549  return ret;
1550  }
1551 
1552  /* If it's a file-based handle, the flush makes sure that the data in the
1553  buffer is actually written to the disk. */
1554  if (IO_FILE == h->type)
1555  ret = GNUNET_BIO_flush (h);
1556 
1557  return ret;
1558 }

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().

Here is the caller graph for this function: