gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -add i18n object syntax check


From: gnunet
Subject: [taler-exchange] branch master updated: -add i18n object syntax check
Date: Mon, 02 Aug 2021 22:16:03 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 61450fad -add i18n object syntax check
61450fad is described below

commit 61450fad8d371a4f75731faa51632229c881ada2
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Aug 2 22:16:01 2021 +0200

    -add i18n object syntax check
---
 src/include/taler_json_lib.h | 10 ++++++
 src/json/i18n.c              | 75 +++++++++++++++++++++++++++++---------------
 2 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index bc21957e..3581252c 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -566,6 +566,16 @@ TALER_JSON_extract_i18n (const json_t *object,
                          const char *field);
 
 
+/**
+ * Check whether a given @a i18n object is wellformed.
+ *
+ * @param i18n object with internationalized content
+ * @return true if @a i18n is well-formed
+ */
+bool
+TALER_JSON_check_i18n (const json_t *i18n);
+
+
 /**
  * Obtain the wire method associated with the given
  * wire account details.  @a wire_s must contain a payto://-URL
diff --git a/src/json/i18n.c b/src/json/i18n.c
index b92d63ed..1d3076e2 100644
--- a/src/json/i18n.c
+++ b/src/json/i18n.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2020 Taler Systems SA
+  Copyright (C) 2020, 2021 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
@@ -24,31 +24,6 @@
 #include "taler_json_lib.h"
 
 
-/**
- * Extract a string from @a object under the field @a field, but respecting
- * the Taler i18n rules and the language preferences expressed in @a
- * language_pattern.
- *
- * Basically, the @a object may optionally contain a sub-object
- * "${field}_i18n" with a map from IETF BCP 47 language tags to a localized
- * version of the string. If this map exists and contains an entry that
- * matches the @a language pattern, that object (usually a string) is
- * returned. If the @a language_pattern does not match any entry, or if the
- * i18n sub-object does not exist, we simply return @a field of @a object
- * (also usually a string).
- *
- * If @a object does not have a member @a field we return NULL (error).
- *
- * @param object the object to extract internationalized
- *        content from
- * @param language_pattern a language preferences string
- *        like "fr-CH, fr;q=0.9, en;q=0.8, *;q=0.1", following
- *        https://tools.ietf.org/html/rfc7231#section-5.3.1
- * @param field name of the field to extract
- * @return NULL on error, otherwise the member from
- *        @a object. Note that the reference counter is
- *        NOT incremented.
- */
 const json_t *
 TALER_JSON_extract_i18n (const json_t *object,
                          const char *language_pattern,
@@ -92,4 +67,52 @@ TALER_JSON_extract_i18n (const json_t *object,
 }
 
 
+bool
+TALER_JSON_check_i18n (const json_t *i18n)
+{
+  const char *field;
+  json_t *member;
+
+  if (! json_is_object (i18n))
+    return false;
+  json_object_foreach ((json_t *) i18n, field, member)
+  {
+    if (! json_is_string (member))
+      return false;
+    /* Field name must be either of format "en_UK"
+       or just "en"; we do not care about capitalization */
+    switch (strlen (field))
+    {
+    case 0:
+    case 1:
+      return false;
+    case 2:
+      if (! isalpha (field[0]))
+        return false;
+      if (! isalpha (field[1]))
+        return false;
+      break;
+    case 3:
+    case 4:
+      return false;
+    case 5:
+      if (! isalpha (field[0]))
+        return false;
+      if (! isalpha (field[1]))
+        return false;
+      if ('_' != field[2])
+        return false;
+      if (! isalpha (field[3]))
+        return false;
+      if (! isalpha (field[4]))
+        return false;
+      break;
+    default:
+      return false;
+    }
+  }
+  return true;
+}
+
+
 /* end of i18n.c */

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