diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/sq/sq_query_helper.c | 61 | ||||
| -rw-r--r-- | src/sq/sq_result_helper.c | 84 | 
2 files changed, 69 insertions, 76 deletions
| diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c index 8e385355..e9070e14 100644 --- a/src/sq/sq_query_helper.c +++ b/src/sq/sq_query_helper.c @@ -29,7 +29,7 @@   * Function called to convert input argument into SQL parameters.   *   * @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 stmt sqlite statement to parameters for   * @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   */  static int -qconv_amount_nbo (void *cls, -                  const void *data, -                  size_t data_len, -                  sqlite3_stmt *stmt, -                  unsigned int off) +qconv_amount (void *cls, +              const void *data, +              size_t data_len, +              sqlite3_stmt *stmt, +              unsigned int off)  { -  const struct TALER_AmountNBO *amount = data; +  const struct TALER_Amount *amount = data;    (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,                                         (int) off,                                         (sqlite3_int64) amount->value)) @@ -67,10 +67,10 @@ qconv_amount_nbo (void *cls,   * @param x pointer to the query parameter to pass   */  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 = -  { &qconv_amount_nbo, NULL, x, sizeof (*x), 2 }; +  { &qconv_amount, NULL, x, sizeof (*x), 2 };    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.   *   * @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 stmt sqlite statement to parameters for   * @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   */  static int -qconv_amount (void *cls, -              const void *data, -              size_t data_len, -              sqlite3_stmt *stmt, -              unsigned int off) +qconv_amount_nbo (void *cls, +                  const void *data, +                  size_t data_len, +                  sqlite3_stmt *stmt, +                  unsigned int off)  { -  const struct TALER_Amount *amount_hbo = data; -  struct TALER_AmountNBO amount; +  const struct TALER_AmountNBO *amount = data; +  struct TALER_Amount amount_hbo;    (void) cls; -  GNUNET_assert (sizeof (struct TALER_AmountNBO) == data_len); -  TALER_amount_hton (&amount, -                     amount_hbo); -  return qconv_amount_nbo (cls, -                           &amount, -                           sizeof (struct TALER_AmountNBO), -                           stmt, -                           off); +  TALER_amount_ntoh (&amount_hbo, +                     amount); +  return qconv_amount (cls, +                       &amount_hbo, +                       sizeof (struct TALER_Amount), +                       stmt, +                       off);  } @@ -116,10 +115,10 @@ qconv_amount (void *cls,   * @param x pointer to the query parameter to pass   */  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 = -  { &qconv_amount, NULL, x, sizeof (*x), 2 }; +  { &qconv_amount_nbo, NULL, x, sizeof (*x), 2 };    return res;  } @@ -199,7 +198,6 @@ qconv_round_time (void *cls,  {    const struct GNUNET_TIME_Absolute *at = data;    struct GNUNET_TIME_Absolute tmp; -  struct GNUNET_TIME_AbsoluteNBO buf;    (void) cls;    GNUNET_assert (sizeof (struct GNUNET_TIME_AbsoluteNBO) == data_len); @@ -207,10 +205,9 @@ qconv_round_time (void *cls,    tmp = *at;    GNUNET_assert (GNUNET_OK ==                   GNUNET_TIME_round_abs (&tmp)); -  buf = GNUNET_TIME_absolute_hton (tmp);    if (SQLITE_OK != sqlite3_bind_int64 (stmt,                                         (int) off, -                                       (sqlite3_int64) buf.abs_value_us__)) +                                       (sqlite3_int64) at->abs_value_us))      return GNUNET_SYSERR;    return GNUNET_OK;  } @@ -263,7 +260,7 @@ qconv_round_time_abs (void *cls,                   GNUNET_TIME_round_abs (&tmp));    if (SQLITE_OK != sqlite3_bind_int64 (stmt,                                         (int) off, -                                       (sqlite3_int64) at->abs_value_us__)) +                                       (sqlite3_int64) tmp.abs_value_us))      return GNUNET_SYSERR;    return GNUNET_OK;  } diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c index d313ed59..bc52913b 100644 --- a/src/sq/sq_result_helper.c +++ b/src/sq/sq_result_helper.c @@ -39,15 +39,15 @@   *   #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)   */  static int -extract_amount_nbo (void *cls, -                    sqlite3_stmt *result, -                    unsigned int column, -                    size_t *dst_size, -                    void *dst) +extract_amount (void *cls, +                sqlite3_stmt *result, +                unsigned int column, +                size_t *dst_size, +                void *dst)  { -  struct TALER_AmountNBO *amount = dst; +  struct TALER_Amount *amount = dst;    const char *currency = cls; -  if ((sizeof (struct TALER_AmountNBO) != *dst_size) || +  if ((sizeof (struct TALER_Amount) != *dst_size) ||        (SQLITE_INTEGER != sqlite3_column_type (result,                                                (int) column)) ||        (SQLITE_INTEGER != sqlite3_column_type (result, @@ -56,11 +56,13 @@ extract_amount_nbo (void *cls,      GNUNET_break (0);      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,                                                     (int) column);    uint64_t frac = (uint64_t) sqlite3_column_int64 (result, -                                                   column + 1); +                                                   (int) column + 1);    amount->fraction = (uint32_t) frac;    return GNUNET_YES;  } @@ -74,14 +76,14 @@ extract_amount_nbo (void *cls,   * @return array entry for the result specification to use   */  struct GNUNET_SQ_ResultSpec -TALER_SQ_result_spec_amount_nbo (const char *currency, -                                 struct TALER_AmountNBO *amount) +TALER_SQ_result_spec_amount (const char *currency, +                             struct TALER_Amount *amount)  {    struct GNUNET_SQ_ResultSpec res = { -    .conv = &extract_amount_nbo, +    .conv = &extract_amount,      .cls = (void *) currency,      .dst = (void *) amount, -    .dst_size = sizeof (struct TALER_AmountNBO), +    .dst_size = sizeof (struct TALER_Amount),      .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)   */  static int -extract_amount (void *cls, -                sqlite3_stmt *result, -                unsigned int column, -                size_t *dst_size, -                void *dst) +extract_amount_nbo (void *cls, +                    sqlite3_stmt *result, +                    unsigned int column, +                    size_t *dst_size, +                    void *dst)  { -  struct TALER_Amount *amount = dst; -  struct TALER_AmountNBO amount_nbo; -  if (GNUNET_YES == extract_amount_nbo (cls, -                                        result, -                                        column, -                                        dst_size, -                                        &amount_nbo)) -  { -    TALER_amount_ntoh (amount, -                       &amount_nbo); -    return GNUNET_YES; -  } -  else +  struct TALER_AmountNBO *amount = dst; +  struct TALER_Amount amount_hbo; +  size_t amount_hbo_size = sizeof (struct TALER_Amount); +  if (GNUNET_YES != extract_amount (cls, +                                    result, +                                    column, +                                    &amount_hbo_size, +                                    &amount_hbo))    { +    GNUNET_break (0);      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   */  struct GNUNET_SQ_ResultSpec -TALER_SQ_result_spec_amount (const char *currency, -                             struct TALER_Amount *amount) +TALER_SQ_result_spec_amount_nbo (const char *currency, +                                 struct TALER_AmountNBO *amount)  {    struct GNUNET_SQ_ResultSpec res = { -    .conv = &extract_amount, +    .conv = &extract_amount_nbo,      .cls = (void *) currency,      .dst = (void *) amount, -    .dst_size = sizeof (struct TALER_Amount), +    .dst_size = sizeof (struct TALER_AmountNBO),      .num_params = 2    }; @@ -264,7 +264,6 @@ extract_round_time (void *cls,                      void *dst)  {    struct GNUNET_TIME_Absolute *udst = dst; -  struct GNUNET_TIME_AbsoluteNBO res;    struct GNUNET_TIME_Absolute tmp;    (void) cls; @@ -280,9 +279,8 @@ extract_round_time (void *cls,      GNUNET_break (0);      return GNUNET_SYSERR;    } -  res.abs_value_us__ = sqlite3_column_int64 (result, -                                             (int) column); -  tmp = GNUNET_TIME_absolute_ntoh (res); +  tmp.abs_value_us = sqlite3_column_int64 (result, +                                           (int) column);    GNUNET_break (GNUNET_OK ==                  GNUNET_TIME_round_abs (&tmp));    *udst = tmp; @@ -333,7 +331,6 @@ extract_round_time_nbo (void *cls,                          void *dst)  {    struct GNUNET_TIME_AbsoluteNBO *udst = dst; -  struct GNUNET_TIME_AbsoluteNBO res;    struct GNUNET_TIME_Absolute tmp;    (void) cls; @@ -349,9 +346,8 @@ extract_round_time_nbo (void *cls,      GNUNET_break (0);      return GNUNET_SYSERR;    } -  res.abs_value_us__ = sqlite3_column_int64 (result, -                                             (int) column); -  tmp = GNUNET_TIME_absolute_ntoh (res); +  tmp.abs_value_us = sqlite3_column_int64 (result, +                                           (int) column);    GNUNET_break (GNUNET_OK ==                  GNUNET_TIME_round_abs (&tmp));    *udst = GNUNET_TIME_absolute_hton (tmp); | 
