GNUnet  0.11.x
Functions
sq_result_helper.c File Reference

helper functions for queries More...

#include "platform.h"
#include "gnunet_sq_lib.h"
Include dependency graph for sq_result_helper.c:

Go to the source code of this file.

Functions

static int extract_var_blob (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract variable-sized binary data from a Postgres database result at row row. More...
 
static void clean_var_blob (void *cls)
 Cleanup memory allocated by extract_var_blob(). More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size (void **dst, size_t *sptr)
 Variable-size result expected. More...
 
static int extract_fixed_blob (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract fixed-sized binary data from a Postgres database result at row row. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_fixed_size (void *dst, size_t dst_size)
 Fixed-size result expected. More...
 
static int extract_utf8_string (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract fixed-sized binary data from a Postgres database result at row row. More...
 
static void clean_utf8_string (void *cls)
 Cleanup memory allocated by extract_var_blob(). More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string (char **dst)
 0-terminated string expected. More...
 
static int extract_rsa_pub (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
static void clean_rsa_pub (void *cls)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_public_key (struct GNUNET_CRYPTO_RsaPublicKey **rsa)
 RSA public key expected. More...
 
static int extract_rsa_sig (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
static void clean_rsa_sig (void *cls)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_signature (struct GNUNET_CRYPTO_RsaSignature **sig)
 RSA signature expected. More...
 
static int extract_abs_time (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract absolute time value from a Postgres database result at row row. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time (struct GNUNET_TIME_Absolute *at)
 Absolute time expected. More...
 
static int extract_abs_time_nbo (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract absolute time value in NBO from a Postgres database result at row row. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time_nbo (struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time expected. More...
 
static int extract_uint16 (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract 16-bit integer from a Postgres database result at row row. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint16 (uint16_t *u16)
 uint16_t expected. More...
 
static int extract_uint32 (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract 32-bit integer from a Postgres database result at row row. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32 (uint32_t *u32)
 uint32_t expected. More...
 
static int extract_uint64 (void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
 Extract 64-bit integer from a Postgres database result at row row. More...
 
struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64 (uint64_t *u64)
 uint64_t expected. More...
 

Detailed Description

helper functions for queries

Author
Christian Grothoff

Definition in file sq_result_helper.c.

Function Documentation

◆ extract_var_blob()

static int extract_var_blob ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract variable-sized binary data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result (actually a void **)
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 42 of file sq_result_helper.c.

References GNUNET_break, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and ret.

Referenced by GNUNET_SQ_result_spec_variable_size().

47 {
48  int have;
49  const void *ret;
50  void **rdst = (void **) dst;
51 
52  if (SQLITE_NULL ==
53  sqlite3_column_type (result,
54  column))
55  {
56  *rdst = NULL;
57  *dst_size = 0;
58  return GNUNET_YES;
59  }
60 
61  if (SQLITE_BLOB !=
62  sqlite3_column_type (result,
63  column))
64  {
65  GNUNET_break (0);
66  return GNUNET_SYSERR;
67  }
68  /* sqlite manual says to invoke 'sqlite3_column_blob()'
69  before calling sqlite3_column_bytes() */
70  ret = sqlite3_column_blob (result,
71  column);
72  have = sqlite3_column_bytes (result,
73  column);
74  if (have < 0)
75  {
76  GNUNET_break (0);
77  return GNUNET_SYSERR;
78  }
79  *dst_size = have;
80  if (0 == have)
81  {
82  *rdst = NULL;
83  return GNUNET_OK;
84  }
85  *rdst = GNUNET_malloc (have);
86  GNUNET_memcpy (*rdst,
87  ret,
88  have);
89  return GNUNET_OK;
90 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int result
Global testing status.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the caller graph for this function:

◆ clean_var_blob()

static void clean_var_blob ( void *  cls)
static

Cleanup memory allocated by extract_var_blob().

Parameters
clspointer to pointer of allocation

Definition at line 99 of file sq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_SQ_result_spec_variable_size().

100 {
101  void **dptr = (void **) cls;
102 
103  if (NULL != *dptr)
104  {
105  GNUNET_free (*dptr);
106  *dptr = NULL;
107  }
108 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_variable_size()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_variable_size ( void **  dst,
size_t *  sptr 
)

Variable-size result expected.

Parameters
[out]dstwhere to store the result, allocated
[out]sptrwhere to store the size of dst
Returns
array entry for the result specification to use

Definition at line 119 of file sq_result_helper.c.

References clean_var_blob(), GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst, and extract_var_blob().

Referenced by execute_get(), get_records_and_call_iterator(), namecache_sqlite_lookup_block(), peerstore_sqlite_iterate_records(), sqlite_plugin_del(), sqlite_plugin_get(), sqlite_plugin_get_closest(), and sqlite_plugin_get_random().

121 {
122  struct GNUNET_SQ_ResultSpec rs = {
124  .cleaner = &clean_var_blob,
125  .dst = dst,
126  .cls = dst,
127  .result_size = sptr,
128  .num_params = 1
129  };
130 
131  return rs;
132 }
static void clean_var_blob(void *cls)
Cleanup memory allocated by extract_var_blob().
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
static int extract_var_blob(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract variable-sized binary data from a Postgres database result at row row.
void * dst
Destination for the data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_fixed_blob()

static int extract_fixed_blob ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract fixed-sized binary data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 148 of file sq_result_helper.c.

References GNUNET_break, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and ret.

Referenced by GNUNET_SQ_result_spec_fixed_size().

153 {
154  int have;
155  const void *ret;
156 
157  if ((0 == *dst_size) &&
158  (SQLITE_NULL ==
159  sqlite3_column_type (result,
160  column)))
161  {
162  return GNUNET_YES;
163  }
164 
165  if (SQLITE_BLOB !=
166  sqlite3_column_type (result,
167  column))
168  {
169  GNUNET_break (0);
170  return GNUNET_SYSERR;
171  }
172  /* sqlite manual says to invoke 'sqlite3_column_blob()'
173  before calling sqlite3_column_bytes() */
174  ret = sqlite3_column_blob (result,
175  column);
176  have = sqlite3_column_bytes (result,
177  column);
178  if (*dst_size != have)
179  {
180  GNUNET_break (0);
181  return GNUNET_SYSERR;
182  }
184  ret,
185  have);
186  return GNUNET_OK;
187 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int result
Global testing status.
void * dst
Destination for the data.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_fixed_size()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_fixed_size ( void *  dst,
size_t  dst_size 
)

Fixed-size result expected.

Parameters
[out]dstwhere to store the result
dst_sizenumber of bytes in dst
Returns
array entry for the result specification to use

Definition at line 198 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst, GNUNET_SQ_ResultSpec::dst_size, and extract_fixed_blob().

200 {
201  struct GNUNET_SQ_ResultSpec rs = {
203  .dst = dst,
204  .dst_size = dst_size,
205  .num_params = 1
206  };
207 
208  return rs;
209 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
void * dst
Destination for the data.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
static int extract_fixed_blob(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract fixed-sized binary data from a Postgres database result at row row.
Here is the call graph for this function:

◆ extract_utf8_string()

static int extract_utf8_string ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract fixed-sized binary data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 225 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::dst, GNUNET_break, GNUNET_OK, GNUNET_strdup, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_result_spec_string().

230 {
231  const char *text;
232  char **rdst = dst;
233 
234  if (SQLITE_NULL ==
235  sqlite3_column_type (result,
236  column))
237  {
238  *rdst = NULL;
239  return GNUNET_OK;
240  }
241  if (SQLITE_TEXT !=
242  sqlite3_column_type (result,
243  column))
244  {
245  GNUNET_break (0);
246  return GNUNET_SYSERR;
247  }
248  /* sqlite manual guarantees that 'sqlite3_column_text()'
249  is 0-terminated */
250  text = (const char *) sqlite3_column_text (result,
251  column);
252  if (NULL == text)
253  {
254  GNUNET_break (0);
255  return GNUNET_SYSERR;
256  }
257  *dst_size = strlen (text) + 1;
258  *rdst = GNUNET_strdup (text);
259  return GNUNET_OK;
260 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int result
Global testing status.
void * dst
Destination for the data.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
Here is the caller graph for this function:

◆ clean_utf8_string()

static void clean_utf8_string ( void *  cls)
static

Cleanup memory allocated by extract_var_blob().

Parameters
clspointer to pointer of allocation

Definition at line 269 of file sq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_SQ_result_spec_string().

270 {
271  char **dptr = (char **) cls;
272 
273  if (NULL != *dptr)
274  {
275  GNUNET_free (*dptr);
276  *dptr = NULL;
277  }
278 }
void * cls
Closure for conv and cleaner.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_string()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_string ( char **  dst)

0-terminated string expected.

Parameters
[out]dstwhere to store the result, allocated
Returns
array entry for the result specification to use

Definition at line 288 of file sq_result_helper.c.

References clean_utf8_string(), GNUNET_SQ_ResultSpec::conv, GNUNET_SQ_ResultSpec::dst, and extract_utf8_string().

Referenced by get_records_and_call_iterator(), and peerstore_sqlite_iterate_records().

289 {
290  struct GNUNET_SQ_ResultSpec rs = {
292  .cleaner = &clean_utf8_string,
293  .cls = dst,
294  .dst = dst,
295  .num_params = 1
296  };
297 
298  return rs;
299 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
void * dst
Destination for the data.
static void clean_utf8_string(void *cls)
Cleanup memory allocated by extract_var_blob().
static int extract_utf8_string(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract fixed-sized binary data from a Postgres database result at row row.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_rsa_pub()

static int extract_rsa_pub ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 315 of file sq_result_helper.c.

References GNUNET_break, GNUNET_CRYPTO_rsa_public_key_decode(), GNUNET_OK, GNUNET_SYSERR, pk, and ret.

Referenced by GNUNET_SQ_result_spec_rsa_public_key().

320 {
321  struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
322  int have;
323  const void *ret;
324 
325  if (SQLITE_BLOB !=
326  sqlite3_column_type (result,
327  column))
328  {
329  GNUNET_break (0);
330  return GNUNET_SYSERR;
331  }
332  /* sqlite manual says to invoke 'sqlite3_column_blob()'
333  before calling sqlite3_column_bytes() */
334  ret = sqlite3_column_blob (result,
335  column);
336  have = sqlite3_column_bytes (result,
337  column);
338  if (have < 0)
339  {
340  GNUNET_break (0);
341  return GNUNET_SYSERR;
342  }
343 
345  have);
346  if (NULL == *pk)
347  {
348  GNUNET_break (0);
349  return GNUNET_SYSERR;
350  }
351  return GNUNET_OK;
352 }
struct GNUNET_CRYPTO_EcdsaPrivateKey pk
Private key from command line option, or NULL.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format. ...
Definition: crypto_rsa.c:443
static int result
Global testing status.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_rsa_pub()

static void clean_rsa_pub ( void *  cls)
static

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsclosure

Definition at line 362 of file sq_result_helper.c.

References GNUNET_CRYPTO_rsa_public_key_free(), and pk.

Referenced by GNUNET_SQ_result_spec_rsa_public_key().

363 {
364  struct GNUNET_CRYPTO_RsaPublicKey **pk = cls;
365 
366  if (NULL != *pk)
367  {
369  *pk = NULL;
370  }
371 }
struct GNUNET_CRYPTO_EcdsaPrivateKey pk
Private key from command line option, or NULL.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:305
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_rsa_public_key()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_public_key ( struct GNUNET_CRYPTO_RsaPublicKey **  rsa)

RSA public key expected.

Parameters
[out]rsawhere to store the result
Returns
array entry for the result specification to use

Definition at line 381 of file sq_result_helper.c.

References clean_rsa_pub(), GNUNET_SQ_ResultSpec::conv, and extract_rsa_pub().

382 {
383  struct GNUNET_SQ_ResultSpec rs = {
384  .conv = &extract_rsa_pub,
385  .cleaner = &clean_rsa_pub,
386  .dst = rsa,
387  .cls = rsa,
388  .num_params = 1
389  };
390 
391  return rs;
392 }
static void clean_rsa_pub(void *cls)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
static int extract_rsa_pub(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
Here is the call graph for this function:

◆ extract_rsa_sig()

static int extract_rsa_sig ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 408 of file sq_result_helper.c.

References GNUNET_break, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_OK, GNUNET_SYSERR, and ret.

Referenced by GNUNET_SQ_result_spec_rsa_signature().

413 {
414  struct GNUNET_CRYPTO_RsaSignature **sig = dst;
415  int have;
416  const void *ret;
417 
418  if (SQLITE_BLOB !=
419  sqlite3_column_type (result,
420  column))
421  {
422  GNUNET_break (0);
423  return GNUNET_SYSERR;
424  }
425  /* sqlite manual says to invoke 'sqlite3_column_blob()'
426  before calling sqlite3_column_bytes() */
427  ret = sqlite3_column_blob (result,
428  column);
429  have = sqlite3_column_bytes (result,
430  column);
431  if (have < 0)
432  {
433  GNUNET_break (0);
434  return GNUNET_SYSERR;
435  }
436 
438  have);
439  if (NULL == *sig)
440  {
441  GNUNET_break (0);
442  return GNUNET_SYSERR;
443  }
444  return GNUNET_OK;
445 }
an RSA signature
Definition: crypto_rsa.c:63
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1124
static int result
Global testing status.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_rsa_sig()

static void clean_rsa_sig ( void *  cls)
static

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsresult data to clean up

Definition at line 455 of file sq_result_helper.c.

References GNUNET_CRYPTO_rsa_signature_free().

Referenced by GNUNET_SQ_result_spec_rsa_signature().

456 {
457  struct GNUNET_CRYPTO_RsaSignature **sig = cls;
458 
459  if (NULL != *sig)
460  {
462  *sig = NULL;
463  }
464 }
an RSA signature
Definition: crypto_rsa.c:63
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1061
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_rsa_signature()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_rsa_signature ( struct GNUNET_CRYPTO_RsaSignature **  sig)

RSA signature expected.

Parameters
[out]sigwhere to store the result;
Returns
array entry for the result specification to use

Definition at line 474 of file sq_result_helper.c.

References clean_rsa_sig(), GNUNET_SQ_ResultSpec::conv, and extract_rsa_sig().

475 {
476  struct GNUNET_SQ_ResultSpec rs = {
477  .conv = &extract_rsa_sig,
478  .cleaner = &clean_rsa_sig,
479  .dst = sig,
480  .cls = sig,
481  .num_params = 1
482  };
483 
484  return rs;
485 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
static void clean_rsa_sig(void *cls)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static int extract_rsa_sig(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
Here is the call graph for this function:

◆ extract_abs_time()

static int extract_abs_time ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract absolute time value from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 501 of file sq_result_helper.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, and t.

Referenced by GNUNET_SQ_result_spec_absolute_time().

506 {
507  struct GNUNET_TIME_Absolute *u = dst;
508  struct GNUNET_TIME_Absolute t;
509 
510  GNUNET_assert (sizeof(uint64_t) == *dst_size);
511  if (SQLITE_INTEGER !=
512  sqlite3_column_type (result,
513  column))
514  {
515  GNUNET_break (0);
516  return GNUNET_SYSERR;
517  }
518  t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
519  column);
520  if (INT64_MAX == t.abs_value_us)
522  *u = t;
523  return GNUNET_OK;
524 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static int result
Global testing status.
Time for absolute times used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_absolute_time()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time ( struct GNUNET_TIME_Absolute at)

Absolute time expected.

Parameters
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 534 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, and extract_abs_time().

Referenced by execute_get(), peerstore_sqlite_iterate_records(), sqlite_plugin_get(), sqlite_plugin_get_closest(), and sqlite_plugin_get_random().

535 {
536  struct GNUNET_SQ_ResultSpec rs = {
538  .dst = at,
539  .dst_size = sizeof(struct GNUNET_TIME_Absolute),
540  .num_params = 1
541  };
542 
543  return rs;
544 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
static int extract_abs_time(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract absolute time value from a Postgres database result at row row.
Time for absolute times used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_abs_time_nbo()

static int extract_abs_time_nbo ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract absolute time value in NBO from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 560 of file sq_result_helper.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), and GNUNET_TIME_UNIT_FOREVER_ABS.

Referenced by GNUNET_SQ_result_spec_absolute_time_nbo().

565 {
566  struct GNUNET_TIME_AbsoluteNBO *u = dst;
567  struct GNUNET_TIME_Absolute t;
568 
569  GNUNET_assert (sizeof(uint64_t) == *dst_size);
570  if (SQLITE_INTEGER !=
571  sqlite3_column_type (result,
572  column))
573  {
574  GNUNET_break (0);
575  return GNUNET_SYSERR;
576  }
577  t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
578  column);
579  if (INT64_MAX == t.abs_value_us)
582  return GNUNET_OK;
583 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * t
Main task.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static int result
Global testing status.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_absolute_time_nbo()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_absolute_time_nbo ( struct GNUNET_TIME_AbsoluteNBO at)

Absolute time expected.

Parameters
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 593 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, and extract_abs_time_nbo().

594 {
595  struct GNUNET_SQ_ResultSpec rs = {
597  .dst = at,
598  .dst_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
599  .num_params = 1
600  };
601 
602  return rs;
603 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
static int extract_abs_time_nbo(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract absolute time value in NBO from a Postgres database result at row row.
Here is the call graph for this function:

◆ extract_uint16()

static int extract_uint16 ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract 16-bit integer from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 619 of file sq_result_helper.c.

References GNUNET_assert, GNUNET_break, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_result_spec_uint16().

624 {
625  uint64_t v;
626  uint16_t *u = dst;
627 
628  GNUNET_assert (sizeof(uint16_t) == *dst_size);
629  if (SQLITE_INTEGER !=
630  sqlite3_column_type (result,
631  column))
632  {
633  GNUNET_break (0);
634  return GNUNET_SYSERR;
635  }
636  v = (uint64_t) sqlite3_column_int64 (result,
637  column);
638  if (v > UINT16_MAX)
639  {
640  GNUNET_break (0);
641  return GNUNET_SYSERR;
642  }
643  *u = (uint16_t) v;
644  return GNUNET_OK;
645 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int result
Global testing status.
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_uint16()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint16 ( uint16_t *  u16)

uint16_t expected.

Parameters
[out]u16where to store the result
Returns
array entry for the result specification to use

Definition at line 655 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, extract_uint16(), and GNUNET_SQ_ResultSpec::num_params.

656 {
657  struct GNUNET_SQ_ResultSpec rs = {
658  .conv = &extract_uint16,
659  .dst = u16,
660  .dst_size = sizeof(uint16_t),
661  .num_params = 1
662  };
663 
664  return rs;
665 }
static int extract_uint16(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract 16-bit integer from a Postgres database result at row row.
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
unsigned int num_params
Number of parameters (columns) eaten by this operation.
Here is the call graph for this function:

◆ extract_uint32()

static int extract_uint32 ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract 32-bit integer from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 681 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::dst, GNUNET_assert, GNUNET_break, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_result_spec_uint32().

686 {
687  uint64_t v;
688  uint32_t *u = dst;
689 
690  GNUNET_assert (sizeof(uint32_t) == *dst_size);
691  if (SQLITE_INTEGER !=
692  sqlite3_column_type (result,
693  column))
694  {
695  GNUNET_break (0);
696  return GNUNET_SYSERR;
697  }
698  v = (uint64_t) sqlite3_column_int64 (result,
699  column);
700  if (v > UINT32_MAX)
701  {
702  GNUNET_break (0);
703  return GNUNET_SYSERR;
704  }
705  *u = (uint32_t) v;
706  return GNUNET_OK;
707 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int result
Global testing status.
void * dst
Destination for the data.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_uint32()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint32 ( uint32_t *  u32)

uint32_t expected.

Parameters
[out]u32where to store the result
Returns
array entry for the result specification to use

Definition at line 717 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, extract_uint32(), and GNUNET_SQ_ResultSpec::num_params.

Referenced by execute_get(), get_records_and_call_iterator(), sqlite_plugin_get_closest(), and sqlite_plugin_get_random().

718 {
719  struct GNUNET_SQ_ResultSpec rs = {
720  .conv = &extract_uint32,
721  .dst = u32,
722  .dst_size = sizeof(uint32_t),
723  .num_params = 1
724  };
725 
726  return rs;
727 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
unsigned int num_params
Number of parameters (columns) eaten by this operation.
static int extract_uint32(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract 32-bit integer from a Postgres database result at row row.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_uint64()

static int extract_uint64 ( void *  cls,
sqlite3_stmt *  result,
unsigned int  column,
size_t *  dst_size,
void *  dst 
)
static

Extract 64-bit integer from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
columncolumn to extract data from
[in,out]dst_sizewhere to store size of result, may be NULL
[out]dstwhere to store the result
Returns
GNUNET_YES if all results could be extracted GNUNET_SYSERR if a result was invalid (non-existing field or NULL)

Definition at line 743 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::dst, GNUNET_assert, GNUNET_break, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_result_spec_uint64().

748 {
749  uint64_t *u = dst;
750 
751  GNUNET_assert (sizeof(uint64_t) == *dst_size);
752  if (SQLITE_INTEGER !=
753  sqlite3_column_type (result,
754  column))
755  {
756  GNUNET_break (0);
757  return GNUNET_SYSERR;
758  }
759  *u = (uint64_t) sqlite3_column_int64 (result,
760  column);
761  return GNUNET_OK;
762 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int result
Global testing status.
void * dst
Destination for the data.
size_t dst_size
Allowed size for the data, 0 for variable-size (in this case, the type of dst is a void ** and we nee...
Here is the caller graph for this function:

◆ GNUNET_SQ_result_spec_uint64()

struct GNUNET_SQ_ResultSpec GNUNET_SQ_result_spec_uint64 ( uint64_t *  u64)

uint64_t expected.

Parameters
[out]u64where to store the result
Returns
array entry for the result specification to use

Definition at line 772 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, extract_uint64(), and GNUNET_SQ_ResultSpec::num_params.

Referenced by execute_get(), get_records_and_call_iterator(), and sqlite_plugin_del().

773 {
774  struct GNUNET_SQ_ResultSpec rs = {
775  .conv = &extract_uint64,
776  .dst = u64,
777  .dst_size = sizeof(uint64_t),
778  .num_params = 1
779  };
780 
781  return rs;
782 }
Description of a DB result cell.
GNUNET_SQ_ResultConverter conv
What is the format of the result?
static int extract_uint64(void *cls, sqlite3_stmt *result, unsigned int column, size_t *dst_size, void *dst)
Extract 64-bit integer from a Postgres database result at row row.
unsigned int num_params
Number of parameters (columns) eaten by this operation.
Here is the call graph for this function:
Here is the caller graph for this function: