[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-mdb] branch master updated: switch to proper base64 encodin
From: |
gnunet |
Subject: |
[taler-taler-mdb] branch master updated: switch to proper base64 encoding of preview images, add mime type logic |
Date: |
Mon, 09 Mar 2020 23:50:29 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository taler-mdb.
The following commit(s) were added to refs/heads/master by this push:
new de54376 switch to proper base64 encoding of preview images, add mime
type logic
de54376 is described below
commit de5437643580173452eb0ab838e2033579604efc
Author: Christian Grothoff <address@hidden>
AuthorDate: Mon Mar 9 23:50:25 2020 +0100
switch to proper base64 encoding of preview images, add mime type logic
---
src/main.c | 47 +++++++++++++++++++++++++++++++++++++++--------
1 file 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);
}
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-mdb] branch master updated: switch to proper base64 encoding of preview images, add mime type logic,
gnunet <=