GNUnet 0.28.1-dev.4-8-g14b9efcb0
 
Loading...
Searching...
No Matches
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_null (void)
 Generate query parameter to create a NULL value.
 
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.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_string (const char *ptr)
 Generate query parameter for a string.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_bool (bool b)
 Pass a boolean into a query.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint16 (const uint16_t *x)
 Generate query parameter for an uint16_t in host byte order.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint32 (const uint32_t *x)
 Generate query parameter for an uint32_t in host byte order.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 (const uint64_t *x)
 Generate query parameter for an uint64_t in host byte order.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int16 (const int16_t *x)
 Generate query parameter for an int16_t in host byte order.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_int64 (const int64_t *x)
 Generate query parameter for an int64_t in host byte order.
 
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.
 
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.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *x)
 Generate query parameter for an RSA signature.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_relative_time (const struct GNUNET_TIME_Relative *x)
 Generate query parameter for a relative time value.
 
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.
 
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_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_PQ_QueryParam GNUNET_PQ_query_param_timestamp (const struct GNUNET_TIME_Timestamp *x)
 Generate query parameter for a timestamp.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_timestamp_nbo (const struct GNUNET_TIME_TimestampNBO *x)
 Generate query parameter for a timestamp in NBO.
 
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.
 
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.
 
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.
 
struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_int16 (unsigned int num, const int16_t *elements, struct GNUNET_PQ_Context *db)
 Generate query parameter for an array of int16_t in host byte order.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

Detailed Description

functions to initialize parameter arrays

Author
Christian Grothoff
Özgür Kesim

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

56{
57 (void) scratch;
58 (void) scratch_length;
59 (void) data;
60 (void) data_len;
61 GNUNET_break (NULL == cls);
62 if (1 != param_length)
63 return -1;
64 param_values[0] = NULL;
65 param_lengths[0] = 0;
66 param_formats[0] = 1;
67 return 0;
68}
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 72 of file pq_query_helper.c.

73{
74 struct GNUNET_PQ_QueryParam res = {
75 .conv = &qconv_null,
76 .num_params = 1
77 };
78
79 return res;
80}
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.
GNUNET_PQ_QueryConverter conv
Function for how to handle this type of entry.

References GNUNET_PQ_QueryParam::conv, 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 98 of file pq_query_helper.c.

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

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

123{
124 struct GNUNET_PQ_QueryParam res = {
125 .conv = &qconv_fixed,
126 .conv_cls = NULL,
127 .data = ptr,
128 .size = ptr_size,
129 .num_params = 1
130 };
131
132 return res;
133}
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 GNUNET_PQ_QueryParam::conv, 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(), 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 137 of file pq_query_helper.c.

138{
140 strlen (ptr));
141}
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 145 of file pq_query_helper.c.

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

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

179{
180 const uint16_t *u_hbo = data;
181 uint16_t *u_nbo;
182
183 (void) scratch;
184 (void) scratch_length;
185 GNUNET_break (NULL == cls);
186 if (1 != param_length)
187 return -1;
188 u_nbo = GNUNET_new (uint16_t);
189 scratch[0] = u_nbo;
190 *u_nbo = htons (*u_hbo);
191 param_values[0] = (void *) u_nbo;
192 param_lengths[0] = sizeof(uint16_t);
193 param_formats[0] = 1;
194 return 1;
195}
#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 199 of file pq_query_helper.c.

200{
201 struct GNUNET_PQ_QueryParam res = {
202 .conv = &qconv_uint16,
203 .data = x,
204 .size = sizeof(*x),
205 .num_params = 1
206 };
207
208 return res;
209}
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 GNUNET_PQ_QueryParam::conv, 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 227 of file pq_query_helper.c.

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

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

257{
258 struct GNUNET_PQ_QueryParam res = {
259 .conv = &qconv_uint32,
260 .data = x,
261 .size = sizeof(*x),
262 .num_params = 1
263 };
264
265 return res;
266}
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 GNUNET_PQ_QueryParam::conv, 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(), postgres_plugin_put(), 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 284 of file pq_query_helper.c.

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

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

314{
315 struct GNUNET_PQ_QueryParam res = {
316 .conv = &qconv_uint64,
317 .data = x,
318 .size = sizeof(*x),
319 .num_params = 1
320 };
321
322 return res;
323}
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 GNUNET_PQ_QueryParam::conv, 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 341 of file pq_query_helper.c.

350{
351 const int16_t *u_hbo = data;
352 int16_t *u_nbo;
353
354 (void) scratch;
355 (void) scratch_length;
356 GNUNET_break (NULL == cls);
357 if (1 != param_length)
358 return -1;
359 u_nbo = GNUNET_new (int16_t);
360 scratch[0] = u_nbo;
361 *u_nbo = GNUNET_htobe16 (*u_hbo);
362 param_values[0] = (void *) u_nbo;
363 param_lengths[0] = sizeof(int16_t);
364 param_formats[0] = 1;
365 return 1;
366}
#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 370 of file pq_query_helper.c.

371{
372 struct GNUNET_PQ_QueryParam res = {
373 .conv = &qconv_int16,
374 .data = x,
375 .size = sizeof(*x),
376 .num_params = 1
377 };
378
379 return res;
380}
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 GNUNET_PQ_QueryParam::conv, 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 398 of file pq_query_helper.c.

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

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

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

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

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

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

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

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

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

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

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

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

672{
674}
#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 678 of file pq_query_helper.c.

679{
681}
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 685 of file pq_query_helper.c.

687{
689}
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 737 of file pq_query_helper.c.

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

772{
773 struct qconv_array_cls *meta = cls;
774 size_t num = data_len;
775 size_t total_size;
776 const size_t *sizes;
777 bool same_sized;
778 size_t *string_lengths = NULL;
779 void *elements = NULL;
780 bool noerror = true;
781 bool has_nulls = false;
782 bool is_null[num];
783
784 (void) (param_length);
785 (void) (scratch_length);
786
787 GNUNET_assert (NULL != meta);
788 GNUNET_assert (num < INT_MAX);
789
790 sizes = meta->sizes;
791 same_sized = (0 != meta->same_size);
792 memset (is_null, 0, sizeof (is_null));
793
794#define RETURN_UNLESS(cond) \
795 do { \
796 if (! (cond)) \
797 { \
798 GNUNET_break ((cond)); \
799 noerror = false; \
800 goto DONE; \
801 } \
802 } while (0)
803
804 /* Calculate sizes and check bounds */
805 {
806 /* num * length-field */
807 size_t x = sizeof(uint32_t);
808 size_t y = x * num; /* for hsz headers of each element */
809
810 RETURN_UNLESS ((0 == num) || (y / num == x));
811
812 /* size of header */
813 total_size = x = sizeof(struct pq_array_header);
814 total_size += y;
815 RETURN_UNLESS (total_size >= x);
816
817 /* sizes of elements */
818 if (same_sized)
819 {
820 if (meta->continuous)
821 {
822 x = num * meta->same_size;
823 RETURN_UNLESS ((0 == num) || (x / num == meta->same_size));
824
825 y = total_size;
826 total_size += x;
827 RETURN_UNLESS (total_size >= y);
828 }
829 else
830 {
831 /* Not continuous, but same sized.
832 * There might be NULL pointers in the array, though. */
833 for (unsigned int i = 0; i < num; i++)
834 {
835 const void **ptr = (const void **) data;
836
837 if (NULL != ptr[i])
838 {
839 total_size += meta->same_size;
840 RETURN_UNLESS (total_size >= meta->same_size);
841 }
842 else
843 {
844 has_nulls = true;
845 is_null[i] = true;
846 }
847 }
848 }
849 }
850 else /* sizes are different per element, provided in sizes[] */
851 {
852 /* For an array of strings we need to get their length's first */
853 if (array_of_string == meta->typ)
854 {
855 string_lengths = GNUNET_new_array (num, size_t);
856
857 if (meta->continuous)
858 {
859 const char *ptr = data;
860
861 for (unsigned int i = 0; i < num; i++)
862 {
863 size_t len = strlen (ptr);
864
865 RETURN_UNLESS (len < INT_MAX);
866 string_lengths[i] = len;
867 ptr += len + 1;
868 }
869 }
870 else
871 {
872 const char **str = (const char **) data;
873
874 for (unsigned int i = 0; i < num; i++)
875 {
876 if (NULL != str[i])
877 {
878 size_t len = strlen (str[i]);
879
880 RETURN_UNLESS (len < INT_MAX);
881 string_lengths[i] = len;
882 }
883 else
884 {
885 has_nulls = true;
886 string_lengths[i] = 0;
887 is_null[i] = true;
888 }
889 }
890 }
891 sizes = string_lengths;
892 }
893 else
894 {
895 /* Ensure consistency between NULL elements and sizes */
896 for (unsigned int i = 0; i < num; i++)
897 {
898 const char **ptr = (const char **) data;
899
900 if (NULL == ptr[i])
901 {
902 RETURN_UNLESS (sizes[i] == 0);
903 has_nulls = true;
904 is_null[i] = true;
905 }
906 else
907 {
908 RETURN_UNLESS (sizes[i] < INT_MAX);
909 }
910 }
911 }
912
913 for (unsigned int i = 0; i < num; i++)
914 {
915 x = total_size;
916 total_size += sizes[i];
917 RETURN_UNLESS (total_size >= x);
918 }
919 }
920
921 RETURN_UNLESS (total_size < INT_MAX);
923 elements = GNUNET_malloc (total_size);
924 }
925
926 /* Write data */
927 {
928 char *in = (char *) data;
929 char *out = elements;
930 struct pq_array_header h = {
931 .ndim = htonl (1), /* We only support one-dimensional arrays */
932 .has_nulls = has_nulls ? htonl (1) : 0,
933 .lbound = htonl (1), /* Default start index value */
934 .dim = htonl (num),
935 .oid = htonl (meta->oid),
936 };
937
938 /* Write header */
939 GNUNET_memcpy (out,
940 &h,
941 sizeof(h));
942 out += sizeof(h);
943
944 /* Write elements */
945 for (unsigned int i = 0; i < num; i++)
946 {
947 size_t sz = same_sized ? meta->same_size : sizes[i];
948 uint32_t hsz = is_null[i] ? htonl (-1) : htonl (sz);
949
950 GNUNET_memcpy (out,
951 &hsz,
952 sizeof(hsz));
953 out += sizeof(uint32_t);
954
955 switch (meta->typ)
956 {
957 case array_of_bool:
958 {
959 GNUNET_assert (sizeof(bool) == sz);
960 *(bool *) out = (*(bool *) in);
961 in += sz;
962 break;
963 }
964 case array_of_int16:
965 {
966 GNUNET_assert (sizeof(int16_t) == sz);
967 *(int16_t *) out = htons (*(int16_t *) in);
968 in += sz;
969 break;
970 }
971 case array_of_uint16:
972 {
973 GNUNET_assert (sizeof(uint16_t) == sz);
974 *(uint16_t *) out = htons (*(uint16_t *) in);
975 in += sz;
976 break;
977 }
978 case array_of_uint32:
979 {
980 uint32_t v;
981
982 GNUNET_assert (sizeof(uint32_t) == sz);
983 v = htonl (*(uint32_t *) in);
984 GNUNET_memcpy (out,
985 &v,
986 sizeof(v));
987 in += sz;
988 break;
989 }
990 case array_of_uint64:
991 {
992 uint64_t tmp;
993
994 GNUNET_assert (sizeof(uint64_t) == sz);
995 tmp = GNUNET_htonll (*(uint64_t *) in);
996 GNUNET_memcpy (out,
997 &tmp,
998 sizeof(tmp));
999 in += sz;
1000 break;
1001 }
1002 case array_of_byte:
1003 case array_of_string:
1004 if (! is_null[i])
1005 {
1006 const void *ptr;
1007
1008 if (meta->continuous)
1009 {
1010 size_t nullbyte = (array_of_string == meta->typ) ? 1 : 0;
1011
1012 ptr = in;
1013 in += sz + nullbyte;
1014 }
1015 else
1016 {
1017 ptr = ((const char **) data)[i];
1018 }
1019 RETURN_UNLESS (NULL != ptr);
1020 GNUNET_memcpy (out,
1021 ptr,
1022 sz);
1023 }
1024 break;
1025 case array_of_abs_time:
1026 case array_of_rel_time:
1027 case array_of_timestamp:
1028 if (! is_null [i])
1029 {
1030 uint64_t val;
1031
1032 switch (meta->typ)
1033 {
1034 case array_of_abs_time:
1035 {
1036 const struct GNUNET_TIME_Absolute *abs =
1037 (const struct GNUNET_TIME_Absolute *) in;
1038
1039 GNUNET_assert (sizeof(struct GNUNET_TIME_Absolute) == sz);
1040
1041 if (! meta->continuous)
1042 abs = ((const struct GNUNET_TIME_Absolute **) data)[i];
1043
1044 RETURN_UNLESS (NULL != abs);
1045 val = abs->abs_value_us;
1046 break;
1047 }
1048 case array_of_rel_time:
1049 {
1050 const struct GNUNET_TIME_Relative *rel =
1051 (const struct GNUNET_TIME_Relative *) in;
1052
1053 GNUNET_assert (sizeof(struct GNUNET_TIME_Relative) == sz);
1054
1055 if (! meta->continuous)
1056 rel = ((const struct GNUNET_TIME_Relative **) data)[i];
1057
1058 RETURN_UNLESS (NULL != rel);
1059 val = rel->rel_value_us;
1060 break;
1061 }
1062 case array_of_timestamp:
1063 {
1064 const struct GNUNET_TIME_Timestamp *ts =
1065 (const struct GNUNET_TIME_Timestamp *) in;
1066
1067 GNUNET_assert (sizeof(struct GNUNET_TIME_Timestamp) == sz);
1068
1069 if (! meta->continuous)
1070 ts = ((const struct GNUNET_TIME_Timestamp **) data)[i];
1071
1072 RETURN_UNLESS (NULL != ts);
1073 val = ts->abs_time.abs_value_us;
1074 break;
1075 }
1076 default:
1077 {
1078 GNUNET_assert (0);
1079 }
1080 }
1081
1082 val = val > INT64_MAX ? INT64_MAX : val;
1083 val = GNUNET_htonll (val);
1084 GNUNET_memcpy (out,
1085 &val,
1086 sizeof(val));
1087
1088 if (meta->continuous)
1089 in += sz;
1090 }
1091 break;
1092 default:
1093 GNUNET_assert (0);
1094 break;
1095 }
1096
1097 if (! is_null[i])
1098 out += sz;
1099 }
1100 }
1101
1102 param_values[0] = elements;
1103 param_lengths[0] = total_size;
1104 param_formats[0] = 1;
1105 scratch[0] = elements;
1106
1107DONE:
1108 GNUNET_free (string_lengths);
1109
1110 if (noerror)
1111 return 1;
1112
1113 return -1;
1114}
#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.
uint32_t lbound
uint32_t oid
uint32_t dim
#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_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#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.
uint32_t has_nulls
Definition pq.h:1
@ array_of_int16
Definition pq.h:137
@ array_of_byte
Definition pq.h:141
@ array_of_uint32
Definition pq.h:139
@ array_of_string
Definition pq.h:142
@ array_of_rel_time
Definition pq.h:144
@ array_of_uint16
Definition pq.h:138
@ array_of_uint64
Definition pq.h:140
@ array_of_abs_time
Definition pq.h:143
@ array_of_timestamp
Definition pq.h:145
@ array_of_bool
Definition pq.h:136
#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:155
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...
const char * str
Definition time.c:1359

References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, array_of_abs_time, array_of_bool, array_of_byte, array_of_int16, 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_MAX_MALLOC_CHECKED, GNUNET_memcpy, GNUNET_new_array, h, has_nulls, INT_MAX, meta, GNUNET_TIME_Relative::rel_value_us, RETURN_UNLESS, qconv_array_cls::sizes, and str.

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

1138{
1140
1141 meta->typ = typ;
1142 meta->oid = oid;
1143 meta->sizes = sizes;
1144 meta->same_size = same_size;
1145 meta->continuous = continuous;
1146
1147 {
1148 struct GNUNET_PQ_QueryParam res = {
1149 .conv = qconv_array,
1150 .conv_cls = meta,
1151 .conv_cls_cleanup = &qconv_array_cls_cleanup,
1152 .data = elements,
1153 .size = num,
1154 .num_params = 1,
1155 };
1156
1157 return res;
1158 }
1159}
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_PQ_QueryParam::conv, 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_int16(), 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 1163 of file pq_query_helper.c.

1167{
1168 Oid oid;
1169
1172 "bool",
1173 &oid));
1174 return query_param_array_generic (num,
1175 true,
1176 elements,
1177 NULL,
1178 sizeof(bool),
1180 oid);
1181}
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:561
@ 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_int16()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_array_int16 ( unsigned int  num,
const int16_t *  elements,
struct GNUNET_PQ_Context db 
)

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

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

Definition at line 1185 of file pq_query_helper.c.

1189{
1190 Oid oid;
1191
1194 "int2",
1195 &oid));
1196 return query_param_array_generic (num,
1197 true,
1198 elements,
1199 NULL,
1200 sizeof(int16_t),
1202 oid);
1203}

References array_of_int16, 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 1207 of file pq_query_helper.c.

1211{
1212 Oid oid;
1213
1216 "int2",
1217 &oid));
1218 return query_param_array_generic (num,
1219 true,
1220 elements,
1221 NULL,
1222 sizeof(uint16_t),
1224 oid);
1225}

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

1233{
1234 Oid oid;
1235
1238 "int4",
1239 &oid));
1240 return query_param_array_generic (num,
1241 true,
1242 elements,
1243 NULL,
1244 sizeof(uint32_t),
1246 oid);
1247}

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

1255{
1256 Oid oid;
1257
1260 "int8",
1261 &oid));
1262 return query_param_array_generic (num,
1263 true,
1264 elements,
1265 NULL,
1266 sizeof(uint64_t),
1268 oid);
1269}

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

1278{
1279 Oid oid;
1280
1283 "bytea",
1284 &oid));
1285 return query_param_array_generic (num,
1286 true,
1287 elements,
1288 sizes,
1289 0,
1291 oid);
1292}

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

1301{
1302 Oid oid;
1303
1306 "bytea",
1307 &oid));
1308 return query_param_array_generic (num,
1309 false,
1310 elements,
1311 sizes,
1312 0,
1314 oid);
1315}

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

1324{
1325 Oid oid;
1326
1329 "bytea",
1330 &oid));
1331 return query_param_array_generic (num,
1332 true,
1333 elements,
1334 NULL,
1335 same_size,
1337 oid);
1338}

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

1347{
1348 Oid oid;
1349
1352 "bytea",
1353 &oid));
1354 return query_param_array_generic (num,
1355 false,
1356 elements,
1357 NULL,
1358 same_size,
1360 oid);
1361}

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

1369{
1370 Oid oid;
1371
1374 "text",
1375 &oid));
1376 return query_param_array_generic (num,
1377 true,
1378 elements,
1379 NULL,
1380 0,
1382 oid);
1383}

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

1391{
1392 Oid oid;
1393
1396 "text",
1397 &oid));
1398 return query_param_array_generic (num,
1399 false,
1400 elements,
1401 NULL,
1402 0,
1404 oid);
1405}

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

1413{
1414 Oid oid;
1415
1418 "int8",
1419 &oid));
1420 return query_param_array_generic (num,
1421 true,
1422 elements,
1423 NULL,
1424 sizeof(struct GNUNET_TIME_Absolute),
1426 oid);
1427}

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

1435{
1436 Oid oid;
1437
1440 "int8",
1441 &oid));
1442 return query_param_array_generic (num,
1443 false,
1444 elements,
1445 NULL,
1446 sizeof(struct GNUNET_TIME_Absolute),
1448 oid);
1449}

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

1457{
1458 Oid oid;
1459
1462 "int8",
1463 &oid));
1464 return query_param_array_generic (num,
1465 true,
1466 elements,
1467 NULL,
1468 sizeof(struct GNUNET_TIME_Relative),
1470 oid);
1471}

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

1479{
1480 Oid oid;
1481
1484 "int8",
1485 &oid));
1486 return query_param_array_generic (num,
1487 false,
1488 elements,
1489 NULL,
1490 sizeof(struct GNUNET_TIME_Relative),
1492 oid);
1493}

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

1501{
1502 Oid oid;
1503
1506 "int8",
1507 &oid));
1508 return query_param_array_generic (num,
1509 true,
1510 elements,
1511 NULL,
1512 sizeof(struct GNUNET_TIME_Timestamp),
1514 oid);
1515}

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

1523{
1524 Oid oid;
1525
1528 "int8",
1529 &oid));
1530 return query_param_array_generic (num,
1531 false,
1532 elements,
1533 NULL,
1534 sizeof(struct GNUNET_TIME_Timestamp),
1536 oid);
1537}

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

1564{
1565 const struct GNUNET_CRYPTO_BlindSignPublicKey *public_key = data;
1566 size_t tlen;
1567 size_t len;
1568 uint32_t be;
1569 char *buf;
1570 void *tbuf;
1571
1572 (void) cls;
1573 (void) data_len;
1574 GNUNET_assert (1 == param_length);
1575 GNUNET_assert (scratch_length > 0);
1576 GNUNET_break (NULL == cls);
1577 be = htonl ((uint32_t) public_key->cipher);
1578 switch (public_key->cipher)
1579 {
1582 public_key->details.rsa_public_key,
1583 &tbuf);
1584 break;
1586 tlen = sizeof (public_key->details.cs_public_key);
1587 break;
1588 default:
1589 GNUNET_assert (0);
1590 }
1591 len = tlen + sizeof (be);
1592 buf = GNUNET_malloc (len);
1593 GNUNET_memcpy (buf,
1594 &be,
1595 sizeof (be));
1596 switch (public_key->cipher)
1597 {
1599 GNUNET_memcpy (&buf[sizeof (be)],
1600 tbuf,
1601 tlen);
1602 GNUNET_free (tbuf);
1603 break;
1605 GNUNET_memcpy (&buf[sizeof (be)],
1606 &public_key->details.cs_public_key,
1607 tlen);
1608 break;
1609 default:
1610 GNUNET_assert (0);
1611 }
1612
1613 scratch[0] = buf;
1614 param_values[0] = (void *) buf;
1615 param_lengths[0] = len;
1616 param_formats[0] = 1;
1617 return 1;
1618}
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
Type of public signing keys for blind signatures.
union GNUNET_CRYPTO_BlindSignPublicKey::@20 details
Details, depending on cipher.
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 1627 of file pq_query_helper.c.

1629{
1630 struct GNUNET_PQ_QueryParam res = {
1632 .data = pub,
1633 .num_params = 1
1634 };
1635
1636 return res;
1637}
static struct GNUNET_CRYPTO_EddsaPublicKey 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)
Function called to convert input argument into SQL parameters.

References GNUNET_PQ_QueryParam::conv, 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 1655 of file pq_query_helper.c.

1664{
1665 const struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key = data;
1666 size_t tlen;
1667 size_t len;
1668 uint32_t be;
1669 char *buf;
1670 void *tbuf;
1671
1672 (void) cls;
1673 (void) data_len;
1674 GNUNET_assert (1 == param_length);
1675 GNUNET_assert (scratch_length > 0);
1676 GNUNET_break (NULL == cls);
1677 be = htonl ((uint32_t) private_key->cipher);
1678 switch (private_key->cipher)
1679 {
1682 private_key->details.rsa_private_key,
1683 &tbuf);
1684 break;
1686 tlen = sizeof (private_key->details.cs_private_key);
1687 break;
1688 default:
1689 GNUNET_assert (0);
1690 }
1691 len = tlen + sizeof (be);
1692 buf = GNUNET_malloc (len);
1693 GNUNET_memcpy (buf,
1694 &be,
1695 sizeof (be));
1696 switch (private_key->cipher)
1697 {
1699 GNUNET_memcpy (&buf[sizeof (be)],
1700 tbuf,
1701 tlen);
1702 GNUNET_free (tbuf);
1703 break;
1705 GNUNET_memcpy (&buf[sizeof (be)],
1706 &private_key->details.cs_private_key,
1707 tlen);
1708 break;
1709 default:
1710 GNUNET_assert (0);
1711 }
1712
1713 scratch[0] = buf;
1714 param_values[0] = (void *) buf;
1715 param_lengths[0] = len;
1716 param_formats[0] = 1;
1717 return 1;
1718}
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::@21 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 1727 of file pq_query_helper.c.

1729{
1730 struct GNUNET_PQ_QueryParam res = {
1732 .data = priv,
1733 .num_params = 1
1734 };
1735
1736 return res;
1737}
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 GNUNET_PQ_QueryParam::conv, 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 1755 of file pq_query_helper.c.

1764{
1765 const struct GNUNET_CRYPTO_UnblindedSignature *ubs = data;
1766 size_t tlen;
1767 size_t len;
1768 uint32_t be[2];
1769 char *buf;
1770 void *tbuf;
1771
1772 (void) cls;
1773 (void) data_len;
1774 GNUNET_assert (1 == param_length);
1775 GNUNET_assert (scratch_length > 0);
1776 GNUNET_break (NULL == cls);
1777 be[0] = htonl ((uint32_t) ubs->cipher);
1778 be[1] = htonl (0x00); /* magic marker: unblinded */
1779 switch (ubs->cipher)
1780 {
1784 &tbuf);
1785 break;
1787 tlen = sizeof (ubs->details.cs_signature);
1788 break;
1789 default:
1790 GNUNET_assert (0);
1791 }
1792 len = tlen + sizeof (be);
1793 buf = GNUNET_malloc (len);
1794 GNUNET_memcpy (buf,
1795 &be,
1796 sizeof (be));
1797 switch (ubs->cipher)
1798 {
1800 GNUNET_memcpy (&buf[sizeof (be)],
1801 tbuf,
1802 tlen);
1803 GNUNET_free (tbuf);
1804 break;
1806 GNUNET_memcpy (&buf[sizeof (be)],
1807 &ubs->details.cs_signature,
1808 tlen);
1809 break;
1810 default:
1811 GNUNET_assert (0);
1812 }
1813
1814 scratch[0] = buf;
1815 param_values[0] = (void *) buf;
1816 param_lengths[0] = len;
1817 param_formats[0] = 1;
1818 return 1;
1819}
Type of (unblinded) signatures.
union GNUNET_CRYPTO_UnblindedSignature::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
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 1828 of file pq_query_helper.c.

1830{
1831 struct GNUNET_PQ_QueryParam res = {
1833 .data = sig,
1834 .num_params = 1
1835 };
1836
1837 return res;
1838}
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 GNUNET_PQ_QueryParam::conv, 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 1856 of file pq_query_helper.c.

1865{
1866 const struct GNUNET_CRYPTO_BlindedSignature *bs = data;
1867 size_t tlen;
1868 size_t len;
1869 uint32_t be[2];
1870 char *buf;
1871 void *tbuf;
1872
1873 (void) cls;
1874 (void) data_len;
1875 GNUNET_assert (1 == param_length);
1876 GNUNET_assert (scratch_length > 0);
1877 GNUNET_break (NULL == cls);
1878 be[0] = htonl ((uint32_t) bs->cipher);
1879 be[1] = htonl (0x01); /* magic marker: blinded */
1880 switch (bs->cipher)
1881 {
1885 &tbuf);
1886 break;
1888 tlen = sizeof (bs->details.blinded_cs_answer);
1889 break;
1890 default:
1891 GNUNET_assert (0);
1892 }
1893 len = tlen + sizeof (be);
1894 buf = GNUNET_malloc (len);
1895 GNUNET_memcpy (buf,
1896 &be,
1897 sizeof (be));
1898 switch (bs->cipher)
1899 {
1901 GNUNET_memcpy (&buf[sizeof (be)],
1902 tbuf,
1903 tlen);
1904 GNUNET_free (tbuf);
1905 break;
1907 GNUNET_memcpy (&buf[sizeof (be)],
1909 tlen);
1910 break;
1911 default:
1912 GNUNET_assert (0);
1913 }
1914
1915 scratch[0] = buf;
1916 param_values[0] = (void *) buf;
1917 param_lengths[0] = len;
1918 param_formats[0] = 1;
1919 return 1;
1920}
Type for blinded signatures.
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
union GNUNET_CRYPTO_BlindedSignature::@19 details
Details, depending on cipher.

References GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, 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 1929 of file pq_query_helper.c.

1931{
1932 struct GNUNET_PQ_QueryParam res = {
1934 .data = b_sig,
1935 .num_params = 1
1936 };
1937
1938 return res;
1939}
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 GNUNET_PQ_QueryParam::conv, qconv_blinded_sig(), and res.

Here is the call graph for this function: