diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/include/taler_mintdb_plugin.h | 6 | ||||
| -rw-r--r-- | src/mintdb/plugin_mintdb_postgres.c | 28 | ||||
| -rw-r--r-- | src/mintdb/test_mintdb.c | 17 | 
3 files changed, 21 insertions, 30 deletions
| diff --git a/src/include/taler_mintdb_plugin.h b/src/include/taler_mintdb_plugin.h index 0cbcb3c4..63dacf73 100644 --- a/src/include/taler_mintdb_plugin.h +++ b/src/include/taler_mintdb_plugin.h @@ -332,7 +332,7 @@ struct TALER_MINTDB_RefreshMelt     */    struct TALER_Amount amount_with_fee; -  /** +  /** FIXME: This can be retrieved from the Denomination? Do we need this?     * Melting fee charged by the mint.  This must match the Mint's     * denomination key's melting fee.  If the client puts in an invalid     * melting fee (too high or too low) that does not match the Mint's @@ -848,7 +848,7 @@ struct TALER_MINTDB_Plugin     * @param cls the plugin closure     * @param session the database session handle     * @param coin_pub the public key of the coin to search for -   * @param ret_coin_info place holder for the returned coin information object +   * @param coin_info place holder for the returned coin information object     * @return #GNUNET_SYSERR upon error; #GNUNET_NO if no coin is found; #GNUNET_OK     *           if upon succesfullying retrieving the record data info @a     *           ret_coin_info @@ -857,7 +857,7 @@ struct TALER_MINTDB_Plugin    (*get_known_coin) (void *cls,                       struct TALER_MINTDB_Session *session,                       const struct TALER_CoinSpendPublicKeyP *coin_pub, -                     struct TALER_CoinPublicInfo **ret_coin_info); +                     struct TALER_CoinPublicInfo *coin_info);    /** diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c index 67097261..1157ca09 100644 --- a/src/mintdb/plugin_mintdb_postgres.c +++ b/src/mintdb/plugin_mintdb_postgres.c @@ -1641,23 +1641,24 @@ postgres_insert_known_coin (void *cls,   * @param cls the plugin closure   * @param session the database session handle   * @param coin_pub the public key of the coin to search for - * @param ret_coin_info place holder for the returned coin information object + * @param coin_info place holder for the returned coin information object   * @return #GNUNET_SYSERR upon error; #GNUNET_NO if no coin is found; #GNUNET_OK   *           if upon succesfullying retrieving the record data info @a - *           ret_coin_info + *           coin_info   */  static int  postgres_get_known_coin (void *cls,                           struct TALER_MINTDB_Session *session,                           const struct TALER_CoinSpendPublicKeyP *coin_pub, -                         struct TALER_CoinPublicInfo **ret_coin_info) +                         struct TALER_CoinPublicInfo *coin_info)  {    PGresult *result;    struct TALER_PQ_QueryParam params[] = {      TALER_PQ_query_param_auto_from_type (coin_pub),      TALER_PQ_query_param_end    }; -  struct TALER_CoinPublicInfo *coin_info; +  int nrows; +    result = TALER_PQ_exec_prepared (session->conn,                                     "get_known_coin",                                     params); @@ -1667,17 +1668,13 @@ postgres_get_known_coin (void *cls,      PQclear (result);      return GNUNET_SYSERR;    } -  if (0 == PQntuples (result)) +  nrows = PQntuples (result); +  if (0 == nrows)    {      PQclear (result);      return GNUNET_NO;    } -  if ((NULL == ret_coin_info) && (1 == PQntuples (result))) -  { -    PQclear (result); -    return GNUNET_OK; -  } -  coin_info = GNUNET_new (struct TALER_CoinPublicInfo); +  GNUNET_assert (1 == nrows);   /* due to primary key */    struct TALER_PQ_ResultSpec rs[] = {      TALER_PQ_result_spec_rsa_public_key ("denom_pub", &coin_info->denom_pub.rsa_public_key),      TALER_PQ_result_spec_rsa_signature ("denom_sig", &coin_info->denom_sig.rsa_signature), @@ -1691,10 +1688,11 @@ postgres_get_known_coin (void *cls,      return GNUNET_SYSERR;    }    PQclear (result); -  (void) memcpy (&coin_info->coin_pub, -                 coin_pub, -                 sizeof (struct TALER_CoinSpendPublicKeyP)); -  *ret_coin_info = coin_info; +  /* no need to copy if the src and dest are same */ +  if (coin_pub != &coin_info->coin_pub) +    (void) memcpy (&coin_info->coin_pub, +                   coin_pub, +                   sizeof (struct TALER_CoinSpendPublicKeyP));    return GNUNET_OK;  } diff --git a/src/mintdb/test_mintdb.c b/src/mintdb/test_mintdb.c index d5399d4c..9e93401c 100644 --- a/src/mintdb/test_mintdb.c +++ b/src/mintdb/test_mintdb.c @@ -180,7 +180,7 @@ static int  test_known_coins (struct TALER_MINTDB_Session *session)  {    struct TALER_CoinPublicInfo coin_info; -  struct TALER_CoinPublicInfo *ret_coin_info; +  struct TALER_CoinPublicInfo ret_coin_info;    struct DenomKeyPair *dkp;    int ret = GNUNET_SYSERR; @@ -190,13 +190,11 @@ test_known_coins (struct TALER_MINTDB_Session *session)    coin_info.denom_sig.rsa_signature =        GNUNET_CRYPTO_rsa_sign (dkp->priv.rsa_private_key,                                "foobar", 6); -  ret_coin_info = NULL;    FAILIF (GNUNET_NO !=            plugin->get_known_coin (plugin->cls,                                    session,                                    &coin_info.coin_pub,                                    &ret_coin_info)); -  FAILIF (NULL != ret_coin_info);    FAILIF (GNUNET_OK !=            plugin->insert_known_coin (plugin->cls,                                       session, @@ -206,23 +204,18 @@ test_known_coins (struct TALER_MINTDB_Session *session)                                    session,                                    &coin_info.coin_pub,                                    &ret_coin_info)); -  FAILIF (NULL == ret_coin_info);    FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp -          (ret_coin_info->denom_pub.rsa_public_key, +          (ret_coin_info.denom_pub.rsa_public_key,             coin_info.denom_pub.rsa_public_key));    FAILIF (0 != GNUNET_CRYPTO_rsa_signature_cmp -          (ret_coin_info->denom_sig.rsa_signature, +          (ret_coin_info.denom_sig.rsa_signature,             coin_info.denom_sig.rsa_signature)); +  GNUNET_CRYPTO_rsa_public_key_free (ret_coin_info.denom_pub.rsa_public_key); +  GNUNET_CRYPTO_rsa_signature_free (ret_coin_info.denom_sig.rsa_signature);    ret = GNUNET_OK;   drop:    destroy_denom_key_pair (dkp);    GNUNET_CRYPTO_rsa_signature_free (coin_info.denom_sig.rsa_signature); -  if (NULL != ret_coin_info) -  { -    GNUNET_CRYPTO_rsa_public_key_free (ret_coin_info->denom_pub.rsa_public_key); -    GNUNET_CRYPTO_rsa_signature_free (ret_coin_info->denom_sig.rsa_signature); -    GNUNET_free (ret_coin_info); -  }    return ret;  } | 
