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

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_allow_null (struct GNUNET_PQ_ResultSpec rs, bool *is_null)
 Allow NULL value to be found in the database for the given value. More...
 
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 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

◆ GNUNET_PQ_result_spec_allow_null()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_allow_null ( struct GNUNET_PQ_ResultSpec  rs,
bool *  is_null 
)

Allow NULL value to be found in the database for the given value.

Parameters
rsresult spec entry to modify
[out]is_nulllocation set to 'true' if the value was indeed NULL, set to 'false' if the value was non-NULL
Returns
array entry for the result specification to use

Definition at line 31 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::is_null, and GNUNET_PQ_ResultSpec::is_nullable.

33 {
34  struct GNUNET_PQ_ResultSpec rsr;
35 
36  rsr = rs;
37  rsr.is_nullable = true;
38  rsr.is_null = is_null;
39  return rsr;
40 }
Description of a DB result cell.
bool is_nullable
True if NULL is allowed for a value in the database.
bool * is_null
Points to a location where we should store "true" if the result found is NULL, and otherwise "false"...

◆ 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 51 of file pq_result_helper.c.

References GNUNET_PQ_ResultSpec::dst, and GNUNET_free.

Referenced by GNUNET_PQ_result_spec_variable_size().

53 {
54  void **dst = rd;
55 
56  (void) cls;
57  if (NULL != *dst)
58  {
59  GNUNET_free (*dst);
60  *dst = NULL;
61  }
62 }
void * cls
Closure for conv and cleaner.
void * dst
Destination for the data.
#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 79 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().

85 {
86  size_t len;
87  const char *res;
88  void *idst;
89  int fnum;
90 
91  (void) cls;
92  *dst_size = 0;
93  *((void **) dst) = NULL;
94 
95  fnum = PQfnumber (result,
96  fname);
97  if (fnum < 0)
98  {
99  GNUNET_break (0);
100  return GNUNET_SYSERR;
101  }
102  if (PQgetisnull (result,
103  row,
104  fnum))
105  {
106  /* Let's allow this for varsize */
107  return GNUNET_OK;
108  }
109  /* if a field is null, continue but
110  * remember that we now return a different result */
111  len = PQgetlength (result,
112  row,
113  fnum);
114  res = PQgetvalue (result,
115  row,
116  fnum);
117  GNUNET_assert (NULL != res);
118  *dst_size = len;
119  idst = GNUNET_malloc (len);
120  *((void **) dst) = idst;
121  GNUNET_memcpy (idst,
122  res,
123  len);
124  return GNUNET_OK;
125 }
#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.
#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 129 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().

132 {
133  struct GNUNET_PQ_ResultSpec res =
135  &clean_varsize_blob, NULL,
136  (void *) (dst), 0, name, sptr };
137 
138  return res;
139 }
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 156 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().

162 {
163  size_t len;
164  const char *res;
165  int fnum;
166 
167  (void) cls;
168  fnum = PQfnumber (result,
169  fname);
170  if (fnum < 0)
171  {
172  GNUNET_break (0);
173  return GNUNET_SYSERR;
174  }
175  if (PQgetisnull (result,
176  row,
177  fnum))
178  {
179  GNUNET_break (0);
180  return GNUNET_SYSERR;
181  }
182 
183  /* if a field is null, continue but
184  * remember that we now return a different result */
185  len = PQgetlength (result,
186  row,
187  fnum);
188  if (*dst_size != len)
189  {
190  GNUNET_break (0);
191  return GNUNET_SYSERR;
192  }
193  res = PQgetvalue (result,
194  row,
195  fnum);
196  GNUNET_assert (NULL != res);
198  res,
199  len);
200  return GNUNET_OK;
201 }
#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 205 of file pq_result_helper.c.

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

208 {
209  struct GNUNET_PQ_ResultSpec res =
211  NULL, NULL,
212  (dst), dst_size, name, NULL };
213 
214  return res;
215 }
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 232 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().

238 {
239  struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
240  size_t len;
241  const char *res;
242  int fnum;
243 
244  (void) cls;
245  *pk = NULL;
246  fnum = PQfnumber (result,
247  fname);
248  if (fnum < 0)
249  {
250  GNUNET_break (0);
251  return GNUNET_SYSERR;
252  }
253  if (PQgetisnull (result,
254  row,
255  fnum))
256  {
257  GNUNET_break (0);
258  return GNUNET_SYSERR;
259  }
260  /* if a field is null, continue but
261  * remember that we now return a different result */
262  len = PQgetlength (result,
263  row,
264  fnum);
265  res = PQgetvalue (result,
266  row,
267  fnum);
269  len);
270  if (NULL == *pk)
271  {
272  GNUNET_break (0);
273  return GNUNET_SYSERR;
274  }
275  return GNUNET_OK;
276 }
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
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
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 287 of file pq_result_helper.c.

References GNUNET_CRYPTO_rsa_public_key_free(), and pk.

Referenced by GNUNET_PQ_result_spec_rsa_public_key().

289 {
290  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
291 
292  (void) cls;
293  if (NULL != *pk)
294  {
296  *pk = NULL;
297  }
298 }
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
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 302 of file pq_result_helper.c.

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

304 {
305  struct GNUNET_PQ_ResultSpec res =
308  NULL,
309  (void *) rsa, 0, name, NULL };
310 
311  return res;
312 }
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 329 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().

335 {
336  struct GNUNET_CRYPTO_RsaSignature **sig = dst;
337  size_t len;
338  const void *res;
339  int fnum;
340 
341  (void) cls;
342  *sig = NULL;
343  fnum = PQfnumber (result,
344  fname);
345  if (fnum < 0)
346  {
347  GNUNET_break (0);
348  return GNUNET_SYSERR;
349  }
350  if (PQgetisnull (result,
351  row,
352  fnum))
353  {
354  GNUNET_break (0);
355  return GNUNET_SYSERR;
356  }
357  /* if a field is null, continue but
358  * remember that we now return a different result */
359  len = PQgetlength (result,
360  row,
361  fnum);
362  res = PQgetvalue (result,
363  row,
364  fnum);
366  len);
367  if (NULL == *sig)
368  {
369  GNUNET_break (0);
370  return GNUNET_SYSERR;
371  }
372  return GNUNET_OK;
373 }
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 384 of file pq_result_helper.c.

References GNUNET_CRYPTO_rsa_signature_free().

Referenced by GNUNET_PQ_result_spec_rsa_signature().

386 {
387  struct GNUNET_CRYPTO_RsaSignature **sig = rd;
388 
389  (void) cls;
390  if (NULL != *sig)
391  {
393  *sig = NULL;
394  }
395 }
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 399 of file pq_result_helper.c.

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

401 {
402  struct GNUNET_PQ_ResultSpec res =
405  NULL,
406  (void *) sig, 0, (name), NULL };
407 
408  return res;
409 }
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 426 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().

432 {
433  char **str = dst;
434  size_t len;
435  const char *res;
436  int fnum;
437 
438  (void) cls;
439  *str = NULL;
440  fnum = PQfnumber (result,
441  fname);
442  if (fnum < 0)
443  {
444  GNUNET_break (0);
445  return GNUNET_SYSERR;
446  }
447  if (PQgetisnull (result,
448  row,
449  fnum))
450  {
451  GNUNET_break (0);
452  return GNUNET_SYSERR;
453  }
454  /* if a field is null, continue but
455  * remember that we now return a different result */
456  len = PQgetlength (result,
457  row,
458  fnum);
459  res = PQgetvalue (result,
460  row,
461  fnum);
462  *str = GNUNET_strndup (res,
463  len);
464  if (NULL == *str)
465  {
466  GNUNET_break (0);
467  return GNUNET_SYSERR;
468  }
469  return GNUNET_OK;
470 }
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 481 of file pq_result_helper.c.

References GNUNET_free.

Referenced by GNUNET_PQ_result_spec_string().

483 {
484  char **str = rd;
485 
486  (void) cls;
487  if (NULL != *str)
488  {
489  GNUNET_free (*str);
490  *str = NULL;
491  }
492 }
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 496 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().

498 {
499  struct GNUNET_PQ_ResultSpec res =
500  { &extract_string,
501  &clean_string,
502  NULL,
503  (void *) dst, 0, (name), NULL };
504 
505  return res;
506 }
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 523 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().

529 {
530  struct GNUNET_TIME_Relative *udst = dst;
531  const int64_t *res;
532  int fnum;
533 
534  (void) cls;
535  fnum = PQfnumber (result,
536  fname);
537  if (fnum < 0)
538  {
539  GNUNET_break (0);
540  return GNUNET_SYSERR;
541  }
542  if (PQgetisnull (result,
543  row,
544  fnum))
545  {
546  GNUNET_break (0);
547  return GNUNET_SYSERR;
548  }
549  GNUNET_assert (NULL != dst);
550  if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
551  {
552  GNUNET_break (0);
553  return GNUNET_SYSERR;
554  }
555  if (sizeof(int64_t) !=
556  PQgetlength (result,
557  row,
558  fnum))
559  {
560  GNUNET_break (0);
561  return GNUNET_SYSERR;
562  }
563  res = (int64_t *) PQgetvalue (result,
564  row,
565  fnum);
566  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
568  else
569  udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
570  return GNUNET_OK;
571 }
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]rtwhere to store the result
Returns
array entry for the result specification to use

Definition at line 575 of file pq_result_helper.c.

References extract_rel_time(), name, and res.

577 {
578  struct GNUNET_PQ_ResultSpec res = {
580  NULL,
581  NULL,
582  (void *) rt,
583  sizeof(*rt),
584  name,
585  NULL
586  };
587 
588  return res;
589 }
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 606 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().

612 {
613  struct GNUNET_TIME_Absolute *udst = dst;
614  const int64_t *res;
615  int fnum;
616 
617  (void) cls;
618  fnum = PQfnumber (result,
619  fname);
620  if (fnum < 0)
621  {
622  GNUNET_break (0);
623  return GNUNET_SYSERR;
624  }
625  if (PQgetisnull (result,
626  row,
627  fnum))
628  {
629  GNUNET_break (0);
630  return GNUNET_SYSERR;
631  }
632  GNUNET_assert (NULL != dst);
633  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
634  {
635  GNUNET_break (0);
636  return GNUNET_SYSERR;
637  }
638  if (sizeof(int64_t) !=
639  PQgetlength (result,
640  row,
641  fnum))
642  {
643  GNUNET_break (0);
644  return GNUNET_SYSERR;
645  }
646  res = (int64_t *) PQgetvalue (result,
647  row,
648  fnum);
649  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
651  else
652  udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
653  return GNUNET_OK;
654 }
#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 658 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().

660 {
661  struct GNUNET_PQ_ResultSpec res =
662  { &extract_abs_time,
663  NULL,
664  NULL,
665  (void *) at, sizeof(*at), (name), NULL };
666 
667  return res;
668 }
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 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 672 of file pq_result_helper.c.

References GNUNET_PQ_result_spec_auto_from_type, and res.

674 {
675  struct GNUNET_PQ_ResultSpec res =
677 
678  return res;
679 }
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 696 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().

702 {
703  uint16_t *udst = dst;
704  const uint16_t *res;
705  int fnum;
706 
707  (void) cls;
708  fnum = PQfnumber (result,
709  fname);
710  if (fnum < 0)
711  {
712  GNUNET_break (0);
713  return GNUNET_SYSERR;
714  }
715  if (PQgetisnull (result,
716  row,
717  fnum))
718  {
719  GNUNET_break (0);
720  return GNUNET_SYSERR;
721  }
722  GNUNET_assert (NULL != dst);
723  if (sizeof(uint16_t) != *dst_size)
724  {
725  GNUNET_break (0);
726  return GNUNET_SYSERR;
727  }
728  if (sizeof(uint16_t) !=
729  PQgetlength (result,
730  row,
731  fnum))
732  {
733  GNUNET_break (0);
734  return GNUNET_SYSERR;
735  }
736  res = (uint16_t *) PQgetvalue (result,
737  row,
738  fnum);
739  *udst = ntohs (*res);
740  return GNUNET_OK;
741 }
#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 745 of file pq_result_helper.c.

References extract_uint16(), name, and res.

747 {
748  struct GNUNET_PQ_ResultSpec res =
749  { &extract_uint16,
750  NULL,
751  NULL,
752  (void *) u16, sizeof(*u16), (name), NULL };
753 
754  return res;
755 }
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 772 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().

778 {
779  uint32_t *udst = dst;
780  const uint32_t *res;
781  int fnum;
782 
783  (void) cls;
784  fnum = PQfnumber (result,
785  fname);
786  if (fnum < 0)
787  {
788  GNUNET_break (0);
789  return GNUNET_SYSERR;
790  }
791  if (PQgetisnull (result,
792  row,
793  fnum))
794  {
795  GNUNET_break (0);
796  return GNUNET_SYSERR;
797  }
798  GNUNET_assert (NULL != dst);
799  if (sizeof(uint32_t) != *dst_size)
800  {
801  GNUNET_break (0);
802  return GNUNET_SYSERR;
803  }
804  if (sizeof(uint32_t) !=
805  PQgetlength (result,
806  row,
807  fnum))
808  {
809  GNUNET_break (0);
810  return GNUNET_SYSERR;
811  }
812  res = (uint32_t *) PQgetvalue (result,
813  row,
814  fnum);
815  *udst = ntohl (*res);
816  return GNUNET_OK;
817 }
#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 821 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().

823 {
824  struct GNUNET_PQ_ResultSpec res =
825  { &extract_uint32,
826  NULL,
827  NULL,
828  (void *) u32, sizeof(*u32), (name), NULL };
829 
830  return res;
831 }
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 848 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().

854 {
855  uint64_t *udst = dst;
856  const uint64_t *res;
857  int fnum;
858 
859  (void) cls;
860  fnum = PQfnumber (result,
861  fname);
862  if (fnum < 0)
863  {
864  GNUNET_break (0);
865  return GNUNET_SYSERR;
866  }
867  if (PQgetisnull (result,
868  row,
869  fnum))
870  {
871  GNUNET_break (0);
872  return GNUNET_SYSERR;
873  }
874  GNUNET_assert (NULL != dst);
875  if (sizeof(uint64_t) != *dst_size)
876  {
877  GNUNET_break (0);
878  return GNUNET_SYSERR;
879  }
880  if (sizeof(uint64_t) !=
881  PQgetlength (result,
882  row,
883  fnum))
884  {
885  GNUNET_break (0);
886  return GNUNET_SYSERR;
887  }
888  res = (uint64_t *) PQgetvalue (result,
889  row,
890  fnum);
891  *udst = GNUNET_ntohll (*res);
892  return GNUNET_OK;
893 }
#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 897 of file pq_result_helper.c.

References extract_uint64(), name, and res.

Referenced by parse_result_call_iterator(), and postgres_plugin_estimate_size().

899 {
900  struct GNUNET_PQ_ResultSpec res = {
902  NULL,
903  NULL,
904  (void *) u64, sizeof(*u64), (name), NULL
905  };
906 
907  return res;
908 }
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: