ignore
[platform/upstream/libzypp.git] / zypp / Url.cc
index 7558095..fff6e8c 100644 (file)
@@ -73,6 +73,11 @@ namespace zypp
         config("psep_querystr",   "?");
         config("vsep_querystr",   "");
 
+        // host is required (isValid=>false)
+        // but not mandatory (see RFC 2255),
+        // that is, accept empty host.
+        config("require_host",    "y");
+
         // not allowed here
         config("rx_username",     "");
         config("rx_password",     "");
@@ -162,21 +167,46 @@ namespace zypp
       {
         UrlRef ref;
 
+        // =====================================
         ref.reset( new LDAPUrl());
         addUrlByScheme("ldap", ref);
         addUrlByScheme("ldaps", ref);
 
+
+        // =====================================
         ref.reset( new UrlBase());
+        ref->config("with_authority",   "n");   // disallow host,...
+        ref->config("require_pathname", "m");   // path is mandatory
+        addUrlByScheme("hd",     ref);
+        addUrlByScheme("cd",     ref);
+        addUrlByScheme("dvd",    ref);
+        addUrlByScheme("dir",    ref);
+        addUrlByScheme("iso",    ref);
+
         // don't show empty authority
         ref->setViewOptions( zypp::url::ViewOption::DEFAULTS -
                              zypp::url::ViewOption::EMPTY_AUTHORITY);
-        ref->config("rx_username",      "");  // disallow username
-        ref->config("rx_password",      "");  // disallow password
-        // FIXME: hmm... also host+port?
-        addUrlByScheme("nfs",    ref);
-
-        ref->config("with_authority"    "n");   // disallow host & port
         addUrlByScheme("mailto", ref);
+        addUrlByScheme("urn",    ref);
+
+        // RFC1738, 3.10: may contain a host
+        ref->config("with_authority",   "y");   // allow host,
+        ref->config("with_port",        "n");   // but no port,
+        ref->config("rx_username",      "");    // username or
+        ref->config("rx_password",      "");    // password ...
+        addUrlByScheme("file",   ref);
+
+        // =====================================
+        ref.reset( new UrlBase());
+        ref->config("require_host",     "m");   // host is mandatory
+        addUrlByScheme("nfs",    ref);
+        addUrlByScheme("smb",    ref);
+        addUrlByScheme("cifs",   ref);
+        addUrlByScheme("http",   ref);
+        addUrlByScheme("https",  ref);
+        ref->config("path_encode_slash2", "y"); // always encode 2. slash
+        addUrlByScheme("ftp",    ref);
+        addUrlByScheme("sftp",   ref);
       }
 
       bool
@@ -217,7 +247,7 @@ namespace zypp
         UrlSchemes                     schemes;
 
         schemes.reserve(urlByScheme.size());
-        for( ; i != urlByScheme.begin(); ++i)
+        for( ; i != urlByScheme.end(); ++i)
         {
           schemes.push_back(i->first);
         }
@@ -291,7 +321,7 @@ namespace zypp
   Url&
   Url::operator = (const std::string &encodedUrl)
   {
-    UrlRef  url( parseUrl(encodedUrl));
+    UrlRef url( parseUrl(encodedUrl));
     if( !url)
     {
       ZYPP_THROW(url::UrlParsingException(
@@ -408,6 +438,26 @@ namespace zypp
 
   // -----------------------------------------------------------------
   std::string
+  Url::asCompleteString() const
+  {
+    // make sure, all url components are included;
+    // regardless of the current configuration...
+    ViewOptions opts(getViewOptions() +
+                     ViewOption::WITH_SCHEME +
+                     ViewOption::WITH_USERNAME +
+                     ViewOption::WITH_PASSWORD +
+                     ViewOption::WITH_HOST +
+                     ViewOption::WITH_PORT +
+                     ViewOption::WITH_PATH_NAME +
+                     ViewOption::WITH_PATH_PARAMS +
+                     ViewOption::WITH_QUERY_STR +
+                     ViewOption::WITH_FRAGMENT);
+    return m_impl->asString(opts);
+  }
+
+
+  // -----------------------------------------------------------------
+  std::string
   Url::asString(const ViewOptions &opts) const
   {
     return m_impl->asString(opts);
@@ -708,6 +758,19 @@ namespace zypp
     m_impl->setQueryParam(param, value);
   }
 
+  // -----------------------------------------------------------------
+  ViewOptions
+  Url::getViewOptions() const
+  {
+    return m_impl->getViewOptions();
+  }
+
+  // -----------------------------------------------------------------
+  void
+  Url::setViewOptions(const ViewOptions &vopts)
+  {
+    m_impl->setViewOptions(vopts);
+  }
 
   // -----------------------------------------------------------------
   std::ostream & operator<<( std::ostream & str, const Url & url )