GNUnet 0.24.1-15-gab6ed22f1
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_int16 (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_int16 (const int16_t *x)
 Generate query parameter for an int16_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 check_patch_applied(), GNUNET_PQ_get_oid_by_name(), 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_int16()

static int qconv_int16 ( 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 int16_t *u_hbo = data;
351 int16_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 (int16_t);
359 scratch[0] = u_nbo;
360 *u_nbo = GNUNET_htobe16 (*u_hbo);
361 param_values[0] = (void *) u_nbo;
362 param_lengths[0] = sizeof(int16_t);
363 param_formats[0] = 1;
364 return 1;
365}
#define GNUNET_htobe16(x)

References data, GNUNET_break, GNUNET_htobe16, and GNUNET_new.

Referenced by GNUNET_PQ_query_param_int16().

Here is the caller graph for this function:

◆ GNUNET_PQ_query_param_int16()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int16 ( const int16_t *  x)

Generate query parameter for an int16_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_int16,
373 .data = x,
374 .size = sizeof(*x),
375 .num_params = 1
376 };
377
378 return res;
379}
static int qconv_int16(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_int16(), and res.

Here is the call 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 397 of file pq_query_helper.c.

406{
407 const int64_t *u_hbo = data;
408 int64_t *u_nbo;
409
410 (void) scratch;
411 (void) scratch_length;
412 GNUNET_break (NULL == cls);
413 if (1 != param_length)
414 return -1;
415 u_nbo = GNUNET_new (int64_t);
416 scratch[0] = u_nbo;
417 *u_nbo = GNUNET_htonll (*u_hbo);
418 param_values[0] = (void *) u_nbo;
419 param_lengths[0] = sizeof(int64_t);
420 param_formats[0] = 1;
421 return 1;
422}

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 426 of file pq_query_helper.c.

427{
428 struct GNUNET_PQ_QueryParam res = {
429 .conv = &qconv_int64,
430 .data = x,
431 .size = sizeof(*x),
432 .num_params = 1
433 };
434
435 return res;
436}
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 454 of file pq_query_helper.c.

463{
464 const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
465 void *buf;
466 size_t buf_size;
467
468 GNUNET_break (NULL == cls);
469 if (1 != param_length)
470 return -1;
472 &buf);
473 scratch[0] = buf;
474 param_values[0] = (void *) buf;
475 param_lengths[0] = buf_size;
476 param_formats[0] = 1;
477 return 1;
478}
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 482 of file pq_query_helper.c.

484{
485 struct GNUNET_PQ_QueryParam res = {
486 .conv = &qconv_rsa_public_key,
487 .data = x,
488 .num_params = 1
489 };
490
491 return res;
492}
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 510 of file pq_query_helper.c.

519{
520 const struct GNUNET_CRYPTO_RsaSignature *sig = data;
521 void *buf;
522 size_t buf_size;
523
524 GNUNET_break (NULL == cls);
525 if (1 != param_length)
526 return -1;
528 &buf);
529 scratch[0] = buf;
530 param_values[0] = (void *) buf;
531 param_lengths[0] = buf_size;
532 param_formats[0] = 1;
533 return 1;
534}
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 538 of file pq_query_helper.c.

539{
540 struct GNUNET_PQ_QueryParam res = {
541 .conv = &qconv_rsa_signature,
542 .data = x,
543 .num_params = 1
544 };
545
546 return res;
547}
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 565 of file pq_query_helper.c.

574{
575 const struct GNUNET_TIME_Relative *u = data;
576 struct GNUNET_TIME_Relative rel;
577 uint64_t *u_nbo;
578
579 GNUNET_break (NULL == cls);
580 if (1 != param_length)
581 return -1;
582 rel = *u;
583 if (rel.rel_value_us > INT64_MAX)
584 rel.rel_value_us = INT64_MAX;
585 u_nbo = GNUNET_new (uint64_t);
586 scratch[0] = u_nbo;
587 *u_nbo = GNUNET_htonll (rel.rel_value_us);
588 param_values[0] = (void *) u_nbo;
589 param_lengths[0] = sizeof(uint64_t);
590 param_formats[0] = 1;
591 return 1;
592}
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 596 of file pq_query_helper.c.

597{
598 struct GNUNET_PQ_QueryParam res = {
599 .conv = &qconv_rel_time,
600 .data = x,
601 .size = sizeof(*x),
602 .num_params = 1
603 };
604
605 return res;
606}
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 624 of file pq_query_helper.c.

633{
634 const struct GNUNET_TIME_Absolute *u = data;
635 struct GNUNET_TIME_Absolute abs;
636 uint64_t *u_nbo;
637
638 GNUNET_break (NULL == cls);
639 if (1 != param_length)
640 return -1;
641 abs = *u;
642 if (abs.abs_value_us > INT64_MAX)
643 abs.abs_value_us = INT64_MAX;
644 u_nbo = GNUNET_new (uint64_t);
645 scratch[0] = u_nbo;
646 *u_nbo = GNUNET_htonll (abs.abs_value_us);
647 param_values[0] = (void *) u_nbo;
648 param_lengths[0] = sizeof(uint64_t);
649 param_formats[0] = 1;
650 return 1;
651}
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 655 of file pq_query_helper.c.

656{
657 struct GNUNET_PQ_QueryParam res = {
658 .conv = &qconv_abs_time,
659 .data = x,
660 .size = sizeof(*x),
661 .num_params = 1
662 };
663
664 return res;
665}
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 669 of file pq_query_helper.c.

671{
673}
#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 677 of file pq_query_helper.c.

678{
680}
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 684 of file pq_query_helper.c.

686{
688}
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 736 of file pq_query_helper.c.

737{
738 GNUNET_free (cls);
739}
#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 761 of file pq_query_helper.c.

771{
772 struct qconv_array_cls *meta = cls;
773 size_t num = data_len;
774 size_t total_size;
775 const size_t *sizes;
776 bool same_sized;
777 size_t *string_lengths = NULL;
778 void *elements = NULL;
779 bool noerror = true;
780
781 (void) (param_length);
782 (void) (scratch_length);
783
784 GNUNET_assert (NULL != meta);
785 GNUNET_assert (num < INT_MAX);
786
787 sizes = meta->sizes;
788 same_sized = (0 != meta->same_size);
789
790#define RETURN_UNLESS(cond) \
791 do { \
792 if (! (cond)) \
793 { \
794 GNUNET_break ((cond)); \
795 noerror = false; \
796 goto DONE; \
797 } \
798 } while (0)
799
800 /* Calculate sizes and check bounds */
801 {
802 /* num * length-field */
803 size_t x = sizeof(uint32_t);
804 size_t y = x * num;
805 RETURN_UNLESS ((0 == num) || (y / num == x));
806
807 /* size of header */
808 total_size = x = sizeof(struct pq_array_header);
809 total_size += y;
810 RETURN_UNLESS (total_size >= x);
811
812 /* sizes of elements */
813 if (same_sized)
814 {
815 x = num * meta->same_size;
816 RETURN_UNLESS ((0 == num) || (x / num == meta->same_size));
817
818 y = total_size;
819 total_size += x;
820 RETURN_UNLESS (total_size >= y);
821 }
822 else /* sizes are different per element */
823 {
824 /* for an array of strings we need to get their length's first */
825 if (array_of_string == meta->typ)
826 {
827 string_lengths = GNUNET_new_array (num, size_t);
828
829 if (meta->continuous)
830 {
831 const char *ptr = data;
832 for (unsigned int i = 0; i < num; i++)
833 {
834 size_t len = strlen (ptr);
835 string_lengths[i] = len;
836 ptr += len + 1;
837 }
838 }
839 else
840 {
841 const char **str = (const char **) data;
842 for (unsigned int i = 0; i < num; i++)
843 string_lengths[i] = strlen (str[i]);
844 }
845
846 sizes = string_lengths;
847 }
848
849 for (unsigned int i = 0; i < num; i++)
850 {
851 x = total_size;
852 total_size += sizes[i];
853 RETURN_UNLESS (total_size >= x);
854 }
855 }
856
857 RETURN_UNLESS (total_size < INT_MAX);
858
859 elements = GNUNET_malloc (total_size);
860 }
861
862 /* Write data */
863 {
864 char *in = (char *) data;
865 char *out = elements;
866 size_t nullbyte = (array_of_string == meta->typ) ? 1 : 0;
867 struct pq_array_header h = {
868 .ndim = htonl (1), /* We only support one-dimensional arrays */
869 .has_null = htonl (0), /* We do not support NULL entries in arrays */
870 .lbound = htonl (1), /* Default start index value */
871 .dim = htonl (num),
872 .oid = htonl (meta->oid),
873 };
874
875 /* Write header */
876 GNUNET_memcpy (out, &h, sizeof(h));
877 out += sizeof(h);
878
879
880 /* Write elements */
881 for (unsigned int i = 0; i < num; i++)
882 {
883 size_t sz = same_sized ? meta->same_size : sizes[i];
884 uint32_t hsz = htonl (sz);
885
886 GNUNET_memcpy (out,
887 &hsz,
888 sizeof(hsz));
889 out += sizeof(uint32_t);
890
891 switch (meta->typ)
892 {
893 case array_of_bool:
894 {
895 GNUNET_assert (sizeof(bool) == sz);
896 *(bool *) out = (*(bool *) in);
897 in += sz;
898 break;
899 }
900 case array_of_uint16:
901 {
902 GNUNET_assert (sizeof(uint16_t) == sz);
903 *(uint16_t *) out = htons (*(uint16_t *) in);
904 in += sz;
905 break;
906 }
907 case array_of_uint32:
908 {
909 uint32_t v;
910 GNUNET_assert (sizeof(uint32_t) == sz);
911
912 v = htonl (*(uint32_t *) in);
913 GNUNET_memcpy (out,
914 &v,
915 sizeof(v));
916 in += sz;
917 break;
918 }
919 case array_of_uint64:
920 {
921 uint64_t tmp;
922 GNUNET_assert (sizeof(uint64_t) == sz);
923
924 tmp = GNUNET_htonll (*(uint64_t *) in);
925 GNUNET_memcpy (out,
926 &tmp,
927 sizeof(tmp));
928 in += sz;
929 break;
930 }
931 case array_of_byte:
932 case array_of_string:
933 {
934 const void *ptr;
935
936 if (meta->continuous)
937 {
938 ptr = in;
939 in += sz + nullbyte;
940 }
941 else
942 ptr = ((const void **) data)[i];
943
944 GNUNET_memcpy (out,
945 ptr,
946 sz);
947 break;
948 }
952 {
953 uint64_t val;
954
955 switch (meta->typ)
956 {
958 {
959 const struct GNUNET_TIME_Absolute *abs =
960 (const struct GNUNET_TIME_Absolute *) in;
961
962 GNUNET_assert (sizeof(struct GNUNET_TIME_Absolute) == sz);
963
964 if (! meta->continuous)
965 abs = ((const struct GNUNET_TIME_Absolute **) data)[i];
966
967 val = abs->abs_value_us;
968 break;
969 }
971 {
972 const struct GNUNET_TIME_Relative *rel =
973 (const struct GNUNET_TIME_Relative *) in;
974
975 GNUNET_assert (sizeof(struct GNUNET_TIME_Relative) == sz);
976
977 if (! meta->continuous)
978 rel = ((const struct GNUNET_TIME_Relative **) data)[i];
979
980 val = rel->rel_value_us;
981 break;
982 }
984 {
985 const struct GNUNET_TIME_Timestamp *ts =
986 (const struct GNUNET_TIME_Timestamp *) in;
987
988 GNUNET_assert (sizeof(struct GNUNET_TIME_Timestamp) == sz);
989
990 if (! meta->continuous)
991 ts = ((const struct GNUNET_TIME_Timestamp **) data)[i];
992
993 val = ts->abs_time.abs_value_us;
994 break;
995 }
996 default:
997 {
998 GNUNET_assert (0);
999 }
1000 }
1001
1002 if (val > INT64_MAX)
1003 val = INT64_MAX;
1004
1005 val = GNUNET_htonll (val);
1006 GNUNET_memcpy (out,
1007 &val,
1008 sizeof(val));
1009
1010 if (meta->continuous)
1011 in += sz;
1012
1013 break;
1014 }
1015 default:
1016 {
1017 GNUNET_assert (0);
1018 break;
1019 }
1020 }
1021 out += sz;
1022 }
1023 }
1024
1025 param_values[0] = elements;
1026 param_lengths[0] = total_size;
1027 param_formats[0] = 1;
1028 scratch[0] = elements;
1029
1030DONE:
1031 GNUNET_free (string_lengths);
1032
1033 if (noerror)
1034 return 1;
1035
1036 return -1;
1037}
#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: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 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:167
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 1053 of file pq_query_helper.c.

1061{
1063
1064 meta->typ = typ;
1065 meta->oid = oid;
1066 meta->sizes = sizes;
1067 meta->same_size = same_size;
1068 meta->continuous = continuous;
1069
1070 {
1071 struct GNUNET_PQ_QueryParam res = {
1072 .conv = qconv_array,
1073 .conv_cls = meta,
1074 .conv_cls_cleanup = &qconv_array_cls_cleanup,
1075 .data = elements,
1076 .size = num,
1077 .num_params = 1,
1078 };
1079
1080 return res;
1081 }
1082}
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 1086 of file pq_query_helper.c.

1090{
1091 Oid oid;
1092
1095 "bool",
1096 &oid));
1097 return query_param_array_generic (num,
1098 true,
1099 elements,
1100 NULL,
1101 sizeof(bool),
1103 oid);
1104}
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
@ 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 1108 of file pq_query_helper.c.

1112{
1113 Oid oid;
1114
1117 "int2",
1118 &oid));
1119 return query_param_array_generic (num,
1120 true,
1121 elements,
1122 NULL,
1123 sizeof(uint16_t),
1125 oid);
1126}

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 1130 of file pq_query_helper.c.

1134{
1135 Oid oid;
1136
1139 "int4",
1140 &oid));
1141 return query_param_array_generic (num,
1142 true,
1143 elements,
1144 NULL,
1145 sizeof(uint32_t),
1147 oid);
1148}

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 1152 of file pq_query_helper.c.

1156{
1157 Oid oid;
1158
1161 "int8",
1162 &oid));
1163 return query_param_array_generic (num,
1164 true,
1165 elements,
1166 NULL,
1167 sizeof(uint64_t),
1169 oid);
1170}

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 1174 of file pq_query_helper.c.

1179{
1180 Oid oid;
1181
1184 "bytea",
1185 &oid));
1186 return query_param_array_generic (num,
1187 true,
1188 elements,
1189 sizes,
1190 0,
1192 oid);
1193}

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 1197 of file pq_query_helper.c.

1202{
1203 Oid oid;
1204
1207 "bytea",
1208 &oid));
1209 return query_param_array_generic (num,
1210 false,
1211 elements,
1212 sizes,
1213 0,
1215 oid);
1216}

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 1220 of file pq_query_helper.c.

1225{
1226 Oid oid;
1227
1230 "bytea",
1231 &oid));
1232 return query_param_array_generic (num,
1233 true,
1234 elements,
1235 NULL,
1236 same_size,
1238 oid);
1239}

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 1243 of file pq_query_helper.c.

1248{
1249 Oid oid;
1250
1253 "bytea",
1254 &oid));
1255 return query_param_array_generic (num,
1256 false,
1257 elements,
1258 NULL,
1259 same_size,
1261 oid);
1262}

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 1266 of file pq_query_helper.c.

1270{
1271 Oid oid;
1272
1275 "text",
1276 &oid));
1277 return query_param_array_generic (num,
1278 true,
1279 elements,
1280 NULL,
1281 0,
1283 oid);
1284}

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 1288 of file pq_query_helper.c.

1292{
1293 Oid oid;
1294
1297 "text",
1298 &oid));
1299 return query_param_array_generic (num,
1300 false,
1301 elements,
1302 NULL,
1303 0,
1305 oid);
1306}

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 1310 of file pq_query_helper.c.

1314{
1315 Oid oid;
1316
1319 "int8",
1320 &oid));
1321 return query_param_array_generic (num,
1322 true,
1323 elements,
1324 NULL,
1325 sizeof(struct GNUNET_TIME_Absolute),
1327 oid);
1328}

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 1332 of file pq_query_helper.c.

1336{
1337 Oid oid;
1338
1341 "int8",
1342 &oid));
1343 return query_param_array_generic (num,
1344 false,
1345 elements,
1346 NULL,
1347 sizeof(struct GNUNET_TIME_Absolute),
1349 oid);
1350}

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 1354 of file pq_query_helper.c.

1358{
1359 Oid oid;
1360
1363 "int8",
1364 &oid));
1365 return query_param_array_generic (num,
1366 true,
1367 elements,
1368 NULL,
1369 sizeof(struct GNUNET_TIME_Relative),
1371 oid);
1372}

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 1376 of file pq_query_helper.c.

1380{
1381 Oid oid;
1382
1385 "int8",
1386 &oid));
1387 return query_param_array_generic (num,
1388 false,
1389 elements,
1390 NULL,
1391 sizeof(struct GNUNET_TIME_Relative),
1393 oid);
1394}

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 1398 of file pq_query_helper.c.

1402{
1403 Oid oid;
1404
1407 "int8",
1408 &oid));
1409 return query_param_array_generic (num,
1410 true,
1411 elements,
1412 NULL,
1413 sizeof(struct GNUNET_TIME_Timestamp),
1415 oid);
1416}

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 1420 of file pq_query_helper.c.

1424{
1425 Oid oid;
1426
1429 "int8",
1430 &oid));
1431 return query_param_array_generic (num,
1432 false,
1433 elements,
1434 NULL,
1435 sizeof(struct GNUNET_TIME_Timestamp),
1437 oid);
1438}

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 1456 of file pq_query_helper.c.

1465{
1466 const struct GNUNET_CRYPTO_BlindSignPublicKey *public_key = data;
1467 size_t tlen;
1468 size_t len;
1469 uint32_t be;
1470 char *buf;
1471 void *tbuf;
1472
1473 (void) cls;
1474 (void) data_len;
1475 GNUNET_assert (1 == param_length);
1476 GNUNET_assert (scratch_length > 0);
1477 GNUNET_break (NULL == cls);
1478 be = htonl ((uint32_t) public_key->cipher);
1479 switch (public_key->cipher)
1480 {
1483 public_key->details.rsa_public_key,
1484 &tbuf);
1485 break;
1487 tlen = sizeof (public_key->details.cs_public_key);
1488 break;
1489 default:
1490 GNUNET_assert (0);
1491 }
1492 len = tlen + sizeof (be);
1493 buf = GNUNET_malloc (len);
1494 GNUNET_memcpy (buf,
1495 &be,
1496 sizeof (be));
1497 switch (public_key->cipher)
1498 {
1500 GNUNET_memcpy (&buf[sizeof (be)],
1501 tbuf,
1502 tlen);
1503 GNUNET_free (tbuf);
1504 break;
1506 GNUNET_memcpy (&buf[sizeof (be)],
1507 &public_key->details.cs_public_key,
1508 tlen);
1509 break;
1510 default:
1511 GNUNET_assert (0);
1512 }
1513
1514 scratch[0] = buf;
1515 param_values[0] = (void *) buf;
1516 param_lengths[0] = len;
1517 param_formats[0] = 1;
1518 return 1;
1519}
@ 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 1528 of file pq_query_helper.c.

1530{
1531 struct GNUNET_PQ_QueryParam res = {
1532 .conv = &qconv_blind_sign_pub,
1533 .data = pub,
1534 .num_params = 1
1535 };
1536
1537 return res;
1538}
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 1556 of file pq_query_helper.c.

1565{
1566 const struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key = data;
1567 size_t tlen;
1568 size_t len;
1569 uint32_t be;
1570 char *buf;
1571 void *tbuf;
1572
1573 (void) cls;
1574 (void) data_len;
1575 GNUNET_assert (1 == param_length);
1576 GNUNET_assert (scratch_length > 0);
1577 GNUNET_break (NULL == cls);
1578 be = htonl ((uint32_t) private_key->cipher);
1579 switch (private_key->cipher)
1580 {
1583 private_key->details.rsa_private_key,
1584 &tbuf);
1585 break;
1587 tlen = sizeof (private_key->details.cs_private_key);
1588 break;
1589 default:
1590 GNUNET_assert (0);
1591 }
1592 len = tlen + sizeof (be);
1593 buf = GNUNET_malloc (len);
1594 GNUNET_memcpy (buf,
1595 &be,
1596 sizeof (be));
1597 switch (private_key->cipher)
1598 {
1600 GNUNET_memcpy (&buf[sizeof (be)],
1601 tbuf,
1602 tlen);
1603 GNUNET_free (tbuf);
1604 break;
1606 GNUNET_memcpy (&buf[sizeof (be)],
1607 &private_key->details.cs_private_key,
1608 tlen);
1609 break;
1610 default:
1611 GNUNET_assert (0);
1612 }
1613
1614 scratch[0] = buf;
1615 param_values[0] = (void *) buf;
1616 param_lengths[0] = len;
1617 param_formats[0] = 1;
1618 return 1;
1619}
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 1628 of file pq_query_helper.c.

1630{
1631 struct GNUNET_PQ_QueryParam res = {
1632 .conv = &qconv_blind_sign_priv,
1633 .data = priv,
1634 .num_params = 1
1635 };
1636
1637 return res;
1638}
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 1656 of file pq_query_helper.c.

1665{
1666 const struct GNUNET_CRYPTO_UnblindedSignature *ubs = data;
1667 size_t tlen;
1668 size_t len;
1669 uint32_t be[2];
1670 char *buf;
1671 void *tbuf;
1672
1673 (void) cls;
1674 (void) data_len;
1675 GNUNET_assert (1 == param_length);
1676 GNUNET_assert (scratch_length > 0);
1677 GNUNET_break (NULL == cls);
1678 be[0] = htonl ((uint32_t) ubs->cipher);
1679 be[1] = htonl (0x00); /* magic marker: unblinded */
1680 switch (ubs->cipher)
1681 {
1685 &tbuf);
1686 break;
1688 tlen = sizeof (ubs->details.cs_signature);
1689 break;
1690 default:
1691 GNUNET_assert (0);
1692 }
1693 len = tlen + sizeof (be);
1694 buf = GNUNET_malloc (len);
1695 GNUNET_memcpy (buf,
1696 &be,
1697 sizeof (be));
1698 switch (ubs->cipher)
1699 {
1701 GNUNET_memcpy (&buf[sizeof (be)],
1702 tbuf,
1703 tlen);
1704 GNUNET_free (tbuf);
1705 break;
1707 GNUNET_memcpy (&buf[sizeof (be)],
1708 &ubs->details.cs_signature,
1709 tlen);
1710 break;
1711 default:
1712 GNUNET_assert (0);
1713 }
1714
1715 scratch[0] = buf;
1716 param_values[0] = (void *) buf;
1717 param_lengths[0] = len;
1718 param_formats[0] = 1;
1719 return 1;
1720}
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 1729 of file pq_query_helper.c.

1731{
1732 struct GNUNET_PQ_QueryParam res = {
1733 .conv = &qconv_unblinded_sig,
1734 .data = sig,
1735 .num_params = 1
1736 };
1737
1738 return res;
1739}
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 1757 of file pq_query_helper.c.

1766{
1767 const struct GNUNET_CRYPTO_BlindedSignature *bs = data;
1768 size_t tlen;
1769 size_t len;
1770 uint32_t be[2];
1771 char *buf;
1772 void *tbuf;
1773
1774 (void) cls;
1775 (void) data_len;
1776 GNUNET_assert (1 == param_length);
1777 GNUNET_assert (scratch_length > 0);
1778 GNUNET_break (NULL == cls);
1779 be[0] = htonl ((uint32_t) bs->cipher);
1780 be[1] = htonl (0x01); /* magic marker: blinded */
1781 switch (bs->cipher)
1782 {
1786 &tbuf);
1787 break;
1789 tlen = sizeof (bs->details.blinded_cs_answer);
1790 break;
1791 default:
1792 GNUNET_assert (0);
1793 }
1794 len = tlen + sizeof (be);
1795 buf = GNUNET_malloc (len);
1796 GNUNET_memcpy (buf,
1797 &be,
1798 sizeof (be));
1799 switch (bs->cipher)
1800 {
1802 GNUNET_memcpy (&buf[sizeof (be)],
1803 tbuf,
1804 tlen);
1805 GNUNET_free (tbuf);
1806 break;
1808 GNUNET_memcpy (&buf[sizeof (be)],
1810 tlen);
1811 break;
1812 default:
1813 GNUNET_assert (0);
1814 }
1815
1816 scratch[0] = buf;
1817 param_values[0] = (void *) buf;
1818 param_lengths[0] = len;
1819 param_formats[0] = 1;
1820 return 1;
1821}
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 1830 of file pq_query_helper.c.

1832{
1833 struct GNUNET_PQ_QueryParam res = {
1834 .conv = &qconv_blinded_sig,
1835 .data = b_sig,
1836 .num_params = 1
1837 };
1838
1839 return res;
1840}
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: