Till Westmann has proposed merging 
lp:~zorba-coders/zorba/bug-988417-block-internal-module into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Markos Zaharioudakis (markos-za)
Related bugs:
  Bug #988417 in Zorba: "block internal modules"
  https://bugs.launchpad.net/zorba/+bug/988417

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-988417-block-internal-module/+merge/103542

Enables a user to disable an built-in module. This is done by adding a 
collection of blocked modules URIs to the static context. This collection is 
checked before a built-in module is added to the context in the translator. 
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-988417-block-internal-module/+merge/103542
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/static_context.h'
--- include/zorba/static_context.h	2012-04-24 12:39:38 +0000
+++ include/zorba/static_context.h	2012-04-25 18:44:54 +0000
@@ -361,6 +361,15 @@
   virtual bool
   registerModule(ExternalModule* aModule) = 0;
 
+  /** \brief Block the usage of an internal module.
+   *
+   * Register a module to be non-accessible by a query.
+   *
+   * @param aModuleNS the module namespace of the module that is blocked
+   */
+  virtual void
+  blockBuiltInModule(const String& aModuleNS) = 0;
+
   /**
    * \brief Register a URI Mapper which will transform a given URI
    * into several alternate potential URIs.

=== modified file 'src/api/staticcontextimpl.cpp'
--- src/api/staticcontextimpl.cpp	2012-04-24 12:39:38 +0000
+++ src/api/staticcontextimpl.cpp	2012-04-25 18:44:54 +0000
@@ -696,6 +696,18 @@
 
 
 /*******************************************************************************
+
+********************************************************************************/
+void
+StaticContextImpl::blockBuiltInModule(const String& aModuleNS)
+{
+  const zstring& ns = Unmarshaller::getInternalString(aModuleNS);
+
+  theCtx->add_blocked_builtin_module(ns);
+}
+
+
+/*******************************************************************************
  URI Mapper
 *******************************************************************************/
 void
@@ -705,6 +717,7 @@
   theCtx->add_uri_mapper(new URIMapperWrapper(*aMapper));
 }
 
+
 /*******************************************************************************
  URL Resolver
 *******************************************************************************/

=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h	2012-04-24 12:39:38 +0000
+++ src/api/staticcontextimpl.h	2012-04-25 18:44:54 +0000
@@ -165,6 +165,9 @@
   getDocumentType(const String& aDocUri) const;
 
   virtual void
+  blockBuiltInModule(const String& aModuleNS);
+
+  virtual void
   registerURIMapper(URIMapper* aMapper);
 
   virtual void

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2012-04-24 12:39:38 +0000
+++ src/compiler/translator/translator.cpp	2012-04-25 18:44:54 +0000
@@ -2838,6 +2838,10 @@
   // importing module that X has been imported.
   if (atlist == NULL && static_context::is_builtin_module(targetNS))
   {
+    if (theRootSctx->is_blocked_builtin_module(targetNS))
+    {
+      RAISE_ERROR(err::XQST0059, loc, ERROR_PARAMS(targetNS));
+    }
     theRootSctx->add_imported_builtin_module(targetNS);
 #ifdef NDEBUG
     // We cannot skip the math or the sctx introspection modules because they

=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp	2012-04-24 12:39:38 +0000
+++ src/context/static_context.cpp	2012-04-25 18:44:54 +0000
@@ -551,6 +551,7 @@
   theParent(NULL),
   theTraceStream(NULL),
   theImportedBuiltinModules(NULL),
+  theBlockedBuiltinModules(NULL),
   theBaseUriInfo(NULL),
   theExternalModulesMap(NULL),
   theNamespaceBindings(NULL),
@@ -599,6 +600,7 @@
   theParent(parent),
   theTraceStream(NULL),
   theImportedBuiltinModules(NULL),
+  theBlockedBuiltinModules(NULL),
   theBaseUriInfo(NULL),
   theExternalModulesMap(NULL),
   theNamespaceBindings(NULL),
@@ -652,6 +654,7 @@
   theParent(NULL),
   theTraceStream(NULL),
   theImportedBuiltinModules(NULL),
+  theBlockedBuiltinModules(NULL),
   theBaseUriInfo(NULL),
   theExternalModulesMap(NULL),
   theNamespaceBindings(NULL),
@@ -700,6 +703,9 @@
   if (theImportedBuiltinModules)
     delete theImportedBuiltinModules;
 
+  if (theBlockedBuiltinModules)
+    delete theBlockedBuiltinModules;
+
   if (theExternalModulesMap)
   {
     ExternalModuleMap::iterator ite = theExternalModulesMap->begin();
@@ -1138,6 +1144,46 @@
 }
 
 
+/***************************************************************************//**
+
+********************************************************************************/
+void static_context::add_blocked_builtin_module(const zstring& ns)
+{
+  if (theBlockedBuiltinModules == NULL)
+  {
+    theBlockedBuiltinModules = new std::vector<zstring>;
+  }
+
+  theBlockedBuiltinModules->push_back(ns);
+}
+
+
+/***************************************************************************//**
+
+********************************************************************************/
+bool static_context::is_blocked_builtin_module(const zstring& ns)
+{
+  static_context* sctx = this;
+
+  while (sctx != NULL)
+  {
+    std::vector<zstring>* lBlockedModules = sctx->theBlockedBuiltinModules;
+    if (lBlockedModules != NULL)
+    {
+      if (std::find(lBlockedModules->begin(), lBlockedModules->end(), ns)
+          != lBlockedModules->end())
+      {
+        return true;
+      }
+    }
+
+    sctx = sctx->theParent;
+  }
+
+  return false;
+}
+
+
 /////////////////////////////////////////////////////////////////////////////////
 //                                                                             //
 //  Base URI                                                                   //

=== modified file 'src/context/static_context.h'
--- src/context/static_context.h	2012-04-24 12:39:38 +0000
+++ src/context/static_context.h	2012-04-25 18:44:54 +0000
@@ -500,6 +500,8 @@
 
   std::vector<zstring>                  * theImportedBuiltinModules;
 
+  std::vector<zstring>                  * theBlockedBuiltinModules;
+
   BaseUriInfo                           * theBaseUriInfo;
 
   ztd::auto_vector<internal::URIMapper>   theURIMappers;
@@ -633,6 +635,10 @@
 
   bool is_imported_builtin_module(const zstring& ns);
 
+  void add_blocked_builtin_module(const zstring& ns);
+
+  bool is_blocked_builtin_module(const zstring& ns);
+
   //
   // Base uri
   //

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