Chris Hillery has proposed merging 
lp:~zorba-coders/zorba/bug-867363-disable-http into lp:zorba.

Commit message:
Added http-uri-resolution feature, default enabled. If disabled via normal 
option mechanism (or the convenience --disable-http-resolution command-line 
parameter), Zorba will not attempt to download HTTP/HTTPS/FTP URLs.

Requested reviews:
  Chris Hillery (ceejatec)
  Markos Zaharioudakis (markos-za)
Related bugs:
  Bug #867363 in Zorba: "disabling schema download"
  https://bugs.launchpad.net/zorba/+bug/867363

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-867363-disable-http/+merge/133032
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-867363-disable-http/+merge/133032
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp	2012-10-10 21:15:05 +0000
+++ bin/zorbacmd.cpp	2012-11-06 10:16:23 +0000
@@ -178,10 +178,10 @@
       Item lQName = zorba->getItemFactory()->createQName(lIter->clark_qname);
       sctx->declareOption(lQName, lIter->value);
     }
-    catch (zorba::ZorbaException const& /* e */) 
+    catch (zorba::ZorbaException const& e)
     {
       std::cerr << "unable to set static context option with qname "
-                << lIter->clark_qname << std::endl;
+                << lIter->clark_qname << ": " << e.what() << std::endl;
       return false;
     }
   }
@@ -251,7 +251,8 @@
       sctx->registerURIMapper(&theThesaurusMapper);
     }
   }
-#endif
+#endif /* ZORBA_NO_FULL_TEXT */
+
   return true;
 }
 

=== modified file 'bin/zorbacmdproperties_base.h'
--- bin/zorbacmdproperties_base.h	2012-09-19 21:16:15 +0000
+++ bin/zorbacmdproperties_base.h	2012-11-06 10:16:23 +0000
@@ -42,7 +42,8 @@
       "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo",
       "--timeout", "--uri-path", "--lib-path", "--module-path", "--classpath",
       "--option", "--trailing-nl", "--stop-words", "--thesaurus",
-      "--compile-plan", "--execute-plan --serialize-plan", NULL };
+      "--compile-plan", "--execute-plan", "--serialize-plan",
+      "--disable-http-resolution", NULL };
     return result;
   }
 
@@ -426,6 +427,11 @@
       {
         theLoadPlan = true;
       }
+      else if (strcmp (*argv, "--disable-http-resolution") == 0)
+      {
+        init_val ("{http://www.zorba-xquery.com/options/features}disable=http-uri-resolution";,
+                  theOption, 0);
+      }
       else if (strcmp (*argv, "--") == 0)
       {
         copy_args (++argv);
@@ -489,6 +495,7 @@
         "--serialize-plan, -s\nSerialize and then load the query execution plan.\n\n"
         "--compile-plan,\nDo not execute the query; just compile it and save the execution plan in the file specified with the -o option.\n\n"
         "--execute-plan\nDo not compile the query; instead load the execution plan from the file specified by the -f -q options, and execute the loaded plan.\n\n"
+        "--disable-http-resolution\nDo not use HTTP to resolve URIs\n\n"
         ;
   }
 

=== modified file 'src/context/default_uri_mappers.cpp'
--- src/context/default_uri_mappers.cpp	2012-09-19 21:16:15 +0000
+++ src/context/default_uri_mappers.cpp	2012-11-06 10:16:23 +0000
@@ -17,6 +17,7 @@
 #include "stdafx.h"
 
 #include <context/default_uri_mappers.h>
+#include <context/default_url_resolvers.h>
 #include <util/uri_util.h>
 #include <util/fs_util.h>
 #include <zorbatypes/URI.h>
@@ -192,7 +193,14 @@
 
   // Finally, append the original URI, so that it will be resolved
   // as-is if there's nothing appropriate on the local filesystem.
-  oUris.push_back(aUri);
+  // Note: For module or schema imports, don't do this if it's a
+  // network (HTTP) URI and the "http_resolution" feature is disabled
+  // on this context.
+  if ( (lKind != EntityData::MODULE && lKind != EntityData::SCHEMA) ||
+       aSctx.is_feature_set(feature::http_resolution) ||
+       (HTTPURLResolver::isHTTPScheme(aUri) == false) ) {
+    oUris.push_back(aUri);
+  }
 }
 
 ZorbaCollectionURIMapper::~ZorbaCollectionURIMapper()

=== modified file 'src/context/default_uri_mappers.h'
--- src/context/default_uri_mappers.h	2012-09-19 21:16:15 +0000
+++ src/context/default_uri_mappers.h	2012-11-06 10:16:23 +0000
@@ -91,10 +91,10 @@
   virtual void mapURI(zstring const& aUri,
     EntityData const* aEntityData,
     static_context const& aSctx,
-    std::vector<zstring>& oUrls);
+    std::vector<zstring>& oUris);
 };
 
-} /* namespace zorba::impl */
+} /* namespace zorba::internal */
 
 } /* namespace zorba */
 

=== modified file 'src/context/default_url_resolvers.cpp'
--- src/context/default_url_resolvers.cpp	2012-09-19 21:16:15 +0000
+++ src/context/default_url_resolvers.cpp	2012-11-06 10:16:23 +0000
@@ -34,34 +34,44 @@
 
 namespace internal {
 
-/******
- * http: (and https: and ftp:) URL resolver.
- ******/
-
-Resource*
-HTTPURLResolver::resolveURL
-(zstring const& aUrl, EntityData const* aEntityData)
+/**
+ * Utility function that identifies URL schemes that will be handled
+ * by the HttpStream class.
+ */
+bool
+HTTPURLResolver::isHTTPScheme(zstring const& aUrl)
 {
-  switch ( aEntityData->getKind() ) {
-    case EntityData::COLLECTION:
-#ifndef ZORBA_NO_FULL_TEXT
-    case EntityData::THESAURUS:
-#endif /* ZORBA_NO_FULL_TEXT */
-      return nullptr;
-    default:
-      break;
-  }
-
   uri::scheme lScheme = uri::get_scheme(aUrl);
   switch (lScheme) {
     case uri::http:
     case uri::https:
     case uri::ftp:
-      // Fall through to actual implementation
+      return true;
+    default:
+      return false;
+  }
+}
+
+/******
+ * http: (and https: and ftp:) URL resolver.
+ ******/
+
+Resource*
+HTTPURLResolver::resolveURL
+(zstring const& aUrl, EntityData const* aEntityData)
+{
+  switch ( aEntityData->getKind() ) {
+    case EntityData::COLLECTION:
+#ifndef ZORBA_NO_FULL_TEXT
+    case EntityData::THESAURUS:
+#endif /* ZORBA_NO_FULL_TEXT */
+      return nullptr;
+    default:
       break;
-    default:
-      // We don't implement other schemes
-      return NULL;
+  }
+
+  if (!isHTTPScheme(aUrl)) {
+    return nullptr;
   }
   try {
     std::auto_ptr<HttpStream> lStream(new HttpStream(aUrl));
@@ -76,7 +86,6 @@
   }
 }
 
-
 /******
  * file: URL resolver.
  ******/

=== modified file 'src/context/default_url_resolvers.h'
--- src/context/default_url_resolvers.h	2012-09-19 21:16:15 +0000
+++ src/context/default_url_resolvers.h	2012-11-06 10:16:23 +0000
@@ -42,6 +42,8 @@
 {
 public:
 
+  static bool isHTTPScheme(zstring const& aUrl);
+
   virtual Resource* resolveURL(zstring const& aUrl,
     EntityData const* aEntityData);
 };

=== modified file 'src/context/features.cpp'
--- src/context/features.cpp	2012-09-19 21:16:15 +0000
+++ src/context/features.cpp	2012-11-06 10:16:23 +0000
@@ -49,6 +49,11 @@
         res = dtd;
         return true;
       }
+      else if ( ztd::equals(s, "http-uri-resolution") )
+      {
+        res = http_resolution;
+        return true;
+      }
       return false;
     }
   }

=== modified file 'src/context/features.h'
--- src/context/features.h	2012-09-19 21:16:15 +0000
+++ src/context/features.h	2012-11-06 10:16:23 +0000
@@ -30,7 +30,8 @@
       scripting   = 4,
       hof         = 8,
       trace       = 16,
-      dtd         = 32
+      dtd         = 32,
+      http_resolution = 64,
     };
 
     bool kind_for( char const*, kind& );

=== modified file 'src/context/root_static_context.cpp'
--- src/context/root_static_context.cpp	2012-10-08 12:09:36 +0000
+++ src/context/root_static_context.cpp	2012-11-06 10:16:23 +0000
@@ -185,6 +185,7 @@
   set_feature( feature::ddl );
   set_feature( feature::scripting );
   set_feature( feature::trace );
+  set_feature( feature::http_resolution );
 } 
 
 

=== added file 'test/rbkt/ExpQueryResults/zorba/uris/disable-http-3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/uris/disable-http-3.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/uris/disable-http-3.xml.res	2012-11-06 10:16:23 +0000
@@ -0,0 +1,1 @@
+<query>querystring</query>

=== modified file 'test/rbkt/Queries/CMakeLists.txt'
--- test/rbkt/Queries/CMakeLists.txt	2012-10-20 21:29:37 +0000
+++ test/rbkt/Queries/CMakeLists.txt	2012-11-06 10:16:23 +0000
@@ -491,6 +491,13 @@
 # hitting w3.org for the DTD, which is bad.
 SET_TESTS_PROPERTIES(test/rbkt/zorba/schemas/local-xhtml
   PROPERTIES TIMEOUT 5)
+# Bug 867363. These should fail or pass quickly because HTTP download
+# is disabled.
+SET_TESTS_PROPERTIES(test/rbkt/zorba/uris/disable-http
+  PROPERTIES TIMEOUT 5)
+SET_TESTS_PROPERTIES(test/rbkt/zorba/uris/disable-http-2
+  PROPERTIES TIMEOUT 5)
+
 
 # --------------------------------------------------------------------------
 # the list of tests that are failing but can be accepted by the commit queue

=== added file 'test/rbkt/Queries/zorba/uris/disable-http-2.spec'
--- test/rbkt/Queries/zorba/uris/disable-http-2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/disable-http-2.spec	2012-11-06 10:16:23 +0000
@@ -0,0 +1,2 @@
+Options: {http://www.zorba-xquery.com/options/features}disable=http-uri-resolution
+Error: http://www.w3.org/2005/xqt-errors:XQST0059

=== added file 'test/rbkt/Queries/zorba/uris/disable-http-2.xq'
--- test/rbkt/Queries/zorba/uris/disable-http-2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/disable-http-2.xq	2012-11-06 10:16:23 +0000
@@ -0,0 +1,4 @@
+import module namespace slow = "http://www.zorba-xquery.com/test/uris/slow";
+  at "slow.xqlib";
+
+slow:ok()

=== added file 'test/rbkt/Queries/zorba/uris/disable-http-3.spec'
--- test/rbkt/Queries/zorba/uris/disable-http-3.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/disable-http-3.spec	2012-11-06 10:16:23 +0000
@@ -0,0 +1,1 @@
+Options: {http://www.zorba-xquery.com/options/features}disable=http-uri-resolution

=== added file 'test/rbkt/Queries/zorba/uris/disable-http-3.xq'
--- test/rbkt/Queries/zorba/uris/disable-http-3.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/disable-http-3.xq	2012-11-06 10:16:23 +0000
@@ -0,0 +1,2 @@
+(: Ensure that disabling HTTP URI resolution doesn't defeat fn:doc(). :)
+fn:doc("http://zorbatest.lambda.nu:8080/cgi-bin/test-xml?querystring";)/body/query

=== added file 'test/rbkt/Queries/zorba/uris/disable-http.spec'
--- test/rbkt/Queries/zorba/uris/disable-http.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/disable-http.spec	2012-11-06 10:16:23 +0000
@@ -0,0 +1,2 @@
+Options: {http://www.zorba-xquery.com/options/features}disable=http-uri-resolution
+Error: http://www.w3.org/2005/xqt-errors:XQST0059

=== added file 'test/rbkt/Queries/zorba/uris/disable-http.xq'
--- test/rbkt/Queries/zorba/uris/disable-http.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/disable-http.xq	2012-11-06 10:16:23 +0000
@@ -0,0 +1,5 @@
+(: For various reasons, importing a bad schema via HTTP can take :)
+(: minutes to complete. This test should time out unless the :)
+(: http-uri-resolution feature is disabled. :)
+import schema "http://www.w3.org/";;
+1

=== added file 'test/rbkt/Queries/zorba/uris/slow.xqlib'
--- test/rbkt/Queries/zorba/uris/slow.xqlib	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/uris/slow.xqlib	2012-11-06 10:16:23 +0000
@@ -0,0 +1,11 @@
+(: For various reasons, importing a bad schema via HTTP can take :)
+(: minutes to complete. A test importing this module should time out :)
+(: unless the http-uri-resolution feature is disabled. :)
+module namespace slow = "http://www.zorba-xquery.com/test/uris/slow";;
+
+import schema "http://www.w3.org/";;
+
+declare function slow:ok() as xs:string
+{
+  "OK"
+};

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to