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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue extract_bool (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_bool (const char *name, bool *dst)
 boolean expected. More...
 
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue extract_timestamp (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_timestamp (const char *name, struct GNUNET_TIME_Timestamp *at)
 Timestamp expected. More...
 
static enum GNUNET_GenericReturnValue extract_timestamp_nbo (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_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *at)
 Timestamp expected. More...
 
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 1 of file pq_result_helper.c.

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_null
Points to a location where we should store "true" if the result found is NULL, and otherwise "false".
bool is_nullable
True if NULL is allowed for a value in the database.

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

◆ 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.

53 {
54  void **dst = rd;
55 
56  (void) cls;
57  if (NULL != *dst)
58  {
59  GNUNET_free (*dst);
60  *dst = NULL;
61  }
62 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, and GNUNET_free.

◆ extract_varsize_blob()

static enum GNUNET_GenericReturnValue 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 51 of file pq_result_helper.c.

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  return GNUNET_NO;
106  /* if a field is null, continue but
107  * remember that we now return a different result */
108  len = PQgetlength (result,
109  row,
110  fnum);
111  res = PQgetvalue (result,
112  row,
113  fnum);
114  GNUNET_assert (NULL != res);
115  *dst_size = len;
116  idst = GNUNET_malloc (len);
117  *((void **) dst) = idst;
118  GNUNET_memcpy (idst,
119  res,
120  len);
121  return GNUNET_OK;
122 }
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...
static int result
Global testing status.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#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.
#define GNUNET_malloc(size)
Wrapper around malloc.

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

129 {
130  struct GNUNET_PQ_ResultSpec res = {
131  .conv = &extract_varsize_blob,
132  .cleaner = &clean_varsize_blob,
133  .dst = (void *) (dst),
134  .fname = name,
135  .result_size = sptr
136  };
137 
138  return res;
139 }
const char * name
static enum GNUNET_GenericReturnValue 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 void clean_varsize_blob(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
void * dst
Destination for the data.

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

Here is the caller graph for this function:

◆ extract_fixed_blob()

static enum GNUNET_GenericReturnValue 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 51 of file pq_result_helper.c.

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);
174  "Result does not have field %s\n",
175  fname);
176  return GNUNET_SYSERR;
177  }
178  if (PQgetisnull (result,
179  row,
180  fnum))
181  return GNUNET_NO;
182  /* if a field is null, continue but
183  * remember that we now return a different result */
184  len = PQgetlength (result,
185  row,
186  fnum);
187  if (*dst_size != len)
188  {
190  "Expected %u bytes for field `%s', got %u\n",
191  (unsigned int) *dst_size,
192  fname,
193  (unsigned int) len);
194  GNUNET_break (0);
195  return GNUNET_SYSERR;
196  }
197  res = PQgetvalue (result,
198  row,
199  fnum);
200  GNUNET_assert (NULL != res);
201  GNUNET_memcpy (dst,
202  res,
203  len);
204  return GNUNET_OK;
205 }
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR

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

212 {
213  struct GNUNET_PQ_ResultSpec res = {
214  .conv = &extract_fixed_blob,
215  .dst = (dst),
216  .dst_size = dst_size,
217  .fname = name
218  };
219 
220  return res;
221 }
static enum GNUNET_GenericReturnValue 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.
const char * fname
Field name of the desired result.
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...

◆ extract_rsa_public_key()

static enum GNUNET_GenericReturnValue 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 51 of file pq_result_helper.c.

244 {
245  struct GNUNET_CRYPTO_RsaPublicKey **pk = dst;
246  size_t len;
247  const char *res;
248  int fnum;
249 
250  (void) cls;
251  *pk = NULL;
252  fnum = PQfnumber (result,
253  fname);
254  if (fnum < 0)
255  {
256  GNUNET_break (0);
257  return GNUNET_SYSERR;
258  }
259  if (PQgetisnull (result,
260  row,
261  fnum))
262  return GNUNET_NO;
263 
264  /* if a field is null, continue but
265  * remember that we now return a different result */
266  len = PQgetlength (result,
267  row,
268  fnum);
269  res = PQgetvalue (result,
270  row,
271  fnum);
273  len);
274  if (NULL == *pk)
275  {
276  GNUNET_break (0);
277  return GNUNET_SYSERR;
278  }
279  return GNUNET_OK;
280 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
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:422
The public information of an RSA key pair.
Definition: crypto_rsa.c:52

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

293 {
294  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
295 
296  (void) cls;
297  if (NULL != *pk)
298  {
300  *pk = NULL;
301  }
302 }
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:267

References GNUNET_CRYPTO_rsa_public_key_free(), and pk.

Here is the call 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 291 of file pq_result_helper.c.

308 {
309  struct GNUNET_PQ_ResultSpec res = {
310  .conv = &extract_rsa_public_key,
311  .cleaner = &clean_rsa_public_key,
312  .dst = (void *) rsa,
313  .fname = name
314  };
315 
316  return res;
317 }
static void clean_rsa_public_key(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static enum GNUNET_GenericReturnValue 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.

◆ extract_rsa_signature()

static enum GNUNET_GenericReturnValue 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 291 of file pq_result_helper.c.

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

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

388 {
389  struct GNUNET_CRYPTO_RsaSignature **sig = rd;
390 
391  (void) cls;
392  if (NULL != *sig)
393  {
395  *sig = NULL;
396  }
397 }
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:984

References GNUNET_CRYPTO_rsa_signature_free().

Here is the call 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 386 of file pq_result_helper.c.

403 {
404  struct GNUNET_PQ_ResultSpec res = {
405  .conv = &extract_rsa_signature,
406  .cleaner = &clean_rsa_signature,
407  .dst = (void *) sig,
408  .fname = name
409  };
410 
411  return res;
412 }
static enum GNUNET_GenericReturnValue 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.
static void clean_rsa_signature(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

◆ extract_string()

static enum GNUNET_GenericReturnValue 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 386 of file pq_result_helper.c.

435 {
436  char **str = dst;
437  size_t len;
438  const char *res;
439  int fnum;
440 
441  (void) cls;
442  *str = NULL;
443  fnum = PQfnumber (result,
444  fname);
445  if (fnum < 0)
446  {
447  GNUNET_break (0);
448  return GNUNET_SYSERR;
449  }
450  if (PQgetisnull (result,
451  row,
452  fnum))
453  return GNUNET_NO;
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 }
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.

◆ 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.

483 {
484  char **str = rd;
485 
486  (void) cls;
487  if (NULL != *str)
488  {
489  GNUNET_free (*str);
490  *str = NULL;
491  }
492 }

References GNUNET_PQ_ResultSpec::cls, and GNUNET_free.

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

498 {
499  struct GNUNET_PQ_ResultSpec res = {
500  .conv = &extract_string,
501  .cleaner = &clean_string,
502  .dst = (void *) dst,
503  .fname = (name)
504  };
505 
506  return res;
507 }
static enum GNUNET_GenericReturnValue 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 void clean_string(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

Referenced by parse_result_call_iterator().

Here is the caller graph for this function:

◆ extract_bool()

static enum GNUNET_GenericReturnValue extract_bool ( 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 481 of file pq_result_helper.c.

530 {
531  bool *b = dst;
532  const uint8_t *res;
533  int fnum;
534  size_t len;
535 
536  (void) cls;
537  fnum = PQfnumber (result,
538  fname);
539  if (fnum < 0)
540  {
541  GNUNET_break (0);
542  return GNUNET_SYSERR;
543  }
544  if (PQgetisnull (result,
545  row,
546  fnum))
547  return GNUNET_NO;
548  /* if a field is null, continue but
549  * remember that we now return a different result */
550  len = PQgetlength (result,
551  row,
552  fnum);
553  if (sizeof (uint8_t) != len)
554  {
555  GNUNET_break (0);
556  return GNUNET_SYSERR;
557  }
558  res = (const uint8_t *) PQgetvalue (result,
559  row,
560  fnum);
561  *b = (0 != *res);
562  return GNUNET_OK;
563 }

◆ GNUNET_PQ_result_spec_bool()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool ( const char *  name,
bool *  dst 
)

boolean expected.

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

Definition at line 481 of file pq_result_helper.c.

569 {
570  struct GNUNET_PQ_ResultSpec res = {
571  .conv = &extract_bool,
572  .dst = (void *) dst,
573  .fname = name
574  };
575 
576  return res;
577 }
static enum GNUNET_GenericReturnValue extract_bool(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.

◆ extract_rel_time()

static enum GNUNET_GenericReturnValue 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 481 of file pq_result_helper.c.

600 {
601  struct GNUNET_TIME_Relative *udst = dst;
602  const int64_t *res;
603  int fnum;
604 
605  (void) cls;
606  fnum = PQfnumber (result,
607  fname);
608  if (fnum < 0)
609  {
610  GNUNET_break (0);
611  return GNUNET_SYSERR;
612  }
613  if (PQgetisnull (result,
614  row,
615  fnum))
616  return GNUNET_NO;
617  GNUNET_assert (NULL != dst);
618  if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
619  {
620  GNUNET_break (0);
621  return GNUNET_SYSERR;
622  }
623  if (sizeof(int64_t) !=
624  PQgetlength (result,
625  row,
626  fnum))
627  {
628  GNUNET_break (0);
629  return GNUNET_SYSERR;
630  }
631  res = (int64_t *) PQgetvalue (result,
632  row,
633  fnum);
634  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
636  else
637  udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
638  return GNUNET_OK;
639 }
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:53
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

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

645 {
646  struct GNUNET_PQ_ResultSpec res = {
647  .conv = &extract_rel_time,
648  .dst = (void *) rt,
649  .dst_size = sizeof(*rt),
650  .fname = name
651  };
652 
653  return res;
654 }
static enum GNUNET_GenericReturnValue 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.

◆ extract_abs_time()

static enum GNUNET_GenericReturnValue 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 481 of file pq_result_helper.c.

677 {
678  struct GNUNET_TIME_Absolute *udst = dst;
679  const int64_t *res;
680  int fnum;
681 
682  (void) cls;
683  fnum = PQfnumber (result,
684  fname);
685  if (fnum < 0)
686  {
687  GNUNET_break (0);
688  return GNUNET_SYSERR;
689  }
690  if (PQgetisnull (result,
691  row,
692  fnum))
693  return GNUNET_NO;
694  GNUNET_assert (NULL != dst);
695  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
696  {
697  GNUNET_break (0);
698  return GNUNET_SYSERR;
699  }
700  if (sizeof(int64_t) !=
701  PQgetlength (result,
702  row,
703  fnum))
704  {
705  GNUNET_break (0);
706  return GNUNET_SYSERR;
707  }
708  res = (int64_t *) PQgetvalue (result,
709  row,
710  fnum);
711  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
713  else
714  udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
715  return GNUNET_OK;
716 }
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.

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

722 {
723  struct GNUNET_PQ_ResultSpec res = {
724  .conv = &extract_abs_time,
725  .dst = (void *) at,
726  .dst_size = sizeof(*at),
727  .fname = name
728  };
729 
730  return res;
731 }
static enum GNUNET_GenericReturnValue 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.

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

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

737 {
738  struct GNUNET_PQ_ResultSpec res =
740  &at->abs_value_us__);
741 
742  return res;
743 }
#define GNUNET_PQ_result_spec_auto_from_type(name, dst)
We expect a fixed-size result, with size determined by the type of * dst
uint64_t abs_value_us__
The actual value (in network byte order).

◆ extract_timestamp()

static enum GNUNET_GenericReturnValue extract_timestamp ( 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 481 of file pq_result_helper.c.

766 {
767  struct GNUNET_TIME_Timestamp *udst = dst;
768  struct GNUNET_TIME_Absolute abs;
769  const int64_t *res;
770  int fnum;
771 
772  (void) cls;
773  fnum = PQfnumber (result,
774  fname);
775  if (fnum < 0)
776  {
777  GNUNET_break (0);
778  return GNUNET_SYSERR;
779  }
780  if (PQgetisnull (result,
781  row,
782  fnum))
783  return GNUNET_NO;
784  GNUNET_assert (NULL != dst);
785  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
786  {
787  GNUNET_break (0);
788  return GNUNET_SYSERR;
789  }
790  if (sizeof(int64_t) !=
791  PQgetlength (result,
792  row,
793  fnum))
794  {
795  GNUNET_break (0);
796  return GNUNET_SYSERR;
797  }
798  res = (int64_t *) PQgetvalue (result,
799  row,
800  fnum);
801  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
802  {
804  }
805  else
806  {
807  abs.abs_value_us = GNUNET_ntohll ((uint64_t) *res);
808  if (0 != abs.abs_value_us % GNUNET_TIME_UNIT_SECONDS.rel_value_us)
809  {
810  /* timestamps must be multiple of seconds! */
811  GNUNET_break (0);
812  return GNUNET_SYSERR;
813  }
814  }
815  udst->abs_time = abs;
816  return GNUNET_OK;
817 }
#define GNUNET_TIME_UNIT_SECONDS
One second.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.

◆ GNUNET_PQ_result_spec_timestamp()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp t 
)

Timestamp expected.

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

Definition at line 481 of file pq_result_helper.c.

823 {
824  struct GNUNET_PQ_ResultSpec res = {
825  .conv = &extract_timestamp,
826  .dst = (void *) at,
827  .dst_size = sizeof(*at),
828  .fname = name
829  };
830 
831  return res;
832 }
static enum GNUNET_GenericReturnValue extract_timestamp(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.

◆ extract_timestamp_nbo()

static enum GNUNET_GenericReturnValue extract_timestamp_nbo ( 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 481 of file pq_result_helper.c.

855 {
856  struct GNUNET_TIME_TimestampNBO *udst = dst;
857  struct GNUNET_TIME_Timestamp t;
859 
860  r = extract_timestamp (NULL,
861  result,
862  row,
863  fname,
864  dst_size,
865  &t);
866  if (GNUNET_OK != r)
867  return r;
868  *udst = GNUNET_TIME_timestamp_hton (t);
869  return r;
870 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
GNUNET_GenericReturnValue
Named constants for return values.
Definition: gnunet_common.h:92
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:74
Time for timestamps used by GNUnet, in seconds and in network byte order.

◆ GNUNET_PQ_result_spec_timestamp_nbo()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO tn 
)

Timestamp expected.

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

Definition at line 481 of file pq_result_helper.c.

876 {
877  struct GNUNET_PQ_ResultSpec res = {
878  .conv = &extract_timestamp_nbo,
879  .dst = (void *) at,
880  .dst_size = sizeof(*at),
881  .fname = name
882  };
883 
884  return res;
885 }
static enum GNUNET_GenericReturnValue extract_timestamp_nbo(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.

◆ extract_uint16()

static enum GNUNET_GenericReturnValue 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 481 of file pq_result_helper.c.

908 {
909  uint16_t *udst = dst;
910  const uint16_t *res;
911  int fnum;
912 
913  (void) cls;
914  fnum = PQfnumber (result,
915  fname);
916  if (fnum < 0)
917  {
918  GNUNET_break (0);
919  return GNUNET_SYSERR;
920  }
921  if (PQgetisnull (result,
922  row,
923  fnum))
924  return GNUNET_NO;
925  GNUNET_assert (NULL != dst);
926  if (sizeof(uint16_t) != *dst_size)
927  {
928  GNUNET_break (0);
929  return GNUNET_SYSERR;
930  }
931  if (sizeof(uint16_t) !=
932  PQgetlength (result,
933  row,
934  fnum))
935  {
936  GNUNET_break (0);
937  return GNUNET_SYSERR;
938  }
939  res = (uint16_t *) PQgetvalue (result,
940  row,
941  fnum);
942  *udst = ntohs (*res);
943  return GNUNET_OK;
944 }

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

950 {
951  struct GNUNET_PQ_ResultSpec res = {
952  .conv = &extract_uint16,
953  .dst = (void *) u16,
954  .dst_size = sizeof(*u16),
955  .fname = name
956  };
957 
958  return res;
959 }
static enum GNUNET_GenericReturnValue 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.

◆ extract_uint32()

static enum GNUNET_GenericReturnValue 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 481 of file pq_result_helper.c.

982 {
983  uint32_t *udst = dst;
984  const uint32_t *res;
985  int fnum;
986 
987  (void) cls;
988  fnum = PQfnumber (result,
989  fname);
990  if (fnum < 0)
991  {
992  GNUNET_break (0);
993  return GNUNET_SYSERR;
994  }
995  if (PQgetisnull (result,
996  row,
997  fnum))
998  return GNUNET_NO;
999  GNUNET_assert (NULL != dst);
1000  if (sizeof(uint32_t) != *dst_size)
1001  {
1002  GNUNET_break (0);
1003  return GNUNET_SYSERR;
1004  }
1005  if (sizeof(uint32_t) !=
1006  PQgetlength (result,
1007  row,
1008  fnum))
1009  {
1010  GNUNET_break (0);
1011  return GNUNET_SYSERR;
1012  }
1013  res = (uint32_t *) PQgetvalue (result,
1014  row,
1015  fnum);
1016  *udst = ntohl (*res);
1017  return GNUNET_OK;
1018 }

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

1024 {
1025  struct GNUNET_PQ_ResultSpec res = {
1026  .conv = &extract_uint32,
1027  .dst = (void *) u32,
1028  .dst_size = sizeof(*u32),
1029  .fname = name
1030  };
1031 
1032  return res;
1033 }
static enum GNUNET_GenericReturnValue 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.

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

Here is the caller graph for this function:

◆ extract_uint64()

static enum GNUNET_GenericReturnValue 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 481 of file pq_result_helper.c.

1056 {
1057  uint64_t *udst = dst;
1058  const uint64_t *res;
1059  int fnum;
1060 
1061  (void) cls;
1062  fnum = PQfnumber (result,
1063  fname);
1064  if (fnum < 0)
1065  {
1067  "Field %s missing in result\n",
1068  fname);
1069  GNUNET_break (0);
1070  return GNUNET_SYSERR;
1071  }
1072  if (PQgetisnull (result,
1073  row,
1074  fnum))
1075  return GNUNET_NO;
1076 
1077  GNUNET_assert (NULL != dst);
1078  if (sizeof(uint64_t) != *dst_size)
1079  {
1080  GNUNET_break (0);
1081  return GNUNET_SYSERR;
1082  }
1083  if (sizeof(uint64_t) !=
1084  PQgetlength (result,
1085  row,
1086  fnum))
1087  {
1088  GNUNET_break (0);
1089  return GNUNET_SYSERR;
1090  }
1091  res = (uint64_t *) PQgetvalue (result,
1092  row,
1093  fnum);
1094  *udst = GNUNET_ntohll (*res);
1095  return GNUNET_OK;
1096 }

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

1102 {
1103  struct GNUNET_PQ_ResultSpec res = {
1104  .conv = &extract_uint64,
1105  .dst = (void *) u64,
1106  .dst_size = sizeof(*u64),
1107  .fname = name
1108  };
1109 
1110  return res;
1111 }
static enum GNUNET_GenericReturnValue 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.

Referenced by parse_result_call_iterator(), and postgres_plugin_estimate_size().

Here is the caller graph for this function: