WARP IRI checking function 03/87103/3 accepted/tizen/common/20160909.115041 accepted/tizen/ivi/20160909.122423 accepted/tizen/mobile/20160909.122330 accepted/tizen/tv/20160909.122346 accepted/tizen/wearable/20160909.122405 submit/tizen/20160909.060412
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 6 Sep 2016 09:32:08 +0000 (11:32 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 7 Sep 2016 08:03:19 +0000 (01:03 -0700)
New function that check if IRI is valid according to:
 - https://www.w3.org/TR/widgets-access/#ta-parse-origin-attr

Change-Id: Ia20346458287cd472d92d3148ef315830b217d7e

src/manifest_parser/utils/iri_util.cc
src/manifest_parser/utils/iri_util.h

index a6bc1ade49c879eca6d3d6196f350070ead943fc..03f6aab533a16f593683ff493c256bb8b99ad65d 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <iri.h>
 
+#include <cstring>
 #include <memory>
 
 namespace parser {
@@ -15,18 +16,34 @@ bool IsValidIRI(const std::string& iri_string) {
   std::unique_ptr<iri_struct, decltype(&iri_destroy)> iri(
       iri_parse(iri_string.c_str()), iri_destroy);
   return
-    iri != NULL &&
-    iri->scheme != NULL && (
-      iri->display != NULL ||
-      iri->user != NULL ||
-      iri->auth != NULL ||
-      iri->password != NULL ||
-      iri->host != NULL ||
-      iri->path != NULL ||
-      iri->query != NULL ||
-      iri->anchor != NULL ||
-      iri->qparams != NULL ||
-      iri->schemelist != NULL);
+      iri != nullptr &&
+      iri->scheme != nullptr && (
+        iri->display != nullptr ||
+        iri->user != nullptr ||
+        iri->auth != nullptr ||
+        iri->password != nullptr ||
+        (iri->host != nullptr && strlen(iri->host) > 0) ||
+        iri->path != nullptr ||
+        iri->query != nullptr ||
+        iri->anchor != nullptr ||
+        iri->qparams != nullptr ||
+        iri->schemelist != nullptr);
+}
+
+bool IsValidWarpIRI(const std::string& iri_string) {
+  std::unique_ptr<iri_struct, decltype(&iri_destroy)> iri(
+      iri_parse(iri_string.c_str()), iri_destroy);
+  return
+      iri != nullptr &&
+      (iri->host != nullptr && strlen(iri->host) > 0) &&
+      iri->scheme != nullptr &&
+      iri->display == nullptr &&
+      iri->user == nullptr &&
+      iri->auth == nullptr &&
+      iri->password == nullptr &&
+      iri->path == nullptr &&
+      iri->query == nullptr &&
+      iri->anchor == nullptr;
 }
 
 }  // namespace utils
index 0ed6f19f11deb85046e6a02271e26b4d7c0dda4a..70a6158f0e1debae0803157dbed034e09ad7c989 100644 (file)
@@ -21,6 +21,22 @@ namespace utils {
  */
 bool IsValidIRI(const std::string& iri_string);
 
+/**
+ * @brief IsValidWarpIRI
+ *        Validate IRI with libiri and check according to WARP spec
+ *        requirements.
+ *
+ * Valid WARP IRI is the one that:
+ *  - is valid IRI,
+ *  - has no other component that scheme and iauthority,
+ *  - has host component,
+ *  - has no iuser component.
+ *
+ * @param iri_string iri string to check
+ * @return bool if iri is valid
+ */
+bool IsValidWarpIRI(const std::string& iri_string);
+
 }  // namespace utils
 }  // namespace parser