fixed endianness in taler_sq_lib
This commit is contained in:
parent
83319e1782
commit
9bbaff19c1
@ -29,7 +29,7 @@
|
|||||||
* Function called to convert input argument into SQL parameters.
|
* Function called to convert input argument into SQL parameters.
|
||||||
*
|
*
|
||||||
* @param cls closure
|
* @param cls closure
|
||||||
* @param data pointer to input argument, here a `struct TALER_AmountNBO`
|
* @param data pointer to input argument, here a `struct TALER_Amount`
|
||||||
* @param data_len number of bytes in @a data (if applicable)
|
* @param data_len number of bytes in @a data (if applicable)
|
||||||
* @param stmt sqlite statement to parameters for
|
* @param stmt sqlite statement to parameters for
|
||||||
* @param off offset of the argument to bind in @a stmt, numbered from 1,
|
* @param off offset of the argument to bind in @a stmt, numbered from 1,
|
||||||
@ -37,16 +37,16 @@
|
|||||||
* @return #GNUNET_SYSERR on error, #GNUNET_OK on success
|
* @return #GNUNET_SYSERR on error, #GNUNET_OK on success
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
qconv_amount_nbo (void *cls,
|
qconv_amount (void *cls,
|
||||||
const void *data,
|
const void *data,
|
||||||
size_t data_len,
|
size_t data_len,
|
||||||
sqlite3_stmt *stmt,
|
sqlite3_stmt *stmt,
|
||||||
unsigned int off)
|
unsigned int off)
|
||||||
{
|
{
|
||||||
const struct TALER_AmountNBO *amount = data;
|
const struct TALER_Amount *amount = data;
|
||||||
|
|
||||||
(void) cls;
|
(void) cls;
|
||||||
GNUNET_assert (sizeof (struct TALER_AmountNBO) == data_len);
|
GNUNET_assert (sizeof (struct TALER_Amount) == data_len);
|
||||||
if (SQLITE_OK != sqlite3_bind_int64 (stmt,
|
if (SQLITE_OK != sqlite3_bind_int64 (stmt,
|
||||||
(int) off,
|
(int) off,
|
||||||
(sqlite3_int64) amount->value))
|
(sqlite3_int64) amount->value))
|
||||||
@ -67,10 +67,10 @@ qconv_amount_nbo (void *cls,
|
|||||||
* @param x pointer to the query parameter to pass
|
* @param x pointer to the query parameter to pass
|
||||||
*/
|
*/
|
||||||
struct GNUNET_SQ_QueryParam
|
struct GNUNET_SQ_QueryParam
|
||||||
TALER_SQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
|
TALER_SQ_query_param_amount (const struct TALER_Amount *x)
|
||||||
{
|
{
|
||||||
struct GNUNET_SQ_QueryParam res =
|
struct GNUNET_SQ_QueryParam res =
|
||||||
{ &qconv_amount_nbo, NULL, x, sizeof (*x), 2 };
|
{ &qconv_amount, NULL, x, sizeof (*x), 2 };
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ TALER_SQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
|
|||||||
* Function called to convert input argument into SQL parameters.
|
* Function called to convert input argument into SQL parameters.
|
||||||
*
|
*
|
||||||
* @param cls closure
|
* @param cls closure
|
||||||
* @param data pointer to input argument, here a `struct TALER_Amount`
|
* @param data pointer to input argument, here a `struct TALER_AmountNBO`
|
||||||
* @param data_len number of bytes in @a data (if applicable)
|
* @param data_len number of bytes in @a data (if applicable)
|
||||||
* @param stmt sqlite statement to parameters for
|
* @param stmt sqlite statement to parameters for
|
||||||
* @param off offset of the argument to bind in @a stmt, numbered from 1,
|
* @param off offset of the argument to bind in @a stmt, numbered from 1,
|
||||||
@ -87,24 +87,23 @@ TALER_SQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
|
|||||||
* @return #GNUNET_SYSERR on error, #GNUNET_OK on success
|
* @return #GNUNET_SYSERR on error, #GNUNET_OK on success
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
qconv_amount (void *cls,
|
qconv_amount_nbo (void *cls,
|
||||||
const void *data,
|
const void *data,
|
||||||
size_t data_len,
|
size_t data_len,
|
||||||
sqlite3_stmt *stmt,
|
sqlite3_stmt *stmt,
|
||||||
unsigned int off)
|
unsigned int off)
|
||||||
{
|
{
|
||||||
const struct TALER_Amount *amount_hbo = data;
|
const struct TALER_AmountNBO *amount = data;
|
||||||
struct TALER_AmountNBO amount;
|
struct TALER_Amount amount_hbo;
|
||||||
|
|
||||||
(void) cls;
|
(void) cls;
|
||||||
GNUNET_assert (sizeof (struct TALER_AmountNBO) == data_len);
|
TALER_amount_ntoh (&amount_hbo,
|
||||||
TALER_amount_hton (&amount,
|
amount);
|
||||||
amount_hbo);
|
return qconv_amount (cls,
|
||||||
return qconv_amount_nbo (cls,
|
&amount_hbo,
|
||||||
&amount,
|
sizeof (struct TALER_Amount),
|
||||||
sizeof (struct TALER_AmountNBO),
|
stmt,
|
||||||
stmt,
|
off);
|
||||||
off);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,10 +115,10 @@ qconv_amount (void *cls,
|
|||||||
* @param x pointer to the query parameter to pass
|
* @param x pointer to the query parameter to pass
|
||||||
*/
|
*/
|
||||||
struct GNUNET_SQ_QueryParam
|
struct GNUNET_SQ_QueryParam
|
||||||
TALER_SQ_query_param_amount (const struct TALER_Amount *x)
|
TALER_SQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
|
||||||
{
|
{
|
||||||
struct GNUNET_SQ_QueryParam res =
|
struct GNUNET_SQ_QueryParam res =
|
||||||
{ &qconv_amount, NULL, x, sizeof (*x), 2 };
|
{ &qconv_amount_nbo, NULL, x, sizeof (*x), 2 };
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +198,6 @@ qconv_round_time (void *cls,
|
|||||||
{
|
{
|
||||||
const struct GNUNET_TIME_Absolute *at = data;
|
const struct GNUNET_TIME_Absolute *at = data;
|
||||||
struct GNUNET_TIME_Absolute tmp;
|
struct GNUNET_TIME_Absolute tmp;
|
||||||
struct GNUNET_TIME_AbsoluteNBO buf;
|
|
||||||
|
|
||||||
(void) cls;
|
(void) cls;
|
||||||
GNUNET_assert (sizeof (struct GNUNET_TIME_AbsoluteNBO) == data_len);
|
GNUNET_assert (sizeof (struct GNUNET_TIME_AbsoluteNBO) == data_len);
|
||||||
@ -207,10 +205,9 @@ qconv_round_time (void *cls,
|
|||||||
tmp = *at;
|
tmp = *at;
|
||||||
GNUNET_assert (GNUNET_OK ==
|
GNUNET_assert (GNUNET_OK ==
|
||||||
GNUNET_TIME_round_abs (&tmp));
|
GNUNET_TIME_round_abs (&tmp));
|
||||||
buf = GNUNET_TIME_absolute_hton (tmp);
|
|
||||||
if (SQLITE_OK != sqlite3_bind_int64 (stmt,
|
if (SQLITE_OK != sqlite3_bind_int64 (stmt,
|
||||||
(int) off,
|
(int) off,
|
||||||
(sqlite3_int64) buf.abs_value_us__))
|
(sqlite3_int64) at->abs_value_us))
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
@ -263,7 +260,7 @@ qconv_round_time_abs (void *cls,
|
|||||||
GNUNET_TIME_round_abs (&tmp));
|
GNUNET_TIME_round_abs (&tmp));
|
||||||
if (SQLITE_OK != sqlite3_bind_int64 (stmt,
|
if (SQLITE_OK != sqlite3_bind_int64 (stmt,
|
||||||
(int) off,
|
(int) off,
|
||||||
(sqlite3_int64) at->abs_value_us__))
|
(sqlite3_int64) tmp.abs_value_us))
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
@ -39,15 +39,15 @@
|
|||||||
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
|
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
extract_amount_nbo (void *cls,
|
extract_amount (void *cls,
|
||||||
sqlite3_stmt *result,
|
sqlite3_stmt *result,
|
||||||
unsigned int column,
|
unsigned int column,
|
||||||
size_t *dst_size,
|
size_t *dst_size,
|
||||||
void *dst)
|
void *dst)
|
||||||
{
|
{
|
||||||
struct TALER_AmountNBO *amount = dst;
|
struct TALER_Amount *amount = dst;
|
||||||
const char *currency = cls;
|
const char *currency = cls;
|
||||||
if ((sizeof (struct TALER_AmountNBO) != *dst_size) ||
|
if ((sizeof (struct TALER_Amount) != *dst_size) ||
|
||||||
(SQLITE_INTEGER != sqlite3_column_type (result,
|
(SQLITE_INTEGER != sqlite3_column_type (result,
|
||||||
(int) column)) ||
|
(int) column)) ||
|
||||||
(SQLITE_INTEGER != sqlite3_column_type (result,
|
(SQLITE_INTEGER != sqlite3_column_type (result,
|
||||||
@ -56,11 +56,13 @@ extract_amount_nbo (void *cls,
|
|||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
GNUNET_strlcpy (amount->currency, currency, TALER_CURRENCY_LEN);
|
GNUNET_strlcpy (amount->currency,
|
||||||
|
currency,
|
||||||
|
TALER_CURRENCY_LEN);
|
||||||
amount->value = (uint64_t) sqlite3_column_int64 (result,
|
amount->value = (uint64_t) sqlite3_column_int64 (result,
|
||||||
(int) column);
|
(int) column);
|
||||||
uint64_t frac = (uint64_t) sqlite3_column_int64 (result,
|
uint64_t frac = (uint64_t) sqlite3_column_int64 (result,
|
||||||
column + 1);
|
(int) column + 1);
|
||||||
amount->fraction = (uint32_t) frac;
|
amount->fraction = (uint32_t) frac;
|
||||||
return GNUNET_YES;
|
return GNUNET_YES;
|
||||||
}
|
}
|
||||||
@ -74,14 +76,14 @@ extract_amount_nbo (void *cls,
|
|||||||
* @return array entry for the result specification to use
|
* @return array entry for the result specification to use
|
||||||
*/
|
*/
|
||||||
struct GNUNET_SQ_ResultSpec
|
struct GNUNET_SQ_ResultSpec
|
||||||
TALER_SQ_result_spec_amount_nbo (const char *currency,
|
TALER_SQ_result_spec_amount (const char *currency,
|
||||||
struct TALER_AmountNBO *amount)
|
struct TALER_Amount *amount)
|
||||||
{
|
{
|
||||||
struct GNUNET_SQ_ResultSpec res = {
|
struct GNUNET_SQ_ResultSpec res = {
|
||||||
.conv = &extract_amount_nbo,
|
.conv = &extract_amount,
|
||||||
.cls = (void *) currency,
|
.cls = (void *) currency,
|
||||||
.dst = (void *) amount,
|
.dst = (void *) amount,
|
||||||
.dst_size = sizeof (struct TALER_AmountNBO),
|
.dst_size = sizeof (struct TALER_Amount),
|
||||||
.num_params = 2
|
.num_params = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,29 +104,27 @@ TALER_SQ_result_spec_amount_nbo (const char *currency,
|
|||||||
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
|
* #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
extract_amount (void *cls,
|
extract_amount_nbo (void *cls,
|
||||||
sqlite3_stmt *result,
|
sqlite3_stmt *result,
|
||||||
unsigned int column,
|
unsigned int column,
|
||||||
size_t *dst_size,
|
size_t *dst_size,
|
||||||
void *dst)
|
void *dst)
|
||||||
{
|
{
|
||||||
struct TALER_Amount *amount = dst;
|
struct TALER_AmountNBO *amount = dst;
|
||||||
struct TALER_AmountNBO amount_nbo;
|
struct TALER_Amount amount_hbo;
|
||||||
if (GNUNET_YES == extract_amount_nbo (cls,
|
size_t amount_hbo_size = sizeof (struct TALER_Amount);
|
||||||
result,
|
if (GNUNET_YES != extract_amount (cls,
|
||||||
column,
|
result,
|
||||||
dst_size,
|
column,
|
||||||
&amount_nbo))
|
&amount_hbo_size,
|
||||||
{
|
&amount_hbo))
|
||||||
TALER_amount_ntoh (amount,
|
|
||||||
&amount_nbo);
|
|
||||||
return GNUNET_YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
|
TALER_amount_hton (amount,
|
||||||
|
&amount_hbo);
|
||||||
|
return GNUNET_YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,14 +136,14 @@ extract_amount (void *cls,
|
|||||||
* @return array entry for the result specification to use
|
* @return array entry for the result specification to use
|
||||||
*/
|
*/
|
||||||
struct GNUNET_SQ_ResultSpec
|
struct GNUNET_SQ_ResultSpec
|
||||||
TALER_SQ_result_spec_amount (const char *currency,
|
TALER_SQ_result_spec_amount_nbo (const char *currency,
|
||||||
struct TALER_Amount *amount)
|
struct TALER_AmountNBO *amount)
|
||||||
{
|
{
|
||||||
struct GNUNET_SQ_ResultSpec res = {
|
struct GNUNET_SQ_ResultSpec res = {
|
||||||
.conv = &extract_amount,
|
.conv = &extract_amount_nbo,
|
||||||
.cls = (void *) currency,
|
.cls = (void *) currency,
|
||||||
.dst = (void *) amount,
|
.dst = (void *) amount,
|
||||||
.dst_size = sizeof (struct TALER_Amount),
|
.dst_size = sizeof (struct TALER_AmountNBO),
|
||||||
.num_params = 2
|
.num_params = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -264,7 +264,6 @@ extract_round_time (void *cls,
|
|||||||
void *dst)
|
void *dst)
|
||||||
{
|
{
|
||||||
struct GNUNET_TIME_Absolute *udst = dst;
|
struct GNUNET_TIME_Absolute *udst = dst;
|
||||||
struct GNUNET_TIME_AbsoluteNBO res;
|
|
||||||
struct GNUNET_TIME_Absolute tmp;
|
struct GNUNET_TIME_Absolute tmp;
|
||||||
|
|
||||||
(void) cls;
|
(void) cls;
|
||||||
@ -280,9 +279,8 @@ extract_round_time (void *cls,
|
|||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
res.abs_value_us__ = sqlite3_column_int64 (result,
|
tmp.abs_value_us = sqlite3_column_int64 (result,
|
||||||
(int) column);
|
(int) column);
|
||||||
tmp = GNUNET_TIME_absolute_ntoh (res);
|
|
||||||
GNUNET_break (GNUNET_OK ==
|
GNUNET_break (GNUNET_OK ==
|
||||||
GNUNET_TIME_round_abs (&tmp));
|
GNUNET_TIME_round_abs (&tmp));
|
||||||
*udst = tmp;
|
*udst = tmp;
|
||||||
@ -333,7 +331,6 @@ extract_round_time_nbo (void *cls,
|
|||||||
void *dst)
|
void *dst)
|
||||||
{
|
{
|
||||||
struct GNUNET_TIME_AbsoluteNBO *udst = dst;
|
struct GNUNET_TIME_AbsoluteNBO *udst = dst;
|
||||||
struct GNUNET_TIME_AbsoluteNBO res;
|
|
||||||
struct GNUNET_TIME_Absolute tmp;
|
struct GNUNET_TIME_Absolute tmp;
|
||||||
|
|
||||||
(void) cls;
|
(void) cls;
|
||||||
@ -349,9 +346,8 @@ extract_round_time_nbo (void *cls,
|
|||||||
GNUNET_break (0);
|
GNUNET_break (0);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
res.abs_value_us__ = sqlite3_column_int64 (result,
|
tmp.abs_value_us = sqlite3_column_int64 (result,
|
||||||
(int) column);
|
(int) column);
|
||||||
tmp = GNUNET_TIME_absolute_ntoh (res);
|
|
||||||
GNUNET_break (GNUNET_OK ==
|
GNUNET_break (GNUNET_OK ==
|
||||||
GNUNET_TIME_round_abs (&tmp));
|
GNUNET_TIME_round_abs (&tmp));
|
||||||
*udst = GNUNET_TIME_absolute_hton (tmp);
|
*udst = GNUNET_TIME_absolute_hton (tmp);
|
||||||
|
Loading…
Reference in New Issue
Block a user