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

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

216 {
217  struct GNUNET_PQ_ResultSpec res =
219  NULL, NULL,
220  (dst), dst_size, name, NULL };
221 
222  return res;
223 }
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 240 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().

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

References GNUNET_CRYPTO_rsa_public_key_free(), and pk.

Referenced by GNUNET_PQ_result_spec_rsa_public_key().

297 {
298  struct GNUNET_CRYPTO_RsaPublicKey **pk = rd;
299 
300  (void) cls;
301  if (NULL != *pk)
302  {
304  *pk = NULL;
305  }
306 }
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:267
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 310 of file pq_result_helper.c.

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

312 {
313  struct GNUNET_PQ_ResultSpec res =
316  NULL,
317  (void *) rsa, 0, name, NULL };
318 
319  return res;
320 }
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 337 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().

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

References GNUNET_CRYPTO_rsa_signature_free().

Referenced by GNUNET_PQ_result_spec_rsa_signature().

394 {
395  struct GNUNET_CRYPTO_RsaSignature **sig = rd;
396 
397  (void) cls;
398  if (NULL != *sig)
399  {
401  *sig = NULL;
402  }
403 }
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:945
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 407 of file pq_result_helper.c.

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

409 {
410  struct GNUNET_PQ_ResultSpec res =
413  NULL,
414  (void *) sig, 0, (name), NULL };
415 
416  return res;
417 }
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 434 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().

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

References GNUNET_free.

Referenced by GNUNET_PQ_result_spec_string().

491 {
492  char **str = rd;
493 
494  (void) cls;
495  if (NULL != *str)
496  {
497  GNUNET_free (*str);
498  *str = NULL;
499  }
500 }
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 504 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().

506 {
507  struct GNUNET_PQ_ResultSpec res =
508  { &extract_string,
509  &clean_string,
510  NULL,
511  (void *) dst, 0, (name), NULL };
512 
513  return res;
514 }
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 531 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().

537 {
538  struct GNUNET_TIME_Relative *udst = dst;
539  const int64_t *res;
540  int fnum;
541 
542  (void) cls;
543  fnum = PQfnumber (result,
544  fname);
545  if (fnum < 0)
546  {
547  GNUNET_break (0);
548  return GNUNET_SYSERR;
549  }
550  if (PQgetisnull (result,
551  row,
552  fnum))
553  {
554  GNUNET_break (0);
555  return GNUNET_SYSERR;
556  }
557  GNUNET_assert (NULL != dst);
558  if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
559  {
560  GNUNET_break (0);
561  return GNUNET_SYSERR;
562  }
563  if (sizeof(int64_t) !=
564  PQgetlength (result,
565  row,
566  fnum))
567  {
568  GNUNET_break (0);
569  return GNUNET_SYSERR;
570  }
571  res = (int64_t *) PQgetvalue (result,
572  row,
573  fnum);
574  if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
576  else
577  udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
578  return GNUNET_OK;
579 }
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 583 of file pq_result_helper.c.

References extract_rel_time(), name, and res.

585 {
586  struct GNUNET_PQ_ResultSpec res = {
588  NULL,
589  NULL,
590  (void *) rt,
591  sizeof(*rt),
592  name,
593  NULL
594  };
595 
596  return res;
597 }
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 614 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().

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

668 {
669  struct GNUNET_PQ_ResultSpec res =
670  { &extract_abs_time,
671  NULL,
672  NULL,
673  (void *) at, sizeof(*at), (name), NULL };
674 
675  return res;
676 }
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 680 of file pq_result_helper.c.

References GNUNET_PQ_result_spec_auto_from_type, and res.

682 {
683  struct GNUNET_PQ_ResultSpec res =
685 
686  return res;
687 }
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 704 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().

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

References extract_uint16(), name, and res.

755 {
756  struct GNUNET_PQ_ResultSpec res =
757  { &extract_uint16,
758  NULL,
759  NULL,
760  (void *) u16, sizeof(*u16), (name), NULL };
761 
762  return res;
763 }
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 780 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().

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

831 {
832  struct GNUNET_PQ_ResultSpec res =
833  { &extract_uint32,
834  NULL,
835  NULL,
836  (void *) u32, sizeof(*u32), (name), NULL };
837 
838  return res;
839 }
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 856 of file pq_result_helper.c.

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

Referenced by GNUNET_PQ_result_spec_uint64().

862 {
863  uint64_t *udst = dst;
864  const uint64_t *res;
865  int fnum;
866 
867  (void) cls;
868  fnum = PQfnumber (result,
869  fname);
870  if (fnum < 0)
871  {
873  "Field %s missing in result\n",
874  fname);
875  GNUNET_break (0);
876  return GNUNET_SYSERR;
877  }
878  if (PQgetisnull (result,
879  row,
880  fnum))
881  {
882  GNUNET_break (0);
883  return GNUNET_SYSERR;
884  }
885  GNUNET_assert (NULL != dst);
886  if (sizeof(uint64_t) != *dst_size)
887  {
888  GNUNET_break (0);
889  return GNUNET_SYSERR;
890  }
891  if (sizeof(uint64_t) !=
892  PQgetlength (result,
893  row,
894  fnum))
895  {
896  GNUNET_break (0);
897  return GNUNET_SYSERR;
898  }
899  res = (uint64_t *) PQgetvalue (result,
900  row,
901  fnum);
902  *udst = GNUNET_ntohll (*res);
903  return GNUNET_OK;
904 }
#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
#define GNUNET_log(kind,...)
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 908 of file pq_result_helper.c.

References extract_uint64(), name, and res.

Referenced by parse_result_call_iterator(), and postgres_plugin_estimate_size().

910 {
911  struct GNUNET_PQ_ResultSpec res = {
913  NULL,
914  NULL,
915  (void *) u64, sizeof(*u64), (name), NULL
916  };
917 
918  return res;
919 }
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: