gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] branch master updated: pass static_url to templates


From: gnunet
Subject: [taler-merchant] branch master updated: pass static_url to templates
Date: Mon, 17 May 2021 14:39:55 +0200

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

dold pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new e0e86588 pass static_url to templates
e0e86588 is described below

commit e0e86588565baf0111db24b431e8a4c908017da5
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon May 17 14:39:43 2021 +0200

    pass static_url to templates
---
 contrib/depleted_tip.en.must                     |  2 +-
 contrib/offer_refund.en.must                     |  2 +-
 contrib/offer_tip.en.must                        |  2 +-
 contrib/request_payment.en.must                  |  2 +-
 contrib/show_order_details.en.must               |  2 +-
 src/backend/taler-merchant-httpd_get-orders-ID.c |  3 +
 src/backend/taler-merchant-httpd_get-tips-ID.c   |  1 +
 src/backend/taler-merchant-httpd_templating.c    | 75 ++++++++++++++++++++++++
 src/backend/taler-merchant-httpd_templating.h    |  2 +
 9 files changed, 86 insertions(+), 5 deletions(-)

diff --git a/contrib/depleted_tip.en.must b/contrib/depleted_tip.en.must
index 795f4f17..3ef0b12d 100644
--- a/contrib/depleted_tip.en.must
+++ b/contrib/depleted_tip.en.must
@@ -24,7 +24,7 @@
   </noscript>
   <title>Status of your tip</title>
   <link rel="stylesheet"
-        href="/static/pure-min.css"
+        href="{{static_url}}pure-min.css"
         
integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ"
         crossorigin="anonymous">
   <style>
diff --git a/contrib/offer_refund.en.must b/contrib/offer_refund.en.must
index 4f8f6631..57b4d55c 100644
--- a/contrib/offer_refund.en.must
+++ b/contrib/offer_refund.en.must
@@ -24,7 +24,7 @@
   </noscript>
   <title>Refund available for {{order_summary}}</title>
   <link rel="stylesheet"
-        href="/static/pure-min.css"
+        href="{{static_url}}pure-min.css"
         
integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ"
         crossorigin="anonymous">
   <style>
diff --git a/contrib/offer_tip.en.must b/contrib/offer_tip.en.must
index ca165b3b..4ae140cf 100644
--- a/contrib/offer_tip.en.must
+++ b/contrib/offer_tip.en.must
@@ -24,7 +24,7 @@
   </noscript>
   <title>Tip available</title>
   <link rel="stylesheet"
-        href="/static/pure-min.css"
+        href="{{static_url}}pure-min.css"
         
integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ"
         crossorigin="anonymous">
   <style>
diff --git a/contrib/request_payment.en.must b/contrib/request_payment.en.must
index 2665923d..e13fb859 100644
--- a/contrib/request_payment.en.must
+++ b/contrib/request_payment.en.must
@@ -24,7 +24,7 @@
   </noscript>
   <title>Payment required for {{order_summary}}</title>
   <link rel="stylesheet"
-        href="/static/pure-min.css"
+        href="{{static_url}}pure-min.css"
         
integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ"
         crossorigin="anonymous">
   <style>
diff --git a/contrib/show_order_details.en.must 
b/contrib/show_order_details.en.must
index a4b23fb9..6a9cbd2e 100644
--- a/contrib/show_order_details.en.must
+++ b/contrib/show_order_details.en.must
@@ -24,7 +24,7 @@
   </noscript>
   <title>Status of your order for {{order_summary}}</title>
   <link rel="stylesheet"
-        href="/static/pure-min.css"
+        href="{{static_url}}pure-min.css"
         
integrity="sha384-cg6SkqEOCV1NbJoCu11+bm0NvBRc8IYLRGXkmNrqUBfTjmMYwNKPWBTIKyw9mHNJ"
         crossorigin="anonymous">
   <style>
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c 
b/src/backend/taler-merchant-httpd_get-orders-ID.c
index 420a19c4..ff2b3fa3 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -562,6 +562,7 @@ send_pay_request (struct GetOrderData *god,
       res = TMH_return_from_template (god->sc.con,
                                       MHD_HTTP_PAYMENT_REQUIRED,
                                       "request_payment",
+                                      god->hc->instance->settings.id,
                                       taler_pay_uri,
                                       context);
       if (GNUNET_SYSERR == res)
@@ -1162,6 +1163,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
           res = TMH_return_from_template (god->sc.con,
                                           MHD_HTTP_OK,
                                           "offer_refund",
+                                          hc->instance->settings.id,
                                           uri,
                                           context);
           json_decref (context);
@@ -1184,6 +1186,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
         res = TMH_return_from_template (god->sc.con,
                                         MHD_HTTP_OK,
                                         "show_order_details",
+                                        hc->instance->settings.id,
                                         NULL,
                                         context);
         json_decref (context);
diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.c 
b/src/backend/taler-merchant-httpd_get-tips-ID.c
index fd60c6e9..09640bde 100644
--- a/src/backend/taler-merchant-httpd_get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_get-tips-ID.c
@@ -262,6 +262,7 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
                                           (0 == remaining.fraction) )
                                         ? "depleted_tip"
                                         : "offer_tip",
+                                        hc->instance->settings.id,
                                         uri,
                                         context);
         json_decref (context);
diff --git a/src/backend/taler-merchant-httpd_templating.c 
b/src/backend/taler-merchant-httpd_templating.c
index 393104dc..9d7766b9 100644
--- a/src/backend/taler-merchant-httpd_templating.c
+++ b/src/backend/taler-merchant-httpd_templating.c
@@ -107,6 +107,70 @@ lookup_template (struct MHD_Connection *connection,
   return best->value;
 }
 
+/**
+ * Get the base URL for static resources.
+ *
+ * @param con the MHD connection
+ * @param instance_id the instance ID
+ * @returns the static files base URL, guaranteed
+ *          to have a trailing slash.
+ */
+static char *
+make_static_url (struct MHD_Connection *con,
+                     const char *instance_id)
+{
+  const char *host;
+  const char *forwarded_host;
+  const char *uri_path;
+  struct GNUNET_Buffer buf = { 0 };
+
+  host = MHD_lookup_connection_value (con,
+                                      MHD_HEADER_KIND,
+                                      "Host");
+  forwarded_host = MHD_lookup_connection_value (con,
+                                                MHD_HEADER_KIND,
+                                                "X-Forwarded-Host");
+
+  uri_path = MHD_lookup_connection_value (con,
+                                          MHD_HEADER_KIND,
+                                          "X-Forwarded-Prefix");
+  if (NULL != forwarded_host)
+    host = forwarded_host;
+
+  if (NULL == host)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+
+  GNUNET_assert (NULL != instance_id);
+
+  if (GNUNET_NO == TALER_mhd_is_https (con))
+    GNUNET_buffer_write_str (&buf,
+                             "http://";);
+  else
+    GNUNET_buffer_write_str (&buf,
+                             "https://";);
+  GNUNET_buffer_write_str (&buf,
+                           host);
+  if (NULL != uri_path)
+    GNUNET_buffer_write_path (&buf,
+                              uri_path);
+  if (0 != strcmp ("default",
+                   instance_id))
+  {
+    GNUNET_buffer_write_path (&buf,
+                              "instances");
+    GNUNET_buffer_write_path (&buf,
+                              instance_id);
+  }
+  GNUNET_buffer_write_path (&buf,
+                            "static/");
+  return GNUNET_buffer_reap_str (&buf);
+}
+
+
+
 
 /**
  * Load a @a template and substitute using @a root, returning
@@ -116,6 +180,7 @@ lookup_template (struct MHD_Connection *connection,
  * @param connection the connection we act upon
  * @param http_status code to use on success
  * @param template basename of the template to load
+ * @param instance_id instance ID, used to compute static files URL
  * @param taler_uri value for "Taler:" header to set, or NULL
  * @param root JSON object to pass as the root context
  * @return #GNUNET_OK on success (reply queued), #GNUNET_NO if an error was 
queued,
@@ -125,6 +190,7 @@ enum GNUNET_GenericReturnValue
 TMH_return_from_template (struct MHD_Connection *connection,
                           unsigned int http_status,
                           const char *template,
+                          const char *instance_id,
                           const char *taler_uri,
                           json_t *root)
 {
@@ -151,6 +217,15 @@ TMH_return_from_template (struct MHD_Connection 
*connection,
         return GNUNET_SYSERR;
       return GNUNET_NO;
     }
+    /* Add default values to the context */
+    {
+      char *static_url = make_static_url (connection,
+                                          instance_id);
+      json_object_set (root,
+                       "static_url",
+                       json_string (static_url));
+      GNUNET_free (static_url);
+    }
     if (0 !=
         (eno = mustach_jansson (tmpl,
                                 root,
diff --git a/src/backend/taler-merchant-httpd_templating.h 
b/src/backend/taler-merchant-httpd_templating.h
index 1fb4781a..a1c2e05a 100644
--- a/src/backend/taler-merchant-httpd_templating.h
+++ b/src/backend/taler-merchant-httpd_templating.h
@@ -32,6 +32,7 @@
  * @param connection the connection we act upon
  * @param http_status code to use on success
  * @param template basename of the template to load
+ * @param instance_id instance ID, used to compute static files URL
  * @param taler_uri value for "Taler:" header to set, or NULL
  * @param root JSON object to pass as the root context
  * @return #GNUNET_OK on success (reply queued), #GNUNET_NO if an error was 
queued,
@@ -41,6 +42,7 @@ enum GNUNET_GenericReturnValue
 TMH_return_from_template (struct MHD_Connection *connection,
                           unsigned int http_status,
                           const char *template,
+                          const char *instance_id,
                           const char *taler_uri,
                           json_t *root);
 

-- 
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]