GNUnet  0.11.x
Functions
pq_result_helper.c File Reference

functions to extract result values More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
Include dependency graph for pq_result_helper.c:

Go to the source code of this file.

Functions

static void clean_varsize_blob (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
static int extract_varsize_blob (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size (const char *name, void **dst, size_t *sptr)
 Variable-size result expected. More...
 
static int extract_fixed_blob (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size)
 Fixed-size result expected. More...
 
static int extract_rsa_public_key (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
static void clean_rsa_public_key (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **rsa)
 RSA public key expected. More...
 
static int extract_rsa_signature (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
static void clean_rsa_signature (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 RSA signature expected. More...
 
static int extract_string (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
static void clean_string (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string (const char *name, char **dst)
 0-terminated string expected. More...
 
static int extract_rel_time (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time expected. More...
 
static int extract_abs_time (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at)
 Absolute time expected. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time in network byte order expected. More...
 
static int extract_uint16 (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16)
 uint16_t expected. More...
 
static int extract_uint32 (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32)
 uint32_t expected. More...
 
static int extract_uint64 (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result at row row. More...
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64)
 uint64_t expected. More...
 

Detailed Description

functions to extract result values

Author
Christian Grothoff

Definition in file pq_result_helper.c.

Function Documentation

◆ clean_varsize_blob()

static void clean_varsize_blob ( void *  cls,
void *  rd 
)
static

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsclosure
rdresult data to clean up

Definition at line 38 of file pq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_PQ_result_spec_variable_size().

40 {
41  void **dst = rd;
42 
43  (void) cls;
44  if (NULL != *dst)
45  {
46  GNUNET_free (*dst);
47  *dst = NULL;
48  }
49 }
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ extract_varsize_blob()

static int extract_varsize_blob ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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)

Definition at line 66 of file pq_result_helper.c.

References GNUNET_assert, GNUNET_break, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, len, and res.

Referenced by GNUNET_PQ_result_spec_variable_size().

72 {
73  size_t len;
74  const char *res;
75  void *idst;
76  int fnum;
77 
78  (void) cls;
79  *dst_size = 0;
80  *((void **) dst) = NULL;
81 
82  fnum = PQfnumber (result,
83  fname);
84  if (fnum < 0)
85  {
86  GNUNET_break (0);
87  return GNUNET_SYSERR;
88  }
89  if (PQgetisnull (result,
90  row,
91  fnum))
92  {
93  /* Let's allow this for varsize */
94  return GNUNET_OK;
95  }
96  /* if a field is null, continue but
97  * remember that we now return a different result */
98  len = PQgetlength (result,
99  row,
100  fnum);
101  res = PQgetvalue (result,
102  row,
103  fnum);
104  GNUNET_assert (NULL != res);
105  *dst_size = len;
106  idst = GNUNET_malloc (len);
107  *((void **) dst) = idst;
108  GNUNET_memcpy (idst,
109  res,
110  len);
111  return GNUNET_OK;
112 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#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.
static int res
#define GNUNET_malloc(size)
Wrapper around malloc.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_variable_size()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size ( const char *  name,
void **  dst,
size_t *  sptr 
)

Variable-size result expected.

Parameters
namename of the field in the table
[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 124 of file pq_result_helper.c.

References clean_varsize_blob(), GNUNET_PQ_ResultSpec::dst, extract_varsize_blob(), name, and res.

Referenced by extract_result_cb(), handle_results(), namecache_postgres_lookup_block(), parse_result_call_iterator(), postgres_plugin_get_random(), and process_result().

127 {
128  struct GNUNET_PQ_ResultSpec res =
130  &clean_varsize_blob, NULL,
131  (void *) (dst), 0, name, sptr };
132 
133  return res;
134 }
Description of a DB result cell.
static int extract_varsize_blob(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static int res
static void clean_varsize_blob(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
const char * name
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,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract from
[in]dst_sizedesired size, never 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 151 of file pq_result_helper.c.

References GNUNET_assert, GNUNET_break, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, len, and res.

Referenced by GNUNET_PQ_result_spec_fixed_size().

157 {
158  size_t len;
159  const char *res;
160  int fnum;
161 
162  (void) cls;
163  fnum = PQfnumber (result,
164  fname);
165  if (fnum < 0)
166  {
167  GNUNET_break (0);
168  return GNUNET_SYSERR;
169  }
170  if (PQgetisnull (result,
171  row,
172  fnum))
173  {
174  GNUNET_break (0);
175  return GNUNET_SYSERR;
176  }
177 
178  /* if a field is null, continue but
179  * remember that we now return a different result */
180  len = PQgetlength (result,
181  row,
182  fnum);
183  if (*dst_size != len)
184  {
185  GNUNET_break (0);
186  return GNUNET_SYSERR;
187  }
188  res = PQgetvalue (result,
189  row,
190  fnum);
191  GNUNET_assert (NULL != res);
193  res,
194  len);
195  return GNUNET_OK;
196 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * fname
Field name of the desired result.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * cls
Closure for conv and cleaner.
static int result
Global testing status.
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 res
void * dst
Destination for the data.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_fixed_size()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size ( const char *  name,
void *  dst,
size_t  dst_size 
)

Fixed-size result expected.

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

Definition at line 208 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, extract_fixed_blob(), and res.

211 {
212  struct GNUNET_PQ_ResultSpec res =
214  NULL, NULL,
215  (dst), dst_size, name, NULL };
216 
217  return res;
218 }
Description of a DB result cell.
static int extract_fixed_blob(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
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 res
const char * name
void * dst
Destination for the data.
Here is the call graph for this function:

◆ extract_rsa_public_key()

static int extract_rsa_public_key ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 235 of file pq_result_helper.c.

References GNUNET_break, GNUNET_CRYPTO_rsa_public_key_decode(), GNUNET_OK, GNUNET_SYSERR, len, pk, and res.

Referenced by GNUNET_PQ_result_spec_rsa_public_key().

241 {
242  struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
243  size_t len;
244  const char *res;
245  int fnum;
246 
247  (void) cls;
248  *pk = NULL;
249  fnum = PQfnumber (result,
250  fname);
251  if (fnum < 0)
252  {
253  GNUNET_break (0);
254  return GNUNET_SYSERR;
255  }
256  if (PQgetisnull (result,
257  row,
258  fnum))
259  {
260  GNUNET_break (0);
261  return GNUNET_SYSERR;
262  }
263  /* if a field is null, continue but
264  * remember that we now return a different result */
265  len = PQgetlength (result,
266  row,
267  fnum);
268  res = PQgetvalue (result,
269  row,
270  fnum);
272  len);
273  if (NULL == *pk)
274  {
275  GNUNET_break (0);
276  return GNUNET_SYSERR;
277  }
278  return GNUNET_OK;
279 }
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
#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.
static int res
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_rsa_public_key()

static void clean_rsa_public_key ( void *  cls,
void *  rd 
)
static

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsclosure
rdresult data to clean up

Definition at line 290 of file pq_result_helper.c.

References GNUNET_CRYPTO_rsa_public_key_free(), and pk.

Referenced by GNUNET_PQ_result_spec_rsa_public_key().

292 {
293  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
294 
295  (void) cls;
296  if (NULL != *pk)
297  {
299  *pk = NULL;
300  }
301 }
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_PQ_result_spec_rsa_public_key()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key ( const char *  name,
struct GNUNET_CRYPTO_RsaPublicKey **  rsa 
)

RSA public key expected.

Parameters
namename of the field in the table
[out]rsawhere to store the result
Returns
array entry for the result specification to use

Definition at line 312 of file pq_result_helper.c.

References clean_rsa_public_key(), extract_rsa_public_key(), and res.

314 {
315  struct GNUNET_PQ_ResultSpec res =
318  NULL,
319  (void *) rsa, 0, name, NULL };
320 
321  return res;
322 }
Description of a DB result cell.
static int res
static void clean_rsa_public_key(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static int extract_rsa_public_key(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
const char * name
Here is the call graph for this function:

◆ extract_rsa_signature()

static int extract_rsa_signature ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 339 of file pq_result_helper.c.

References GNUNET_break, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_OK, GNUNET_SYSERR, len, and res.

Referenced by GNUNET_PQ_result_spec_rsa_signature().

345 {
346  struct GNUNET_CRYPTO_RsaSignature **sig = dst;
347  size_t len;
348  const void *res;
349  int fnum;
350 
351  (void) cls;
352  *sig = NULL;
353  fnum = PQfnumber (result,
354  fname);
355  if (fnum < 0)
356  {
357  GNUNET_break (0);
358  return GNUNET_SYSERR;
359  }
360  if (PQgetisnull (result,
361  row,
362  fnum))
363  {
364  GNUNET_break (0);
365  return GNUNET_SYSERR;
366  }
367  /* if a field is null, continue but
368  * remember that we now return a different result */
369  len = PQgetlength (result,
370  row,
371  fnum);
372  res = PQgetvalue (result,
373  row,
374  fnum);
376  len);
377  if (NULL == *sig)
378  {
379  GNUNET_break (0);
380  return GNUNET_SYSERR;
381  }
382  return GNUNET_OK;
383 }
an RSA signature
Definition: crypto_rsa.c:63
#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.
static int res
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_rsa_signature()

static void clean_rsa_signature ( void *  cls,
void *  rd 
)
static

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsclosure
rdresult data to clean up

Definition at line 394 of file pq_result_helper.c.

References GNUNET_CRYPTO_rsa_signature_free().

Referenced by GNUNET_PQ_result_spec_rsa_signature().

396 {
397  struct GNUNET_CRYPTO_RsaSignature **sig = rd;
398 
399  (void) cls;
400  if (NULL != *sig)
401  {
403  *sig = NULL;
404  }
405 }
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_PQ_result_spec_rsa_signature()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature ( const char *  name,
struct GNUNET_CRYPTO_RsaSignature **  sig 
)

RSA signature expected.

Parameters
namename of the field in the table
[out]sigwhere to store the result;
Returns
array entry for the result specification to use

Definition at line 416 of file pq_result_helper.c.

References clean_rsa_signature(), extract_rsa_signature(), and res.

418 {
419  struct GNUNET_PQ_ResultSpec res =
422  NULL,
423  (void *) sig, 0, (name), NULL };
424 
425  return res;
426 }
Description of a DB result cell.
static void clean_rsa_signature(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static int res
static int extract_rsa_signature(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
const char * name
Here is the call graph for this function:

◆ extract_string()

static int extract_string ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 443 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::dst, GNUNET_break, GNUNET_OK, GNUNET_strndup, GNUNET_SYSERR, len, and res.

Referenced by GNUNET_PQ_result_spec_string().

449 {
450  char **str = dst;
451  size_t len;
452  const char *res;
453  int fnum;
454 
455  (void) cls;
456  *str = NULL;
457  fnum = PQfnumber (result,
458  fname);
459  if (fnum < 0)
460  {
461  GNUNET_break (0);
462  return GNUNET_SYSERR;
463  }
464  if (PQgetisnull (result,
465  row,
466  fnum))
467  {
468  GNUNET_break (0);
469  return GNUNET_SYSERR;
470  }
471  /* if a field is null, continue but
472  * remember that we now return a different result */
473  len = PQgetlength (result,
474  row,
475  fnum);
476  res = PQgetvalue (result,
477  row,
478  fnum);
479  *str = GNUNET_strndup (res,
480  len);
481  if (NULL == *str)
482  {
483  GNUNET_break (0);
484  return GNUNET_SYSERR;
485  }
486  return GNUNET_OK;
487 }
const char * fname
Field name of the desired result.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * cls
Closure for conv and cleaner.
static int result
Global testing status.
static int res
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
void * dst
Destination for the data.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ clean_string()

static void clean_string ( void *  cls,
void *  rd 
)
static

Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Parameters
clsclosure
rdresult data to clean up

Definition at line 498 of file pq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_PQ_result_spec_string().

500 {
501  char **str = rd;
502 
503  (void) cls;
504  if (NULL != *str)
505  {
506  GNUNET_free (*str);
507  *str = NULL;
508  }
509 }
void * cls
Closure for conv and cleaner.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_string()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string ( const char *  name,
char **  dst 
)

0-terminated string expected.

Parameters
namename of the field in the table
[out]dstwhere to store the result, allocated
Returns
array entry for the result specification to use

Definition at line 520 of file pq_result_helper.c.

References clean_string(), GNUNET_PQ_ResultSpec::dst, extract_string(), and res.

Referenced by GNUNET_PQ_run_sql(), and parse_result_call_iterator().

522 {
523  struct GNUNET_PQ_ResultSpec res =
524  { &extract_string,
525  &clean_string,
526  NULL,
527  (void *) dst, 0, (name), NULL };
528 
529  return res;
530 }
static void clean_string(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
Description of a DB result cell.
static int extract_string(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static int res
const char * name
void * dst
Destination for the data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_rel_time()

static int extract_rel_time ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 547 of file pq_result_helper.c.

References GNUNET_assert, GNUNET_break, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_Relative::rel_value_us, and res.

Referenced by GNUNET_PQ_result_spec_relative_time().

553 {
554  struct GNUNET_TIME_Relative *udst = dst;
555  const int64_t *res;
556  int fnum;
557 
558  (void) cls;
559  fnum = PQfnumber (result,
560  fname);
561  if (fnum < 0)
562  {
563  GNUNET_break (0);
564  return GNUNET_SYSERR;
565  }
566  if (PQgetisnull (result,
567  row,
568  fnum))
569  {
570  GNUNET_break (0);
571  return GNUNET_SYSERR;
572  }
573  GNUNET_assert (NULL != dst);
574  if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
575  {
576  GNUNET_break (0);
577  return GNUNET_SYSERR;
578  }
579  if (sizeof(int64_t) !=
580  PQgetlength (result,
581  row,
582  fnum))
583  {
584  GNUNET_break (0);
585  return GNUNET_SYSERR;
586  }
587  res = (int64_t *) PQgetvalue (result,
588  row,
589  fnum);
590  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
592  else
593  udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
594  return GNUNET_OK;
595 }
uint64_t rel_value_us
The actual value.
#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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static int res
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_relative_time()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time ( const char *  name,
struct GNUNET_TIME_Relative rt 
)

Relative time expected.

Parameters
namename of the field in the table
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 606 of file pq_result_helper.c.

References extract_rel_time(), name, and res.

608 {
609  struct GNUNET_PQ_ResultSpec res = {
611  NULL,
612  NULL,
613  (void *) rt,
614  sizeof(*rt),
615  name,
616  NULL
617  };
618 
619  return res;
620 }
Description of a DB result cell.
static int res
const char * name
static int extract_rel_time(void *cls, PGresult *result, int row, const char *fname, 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,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 637 of file pq_result_helper.c.

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

Referenced by GNUNET_PQ_result_spec_absolute_time().

643 {
644  struct GNUNET_TIME_Absolute *udst = dst;
645  const int64_t *res;
646  int fnum;
647 
648  (void) cls;
649  fnum = PQfnumber (result,
650  fname);
651  if (fnum < 0)
652  {
653  GNUNET_break (0);
654  return GNUNET_SYSERR;
655  }
656  if (PQgetisnull (result,
657  row,
658  fnum))
659  {
660  GNUNET_break (0);
661  return GNUNET_SYSERR;
662  }
663  GNUNET_assert (NULL != dst);
664  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
665  {
666  GNUNET_break (0);
667  return GNUNET_SYSERR;
668  }
669  if (sizeof(int64_t) !=
670  PQgetlength (result,
671  row,
672  fnum))
673  {
674  GNUNET_break (0);
675  return GNUNET_SYSERR;
676  }
677  res = (int64_t *) PQgetvalue (result,
678  row,
679  fnum);
680  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
682  else
683  udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
684  return GNUNET_OK;
685 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint64_t abs_value_us
The actual value.
#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.
static int res
Time for absolute times used by GNUnet, in microseconds.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_absolute_time()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time ( const char *  name,
struct GNUNET_TIME_Absolute at 
)

Absolute time expected.

Parameters
namename of the field in the table
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 696 of file pq_result_helper.c.

References extract_abs_time(), name, and res.

Referenced by extract_result_cb(), handle_results(), postgres_plugin_get_random(), and process_result().

698 {
699  struct GNUNET_PQ_ResultSpec res =
700  { &extract_abs_time,
701  NULL,
702  NULL,
703  (void *) at, sizeof(*at), (name), NULL };
704 
705  return res;
706 }
Description of a DB result cell.
static int res
static int extract_abs_time(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
const char * name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_absolute_time_nbo()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo ( const char *  name,
struct GNUNET_TIME_AbsoluteNBO at 
)

Absolute time in network byte order expected.

Absolute time expected.

Parameters
namename of the field in the table
[out]atwhere to store the result
Returns
array entry for the result specification to use

Definition at line 717 of file pq_result_helper.c.

References GNUNET_PQ_result_spec_auto_from_type, and res.

719 {
720  struct GNUNET_PQ_ResultSpec res =
722 
723  return res;
724 }
Description of a DB result cell.
static int res
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
const char * name
uint64_t abs_value_us__
The actual value (in network byte order).

◆ extract_uint16()

static int extract_uint16 ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 741 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::dst, GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, and res.

Referenced by GNUNET_PQ_result_spec_uint16().

747 {
748  uint16_t *udst = dst;
749  const uint16_t *res;
750  int fnum;
751 
752  (void) cls;
753  fnum = PQfnumber (result,
754  fname);
755  if (fnum < 0)
756  {
757  GNUNET_break (0);
758  return GNUNET_SYSERR;
759  }
760  if (PQgetisnull (result,
761  row,
762  fnum))
763  {
764  GNUNET_break (0);
765  return GNUNET_SYSERR;
766  }
767  GNUNET_assert (NULL != dst);
768  if (sizeof(uint16_t) != *dst_size)
769  {
770  GNUNET_break (0);
771  return GNUNET_SYSERR;
772  }
773  if (sizeof(uint16_t) !=
774  PQgetlength (result,
775  row,
776  fnum))
777  {
778  GNUNET_break (0);
779  return GNUNET_SYSERR;
780  }
781  res = (uint16_t *) PQgetvalue (result,
782  row,
783  fnum);
784  *udst = ntohs (*res);
785  return GNUNET_OK;
786 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * fname
Field name of the desired result.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * cls
Closure for conv and cleaner.
static int result
Global testing status.
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 res
void * dst
Destination for the data.
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_uint16()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16 ( const char *  name,
uint16_t *  u16 
)

uint16_t expected.

Parameters
namename of the field in the table
[out]u16where to store the result
Returns
array entry for the result specification to use

Definition at line 797 of file pq_result_helper.c.

References extract_uint16(), name, and res.

799 {
800  struct GNUNET_PQ_ResultSpec res =
801  { &extract_uint16,
802  NULL,
803  NULL,
804  (void *) u16, sizeof(*u16), (name), NULL };
805 
806  return res;
807 }
Description of a DB result cell.
static int res
const char * name
static int extract_uint16(void *cls, PGresult *result, int row, const char *fname, 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_uint32()

static int extract_uint32 ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 824 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::dst, GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, and res.

Referenced by GNUNET_PQ_result_spec_uint32().

830 {
831  uint32_t *udst = dst;
832  const uint32_t *res;
833  int fnum;
834 
835  (void) cls;
836  fnum = PQfnumber (result,
837  fname);
838  if (fnum < 0)
839  {
840  GNUNET_break (0);
841  return GNUNET_SYSERR;
842  }
843  if (PQgetisnull (result,
844  row,
845  fnum))
846  {
847  GNUNET_break (0);
848  return GNUNET_SYSERR;
849  }
850  GNUNET_assert (NULL != dst);
851  if (sizeof(uint32_t) != *dst_size)
852  {
853  GNUNET_break (0);
854  return GNUNET_SYSERR;
855  }
856  if (sizeof(uint32_t) !=
857  PQgetlength (result,
858  row,
859  fnum))
860  {
861  GNUNET_break (0);
862  return GNUNET_SYSERR;
863  }
864  res = (uint32_t *) PQgetvalue (result,
865  row,
866  fnum);
867  *udst = ntohl (*res);
868  return GNUNET_OK;
869 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * fname
Field name of the desired result.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * cls
Closure for conv and cleaner.
static int result
Global testing status.
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 res
void * dst
Destination for the data.
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_uint32()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32 ( const char *  name,
uint32_t *  u32 
)

uint32_t expected.

Parameters
namename of the field in the table
[out]u32where to store the result
Returns
array entry for the result specification to use

Definition at line 880 of file pq_result_helper.c.

References extract_uint32(), name, and res.

Referenced by extract_result_cb(), handle_results(), parse_result_call_iterator(), postgres_plugin_del(), postgres_plugin_get_random(), and process_result().

882 {
883  struct GNUNET_PQ_ResultSpec res =
884  { &extract_uint32,
885  NULL,
886  NULL,
887  (void *) u32, sizeof(*u32), (name), NULL };
888 
889  return res;
890 }
Description of a DB result cell.
static int extract_uint32(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static int res
const char * name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_uint64()

static int extract_uint64 ( void *  cls,
PGresult *  result,
int  row,
const char *  fname,
size_t *  dst_size,
void *  dst 
)
static

Extract data from a Postgres database result at row row.

Parameters
clsclosure
resultwhere to extract data from
introw to extract data from
fnamename (or prefix) of the fields to extract 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 907 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::dst, GNUNET_assert, GNUNET_break, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, and res.

Referenced by GNUNET_PQ_result_spec_uint64().

913 {
914  uint64_t *udst = dst;
915  const uint64_t *res;
916  int fnum;
917 
918  (void) cls;
919  fnum = PQfnumber (result,
920  fname);
921  if (fnum < 0)
922  {
923  GNUNET_break (0);
924  return GNUNET_SYSERR;
925  }
926  if (PQgetisnull (result,
927  row,
928  fnum))
929  {
930  GNUNET_break (0);
931  return GNUNET_SYSERR;
932  }
933  GNUNET_assert (NULL != dst);
934  if (sizeof(uint64_t) != *dst_size)
935  {
936  GNUNET_break (0);
937  return GNUNET_SYSERR;
938  }
939  if (sizeof(uint64_t) !=
940  PQgetlength (result,
941  row,
942  fnum))
943  {
944  GNUNET_break (0);
945  return GNUNET_SYSERR;
946  }
947  res = (uint64_t *) PQgetvalue (result,
948  row,
949  fnum);
950  *udst = GNUNET_ntohll (*res);
951  return GNUNET_OK;
952 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * fname
Field name of the desired result.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * cls
Closure for conv and cleaner.
static int result
Global testing status.
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 res
void * dst
Destination for the data.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_uint64()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64 ( const char *  name,
uint64_t *  u64 
)

uint64_t expected.

Parameters
namename of the field in the table
[out]u64where to store the result
Returns
array entry for the result specification to use

Definition at line 963 of file pq_result_helper.c.

References extract_uint64(), name, and res.

Referenced by parse_result_call_iterator(), and postgres_plugin_estimate_size().

965 {
966  struct GNUNET_PQ_ResultSpec res =
967  { &extract_uint64,
968  NULL,
969  NULL,
970  (void *) u64, sizeof(*u64), (name), NULL };
971 
972  return res;
973 }
Description of a DB result cell.
static int extract_uint64(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result at row row.
static int res
const char * name
Here is the call graph for this function:
Here is the caller graph for this function: