aboutsummaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_private-post-orders.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-orders.c')
-rw-r--r--src/backend/taler-merchant-httpd_private-post-orders.c156
1 files changed, 92 insertions, 64 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c
index eedece55..8bdae3f1 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders.c
@@ -940,6 +940,8 @@ execute_order (struct OrderContext *oc)
struct TALER_MERCHANTDB_ProductDetails pd;
MHD_RESULT ret;
const struct InventoryProduct *ip;
+ size_t num_categories = 0;
+ uint64_t *categories = NULL;
ip = &oc->parse_request.inventory_products[
oc->execute_order.out_of_stock_index];
@@ -950,10 +952,13 @@ execute_order (struct OrderContext *oc)
TMH_db->cls,
oc->hc->instance->settings.id,
ip->product_id,
- &pd);
+ &pd,
+ &num_categories,
+ &categories);
switch (qs)
{
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ GNUNET_free (categories);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Order creation failed: product out of stock\n");
ret = TALER_MHD_REPLY_JSON_PACK (
@@ -1317,6 +1322,7 @@ get_exchange_keys (void *cls,
rx);
}
+
/**
* Fetch details about the token family with the given @a slug
* and add them to the list of token authorities. Check if the
@@ -1340,12 +1346,13 @@ set_token_authority (struct OrderContext *oc,
// TODO: make this configurable. This is the granularity of token
// expiration dates.
GNUNET_TIME_UNIT_DAYS
- );
+ );
qs = TMH_db->lookup_token_family_key (TMH_db->cls,
oc->hc->instance->settings.id,
slug,
- GNUNET_TIME_absolute_to_timestamp (min_start_date),
+ GNUNET_TIME_absolute_to_timestamp (
+ min_start_date),
start_date,
&key_details);
@@ -1390,9 +1397,10 @@ set_token_authority (struct OrderContext *oc,
struct GNUNET_CRYPTO_BlindSignPrivateKey *priv;
struct GNUNET_CRYPTO_BlindSignPublicKey *pub;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- struct GNUNET_TIME_Timestamp valid_before = GNUNET_TIME_absolute_to_timestamp(
- GNUNET_TIME_absolute_add (now,
- key_details.token_family.duration));
+ struct GNUNET_TIME_Timestamp valid_before =
+ GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (now,
+ key_details.token_family.duration));
GNUNET_CRYPTO_blind_sign_keys_create (&priv,
&pub,
@@ -1411,13 +1419,16 @@ set_token_authority (struct OrderContext *oc,
slug,
&token_pub,
&token_priv,
- GNUNET_TIME_absolute_to_timestamp (now),
+ GNUNET_TIME_absolute_to_timestamp (now
+ ),
valid_before);
authority.token_expiration = valid_before;
authority.pub = &token_pub;
// GNUNET_CRYPTO_blind_sign_priv_decref (&token_priv.private_key);
- } else {
+ }
+ else
+ {
authority.token_expiration = key_details.valid_before;
authority.pub = key_details.pub;
}
@@ -1428,11 +1439,13 @@ set_token_authority (struct OrderContext *oc,
GNUNET_free (key_details.token_family.slug);
GNUNET_free (key_details.token_family.name);
- if (NULL != key_details.priv) {
+ if (NULL != key_details.priv)
+ {
GNUNET_CRYPTO_blind_sign_priv_decref (&key_details.priv->private_key);
}
- switch (key_details.token_family.kind) {
+ switch (key_details.token_family.kind)
+ {
case TALER_MERCHANTDB_TFK_Subscription:
authority.kind = TALER_MCTK_SUBSCRIPTION;
authority.details.subscription.start_date = key_details.valid_after;
@@ -1454,6 +1467,7 @@ set_token_authority (struct OrderContext *oc,
return MHD_YES;
}
+
/**
* Serialize order into @a oc->serialize_order.contract,
* ready to be stored in the database. Upon success, continue
@@ -1472,16 +1486,16 @@ serialize_order (struct OrderContext *oc)
merchant = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("name",
- settings->name),
+ settings->name),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("website",
- settings->website)),
+ settings->website)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("email",
- settings->email)),
+ settings->email)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("logo",
- settings->logo)));
+ settings->logo)));
GNUNET_assert (NULL != merchant);
{
json_t *loca;
@@ -1493,7 +1507,7 @@ serialize_order (struct OrderContext *oc)
loca = json_deep_copy (loca);
GNUNET_assert (NULL != loca);
GNUNET_assert (0 ==
- json_object_set_new (merchant,
+ json_object_set_new (merchant,
"address",
loca));
}
@@ -1508,7 +1522,7 @@ serialize_order (struct OrderContext *oc)
juri = json_deep_copy (juri);
GNUNET_assert (NULL != juri);
GNUNET_assert (0 ==
- json_object_set_new (merchant,
+ json_object_set_new (merchant,
"jurisdiction",
juri));
}
@@ -1516,7 +1530,8 @@ serialize_order (struct OrderContext *oc)
for (unsigned int i = 0; i<oc->parse_choices.authorities_len; i++)
{
- struct TALER_MerchantContractTokenAuthority *authority = &oc->parse_choices.authorities[i];
+ struct TALER_MerchantContractTokenAuthority *authority = &oc->parse_choices.
+ authorities[i];
// TODO: Finish spec to clearly define how token families are stored in
// ContractTerms.
@@ -1529,7 +1544,7 @@ serialize_order (struct OrderContext *oc)
// so it's clear with key is referenced.
json_t *jauthority = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("description",
- authority->description),
+ authority->description),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("description_i18n",
authority->description_i18n)),
@@ -1539,10 +1554,10 @@ serialize_order (struct OrderContext *oc)
&authority->pub->public_key.pub_key_hash),
GNUNET_JSON_pack_timestamp ("token_expiration",
authority->token_expiration)
- );
+ );
GNUNET_assert (0 ==
- json_object_set_new (token_types,
+ json_object_set_new (token_types,
authority->label,
jauthority));
}
@@ -1561,20 +1576,21 @@ serialize_order (struct OrderContext *oc)
json_t *jinput = GNUNET_JSON_PACK (
GNUNET_JSON_pack_int64 ("type",
input->type)
- );
+ );
if (TALER_MCIT_TOKEN == input->type)
{
- GNUNET_assert(0 ==
- json_object_set_new(jinput,
- "number",
- json_integer (
- input->details.token.count)));
- GNUNET_assert(0 ==
- json_object_set_new(jinput,
- "token_family_slug",
- json_string (
- input->details.token.token_family_slug)));
+ GNUNET_assert (0 ==
+ json_object_set_new (jinput,
+ "number",
+ json_integer (
+ input->details.token.count)));
+ GNUNET_assert (0 ==
+ json_object_set_new (jinput,
+ "token_family_slug",
+ json_string (
+ input->details.token.
+ token_family_slug)));
}
GNUNET_assert (0 == json_array_append_new (inputs, jinput));
@@ -1587,21 +1603,22 @@ serialize_order (struct OrderContext *oc)
json_t *joutput = GNUNET_JSON_PACK (
GNUNET_JSON_pack_int64 ("type",
output->type)
- );
+ );
if (TALER_MCOT_TOKEN == output->type)
{
- GNUNET_assert(0 ==
- json_object_set_new(joutput,
- "number",
- json_integer (
- output->details.token.count)));
-
- GNUNET_assert(0 ==
- json_object_set_new(joutput,
- "token_family_slug",
- json_string (
- output->details.token.token_family_slug)));
+ GNUNET_assert (0 ==
+ json_object_set_new (joutput,
+ "number",
+ json_integer (
+ output->details.token.count)));
+
+ GNUNET_assert (0 ==
+ json_object_set_new (joutput,
+ "token_family_slug",
+ json_string (
+ output->details.token.
+ token_family_slug)));
}
GNUNET_assert (0 == json_array_append (outputs, joutput));
@@ -1609,10 +1626,10 @@ serialize_order (struct OrderContext *oc)
json_t *jchoice = GNUNET_JSON_PACK (
GNUNET_JSON_pack_array_incref ("inputs",
- inputs),
+ inputs),
GNUNET_JSON_pack_array_incref ("outputs",
- outputs)
- );
+ outputs)
+ );
GNUNET_assert (0 == json_array_append (choices, jchoice));
}
@@ -1633,7 +1650,8 @@ serialize_order (struct OrderContext *oc)
oc->parse_order.fulfillment_message)),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("fulfillment_message_i18n",
- oc->parse_order.fulfillment_message_i18n)),
+ oc->parse_order.fulfillment_message_i18n))
+ ,
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_string ("fulfillment_url",
oc->parse_order.fulfillment_url)),
@@ -1674,12 +1692,12 @@ serialize_order (struct OrderContext *oc)
&oc->parse_order.brutto),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_array_incref ("choices",
- choices)
- ),
+ choices)
+ ),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("token_types",
token_types)
- ),
+ ),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_object_incref ("extra",
(json_t *) oc->parse_order.extra))
@@ -1715,6 +1733,7 @@ serialize_order (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Set max_fee in @a oc based on STEFAN value if
* not yet present. Upon success, continue
@@ -1750,6 +1769,7 @@ set_max_fee (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Set list of acceptable exchanges in @a oc. Upon success, continue
* processing with set_max_fee().
@@ -1871,7 +1891,7 @@ parse_order (struct OrderContext *oc)
NULL),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_array_const ("choices",
- &oc->parse_order.choices),
+ &oc->parse_order.choices),
NULL),
GNUNET_JSON_spec_mark_optional (
TALER_JSON_spec_web_url ("merchant_base_url",
@@ -1937,7 +1957,7 @@ parse_order (struct OrderContext *oc)
ret);
return;
}
- if (NULL == version || 0 == strcmp("0", version))
+ if (NULL == version || 0 == strcmp ("0", version))
{
oc->parse_order.version = TALER_MCV_V0;
@@ -1952,11 +1972,11 @@ parse_order (struct OrderContext *oc)
return;
}
}
- else if (0 == strcmp("1", version))
+ else if (0 == strcmp ("1", version))
{
oc->parse_order.version = TALER_MCV_V1;
- if (! json_is_array(oc->parse_order.choices))
+ if (! json_is_array (oc->parse_order.choices))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -1989,9 +2009,9 @@ parse_order (struct OrderContext *oc)
return;
}
if ( (! no_fee) &&
- (GNUNET_OK !=
- TALER_amount_cmp_currency (&oc->parse_order.brutto,
- &oc->parse_order.max_fee)) )
+ (GNUNET_OK !=
+ TALER_amount_cmp_currency (&oc->parse_order.brutto,
+ &oc->parse_order.max_fee)) )
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -2268,6 +2288,7 @@ parse_order (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Parse contract choices. Upon success, continue
* processing with merge_inventory().
@@ -2355,7 +2376,7 @@ parse_choices (struct OrderContext *oc)
GNUNET_JSON_spec_uint32 ("count",
&input.details.token.count),
NULL),
- GNUNET_JSON_spec_end()
+ GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
@@ -2431,7 +2452,8 @@ parse_choices (struct OrderContext *oc)
size_t idx;
json_array_foreach ((json_t *) joutputs, idx, joutput)
{
- struct TALER_MerchantContractOutput output = { .details.token.count = 1 };
+ struct TALER_MerchantContractOutput output = { .details.token.count = 1}
+ ;
const char *kind;
const char *ierror_name;
unsigned int ierror_line;
@@ -2447,14 +2469,14 @@ parse_choices (struct OrderContext *oc)
GNUNET_JSON_spec_uint32 ("count",
&output.details.token.count),
NULL),
- GNUNET_JSON_spec_end()
+ GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
GNUNET_JSON_parse (joutput,
- ispec,
- &ierror_name,
- &ierror_line))
+ ispec,
+ &ierror_name,
+ &ierror_line))
{
GNUNET_JSON_parse_free (spec);
GNUNET_JSON_parse_free (ispec);
@@ -2526,6 +2548,7 @@ parse_choices (struct OrderContext *oc)
oc->phase++;
}
+
/**
* Process the @a payment_target and add the details of how the
* order could be paid to @a order. On success, continue
@@ -2591,11 +2614,15 @@ merge_inventory (struct OrderContext *oc)
= &oc->parse_request.inventory_products[i];
struct TALER_MERCHANTDB_ProductDetails pd;
enum GNUNET_DB_QueryStatus qs;
+ size_t num_categories = 0;
+ uint64_t *categories = NULL;
qs = TMH_db->lookup_product (TMH_db->cls,
oc->hc->instance->settings.id,
ip->product_id,
- &pd);
+ &pd,
+ &num_categories,
+ &categories);
if (qs <= 0)
{
enum TALER_ErrorCode ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
@@ -2631,6 +2658,7 @@ merge_inventory (struct OrderContext *oc)
ip->product_id);
return;
}
+ GNUNET_free (categories);
oc->parse_order.minimum_age
= GNUNET_MAX (oc->parse_order.minimum_age,
pd.minimum_age);