GNUnet  0.11.x
Functions
pq_query_helper.c File Reference

functions to initialize parameter arrays More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_pq_lib.h"
Include dependency graph for pq_query_helper.c:

Go to the source code of this file.

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

Detailed Description

functions to initialize parameter arrays

Author
Christian Grothoff

Definition in file pq_query_helper.c.

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

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

71 {
72  struct GNUNET_PQ_QueryParam res = {
73  .conv = &qconv_null,
74  .num_params = 1
75  };
76 
77  return res;
78 }
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:65

References data, and GNUNET_break.

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

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

◆ 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 @oaran ptr_size number of bytes in ptr
Returns
query parameter to use

Definition at line 96 of file pq_query_helper.c.

121 {
122  struct GNUNET_PQ_QueryParam res = {
123  &qconv_fixed, NULL, ptr, ptr_size, 1
124  };
125 
126  return res;
127 }
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 namecache_postgres_cache_block(), namestore_postgres_store_records(), 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 96 of file pq_query_helper.c.

132 {
134  strlen (ptr));
135 }
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.

Referenced by namestore_postgres_lookup_records(), and namestore_postgres_store_records().

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

140 {
141  static uint8_t bt = 1;
142  static uint8_t bf = 0;
143 
144  return GNUNET_PQ_query_param_fixed_size (b ? &bt : &bf,
145  sizeof (uint8_t));
146 }

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

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

194 {
195  struct GNUNET_PQ_QueryParam res = {
196  .conv = &qconv_uint16,
197  .data = x,
198  .size = sizeof(*x),
199  .num_params = 1
200  };
201 
202  return res;
203 }
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 221 of file pq_query_helper.c.

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

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

251 {
252  struct GNUNET_PQ_QueryParam res = {
253  .conv = &qconv_uint32,
254  .data = x,
255  .size = sizeof(*x),
256  .num_params = 1
257  };
258 
259  return res;
260 }
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 namestore_postgres_store_records(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), postgres_plugin_put(), process_result(), and repl_proc().

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

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

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

308 {
309  struct GNUNET_PQ_QueryParam res = {
310  .conv = &qconv_uint64,
311  .data = x,
312  .size = sizeof(*x),
313  .num_params = 1
314  };
315 
316  return res;
317 }
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 namestore_postgres_iterate_records(), namestore_postgres_store_records(), postgres_plugin_get_key(), postgres_plugin_get_zero_anonymity(), and postgres_plugin_put().

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

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

344 {
345  const struct GNUNET_CRYPTO_RsaPublicKey *rsa = data;
346  void *buf;
347  size_t buf_size;
348 
349  GNUNET_break (NULL == cls);
350  if (1 != param_length)
351  return -1;
352  buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
353  &buf);
354  scratch[0] = buf;
355  param_values[0] = (void *) buf;
356  param_lengths[0] = buf_size;
357  param_formats[0] = 1;
358  return 1;
359 }
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:324
The public information of an RSA key pair.
Definition: crypto_rsa.c:52

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

365 {
366  struct GNUNET_PQ_QueryParam res = {
367  .conv = &qconv_rsa_public_key,
368  .data = x,
369  .num_params = 1
370  };
371 
372  return res;
373 }
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 391 of file pq_query_helper.c.

400 {
401  const struct GNUNET_CRYPTO_RsaSignature *sig = data;
402  void *buf;
403  size_t buf_size;
404 
405  GNUNET_break (NULL == cls);
406  if (1 != param_length)
407  return -1;
408  buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
409  &buf);
410  scratch[0] = buf;
411  param_values[0] = (void *) buf;
412  param_lengths[0] = buf_size;
413  param_formats[0] = 1;
414  return 1;
415 }
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:998
an RSA signature
Definition: crypto_rsa.c:64

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

420 {
421  struct GNUNET_PQ_QueryParam res = {
422  .conv = &qconv_rsa_signature,
423  .data = x,
424  .num_params = 1
425  };
426 
427  return res;
428 }
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 446 of file pq_query_helper.c.

455 {
456  const struct GNUNET_TIME_Relative *u = data;
457  struct GNUNET_TIME_Relative rel;
458  uint64_t *u_nbo;
459 
460  GNUNET_break (NULL == cls);
461  if (1 != param_length)
462  return -1;
463  rel = *u;
464  if (rel.rel_value_us > INT64_MAX)
465  rel.rel_value_us = INT64_MAX;
466  u_nbo = GNUNET_new (uint64_t);
467  scratch[0] = u_nbo;
468  *u_nbo = GNUNET_htonll (rel.rel_value_us);
469  param_values[0] = (void *) u_nbo;
470  param_lengths[0] = sizeof(uint64_t);
471  param_formats[0] = 1;
472  return 1;
473 }
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 446 of file pq_query_helper.c.

478 {
479  struct GNUNET_PQ_QueryParam res = {
480  .conv = &qconv_rel_time,
481  .data = x,
482  .size = sizeof(*x),
483  .num_params = 1
484  };
485 
486  return res;
487 }
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 505 of file pq_query_helper.c.

514 {
515  const struct GNUNET_TIME_Absolute *u = data;
516  struct GNUNET_TIME_Absolute abs;
517  uint64_t *u_nbo;
518 
519  GNUNET_break (NULL == cls);
520  if (1 != param_length)
521  return -1;
522  abs = *u;
523  if (abs.abs_value_us > INT64_MAX)
524  abs.abs_value_us = INT64_MAX;
525  u_nbo = GNUNET_new (uint64_t);
526  scratch[0] = u_nbo;
527  *u_nbo = GNUNET_htonll (abs.abs_value_us);
528  param_values[0] = (void *) u_nbo;
529  param_lengths[0] = sizeof(uint64_t);
530  param_formats[0] = 1;
531  return 1;
532 }
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 505 of file pq_query_helper.c.

537 {
538  struct GNUNET_PQ_QueryParam res = {
539  .conv = &qconv_abs_time,
540  .data = x,
541  .size = sizeof(*x),
542  .num_params = 1
543  };
544 
545  return res;
546 }
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_cache_block(), namecache_postgres_expire_blocks(), postgres_plugin_del(), postgres_plugin_get(), postgres_plugin_get_closest(), postgres_plugin_get_expiration(), and postgres_plugin_put().

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

◆ GNUNET_PQ_query_param_absolute_time_nbo()

struct GNUNET_PQ_QueryParam GNUNET_PQ_query_param_absolute_time_nbo ( const struct GNUNET_TIME_AbsoluteNBO x)

Generate query parameter for an absolute time value.

The database must store a 64-bit integer.

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

Definition at line 505 of file pq_query_helper.c.

552 {
554 }
#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 505 of file pq_query_helper.c.

559 {
561 }
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 t)

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

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