GNUnet  0.20.0
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 uint16_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 genreate 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)
 
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...
 

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 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 }
uint32_t data
The data value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.

◆ 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 47 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 int res
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 data, and GNUNET_break.

Referenced by postgres_plugin_put().

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 }

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

Referenced by postgres_plugin_put(), and postgres_plugin_remove_key().

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 98 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.

◆ 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 98 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 data, and GNUNET_break.

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

◆ 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 170 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 data, GNUNET_break, and GNUNET_new.

Referenced by postgres_plugin_get_key().

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 }

◆ 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 227 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 data, GNUNET_break, and GNUNET_new.

Referenced by postgres_plugin_del(), postgres_plugin_get_closest(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), and postgres_plugin_put().

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.
Definition: common_endian.c:37

◆ GNUNET_PQ_query_param_uint64()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_uint64 ( const uint64_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 284 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 data, GNUNET_break, GNUNET_htonll(), and GNUNET_new.

Referenced by 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_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 341 of file pq_query_helper.c.

350 {
351  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
352  void *buf;
353  size_t buf_size;
354 
355  GNUNET_break (NULL == cls);
356  if (1 != param_length)
357  return -1;
358  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
359  &buf);
360  scratch[0] = buf;
361  param_values[0] = (void *) buf;
362  param_lengths[0] = buf_size;
363  param_formats[0] = 1;
364  return 1;
365 }
static char buf[2048]
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

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

371 {
372  struct GNUNET_PQ_QueryParam res = {
373  .conv = &qconv_rsa_public_key,
374  .data = x,
375  .num_params = 1
376  };
377 
378  return res;
379 }
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 buf, data, GNUNET_break, and GNUNET_CRYPTO_rsa_public_key_encode().

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

406 {
407  const struct GNUNET_CRYPTO_RsaSignature *sig = data;
408  void *buf;
409  size_t buf_size;
410 
411  GNUNET_break (NULL == cls);
412  if (1 != param_length)
413  return -1;
414  buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
415  &buf);
416  scratch[0] = buf;
417  param_values[0] = (void *) buf;
418  param_lengths[0] = buf_size;
419  param_formats[0] = 1;
420  return 1;
421 }
size_t GNUNET_CRYPTO_rsa_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:999
an RSA signature
Definition: crypto_rsa.c:65

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

426 {
427  struct GNUNET_PQ_QueryParam res = {
428  .conv = &qconv_rsa_signature,
429  .data = x,
430  .num_params = 1
431  };
432 
433  return res;
434 }
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 buf, data, GNUNET_break, and GNUNET_CRYPTO_rsa_signature_encode().

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

461 {
462  const struct GNUNET_TIME_Relative *u = data;
463  struct GNUNET_TIME_Relative rel;
464  uint64_t *u_nbo;
465 
466  GNUNET_break (NULL == cls);
467  if (1 != param_length)
468  return -1;
469  rel = *u;
470  if (rel.rel_value_us > INT64_MAX)
471  rel.rel_value_us = INT64_MAX;
472  u_nbo = GNUNET_new (uint64_t);
473  scratch[0] = u_nbo;
474  *u_nbo = GNUNET_htonll (rel.rel_value_us);
475  param_values[0] = (void *) u_nbo;
476  param_lengths[0] = sizeof(uint64_t);
477  param_formats[0] = 1;
478  return 1;
479 }
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

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

484 {
485  struct GNUNET_PQ_QueryParam res = {
486  .conv = &qconv_rel_time,
487  .data = x,
488  .size = sizeof(*x),
489  .num_params = 1
490  };
491 
492  return res;
493 }
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 data, GNUNET_break, GNUNET_htonll(), GNUNET_new, and GNUNET_TIME_Relative::rel_value_us.

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

520 {
521  const struct GNUNET_TIME_Absolute *u = data;
522  struct GNUNET_TIME_Absolute abs;
523  uint64_t *u_nbo;
524 
525  GNUNET_break (NULL == cls);
526  if (1 != param_length)
527  return -1;
528  abs = *u;
529  if (abs.abs_value_us > INT64_MAX)
530  abs.abs_value_us = INT64_MAX;
531  u_nbo = GNUNET_new (uint64_t);
532  scratch[0] = u_nbo;
533  *u_nbo = GNUNET_htonll (abs.abs_value_us);
534  param_values[0] = (void *) u_nbo;
535  param_lengths[0] = sizeof(uint64_t);
536  param_formats[0] = 1;
537  return 1;
538 }
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.

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

543 {
544  struct GNUNET_PQ_QueryParam res = {
545  .conv = &qconv_abs_time,
546  .data = x,
547  .size = sizeof(*x),
548  .num_params = 1
549  };
550 
551  return res;
552 }
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_TIME_Absolute::abs_value_us, data, GNUNET_break, GNUNET_htonll(), and GNUNET_new.

Referenced by delete_old_block(), namecache_postgres_expire_blocks(), postgres_plugin_del(), 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 511 of file pq_query_helper.c.

558 {
560 }
#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).

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

565 {
567 }
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.

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

573 {
575 }
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.

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

624 {
625  GNUNET_free (cls);
626 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free.

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

658 {
659  struct qconv_array_cls *meta = cls;
660  size_t num = data_len;
661  size_t total_size;
662  const size_t *sizes;
663  bool same_sized;
664  size_t *string_lengths = NULL;
665  void *elements = NULL;
666  bool noerror = true;
667 
668  (void) (param_length);
669  (void) (scratch_length);
670 
671  GNUNET_assert (NULL != meta);
672  GNUNET_assert (num < INT_MAX);
673 
674  sizes = meta->sizes;
675  same_sized = (0 != meta->same_size);
676 
677 #define RETURN_UNLESS(cond) \
678  do { \
679  if (! (cond)) \
680  { \
681  GNUNET_break ((cond)); \
682  noerror = false; \
683  goto DONE; \
684  } \
685  } while (0)
686 
687  /* Calculate sizes and check bounds */
688  {
689  /* num * length-field */
690  size_t x = sizeof(uint32_t);
691  size_t y = x * num;
692  RETURN_UNLESS ((0 == num) || (y / num == x));
693 
694  /* size of header */
695  total_size = x = sizeof(struct pq_array_header);
696  total_size += y;
697  RETURN_UNLESS (total_size >= x);
698 
699  /* sizes of elements */
700  if (same_sized)
701  {
702  x = num * meta->same_size;
703  RETURN_UNLESS ((0 == num) || (x / num == meta->same_size));
704 
705  y = total_size;
706  total_size += x;
707  RETURN_UNLESS (total_size >= y);
708  }
709  else /* sizes are different per element */
710  {
711  /* for an array of strings we need to get their length's first */
712  if (array_of_string == meta->typ)
713  {
714  string_lengths = GNUNET_new_array (num, size_t);
715 
716  if (meta->continuous)
717  {
718  const char *ptr = data;
719  for (unsigned int i = 0; i < num; i++)
720  {
721  size_t len = strlen (ptr);
722  string_lengths[i] = len;
723  ptr += len + 1;
724  }
725  }
726  else
727  {
728  const char **str = (const char **) data;
729  for (unsigned int i = 0; i < num; i++)
730  string_lengths[i] = strlen (str[i]);
731  }
732 
733  sizes = string_lengths;
734  }
735 
736  for (unsigned int i = 0; i < num; i++)
737  {
738  x = total_size;
739  total_size += sizes[i];
740  RETURN_UNLESS (total_size >= x);
741  }
742  }
743 
744  RETURN_UNLESS (total_size < INT_MAX);
745 
746  elements = GNUNET_malloc (total_size);
747  }
748 
749  /* Write data */
750  {
751  char *in = (char *) data;
752  char *out = elements;
753  size_t nullbyte = (array_of_string == meta->typ) ? 1 : 0;
754  struct pq_array_header h = {
755  .ndim = htonl (1), /* We only support one-dimensional arrays */
756  .has_null = htonl (0), /* We do not support NULL entries in arrays */
757  .lbound = htonl (1), /* Default start index value */
758  .dim = htonl (num),
759  .oid = htonl (meta->oid),
760  };
761 
762  /* Write header */
763  GNUNET_memcpy (out, &h, sizeof(h));
764  out += sizeof(h);
765 
766 
767  /* Write elements */
768  for (unsigned int i = 0; i < num; i++)
769  {
770  size_t sz = same_sized ? meta->same_size : sizes[i];
771  size_t hsz = htonl (sz);
772 
773  GNUNET_memcpy (out,
774  &hsz,
775  sizeof(hsz));
776  out += sizeof(uint32_t);
777 
778  switch (meta->typ)
779  {
780  case array_of_bool:
781  {
782  GNUNET_assert (sizeof(bool) == sz);
783  *(bool *) out = (*(bool *) in);
784  in += sz;
785  break;
786  }
787  case array_of_uint16:
788  {
789  GNUNET_assert (sizeof(uint16_t) == sz);
790  *(uint16_t *) out = htons (*(uint16_t *) in);
791  in += sz;
792  break;
793  }
794  case array_of_uint32:
795  {
796  uint32_t v;
797  GNUNET_assert (sizeof(uint32_t) == sz);
798 
799  v = htonl (*(uint32_t *) in);
800  GNUNET_memcpy (out,
801  &v,
802  sizeof(v));
803  in += sz;
804  break;
805  }
806  case array_of_uint64:
807  {
808  uint64_t tmp;
809  GNUNET_assert (sizeof(uint64_t) == sz);
810 
811  tmp = GNUNET_htonll (*(uint64_t *) in);
812  GNUNET_memcpy (out,
813  &tmp,
814  sizeof(tmp));
815  in += sz;
816  break;
817  }
818  case array_of_byte:
819  case array_of_string:
820  {
821  const void *ptr;
822 
823  if (meta->continuous)
824  {
825  ptr = in;
826  in += sz + nullbyte;
827  }
828  else
829  ptr = ((const void **) data)[i];
830 
831  GNUNET_memcpy (out,
832  ptr,
833  sz);
834  break;
835  }
836  case array_of_abs_time:
837  case array_of_rel_time:
838  case array_of_timestamp:
839  {
840  uint64_t val;
841 
842  switch (meta->typ)
843  {
844  case array_of_abs_time:
845  {
846  const struct GNUNET_TIME_Absolute *abs =
847  (const struct GNUNET_TIME_Absolute *) in;
848 
849  GNUNET_assert (sizeof(struct GNUNET_TIME_Absolute) == sz);
850 
851  if (! meta->continuous)
852  abs = ((const struct GNUNET_TIME_Absolute **) data)[i];
853 
854  val = abs->abs_value_us;
855  break;
856  }
857  case array_of_rel_time:
858  {
859  const struct GNUNET_TIME_Relative *rel =
860  (const struct GNUNET_TIME_Relative *) in;
861 
862  GNUNET_assert (sizeof(struct GNUNET_TIME_Relative) == sz);
863 
864  if (! meta->continuous)
865  rel = ((const struct GNUNET_TIME_Relative **) data)[i];
866 
867  val = rel->rel_value_us;
868  break;
869  }
870  case array_of_timestamp:
871  {
872  const struct GNUNET_TIME_Timestamp *ts =
873  (const struct GNUNET_TIME_Timestamp *) in;
874 
875  GNUNET_assert (sizeof(struct GNUNET_TIME_Timestamp) == sz);
876 
877  if (! meta->continuous)
878  ts = ((const struct GNUNET_TIME_Timestamp **) data)[i];
879 
880  val = ts->abs_time.abs_value_us;
881  break;
882  }
883  default:
884  {
885  GNUNET_assert (0);
886  }
887  }
888 
889  if (val > INT64_MAX)
890  val = INT64_MAX;
891 
892  val = GNUNET_htonll (val);
893  GNUNET_memcpy (out,
894  &val,
895  sizeof(val));
896 
897  if (meta->continuous)
898  in += sz;
899 
900  break;
901  }
902  default:
903  {
904  GNUNET_assert (0);
905  break;
906  }
907  }
908  out += sz;
909  }
910  }
911 
912  param_values[0] = elements;
913  param_lengths[0] = total_size;
914  param_formats[0] = 1;
915  scratch[0] = elements;
916 
917 DONE:
918  GNUNET_free (string_lengths);
919 
920  if (noerror)
921  return 1;
922 
923  return -1;
924 }
#define INT_MAX
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
@ array_of_byte
Definition: pq.h:137
@ array_of_uint32
Definition: pq.h:135
@ array_of_string
Definition: pq.h:138
@ array_of_rel_time
Definition: pq.h:140
@ array_of_uint16
Definition: pq.h:134
@ array_of_uint64
Definition: pq.h:136
@ array_of_abs_time
Definition: pq.h:139
@ array_of_timestamp
Definition: pq.h:141
@ array_of_bool
Definition: pq.h:133
#define RETURN_UNLESS(cond)
Rounded time for timestamps used by GNUnet, in seconds.
the header for a postgresql array in binary format.
Definition: pq.h:151
Closure for the array type handlers.
const size_t * sizes
If not null, contains the array of sizes (the size of the array is the .size field in the ambient GNU...

◆ 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 genreate 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 648 of file pq_query_helper.c.

948 {
949  struct qconv_array_cls *meta = GNUNET_new (struct qconv_array_cls);
950 
951  meta->typ = typ;
952  meta->oid = oid;
953  meta->sizes = sizes;
954  meta->same_size = same_size;
955  meta->continuous = continuous;
956 
957  {
958  struct GNUNET_PQ_QueryParam res = {
959  .conv = qconv_array,
960  .conv_cls = meta,
961  .conv_cls_cleanup = &qconv_array_cls_cleanup,
962  .data = elements,
963  .size = num,
964  .num_params = 1,
965  };
966 
967  return res;
968  }
969 }
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...

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

977 {
978  Oid oid;
979 
982  "bool",
983  &oid));
984  return query_param_array_generic (num,
985  true,
986  elements,
987  NULL,
988  sizeof(bool),
990  oid);
991 }
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:97
enum GNUNET_GenericReturnValue GNUNET_PQ_get_oid_by_name(struct GNUNET_PQ_Context *db, const char *name, Oid *oid)
Returns the oid for a given datatype by name.
Definition: pq_connect.c:326
@ GNUNET_OK
static struct GNUNET_PQ_QueryParam query_param_array_generic(unsigned int num, bool continuous, const void *elements, const size_t *sizes, size_t same_size, enum array_types typ, Oid oid)
Function to genreate a typ specific query parameter and corresponding closure.

◆ 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 (unsigend) 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 648 of file pq_query_helper.c.

999 {
1000  Oid oid;
1001 
1004  "int2",
1005  &oid));
1006  return query_param_array_generic (num,
1007  true,
1008  elements,
1009  NULL,
1010  sizeof(uint16_t),
1012  oid);
1013 }

◆ 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 (unsigend) 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 648 of file pq_query_helper.c.

1021 {
1022  Oid oid;
1023 
1026  "int4",
1027  &oid));
1028  return query_param_array_generic (num,
1029  true,
1030  elements,
1031  NULL,
1032  sizeof(uint32_t),
1034  oid);
1035 }

◆ 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 (unsigend) 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 648 of file pq_query_helper.c.

1043 {
1044  Oid oid;
1045 
1048  "int8",
1049  &oid));
1050  return query_param_array_generic (num,
1051  true,
1052  elements,
1053  NULL,
1054  sizeof(uint64_t),
1056  oid);
1057 }

◆ 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
elementsContinous 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 648 of file pq_query_helper.c.

1066 {
1067  Oid oid;
1068 
1071  "bytea",
1072  &oid));
1073  return query_param_array_generic (num,
1074  true,
1075  elements,
1076  sizes,
1077  0,
1078  array_of_byte,
1079  oid);
1080 }

◆ 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 
)

Definition at line 648 of file pq_query_helper.c.

1089 {
1090  Oid oid;
1091 
1094  "bytea",
1095  &oid));
1096  return query_param_array_generic (num,
1097  false,
1098  elements,
1099  sizes,
1100  0,
1101  array_of_byte,
1102  oid);
1103 }

◆ 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
elementsContinous 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 648 of file pq_query_helper.c.

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

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

1135 {
1136  Oid oid;
1137 
1140  "bytea",
1141  &oid));
1142  return query_param_array_generic (num,
1143  false,
1144  elements,
1145  NULL,
1146  same_size,
1147  array_of_byte,
1148  oid);
1149 }

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

1157 {
1158  Oid oid;
1159 
1162  "text",
1163  &oid));
1164  return query_param_array_generic (num,
1165  true,
1166  elements,
1167  NULL,
1168  0,
1170  oid);
1171 }

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

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

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

1201 {
1202  Oid oid;
1203 
1206  "int8",
1207  &oid));
1208  return query_param_array_generic (num,
1209  true,
1210  elements,
1211  NULL,
1212  sizeof(struct GNUNET_TIME_Absolute),
1214  oid);
1215 }

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, len, meta, GNUNET_TIME_Relative::rel_value_us, RETURN_UNLESS, and qconv_array_cls::sizes.

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

1223 {
1224  Oid oid;
1225 
1228  "int8",
1229  &oid));
1230  return query_param_array_generic (num,
1231  false,
1232  elements,
1233  NULL,
1234  sizeof(struct GNUNET_TIME_Absolute),
1236  oid);
1237 }

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

1245 {
1246  Oid oid;
1247 
1250  "int8",
1251  &oid));
1252  return query_param_array_generic (num,
1253  true,
1254  elements,
1255  NULL,
1256  sizeof(struct GNUNET_TIME_Relative),
1258  oid);
1259 }

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

1267 {
1268  Oid oid;
1269 
1272  "int8",
1273  &oid));
1274  return query_param_array_generic (num,
1275  false,
1276  elements,
1277  NULL,
1278  sizeof(struct GNUNET_TIME_Relative),
1280  oid);
1281 }

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

1289 {
1290  Oid oid;
1291 
1294  "int8",
1295  &oid));
1296  return query_param_array_generic (num,
1297  true,
1298  elements,
1299  NULL,
1300  sizeof(struct GNUNET_TIME_Timestamp),
1302  oid);
1303 }

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

1311 {
1312  Oid oid;
1313 
1316  "int8",
1317  &oid));
1318  return query_param_array_generic (num,
1319  false,
1320  elements,
1321  NULL,
1322  sizeof(struct GNUNET_TIME_Timestamp),
1324  oid);
1325 }