summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-03 11:05:41 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-03 11:05:41 +0200
commit91f07f2b0a5e6c2213f8a903b8751176ad9c72fe (patch)
treefb2c1e3b6903ee1705ab56c50c4da8cc0e043920 /src/backend
parentadf0f4fd36290becd33292d56d819aeaf260d5f6 (diff)
downloadmerchant-91f07f2b0a5e6c2213f8a903b8751176ad9c72fe.tar.gz
merchant-91f07f2b0a5e6c2213f8a903b8751176ad9c72fe.tar.bz2
merchant-91f07f2b0a5e6c2213f8a903b8751176ad9c72fe.zip
separate out QR logic
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile.am2
-rw-r--r--src/backend/taler-merchant-httpd_get-orders-ID.c81
-rw-r--r--src/backend/taler-merchant-httpd_qr.c98
-rw-r--r--src/backend/taler-merchant-httpd_qr.h35
4 files changed, 138 insertions, 78 deletions
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 925746b3..8e99993f 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -89,6 +89,8 @@ taler_merchant_httpd_SOURCES = \
taler-merchant-httpd_post-orders-ID-paid.h \
taler-merchant-httpd_post-tips-ID-pickup.c \
taler-merchant-httpd_post-tips-ID-pickup.h \
+ taler-merchant-httpd_qr.c \
+ taler-merchant-httpd_qr.h \
taler-merchant-httpd_reserves.c \
taler-merchant-httpd_reserves.h \
taler-merchant-httpd_templating.c \
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c
index f34b7ec7..f51b1962 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -21,12 +21,12 @@
*/
#include "platform.h"
#include <jansson.h>
-#include <qrencode.h>
#include <taler/taler_signatures.h>
#include <taler/taler_json_lib.h>
#include <taler/taler_exchange_service.h>
#include "taler-merchant-httpd_exchanges.h"
#include "taler-merchant-httpd_get-orders-ID.h"
+#include "taler-merchant-httpd_qr.h"
#include "taler-merchant-httpd_templating.h"
@@ -258,81 +258,6 @@ static struct GetOrderData *god_tail;
/**
- * Create the QR code image for a URI.
- *
- * @param uri input string to encode
- * @return NULL on error, encoded URI otherwise
- */
-static char *
-create_qrcode (const char *uri)
-{
- QRinput *qri;
- QRcode *qrc;
- struct GNUNET_Buffer buf = { 0 };
-
- qri = QRinput_new2 (0,
- QR_ECLEVEL_M);
- if (NULL == qri)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "QRinput_new2");
- return NULL;
- }
- /* first try encoding as uppercase-only alpha-numerical
- QR code (much smaller encoding); if that fails, also
- try using binary encoding */
- if ( (0 !=
- QRinput_append (qri,
- QR_MODE_AN,
- strlen (uri),
- (unsigned char *) uri)) &&
- (0 !=
- QRinput_append (qri,
- QR_MODE_8,
- strlen (uri),
- (unsigned char *) uri)) )
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "QRinput_append");
- QRinput_free (qri);
- return NULL;
- }
- qrc = QRcode_encodeInput (qri);
- if (NULL == qrc)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "QRcode_encodeInput");
- QRinput_free (qri);
- return NULL;
- }
- QRinput_free (qri);
- /* FIXME-Dold: generate <img> with inline SVG instead of <pre> here! */
- GNUNET_buffer_write_str (&buf,
- "<p class=\"qrtext\"><br>\n<br>\n<br>\n<br>\n");
- for (unsigned int y = 0; y<qrc->width; y++)
- {
- GNUNET_buffer_write_str (&buf,
- "&nbsp;&nbsp;&nbsp;&nbsp;");
- for (unsigned int x = 0; x<qrc->width; x++)
- {
- unsigned int off = x + y * qrc->width;
- GNUNET_buffer_write_fstr (&buf,
- "%s",
- (0 != (qrc->data[off] & 1))
- ? "██"
- : "&nbsp;&nbsp;");
- }
- GNUNET_buffer_write_str (&buf,
- "&nbsp;&nbsp;&nbsp;&nbsp;<br>");
- }
- GNUNET_buffer_write_str (&buf,
- "<br>\n<br>\n<br>\n<br>\n</p>");
- QRcode_free (qrc);
- return GNUNET_buffer_reap_str (&buf);
-}
-
-
-/**
* Force resuming all suspended order lookups, needed during shutdown.
*/
void
@@ -495,7 +420,7 @@ send_pay_request (struct GetOrderData *god,
{
char *qr;
- qr = create_qrcode (taler_pay_uri);
+ qr = TMH_create_qrcode (taler_pay_uri);
if (NULL == qr)
{
GNUNET_break (0);
@@ -1317,7 +1242,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
{
char *qr;
- qr = create_qrcode ("taler://refund/FIXME");
+ qr = TMH_create_qrcode ("taler://refund/FIXME");
if (NULL == qr)
{
GNUNET_break (0);
diff --git a/src/backend/taler-merchant-httpd_qr.c b/src/backend/taler-merchant-httpd_qr.c
new file mode 100644
index 00000000..367a61f5
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_qr.c
@@ -0,0 +1,98 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file merchant/backend/taler-merchant-httpd_qr.c
+ * @brief logic to create QR codes in HTML
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <qrencode.h>
+
+
+/**
+ * Create the HTML for a QR code for a URI.
+ *
+ * @param uri input string to encode
+ * @return NULL on error, encoded URI otherwise
+ */
+char *
+TMH_create_qrcode (const char *uri)
+{
+ QRinput *qri;
+ QRcode *qrc;
+ struct GNUNET_Buffer buf = { 0 };
+
+ qri = QRinput_new2 (0,
+ QR_ECLEVEL_M);
+ if (NULL == qri)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "QRinput_new2");
+ return NULL;
+ }
+ /* first try encoding as uppercase-only alpha-numerical
+ QR code (much smaller encoding); if that fails, also
+ try using binary encoding */
+ if ( (0 !=
+ QRinput_append (qri,
+ QR_MODE_AN,
+ strlen (uri),
+ (unsigned char *) uri)) &&
+ (0 !=
+ QRinput_append (qri,
+ QR_MODE_8,
+ strlen (uri),
+ (unsigned char *) uri)) )
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "QRinput_append");
+ QRinput_free (qri);
+ return NULL;
+ }
+ qrc = QRcode_encodeInput (qri);
+ if (NULL == qrc)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "QRcode_encodeInput");
+ QRinput_free (qri);
+ return NULL;
+ }
+ QRinput_free (qri);
+ /* FIXME-Dold: generate <img> with inline SVG instead of <pre> here! */
+ GNUNET_buffer_write_str (&buf,
+ "<p class=\"qrtext\"><br>\n<br>\n<br>\n<br>\n");
+ for (unsigned int y = 0; y<qrc->width; y++)
+ {
+ GNUNET_buffer_write_str (&buf,
+ "&nbsp;&nbsp;&nbsp;&nbsp;");
+ for (unsigned int x = 0; x<qrc->width; x++)
+ {
+ unsigned int off = x + y * qrc->width;
+ GNUNET_buffer_write_fstr (&buf,
+ "%s",
+ (0 != (qrc->data[off] & 1))
+ ? "██"
+ : "&nbsp;&nbsp;");
+ }
+ GNUNET_buffer_write_str (&buf,
+ "&nbsp;&nbsp;&nbsp;&nbsp;<br>");
+ }
+ GNUNET_buffer_write_str (&buf,
+ "<br>\n<br>\n<br>\n<br>\n</p>");
+ QRcode_free (qrc);
+ return GNUNET_buffer_reap_str (&buf);
+}
diff --git a/src/backend/taler-merchant-httpd_qr.h b/src/backend/taler-merchant-httpd_qr.h
new file mode 100644
index 00000000..ffcb0049
--- /dev/null
+++ b/src/backend/taler-merchant-httpd_qr.h
@@ -0,0 +1,35 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file merchant/backend/taler-merchant-httpd_qr.h
+ * @brief logic to create QR codes in HTML
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT_HTTPD_QR_H
+#define TALER_MERCHANT_HTTPD_QR_H
+
+
+/**
+ * Create the HTML for a QR code for a URI.
+ *
+ * @param uri input string to encode
+ * @return NULL on error, encoded URI otherwise
+ */
+char *
+TMH_create_qrcode (const char *uri);
+
+
+#endif