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_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_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 =
132  &clean_varsize_blob, NULL,
133  (void *) (dst), 0, name, sptr };
134 
135  return res;
136 }
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(), postgres_plugin_get_random(), 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.

159 {
160  size_t len;
161  const char *res;
162  int fnum;
163 
164  (void) cls;
165  fnum = PQfnumber (result,
166  fname);
167  if (fnum < 0)
168  {
169  GNUNET_break (0);
171  "Result does not have field %s\n",
172  fname);
173  return GNUNET_SYSERR;
174  }
175  if (PQgetisnull (result,
176  row,
177  fnum))
178  return GNUNET_NO;
179  /* if a field is null, continue but
180  * remember that we now return a different result */
181  len = PQgetlength (result,
182  row,
183  fnum);
184  if (*dst_size != len)
185  {
187  "Expected %u bytes for field `%s', got %u\n",
188  (unsigned int) *dst_size,
189  fname,
190  (unsigned int) len);
191  GNUNET_break (0);
192  return GNUNET_SYSERR;
193  }
194  res = PQgetvalue (result,
195  row,
196  fnum);
197  GNUNET_assert (NULL != res);
198  GNUNET_memcpy (dst,
199  res,
200  len);
201  return GNUNET_OK;
202 }
#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.

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

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

288 {
289  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
290 
291  (void) cls;
292  if (NULL != *pk)
293  {
295  *pk = NULL;
296  }
297 }
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 286 of file pq_result_helper.c.

303 {
304  struct GNUNET_PQ_ResultSpec res =
307  NULL,
308  (void *) rsa, 0, name, NULL };
309 
310  return res;
311 }
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 286 of file pq_result_helper.c.

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

382 {
383  struct GNUNET_CRYPTO_RsaSignature **sig = rd;
384 
385  (void) cls;
386  if (NULL != *sig)
387  {
389  *sig = NULL;
390  }
391 }
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:945

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

397 {
398  struct GNUNET_PQ_ResultSpec res =
401  NULL,
402  (void *) sig, 0, (name), NULL };
403 
404  return res;
405 }
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 380 of file pq_result_helper.c.

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

476 {
477  char **str = rd;
478 
479  (void) cls;
480  if (NULL != *str)
481  {
482  GNUNET_free (*str);
483  *str = NULL;
484  }
485 }

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

491 {
492  struct GNUNET_PQ_ResultSpec res =
493  { &extract_string,
494  &clean_string,
495  NULL,
496  (void *) dst, 0, (name), NULL };
497 
498  return res;
499 }
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_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 474 of file pq_result_helper.c.

522 {
523  struct GNUNET_TIME_Relative *udst = dst;
524  const int64_t *res;
525  int fnum;
526 
527  (void) cls;
528  fnum = PQfnumber (result,
529  fname);
530  if (fnum < 0)
531  {
532  GNUNET_break (0);
533  return GNUNET_SYSERR;
534  }
535  if (PQgetisnull (result,
536  row,
537  fnum))
538  return GNUNET_NO;
539  GNUNET_assert (NULL != dst);
540  if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
541  {
542  GNUNET_break (0);
543  return GNUNET_SYSERR;
544  }
545  if (sizeof(int64_t) !=
546  PQgetlength (result,
547  row,
548  fnum))
549  {
550  GNUNET_break (0);
551  return GNUNET_SYSERR;
552  }
553  res = (int64_t *) PQgetvalue (result,
554  row,
555  fnum);
556  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
558  else
559  udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
560  return GNUNET_OK;
561 }
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 474 of file pq_result_helper.c.

567 {
568  struct GNUNET_PQ_ResultSpec res = {
570  NULL,
571  NULL,
572  (void *) rt,
573  sizeof(*rt),
574  name,
575  NULL
576  };
577 
578  return res;
579 }
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 474 of file pq_result_helper.c.

602 {
603  struct GNUNET_TIME_Absolute *udst = dst;
604  const int64_t *res;
605  int fnum;
606 
607  (void) cls;
608  fnum = PQfnumber (result,
609  fname);
610  if (fnum < 0)
611  {
612  GNUNET_break (0);
613  return GNUNET_SYSERR;
614  }
615  if (PQgetisnull (result,
616  row,
617  fnum))
618  return GNUNET_NO;
619  GNUNET_assert (NULL != dst);
620  if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
621  {
622  GNUNET_break (0);
623  return GNUNET_SYSERR;
624  }
625  if (sizeof(int64_t) !=
626  PQgetlength (result,
627  row,
628  fnum))
629  {
630  GNUNET_break (0);
631  return GNUNET_SYSERR;
632  }
633  res = (int64_t *) PQgetvalue (result,
634  row,
635  fnum);
636  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
638  else
639  udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
640  return GNUNET_OK;
641 }
#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 474 of file pq_result_helper.c.

647 {
648  struct GNUNET_PQ_ResultSpec res =
649  { &extract_abs_time,
650  NULL,
651  NULL,
652  (void *) at, sizeof(*at), (name), NULL };
653 
654  return res;
655 }
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(), postgres_plugin_get_random(), 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 474 of file pq_result_helper.c.

661 {
662  struct GNUNET_PQ_ResultSpec res =
664 
665  return res;
666 }
#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_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 474 of file pq_result_helper.c.

689 {
690  uint16_t *udst = dst;
691  const uint16_t *res;
692  int fnum;
693 
694  (void) cls;
695  fnum = PQfnumber (result,
696  fname);
697  if (fnum < 0)
698  {
699  GNUNET_break (0);
700  return GNUNET_SYSERR;
701  }
702  if (PQgetisnull (result,
703  row,
704  fnum))
705  return GNUNET_NO;
706  GNUNET_assert (NULL != dst);
707  if (sizeof(uint16_t) != *dst_size)
708  {
709  GNUNET_break (0);
710  return GNUNET_SYSERR;
711  }
712  if (sizeof(uint16_t) !=
713  PQgetlength (result,
714  row,
715  fnum))
716  {
717  GNUNET_break (0);
718  return GNUNET_SYSERR;
719  }
720  res = (uint16_t *) PQgetvalue (result,
721  row,
722  fnum);
723  *udst = ntohs (*res);
724  return GNUNET_OK;
725 }

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

731 {
732  struct GNUNET_PQ_ResultSpec res =
733  { &extract_uint16,
734  NULL,
735  NULL,
736  (void *) u16, sizeof(*u16), (name), NULL };
737 
738  return res;
739 }
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 474 of file pq_result_helper.c.

762 {
763  uint32_t *udst = dst;
764  const uint32_t *res;
765  int fnum;
766 
767  (void) cls;
768  fnum = PQfnumber (result,
769  fname);
770  if (fnum < 0)
771  {
772  GNUNET_break (0);
773  return GNUNET_SYSERR;
774  }
775  if (PQgetisnull (result,
776  row,
777  fnum))
778  return GNUNET_NO;
779  GNUNET_assert (NULL != dst);
780  if (sizeof(uint32_t) != *dst_size)
781  {
782  GNUNET_break (0);
783  return GNUNET_SYSERR;
784  }
785  if (sizeof(uint32_t) !=
786  PQgetlength (result,
787  row,
788  fnum))
789  {
790  GNUNET_break (0);
791  return GNUNET_SYSERR;
792  }
793  res = (uint32_t *) PQgetvalue (result,
794  row,
795  fnum);
796  *udst = ntohl (*res);
797  return GNUNET_OK;
798 }

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

804 {
805  struct GNUNET_PQ_ResultSpec res = {
807  NULL,
808  NULL,
809  (void *) u32,
810  sizeof(*u32),
811  (name),
812  NULL
813  };
814 
815  return res;
816 }
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(), postgres_plugin_get_random(), 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 474 of file pq_result_helper.c.

839 {
840  uint64_t *udst = dst;
841  const uint64_t *res;
842  int fnum;
843 
844  (void) cls;
845  fnum = PQfnumber (result,
846  fname);
847  if (fnum < 0)
848  {
850  "Field %s missing in result\n",
851  fname);
852  GNUNET_break (0);
853  return GNUNET_SYSERR;
854  }
855  if (PQgetisnull (result,
856  row,
857  fnum))
858  return GNUNET_NO;
859 
860  GNUNET_assert (NULL != dst);
861  if (sizeof(uint64_t) != *dst_size)
862  {
863  GNUNET_break (0);
864  return GNUNET_SYSERR;
865  }
866  if (sizeof(uint64_t) !=
867  PQgetlength (result,
868  row,
869  fnum))
870  {
871  GNUNET_break (0);
872  return GNUNET_SYSERR;
873  }
874  res = (uint64_t *) PQgetvalue (result,
875  row,
876  fnum);
877  *udst = GNUNET_ntohll (*res);
878  return GNUNET_OK;
879 }

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

885 {
886  struct GNUNET_PQ_ResultSpec res = {
888  NULL,
889  NULL,
890  (void *) u64,
891  sizeof(*u64),
892  (name),
893  NULL
894  };
895 
896  return res;
897 }
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: