summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-09 23:50:25 +0100
committerChristian Grothoff <christian@grothoff.org>2020-03-09 23:50:25 +0100
commitde5437643580173452eb0ab838e2033579604efc (patch)
tree8ed074727462e9af53c0a00736b123facce57605
parent4a03b065cfd269d8f94b5924bf89131492475c9d (diff)
downloadtaler-mdb-de5437643580173452eb0ab838e2033579604efc.tar.gz
taler-mdb-de5437643580173452eb0ab838e2033579604efc.tar.bz2
taler-mdb-de5437643580173452eb0ab838e2033579604efc.zip
switch to proper base64 encoding of preview images, add mime type logic
-rw-r--r--src/main.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index ff46a7e..ba1b6dc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1557,9 +1557,8 @@ launch_payment (struct Product *product)
/* create the json object for the order request */
if (NULL != product->preview)
{
- orderReq = json_pack ("{ s:{s:s}, s:s, s:o, s:s, s:o }",
+ orderReq = json_pack ("{ s:s, s:s, s:o, s:s, s:o }",
"summary",
- "_",
product->description,
"preview", product->preview,
"amount", TALER_JSON_from_amount (&product->price),
@@ -1570,9 +1569,8 @@ launch_payment (struct Product *product)
}
else
{
- orderReq = json_pack ("{ s:{s:s}, s:o, s:s, s:o }",
+ orderReq = json_pack ("{ s:s}, s:o, s:s, s:o }",
"summary",
- "_",
product->description,
"amount", TALER_JSON_from_amount (&product->price),
"fulfillment_url", fulflmntUrl
@@ -2036,7 +2034,7 @@ write_mdb_command (void *cls)
chkSum += mdb.txBuffer[idx] = mdb.cmd->cmd.bin[idx];
for (size_t idx = 0; idx < mdb.cmd->data.bin_size; idx++)
chkSum += mdb.txBuffer[idx + mdb.cmd->cmd.bin_size] =
- mdb.cmd->data.bin[idx];
+ mdb.cmd->data.bin[idx];
mdb.txBuffer[mdb.cmd->cmd.bin_size + mdb.cmd->data.bin_size] =
(uint8_t) (chkSum & 0xFF);
}
@@ -2715,9 +2713,42 @@ read_products (void *cls,
}
else
{
- tmpProduct.preview
- = GNUNET_STRINGS_data_to_string_alloc (thumb,
- len);
+ const char *mime_type = "";
+ const char *ext;
+ size_t preview_len;
+ char *base64;
+
+ ext = strrchr (thumbnail_fn, '.');
+ if (NULL != ext)
+ {
+ static const struct
+ {
+ const char *ext;
+ const char *mime;
+ } mimes[] = {
+ { ".png", "image/png" },
+ { ".jpg", "image/jpeg" },
+ { ".jpeg", "image/jpeg" },
+ { ".svg", "image/svg" },
+ { NULL, NULL }
+ };
+
+ for (unsigned int i = 0; NULL != mimes[i].ext; i++)
+ if (0 == strcasecmp (mimes[i].ext,
+ ext))
+ {
+ mime_type = mimes[i].mime;
+ break;
+ }
+ }
+ (void) GNUNET_STRINGS_base64_encode (thumb,
+ len,
+ &base64);
+ GNUNET_asprintf (&tmpProduct.preview,
+ "data:%s;base64,%s",
+ mime_type,
+ base64);
+ GNUNET_free (base64);
}
GNUNET_free (thumb);
}