GNUnet 0.22.2
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_LIB_H
 
#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...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
 Close an open handle. More...
 
void GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char *emsg)
 Set read error to handle. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
 Read some contents into a buffer. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length)
 Read 0-terminated string. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, const char *what, float *f)
 Read a float. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, const char *what, double *f)
 Read a double. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
 Read an (u)int32_t. More...
 
enum GNUNET_GenericReturnValue 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...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h)
 Force a file-based buffered writer to flush its buffer. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, char **emsg, void **contents, size_t *size)
 Get the IO handle's contents. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg)
 Close an IO handle. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
 Write a buffer to a handle. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s)
 Write a 0-terminated string. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, const char *what, float f)
 Write a float. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, const char *what, double f)
 Write a double. More...
 
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
 Write an (u)int32_t. More...
 
enum GNUNET_GenericReturnValue 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_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...
 
enum GNUNET_GenericReturnValue 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_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...
 
enum GNUNET_GenericReturnValue 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_LIB_H

#define GNUNET_BIO_LIB_H

Definition at line 42 of file gnunet_bio_lib.h.

◆ GNUNET_BIO_read_spec_end

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

End of specifications marker.

Definition at line 407 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 555 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 363 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 511 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 114 of file bio.c.

115{
117 struct GNUNET_BIO_ReadHandle *h;
118
120 if (NULL == fd)
121 return NULL;
123 h->type = IO_FILE;
124 h->buffer = (char *) &h[1];
125 h->size = BIO_BUFFER_SIZE;
126 h->fd = fd;
127 return h;
128}
#define BIO_BUFFER_SIZE
Size for I/O buffers.
Definition: bio.c:42
@ IO_FILE
The handle uses a file to read/write data.
Definition: bio.c:56
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
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:1234
@ 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:69
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:78
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 139 of file bio.c.

140{
141 struct GNUNET_BIO_ReadHandle *h;
142
144 h->type = IO_BUFFER;
145 h->buffer = buffer;
146 h->size = size;
147 return h;
148}
@ IO_BUFFER
The data is stored entirely in memory.
Definition: bio.c:61
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int size
Size of the "table".
Definition: peer.c:68
char * buffer
I/O buffer.
Definition: bio.c:88

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

◆ GNUNET_BIO_read_close()

enum GNUNET_GenericReturnValue 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 162 of file bio.c.

163{
164 int err;
165
166 err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
167 if (NULL != emsg)
168 *emsg = h->emsg;
169 else
170 GNUNET_free (h->emsg);
171 switch (h->type)
172 {
173 case IO_FILE:
175 break;
176 case IO_BUFFER:
177 break;
178 default:
179 break;
180 }
181 GNUNET_free (h);
182 return err;
183}
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
@ GNUNET_OK
@ GNUNET_SYSERR
#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_set_error()

void GNUNET_BIO_read_set_error ( struct GNUNET_BIO_ReadHandle h,
const char *  emsg 
)

Set read error to handle.

Parameters
hthe handle
emsgthe message

Definition at line 187 of file bio.c.

188{
189 GNUNET_assert (NULL == h->emsg);
190 h->emsg = GNUNET_strdup (emsg);
191}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References GNUNET_BIO_ReadHandle::emsg, GNUNET_assert, GNUNET_strdup, and h.

Referenced by GNUNET_FS_read_meta_data().

Here is the caller graph for this function:

◆ GNUNET_BIO_read()

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

Read some contents into a buffer.

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

295{
296 char *dst = result;
297
298 if (NULL != h->emsg)
299 return GNUNET_SYSERR;
300
301 if (0 == len)
302 return GNUNET_OK;
303
304 switch (h->type)
305 {
306 case IO_FILE:
307 return read_from_file (h, what, dst, len);
308 case IO_BUFFER:
309 return read_from_buffer (h, what, dst, len);
310 default:
311 GNUNET_asprintf (&h->emsg,
312 _ ("Invalid handle type while reading `%s'"),
313 what);
314 return GNUNET_SYSERR;
315 }
316}
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:262
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:204
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:178

References _, GNUNET_asprintf(), GNUNET_OK, GNUNET_SYSERR, h, IO_BUFFER, IO_FILE, 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_string(), GNUNET_FS_read_meta_data(), load(), read_download_request(), read_index_list(), and read_spec_handler_object().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_string()

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

Read 0-terminated string.

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

334{
335 char *buf;
336 uint32_t big;
337
339 _ ("string length"),
340 (int32_t *) &big))
341 {
342 char *tmp = h->emsg;
343 if (NULL != tmp)
344 GNUNET_asprintf (&h->emsg,
345 _ ("%s (while reading `%s')"),
346 tmp,
347 what);
348 else
349 GNUNET_asprintf (&h->emsg,
350 _ ("Error reading length of string `%s'"),
351 what);
352 GNUNET_free (tmp);
353 return GNUNET_SYSERR;
354 }
355 if (0 == big)
356 {
357 *result = NULL;
358 return GNUNET_OK;
359 }
360 if (big > max_length)
361 {
362 GNUNET_asprintf (&h->emsg,
363 _ ("String `%s' longer than allowed (%u > %lu)"),
364 what,
365 big,
366 (unsigned long) max_length);
367 return GNUNET_SYSERR;
368 }
369 buf = GNUNET_malloc (big);
370 *result = buf;
371 buf[--big] = '\0';
372 if (0 == big)
373 return GNUNET_OK;
374 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
375 {
376 GNUNET_free (buf);
377 *result = NULL;
378 return GNUNET_SYSERR;
379 }
380 return GNUNET_OK;
381}
enum GNUNET_GenericReturnValue GNUNET_BIO_read(struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len)
Read some contents into a buffer.
Definition: bio.c:291
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int32(struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i)
Read an (u)int32_t.
Definition: bio.c:427

References _, 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(), load_hostlist_file(), read_index_list(), and read_spec_handler_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_read_float()

enum GNUNET_GenericReturnValue 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 392 of file bio.c.

395{
396 int32_t *i = (int32_t *) f;
397 return GNUNET_BIO_read_int32 (h, what, i);
398}

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

Here is the call graph for this function:

◆ GNUNET_BIO_read_double()

enum GNUNET_GenericReturnValue 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 409 of file bio.c.

412{
413 int64_t *i = (int64_t *) f;
414 return GNUNET_BIO_read_int64 (h, what, i);
415}
enum GNUNET_GenericReturnValue GNUNET_BIO_read_int64(struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i)
Read an (u)int64_t.
Definition: bio.c:449

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

Here is the call graph for this function:

◆ GNUNET_BIO_read_int32()

enum GNUNET_GenericReturnValue 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 427 of file bio.c.

430{
431 int32_t big;
432
433 if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int32_t)))
434 return GNUNET_SYSERR;
435 *i = ntohl (big);
436 return GNUNET_OK;
437}

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_string(), GNUNET_FS_read_meta_data(), load_state(), read_download_request(), read_spec_handler_int32(), 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()

enum GNUNET_GenericReturnValue 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 449 of file bio.c.

452{
453 int64_t big;
454
455 if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof(int64_t)))
456 return GNUNET_SYSERR;
457 *i = GNUNET_ntohll (big);
458 return GNUNET_OK;
459}
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:54

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

Referenced by deserialize_fi_node(), deserialize_unindex_file(), GNUNET_BIO_read_double(), read_spec_handler_int64(), 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 508 of file bio.c.

509{
512
519 if (NULL == fd)
520 return NULL;
522 h->buffer = &h[1];
523 h->size = BIO_BUFFER_SIZE;
524 h->fd = fd;
525 return h;
526}
@ 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:466
struct GNUNET_DISK_FileHandle * fd
Handle to a file on disk, if type is IO_FILE.
Definition: bio.c:475

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_(), 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 535 of file bio.c.

536{
538
540 h->type = IO_BUFFER;
541 h->buffer = (void *) GNUNET_malloc (sizeof (struct GNUNET_Buffer));
542 return h;
543}
Dynamically growing buffer.

References GNUNET_malloc, GNUNET_new, h, and IO_BUFFER.

◆ GNUNET_BIO_flush()

enum GNUNET_GenericReturnValue 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 607 of file bio.c.

608{
609 ssize_t ret;
610
611 if (IO_FILE != h->type)
612 return GNUNET_OK;
614 h->buffer,
615 h->have);
616 if (ret != (ssize_t) h->have)
617 {
619 h->fd = NULL;
620 GNUNET_free (h->emsg);
621 GNUNET_asprintf (&h->emsg,
622 "Unable to flush buffer to file");
623 return GNUNET_SYSERR;
624 }
625 h->have = 0;
626 return GNUNET_OK;
627}
static int ret
Final status code.
Definition: gnunet-arm.c:93
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:697

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(), GNUNET_BIO_write_spec_commit(), 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()

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

Get the IO handle's contents.

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

647{
649 if (IO_BUFFER != h->type)
650 return GNUNET_SYSERR;
651 if ((NULL == contents) || (NULL == size))
652 return GNUNET_SYSERR;
653 ret = (NULL != h->emsg) ? GNUNET_SYSERR : GNUNET_OK;
654 if (NULL != emsg)
655 *emsg = h->emsg;
656 else
657 GNUNET_free (h->emsg);
658 *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size);
659 return ret;
660}
void * GNUNET_buffer_reap(struct GNUNET_Buffer *buf, size_t *size)
Clear the buffer and return its contents.
Definition: buffer.c:149
GNUNET_GenericReturnValue
Named constants for return values.

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

enum GNUNET_GenericReturnValue 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 556 of file bio.c.

558{
559 int err;
560
561 err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
562 if (NULL != emsg)
563 *emsg = h->emsg;
564 else
565 GNUNET_free (h->emsg);
566 switch (h->type)
567 {
568 case IO_FILE:
569 if (NULL == h->fd)
570 {
571 err = GNUNET_SYSERR;
572 break;
573 }
575 {
576 if (NULL != emsg)
577 *emsg = h->emsg;
578 else
579 GNUNET_free (h->emsg);
580 err = GNUNET_SYSERR;
581 }
582 else
583 {
585 }
586 break;
587 case IO_BUFFER:
588 GNUNET_buffer_clear ((struct GNUNET_Buffer *) h->buffer);
589 GNUNET_free (h->buffer);
590 break;
591 }
592 GNUNET_free (h);
593 return err;
594}
enum GNUNET_GenericReturnValue GNUNET_BIO_flush(struct GNUNET_BIO_WriteHandle *h)
Force a file-based buffered writer to flush its buffer.
Definition: bio.c:607
void GNUNET_buffer_clear(struct GNUNET_Buffer *buf)
Free the backing memory of the given buffer.
Definition: buffer.c:165

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_(), 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()

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

Write a buffer to a handle.

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

754{
755 const char *src = buffer;
756
757 if (NULL != h->emsg)
758 return GNUNET_SYSERR;
759
760 if (0 == n)
761 return GNUNET_OK;
762
763 switch (h->type)
764 {
765 case IO_FILE:
766 return write_to_file (h, what, src, n);
767 case IO_BUFFER:
768 return write_to_buffer (h, what, src, n);
769 default:
770 GNUNET_asprintf (&h->emsg,
771 _ ("Invalid handle type while writing `%s'"),
772 what);
773 return GNUNET_SYSERR;
774 }
775}
static enum GNUNET_GenericReturnValue 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:673
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:729

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_string(), GNUNET_FS_file_information_sync_(), GNUNET_FS_publish_sync_(), GNUNET_FS_search_result_sync_(), GNUNET_FS_search_sync_(), GNUNET_FS_unindex_sync_(), GNUNET_FS_write_meta_data(), save(), write_download_request(), write_index_list(), and write_spec_handler_object().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_string()

enum GNUNET_GenericReturnValue 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 787 of file bio.c.

790{
791 uint32_t slen;
792
793 slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
794 if (GNUNET_OK != GNUNET_BIO_write_int32 (h, _ ("string length"), slen))
795 return GNUNET_SYSERR;
796 if (0 != slen)
797 return GNUNET_BIO_write (h, what, s, slen - 1);
798 return GNUNET_OK;
799}
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int32(struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i)
Write an (u)int32_t.
Definition: bio.c:845
enum GNUNET_GenericReturnValue GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n)
Write a buffer to a handle.
Definition: bio.c:750

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_BIO_write_float()

enum GNUNET_GenericReturnValue 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 810 of file bio.c.

813{
814 int32_t i = f;
815 return GNUNET_BIO_write_int32 (h, what, i);
816}

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

Here is the call graph for this function:

◆ GNUNET_BIO_write_double()

enum GNUNET_GenericReturnValue 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 827 of file bio.c.

830{
831 int64_t i = f;
832 return GNUNET_BIO_write_int64 (h, what, i);
833}
enum GNUNET_GenericReturnValue GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i)
Write an (u)int64_t.
Definition: bio.c:865

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

Here is the call graph for this function:

◆ GNUNET_BIO_write_int32()

enum GNUNET_GenericReturnValue 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 845 of file bio.c.

848{
849 int32_t big;
850
851 big = htonl (i);
852 return GNUNET_BIO_write (h, what, &big, sizeof(int32_t));
853}

References GNUNET_BIO_write(), and h.

Referenced by GNUNET_BIO_write_float(), GNUNET_BIO_write_string(), GNUNET_FS_search_sync_(), GNUNET_FS_write_meta_data(), save_state(), write_spec_handler_int32(), 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()

enum GNUNET_GenericReturnValue 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 865 of file bio.c.

868{
869 int64_t big;
870
871 big = GNUNET_htonll (i);
872 return GNUNET_BIO_write (h, what, &big, sizeof(int64_t));
873}
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37

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

Referenced by GNUNET_BIO_write_double(), GNUNET_FS_file_information_sync_(), handle_p2p_estimate(), write_spec_handler_int64(), 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 906 of file bio.c.

909{
910 struct GNUNET_BIO_ReadSpec rs = {
912 .cls = NULL,
913 .what = what,
914 .target = result,
915 .size = len,
916 };
917
918 return rs;
919}
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:887
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 read_spec_handler_object(), result, GNUNET_BIO_ReadSpec::rh, and GNUNET_BIO_ReadSpec::what.

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

957{
958 struct GNUNET_BIO_ReadSpec rs = {
960 .cls = NULL,
961 .target = result,
962 .size = max_length,
963 };
964
965 return rs;
966}
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:933

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

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

1001{
1002 struct GNUNET_BIO_ReadSpec rs = {
1004 .cls = NULL,
1005 .target = i,
1006 .size = 0,
1007 };
1008
1009 return rs;
1010}
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:980

References read_spec_handler_int32(), and GNUNET_BIO_ReadSpec::rh.

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

1045{
1046 struct GNUNET_BIO_ReadSpec rs = {
1048 .cls = NULL,
1049 .target = i,
1050 .size = 0,
1051 };
1052
1053 return rs;
1054}
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:1024

References read_spec_handler_int64(), and GNUNET_BIO_ReadSpec::rh.

Referenced by deserialize_download(), 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_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 1064 of file bio.c.

1065{
1066 struct GNUNET_BIO_ReadSpec rs = {
1068 .cls = NULL,
1069 .target = (int32_t *) f,
1070 .size = 0,
1071 };
1072
1073 return rs;
1074}

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

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

1085{
1086 struct GNUNET_BIO_ReadSpec rs = {
1088 .cls = NULL,
1089 .target = (int64_t *) f,
1090 .size = 0,
1091 };
1092
1093 return rs;
1094}

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

Here is the call graph for this function:

◆ GNUNET_BIO_read_spec_commit()

enum GNUNET_GenericReturnValue 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 1106 of file bio.c.

1108{
1109 int ret = GNUNET_OK;
1110
1111 for (size_t i = 0; NULL!=rs[i].rh; ++i)
1112 {
1113 ret = rs[i].rh (rs[i].cls, h, rs[i].what, rs[i].target, rs[i].size);
1114 if (GNUNET_OK != ret)
1115 return ret;
1116 }
1117
1118 return ret;
1119}

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

1155{
1156 struct GNUNET_BIO_WriteSpec ws = {
1158 .cls = NULL,
1159 .what = what,
1160 .source = source,
1161 .source_size = size,
1162 };
1163
1164 return ws;
1165}
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:1133
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 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().

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

1201{
1202 struct GNUNET_BIO_WriteSpec ws = {
1204 .cls = NULL,
1205 .what = what,
1206 .source = (void *) s,
1207 .source_size = 0,
1208 };
1209
1210 return ws;
1211}
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:1180
size_t source_size
Size of source.

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

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

1246{
1247 struct GNUNET_BIO_WriteSpec ws = {
1249 .cls = NULL,
1250 .what = what,
1251 .source = i,
1252 .source_size = 0,
1253 };
1254
1255 return ws;
1256}
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:1225

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

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

1291{
1292 struct GNUNET_BIO_WriteSpec ws = {
1294 .cls = NULL,
1295 .what = what,
1296 .source = i,
1297 .source_size = 0,
1298 };
1299
1300 return ws;
1301}
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:1270

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

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

1313{
1314 struct GNUNET_BIO_WriteSpec ws = {
1316 .cls = NULL,
1317 .what = what,
1318 .source = (int32_t *) f,
1319 .source_size = 0,
1320 };
1321
1322 return ws;
1323}

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

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

1335{
1336 struct GNUNET_BIO_WriteSpec ws = {
1338 .cls = NULL,
1339 .what = what,
1340 .source = (int64_t *) f,
1341 .source_size = 0,
1342 };
1343
1344 return ws;
1345}

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

Here is the call graph for this function:

◆ GNUNET_BIO_write_spec_commit()

enum GNUNET_GenericReturnValue 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 1357 of file bio.c.

1359{
1360 int ret = GNUNET_OK;
1361
1362 for (size_t i = 0; NULL!=ws[i].wh; ++i)
1363 {
1364 ret = ws[i].wh (ws[i].cls, h, ws[i].what, ws[i].source, ws[i].source_size);
1365 if (GNUNET_OK != ret)
1366 return ret;
1367 }
1368
1369 /* If it's a file-based handle, the flush makes sure that the data in the
1370 buffer is actually written to the disk. */
1371 if (IO_FILE == h->type)
1373
1374 return ret;
1375}

References GNUNET_BIO_WriteSpec::cls, GNUNET_BIO_flush(), GNUNET_OK, h, IO_FILE, ret, source, GNUNET_BIO_WriteSpec::source_size, GNUNET_BIO_WriteSpec::wh, 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_download_request(), write_item(), and write_update_information_graph().

Here is the call graph for this function:
Here is the caller graph for this function: