diff options
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 83a4cea2..37d1992f 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1483,6 +1483,31 @@ postgres_lookup_contract_terms (void *cls, /** + * Create a dummy URL for the 'fulfillment' URL that consist + * of random letters. Used because we do not like putting NULL + * into the database, but do need to ensure that a query + * never matches this URL. + * + * @return randomized URL starting with "void://", changes at + * ever call to this function + */ +static const char * +make_dummy_url (void) +{ + static char buf[128] = "void://"; + struct GNUNET_HashCode hc; + + GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, + &hc); + GNUNET_STRINGS_data_to_string (&hc, + sizeof (hc), + &buf[7], + sizeof (buf) - 8); + return buf; +} + + +/** * Store contract terms given its @a order_id. Note that some attributes are * expected to be calculated inside of the function, like the hash of the * contract terms (to be hashed), the creation_time and pay_deadline (to be @@ -1519,8 +1544,6 @@ postgres_insert_contract_terms (void *cls, { struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("fulfillment_url", - &fulfillment_url), TALER_JSON_spec_absolute_time ("pay_deadline", &pay_deadline), TALER_JSON_spec_absolute_time ("refund_deadline", @@ -1539,6 +1562,11 @@ postgres_insert_contract_terms (void *cls, } } + fulfillment_url = + json_string_value (json_object_get (contract_terms, + "fulfillment_url")); + if (NULL == fulfillment_url) + fulfillment_url = make_dummy_url (); check_connection (pg); { struct GNUNET_PQ_QueryParam params[] = { @@ -1596,8 +1624,6 @@ postgres_update_contract_terms (void *cls, { struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("fulfillment_url", - &fulfillment_url), TALER_JSON_spec_absolute_time ("pay_deadline", &pay_deadline), TALER_JSON_spec_absolute_time ("refund_deadline", @@ -1616,6 +1642,12 @@ postgres_update_contract_terms (void *cls, } } + fulfillment_url = + json_string_value (json_object_get (contract_terms, + "fulfillment_url")); + if (NULL == fulfillment_url) + fulfillment_url = make_dummy_url (); + check_connection (pg); { struct GNUNET_PQ_QueryParam params[] = { @@ -3232,7 +3264,6 @@ postgres_lookup_order_by_fulfillment (void *cls, char **order_id) { struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (instance_id), GNUNET_PQ_query_param_string (fulfillment_url), |