GNUnet 0.25.2-11-g84e94e98c
 
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_BlindablePrivateKey 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);
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_.
const char * str
Definition time.c:1252

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

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, rd, and str.

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)

The sizes of the elements in the input. A NULL element will be indicated in the input by a size of -1. However, we will then use an element size of either 0 (for variable sized data) or info->same_size (for fixed sized data).

The amounts of bytes to advance the in-pointer after the encoded size of an element. If the element is NULL (indicated by a size of -1), the value will be 0, independent of the corresponding value of elem_sz.

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 case array_of_uint16:
1382 HANDLE_ARRAY (uint16_t, ntohs, DEREF);
1383 break;
1384 case array_of_uint32:
1385 HANDLE_ARRAY (uint32_t, ntohl, DEREF);
1386 break;
1387 case array_of_uint64:
1388 HANDLE_ARRAY (uint64_t, GNUNET_ntohll, DEREF);
1389 break;
1390 case array_of_abs_time:
1393 ACCESS_ABS);
1394 break;
1395 case array_of_rel_time:
1398 ACCESS_REL);
1399 break;
1400 case array_of_timestamp:
1403 ACCESS_TSTMP);
1404 break;
1405 case array_of_byte:
1406 if (0 == info->same_size)
1407 *info->sizes = GNUNET_new_array (header.dim, size_t);
1408 /* fallthrough */
1409 case array_of_string:
1410 {
1411 size_t total_sz = 0;
1412 bool is_string = (array_of_string == info->typ);
1419 uint32_t elem_sz[header.dim];
1426 uint32_t in_adv[header.dim];
1427 bool is_null[header.dim];
1428
1429 memset (elem_sz, 0, sizeof(elem_sz));
1430 memset (in_adv, 0, sizeof(in_adv));
1431 memset (is_null, 0, sizeof(is_null));
1432
1433 /* first, calculate total size required for allocation */
1434 for (uint32_t i = 0; i < header.dim; i++)
1435 {
1436 int32_t sz = ntohl (*(int32_t *) in);
1437
1438 if (-1 == sz) /* signifies NULL entry */
1439 {
1440 FAIL_IF (! info->allow_nulls);
1441 is_null[i] = true;
1442 elem_sz[i] = info->same_size ? info->same_size : 0;
1443 in_adv[i] = 0;
1444 }
1445 else
1446 {
1447 FAIL_IF (0 > sz);
1448 elem_sz[i] = sz;
1449 in_adv[i] = sz;
1450 }
1451 FAIL_IF (info->same_size &&
1452 (elem_sz[i] != info->same_size));
1453
1454 if (info->allow_nulls)
1455 (*info->is_nulls)[i] = is_null[i];
1456
1457 if ((! is_string) &&
1458 (! info->same_size))
1459 (*info->sizes)[i] = elem_sz[i];
1460
1461 total_sz += elem_sz[i];
1462 /* add room for terminator for non-NULL entry of type string */
1463 total_sz += (is_string && ! is_null[i]) ? 1 : 0;
1464 in += sizeof(int32_t);
1465 in += in_adv[i];
1466
1467 FAIL_IF (total_sz < elem_sz[i]);
1468 }
1469
1470 FAIL_IF ((! info->allow_nulls) && (0 == total_sz));
1471 if (NULL != dst_size)
1472 *dst_size = total_sz;
1473
1474 out = GNUNET_malloc (total_sz);
1475 *((void **) dst) = out;
1476 in = data + sizeof(header); /* reset to beginning of input */
1477
1478 /* Finally, copy the data */
1479 for (uint32_t i = 0; i < header.dim; i++)
1480 {
1481 in += sizeof(uint32_t); /* skip length */
1482 if (! is_null[i])
1483 GNUNET_memcpy (out, in, elem_sz[i]);
1484
1485 in += in_adv[i];
1486 out += elem_sz[i];
1487 out += (is_string && ! is_null[i]) ? 1 : 0;
1488 }
1489 break;
1490 }
1491 default:
1492 FAIL_IF (1 != 0);
1493 }
1494 }
1495
1496 return GNUNET_OK;
1497
1498FAIL:
1499 GNUNET_free (*(void **) dst);
1500 return GNUNET_SYSERR;
1501#undef FAIL_IF
1502#undef DEREF
1503#undef ACCESS_ABS
1504#undef ACCESS_REL
1505#undef ACCESS_TSTMP
1506#undef HANDLE_ARRAY
1507#undef HANDLE_ELEMENT
1508}
#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 1512 of file pq_result_helper.c.

1515{
1516 struct GNUNET_PQ_ResultSpec rsr;
1517 struct array_result_cls *info = rs.cls;
1518
1520 GNUNET_assert (NULL != is_nulls);
1521 info->allow_nulls = true;
1522 info->is_nulls = is_nulls;
1523
1524 rsr = rs;
1525 return rsr;
1526}
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 1533 of file pq_result_helper.c.

1535{
1536
1537 struct array_result_cls *info = cls;
1538 void **dst = rd;
1539
1540 if ((array_of_byte == info->typ) &&
1541 (0 == info->same_size) &&
1542 (NULL != info->sizes))
1543 GNUNET_free (*(info->sizes));
1544
1545 if (info->allow_nulls)
1546 GNUNET_free (*info->is_nulls);
1547
1548 GNUNET_free (cls);
1549 GNUNET_free (*dst);
1550 *dst = NULL;
1551}

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

1560{
1561 struct array_result_cls *info =
1563
1564 info->num = num;
1565 info->typ = array_of_bool;
1568 "bool",
1569 &info->oid));
1570
1571 {
1572 struct GNUNET_PQ_ResultSpec res = {
1574 .cleaner = array_cleanup,
1575 .dst = (void *) dst,
1576 .fname = name,
1577 .cls = info
1578 };
1579 return res;
1580 }
1581}
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 1585 of file pq_result_helper.c.

1590{
1591 struct array_result_cls *info =
1593
1594 info->num = num;
1595 info->typ = array_of_uint16;
1598 "int2",
1599 &info->oid));
1600
1601 {
1602 struct GNUNET_PQ_ResultSpec res = {
1604 .cleaner = array_cleanup,
1605 .dst = (void *) dst,
1606 .fname = name,
1607 .cls = info
1608 };
1609 return res;
1610 }
1611}

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

1620{
1621 struct array_result_cls *info =
1623
1624 info->num = num;
1625 info->typ = array_of_uint32;
1628 "int4",
1629 &info->oid));
1630
1631 {
1632 struct GNUNET_PQ_ResultSpec res = {
1634 .cleaner = array_cleanup,
1635 .dst = (void *) dst,
1636 .fname = name,
1637 .cls = info
1638 };
1639 return res;
1640 }
1641}

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

1650{
1651 struct array_result_cls *info =
1653
1654 info->num = num;
1655 info->typ = array_of_uint64;
1658 "int8",
1659 &info->oid));
1660
1661 {struct GNUNET_PQ_ResultSpec res = {
1663 .cleaner = array_cleanup,
1664 .dst = (void *) dst,
1665 .fname = name,
1666 .cls = info
1667 };
1668 return res;}
1669}

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

1678{
1679 struct array_result_cls *info =
1681
1682 info->num = num;
1683 info->typ = array_of_abs_time;
1686 "int8",
1687 &info->oid));
1688
1689 {struct GNUNET_PQ_ResultSpec res = {
1691 .cleaner = array_cleanup,
1692 .dst = (void *) dst,
1693 .fname = name,
1694 .cls = info
1695 };
1696 return res;}
1697}

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

1706{
1707 struct array_result_cls *info =
1709
1710 info->num = num;
1711 info->typ = array_of_rel_time;
1714 "int8",
1715 &info->oid));
1716
1717 {
1718 struct GNUNET_PQ_ResultSpec res = {
1720 .cleaner = array_cleanup,
1721 .dst = (void *) dst,
1722 .fname = name,
1723 .cls = info
1724 };
1725 return res;
1726 }
1727}

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

1736{
1737 struct array_result_cls *info =
1739
1740 info->num = num;
1741 info->typ = array_of_timestamp;
1744 "int8",
1745 &info->oid));
1746
1747 {
1748 struct GNUNET_PQ_ResultSpec res = {
1750 .cleaner = array_cleanup,
1751 .dst = (void *) dst,
1752 .fname = name,
1753 .cls = info
1754 };
1755 return res;
1756 }
1757}

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 of sizes given in size, allocated
Returns
array entry for the result specification to use

Definition at line 1761 of file pq_result_helper.c.

1767{
1768 struct array_result_cls *info =
1770
1771 info->num = num;
1772 info->sizes = sizes;
1773 info->typ = array_of_byte;
1776 "bytea",
1777 &info->oid));
1778
1779 {
1780 struct GNUNET_PQ_ResultSpec res = {
1782 .cleaner = array_cleanup,
1783 .dst = (void *) dst,
1784 .fname = name,
1785 .cls = info
1786 };
1787 return res;
1788 }
1789}

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 @num fixed-size elements
Returns
array entry for the result specification to use

Definition at line 1793 of file pq_result_helper.c.

1799{
1800 struct array_result_cls *info =
1802
1803 info->num = num;
1804 info->same_size = size;
1805 info->typ = array_of_byte;
1808 "bytea",
1809 &info->oid));
1810
1811 {
1812 struct GNUNET_PQ_ResultSpec res = {
1814 .cleaner = array_cleanup,
1815 .dst = (void *) dst,
1816 .fname = name,
1817 .cls = info
1818 };
1819 return res;
1820 }
1821}
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 1825 of file pq_result_helper.c.

1830{
1831 struct array_result_cls *info =
1833
1834 info->num = num;
1835 info->typ = array_of_string;
1838 "text",
1839 &info->oid));
1840
1841 {
1842 struct GNUNET_PQ_ResultSpec res = {
1844 .cleaner = array_cleanup,
1845 .dst = (void *) dst,
1846 .fname = name,
1847 .cls = info
1848 };
1849 return res;
1850 }
1851}

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

1874{
1875 struct GNUNET_CRYPTO_BlindSignPublicKey **bpk = dst;
1877 size_t len;
1878 const char *res;
1879 int fnum;
1880 uint32_t be;
1881
1882 (void) cls;
1883 (void) dst_size;
1884 fnum = PQfnumber (result,
1885 fname);
1886 if (fnum < 0)
1887 {
1888 GNUNET_break (0);
1889 return GNUNET_SYSERR;
1890 }
1891 if (PQgetisnull (result,
1892 row,
1893 fnum))
1894 return GNUNET_NO;
1895
1896 /* if a field is null, continue but
1897 * remember that we now return a different result */
1898 len = PQgetlength (result,
1899 row,
1900 fnum);
1901 res = PQgetvalue (result,
1902 row,
1903 fnum);
1904 if (len < sizeof (be))
1905 {
1906 GNUNET_break (0);
1907 return GNUNET_SYSERR;
1908 }
1909 GNUNET_memcpy (&be,
1910 res,
1911 sizeof (be));
1912 res += sizeof (be);
1913 len -= sizeof (be);
1915 tmp->cipher = ntohl (be);
1916 tmp->rc = 1;
1917 switch (tmp->cipher)
1918 {
1920 break;
1924 len);
1925 if (NULL == tmp->details.rsa_public_key)
1926 {
1927 GNUNET_break (0);
1928 GNUNET_free (tmp);
1929 return GNUNET_SYSERR;
1930 }
1932 len,
1933 &tmp->pub_key_hash);
1934 *bpk = tmp;
1935 return GNUNET_OK;
1937 if (sizeof (tmp->details.cs_public_key) != len)
1938 {
1939 GNUNET_break (0);
1940 GNUNET_free (tmp);
1941 return GNUNET_SYSERR;
1942 }
1944 res,
1945 len);
1947 len,
1948 &tmp->pub_key_hash);
1949 *bpk = tmp;
1950 return GNUNET_OK;
1951 }
1952 GNUNET_break (0);
1953 GNUNET_free (tmp);
1954 return GNUNET_SYSERR;
1955}
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::@20 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 1966 of file pq_result_helper.c.

1968{
1970
1971 (void) cls;
1972 if (NULL != *pub)
1973 {
1975 *pub = NULL;
1976 }
1977}
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 1981 of file pq_result_helper.c.

1984{
1985 struct GNUNET_PQ_ResultSpec res = {
1987 .cleaner = &clean_blind_sign_pub,
1988 .dst = (void *) pub,
1989 .fname = name
1990 };
1991
1992 return res;
1993}
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 2010 of file pq_result_helper.c.

2016{
2017 struct GNUNET_CRYPTO_BlindSignPrivateKey **bpk = dst;
2019 size_t len;
2020 const char *res;
2021 int fnum;
2022 uint32_t be;
2023
2024 (void) cls;
2025 (void) dst_size;
2026 fnum = PQfnumber (result,
2027 fname);
2028 if (fnum < 0)
2029 {
2030 GNUNET_break (0);
2031 return GNUNET_SYSERR;
2032 }
2033 if (PQgetisnull (result,
2034 row,
2035 fnum))
2036 return GNUNET_NO;
2037
2038 /* if a field is null, continue but
2039 * remember that we now return a different result */
2040 len = PQgetlength (result,
2041 row,
2042 fnum);
2043 res = PQgetvalue (result,
2044 row,
2045 fnum);
2046 if (len < sizeof (be))
2047 {
2048 GNUNET_break (0);
2049 return GNUNET_SYSERR;
2050 }
2051 GNUNET_memcpy (&be,
2052 res,
2053 sizeof (be));
2054 res += sizeof (be);
2055 len -= sizeof (be);
2057 tmp->cipher = ntohl (be);
2058 tmp->rc = 1;
2059 switch (tmp->cipher)
2060 {
2062 break;
2066 len);
2067 if (NULL == tmp->details.rsa_private_key)
2068 {
2069 GNUNET_break (0);
2070 GNUNET_free (tmp);
2071 return GNUNET_SYSERR;
2072 }
2073 *bpk = tmp;
2074 return GNUNET_OK;
2076 if (sizeof (tmp->details.cs_private_key) != len)
2077 {
2078 GNUNET_break (0);
2079 GNUNET_free (tmp);
2080 return GNUNET_SYSERR;
2081 }
2083 res,
2084 len);
2085 *bpk = tmp;
2086 return GNUNET_OK;
2087 }
2088 GNUNET_break (0);
2089 GNUNET_free (tmp);
2090 return GNUNET_SYSERR;
2091}
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::@21 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 2102 of file pq_result_helper.c.

2104{
2105 struct GNUNET_CRYPTO_BlindSignPrivateKey **priv = rd;
2106
2107 (void) cls;
2108 if (NULL != *priv)
2109 {
2111 *priv = NULL;
2112 }
2113}
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 2117 of file pq_result_helper.c.

2120{
2121 struct GNUNET_PQ_ResultSpec res = {
2123 .cleaner = &clean_blind_sign_priv,
2124 .dst = (void *) priv,
2125 .fname = name
2126 };
2127
2128 return res;
2129}
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 2146 of file pq_result_helper.c.

2152{
2153 struct GNUNET_CRYPTO_BlindedSignature **sig = dst;
2155 size_t len;
2156 const char *res;
2157 int fnum;
2158 uint32_t be[2];
2159
2160 (void) cls;
2161 (void) dst_size;
2162 fnum = PQfnumber (result,
2163 fname);
2164 if (fnum < 0)
2165 {
2166 GNUNET_break (0);
2167 return GNUNET_SYSERR;
2168 }
2169 if (PQgetisnull (result,
2170 row,
2171 fnum))
2172 return GNUNET_NO;
2173
2174 /* if a field is null, continue but
2175 * remember that we now return a different result */
2176 len = PQgetlength (result,
2177 row,
2178 fnum);
2179 res = PQgetvalue (result,
2180 row,
2181 fnum);
2182 if (len < sizeof (be))
2183 {
2184 GNUNET_break (0);
2185 return GNUNET_SYSERR;
2186 }
2187 GNUNET_memcpy (&be,
2188 res,
2189 sizeof (be));
2190 if (0x01 != ntohl (be[1])) /* magic marker: blinded */
2191 {
2192 GNUNET_break (0);
2193 return GNUNET_SYSERR;
2194 }
2195 res += sizeof (be);
2196 len -= sizeof (be);
2198 bs->rc = 1;
2199 bs->cipher = ntohl (be[0]);
2200 switch (bs->cipher)
2201 {
2203 break;
2207 len);
2208 if (NULL == bs->details.blinded_rsa_signature)
2209 {
2210 GNUNET_break (0);
2211 GNUNET_free (bs);
2212 return GNUNET_SYSERR;
2213 }
2214 *sig = bs;
2215 return GNUNET_OK;
2217 if (sizeof (bs->details.blinded_cs_answer) != len)
2218 {
2219 GNUNET_break (0);
2220 GNUNET_free (bs);
2221 return GNUNET_SYSERR;
2222 }
2224 res,
2225 len);
2226 *sig = bs;
2227 return GNUNET_OK;
2228 }
2229 GNUNET_break (0);
2230 GNUNET_free (bs);
2231 return GNUNET_SYSERR;
2232}
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.
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.
union GNUNET_CRYPTO_BlindedSignature::@19 details
Details, depending on 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 2243 of file pq_result_helper.c.

2245{
2246 struct GNUNET_CRYPTO_BlindedSignature **b_sig = rd;
2247
2248 (void) cls;
2250}
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 2254 of file pq_result_helper.c.

2257{
2258 struct GNUNET_PQ_ResultSpec res = {
2260 .cleaner = &clean_blinded_sig,
2261 .dst = (void *) b_sig,
2262 .fname = name
2263 };
2264
2265 return res;
2266}
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 2283 of file pq_result_helper.c.

2289{
2290 struct GNUNET_CRYPTO_UnblindedSignature **sig = dst;
2292 size_t len;
2293 const char *res;
2294 int fnum;
2295 uint32_t be[2];
2296
2297 (void) cls;
2298 (void) dst_size;
2299 fnum = PQfnumber (result,
2300 fname);
2301 if (fnum < 0)
2302 {
2303 GNUNET_break (0);
2304 return GNUNET_SYSERR;
2305 }
2306 if (PQgetisnull (result,
2307 row,
2308 fnum))
2309 return GNUNET_NO;
2310
2311 /* if a field is null, continue but
2312 * remember that we now return a different result */
2313 len = PQgetlength (result,
2314 row,
2315 fnum);
2316 res = PQgetvalue (result,
2317 row,
2318 fnum);
2319 if (len < sizeof (be))
2320 {
2321 GNUNET_break (0);
2322 return GNUNET_SYSERR;
2323 }
2324 GNUNET_memcpy (&be,
2325 res,
2326 sizeof (be));
2327 if (0x00 != ntohl (be[1])) /* magic marker: unblinded */
2328 {
2329 GNUNET_break (0);
2330 return GNUNET_SYSERR;
2331 }
2332 res += sizeof (be);
2333 len -= sizeof (be);
2335 ubs->rc = 1;
2336 ubs->cipher = ntohl (be[0]);
2337 switch (ubs->cipher)
2338 {
2340 break;
2344 len);
2345 if (NULL == ubs->details.rsa_signature)
2346 {
2347 GNUNET_break (0);
2348 GNUNET_free (ubs);
2349 return GNUNET_SYSERR;
2350 }
2351 *sig = ubs;
2352 return GNUNET_OK;
2354 if (sizeof (ubs->details.cs_signature) != len)
2355 {
2356 GNUNET_break (0);
2357 GNUNET_free (ubs);
2358 return GNUNET_SYSERR;
2359 }
2361 res,
2362 len);
2363 *sig = ubs;
2364 return GNUNET_OK;
2365 }
2366 GNUNET_break (0);
2367 GNUNET_free (ubs);
2368 return GNUNET_SYSERR;
2369}
Type of (unblinded) signatures.
union GNUNET_CRYPTO_UnblindedSignature::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
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 2380 of file pq_result_helper.c.

2382{
2383 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = rd;
2384
2385 (void) cls;
2387}
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 2391 of file pq_result_helper.c.

2394{
2395 struct GNUNET_PQ_ResultSpec res = {
2397 .cleaner = &clean_unblinded_sig,
2398 .dst = (void *) ub_sig,
2399 .fname = name
2400 };
2401
2402 return res;
2403}
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: