gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: payto parser: extract 'subject'


From: gnunet
Subject: [taler-exchange] branch master updated: payto parser: extract 'subject' parameter.
Date: Mon, 27 Jul 2020 12:49:22 +0200

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

ms pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 7c2de4c5 payto parser: extract 'subject' parameter.
7c2de4c5 is described below

commit 7c2de4c5e6b7b1184d059057e1d412d6f0133816
Author: MS <ms@taler.net>
AuthorDate: Mon Jul 27 12:48:48 2020 +0200

    payto parser: extract 'subject' parameter.
---
 src/include/taler_util.h |  9 +++++++++
 src/util/payto.c         | 39 +++++++++++++++++++++++++++++++++++++++
 src/util/test_payto.c    | 11 +++++++++++
 3 files changed, 59 insertions(+)

diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 22d7f7f2..1d1c01ea 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -297,6 +297,15 @@ TALER_payto_get_method (const char *payto_uri);
 char *
 TALER_xtalerbank_account_from_payto (const char *payto);
 
+/**
+ * Extract the subject value from the URI parameters.
+ *
+ * @param payto_uri the URL to parse
+ * @return NULL if the subject parameter is not found.
+ *         The caller should free the returned value.
+ */
+char *
+TALER_payto_get_subject (const char *payto_uri);
 
 /**
  * Possible values for a binary filter.
diff --git a/src/util/payto.c b/src/util/payto.c
index 3540052c..4b2bbf4e 100644
--- a/src/util/payto.c
+++ b/src/util/payto.c
@@ -28,6 +28,45 @@
 #define PAYTO "payto://"
 
 
+/**
+ * Extract the subject value from the URI parameters.
+ *
+ * @param payto_uri the URL to parse
+ * @return NULL if the subject parameter is not found.
+ *         The caller should free the returned value.
+ */
+char *
+TALER_payto_get_subject (const char *payto_uri)
+{
+  const char *key;
+  const char *value_start;
+  const char *value_end;
+
+  key = strchr (payto_uri,
+                (unsigned char) '?');
+  if (NULL == key)
+    return NULL;
+
+  do {
+    if (0 == strncasecmp (++key,
+                         "subject",
+                         strlen ("subject")))
+    {
+      value_start = strchr (key,
+                           (unsigned char) '=');
+      if (NULL == value_start)
+        return NULL;
+      value_end = strchrnul (value_start,
+                            (unsigned char) '&');
+
+      return GNUNET_strndup (value_start + 1,
+                            value_end - value_start - 1);
+    }
+  } while ( (key = strchr (key,
+                        (unsigned char) '&')) );
+  return NULL;
+}
+
 /**
  * Obtain the payment method from a @a payto_uri. The
  * format of a payto URI is 'payto://$METHOD/$SOMETHING'.
diff --git a/src/util/test_payto.c b/src/util/test_payto.c
index 7dc2eb14..c809a039 100644
--- a/src/util/test_payto.c
+++ b/src/util/test_payto.c
@@ -22,6 +22,8 @@
 #include "taler_util.h"
 
 #define CHECK(a,b) do { \
+    GNUNET_assert (a != NULL); \
+    GNUNET_assert (b != NULL); \
     if (0 != strcmp (a,b)) {   \
       GNUNET_break (0); \
       fprintf (stderr, "Got %s, wanted %s\n", b, a); \
@@ -52,6 +54,15 @@ main (int argc,
     "payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
   CHECK ("alice",
          r);
+
+  r = TALER_payto_get_subject (
+    "payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
+  CHECK ("hello",
+        r);
+
+  r = TALER_payto_get_subject (
+    "payto://x-taler-bank/localhost:1080/alice");
+  GNUNET_assert (r == NULL);
   return 0;
 }
 

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