GNUnet 0.21.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_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: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:1237
@ 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:94
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(), 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{
648 if (IO_BUFFER != h->type)
649 return GNUNET_SYSERR;
650 if ((NULL == contents) || (NULL == size))
651 return GNUNET_SYSERR;
653 = (NULL != h->emsg)
655 : GNUNET_OK;
656 if (NULL != emsg)
657 *emsg = h->emsg;
658 else
659 GNUNET_free (h->emsg);
660 *contents = GNUNET_buffer_reap ((struct GNUNET_Buffer *) h->buffer, size);
661 return ret;
662}
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: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_(), 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 752 of file bio.c.

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

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

792{
793 uint32_t slen;
794
795 slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
796 if (GNUNET_OK != GNUNET_BIO_write_int32 (h, _ ("string length"), slen))
797 return GNUNET_SYSERR;
798 if (0 != slen)
799 return GNUNET_BIO_write (h, what, s, slen - 1);
800 return GNUNET_OK;
801}
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:847
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:752

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

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

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

832{
833 int64_t i = f;
834 return GNUNET_BIO_write_int64 (h, what, i);
835}
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:867

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

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

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

870{
871 int64_t big;
872
873 big = GNUNET_htonll (i);
874 return GNUNET_BIO_write (h, what, &big, sizeof(int64_t));
875}
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 908 of file bio.c.

911{
912 struct GNUNET_BIO_ReadSpec rs = {
914 .cls = NULL,
915 .what = what,
916 .target = result,
917 .size = len,
918 };
919
920 return rs;
921}
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:889
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 956 of file bio.c.

959{
960 struct GNUNET_BIO_ReadSpec rs = {
962 .cls = NULL,
963 .target = result,
964 .size = max_length,
965 };
966
967 return rs;
968}
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:935

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

1003{
1004 struct GNUNET_BIO_ReadSpec rs = {
1006 .cls = NULL,
1007 .target = i,
1008 .size = 0,
1009 };
1010
1011 return rs;
1012}
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:982

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

1047{
1048 struct GNUNET_BIO_ReadSpec rs = {
1050 .cls = NULL,
1051 .target = i,
1052 .size = 0,
1053 };
1054
1055 return rs;
1056}
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:1026

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

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

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

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

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

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

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

1157{
1158 struct GNUNET_BIO_WriteSpec ws = {
1160 .cls = NULL,
1161 .what = what,
1162 .source = source,
1163 .source_size = size,
1164 };
1165
1166 return ws;
1167}
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:1135
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 1201 of file bio.c.

1203{
1204 struct GNUNET_BIO_WriteSpec ws = {
1206 .cls = NULL,
1207 .what = what,
1208 .source = (void *) s,
1209 .source_size = 0,
1210 };
1211
1212 return ws;
1213}
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:1182
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 1246 of file bio.c.

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

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

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

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

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

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

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

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

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

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: