GNUnet  0.10.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 43 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().

48 {
49  int have;
50  const void *ret;
51  void **rdst = (void **) dst;
52 
53  if (SQLITE_NULL ==
54  sqlite3_column_type (result,
55  column))
56  {
57  *rdst = NULL;
58  *dst_size = 0;
59  return GNUNET_YES;
60  }
61 
62  if (SQLITE_BLOB !=
63  sqlite3_column_type (result,
64  column))
65  {
66  GNUNET_break (0);
67  return GNUNET_SYSERR;
68  }
69  /* sqlite manual says to invoke 'sqlite3_column_blob()'
70  before calling sqlite3_column_bytes() */
71  ret = sqlite3_column_blob (result,
72  column);
73  have = sqlite3_column_bytes (result,
74  column);
75  if (have < 0)
76  {
77  GNUNET_break (0);
78  return GNUNET_SYSERR;
79  }
80  *dst_size = have;
81  if (0 == have)
82  {
83  *rdst = NULL;
84  return GNUNET_OK;
85  }
86  *rdst = GNUNET_malloc (have);
87  GNUNET_memcpy (*rdst,
88  ret,
89  have);
90  return GNUNET_OK;
91 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_memcpy(dst, src, n)
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
#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 100 of file sq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_SQ_result_spec_variable_size().

101 {
102  void **dptr = (void **) cls;
103 
104  if (NULL != *dptr)
105  {
106  GNUNET_free (*dptr);
107  *dptr = NULL;
108  }
109 }
#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 120 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().

122 {
123  struct GNUNET_SQ_ResultSpec rs = {
125  .cleaner = &clean_var_blob,
126  .dst = dst,
127  .cls = dst,
128  .result_size = sptr,
129  .num_params = 1
130  };
131 
132  return rs;
133 }
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 149 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().

154 {
155  int have;
156  const void *ret;
157 
158  if ( (0 == *dst_size) &&
159  (SQLITE_NULL ==
160  sqlite3_column_type (result,
161  column)) )
162  {
163  return GNUNET_YES;
164  }
165 
166  if (SQLITE_BLOB !=
167  sqlite3_column_type (result,
168  column))
169  {
170  GNUNET_break (0);
171  return GNUNET_SYSERR;
172  }
173  /* sqlite manual says to invoke 'sqlite3_column_blob()'
174  before calling sqlite3_column_bytes() */
175  ret = sqlite3_column_blob (result,
176  column);
177  have = sqlite3_column_bytes (result,
178  column);
179  if (*dst_size != have)
180  {
181  GNUNET_break (0);
182  return GNUNET_SYSERR;
183  }
185  ret,
186  have);
187  return GNUNET_OK;
188 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_memcpy(dst, src, n)
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...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
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 199 of file sq_result_helper.c.

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

201 {
202  struct GNUNET_SQ_ResultSpec rs = {
204  .dst = dst,
205  .dst_size = dst_size,
206  .num_params = 1
207  };
208 
209  return rs;
210 }
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 226 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().

231 {
232  const char *text;
233  char **rdst = dst;
234 
235  if (SQLITE_NULL ==
236  sqlite3_column_type (result,
237  column))
238  {
239  *rdst = NULL;
240  return GNUNET_OK;
241  }
242  if (SQLITE_TEXT !=
243  sqlite3_column_type (result,
244  column))
245  {
246  GNUNET_break (0);
247  return GNUNET_SYSERR;
248  }
249  /* sqlite manual guarantees that 'sqlite3_column_text()'
250  is 0-terminated */
251  text = (const char *) sqlite3_column_text (result,
252  column);
253  if (NULL == text)
254  {
255  GNUNET_break (0);
256  return GNUNET_SYSERR;
257  }
258  *dst_size = strlen (text) + 1;
259  *rdst = GNUNET_strdup (text);
260  return GNUNET_OK;
261 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 270 of file sq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_SQ_result_spec_string().

271 {
272  char **dptr = (char **) cls;
273 
274  if (NULL != *dptr)
275  {
276  GNUNET_free (*dptr);
277  *dptr = NULL;
278  }
279 }
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 289 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().

290 {
291  struct GNUNET_SQ_ResultSpec rs = {
293  .cleaner = &clean_utf8_string,
294  .cls = dst,
295  .dst = dst,
296  .num_params = 1
297  };
298 
299  return rs;
300 }
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 316 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().

321 {
322  struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
323  int have;
324  const void *ret;
325 
326  if (SQLITE_BLOB !=
327  sqlite3_column_type (result,
328  column))
329  {
330  GNUNET_break (0);
331  return GNUNET_SYSERR;
332  }
333  /* sqlite manual says to invoke 'sqlite3_column_blob()'
334  before calling sqlite3_column_bytes() */
335  ret = sqlite3_column_blob (result,
336  column);
337  have = sqlite3_column_bytes (result,
338  column);
339  if (have < 0)
340  {
341  GNUNET_break (0);
342  return GNUNET_SYSERR;
343  }
344 
346  have);
347  if (NULL == *pk)
348  {
349  GNUNET_break (0);
350  return GNUNET_SYSERR;
351  }
352  return GNUNET_OK;
353 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:370
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 363 of file sq_result_helper.c.

References GNUNET_CRYPTO_rsa_public_key_free(), and pk.

Referenced by GNUNET_SQ_result_spec_rsa_public_key().

364 {
365  struct GNUNET_CRYPTO_RsaPublicKey **pk = cls;
366 
367  if (NULL != *pk)
368  {
370  *pk = NULL;
371  }
372 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
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:302
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 382 of file sq_result_helper.c.

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

383 {
384  struct GNUNET_SQ_ResultSpec rs = {
385  .conv = &extract_rsa_pub,
386  .cleaner = &clean_rsa_pub,
387  .dst = rsa,
388  .cls = rsa,
389  .num_params = 1
390  };
391 
392  return rs;
393 }
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 409 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().

414 {
415  struct GNUNET_CRYPTO_RsaSignature **sig = dst;
416  int have;
417  const void *ret;
418 
419  if (SQLITE_BLOB !=
420  sqlite3_column_type (result,
421  column))
422  {
423  GNUNET_break (0);
424  return GNUNET_SYSERR;
425  }
426  /* sqlite manual says to invoke 'sqlite3_column_blob()'
427  before calling sqlite3_column_bytes() */
428  ret = sqlite3_column_blob (result,
429  column);
430  have = sqlite3_column_bytes (result,
431  column);
432  if (have < 0)
433  {
434  GNUNET_break (0);
435  return GNUNET_SYSERR;
436  }
437 
439  have);
440  if (NULL == *sig)
441  {
442  GNUNET_break (0);
443  return GNUNET_SYSERR;
444  }
445  return GNUNET_OK;
446 }
an RSA signature
Definition: crypto_rsa.c:63
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const char *buf, size_t len)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:996
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 456 of file sq_result_helper.c.

References GNUNET_CRYPTO_rsa_signature_free().

Referenced by GNUNET_SQ_result_spec_rsa_signature().

457 {
458  struct GNUNET_CRYPTO_RsaSignature **sig = cls;
459 
460  if (NULL != *sig)
461  {
463  *sig = NULL;
464  }
465 }
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:951
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 475 of file sq_result_helper.c.

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

476 {
477  struct GNUNET_SQ_ResultSpec rs = {
478  .conv = &extract_rsa_sig,
479  .cleaner = &clean_rsa_sig,
480  .dst = sig,
481  .cls = sig,
482  .num_params = 1
483  };
484 
485  return rs;
486 }
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 502 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().

507 {
508  struct GNUNET_TIME_Absolute *u = dst;
509  struct GNUNET_TIME_Absolute t;
510 
511  GNUNET_assert (sizeof (uint64_t) == *dst_size);
512  if (SQLITE_INTEGER !=
513  sqlite3_column_type (result,
514  column))
515  {
516  GNUNET_break (0);
517  return GNUNET_SYSERR;
518  }
519  t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
520  column);
521  if (INT64_MAX == t.abs_value_us)
523  *u = t;
524  return GNUNET_OK;
525 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 535 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().

536 {
537  struct GNUNET_SQ_ResultSpec rs = {
539  .dst = at,
540  .dst_size = sizeof (struct GNUNET_TIME_Absolute),
541  .num_params = 1
542  };
543 
544  return rs;
545 }
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 561 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().

566 {
567  struct GNUNET_TIME_AbsoluteNBO *u = dst;
568  struct GNUNET_TIME_Absolute t;
569 
570  GNUNET_assert (sizeof (uint64_t) == *dst_size);
571  if (SQLITE_INTEGER !=
572  sqlite3_column_type (result,
573  column))
574  {
575  GNUNET_break (0);
576  return GNUNET_SYSERR;
577  }
578  t.abs_value_us = (uint64_t) sqlite3_column_int64 (result,
579  column);
580  if (INT64_MAX == t.abs_value_us)
583  return GNUNET_OK;
584 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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:654
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 594 of file sq_result_helper.c.

References GNUNET_SQ_ResultSpec::conv, and extract_abs_time_nbo().

595 {
596  struct GNUNET_SQ_ResultSpec rs = {
598  .dst = at,
599  .dst_size = sizeof (struct GNUNET_TIME_AbsoluteNBO),
600  .num_params = 1
601  };
602 
603  return rs;
604 }
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 620 of file sq_result_helper.c.

References GNUNET_assert, GNUNET_break, GNUNET_OK, and GNUNET_SYSERR.

Referenced by GNUNET_SQ_result_spec_uint16().

625 {
626  uint64_t v;
627  uint16_t *u = dst;
628 
629  GNUNET_assert (sizeof (uint16_t) == *dst_size);
630  if (SQLITE_INTEGER !=
631  sqlite3_column_type (result,
632  column))
633  {
634  GNUNET_break (0);
635  return GNUNET_SYSERR;
636  }
637  v = (uint64_t) sqlite3_column_int64 (result,
638  column);
639  if (v > UINT16_MAX)
640  {
641  GNUNET_break (0);
642  return GNUNET_SYSERR;
643  }
644  *u = (uint16_t) v;
645  return GNUNET_OK;
646 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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_SYSERR
Definition: gnunet_common.h:79
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 656 of file sq_result_helper.c.

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

657 {
658  struct GNUNET_SQ_ResultSpec rs = {
659  .conv = &extract_uint16,
660  .dst = u16,
661  .dst_size = sizeof (uint16_t),
662  .num_params = 1
663  };
664 
665  return rs;
666 }
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 682 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().

687 {
688  uint64_t v;
689  uint32_t *u = dst;
690 
691  GNUNET_assert (sizeof (uint32_t) == *dst_size);
692  if (SQLITE_INTEGER !=
693  sqlite3_column_type (result,
694  column))
695  {
696  GNUNET_break (0);
697  return GNUNET_SYSERR;
698  }
699  v = (uint64_t) sqlite3_column_int64 (result,
700  column);
701  if (v > UINT32_MAX)
702  {
703  GNUNET_break (0);
704  return GNUNET_SYSERR;
705  }
706  *u = (uint32_t) v;
707  return GNUNET_OK;
708 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 718 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().

719 {
720  struct GNUNET_SQ_ResultSpec rs = {
721  .conv = &extract_uint32,
722  .dst = u32,
723  .dst_size = sizeof (uint32_t),
724  .num_params = 1
725  };
726 
727  return rs;
728 }
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 744 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().

749 {
750  uint64_t *u = dst;
751 
752  GNUNET_assert (sizeof (uint64_t) == *dst_size);
753  if (SQLITE_INTEGER !=
754  sqlite3_column_type (result,
755  column))
756  {
757  GNUNET_break (0);
758  return GNUNET_SYSERR;
759  }
760  *u = (uint64_t) sqlite3_column_int64 (result,
761  column);
762  return GNUNET_OK;
763 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 773 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().

774 {
775  struct GNUNET_SQ_ResultSpec rs = {
776  .conv = &extract_uint64,
777  .dst = u64,
778  .dst_size = sizeof (uint64_t),
779  .num_params = 1
780  };
781 
782  return rs;
783 }
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: