GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
pq_result_helper.c File Reference

functions to extract result values More...

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

Go to the source code of this file.

Data Structures

struct  array_result_cls
 Closure for the array result specifications. More...
 

Macros

#define FAIL_IF(cond)
 
#define HANDLE_ELEMENT(typ, conv, access)
 
#define HANDLE_ARRAY(typ, conv, access)
 
#define DEREF(typ, conv)    *(typ *) out = conv (*(typ *) in)
 
#define ACCESS_ABS(typ, conv)    ((typ *) out)->abs_value_us = conv (*(uint64_t *) in)
 
#define ACCESS_REL(typ, conv)    ((typ *) out)->rel_value_us = conv (*(uint64_t *) in)
 
#define ACCESS_TSTMP(typ, conv)    ((typ *) out)->abs_time.abs_value_us = conv (*(uint64_t *) in)
 

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.
 
static void clean_varsize_blob (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_variable_size (const char *name, void **dst, size_t *sptr)
 Variable-size result expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_fixed_size (const char *name, void *dst, size_t dst_size)
 Fixed-size result expected.
 
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.
 
static void clean_rsa_public_key (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **rsa)
 RSA public key expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 RSA signature expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_string (const char *name, char **dst)
 0-terminated string expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_bool (const char *name, bool *dst)
 boolean expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at)
 Absolute time expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *at)
 Timestamp expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *at)
 Timestamp expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint16 (const char *name, uint16_t *u16)
 uint16_t expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint32 (const char *name, uint32_t *u32)
 uint32_t expected.
 
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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_uint64 (const char *name, uint64_t *u64)
 uint64_t expected.
 
static enum GNUNET_GenericReturnValue extract_int64 (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.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_int64 (const char *name, int64_t *i64)
 int64_t expected.
 
static enum GNUNET_GenericReturnValue extract_array_generic (void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
 Extract data from a Postgres database result as array of a specific type from row row.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_allow_nulls (struct GNUNET_PQ_ResultSpec rs, bool **is_nulls)
 Allow NULL values in an array to be found in the database for the given value.
 
static void array_cleanup (void *cls, void *rd)
 Cleanup of the data and closure of an array spec.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_bool (struct GNUNET_PQ_Context *db, const char *name, size_t *num, bool **dst)
 array of bool expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint16 (struct GNUNET_PQ_Context *db, const char *name, size_t *num, uint16_t **dst)
 array of uint16_t expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint32 (struct GNUNET_PQ_Context *db, const char *name, size_t *num, uint32_t **dst)
 array of uint32_t expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint64 (struct GNUNET_PQ_Context *db, const char *name, size_t *num, uint64_t **dst)
 array of uint64_t expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_abs_time (struct GNUNET_PQ_Context *db, const char *name, size_t *num, struct GNUNET_TIME_Absolute **dst)
 array of absolute time expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_rel_time (struct GNUNET_PQ_Context *db, const char *name, size_t *num, struct GNUNET_TIME_Relative **dst)
 array of relative time expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_timestamp (struct GNUNET_PQ_Context *db, const char *name, size_t *num, struct GNUNET_TIME_Timestamp **dst)
 array of relative time expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_variable_size (struct GNUNET_PQ_Context *db, const char *name, size_t *num, size_t **sizes, void **dst)
 Array of variable-size result expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_fixed_size (struct GNUNET_PQ_Context *db, const char *name, size_t size, size_t *num, void **dst)
 Array of fixed-size result expected.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_string (struct GNUNET_PQ_Context *db, const char *name, size_t *num, char **dst)
 Array of 0-terminated strings expected.
 
static enum GNUNET_GenericReturnValue extract_blind_sign_pub (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_blind_sign_pub (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_pub (const char *name, struct GNUNET_CRYPTO_BlindSignPublicKey **pub)
 Blind sign public key expected.
 
static enum GNUNET_GenericReturnValue extract_blind_sign_priv (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_blind_sign_priv (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_priv (const char *name, struct GNUNET_CRYPTO_BlindSignPrivateKey **priv)
 Blind sign private key expected.
 
static enum GNUNET_GenericReturnValue extract_blinded_sig (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_blinded_sig (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blinded_sig (const char *name, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
 Blinded signature expected.
 
static enum GNUNET_GenericReturnValue extract_unblinded_sig (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_unblinded_sig (void *cls, void *rd)
 Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
 
struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_unblinded_sig (const char *name, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
 Unblinded signature expected.
 

Detailed Description

functions to extract result values

Author
Christian Grothoff
Özgür Kesim

Definition in file pq_result_helper.c.

Macro Definition Documentation

◆ FAIL_IF

#define FAIL_IF (   cond)
Value:
do { \
if ((cond)) \
{ \
GNUNET_break (! (cond)); \
goto FAIL; \
} \
} while (0)
@ FAIL

◆ HANDLE_ELEMENT

#define HANDLE_ELEMENT (   typ,
  conv,
  access 
)
Value:
do { \
int32_t sz = ntohl (*(int32_t *) in); \
\
in += sizeof(uint32_t); \
if (-1 != sz) \
{ \
FAIL_IF (sz != sizeof(typ)); \
access (typ, conv); \
in += sz; \
} \
else \
{ \
FAIL_IF (! info->allow_nulls); \
(*info->is_nulls)[i] = true; \
} \
\
out += sizeof(typ); \
} while (0)
static GstElement * conv
#define info

◆ HANDLE_ARRAY

#define HANDLE_ARRAY (   typ,
  conv,
  access 
)
Value:
do { \
if (NULL != dst_size) \
*dst_size = sizeof(typ) *(header.dim); \
out = GNUNET_new_array (header.dim, typ); \
*((void **) dst) = out; \
for (uint32_t i = 0; i < header.dim; i++) \
{ \
HANDLE_ELEMENT (typ, conv, access); \
} \
} while (0)
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.

◆ DEREF

#define DEREF (   typ,
  conv 
)     *(typ *) out = conv (*(typ *) in)

◆ ACCESS_ABS

#define ACCESS_ABS (   typ,
  conv 
)     ((typ *) out)->abs_value_us = conv (*(uint64_t *) in)

◆ ACCESS_REL

#define ACCESS_REL (   typ,
  conv 
)     ((typ *) out)->rel_value_us = conv (*(uint64_t *) in)

◆ ACCESS_TSTMP

#define ACCESS_TSTMP (   typ,
  conv 
)     ((typ *) out)->abs_time.abs_value_us = conv (*(uint64_t *) in)

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

36{
37 struct GNUNET_PQ_ResultSpec rsr;
38
39 rsr = rs;
40 rsr.is_nullable = true;
41 rsr.is_null = is_null;
42 return rsr;
43}
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.

Referenced by handle_results().

Here is the caller graph for this function:

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

56{
57 void **dst = rd;
58
59 (void) cls;
60 if (NULL != *dst)
61 {
62 GNUNET_free (*dst);
63 *dst = NULL;
64 }
65}
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
#define GNUNET_free(ptr)
Wrapper around free.

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

Referenced by GNUNET_PQ_result_spec_variable_size().

Here is the caller graph for this function:

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

88{
89 size_t len;
90 const char *res;
91 void *idst;
92 int fnum;
93
94 (void) cls;
95 *dst_size = 0;
96 *((void **) dst) = NULL;
97
98 fnum = PQfnumber (result,
99 fname);
100 if (fnum < 0)
101 {
102 GNUNET_break (0);
103 return GNUNET_SYSERR;
104 }
105 if (PQgetisnull (result,
106 row,
107 fnum))
108 return GNUNET_NO;
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}
static char * res
Currently read line or NULL on EOF.
static int result
Global testing status.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#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.

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_break, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_variable_size().

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.

132{
133 struct GNUNET_PQ_ResultSpec res = {
135 .cleaner = &clean_varsize_blob,
136 .dst = (void *) (dst),
137 .fname = name,
138 .result_size = sptr
139 };
140
141 return res;
142}
static char * name
Name (label) of the records to list.
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.
GNUNET_PQ_ResultConverter conv
What is the format of the result?

References clean_varsize_blob(), GNUNET_PQ_ResultSpec::conv, 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(), and process_result().

Here is the call graph for this function:
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
rowrow 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 159 of file pq_result_helper.c.

165{
166 size_t len;
167 const char *res;
168 int fnum;
169
170 (void) cls;
171 fnum = PQfnumber (result,
172 fname);
173 if (fnum < 0)
174 {
175 GNUNET_break (0);
177 "Result does not have field %s\n",
178 fname);
179 return GNUNET_SYSERR;
180 }
181 if (PQgetisnull (result,
182 row,
183 fnum))
184 return GNUNET_NO;
185 /* if a field is null, continue but
186 * remember that we now return a different result */
187 len = PQgetlength (result,
188 row,
189 fnum);
190 if (*dst_size != len)
191 {
193 "Expected %u bytes for field `%s', got %u\n",
194 (unsigned int) *dst_size,
195 fname,
196 (unsigned int) len);
197 GNUNET_break (0);
198 return GNUNET_SYSERR;
199 }
200 res = PQgetvalue (result,
201 row,
202 fnum);
203 GNUNET_assert (NULL != res);
204 GNUNET_memcpy (dst,
205 res,
206 len);
207 return GNUNET_OK;
208}
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_ERROR

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_fixed_size().

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

215{
216 struct GNUNET_PQ_ResultSpec res = {
218 .dst = (dst),
220 .fname = name
221 };
222
223 return res;
224}
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...

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

Here is the call graph for this function:

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

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

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

Referenced by GNUNET_PQ_result_spec_rsa_public_key().

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

296{
298
299 (void) cls;
300 if (NULL != *pk)
301 {
303 *pk = NULL;
304 }
305}
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition crypto_rsa.c:268

References GNUNET_CRYPTO_rsa_public_key_free(), pk, and rd.

Referenced by GNUNET_PQ_result_spec_rsa_public_key().

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

311{
312 struct GNUNET_PQ_ResultSpec res = {
314 .cleaner = &clean_rsa_public_key,
315 .dst = (void *) rsa,
316 .fname = name
317 };
318
319 return res;
320}
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.

References clean_rsa_public_key(), GNUNET_PQ_ResultSpec::conv, extract_rsa_public_key(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

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

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 return GNUNET_NO;
362 /* if a field is null, continue but
363 * remember that we now return a different result */
364 len = PQgetlength (result,
365 row,
366 fnum);
367 res = PQgetvalue (result,
368 row,
369 fnum);
371 len);
372 if (NULL == *sig)
373 {
374 GNUNET_break (0);
375 return GNUNET_SYSERR;
376 }
377 return GNUNET_OK;
378}
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.

References GNUNET_break, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_rsa_signature().

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

391{
392 struct GNUNET_CRYPTO_RsaSignature **sig = rd;
393
394 (void) cls;
395 if (NULL != *sig)
396 {
398 *sig = NULL;
399 }
400}
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.

References GNUNET_CRYPTO_rsa_signature_free(), and rd.

Referenced by GNUNET_PQ_result_spec_rsa_signature().

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

406{
407 struct GNUNET_PQ_ResultSpec res = {
409 .cleaner = &clean_rsa_signature,
410 .dst = (void *) sig,
411 .fname = name
412 };
413
414 return res;
415}
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.

References clean_rsa_signature(), GNUNET_PQ_ResultSpec::conv, extract_rsa_signature(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

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

438{
439 char **str = dst;
440 size_t len;
441 const char *res;
442 int fnum;
443
444 (void) cls;
445 *str = NULL;
446 fnum = PQfnumber (result,
447 fname);
448 if (fnum < 0)
449 {
450 GNUNET_break (0);
451 return GNUNET_SYSERR;
452 }
453 if (PQgetisnull (result,
454 row,
455 fnum))
456 return GNUNET_NO;
457 /* if a field is null, continue but
458 * remember that we now return a different result */
459 len = PQgetlength (result,
460 row,
461 fnum);
462 res = PQgetvalue (result,
463 row,
464 fnum);
465 *str = GNUNET_strndup (res,
466 len);
467 if (NULL == *str)
468 {
469 GNUNET_break (0);
470 return GNUNET_SYSERR;
471 }
472 return GNUNET_OK;
473}
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::fname, GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_strndup, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_string().

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

486{
487 char **str = rd;
488
489 (void) cls;
490 if (NULL != *str)
491 {
492 GNUNET_free (*str);
493 *str = NULL;
494 }
495}

References GNUNET_PQ_ResultSpec::cls, GNUNET_free, and rd.

Referenced by GNUNET_PQ_result_spec_string().

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

501{
502 struct GNUNET_PQ_ResultSpec res = {
504 .cleaner = &clean_string,
505 .dst = (void *) dst,
506 .fname = (name)
507 };
508
509 return res;
510}
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.

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

Referenced by check_patch_applied(), and parse_result_call_iterator().

Here is the call graph for this function:
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
rowrow 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 527 of file pq_result_helper.c.

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

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::fname, GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_bool().

Here is the caller graph for this function:

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

572{
573 struct GNUNET_PQ_ResultSpec res = {
574 .conv = &extract_bool,
575 .dst = (void *) dst,
576 .fname = name
577 };
578
579 return res;
580}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst, extract_bool(), GNUNET_PQ_ResultSpec::fname, name, and res.

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

603{
604 struct GNUNET_TIME_Relative *udst = dst;
605 const int64_t *res;
606 int fnum;
607
608 (void) cls;
609 fnum = PQfnumber (result,
610 fname);
611 if (fnum < 0)
612 {
613 GNUNET_break (0);
614 return GNUNET_SYSERR;
615 }
616 if (PQgetisnull (result,
617 row,
618 fnum))
619 return GNUNET_NO;
620 GNUNET_assert (NULL != dst);
621 if (sizeof(struct GNUNET_TIME_Relative) != *dst_size)
622 {
623 GNUNET_break (0);
624 return GNUNET_SYSERR;
625 }
626 if (sizeof(int64_t) !=
627 PQgetlength (result,
628 row,
629 fnum))
630 {
631 GNUNET_break (0);
632 return GNUNET_SYSERR;
633 }
634 res = (int64_t *) PQgetvalue (result,
635 row,
636 fnum);
637 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
639 else
640 udst->rel_value_us = GNUNET_ntohll ((uint64_t) *res);
641 return GNUNET_OK;
642}
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
#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.

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

Referenced by GNUNET_PQ_result_spec_relative_time().

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

648{
649 struct GNUNET_PQ_ResultSpec res = {
651 .dst = (void *) rt,
652 .dst_size = sizeof(*rt),
653 .fname = name
654 };
655
656 return res;
657}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_rel_time(), name, and res.

Here is the call graph for this function:

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

680{
681 struct GNUNET_TIME_Absolute *udst = dst;
682 const int64_t *res;
683 int fnum;
684
685 (void) cls;
686 fnum = PQfnumber (result,
687 fname);
688 if (fnum < 0)
689 {
690 GNUNET_break (0);
691 return GNUNET_SYSERR;
692 }
693 if (PQgetisnull (result,
694 row,
695 fnum))
696 return GNUNET_NO;
697 GNUNET_assert (NULL != dst);
698 if (sizeof(struct GNUNET_TIME_Absolute) != *dst_size)
699 {
700 GNUNET_break (0);
701 return GNUNET_SYSERR;
702 }
703 if (sizeof(int64_t) !=
704 PQgetlength (result,
705 row,
706 fnum))
707 {
708 GNUNET_break (0);
709 return GNUNET_SYSERR;
710 }
711 res = (int64_t *) PQgetvalue (result,
712 row,
713 fnum);
714 if (INT64_MAX == GNUNET_ntohll ((uint64_t) *res))
716 else
717 udst->abs_value_us = GNUNET_ntohll ((uint64_t) *res);
718 return GNUNET_OK;
719}
#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.

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

Referenced by GNUNET_PQ_result_spec_absolute_time().

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

725{
726 struct GNUNET_PQ_ResultSpec res = {
728 .dst = (void *) at,
729 .dst_size = sizeof(*at),
730 .fname = name
731 };
732
733 return res;
734}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_abs_time(), name, and res.

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

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

740{
743 &at->abs_value_us__);
744
745 return res;
746}
#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).

References GNUNET_PQ_result_spec_auto_from_type, name, and res.

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

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

References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_SECONDS, res, and result.

Referenced by extract_timestamp_nbo(), and GNUNET_PQ_result_spec_timestamp().

Here is the call graph for this function:
Here is the caller graph for this function:

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

826{
827 struct GNUNET_PQ_ResultSpec res = {
829 .dst = (void *) at,
830 .dst_size = sizeof(*at),
831 .fname = name
832 };
833
834 return res;
835}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_timestamp(), name, and res.

Here is the call graph for this function:

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

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

References extract_timestamp(), GNUNET_OK, GNUNET_TIME_timestamp_hton(), result, and t.

Referenced by GNUNET_PQ_result_spec_timestamp_nbo().

Here is the call graph for this function:
Here is the caller graph for this function:

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

879{
880 struct GNUNET_PQ_ResultSpec res = {
882 .dst = (void *) at,
883 .dst_size = sizeof(*at),
884 .fname = name
885 };
886
887 return res;
888}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_timestamp_nbo(), name, and res.

Here is the call graph for this function:

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

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

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_uint16().

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

953{
954 struct GNUNET_PQ_ResultSpec res = {
956 .dst = (void *) u16,
957 .dst_size = sizeof(*u16),
958 .fname = name
959 };
960
961 return res;
962}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_uint16(), name, and res.

Here is the call graph for this function:

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

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

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_uint32().

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

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

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_uint32(), name, and res.

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

Here is the call graph for this function:
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
rowrow 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 1053 of file pq_result_helper.c.

1059{
1060 uint64_t *udst = dst;
1061 const uint64_t *res;
1062 int fnum;
1063
1064 (void) cls;
1065 fnum = PQfnumber (result,
1066 fname);
1067 if (fnum < 0)
1068 {
1070 "Field %s missing in result\n",
1071 fname);
1072 GNUNET_break (0);
1073 return GNUNET_SYSERR;
1074 }
1075 if (PQgetisnull (result,
1076 row,
1077 fnum))
1078 return GNUNET_NO;
1079
1080 GNUNET_assert (NULL != dst);
1081 if (sizeof(uint64_t) != *dst_size)
1082 {
1083 GNUNET_break (0);
1084 return GNUNET_SYSERR;
1085 }
1086 if (sizeof(uint64_t) !=
1087 PQgetlength (result,
1088 row,
1089 fnum))
1090 {
1091 GNUNET_break (0);
1093 "Got length %u for field `%s'\n",
1094 PQgetlength (result,
1095 row,
1096 fnum),
1097 fname);
1098 return GNUNET_SYSERR;
1099 }
1100 res = (uint64_t *) PQgetvalue (result,
1101 row,
1102 fnum);
1103 *udst = GNUNET_ntohll (*res);
1104 return GNUNET_OK;
1105}

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_uint64().

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

1111{
1112 struct GNUNET_PQ_ResultSpec res = {
1113 .conv = &extract_uint64,
1114 .dst = (void *) u64,
1115 .dst_size = sizeof(*u64),
1116 .fname = name
1117 };
1118
1119 return res;
1120}
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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_uint64(), name, and res.

Referenced by parse_result_call_iterator(), postgres_plugin_del(), postgres_plugin_estimate_size(), and process_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extract_int64()

static enum GNUNET_GenericReturnValue extract_int64 ( 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
rowrow 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 1137 of file pq_result_helper.c.

1143{
1144 int64_t *udst = dst;
1145 const int64_t *res;
1146 int fnum;
1147
1148 (void) cls;
1149 fnum = PQfnumber (result,
1150 fname);
1151 if (fnum < 0)
1152 {
1154 "Field %s missing in result\n",
1155 fname);
1156 GNUNET_break (0);
1157 return GNUNET_SYSERR;
1158 }
1159 if (PQgetisnull (result,
1160 row,
1161 fnum))
1162 return GNUNET_NO;
1163
1164 GNUNET_assert (NULL != dst);
1165 if (sizeof(int64_t) != *dst_size)
1166 {
1167 GNUNET_break (0);
1168 return GNUNET_SYSERR;
1169 }
1170 if (sizeof(int64_t) !=
1171 PQgetlength (result,
1172 row,
1173 fnum))
1174 {
1175 GNUNET_break (0);
1177 "Got length %u for field `%s'\n",
1178 PQgetlength (result,
1179 row,
1180 fnum),
1181 fname);
1182 return GNUNET_SYSERR;
1183 }
1184 res = (int64_t *) PQgetvalue (result,
1185 row,
1186 fnum);
1187 *udst = GNUNET_ntohll (*res);
1188 return GNUNET_OK;
1189}

References GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::dst, GNUNET_PQ_ResultSpec::dst_size, GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, res, and result.

Referenced by GNUNET_PQ_result_spec_int64().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_int64()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_int64 ( const char *  name,
int64_t *  i64 
)

int64_t expected.

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

Definition at line 1193 of file pq_result_helper.c.

1195{
1196 struct GNUNET_PQ_ResultSpec res = {
1197 .conv = &extract_int64,
1198 .dst = (void *) i64,
1199 .dst_size = sizeof(*i64),
1200 .fname = name
1201 };
1202
1203 return res;
1204}
static enum GNUNET_GenericReturnValue extract_int64(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.

References GNUNET_PQ_ResultSpec::conv, GNUNET_PQ_ResultSpec::dst_size, extract_int64(), name, and res.

Here is the call graph for this function:

◆ extract_array_generic()

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

Extract data from a Postgres database result as array of a specific type from row row.

The type information and optionally additional out-parameters are given in cls which is of type array_result_cls.

Parameters
clsclosure of type array_result_cls
resultwhere to extract data from
rowrow 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 1255 of file pq_result_helper.c.

1262{
1263 const struct array_result_cls *info = cls;
1264 int data_sz;
1265 char *data;
1266 void *out = NULL;
1267 struct pq_array_header header;
1268 int col_num;
1269
1270 GNUNET_assert (NULL != dst);
1271 *((void **) dst) = NULL;
1272
1273#define FAIL_IF(cond) \
1274 do { \
1275 if ((cond)) \
1276 { \
1277 GNUNET_break (! (cond)); \
1278 goto FAIL; \
1279 } \
1280 } while (0)
1281
1282 col_num = PQfnumber (result, fname);
1283 FAIL_IF (0 > col_num);
1284
1285 data_sz = PQgetlength (result, row, col_num);
1286 FAIL_IF (0 > data_sz);
1287 data = PQgetvalue (result, row, col_num);
1288 if (sizeof(header) > (size_t) data_sz)
1289 {
1290 uint32_t ndim;
1291
1292 /* data_sz is shorter than header if the
1293 array length is 0, in which case ndim is 0! */
1294 FAIL_IF (sizeof(uint32_t) > (size_t) data_sz);
1295 memcpy (&ndim,
1296 data,
1297 sizeof (ndim));
1298 FAIL_IF (0 != ndim);
1299 *info->num = 0;
1300 return GNUNET_OK;
1301 }
1302 FAIL_IF (sizeof(header) > (size_t) data_sz);
1303 FAIL_IF (NULL == data);
1304
1305 {
1306 struct pq_array_header *h =
1307 (struct pq_array_header *) data;
1308
1309 header.ndim = ntohl (h->ndim);
1310 header.has_nulls = ntohl (h->has_nulls);
1311 header.oid = ntohl (h->oid);
1312 header.dim = ntohl (h->dim);
1313 header.lbound = ntohl (h->lbound);
1314
1315 FAIL_IF (1 != header.ndim);
1316 FAIL_IF (INT_MAX <= header.dim);
1317 FAIL_IF ((0 != header.has_nulls) && ! info->allow_nulls);
1318 FAIL_IF (1 != header.lbound);
1319 FAIL_IF (info->oid != header.oid);
1320 }
1321
1322 if (NULL != info->num)
1323 *info->num = header.dim;
1324
1325 /* Prepare the array of bools, marking NULL elements */
1326 if (info->allow_nulls)
1327 *info->is_nulls = GNUNET_new_array (header.dim, bool);
1328
1329 {
1330 char *in = data + sizeof(header);
1331
1332#define HANDLE_ELEMENT(typ, conv, access) \
1333 do { \
1334 int32_t sz = ntohl (*(int32_t *) in); \
1335\
1336 in += sizeof(uint32_t); \
1337 if (-1 != sz) \
1338 { \
1339 FAIL_IF (sz != sizeof(typ)); \
1340 access (typ, conv); \
1341 in += sz; \
1342 } \
1343 else \
1344 { \
1345 FAIL_IF (! info->allow_nulls); \
1346 (*info->is_nulls)[i] = true; \
1347 } \
1348\
1349 out += sizeof(typ); \
1350 } while (0)
1351
1352#define HANDLE_ARRAY(typ, conv, access) \
1353 do { \
1354 if (NULL != dst_size) \
1355 *dst_size = sizeof(typ) *(header.dim); \
1356 out = GNUNET_new_array (header.dim, typ); \
1357 *((void **) dst) = out; \
1358 for (uint32_t i = 0; i < header.dim; i++) \
1359 { \
1360 HANDLE_ELEMENT (typ, conv, access); \
1361 } \
1362 } while (0)
1363
1364#define DEREF(typ, conv) \
1365 *(typ *) out = conv (*(typ *) in)
1366
1367#define ACCESS_ABS(typ, conv) \
1368 ((typ *) out)->abs_value_us = conv (*(uint64_t *) in)
1369
1370#define ACCESS_REL(typ, conv) \
1371 ((typ *) out)->rel_value_us = conv (*(uint64_t *) in)
1372
1373#define ACCESS_TSTMP(typ, conv) \
1374 ((typ *) out)->abs_time.abs_value_us = conv (*(uint64_t *) in)
1375
1376 switch (info->typ)
1377 {
1378 case array_of_bool:
1379 HANDLE_ARRAY (bool, /* no conv */, DEREF);
1380 break;
1381
1382 case array_of_uint16:
1383 HANDLE_ARRAY (uint16_t, ntohs, DEREF);
1384 break;
1385
1386 case array_of_uint32:
1387 HANDLE_ARRAY (uint32_t, ntohl, DEREF);
1388 break;
1389
1390 case array_of_uint64:
1391 HANDLE_ARRAY (uint64_t, GNUNET_ntohll, DEREF);
1392 break;
1393
1394 case array_of_abs_time:
1397 ACCESS_ABS);
1398 break;
1399
1400 case array_of_rel_time:
1403 ACCESS_REL);
1404 break;
1405
1406 case array_of_timestamp:
1409 ACCESS_TSTMP);
1410 break;
1411
1412 case array_of_byte:
1413 if (0 == info->same_size)
1414 *info->sizes = GNUNET_new_array (header.dim, size_t);
1415 /* fallthrough */
1416 case array_of_string:
1417 {
1418 size_t total = 0;
1419 bool is_string = (array_of_string == info->typ);
1420
1421 /* first, calculate total size required for allocation */
1422 {
1423 char *ptr = data + sizeof(header);
1424 for (uint32_t i = 0; i < header.dim; i++)
1425 {
1426 int32_t sz;
1427
1428 sz = ntohl (*(int32_t *) ptr);
1429 if (-1 == sz) /* signifies NULL entry */
1430 {
1431 FAIL_IF (! info->allow_nulls);
1432 (*info->is_nulls)[i] = true;
1433 sz = 0;
1434 }
1435 else
1436 FAIL_IF (0 > sz);
1437
1438 total += sz + (is_string ? 1 : 0);
1439 ptr += sizeof(int32_t);
1440 ptr += sz;
1441
1442 if ((! is_string) &&
1443 (0 == info->same_size))
1444 (*info->sizes)[i] = sz;
1445
1446 FAIL_IF ((0 != info->same_size) &&
1447 (sz != info->same_size));
1448 FAIL_IF (total < sz);
1449 }
1450 }
1451 FAIL_IF ((! info->allow_nulls) && (0 == total));
1452
1453 if (NULL != dst_size)
1454 *dst_size = total;
1455
1456 out = GNUNET_malloc (total);
1457 *((void **) dst) = out;
1458
1459 /* copy data */
1460 for (uint32_t i = 0; i < header.dim; i++)
1461 {
1462 int32_t sz = ntohl (*(int32_t *) in);
1463
1464 in += sizeof(uint32_t);
1465 if (-1 == sz)
1466 sz = 0;
1467 else
1468 GNUNET_memcpy (out, in, sz);
1469
1470 in += sz;
1471 out += sz;
1472 out += (is_string) ? 1 : 0;
1473 }
1474 break;
1475 }
1476 default:
1477 FAIL_IF (1 != 0);
1478 }
1479 }
1480
1481 return GNUNET_OK;
1482
1483FAIL:
1484 GNUNET_free (*(void **) dst);
1485 return GNUNET_SYSERR;
1486#undef FAIL_IF
1487#undef DEREF
1488#undef ACCESS_ABS
1489#undef ACCESS_REL
1490#undef ACCESS_TSTMP
1491#undef HANDLE_ARRAY
1492#undef HANDLE_ELEMENT
1493}
#define INT_MAX
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition gnunet-arm.c:98
static char * data
The data to insert into the dht.
uint32_t ndim
@ array_of_byte
Definition pq.h:153
@ array_of_uint32
Definition pq.h:151
@ array_of_string
Definition pq.h:154
@ array_of_rel_time
Definition pq.h:156
@ array_of_uint16
Definition pq.h:150
@ array_of_uint64
Definition pq.h:152
@ array_of_abs_time
Definition pq.h:155
@ array_of_timestamp
Definition pq.h:157
@ array_of_bool
Definition pq.h:149
#define DEREF(typ, conv)
#define FAIL_IF(cond)
#define ACCESS_ABS(typ, conv)
#define ACCESS_REL(typ, conv)
#define HANDLE_ARRAY(typ, conv, access)
#define ACCESS_TSTMP(typ, conv)
Closure for the array result specifications.
The header for a postgresql array in binary format.
Definition pq.h:167

References ACCESS_ABS, ACCESS_REL, ACCESS_TSTMP, array_of_abs_time, array_of_bool, array_of_byte, array_of_rel_time, array_of_string, array_of_timestamp, array_of_uint16, array_of_uint32, array_of_uint64, data, DEREF, pq_array_header::dim, FAIL, FAIL_IF, GNUNET_assert, GNUNET_free, GNUNET_malloc, GNUNET_memcpy, GNUNET_new_array, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, h, HANDLE_ARRAY, pq_array_header::has_nulls, info, INT_MAX, pq_array_header::lbound, ndim, pq_array_header::ndim, pq_array_header::oid, and result.

Referenced by GNUNET_PQ_result_spec_array_abs_time(), GNUNET_PQ_result_spec_array_allow_nulls(), GNUNET_PQ_result_spec_array_bool(), GNUNET_PQ_result_spec_array_fixed_size(), GNUNET_PQ_result_spec_array_rel_time(), GNUNET_PQ_result_spec_array_string(), GNUNET_PQ_result_spec_array_timestamp(), GNUNET_PQ_result_spec_array_uint16(), GNUNET_PQ_result_spec_array_uint32(), GNUNET_PQ_result_spec_array_uint64(), and GNUNET_PQ_result_spec_array_variable_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_array_allow_nulls()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_allow_nulls ( struct GNUNET_PQ_ResultSpec  rs,
bool **  is_nulls 
)

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

Parameters
rsresult spec entry to modify, MUST be one for the array types
[out]is_nullslocation where to put the array of bools, whose elements will be set to 'true' if the value was indeed NULL, or to 'false' if the value was non-NULL. This parameter MUST NOT be NULL itself. The length of the allocated array will be equal to the length of the result for the values in rs.
Returns
array entry for the result specification to use

Definition at line 1497 of file pq_result_helper.c.

1500{
1501 struct GNUNET_PQ_ResultSpec rsr;
1502 struct array_result_cls *info = rs.cls;
1503
1505 GNUNET_assert (NULL != is_nulls);
1506 info->allow_nulls = true;
1507 info->is_nulls = is_nulls;
1508
1509 rsr = rs;
1510 return rsr;
1511}
static enum GNUNET_GenericReturnValue extract_array_generic(void *cls, PGresult *result, int row, const char *fname, size_t *dst_size, void *dst)
Extract data from a Postgres database result as array of a specific type from row row.
void * cls
Closure for conv and cleaner.

References extract_array_generic(), GNUNET_assert, info, and array_result_cls::is_nulls.

Here is the call graph for this function:

◆ array_cleanup()

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

Cleanup of the data and closure of an array spec.

Definition at line 1518 of file pq_result_helper.c.

1520{
1521
1522 struct array_result_cls *info = cls;
1523 void **dst = rd;
1524
1525 if ((array_of_byte == info->typ) &&
1526 (0 == info->same_size) &&
1527 (NULL != info->sizes))
1528 GNUNET_free (*(info->sizes));
1529
1530 if (info->allow_nulls)
1531 GNUNET_free (*info->is_nulls);
1532
1533 GNUNET_free (cls);
1534 GNUNET_free (*dst);
1535 *dst = NULL;
1536}

References array_of_byte, GNUNET_free, info, and rd.

Referenced by GNUNET_PQ_result_spec_array_abs_time(), GNUNET_PQ_result_spec_array_bool(), GNUNET_PQ_result_spec_array_fixed_size(), GNUNET_PQ_result_spec_array_rel_time(), GNUNET_PQ_result_spec_array_string(), GNUNET_PQ_result_spec_array_timestamp(), GNUNET_PQ_result_spec_array_uint16(), GNUNET_PQ_result_spec_array_uint32(), GNUNET_PQ_result_spec_array_uint64(), and GNUNET_PQ_result_spec_array_variable_size().

Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_array_bool()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_bool ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
bool **  bools 
)

array of bool expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array bools.
[out]boolspointer to where to store the result, an array of num bool's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1540 of file pq_result_helper.c.

1545{
1546 struct array_result_cls *info =
1548
1549 info->num = num;
1550 info->typ = array_of_bool;
1553 "bool",
1554 &info->oid));
1555
1556 {
1557 struct GNUNET_PQ_ResultSpec res = {
1559 .cleaner = array_cleanup,
1560 .dst = (void *) dst,
1561 .fname = name,
1562 .cls = info
1563 };
1564 return res;
1565 }
1566}
static struct GNUNET_FS_DirectoryBuilder * db
enum GNUNET_GenericReturnValue GNUNET_PQ_get_oid_by_name(struct GNUNET_PQ_Context *db, const char *name, Oid *oid)
Returns the oid for a given datatype by name.
Definition pq_connect.c:461
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void array_cleanup(void *cls, void *rd)
Cleanup of the data and closure of an array spec.

References array_cleanup(), array_of_bool, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_uint16()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint16 ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
uint16_t **  dst 
)

array of uint16_t expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u16s.
[out]dstpointer to where to store the an array of num uint16_t's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1570 of file pq_result_helper.c.

1575{
1576 struct array_result_cls *info =
1578
1579 info->num = num;
1580 info->typ = array_of_uint16;
1583 "int2",
1584 &info->oid));
1585
1586 {
1587 struct GNUNET_PQ_ResultSpec res = {
1589 .cleaner = array_cleanup,
1590 .dst = (void *) dst,
1591 .fname = name,
1592 .cls = info
1593 };
1594 return res;
1595 }
1596}

References array_cleanup(), array_of_uint16, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_uint32()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint32 ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
uint32_t **  dst 
)

array of uint32_t expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u32s.
[out]dstpointer to where to store the array of num uint32_t's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1600 of file pq_result_helper.c.

1605{
1606 struct array_result_cls *info =
1608
1609 info->num = num;
1610 info->typ = array_of_uint32;
1613 "int4",
1614 &info->oid));
1615
1616 {
1617 struct GNUNET_PQ_ResultSpec res = {
1619 .cleaner = array_cleanup,
1620 .dst = (void *) dst,
1621 .fname = name,
1622 .cls = info
1623 };
1624 return res;
1625 }
1626}

References array_cleanup(), array_of_uint32, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_uint64()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_uint64 ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
uint64_t **  dst 
)

array of uint64_t expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num uint64_t's. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1630 of file pq_result_helper.c.

1635{
1636 struct array_result_cls *info =
1638
1639 info->num = num;
1640 info->typ = array_of_uint64;
1643 "int8",
1644 &info->oid));
1645
1646 {struct GNUNET_PQ_ResultSpec res = {
1648 .cleaner = array_cleanup,
1649 .dst = (void *) dst,
1650 .fname = name,
1651 .cls = info
1652 };
1653 return res;}
1654}

References array_cleanup(), array_of_uint64, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_abs_time()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_abs_time ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
struct GNUNET_TIME_Absolute **  dst 
)

array of absolute time expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num absolute time. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1658 of file pq_result_helper.c.

1663{
1664 struct array_result_cls *info =
1666
1667 info->num = num;
1668 info->typ = array_of_abs_time;
1671 "int8",
1672 &info->oid));
1673
1674 {struct GNUNET_PQ_ResultSpec res = {
1676 .cleaner = array_cleanup,
1677 .dst = (void *) dst,
1678 .fname = name,
1679 .cls = info
1680 };
1681 return res;}
1682}

References array_cleanup(), array_of_abs_time, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_rel_time()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_rel_time ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
struct GNUNET_TIME_Relative **  dst 
)

array of relative time expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num relate time. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1686 of file pq_result_helper.c.

1691{
1692 struct array_result_cls *info =
1694
1695 info->num = num;
1696 info->typ = array_of_rel_time;
1699 "int8",
1700 &info->oid));
1701
1702 {
1703 struct GNUNET_PQ_ResultSpec res = {
1705 .cleaner = array_cleanup,
1706 .dst = (void *) dst,
1707 .fname = name,
1708 .cls = info
1709 };
1710 return res;
1711 }
1712}

References array_cleanup(), array_of_rel_time, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_timestamp()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_timestamp ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
struct GNUNET_TIME_Timestamp **  dst 
)

array of relative time expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements in the array u64s.
[out]dstpointer to where to store the array of num timestamps. Allocated by the function, MUST be freed with GNUNET_free.
Returns
array entry for the result specification to use

Definition at line 1716 of file pq_result_helper.c.

1721{
1722 struct array_result_cls *info =
1724
1725 info->num = num;
1726 info->typ = array_of_timestamp;
1729 "int8",
1730 &info->oid));
1731
1732 {
1733 struct GNUNET_PQ_ResultSpec res = {
1735 .cleaner = array_cleanup,
1736 .dst = (void *) dst,
1737 .fname = name,
1738 .cls = info
1739 };
1740 return res;
1741 }
1742}

References array_cleanup(), array_of_timestamp, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_variable_size()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_variable_size ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
size_t **  sizes,
void **  dst 
)

Array of variable-size result expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements
[out]sizeswhere to store the num size's of byte-buffers in dst
[out]dstwhere to store the continuous array of num byte-buffers , allocated
Returns
array entry for the result specification to use

Definition at line 1746 of file pq_result_helper.c.

1752{
1753 struct array_result_cls *info =
1755
1756 info->num = num;
1757 info->sizes = sizes;
1758 info->typ = array_of_byte;
1761 "bytea",
1762 &info->oid));
1763
1764 {
1765 struct GNUNET_PQ_ResultSpec res = {
1767 .cleaner = array_cleanup,
1768 .dst = (void *) dst,
1769 .fname = name,
1770 .cls = info
1771 };
1772 return res;
1773 }
1774}

References array_cleanup(), array_of_byte, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, res, and array_result_cls::sizes.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_fixed_size()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_fixed_size ( struct GNUNET_PQ_Context db,
const char *  name,
size_t  size,
size_t *  num,
void **  dst 
)

Array of fixed-size result expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
sizenumber of bytes expected in each element of dst
[out]numwhere to store the number of elements
[out]dstwhere to store the results, an continuous array of fixed-size elements
Returns
array entry for the result specification to use

Definition at line 1778 of file pq_result_helper.c.

1784{
1785 struct array_result_cls *info =
1787
1788 info->num = num;
1789 info->same_size = size;
1790 info->typ = array_of_byte;
1793 "bytea",
1794 &info->oid));
1795
1796 {
1797 struct GNUNET_PQ_ResultSpec res = {
1799 .cleaner = array_cleanup,
1800 .dst = (void *) dst,
1801 .fname = name,
1802 .cls = info
1803 };
1804 return res;
1805 }
1806}
static unsigned int size
Size of the "table".
Definition peer.c:68

References array_cleanup(), array_of_byte, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, res, and size.

Here is the call graph for this function:

◆ GNUNET_PQ_result_spec_array_string()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_array_string ( struct GNUNET_PQ_Context db,
const char *  name,
size_t *  num,
char **  dst 
)

Array of 0-terminated strings expected.

Parameters
dbDatabase context, needed for OID lookup for the correct type
namename of the field in the table
[out]numwhere to store the number of elements
[out]dstwhere to store the allocated continuous array of num 0-terminated strings
Returns
array entry for the result specification to use

Definition at line 1810 of file pq_result_helper.c.

1815{
1816 struct array_result_cls *info =
1818
1819 info->num = num;
1820 info->typ = array_of_string;
1823 "text",
1824 &info->oid));
1825
1826 {
1827 struct GNUNET_PQ_ResultSpec res = {
1829 .cleaner = array_cleanup,
1830 .dst = (void *) dst,
1831 .fname = name,
1832 .cls = info
1833 };
1834 return res;
1835 }
1836}

References array_cleanup(), array_of_string, GNUNET_PQ_ResultSpec::cls, GNUNET_PQ_ResultSpec::conv, db, GNUNET_PQ_ResultSpec::dst, extract_array_generic(), GNUNET_PQ_ResultSpec::fname, GNUNET_assert, GNUNET_new, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), info, name, array_result_cls::num, and res.

Here is the call graph for this function:

◆ extract_blind_sign_pub()

static enum GNUNET_GenericReturnValue extract_blind_sign_pub ( 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
rowthe row 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 1853 of file pq_result_helper.c.

1859{
1860 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1862 size_t len;
1863 const char *res;
1864 int fnum;
1865 uint32_t be;
1866
1867 (void) cls;
1868 (void) dst_size;
1869 fnum = PQfnumber (result,
1870 fname);
1871 if (fnum < 0)
1872 {
1873 GNUNET_break (0);
1874 return GNUNET_SYSERR;
1875 }
1876 if (PQgetisnull (result,
1877 row,
1878 fnum))
1879 return GNUNET_NO;
1880
1881 /* if a field is null, continue but
1882 * remember that we now return a different result */
1883 len = PQgetlength (result,
1884 row,
1885 fnum);
1886 res = PQgetvalue (result,
1887 row,
1888 fnum);
1889 if (len < sizeof (be))
1890 {
1891 GNUNET_break (0);
1892 return GNUNET_SYSERR;
1893 }
1894 GNUNET_memcpy (&be,
1895 res,
1896 sizeof (be));
1897 res += sizeof (be);
1898 len -= sizeof (be);
1900 tmp->cipher = ntohl (be);
1901 tmp->rc = 1;
1902 switch (tmp->cipher)
1903 {
1905 break;
1909 len);
1910 if (NULL == tmp->details.rsa_public_key)
1911 {
1912 GNUNET_break (0);
1913 GNUNET_free (tmp);
1914 return GNUNET_SYSERR;
1915 }
1917 len,
1918 &tmp->pub_key_hash);
1919 *bpk = tmp;
1920 return GNUNET_OK;
1922 if (sizeof (tmp->details.cs_public_key) != len)
1923 {
1924 GNUNET_break (0);
1925 GNUNET_free (tmp);
1926 return GNUNET_SYSERR;
1927 }
1929 res,
1930 len);
1932 len,
1933 &tmp->pub_key_hash);
1934 *bpk = tmp;
1935 return GNUNET_OK;
1936 }
1937 GNUNET_break (0);
1938 GNUNET_free (tmp);
1939 return GNUNET_SYSERR;
1940}
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
Type of public signing keys for blind signatures.
union GNUNET_CRYPTO_BlindSignPublicKey::@16 details
Details, depending on cipher.
unsigned int rc
Reference counter.
struct GNUNET_HashCode pub_key_hash
Hash of the public key.
struct GNUNET_CRYPTO_CsPublicKey cs_public_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
struct GNUNET_CRYPTO_RsaPublicKey * rsa_public_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_BlindSignPublicKey::cipher, GNUNET_CRYPTO_BlindSignPublicKey::cs_public_key, GNUNET_CRYPTO_BlindSignPublicKey::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_rsa_public_key_decode(), GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_BlindSignPublicKey::pub_key_hash, GNUNET_CRYPTO_BlindSignPublicKey::rc, res, result, and GNUNET_CRYPTO_BlindSignPublicKey::rsa_public_key.

Referenced by GNUNET_PQ_result_spec_blind_sign_pub().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_blind_sign_pub()

static void clean_blind_sign_pub ( 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 1951 of file pq_result_helper.c.

1953{
1955
1956 (void) cls;
1957 if (NULL != *pub)
1958 {
1960 *pub = NULL;
1961 }
1962}
static struct GNUNET_CRYPTO_EddsaPublicKey pub
void GNUNET_CRYPTO_blind_sign_pub_decref(struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub)
Decrement reference counter of a bsign_pub, and free it if it reaches zero.

References GNUNET_CRYPTO_blind_sign_pub_decref(), pub, and rd.

Referenced by GNUNET_PQ_result_spec_blind_sign_pub().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_blind_sign_pub()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_pub ( const char *  name,
struct GNUNET_CRYPTO_BlindSignPublicKey **  public_key 
)

Blind sign public key expected.

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

Definition at line 1966 of file pq_result_helper.c.

1969{
1970 struct GNUNET_PQ_ResultSpec res = {
1972 .cleaner = &clean_blind_sign_pub,
1973 .dst = (void *) pub,
1974 .fname = name
1975 };
1976
1977 return res;
1978}
static void clean_blind_sign_pub(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static enum GNUNET_GenericReturnValue extract_blind_sign_pub(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.

References clean_blind_sign_pub(), GNUNET_PQ_ResultSpec::conv, extract_blind_sign_pub(), GNUNET_PQ_ResultSpec::fname, name, pub, and res.

Here is the call graph for this function:

◆ extract_blind_sign_priv()

static enum GNUNET_GenericReturnValue extract_blind_sign_priv ( 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
rowthe row 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 1995 of file pq_result_helper.c.

2001{
2002 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
2004 size_t len;
2005 const char *res;
2006 int fnum;
2007 uint32_t be;
2008
2009 (void) cls;
2010 (void) dst_size;
2011 fnum = PQfnumber (result,
2012 fname);
2013 if (fnum < 0)
2014 {
2015 GNUNET_break (0);
2016 return GNUNET_SYSERR;
2017 }
2018 if (PQgetisnull (result,
2019 row,
2020 fnum))
2021 return GNUNET_NO;
2022
2023 /* if a field is null, continue but
2024 * remember that we now return a different result */
2025 len = PQgetlength (result,
2026 row,
2027 fnum);
2028 res = PQgetvalue (result,
2029 row,
2030 fnum);
2031 if (len < sizeof (be))
2032 {
2033 GNUNET_break (0);
2034 return GNUNET_SYSERR;
2035 }
2036 GNUNET_memcpy (&be,
2037 res,
2038 sizeof (be));
2039 res += sizeof (be);
2040 len -= sizeof (be);
2042 tmp->cipher = ntohl (be);
2043 tmp->rc = 1;
2044 switch (tmp->cipher)
2045 {
2047 break;
2051 len);
2052 if (NULL == tmp->details.rsa_private_key)
2053 {
2054 GNUNET_break (0);
2055 GNUNET_free (tmp);
2056 return GNUNET_SYSERR;
2057 }
2058 *bpk = tmp;
2059 return GNUNET_OK;
2061 if (sizeof (tmp->details.cs_private_key) != len)
2062 {
2063 GNUNET_break (0);
2064 GNUNET_free (tmp);
2065 return GNUNET_SYSERR;
2066 }
2068 res,
2069 len);
2070 *bpk = tmp;
2071 return GNUNET_OK;
2072 }
2073 GNUNET_break (0);
2074 GNUNET_free (tmp);
2075 return GNUNET_SYSERR;
2076}
struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_decode(const void *buf, size_t buf_size)
Decode the private key from the data-format back to the "normal", internal format.
Definition crypto_rsa.c:204
Type of private signing keys for blind signing.
struct GNUNET_CRYPTO_CsPrivateKey cs_private_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_RsaPrivateKey * rsa_private_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
union GNUNET_CRYPTO_BlindSignPrivateKey::@17 details
Details, depending on cipher.

References GNUNET_CRYPTO_BlindSignPrivateKey::cipher, GNUNET_CRYPTO_BlindSignPrivateKey::cs_private_key, GNUNET_CRYPTO_BlindSignPrivateKey::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_private_key_decode(), GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_BlindSignPrivateKey::rc, res, result, and GNUNET_CRYPTO_BlindSignPrivateKey::rsa_private_key.

Referenced by GNUNET_PQ_result_spec_blind_sign_priv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_blind_sign_priv()

static void clean_blind_sign_priv ( 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 2087 of file pq_result_helper.c.

2089{
2090 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2091
2092 (void) cls;
2093 if (NULL != *priv)
2094 {
2096 *priv = NULL;
2097 }
2098}
void GNUNET_CRYPTO_blind_sign_priv_decref(struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv)
Decrement reference counter of a bsign_priv, and free it if it reaches zero.

References GNUNET_CRYPTO_blind_sign_priv_decref(), and rd.

Referenced by GNUNET_PQ_result_spec_blind_sign_priv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_blind_sign_priv()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blind_sign_priv ( const char *  name,
struct GNUNET_CRYPTO_BlindSignPrivateKey **  private_key 
)

Blind sign private key expected.

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

Definition at line 2102 of file pq_result_helper.c.

2105{
2106 struct GNUNET_PQ_ResultSpec res = {
2108 .cleaner = &clean_blind_sign_priv,
2109 .dst = (void *) priv,
2110 .fname = name
2111 };
2112
2113 return res;
2114}
static enum GNUNET_GenericReturnValue extract_blind_sign_priv(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_blind_sign_priv(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

References clean_blind_sign_priv(), GNUNET_PQ_ResultSpec::conv, extract_blind_sign_priv(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

◆ extract_blinded_sig()

static enum GNUNET_GenericReturnValue extract_blinded_sig ( 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
rowthe row 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 2131 of file pq_result_helper.c.

2137{
2138 struct GNUNET_CRYPTO_BlindedSignature **sig = dst;
2140 size_t len;
2141 const char *res;
2142 int fnum;
2143 uint32_t be[2];
2144
2145 (void) cls;
2146 (void) dst_size;
2147 fnum = PQfnumber (result,
2148 fname);
2149 if (fnum < 0)
2150 {
2151 GNUNET_break (0);
2152 return GNUNET_SYSERR;
2153 }
2154 if (PQgetisnull (result,
2155 row,
2156 fnum))
2157 return GNUNET_NO;
2158
2159 /* if a field is null, continue but
2160 * remember that we now return a different result */
2161 len = PQgetlength (result,
2162 row,
2163 fnum);
2164 res = PQgetvalue (result,
2165 row,
2166 fnum);
2167 if (len < sizeof (be))
2168 {
2169 GNUNET_break (0);
2170 return GNUNET_SYSERR;
2171 }
2172 GNUNET_memcpy (&be,
2173 res,
2174 sizeof (be));
2175 if (0x01 != ntohl (be[1])) /* magic marker: blinded */
2176 {
2177 GNUNET_break (0);
2178 return GNUNET_SYSERR;
2179 }
2180 res += sizeof (be);
2181 len -= sizeof (be);
2183 bs->rc = 1;
2184 bs->cipher = ntohl (be[0]);
2185 switch (bs->cipher)
2186 {
2188 break;
2192 len);
2193 if (NULL == bs->details.blinded_rsa_signature)
2194 {
2195 GNUNET_break (0);
2196 GNUNET_free (bs);
2197 return GNUNET_SYSERR;
2198 }
2199 *sig = bs;
2200 return GNUNET_OK;
2202 if (sizeof (bs->details.blinded_cs_answer) != len)
2203 {
2204 GNUNET_break (0);
2205 GNUNET_free (bs);
2206 return GNUNET_SYSERR;
2207 }
2209 res,
2210 len);
2211 *sig = bs;
2212 return GNUNET_OK;
2213 }
2214 GNUNET_break (0);
2215 GNUNET_free (bs);
2216 return GNUNET_SYSERR;
2217}
Type for blinded signatures.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_BlindedSignature::rc, res, and result.

Referenced by GNUNET_PQ_result_spec_blinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_blinded_sig()

static void clean_blinded_sig ( 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 2228 of file pq_result_helper.c.

2230{
2231 struct GNUNET_CRYPTO_BlindedSignature **b_sig = rd;
2232
2233 (void) cls;
2235}
void GNUNET_CRYPTO_blinded_sig_decref(struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
Decrement reference counter of a blind_sig, and free it if it reaches zero.

References GNUNET_CRYPTO_blinded_sig_decref(), and rd.

Referenced by GNUNET_PQ_result_spec_blinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_blinded_sig()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_blinded_sig ( const char *  name,
struct GNUNET_CRYPTO_BlindedSignature **  b_sig 
)

Blinded signature expected.

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

Definition at line 2239 of file pq_result_helper.c.

2242{
2243 struct GNUNET_PQ_ResultSpec res = {
2245 .cleaner = &clean_blinded_sig,
2246 .dst = (void *) b_sig,
2247 .fname = name
2248 };
2249
2250 return res;
2251}
static void clean_blinded_sig(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.
static enum GNUNET_GenericReturnValue extract_blinded_sig(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.

References clean_blinded_sig(), GNUNET_PQ_ResultSpec::conv, extract_blinded_sig(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function:

◆ extract_unblinded_sig()

static enum GNUNET_GenericReturnValue extract_unblinded_sig ( 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
rowthe row 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 2268 of file pq_result_helper.c.

2274{
2275 struct GNUNET_CRYPTO_UnblindedSignature **sig = dst;
2277 size_t len;
2278 const char *res;
2279 int fnum;
2280 uint32_t be[2];
2281
2282 (void) cls;
2283 (void) dst_size;
2284 fnum = PQfnumber (result,
2285 fname);
2286 if (fnum < 0)
2287 {
2288 GNUNET_break (0);
2289 return GNUNET_SYSERR;
2290 }
2291 if (PQgetisnull (result,
2292 row,
2293 fnum))
2294 return GNUNET_NO;
2295
2296 /* if a field is null, continue but
2297 * remember that we now return a different result */
2298 len = PQgetlength (result,
2299 row,
2300 fnum);
2301 res = PQgetvalue (result,
2302 row,
2303 fnum);
2304 if (len < sizeof (be))
2305 {
2306 GNUNET_break (0);
2307 return GNUNET_SYSERR;
2308 }
2309 GNUNET_memcpy (&be,
2310 res,
2311 sizeof (be));
2312 if (0x00 != ntohl (be[1])) /* magic marker: unblinded */
2313 {
2314 GNUNET_break (0);
2315 return GNUNET_SYSERR;
2316 }
2317 res += sizeof (be);
2318 len -= sizeof (be);
2320 ubs->rc = 1;
2321 ubs->cipher = ntohl (be[0]);
2322 switch (ubs->cipher)
2323 {
2325 break;
2329 len);
2330 if (NULL == ubs->details.rsa_signature)
2331 {
2332 GNUNET_break (0);
2333 GNUNET_free (ubs);
2334 return GNUNET_SYSERR;
2335 }
2336 *sig = ubs;
2337 return GNUNET_OK;
2339 if (sizeof (ubs->details.cs_signature) != len)
2340 {
2341 GNUNET_break (0);
2342 GNUNET_free (ubs);
2343 return GNUNET_SYSERR;
2344 }
2346 res,
2347 len);
2348 *sig = ubs;
2349 return GNUNET_OK;
2350 }
2351 GNUNET_break (0);
2352 GNUNET_free (ubs);
2353 return GNUNET_SYSERR;
2354}
Type of (unblinded) signatures.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.

References GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_CRYPTO_UnblindedSignature::cs_signature, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_free, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_UnblindedSignature::rc, res, result, and GNUNET_CRYPTO_UnblindedSignature::rsa_signature.

Referenced by GNUNET_PQ_result_spec_unblinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_unblinded_sig()

static void clean_unblinded_sig ( 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 2365 of file pq_result_helper.c.

2367{
2368 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = rd;
2369
2370 (void) cls;
2372}
void GNUNET_CRYPTO_unblinded_sig_decref(struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
Decrement reference counter of a ub_sig, and free it if it reaches zero.

References GNUNET_CRYPTO_unblinded_sig_decref(), and rd.

Referenced by GNUNET_PQ_result_spec_unblinded_sig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_PQ_result_spec_unblinded_sig()

struct GNUNET_PQ_ResultSpec GNUNET_PQ_result_spec_unblinded_sig ( const char *  name,
struct GNUNET_CRYPTO_UnblindedSignature **  ub_sig 
)

Unblinded signature expected.

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

Definition at line 2376 of file pq_result_helper.c.

2379{
2380 struct GNUNET_PQ_ResultSpec res = {
2382 .cleaner = &clean_unblinded_sig,
2383 .dst = (void *) ub_sig,
2384 .fname = name
2385 };
2386
2387 return res;
2388}
static enum GNUNET_GenericReturnValue extract_unblinded_sig(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_unblinded_sig(void *cls, void *rd)
Function called to clean up memory allocated by a GNUNET_PQ_ResultConverter.

References clean_unblinded_sig(), GNUNET_PQ_ResultSpec::conv, extract_unblinded_sig(), GNUNET_PQ_ResultSpec::fname, name, and res.

Here is the call graph for this function: