summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend-lib/taler-merchant-httpd_contract.c45
-rw-r--r--src/backend/taler-merchant-httpd.c64
-rw-r--r--src/tests/merchant-contract-test.c28
3 files changed, 103 insertions, 34 deletions
diff --git a/src/backend-lib/taler-merchant-httpd_contract.c b/src/backend-lib/taler-merchant-httpd_contract.c
index 0a6ed0de..319ca07c 100644
--- a/src/backend-lib/taler-merchant-httpd_contract.c
+++ b/src/backend-lib/taler-merchant-httpd_contract.c
@@ -52,15 +52,16 @@ hash_wireformat (uint64_t nounce, const struct MERCHANT_WIREFORMAT_Sepa *wire)
* Take from the frontend the (partly) generated contract and fill
* the missing values in it; for example, the SEPA-aware values.
* Moreover, it stores the contract in the DB.
-* @param contract parsed contract, originated by the frontend
+* @param j_contract parsed contract, originated by the frontend
* @param db_conn the handle to the local DB
* @param wire merchant's bank's details
-* @param sig where to store the (subset of the) contract to be signed
+* @param where to store the (subset of the) contract to be (still) signed
* @return pointer to the complete JSON; NULL upon errors
*/
-/* TODO: this handles a simplified version (for debugging purposes)
- of the contract. To expand to the full fledged version */
+/**
+* TODO: inspection of reference counting and, accordingly, free those json_t*(s)
+* still allocated */
json_t *
MERCHANT_handle_contract (json_t *j_contract,
@@ -73,10 +74,13 @@ MERCHANT_handle_contract (json_t *j_contract,
json_t *j_timestamp;
json_t *jh_wire;
json_t *j_amount;
+ json_t *j_mints;
+ json_t *j_max_fee;
json_int_t j_trans_id;
uint64_t nounce;
- uint64_t product_id;
+ json_t *j_product_id;
+ json_t *j_items_tmp;
char *a;
char *h_wire_enc;
#ifdef DEBUG
@@ -98,32 +102,37 @@ MERCHANT_handle_contract (json_t *j_contract,
h_wire = hash_wireformat (nounce, wire);
h_wire_enc = GNUNET_STRINGS_data_to_string_alloc (&h_wire,
sizeof (struct GNUNET_HashCode));
-
jh_wire = json_string (h_wire_enc);
-
- #ifdef DEBUG
- str = json_dumps (j_contract, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
- #endif
-
-
- if (-1 == json_unpack (j_contract, "{s:o, s:I, s:o}",
+ if (-1 == json_unpack (j_contract, "{s:o, s:o, s:I, s:o, s:o}",
"amount", &j_amount,
+ "max fee", &j_max_fee,
"trans_id", &j_trans_id,
+ "mints", &j_mints,
"details", &j_details))
return NULL;
/* needed for DB stuff */
TALER_json_to_amount (j_amount, &amount);
- /* temporary way of getting this value. To be adapted to the expanded contract
- format. (This value is now supplied in the 'item' object!!) See 'TODO' above. */
- product_id = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
+ j_items_tmp = json_object_get (j_details, "items");
+ j_product_id = json_object_get (j_items_tmp, "product_id");
+
+ #ifdef DEBUG
+ printf ("prod id is at %p, eval to %d\n", j_product_id, json_integer_value (j_product_id));
+ return NULL;
+ #endif
+
+
+
+
/* adding the generated values in this JSON */
- root = json_pack ("{s:o, s:I, s:s, s:o, s:o}",
+ root = json_pack ("{s:o, s:o, s:I, s:s, s:o, s:o, s:o}",
"amount", j_amount,
+ "max fee", j_max_fee,
"trans_id", j_trans_id,
"h_wire", jh_wire,
"timestamp", j_timestamp,
+ "mints", j_mints,
"details", j_details);
a = json_dumps (root, JSON_COMPACT | JSON_PRESERVE_ORDER);
@@ -135,7 +144,7 @@ MERCHANT_handle_contract (json_t *j_contract,
(uint64_t) j_trans_id, // safe?
a,
nounce,
- product_id));
+ json_integer_value (j_product_id)));
contract->h_wire = h_wire;
TALER_amount_hton (&amount_nbo, &amount);
contract->amount = amount_nbo;
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 5c17274a..57a8b109 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -348,11 +348,13 @@ url_handler (void *cls,
json_t *j_mints;
json_t *j_mint;
int cnt; /* loop counter */
- #if 0
+ char *str; /* to debug JSONs */
+ #if 1
json_t *root_tmp;
json_t *j_amount_tmp;
json_t *j_details_tmp;
- json_int_t *j_trans_id_tmp;
+ json_t *j_max_fee_tmp;
+ json_int_t j_trans_id_tmp;
#endif
int res = GNUNET_SYSERR;
@@ -414,26 +416,50 @@ url_handler (void *cls,
mint_infos[cnt].hostname,
GNUNET_CRYPTO_eddsa_public_key_to_string (&mint_infos[cnt].pubkey));
json_array_append_new (j_mints, j_mint);
+
+ #define DEBUGG
#ifdef DEBUG
- printf ("mint(s): url %s, key %s", mint_infos[cnt].hostname,
+ printf ("mint(s): url %s, key %s\n", mint_infos[cnt].hostname,
GNUNET_CRYPTO_eddsa_public_key_to_string (&mint_infos[cnt].pubkey));
+ str = json_dumps (j_mint, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
+ printf ("%s\n", str);
#endif
}
- json_object_set (root, "mints", j_mints);
+ if (-1 == (json_unpack (root,
+ "{s:o, s:o, s:I, s:o}",
+ "amount", &j_amount_tmp,
+ "max fee", &j_max_fee_tmp,
+ "trans_id", &j_trans_id_tmp,
+ "details", &j_details_tmp)))
+ {
+ printf ("no unpack\n");
+ status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ goto end;
+ }
- TMH_RESPONSE_reply_json (connection, root, MHD_HTTP_OK);
- return MHD_YES;
+
+ if (NULL == (root_tmp = json_pack ("{s:o, s:o, s:I, s:o, s:o}",
+ "amount", j_amount_tmp,
+ "max fee", j_max_fee_tmp,
+ "trans_id", j_trans_id_tmp,
+ "mints", j_mints,
+ "details", j_details_tmp)))
+ {
+ printf ("no pack\n");
+ status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ goto end;
+ }
#if 0
- root_tmp = json_unpack ("{s:o, s:I, s:o}",
- "amount", &j_amount_tmp,
- "trans_id", &j_trans_id_tmp,
- "details", &j_details_tmp);
+ /* FIXME TMH_RESPONSE_reply_json subverts the order of some fields */
+ str = json_dumps (root_tmp, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
+ printf ("%s\n", str);
+ return;
#endif
- if (NULL == (j_contract_complete = MERCHANT_handle_contract (root,
+ if (NULL == (j_contract_complete = MERCHANT_handle_contract (root_tmp,
db_conn,
wire,
&contract)))
@@ -442,6 +468,14 @@ url_handler (void *cls,
goto end;
}
+ #if 0
+ /* FIXME TMH_RESPONSE_reply_json subverts the order of some fields */
+ str = json_dumps (j_contract_complete, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
+ printf ("%s\n", str);
+ return;
+ #endif
+
+
GNUNET_CRYPTO_eddsa_sign (privkey, &contract.purpose, &c_sig);
/**
@@ -462,6 +496,14 @@ url_handler (void *cls,
"sig", j_sig_enc,
"eddsa_pub", eddsa_pub_enc);
+
+ #if 1
+ /* FIXME TMH_RESPONSE_reply_json subverts the order of some fields */
+ str = json_dumps (response, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
+ printf ("%s\n", str);
+ return;
+ #endif
+
TMH_RESPONSE_reply_json (connection, response, MHD_HTTP_OK);
return MHD_YES;
diff --git a/src/tests/merchant-contract-test.c b/src/tests/merchant-contract-test.c
index 2a68bb48..a1855203 100644
--- a/src/tests/merchant-contract-test.c
+++ b/src/tests/merchant-contract-test.c
@@ -74,6 +74,7 @@ run (void *cls, char *const *args, const char *cfgfile,
json_t *j_fake_contract;
json_t *j_root;
json_t *j_details;
+ json_t *j_mints;
json_t *j_item;
json_t *j_amount;
json_t *j_tax_amount;
@@ -184,9 +185,8 @@ run (void *cls, char *const *args, const char *cfgfile,
j_teatax = json_pack ("{s:o}",
"teatax", j_tax_amount);
- if (NULL == (j_item = json_pack ("{s:s, s:o, s:I, s:o, s:I, s:[o]}",
+ if (NULL == (j_item = json_pack ("{s:s, s:I, s:o, s:I, s:[o]}",
"description", desc,
- "max fee", j_max_fee,
"quantity", json_integer_value (j_quantity),
"itemprice", j_item_price,
"product_id", json_integer_value (j_pid),
@@ -242,15 +242,31 @@ run (void *cls, char *const *args, const char *cfgfile,
"merchant", j_merchant,
"L-names", j_lnames);
- j_fake_contract = json_pack ("{s:o, s:I, s:o}",
+ /* Faking out the mints' list */
+ j_mints = json_pack ("[{s:s}]",
+ "demo.taler.net",
+ "Q1WVGRGC1F4W7RYC6M23AEGFEXQEHQ730K3GG0B67VPHQSRR75H0");
+
+ j_fake_contract = json_pack ("{s:o, s:o, s:I, s:o, s:o}",
"amount", j_amount,
+ "max fee", j_max_fee,
"trans_id", json_integer_value (j_id),
+ "mints", j_mints,
"details", j_details);
+ #if 0
+ str = json_dumps (j_fake_contract, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
+ printf ("%s\n", str);
+ return;
+ #endif
- j_root = MERCHANT_handle_contract (j_fake_contract,
+ if (NULL == (j_root = MERCHANT_handle_contract (j_fake_contract,
db_conn,
wire,
- &contract);
+ &contract)))
+ {
+ printf ("errors in contract handling\n");
+ return;
+ }
#if 1
str = json_dumps (j_root, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
@@ -258,6 +274,8 @@ run (void *cls, char *const *args, const char *cfgfile,
return;
#endif
+
+
}