GNUnet 0.22.1
pq_query_helper.c File Reference

functions to initialize parameter arrays More...

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

Go to the source code of this file.

Data Structures

struct  qconv_array_cls
 Closure for the array type handlers. More...
 

Macros

#define RETURN_UNLESS(cond)
 

Functions

static int qconv_null (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null (void)
 Generate query parameter to create a NULL value. More...
 
static int qconv_fixed (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_fixed_size (const void *ptr, size_t ptr_size)
 Generate query parameter for a buffer ptr of ptr_size bytes. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string (const char *ptr)
 Generate query parameter for a string. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool (bool b)
 Pass a boolean into a query. More...
 
static int qconv_uint16 (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16 (const uint16_t *x)
 Generate query parameter for an uint16_t in host byte order. More...
 
static int qconv_uint32 (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32 (const uint32_t *x)
 Generate query parameter for an uint32_t in host byte order. More...
 
static int qconv_uint64 (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 (const uint64_t *x)
 Generate query parameter for an uint64_t in host byte order. More...
 
static int qconv_int64 (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int64 (const int64_t *x)
 Generate query parameter for an int64_t in host byte order. More...
 
static int qconv_rsa_public_key (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *x)
 Generate query parameter for an RSA public key. More...
 
static int qconv_rsa_signature (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
 Generate query parameter for an RSA signature. More...
 
static int qconv_rel_time (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x)
 Generate query parameter for a relative time value. More...
 
static int qconv_abs_time (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
 Generate query parameter for an absolute time value. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x)
 Generate query parameter for an absolute time value. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x)
 Generate query parameter for a timestamp. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo (const struct GNUNET_TIME_TimestampNBO *x)
 Generate query parameter for a timestamp in NBO. More...
 
static void qconv_array_cls_cleanup (void *cls)
 Callback to cleanup a qconv_array_cls to be used during GNUNET_PQ_cleanup_query_params_closures. More...
 
static int qconv_array (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters for arrays. More...
 
static struct GNUNET_PQ_QueryParam query_param_array_generic (unsigned int num, bool continuous, const void *elements, const size_t *sizes, size_t same_size, enum array_types typ, Oid oid)
 Function to generate a typ specific query parameter and corresponding closure. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bool (unsigned int num, const bool *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of bool in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint16 (unsigned int num, const uint16_t *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of uint16_t in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint32 (unsigned int num, const uint32_t *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of uint32_t in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint64 (unsigned int num, const uint64_t *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of uint64 in host byte order. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bytes (unsigned int num, const void *elements, const size_t *sizes, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of buffers elements, each of corresponding size given in sizes. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes (unsigned int num, const void *elements[static num], const size_t *sizes, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of buffers elements, with sizes sizes. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bytes_same_size (unsigned int num, const void *elements, size_t same_size, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of buffers elements, each of the same size size. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes_same_size (unsigned int num, const void *elements[static num], size_t same_size, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of pointers to buffers elements, each of the same size size. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_string (unsigned int num, const char *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of strings (continuous) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_string (unsigned int num, const char *elements[static num], struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of strings (pointers) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_abs_time (unsigned int num, const struct GNUNET_TIME_Absolute *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of absolute time stamps (continuous) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_abs_time (unsigned int num, const struct GNUNET_TIME_Absolute *elements[], struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of absolute time stamps (pointers) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_rel_time (unsigned int num, const struct GNUNET_TIME_Relative *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of relative time stamps (continuous) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_rel_time (unsigned int num, const struct GNUNET_TIME_Relative *elements[], struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of relative time stamps (pointers) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_timestamp (unsigned int num, const struct GNUNET_TIME_Timestamp *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of time stamps (continuous) More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_timestamp (unsigned int num, const struct GNUNET_TIME_Timestamp *elements[], struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of time stamps (pointers) More...
 
static int qconv_blind_sign_pub (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_pub (const struct GNUNET_CRYPTO_BlindSignPublicKey *pub)
 Generate query parameter for a blind sign public key of variable size. More...
 
static int qconv_blind_sign_priv (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_priv (const struct GNUNET_CRYPTO_BlindSignPrivateKey *priv)
 Generate query parameter for a blind sign private key of variable size. More...
 
static int qconv_unblinded_sig (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_unblinded_sig (const struct GNUNET_CRYPTO_UnblindedSignature *sig)
 Generate query parameter for an unblinded signature of variable size. More...
 
static int qconv_blinded_sig (void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
 Function called to convert input argument into SQL parameters. More...
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blinded_sig (const struct GNUNET_CRYPTO_BlindedSignature *b_sig)
 Generate query parameter for a blinded signature of variable size. More...
 

Detailed Description

functions to initialize parameter arrays

Author
Christian Grothoff

Definition in file pq_query_helper.c.

Macro Definition Documentation

◆ RETURN_UNLESS

#define RETURN_UNLESS (   cond)
Value:
do { \
if (! (cond)) \
{ \
GNUNET_break ((cond)); \
noerror = false; \
goto DONE; \
} \
} while (0)

Function Documentation

◆ qconv_null()

static int qconv_null ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 46 of file pq_query_helper.c.

55{
56 (void) scratch;
57 (void) scratch_length;
58 (void) data;
59 (void) data_len;
60 GNUNET_break (NULL == cls);
61 if (1 != param_length)
62 return -1;
63 param_values[0] = NULL;
64 param_lengths[0] = 0;
65 param_formats[0] = 1;
66 return 0;
67}
static char * data
The data to insert into the dht.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

References data, and GNUNET_break.

Referenced by GNUNET_PQ_query_param_null().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_null()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null ( void  )

Generate query parameter to create a NULL value.

Returns
query parameter to use to insert NULL into DB

Definition at line 71 of file pq_query_helper.c.

72{
73 struct GNUNET_PQ_QueryParam res = {
74 .conv = &qconv_null,
75 .num_params = 1
76 };
77
78 return res;
79}
static char * res
Currently read line or NULL on EOF.
static int qconv_null(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.
Description of a DB query parameter.
Definition: gnunet_pq_lib.h:83

References qconv_null(), and res.

Referenced by postgres_plugin_put().

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

◆ qconv_fixed()

static int qconv_fixed ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 97 of file pq_query_helper.c.

106{
107 (void) scratch;
108 (void) scratch_length;
109 GNUNET_break (NULL == cls);
110 if (1 != param_length)
111 return -1;
112 param_values[0] = (void *) data;
113 param_lengths[0] = data_len;
114 param_formats[0] = 1;
115 return 0;
116}

References data, and GNUNET_break.

Referenced by GNUNET_PQ_query_param_fixed_size().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_fixed_size()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_fixed_size ( const void *  ptr,
size_t  ptr_size 
)

Generate query parameter for a buffer ptr of ptr_size bytes.

Parameters
ptrpointer to the query parameter to pass
ptr_sizenumber of bytes in ptr
Returns
query parameter to use

Definition at line 120 of file pq_query_helper.c.

122{
123 struct GNUNET_PQ_QueryParam res = {
124 .conv = &qconv_fixed,
125 .conv_cls = NULL,
126 .data = ptr,
127 .size = ptr_size,
128 .num_params = 1
129 };
130
131 return res;
132}
static int qconv_fixed(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_fixed(), res, and GNUNET_PQ_QueryParam::size.

Referenced by GNUNET_PQ_query_param_bool(), GNUNET_PQ_query_param_string(), namecache_postgres_cache_block(), namestore_postgres_store_records(), postgres_plugin_put(), and postgres_plugin_remove_key().

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

◆ GNUNET_PQ_query_param_string()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string ( const char *  ptr)

Generate query parameter for a string.

Parameters
ptrpointer to the string query parameter to pass
Returns
query parameter to use

Definition at line 136 of file pq_query_helper.c.

137{
139 strlen (ptr));
140}
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_fixed_size(const void *ptr, size_t ptr_size)
Generate query parameter for a buffer ptr of ptr_size bytes.

References GNUNET_PQ_query_param_fixed_size().

Referenced by GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_run_sql(), namestore_postgres_clear_editor_hint(), namestore_postgres_edit_records(), namestore_postgres_lookup_records(), and namestore_postgres_store_records().

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

◆ GNUNET_PQ_query_param_bool()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool ( bool  b)

Pass a boolean into a query.

Parameters
bboolean bit to pass
Returns
query parameter to use

Definition at line 144 of file pq_query_helper.c.

145{
146 static uint8_t bt = 1;
147 static uint8_t bf = 0;
148
149 return GNUNET_PQ_query_param_fixed_size (b ? &bt : &bf,
150 sizeof (uint8_t));
151}

References GNUNET_PQ_query_param_fixed_size().

Here is the call graph for this function:

◆ qconv_uint16()

static int qconv_uint16 ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 169 of file pq_query_helper.c.

178{
179 const uint16_t *u_hbo = data;
180 uint16_t *u_nbo;
181
182 (void) scratch;
183 (void) scratch_length;
184 GNUNET_break (NULL == cls);
185 if (1 != param_length)
186 return -1;
187 u_nbo = GNUNET_new (uint16_t);
188 scratch[0] = u_nbo;
189 *u_nbo = htons (*u_hbo);
190 param_values[0] = (void *) u_nbo;
191 param_lengths[0] = sizeof(uint16_t);
192 param_formats[0] = 1;
193 return 1;
194}
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References data, GNUNET_break, and GNUNET_new.

Referenced by GNUNET_PQ_query_param_uint16().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_uint16()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16 ( const uint16_t *  x)

Generate query parameter for an uint16_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 198 of file pq_query_helper.c.

199{
200 struct GNUNET_PQ_QueryParam res = {
201 .conv = &qconv_uint16,
202 .data = x,
203 .size = sizeof(*x),
204 .num_params = 1
205 };
206
207 return res;
208}
static int qconv_uint16(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_uint16(), and res.

Referenced by postgres_plugin_get_key().

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

◆ qconv_uint32()

static int qconv_uint32 ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 226 of file pq_query_helper.c.

235{
236 const uint32_t *u_hbo = data;
237 uint32_t *u_nbo;
238
239 (void) scratch;
240 (void) scratch_length;
241 GNUNET_break (NULL == cls);
242 if (1 != param_length)
243 return -1;
244 u_nbo = GNUNET_new (uint32_t);
245 scratch[0] = u_nbo;
246 *u_nbo = htonl (*u_hbo);
247 param_values[0] = (void *) u_nbo;
248 param_lengths[0] = sizeof(uint32_t);
249 param_formats[0] = 1;
250 return 1;
251}

References data, GNUNET_break, and GNUNET_new.

Referenced by GNUNET_PQ_query_param_uint32().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_uint32()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32 ( const uint32_t *  x)

Generate query parameter for an uint32_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 255 of file pq_query_helper.c.

256{
257 struct GNUNET_PQ_QueryParam res = {
258 .conv = &qconv_uint32,
259 .data = x,
260 .size = sizeof(*x),
261 .num_params = 1
262 };
263
264 return res;
265}
static int qconv_uint32(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_uint32(), and res.

Referenced by namestore_postgres_store_records(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), and postgres_plugin_put().

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

◆ qconv_uint64()

static int qconv_uint64 ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 283 of file pq_query_helper.c.

292{
293 const uint64_t *u_hbo = data;
294 uint64_t *u_nbo;
295
296 (void) scratch;
297 (void) scratch_length;
298 GNUNET_break (NULL == cls);
299 if (1 != param_length)
300 return -1;
301 u_nbo = GNUNET_new (uint64_t);
302 scratch[0] = u_nbo;
303 *u_nbo = GNUNET_htonll (*u_hbo);
304 param_values[0] = (void *) u_nbo;
305 param_lengths[0] = sizeof(uint64_t);
306 param_formats[0] = 1;
307 return 1;
308}
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37

References data, GNUNET_break, GNUNET_htonll(), and GNUNET_new.

Referenced by GNUNET_PQ_query_param_uint64().

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

◆ GNUNET_PQ_query_param_uint64()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 ( const uint64_t *  x)

Generate query parameter for an uint64_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 312 of file pq_query_helper.c.

313{
314 struct GNUNET_PQ_QueryParam res = {
315 .conv = &qconv_uint64,
316 .data = x,
317 .size = sizeof(*x),
318 .num_params = 1
319 };
320
321 return res;
322}
static int qconv_uint64(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_uint64(), and res.

Referenced by namestore_postgres_iterate_records(), namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), process_result(), and repl_proc().

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

◆ qconv_int64()

static int qconv_int64 ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 340 of file pq_query_helper.c.

349{
350 const int64_t *u_hbo = data;
351 int64_t *u_nbo;
352
353 (void) scratch;
354 (void) scratch_length;
355 GNUNET_break (NULL == cls);
356 if (1 != param_length)
357 return -1;
358 u_nbo = GNUNET_new (int64_t);
359 scratch[0] = u_nbo;
360 *u_nbo = GNUNET_htonll (*u_hbo);
361 param_values[0] = (void *) u_nbo;
362 param_lengths[0] = sizeof(int64_t);
363 param_formats[0] = 1;
364 return 1;
365}

References data, GNUNET_break, GNUNET_htonll(), and GNUNET_new.

Referenced by GNUNET_PQ_query_param_int64().

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

◆ GNUNET_PQ_query_param_int64()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int64 ( const int64_t *  x)

Generate query parameter for an int64_t in host byte order.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 369 of file pq_query_helper.c.

370{
371 struct GNUNET_PQ_QueryParam res = {
372 .conv = &qconv_int64,
373 .data = x,
374 .size = sizeof(*x),
375 .num_params = 1
376 };
377
378 return res;
379}
static int qconv_int64(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_int64(), and res.

Here is the call graph for this function:

◆ qconv_rsa_public_key()

static int qconv_rsa_public_key ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 397 of file pq_query_helper.c.

406{
407 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
408 void *buf;
409 size_t buf_size;
410
411 GNUNET_break (NULL == cls);
412 if (1 != param_length)
413 return -1;
415 &buf);
416 scratch[0] = buf;
417 param_values[0] = (void *) buf;
418 param_lengths[0] = buf_size;
419 param_formats[0] = 1;
420 return 1;
421}
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:325
The public information of an RSA key pair.
Definition: crypto_rsa.c:53

References data, GNUNET_break, and GNUNET_CRYPTO_rsa_public_key_encode().

Referenced by GNUNET_PQ_query_param_rsa_public_key().

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

◆ GNUNET_PQ_query_param_rsa_public_key()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_public_key ( const struct GNUNET_CRYPTO_RsaPublicKey x)

Generate query parameter for an RSA public key.

The database must contain a BLOB type in the respective position.

Parameters
xthe query parameter to pass.
Returns
query parameter to use

Definition at line 425 of file pq_query_helper.c.

427{
428 struct GNUNET_PQ_QueryParam res = {
429 .conv = &qconv_rsa_public_key,
430 .data = x,
431 .num_params = 1
432 };
433
434 return res;
435}
static int qconv_rsa_public_key(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_rsa_public_key(), and res.

Here is the call graph for this function:

◆ qconv_rsa_signature()

static int qconv_rsa_signature ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 453 of file pq_query_helper.c.

462{
463 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
464 void *buf;
465 size_t buf_size;
466
467 GNUNET_break (NULL == cls);
468 if (1 != param_length)
469 return -1;
471 &buf);
472 scratch[0] = buf;
473 param_values[0] = (void *) buf;
474 param_lengths[0] = buf_size;
475 param_formats[0] = 1;
476 return 1;
477}
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:1023
an RSA signature
Definition: crypto_rsa.c:65

References data, GNUNET_break, and GNUNET_CRYPTO_rsa_signature_encode().

Referenced by GNUNET_PQ_query_param_rsa_signature().

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

◆ GNUNET_PQ_query_param_rsa_signature()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_signature ( const struct GNUNET_CRYPTO_RsaSignature x)

Generate query parameter for an RSA signature.

The database must contain a BLOB type in the respective position.

Parameters
xthe query parameter to pass
Returns
query parameter to use

Definition at line 481 of file pq_query_helper.c.

482{
483 struct GNUNET_PQ_QueryParam res = {
484 .conv = &qconv_rsa_signature,
485 .data = x,
486 .num_params = 1
487 };
488
489 return res;
490}
static int qconv_rsa_signature(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_rsa_signature(), and res.

Here is the call graph for this function:

◆ qconv_rel_time()

static int qconv_rel_time ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 508 of file pq_query_helper.c.

517{
518 const struct GNUNET_TIME_Relative *u = data;
519 struct GNUNET_TIME_Relative rel;
520 uint64_t *u_nbo;
521
522 GNUNET_break (NULL == cls);
523 if (1 != param_length)
524 return -1;
525 rel = *u;
526 if (rel.rel_value_us > INT64_MAX)
527 rel.rel_value_us = INT64_MAX;
528 u_nbo = GNUNET_new (uint64_t);
529 scratch[0] = u_nbo;
530 *u_nbo = GNUNET_htonll (rel.rel_value_us);
531 param_values[0] = (void *) u_nbo;
532 param_lengths[0] = sizeof(uint64_t);
533 param_formats[0] = 1;
534 return 1;
535}
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
Time for relative time used by GNUnet, in microseconds.

References data, GNUNET_break, GNUNET_htonll(), GNUNET_new, GNUNET_TIME_Relative::rel_value_us, and u.

Referenced by GNUNET_PQ_query_param_relative_time().

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

◆ GNUNET_PQ_query_param_relative_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_relative_time ( const struct GNUNET_TIME_Relative x)

Generate query parameter for a relative time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 539 of file pq_query_helper.c.

540{
541 struct GNUNET_PQ_QueryParam res = {
542 .conv = &qconv_rel_time,
543 .data = x,
544 .size = sizeof(*x),
545 .num_params = 1
546 };
547
548 return res;
549}
static int qconv_rel_time(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_rel_time(), and res.

Here is the call graph for this function:

◆ qconv_abs_time()

static int qconv_abs_time ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 567 of file pq_query_helper.c.

576{
577 const struct GNUNET_TIME_Absolute *u = data;
578 struct GNUNET_TIME_Absolute abs;
579 uint64_t *u_nbo;
580
581 GNUNET_break (NULL == cls);
582 if (1 != param_length)
583 return -1;
584 abs = *u;
585 if (abs.abs_value_us > INT64_MAX)
586 abs.abs_value_us = INT64_MAX;
587 u_nbo = GNUNET_new (uint64_t);
588 scratch[0] = u_nbo;
589 *u_nbo = GNUNET_htonll (abs.abs_value_us);
590 param_values[0] = (void *) u_nbo;
591 param_lengths[0] = sizeof(uint64_t);
592 param_formats[0] = 1;
593 return 1;
594}
Time for absolute times used by GNUnet, in microseconds.

References GNUNET_TIME_Absolute::abs_value_us, data, GNUNET_break, GNUNET_htonll(), GNUNET_new, and u.

Referenced by GNUNET_PQ_query_param_absolute_time().

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

◆ GNUNET_PQ_query_param_absolute_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time ( const struct GNUNET_TIME_Absolute x)

Generate query parameter for an absolute time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 598 of file pq_query_helper.c.

599{
600 struct GNUNET_PQ_QueryParam res = {
601 .conv = &qconv_abs_time,
602 .data = x,
603 .size = sizeof(*x),
604 .num_params = 1
605 };
606
607 return res;
608}
static int qconv_abs_time(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_abs_time(), and res.

Referenced by delete_old_block(), GNUNET_PQ_query_param_timestamp(), namecache_postgres_cache_block(), namecache_postgres_expire_blocks(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), and postgres_plugin_put().

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

◆ GNUNET_PQ_query_param_absolute_time_nbo()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time_nbo ( const struct GNUNET_TIME_AbsoluteNBO x)

Generate query parameter for an absolute time value.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 612 of file pq_query_helper.c.

614{
616}
#define GNUNET_PQ_query_param_auto_from_type(x)
Generate fixed-size query parameter with size determined by variable type.
uint64_t abs_value_us__
The actual value (in network byte order).

References GNUNET_PQ_query_param_auto_from_type.

Referenced by GNUNET_PQ_query_param_timestamp_nbo().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_timestamp()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp ( const struct GNUNET_TIME_Timestamp x)

Generate query parameter for a timestamp.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 620 of file pq_query_helper.c.

621{
623}
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time(const struct GNUNET_TIME_Absolute *x)
Generate query parameter for an absolute time value.
struct GNUNET_TIME_Absolute abs_time
The actual value.

References GNUNET_PQ_query_param_absolute_time().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_timestamp_nbo()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo ( const struct GNUNET_TIME_TimestampNBO x)

Generate query parameter for a timestamp in NBO.

The database must store a 64-bit integer.

Parameters
xpointer to the query parameter to pass
Returns
query parameter to use

Definition at line 627 of file pq_query_helper.c.

629{
631}
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
Generate query parameter for an absolute time value.
struct GNUNET_TIME_AbsoluteNBO abs_time_nbo
The actual value.

References GNUNET_PQ_query_param_absolute_time_nbo().

Here is the call graph for this function:

◆ qconv_array_cls_cleanup()

static void qconv_array_cls_cleanup ( void *  cls)
static

Callback to cleanup a qconv_array_cls to be used during GNUNET_PQ_cleanup_query_params_closures.

Definition at line 679 of file pq_query_helper.c.

680{
681 GNUNET_free (cls);
682}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

Referenced by query_param_array_generic().

Here is the caller graph for this function:

◆ qconv_array()

static int qconv_array ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters for arrays.

Note: the format for the encoding of arrays for libpq is not very well documented. We peeked into various sources (postgresql and libpqtypes) for guidance.

Parameters
clsClosure of type struct qconv_array_cls*
dataPointer to first element in the array
data_lenNumber of elements in array data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 704 of file pq_query_helper.c.

714{
715 struct qconv_array_cls *meta = cls;
716 size_t num = data_len;
717 size_t total_size;
718 const size_t *sizes;
719 bool same_sized;
720 size_t *string_lengths = NULL;
721 void *elements = NULL;
722 bool noerror = true;
723
724 (void) (param_length);
725 (void) (scratch_length);
726
727 GNUNET_assert (NULL != meta);
728 GNUNET_assert (num < INT_MAX);
729
730 sizes = meta->sizes;
731 same_sized = (0 != meta->same_size);
732
733#define RETURN_UNLESS(cond) \
734 do { \
735 if (! (cond)) \
736 { \
737 GNUNET_break ((cond)); \
738 noerror = false; \
739 goto DONE; \
740 } \
741 } while (0)
742
743 /* Calculate sizes and check bounds */
744 {
745 /* num * length-field */
746 size_t x = sizeof(uint32_t);
747 size_t y = x * num;
748 RETURN_UNLESS ((0 == num) || (y / num == x));
749
750 /* size of header */
751 total_size = x = sizeof(struct pq_array_header);
752 total_size += y;
753 RETURN_UNLESS (total_size >= x);
754
755 /* sizes of elements */
756 if (same_sized)
757 {
758 x = num * meta->same_size;
759 RETURN_UNLESS ((0 == num) || (x / num == meta->same_size));
760
761 y = total_size;
762 total_size += x;
763 RETURN_UNLESS (total_size >= y);
764 }
765 else /* sizes are different per element */
766 {
767 /* for an array of strings we need to get their length's first */
768 if (array_of_string == meta->typ)
769 {
770 string_lengths = GNUNET_new_array (num, size_t);
771
772 if (meta->continuous)
773 {
774 const char *ptr = data;
775 for (unsigned int i = 0; i < num; i++)
776 {
777 size_t len = strlen (ptr);
778 string_lengths[i] = len;
779 ptr += len + 1;
780 }
781 }
782 else
783 {
784 const char **str = (const char **) data;
785 for (unsigned int i = 0; i < num; i++)
786 string_lengths[i] = strlen (str[i]);
787 }
788
789 sizes = string_lengths;
790 }
791
792 for (unsigned int i = 0; i < num; i++)
793 {
794 x = total_size;
795 total_size += sizes[i];
796 RETURN_UNLESS (total_size >= x);
797 }
798 }
799
800 RETURN_UNLESS (total_size < INT_MAX);
801
802 elements = GNUNET_malloc (total_size);
803 }
804
805 /* Write data */
806 {
807 char *in = (char *) data;
808 char *out = elements;
809 size_t nullbyte = (array_of_string == meta->typ) ? 1 : 0;
810 struct pq_array_header h = {
811 .ndim = htonl (1), /* We only support one-dimensional arrays */
812 .has_null = htonl (0), /* We do not support NULL entries in arrays */
813 .lbound = htonl (1), /* Default start index value */
814 .dim = htonl (num),
815 .oid = htonl (meta->oid),
816 };
817
818 /* Write header */
819 GNUNET_memcpy (out, &h, sizeof(h));
820 out += sizeof(h);
821
822
823 /* Write elements */
824 for (unsigned int i = 0; i < num; i++)
825 {
826 size_t sz = same_sized ? meta->same_size : sizes[i];
827 uint32_t hsz = htonl (sz);
828
829 GNUNET_memcpy (out,
830 &hsz,
831 sizeof(hsz));
832 out += sizeof(uint32_t);
833
834 switch (meta->typ)
835 {
836 case array_of_bool:
837 {
838 GNUNET_assert (sizeof(bool) == sz);
839 *(bool *) out = (*(bool *) in);
840 in += sz;
841 break;
842 }
843 case array_of_uint16:
844 {
845 GNUNET_assert (sizeof(uint16_t) == sz);
846 *(uint16_t *) out = htons (*(uint16_t *) in);
847 in += sz;
848 break;
849 }
850 case array_of_uint32:
851 {
852 uint32_t v;
853 GNUNET_assert (sizeof(uint32_t) == sz);
854
855 v = htonl (*(uint32_t *) in);
856 GNUNET_memcpy (out,
857 &v,
858 sizeof(v));
859 in += sz;
860 break;
861 }
862 case array_of_uint64:
863 {
864 uint64_t tmp;
865 GNUNET_assert (sizeof(uint64_t) == sz);
866
867 tmp = GNUNET_htonll (*(uint64_t *) in);
868 GNUNET_memcpy (out,
869 &tmp,
870 sizeof(tmp));
871 in += sz;
872 break;
873 }
874 case array_of_byte:
875 case array_of_string:
876 {
877 const void *ptr;
878
879 if (meta->continuous)
880 {
881 ptr = in;
882 in += sz + nullbyte;
883 }
884 else
885 ptr = ((const void **) data)[i];
886
887 GNUNET_memcpy (out,
888 ptr,
889 sz);
890 break;
891 }
895 {
896 uint64_t val;
897
898 switch (meta->typ)
899 {
901 {
902 const struct GNUNET_TIME_Absolute *abs =
903 (const struct GNUNET_TIME_Absolute *) in;
904
905 GNUNET_assert (sizeof(struct GNUNET_TIME_Absolute) == sz);
906
907 if (! meta->continuous)
908 abs = ((const struct GNUNET_TIME_Absolute **) data)[i];
909
910 val = abs->abs_value_us;
911 break;
912 }
914 {
915 const struct GNUNET_TIME_Relative *rel =
916 (const struct GNUNET_TIME_Relative *) in;
917
918 GNUNET_assert (sizeof(struct GNUNET_TIME_Relative) == sz);
919
920 if (! meta->continuous)
921 rel = ((const struct GNUNET_TIME_Relative **) data)[i];
922
923 val = rel->rel_value_us;
924 break;
925 }
927 {
928 const struct GNUNET_TIME_Timestamp *ts =
929 (const struct GNUNET_TIME_Timestamp *) in;
930
931 GNUNET_assert (sizeof(struct GNUNET_TIME_Timestamp) == sz);
932
933 if (! meta->continuous)
934 ts = ((const struct GNUNET_TIME_Timestamp **) data)[i];
935
936 val = ts->abs_time.abs_value_us;
937 break;
938 }
939 default:
940 {
941 GNUNET_assert (0);
942 }
943 }
944
945 if (val > INT64_MAX)
946 val = INT64_MAX;
947
948 val = GNUNET_htonll (val);
949 GNUNET_memcpy (out,
950 &val,
951 sizeof(val));
952
953 if (meta->continuous)
954 in += sz;
955
956 break;
957 }
958 default:
959 {
960 GNUNET_assert (0);
961 break;
962 }
963 }
964 out += sz;
965 }
966 }
967
968 param_values[0] = elements;
969 param_lengths[0] = total_size;
970 param_formats[0] = 1;
971 scratch[0] = elements;
972
973DONE:
974 GNUNET_free (string_lengths);
975
976 if (noerror)
977 return 1;
978
979 return -1;
980}
#define INT_MAX
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
@ array_of_byte
Definition: pq.h:137
@ array_of_uint32
Definition: pq.h:135
@ array_of_string
Definition: pq.h:138
@ array_of_rel_time
Definition: pq.h:140
@ array_of_uint16
Definition: pq.h:134
@ array_of_uint64
Definition: pq.h:136
@ array_of_abs_time
Definition: pq.h:139
@ array_of_timestamp
Definition: pq.h:141
@ array_of_bool
Definition: pq.h:133
#define RETURN_UNLESS(cond)
uint64_t abs_value_us
The actual value.
uint64_t rel_value_us
The actual value.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
the header for a postgresql array in binary format.
Definition: pq.h:151
Closure for the array type handlers.
const size_t * sizes
If not null, contains the array of sizes (the size of the array is the .size field in the ambient GNU...

References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, 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, GNUNET_assert, GNUNET_free, GNUNET_htonll(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new_array, h, INT_MAX, meta, GNUNET_TIME_Relative::rel_value_us, RETURN_UNLESS, and qconv_array_cls::sizes.

Referenced by query_param_array_generic().

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

◆ query_param_array_generic()

static struct GNUNET_PQ_QueryParam query_param_array_generic ( unsigned int  num,
bool  continuous,
const void *  elements,
const size_t *  sizes,
size_t  same_size,
enum array_types  typ,
Oid  oid 
)
static

Function to generate a typ specific query parameter and corresponding closure.

Parameters
numNumber of elements in elements
continuousIf true, elements is an continuous array of data
elementsArray of num elements, either continuous or pointers
sizesArray of num sizes, one per element, may be NULL
same_sizeIf not 0, all elements in elements have this size
typSupported internal type of each element in elements
oidOid of the type to be used in Postgres
Returns
Query parameter

Definition at line 996 of file pq_query_helper.c.

1004{
1006
1007 meta->typ = typ;
1008 meta->oid = oid;
1009 meta->sizes = sizes;
1010 meta->same_size = same_size;
1011 meta->continuous = continuous;
1012
1013 {
1014 struct GNUNET_PQ_QueryParam res = {
1015 .conv = qconv_array,
1016 .conv_cls = meta,
1017 .conv_cls_cleanup = &qconv_array_cls_cleanup,
1018 .data = elements,
1019 .size = num,
1020 .num_params = 1,
1021 };
1022
1023 return res;
1024 }
1025}
uint32_t oid
Definition: gnunet_pq_lib.h:2
static void qconv_array_cls_cleanup(void *cls)
Callback to cleanup a qconv_array_cls to be used during GNUNET_PQ_cleanup_query_params_closures.
static int qconv_array(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters for arrays.
enum array_types typ
Type of the array elements.
size_t same_size
If size and c_sizes are NULL, this field defines the same size for each element in the array.
bool continuous
If true, the array parameter to the data pointer to the qconv_array is a continuous byte array of dat...

References qconv_array_cls::continuous, GNUNET_new, meta, oid, qconv_array(), qconv_array_cls_cleanup(), res, qconv_array_cls::same_size, GNUNET_PQ_QueryParam::size, qconv_array_cls::sizes, and qconv_array_cls::typ.

Referenced by GNUNET_PQ_query_param_array_abs_time(), GNUNET_PQ_query_param_array_bool(), GNUNET_PQ_query_param_array_bytes(), GNUNET_PQ_query_param_array_bytes_same_size(), GNUNET_PQ_query_param_array_ptrs_abs_time(), GNUNET_PQ_query_param_array_ptrs_bytes(), GNUNET_PQ_query_param_array_ptrs_bytes_same_size(), GNUNET_PQ_query_param_array_ptrs_rel_time(), GNUNET_PQ_query_param_array_ptrs_string(), GNUNET_PQ_query_param_array_ptrs_timestamp(), GNUNET_PQ_query_param_array_rel_time(), GNUNET_PQ_query_param_array_string(), GNUNET_PQ_query_param_array_timestamp(), GNUNET_PQ_query_param_array_uint16(), GNUNET_PQ_query_param_array_uint32(), and GNUNET_PQ_query_param_array_uint64().

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

◆ GNUNET_PQ_query_param_array_bool()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bool ( unsigned int  num,
const bool *  elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of bool in host byte order.

Parameters
numNumber of elements in elements
elementsContinuous array of num boolean elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1029 of file pq_query_helper.c.

1033{
1034 Oid oid;
1035
1038 "bool",
1039 &oid));
1040 return query_param_array_generic (num,
1041 true,
1042 elements,
1043 NULL,
1044 sizeof(bool),
1046 oid);
1047}
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:326
@ GNUNET_OK
static struct GNUNET_PQ_QueryParam query_param_array_generic(unsigned int num, bool continuous, const void *elements, const size_t *sizes, size_t same_size, enum array_types typ, Oid oid)
Function to generate a typ specific query parameter and corresponding closure.

References array_of_bool, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_uint16()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint16 ( unsigned int  num,
const uint16_t *  elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of uint16_t in host byte order.

Note that the (unsigned) elements are not checked to wrap over INT2_MAX

Parameters
numNumber of elements in elements
elementsContinuous array of num uint16 elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1051 of file pq_query_helper.c.

1055{
1056 Oid oid;
1057
1060 "int2",
1061 &oid));
1062 return query_param_array_generic (num,
1063 true,
1064 elements,
1065 NULL,
1066 sizeof(uint16_t),
1068 oid);
1069}

References array_of_uint16, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_uint32()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint32 ( unsigned int  num,
const uint32_t *  elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of uint32_t in host byte order.

Note that the (unsigned) elements are not checked to wrap over INT4_MAX

Parameters
numNumber of elements in elements
elementsContinuous Array of num uint32_t elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1073 of file pq_query_helper.c.

1077{
1078 Oid oid;
1079
1082 "int4",
1083 &oid));
1084 return query_param_array_generic (num,
1085 true,
1086 elements,
1087 NULL,
1088 sizeof(uint32_t),
1090 oid);
1091}

References array_of_uint32, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_uint64()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_uint64 ( unsigned int  num,
const uint64_t *  elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of uint64 in host byte order.

Note that the (unsigned) elements are not checked to wrap over INT8_MAX

Parameters
numNumber of elements in elements
elementsContinuous array of num uint64_t elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1095 of file pq_query_helper.c.

1099{
1100 Oid oid;
1101
1104 "int8",
1105 &oid));
1106 return query_param_array_generic (num,
1107 true,
1108 elements,
1109 NULL,
1110 sizeof(uint64_t),
1112 oid);
1113}

References array_of_uint64, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_bytes()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bytes ( unsigned int  num,
const void *  elements,
const size_t *  sizes,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of buffers elements, each of corresponding size given in sizes.

Parameters
numNumber of elements in elements
elementsContinuous array of num buffers, each of corresponding size given in sizes.
sizesPointer to sizes in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1117 of file pq_query_helper.c.

1122{
1123 Oid oid;
1124
1127 "bytea",
1128 &oid));
1129 return query_param_array_generic (num,
1130 true,
1131 elements,
1132 sizes,
1133 0,
1135 oid);
1136}

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_bytes()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes ( unsigned int  num,
const void *  elements[static num],
const size_t *  sizes,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of buffers elements, with sizes sizes.

Parameters
numNumber of elements in elements
elementsContinuous array of num buffers, each with the same size same_size
sizesSizes in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1140 of file pq_query_helper.c.

1145{
1146 Oid oid;
1147
1150 "bytea",
1151 &oid));
1152 return query_param_array_generic (num,
1153 false,
1154 elements,
1155 sizes,
1156 0,
1158 oid);
1159}

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_bytes_same_size()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_bytes_same_size ( unsigned int  num,
const void *  elements,
size_t  same_size,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of buffers elements, each of the same size size.

Parameters
numNumber of elements in elements
elementsContinuous array of num buffers, each with the same size same_size
same_sizeSize in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1163 of file pq_query_helper.c.

1168{
1169 Oid oid;
1170
1173 "bytea",
1174 &oid));
1175 return query_param_array_generic (num,
1176 true,
1177 elements,
1178 NULL,
1179 same_size,
1181 oid);
1182}

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_bytes_same_size()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_bytes_same_size ( unsigned int  num,
const void *  elements[static num],
size_t  same_size,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of pointers to buffers elements, each of the same size size.

Parameters
numNumber of elements in elements
elementsArray of num pointers to buffers, each with the same size same_size
same_sizeSize in bytes of each element in elements
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1186 of file pq_query_helper.c.

1191{
1192 Oid oid;
1193
1196 "bytea",
1197 &oid));
1198 return query_param_array_generic (num,
1199 false,
1200 elements,
1201 NULL,
1202 same_size,
1204 oid);
1205}

References array_of_byte, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_string()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_string ( unsigned int  num,
const char *  elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of strings (continuous)

Parameters
numNumber of elements in elements
elementsArray of num continuous strings (zero-terminated each)
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1209 of file pq_query_helper.c.

1213{
1214 Oid oid;
1215
1218 "text",
1219 &oid));
1220 return query_param_array_generic (num,
1221 true,
1222 elements,
1223 NULL,
1224 0,
1226 oid);
1227}

References array_of_string, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_string()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_string ( unsigned int  num,
const char *  elements[static num],
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of strings (pointers)

Parameters
numNumber of elements in elements
elementsArray of num pointer to strings
dbDatabase context, needed for database-depending encoding of elements
Returns
query parameter to use

Definition at line 1231 of file pq_query_helper.c.

1235{
1236 Oid oid;
1237
1240 "text",
1241 &oid));
1242 return query_param_array_generic (num,
1243 false,
1244 elements,
1245 NULL,
1246 0,
1248 oid);
1249}

References array_of_string, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_abs_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_abs_time ( unsigned int  num,
const struct GNUNET_TIME_Absolute elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of absolute time stamps (continuous)

Parameters
numNumber of elements in elements
elementsArray of num absolute timestamps
Returns
query parameter to use

Definition at line 1253 of file pq_query_helper.c.

1257{
1258 Oid oid;
1259
1262 "int8",
1263 &oid));
1264 return query_param_array_generic (num,
1265 true,
1266 elements,
1267 NULL,
1268 sizeof(struct GNUNET_TIME_Absolute),
1270 oid);
1271}

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_abs_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_abs_time ( unsigned int  num,
const struct GNUNET_TIME_Absolute elements[],
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of absolute time stamps (pointers)

Parameters
numNumber of elements in elements
elementsArray of num pointers to absolute timestamps
Returns
query parameter to use

Definition at line 1275 of file pq_query_helper.c.

1279{
1280 Oid oid;
1281
1284 "int8",
1285 &oid));
1286 return query_param_array_generic (num,
1287 false,
1288 elements,
1289 NULL,
1290 sizeof(struct GNUNET_TIME_Absolute),
1292 oid);
1293}

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_rel_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_rel_time ( unsigned int  num,
const struct GNUNET_TIME_Relative elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of relative time stamps (continuous)

Parameters
numNumber of elements in elements
elementsArray of num relative timestamps
Returns
query parameter to use

Definition at line 1297 of file pq_query_helper.c.

1301{
1302 Oid oid;
1303
1306 "int8",
1307 &oid));
1308 return query_param_array_generic (num,
1309 true,
1310 elements,
1311 NULL,
1312 sizeof(struct GNUNET_TIME_Relative),
1314 oid);
1315}

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_rel_time()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_rel_time ( unsigned int  num,
const struct GNUNET_TIME_Relative elements[],
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of relative time stamps (pointers)

Parameters
numNumber of elements in elements
elementsArray of num pointers to relative timestamps
Returns
query parameter to use

Definition at line 1319 of file pq_query_helper.c.

1323{
1324 Oid oid;
1325
1328 "int8",
1329 &oid));
1330 return query_param_array_generic (num,
1331 false,
1332 elements,
1333 NULL,
1334 sizeof(struct GNUNET_TIME_Relative),
1336 oid);
1337}

References array_of_abs_time, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_timestamp()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_timestamp ( unsigned int  num,
const struct GNUNET_TIME_Timestamp elements,
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of time stamps (continuous)

Parameters
numNumber of elements in elements
elementsArray of num timestamps
Returns
query parameter to use

Definition at line 1341 of file pq_query_helper.c.

1345{
1346 Oid oid;
1347
1350 "int8",
1351 &oid));
1352 return query_param_array_generic (num,
1353 true,
1354 elements,
1355 NULL,
1356 sizeof(struct GNUNET_TIME_Timestamp),
1358 oid);
1359}

References array_of_timestamp, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ GNUNET_PQ_query_param_array_ptrs_timestamp()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_ptrs_timestamp ( unsigned int  num,
const struct GNUNET_TIME_Timestamp elements[],
struct GNUNET_PQ_Context db 
)

Generate query parameter for an array of time stamps (pointers)

Parameters
numNumber of elements in elements
elementsArray of num pointers to relative timestamps
Returns
query parameter to use

Definition at line 1363 of file pq_query_helper.c.

1367{
1368 Oid oid;
1369
1372 "int8",
1373 &oid));
1374 return query_param_array_generic (num,
1375 false,
1376 elements,
1377 NULL,
1378 sizeof(struct GNUNET_TIME_Timestamp),
1380 oid);
1381}

References array_of_timestamp, db, GNUNET_assert, GNUNET_OK, GNUNET_PQ_get_oid_by_name(), GNUNET_PQ_Context::num, oid, and query_param_array_generic().

Here is the call graph for this function:

◆ qconv_blind_sign_pub()

static int qconv_blind_sign_pub ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 1399 of file pq_query_helper.c.

1408{
1409 const struct GNUNET_CRYPTO_BlindSignPublicKey *public_key = data;
1410 size_t tlen;
1411 size_t len;
1412 uint32_t be;
1413 char *buf;
1414 void *tbuf;
1415
1416 (void) cls;
1417 (void) data_len;
1418 GNUNET_assert (1 == param_length);
1419 GNUNET_assert (scratch_length > 0);
1420 GNUNET_break (NULL == cls);
1421 be = htonl ((uint32_t) public_key->cipher);
1422 switch (public_key->cipher)
1423 {
1426 public_key->details.rsa_public_key,
1427 &tbuf);
1428 break;
1430 tlen = sizeof (public_key->details.cs_public_key);
1431 break;
1432 default:
1433 GNUNET_assert (0);
1434 }
1435 len = tlen + sizeof (be);
1436 buf = GNUNET_malloc (len);
1437 GNUNET_memcpy (buf,
1438 &be,
1439 sizeof (be));
1440 switch (public_key->cipher)
1441 {
1443 GNUNET_memcpy (&buf[sizeof (be)],
1444 tbuf,
1445 tlen);
1446 GNUNET_free (tbuf);
1447 break;
1449 GNUNET_memcpy (&buf[sizeof (be)],
1450 &public_key->details.cs_public_key,
1451 tlen);
1452 break;
1453 default:
1454 GNUNET_assert (0);
1455 }
1456
1457 scratch[0] = buf;
1458 param_values[0] = (void *) buf;
1459 param_lengths[0] = len;
1460 param_formats[0] = 1;
1461 return 1;
1462}
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
Type of public signing keys for blind signatures.
union GNUNET_CRYPTO_BlindSignPublicKey::@16 details
Details, depending on cipher.
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, data, GNUNET_CRYPTO_BlindSignPublicKey::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, and GNUNET_CRYPTO_BlindSignPublicKey::rsa_public_key.

Referenced by GNUNET_PQ_query_param_blind_sign_pub().

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

◆ GNUNET_PQ_query_param_blind_sign_pub()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_pub ( const struct GNUNET_CRYPTO_BlindSignPublicKey pub)

Generate query parameter for a blind sign public key of variable size.

Generate query parameter for a blind sign public key.

Parameters
pubpointer to the query parameter to pass

Definition at line 1471 of file pq_query_helper.c.

1473{
1474 struct GNUNET_PQ_QueryParam res = {
1475 .conv = &qconv_blind_sign_pub,
1476 .data = pub,
1477 .num_params = 1
1478 };
1479
1480 return res;
1481}
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
static int qconv_blind_sign_pub(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References pub, qconv_blind_sign_pub(), and res.

Here is the call graph for this function:

◆ qconv_blind_sign_priv()

static int qconv_blind_sign_priv ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 1499 of file pq_query_helper.c.

1508{
1509 const struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key = data;
1510 size_t tlen;
1511 size_t len;
1512 uint32_t be;
1513 char *buf;
1514 void *tbuf;
1515
1516 (void) cls;
1517 (void) data_len;
1518 GNUNET_assert (1 == param_length);
1519 GNUNET_assert (scratch_length > 0);
1520 GNUNET_break (NULL == cls);
1521 be = htonl ((uint32_t) private_key->cipher);
1522 switch (private_key->cipher)
1523 {
1526 private_key->details.rsa_private_key,
1527 &tbuf);
1528 break;
1530 tlen = sizeof (private_key->details.cs_private_key);
1531 break;
1532 default:
1533 GNUNET_assert (0);
1534 }
1535 len = tlen + sizeof (be);
1536 buf = GNUNET_malloc (len);
1537 GNUNET_memcpy (buf,
1538 &be,
1539 sizeof (be));
1540 switch (private_key->cipher)
1541 {
1543 GNUNET_memcpy (&buf[sizeof (be)],
1544 tbuf,
1545 tlen);
1546 GNUNET_free (tbuf);
1547 break;
1549 GNUNET_memcpy (&buf[sizeof (be)],
1550 &private_key->details.cs_private_key,
1551 tlen);
1552 break;
1553 default:
1554 GNUNET_assert (0);
1555 }
1556
1557 scratch[0] = buf;
1558 param_values[0] = (void *) buf;
1559 param_lengths[0] = len;
1560 param_formats[0] = 1;
1561 return 1;
1562}
size_t GNUNET_CRYPTO_rsa_private_key_encode(const struct GNUNET_CRYPTO_RsaPrivateKey *key, void **buffer)
Encode the private key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:181
Type of private signing keys for blind signing.
struct GNUNET_CRYPTO_CsPrivateKey cs_private_key
If we use GNUNET_CRYPTO_BSA_CS in cipher.
struct GNUNET_CRYPTO_RsaPrivateKey * rsa_private_key
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the public key.
union GNUNET_CRYPTO_BlindSignPrivateKey::@17 details
Details, depending on cipher.

References GNUNET_CRYPTO_BlindSignPrivateKey::cipher, GNUNET_CRYPTO_BlindSignPrivateKey::cs_private_key, data, GNUNET_CRYPTO_BlindSignPrivateKey::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_private_key_encode(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, and GNUNET_CRYPTO_BlindSignPrivateKey::rsa_private_key.

Referenced by GNUNET_PQ_query_param_blind_sign_priv().

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

◆ GNUNET_PQ_query_param_blind_sign_priv()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blind_sign_priv ( const struct GNUNET_CRYPTO_BlindSignPrivateKey priv)

Generate query parameter for a blind sign private key of variable size.

Parameters
privpointer to the query parameter to pass

Definition at line 1571 of file pq_query_helper.c.

1573{
1574 struct GNUNET_PQ_QueryParam res = {
1575 .conv = &qconv_blind_sign_priv,
1576 .data = priv,
1577 .num_params = 1
1578 };
1579
1580 return res;
1581}
static int qconv_blind_sign_priv(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_blind_sign_priv(), and res.

Here is the call graph for this function:

◆ qconv_unblinded_sig()

static int qconv_unblinded_sig ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 1599 of file pq_query_helper.c.

1608{
1609 const struct GNUNET_CRYPTO_UnblindedSignature *ubs = data;
1610 size_t tlen;
1611 size_t len;
1612 uint32_t be[2];
1613 char *buf;
1614 void *tbuf;
1615
1616 (void) cls;
1617 (void) data_len;
1618 GNUNET_assert (1 == param_length);
1619 GNUNET_assert (scratch_length > 0);
1620 GNUNET_break (NULL == cls);
1621 be[0] = htonl ((uint32_t) ubs->cipher);
1622 be[1] = htonl (0x00); /* magic marker: unblinded */
1623 switch (ubs->cipher)
1624 {
1628 &tbuf);
1629 break;
1631 tlen = sizeof (ubs->details.cs_signature);
1632 break;
1633 default:
1634 GNUNET_assert (0);
1635 }
1636 len = tlen + sizeof (be);
1637 buf = GNUNET_malloc (len);
1638 GNUNET_memcpy (buf,
1639 &be,
1640 sizeof (be));
1641 switch (ubs->cipher)
1642 {
1644 GNUNET_memcpy (&buf[sizeof (be)],
1645 tbuf,
1646 tlen);
1647 GNUNET_free (tbuf);
1648 break;
1650 GNUNET_memcpy (&buf[sizeof (be)],
1651 &ubs->details.cs_signature,
1652 tlen);
1653 break;
1654 default:
1655 GNUNET_assert (0);
1656 }
1657
1658 scratch[0] = buf;
1659 param_values[0] = (void *) buf;
1660 param_lengths[0] = len;
1661 param_formats[0] = 1;
1662 return 1;
1663}
Type of (unblinded) signatures.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.

References GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_CRYPTO_UnblindedSignature::cs_signature, data, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_malloc, GNUNET_memcpy, and GNUNET_CRYPTO_UnblindedSignature::rsa_signature.

Referenced by GNUNET_PQ_query_param_unblinded_sig().

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

◆ GNUNET_PQ_query_param_unblinded_sig()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_unblinded_sig ( const struct GNUNET_CRYPTO_UnblindedSignature sig)

Generate query parameter for an unblinded signature of variable size.

Parameters
sigpointer to the query parameter to pass

Definition at line 1672 of file pq_query_helper.c.

1674{
1675 struct GNUNET_PQ_QueryParam res = {
1676 .conv = &qconv_unblinded_sig,
1677 .data = sig,
1678 .num_params = 1
1679 };
1680
1681 return res;
1682}
static int qconv_unblinded_sig(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_unblinded_sig(), and res.

Here is the call graph for this function:

◆ qconv_blinded_sig()

static int qconv_blinded_sig ( void *  cls,
const void *  data,
size_t  data_len,
void *  param_values[],
int  param_lengths[],
int  param_formats[],
unsigned int  param_length,
void *  scratch[],
unsigned int  scratch_length 
)
static

Function called to convert input argument into SQL parameters.

Parameters
clsclosure
datapointer to input argument
data_lennumber of bytes in data (if applicable)
[out]param_valuesSQL data to set
[out]param_lengthsSQL length data to set
[out]param_formatsSQL format data to set
param_lengthnumber of entries available in the param_values, param_lengths and param_formats arrays
[out]scratchbuffer for dynamic allocations (to be done via GNUNET_malloc()
scratch_lengthnumber of entries left in scratch
Returns
-1 on error, number of offsets used in scratch otherwise

Definition at line 1700 of file pq_query_helper.c.

1709{
1710 const struct GNUNET_CRYPTO_BlindedSignature *bs = data;
1711 size_t tlen;
1712 size_t len;
1713 uint32_t be[2];
1714 char *buf;
1715 void *tbuf;
1716
1717 (void) cls;
1718 (void) data_len;
1719 GNUNET_assert (1 == param_length);
1720 GNUNET_assert (scratch_length > 0);
1721 GNUNET_break (NULL == cls);
1722 be[0] = htonl ((uint32_t) bs->cipher);
1723 be[1] = htonl (0x01); /* magic marker: blinded */
1724 switch (bs->cipher)
1725 {
1729 &tbuf);
1730 break;
1732 tlen = sizeof (bs->details.blinded_cs_answer);
1733 break;
1734 default:
1735 GNUNET_assert (0);
1736 }
1737 len = tlen + sizeof (be);
1738 buf = GNUNET_malloc (len);
1739 GNUNET_memcpy (buf,
1740 &be,
1741 sizeof (be));
1742 switch (bs->cipher)
1743 {
1745 GNUNET_memcpy (&buf[sizeof (be)],
1746 tbuf,
1747 tlen);
1748 GNUNET_free (tbuf);
1749 break;
1751 GNUNET_memcpy (&buf[sizeof (be)],
1753 tlen);
1754 break;
1755 default:
1756 GNUNET_assert (0);
1757 }
1758
1759 scratch[0] = buf;
1760 param_values[0] = (void *) buf;
1761 param_lengths[0] = len;
1762 param_formats[0] = 1;
1763 return 1;
1764}
Type for blinded signatures.
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.

References GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, data, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_RSA, GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_malloc, and GNUNET_memcpy.

Referenced by GNUNET_PQ_query_param_blinded_sig().

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

◆ GNUNET_PQ_query_param_blinded_sig()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_blinded_sig ( const struct GNUNET_CRYPTO_BlindedSignature b_sig)

Generate query parameter for a blinded signature of variable size.

Parameters
b_sigpointer to the query parameter to pass

Definition at line 1773 of file pq_query_helper.c.

1775{
1776 struct GNUNET_PQ_QueryParam res = {
1777 .conv = &qconv_blinded_sig,
1778 .data = b_sig,
1779 .num_params = 1
1780 };
1781
1782 return res;
1783}
static int qconv_blinded_sig(void *cls, const void *data, size_t data_len, void *param_values[], int param_lengths[], int param_formats[], unsigned int param_length, void *scratch[], unsigned int scratch_length)
Function called to convert input argument into SQL parameters.

References qconv_blinded_sig(), and res.

Here is the call graph for this function: