gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: separate out QR logic


From: gnunet
Subject: [taler-merchant] branch master updated: separate out QR logic
Date: Mon, 03 Aug 2020 11:05:44 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 91f07f2  separate out QR logic
91f07f2 is described below

commit 91f07f2b0a5e6c2213f8a903b8751176ad9c72fe
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Aug 3 11:05:41 2020 +0200

    separate out QR logic
---
 src/backend/Makefile.am                          |  2 +
 src/backend/taler-merchant-httpd_get-orders-ID.c | 81 +-------------------
 src/backend/taler-merchant-httpd_qr.c            | 98 ++++++++++++++++++++++++
 src/backend/taler-merchant-httpd_qr.h            | 35 +++++++++
 4 files changed, 138 insertions(+), 78 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 925746b..8e99993 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 f34b7ec..f51b196 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"
 
 
@@ -257,81 +257,6 @@ static struct GetOrderData *god_head;
 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.
  */
@@ -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 0000000..367a61f
--- /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 0000000..ffcb004
--- /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

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]