Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Friends
Arc::URL Class Reference

#include <URL.h>

Inheritance diagram for Arc::URL:
Inheritance graph
[legend]
Collaboration diagram for Arc::URL:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Scope { base, onelevel, subtree }
 Scope for LDAP URLs. More...

Public Member Functions

 URL ()
 Empty constructor.
 URL (const std::string &url)
 Constructs a new URL from a string representation.
virtual ~URL ()
 URL Destructor.
const std::string & Protocol () const
 Returns the protocol of the URL.
void ChangeProtocol (const std::string &newprot)
 Changes the protocol of the URL.
bool IsSecureProtocol () const
 Indicates whether the protocol is secure or not.
const std::string & Username () const
 Returns the username of the URL.
const std::string & Passwd () const
 Returns the password of the URL.
const std::string & Host () const
 Returns the hostname of the URL.
void ChangeHost (const std::string &newhost)
 Changes the hostname of the URL.
int Port () const
 Returns the port of the URL.
void ChangePort (int newport)
 Changes the port of the URL.
const std::string & Path () const
 Returns the path of the URL.
std::string FullPath () const
 Returns the path of the URL with all options attached.
void ChangePath (const std::string &newpath)
 Changes the path of the URL.
const std::map< std::string,
std::string > & 
HTTPOptions () const
 Returns HTTP options if any.
const std::string & HTTPOption (const std::string &option, const std::string &undefined="") const
 Returns the value of an HTTP option.
const std::list< std::string > & LDAPAttributes () const
 Returns the LDAP attributes if any.
void AddLDAPAttribute (const std::string &attribute)
 Adds an LDAP attribute.
Scope LDAPScope () const
 Returns the LDAP scope.
void ChangeLDAPScope (const Scope newscope)
 Changes the LDAP scope.
const std::string & LDAPFilter () const
 Returns the LDAP filter.
void ChangeLDAPFilter (const std::string &newfilter)
 Changes the LDAP filter.
const std::map< std::string,
std::string > & 
Options () const
 Returns URL options if any.
const std::string & Option (const std::string &option, const std::string &undefined="") const
 Returns the value of a URL option.
const std::map< std::string,
std::string > & 
MetaDataOptions () const
 Returns metadata options if any.
const std::string & MetaDataOption (const std::string &option, const std::string &undefined="") const
 Returns the value of a metadata option.
void AddOption (const std::string &option, const std::string &value, bool overwrite=true)
 Adds a URL option.
const std::list< URLLocation > & Locations () const
 Returns the locations if any.
const std::map< std::string,
std::string > & 
CommonLocOptions () const
 Returns the common location options if any.
const std::string & CommonLocOption (const std::string &option, const std::string &undefined="") const
 Returns the value of a common location option.
virtual std::string str () const
 Returns a string representation of the URL.
virtual std::string fullstr () const
 Returns a string representation including options and locations.
virtual std::string ConnectionURL () const
 Returns a string representation with protocol, host and port only.
bool operator< (const URL &url) const
 Compares one URL to another.
bool operator== (const URL &url) const
 Is one URL equal to another?
 operator bool () const
 Check if instance holds valid URL.
bool operator! () const
std::map< std::string,
std::string > 
ParseOptions (const std::string &optstring, char separator)
 Parse a string of options separated by separator into an attribute->value map.

Static Public Member Functions

static std::string OptionString (const std::map< std::string, std::string > &options, char separator)
 Returns a string representation of the options given in the options map.

Static Protected Member Functions

static std::string BaseDN2Path (const std::string &)
 a private method that converts an ldap basedn to a path.
static std::string Path2BaseDN (const std::string &)
 a private method that converts an ldap path to a basedn.

Protected Attributes

std::string protocol
 the url protocol.
std::string username
 username of the url.
std::string passwd
 password of the url.
std::string host
 hostname of the url.
bool ip6addr
 if host is IPv6 numerical address notation.
int port
 portnumber of the url.
std::string path
 the url path.
std::map< std::string,
std::string > 
httpoptions
 HTTP options of the url.
std::map< std::string,
std::string > 
metadataoptions
 Meta data options.
std::list< std::string > ldapattributes
 LDAP attributes of the url.
Scope ldapscope
 LDAP scope of the url.
std::string ldapfilter
 LDAP filter of the url.
std::map< std::string,
std::string > 
urloptions
 options of the url.
std::list< URLLocationlocations
 locations for index server URLs.
std::map< std::string,
std::string > 
commonlocoptions
 common location options for index server URLs.
bool valid
 flag to describe validity of URL

Friends

std::ostream & operator<< (std::ostream &out, const URL &u)
 Overloaded operator << to print a URL.

Detailed Description

Definition at line 74 of file URL.h.


Member Enumeration Documentation

Scope for LDAP URLs.

Enumerator:
base 
onelevel 
subtree 

Definition at line 88 of file URL.h.


Constructor & Destructor Documentation

Empty constructor.

Necessary when the class is part of another class and the like.

Definition at line 103 of file URL.cpp.

    : ip6addr(false),
      port(-1),
      ldapscope(base),
      valid(false) {}
Arc::URL::URL ( const std::string &  url)

Constructs a new URL from a string representation.

Definition at line 109 of file URL.cpp.

    : ip6addr(false),
      port(-1),
      ldapscope(base),
      valid(true) {

    std::string::size_type pos, pos2, pos3;

    if (url[0] == '\0') {
      valid = false;
      return;
    }

    if (url[0] == '#') {
      URLLogger.msg(ERROR, "URL is not valid: %s", url);
      valid = false;
      return;
    }

    // Looking for protocol separator
    pos = url.find(":");
    if (pos != std::string::npos) {
      // Check if protocol looks like protocol
      for(std::string::size_type p = 0; p < pos; ++p) {
        char c = url[p];
        if(isalnum(c) || (c == '+') || (c == '-') || (c == '.')) continue;
        pos = std::string::npos;
        break;
      }
#ifdef WIN32
      // Windows paths look like protocols - additional checks are needed
      // So for windows it looks like "disk:\"
      // TODO: probably some additional check is needed for "disk:"-like
      // paths. If such path can exist at all.
      if(pos != std::string::npos) {
        if(url[pos+1] == '\\') {
          pos = std::string::npos;
        }
      }
#endif
    }
    if (pos == std::string::npos) {
      // URL does not start from protocol - must be simple path
      if (url[0] == '@') {
        protocol = "urllist";
        path = url.substr(1);
      }
      else {
        protocol = "file";
        path = url;
      }
      if (!Glib::path_is_absolute(path)) {
        char cwd[PATH_MAX];
        if (getcwd(cwd, PATH_MAX))
          path = Glib::build_filename(cwd, path);
      }
      // Simple paths are not expected to contain any options or metadata
      return;
    }

    // RFC says protocols should be lowercase and uppercase
    // must be converted to lowercase for consistency
    protocol = lower(url.substr(0, pos));

    // Checking if protocol followed by host/authority part
    // or by path directly
    if((url[pos+1] != '/') || (url[pos+2] != '/')) {
      // No host part
      host = "";
      pos += 1;
      pos2 = pos; // path start position
      path = url.substr(pos2);
      // This must be only path - we can accept path only for
      // limited set of protocols
      if ((protocol == "file" || protocol == "urllist")) {
        if (!Glib::path_is_absolute(path)) {
          char cwd[PATH_MAX];
          if (getcwd(cwd, PATH_MAX))
            path = Glib::build_filename(cwd, path);
        }
        return;
      } else if (protocol == "arc") {
        // TODO: It is not defined how arc protocol discovers
        // entry point in general case.
        // For same reason let's assume path must be always
        // absolute.
        if(url[pos] != '/') {
          URLLogger.msg(ERROR, "Illegal URL - path must be absolute");
          valid = false;
          return;
        }
      } else {
        URLLogger.msg(ERROR, "Illegal URL - no hostname given");
        valid = false;
        return;
      }
    } else {
      // There is host/authority part in this URL. That also
      // means path is absolute if present
      pos += 3;

      pos2 = url.find("@", pos);
      if (pos2 != std::string::npos) {

        if (protocol == "rc" || protocol == "rls" ||
            protocol == "fireman" || protocol == "lfc") {
          // Indexing protocols may contain locations

          std::string locstring = url.substr(pos, pos2 - pos);
          pos = pos2 + 1;

          pos2 = 0;
          while (pos2 != std::string::npos) {

            pos3 = locstring.find('|', pos2);
            std::string loc = (pos3 == std::string::npos ?
                               locstring.substr(pos2) :
                               locstring.substr(pos2, pos3 - pos2));

            pos2 = pos3;
            if (pos2 != std::string::npos)
              pos2++;

            if (loc[0] == ';')
              commonlocoptions = ParseOptions(loc.substr(1), ';');
            else {
              if (protocol == "rc") {
                pos3 = loc.find(';');
                if (pos3 == std::string::npos)
                  locations.push_back(URLLocation(ParseOptions("", ';'), loc));
                else
                  locations.push_back(URLLocation(ParseOptions
                                                  (loc.substr(pos3 + 1), ';'),
                                                  loc.substr(pos3 + 1)));
              }
              else
                locations.push_back(loc);
            }
          }
        }
        else {
          pos3 = url.find("/", pos);
          if (pos3 == std::string::npos)
            pos3 = url.length();
          if (pos3 > pos2) {
            username = url.substr(pos, pos2 - pos);
            pos3 = username.find(':');
            if (pos3 != std::string::npos) {
              passwd = username.substr(pos3 + 1);
              username.resize(pos3);
            }
            pos = pos2 + 1;
          }
        }
      }

      // Looking for end of host/authority part
      pos2 = url.find("/", pos);
      if (pos2 == std::string::npos) {
        // Path part is empty, host may be empty too
        host = url.substr(pos);
        path = "";
      }
      else if (pos2 == pos) {
        // Empty host and non-empty absolute path
        host = "";
        path = url.substr(pos2);
      }
      else {
        // Both host and absolute path present
        host = url.substr(pos, pos2 - pos);
        path = url.substr(pos2);
      }
    }

    // At this point path must be absolutely absolute (starts with /) or empty
    if ((!path.empty()) && (path[0] != '/')) {
      URLLogger.msg(ERROR, "Illegal URL - path must be absolute or empty");
      valid = false;
      return;
    }

    // Extracting port URL options (ARC extension)
    if (!host.empty()) {
      // Check for [ip6address] notation
      // If behaving strictly we should check for valid address 
      // inside []. But if we do not do that only drawback is that
      // URL may have any hostname inside []. Not really important
      // issue.
      if(host[0] == '[') {
        ip6addr = true;
        pos2 = host.find(']');
        if(pos2 == std::string::npos) {
          URLLogger.msg(ERROR, "Illegal URL - no closing ] for IPv6 address found");
          valid = false;
          return;
        }
        // There may be only port or options after closing ]
        ++pos2;
        if(pos2 < host.length()) {
          if((host[pos2] != ':') && (host[pos2] != ';')) {
            URLLogger.msg(ERROR, "Illegal URL - closing ] for IPv6 address is at followed by illegal token");
            valid = false;
            return;
          }
          if(host[pos2] != ':') pos2 = std::string::npos;
        } else {
          pos2 = std::string::npos;
        }
      } else {
        pos2 = host.find(':');
      }
      if (pos2 != std::string::npos) {
        pos3 = host.find(';', pos2);
        port = stringtoi(pos3 == std::string::npos ?
                         host.substr(pos2 + 1) :
                         host.substr(pos2 + 1, pos3 - pos2 - 1));
      }
      else {
        pos3 = host.find(';');
        pos2 = pos3;
      }
      if (pos3 != std::string::npos)
        urloptions = ParseOptions(host.substr(pos3 + 1), ';');
      if (pos2 != std::string::npos) 
        host.resize(pos2);
      if (ip6addr)
        host = host.substr(1,host.length()-2);
    }

    if (port == -1) {
      if (protocol == "rc")
        port = RC_DEFAULT_PORT;
      if (protocol == "rls")
        port = RLS_DEFAULT_PORT;
      if (protocol == "http")
        port = HTTP_DEFAULT_PORT;
      if (protocol == "https")
        port = HTTPS_DEFAULT_PORT;
      if (protocol == "httpg")
        port = HTTPG_DEFAULT_PORT;
      if (protocol == "srm")
        port = SRM_DEFAULT_PORT;
      if (protocol == "ldap")
        port = LDAP_DEFAULT_PORT;
      if (protocol == "ftp")
        port = FTP_DEFAULT_PORT;
      if (protocol == "gsiftp")
        port = GSIFTP_DEFAULT_PORT;
      if (protocol == "lfc")
        port = LFC_DEFAULT_PORT;
    }

    if (protocol != "ldap" && protocol != "arc") {
      pos2 = path.rfind('=');
      if (pos2 != std::string::npos) {
        pos3 = path.rfind(':', pos2);
        if (pos3 != std::string::npos) {
          pos = pos3;
          while (pos2 != std::string::npos && pos3 != std::string::npos) {
            pos2 = path.rfind('=', pos);
            if (pos2 != std::string::npos) {
              pos3 = path.rfind(':', pos2);
              if (pos3 != std::string::npos)
                pos = pos3;
            }
          }
          metadataoptions = ParseOptions(path.substr(pos + 1), ':');
          path = path.substr(0, pos);
        }
      }
    }

    // if protocol = http, get the options after the ?
    if (protocol == "http" ||
        protocol == "https" ||
        protocol == "httpg" ||
        protocol == "arc" ||
        protocol == "srm") {
      pos = path.find("?");
      if (pos != std::string::npos) {
        httpoptions = ParseOptions(path.substr(pos + 1), '&');
        path = path.substr(0, pos);
      }
    }

    // parse ldap protocol specific attributes
    if (protocol == "ldap") {
      std::string ldapscopestr;
      pos = path.find('?');
      if (pos != std::string::npos) {
        pos2 = path.find('?', pos + 1);
        if (pos2 != std::string::npos) {
          pos3 = path.find('?', pos2 + 1);
          if (pos3 != std::string::npos) {
            ldapfilter = path.substr(pos3 + 1);
            ldapscopestr = path.substr(pos2 + 1, pos3 - pos2 - 1);
          }
          else
            ldapscopestr = path.substr(pos2 + 1);
          ldapattributes = ParseAttributes(path.substr(pos + 1,
                                                       pos2 - pos - 1), ',');
        }
        else
          ldapattributes = ParseAttributes(path.substr(pos + 1), ',');
        path = path.substr(0, pos);
      }
      if (ldapscopestr == "base")
        ldapscope = base;
      else if (ldapscopestr == "one")
        ldapscope = onelevel;
      else if (ldapscopestr == "sub")
        ldapscope = subtree;
      else if (!ldapscopestr.empty())
        URLLogger.msg(ERROR, "Unknown LDAP scope %s - using base",
                      ldapscopestr);
      if (ldapfilter.empty())
        ldapfilter = "(objectClass=*)";
      if (path.find("/",1) != std::string::npos)
        path = Path2BaseDN(path);
      else
        path.erase(0,1);
    }

    // Normally host/authority names are case-insensitive
    host = lower(host);
  }

Here is the call graph for this function:

Arc::URL::~URL ( ) [virtual]

URL Destructor.

Definition at line 437 of file URL.cpp.

{}

Member Function Documentation

void Arc::URL::AddLDAPAttribute ( const std::string &  attribute)

Adds an LDAP attribute.

Definition at line 577 of file URL.cpp.

                                                       {
    ldapattributes.push_back(attribute);
  }

Here is the caller graph for this function:

void Arc::URL::AddOption ( const std::string &  option,
const std::string &  value,
bool  overwrite = true 
)

Adds a URL option.

Definition at line 611 of file URL.cpp.

                                      {
    if (!overwrite && urloptions.find(option) != urloptions.end())
      return;
    urloptions[option] = value;
  }

Here is the caller graph for this function:

std::string Arc::URL::BaseDN2Path ( const std::string &  basedn) [static, protected]

a private method that converts an ldap basedn to a path.

Definition at line 823 of file URL.cpp.

                                                    {

    std::string::size_type pos, pos2;
    // mds-vo-name=local, o=grid --> o=grid/mds-vo-name=local
    std::string newpath;

    pos = basedn.size();
    while ((pos2 = basedn.rfind(",", pos - 1)) != std::string::npos) {
      std::string tmppath = basedn.substr(pos2 + 1, pos - pos2 - 1);
      tmppath = tmppath.substr(tmppath.find_first_not_of(' '));
      newpath += tmppath + '/';
      pos = pos2;
    }

    newpath += basedn.substr(0, pos);

    return newpath;
  }
void Arc::URL::ChangeHost ( const std::string &  newhost)

Changes the hostname of the URL.

Definition at line 471 of file URL.cpp.

                                               {
    host = lower(newhost);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::URL::ChangeLDAPFilter ( const std::string &  newfilter)

Changes the LDAP filter.

Definition at line 593 of file URL.cpp.

                                                       {
    ldapfilter = newfilter;
  }

Here is the caller graph for this function:

void Arc::URL::ChangeLDAPScope ( const Scope  newscope)

Changes the LDAP scope.

Definition at line 585 of file URL.cpp.

                                                {
    ldapscope = newscope;
  }

Here is the caller graph for this function:

void Arc::URL::ChangePath ( const std::string &  newpath)

Changes the path of the URL.

Definition at line 521 of file URL.cpp.

                                               {
    path = newpath;

    // parse basedn in case of ldap-protocol
    if (protocol == "ldap") {
      if (path.find("/") != std::string::npos)
        path = Path2BaseDN(path);

    // add absolute path for relative file URLs
    } else if (protocol == "file" || protocol == "urllist") {
      if(!Glib::path_is_absolute(path)) {
        char cwd[PATH_MAX];
        if (getcwd(cwd, PATH_MAX))
          path = Glib::build_filename(cwd, path);
      }
    }

    // for generic URL just make sure path has leading /
    else if ((path[0] != '/') && (!path.empty())) {
      URLLogger.msg(WARNING, "Attempt to assign relative path to URL - making it absolute");
      path = "/" + path;
    }

  }

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::URL::ChangePort ( int  newport)

Changes the port of the URL.

Definition at line 479 of file URL.cpp.

                                  {
    port = newport;
  }
void Arc::URL::ChangeProtocol ( const std::string &  newprot)

Changes the protocol of the URL.

Definition at line 443 of file URL.cpp.

                                                   {
    protocol = lower(newprot);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & Arc::URL::CommonLocOption ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of a common location option.

Parameters:
optionThe option whose value is returned.
undefinedThis value is returned if the common location option is not defined.

Definition at line 626 of file URL.cpp.

                                                                            {
    std::map<std::string, std::string>::const_iterator
    opt = commonlocoptions.find(option);
    if (opt != commonlocoptions.end())
      return opt->second;
    else
      return undefined;
  }
const std::map< std::string, std::string > & Arc::URL::CommonLocOptions ( ) const

Returns the common location options if any.

Definition at line 622 of file URL.cpp.

                                                                  {
    return commonlocoptions;
  }

Here is the caller graph for this function:

std::string Arc::URL::ConnectionURL ( ) const [virtual]

Returns a string representation with protocol, host and port only.

Definition at line 796 of file URL.cpp.

                                     {

    std::string urlstr;
    if (!protocol.empty())
      urlstr = protocol + "://";

    if (!host.empty()) {
      if(ip6addr)
        urlstr += "[" + host + "]";
      else
        urlstr += host;
    }

    if (port != -1)
      urlstr += ':' + tostring(port);

    return urlstr;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Arc::URL::FullPath ( ) const

Returns the path of the URL with all options attached.

Definition at line 487 of file URL.cpp.

                                {
    std::string fullpath;

    if (!path.empty())
      fullpath += path;

    if (!httpoptions.empty())
      fullpath += '?' + OptionString(httpoptions, '&');

    if (!ldapattributes.empty() || (ldapscope != base) || !ldapfilter.empty())
      fullpath += '?' + AttributeString(ldapattributes, ',');

    if ((ldapscope != base) || !ldapfilter.empty()) {
      switch (ldapscope) {
      case base:
        fullpath += "?base";
        break;

      case onelevel:
        fullpath += "?one";
        break;

      case subtree:
        fullpath += "?sub";
        break;
      }
    }

    if (!ldapfilter.empty())
      fullpath += '?' + ldapfilter;

    return fullpath;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Arc::URL::fullstr ( ) const [virtual]

Returns a string representation including options and locations.

Reimplemented in Arc::URLLocation.

Definition at line 636 of file URL.cpp.

                               {

    std::string urlstr;

    if (!username.empty())
      urlstr += username;

    if (!passwd.empty())
      urlstr += ':' + passwd;

    for (std::list<URLLocation>::const_iterator it = locations.begin();
         it != locations.end(); it++) {
      if (it != locations.begin())
        urlstr += '|';
      urlstr += it->fullstr();
    }

    if (!locations.empty() && !commonlocoptions.empty())
      urlstr += '|';

    if (!commonlocoptions.empty())
      urlstr += ';' + OptionString(commonlocoptions, ';');

    if (!username.empty() || !passwd.empty() || !locations.empty())
      urlstr += '@';

    if (!host.empty()) {
      if(ip6addr) 
        urlstr += "[" + host + "]";
      else
        urlstr += host;
    }

    if (port != -1)
      urlstr += ':' + tostring(port);

    if (!urloptions.empty())
      urlstr += ';' + OptionString(urloptions, ';');

    if (!protocol.empty()) {
      if (!urlstr.empty())
        urlstr = protocol + "://" + urlstr;
      else
        urlstr = protocol + ":";
    }

    // Constructor makes sure path is absolute or empty.
    // ChangePath() also makes such check.
    if ( protocol == "ldap") // Unfortunately ldap is special case
      urlstr += '/';
    urlstr += path;

    // If there is nothing at this point there is no sense
    // to add any options
    if (urlstr.empty())
      return urlstr;

    if (!httpoptions.empty())
      urlstr += '?' + OptionString(httpoptions, '&');

    if (!ldapattributes.empty() || (ldapscope != base) || !ldapfilter.empty())
      urlstr += '?' + AttributeString(ldapattributes, ',');

    if ((ldapscope != base) || !ldapfilter.empty()) {
      switch (ldapscope) {
      case base:
        urlstr += "?base";
        break;

      case onelevel:
        urlstr += "?one";
        break;

      case subtree:
        urlstr += "?sub";
        break;
      }
    }

    if (!ldapfilter.empty())
      urlstr += '?' + ldapfilter;

    if (!metadataoptions.empty())
      urlstr += ':' + OptionString(metadataoptions, ':');

    return urlstr;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string & Arc::URL::Host ( ) const

Returns the hostname of the URL.

Definition at line 467 of file URL.cpp.

                                   {
    return host;
  }
const std::string & Arc::URL::HTTPOption ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of an HTTP option.

Parameters:
optionThe option whose value is returned.
undefinedThis value is returned if the HTTP option is not defined.

Definition at line 550 of file URL.cpp.

                                                                       {
    std::map<std::string, std::string>::const_iterator
    opt = httpoptions.find(option);
    if (opt != httpoptions.end())
      return opt->second;
    else
      return undefined;
  }

Here is the caller graph for this function:

const std::map< std::string, std::string > & Arc::URL::HTTPOptions ( ) const

Returns HTTP options if any.

Definition at line 546 of file URL.cpp.

                                                             {
    return httpoptions;
  }

Here is the caller graph for this function:

Indicates whether the protocol is secure or not.

Definition at line 447 of file URL.cpp.

                                   {
    return protocol == "gsiftp" ||
           protocol == "https" ||
           protocol == "httpg" ||
           protocol == "rc" ||
           protocol == "rls" ||
           protocol == "srm" ||
           protocol == "arc" ||
           protocol == "fireman" ||
           protocol == "lfc";
  }

Here is the caller graph for this function:

const std::list< std::string > & Arc::URL::LDAPAttributes ( ) const

Returns the LDAP attributes if any.

Definition at line 573 of file URL.cpp.

                                                      {
    return ldapattributes;
  }

Here is the caller graph for this function:

const std::string & Arc::URL::LDAPFilter ( ) const

Returns the LDAP filter.

Definition at line 589 of file URL.cpp.

                                         {
    return ldapfilter;
  }

Here is the caller graph for this function:

Returns the LDAP scope.

Definition at line 581 of file URL.cpp.

                                {
    return ldapscope;
  }

Here is the caller graph for this function:

const std::list< URLLocation > & Arc::URL::Locations ( ) const

Returns the locations if any.

Definition at line 618 of file URL.cpp.

                                                   {
    return locations;
  }

Here is the caller graph for this function:

const std::string & Arc::URL::MetaDataOption ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of a metadata option.

Parameters:
optionThe option whose value is returned.
undefinedThis value is returned if the metadata option is not defined.

Definition at line 564 of file URL.cpp.

                                                                           {
    std::map<std::string, std::string>::const_iterator opt = metadataoptions.find(option);
    if (opt != metadataoptions.end())
      return opt->second;
    else
      return undefined;
  }

Here is the caller graph for this function:

const std::map< std::string, std::string > & Arc::URL::MetaDataOptions ( ) const

Returns metadata options if any.

Definition at line 560 of file URL.cpp.

                                                                 {
    return metadataoptions;
  }

Here is the caller graph for this function:

Arc::URL::operator bool ( void  ) const

Check if instance holds valid URL.

Reimplemented in SRMURL.

Definition at line 865 of file URL.cpp.

                           {
    return valid;
  }
bool Arc::URL::operator! ( void  ) const

Reimplemented in SRMURL.

Definition at line 869 of file URL.cpp.

                            {
    return !valid;
  }
bool Arc::URL::operator< ( const URL url) const

Compares one URL to another.

Definition at line 815 of file URL.cpp.

                                          {
    return (str() < url.str());
  }

Here is the call graph for this function:

bool Arc::URL::operator== ( const URL url) const

Is one URL equal to another?

Definition at line 819 of file URL.cpp.

                                           {
    return (str() == url.str());
  }

Here is the call graph for this function:

const std::string & Arc::URL::Option ( const std::string &  option,
const std::string &  undefined = "" 
) const

Returns the value of a URL option.

Parameters:
optionThe option whose value is returned.
undefinedThis value is returned if the URL option is not defined.

Definition at line 601 of file URL.cpp.

                                                                   {
    std::map<std::string, std::string>::const_iterator
    opt = urloptions.find(option);
    if (opt != urloptions.end())
      return opt->second;
    else
      return undefined;
  }

Here is the caller graph for this function:

const std::map< std::string, std::string > & Arc::URL::Options ( ) const

Returns URL options if any.

Definition at line 597 of file URL.cpp.

                                                         {
    return urloptions;
  }

Here is the caller graph for this function:

std::string Arc::URL::OptionString ( const std::map< std::string, std::string > &  options,
char  separator 
) [static]

Returns a string representation of the options given in the options map.

Definition at line 873 of file URL.cpp.

                                                                                    {

    std::string optstring;

    if (options.empty())
      return optstring;

    for (std::map<std::string, std::string>::const_iterator
         it = options.begin(); it != options.end(); it++) {
      if (it != options.begin())
        optstring += separator;
      optstring += it->first + '=' + it->second;
    }
    return optstring;
  }

Here is the caller graph for this function:

std::map< std::string, std::string > Arc::URL::ParseOptions ( const std::string &  optstring,
char  separator 
)

Parse a string of options separated by separator into an attribute->value map.

Definition at line 26 of file URL.cpp.

                                                                                           {

    std::map<std::string, std::string> options;

    if (optstring.empty())
      return options;

    std::string::size_type pos = 0;
    while (pos != std::string::npos) {

      std::string::size_type pos2 = optstring.find(separator, pos);

      std::string opt = (pos2 == std::string::npos ?
                         optstring.substr(pos) :
                         optstring.substr(pos, pos2 - pos));

      pos = pos2;
      if (pos != std::string::npos)
        pos++;

      pos2 = opt.find('=');
      std::string option_name, option_value = "";
      if (pos2 == std::string::npos) {
        option_name = opt;
      } else {
        option_name = opt.substr(0, pos2);
        option_value = opt.substr(pos2 + 1);
      }
      options[option_name] = option_value;
    }
    return options;
  }

Here is the caller graph for this function:

const std::string & Arc::URL::Passwd ( ) const

Returns the password of the URL.

Definition at line 463 of file URL.cpp.

                                     {
    return passwd;
  }

Here is the caller graph for this function:

const std::string & Arc::URL::Path ( ) const

Returns the path of the URL.

Definition at line 483 of file URL.cpp.

                                   {
    return path;
  }
std::string Arc::URL::Path2BaseDN ( const std::string &  newpath) [static, protected]

a private method that converts an ldap path to a basedn.

Definition at line 842 of file URL.cpp.

                                                     {

    if (newpath.empty())
      return "";

    std::string basedn;
    std::string::size_type pos, pos2;

    pos = newpath.size();
    while ((pos2 = newpath.rfind("/", pos - 1)) != std::string::npos) {
      if (pos2 == 0) break;
      basedn += newpath.substr(pos2 + 1, pos - pos2 - 1) + ", ";
      pos = pos2;
    }

    if (pos2 == std::string::npos)
      basedn += newpath.substr(0, pos);
    else
      basedn += newpath.substr(pos2 + 1, pos - pos2 - 1);

    return basedn;
  }

Here is the caller graph for this function:

int Arc::URL::Port ( ) const

Returns the port of the URL.

Definition at line 475 of file URL.cpp.

                      {
    return port;
  }

Here is the caller graph for this function:

const std::string & Arc::URL::Protocol ( ) const

Returns the protocol of the URL.

Definition at line 439 of file URL.cpp.

                                       {
    return protocol;
  }
std::string Arc::URL::str ( ) const [virtual]

Returns a string representation of the URL.

Reimplemented in Arc::URLLocation.

Definition at line 724 of file URL.cpp.

                           {

    std::string urlstr;

    if (!username.empty())
      urlstr += username;

    if (!passwd.empty())
      urlstr += ':' + passwd;

    if (!username.empty() || !passwd.empty())
      urlstr += '@';

    if (!host.empty()) {
      if(ip6addr)
        urlstr += "[" + host + "]";
      else
        urlstr += host;
    }

    if (port != -1)
      urlstr += ':' + tostring(port);

    if (!protocol.empty()) {
      if (!urlstr.empty())
        urlstr = protocol + "://" + urlstr;
      else
        urlstr = protocol + ":";
    }

    // Constructor makes sure path is absolute or empty.
    // ChangePath also makes such check.
    if ( protocol == "ldap") // Unfortunately ldap is special case
      urlstr += '/';
    urlstr += path;

    // If there is nothing at this point there is no sense
    // to add any options
    if (urlstr.empty())
      return urlstr;

    if (!httpoptions.empty())
      urlstr += '?' + OptionString(httpoptions, '&');

    if (!ldapattributes.empty() || (ldapscope != base) || !ldapfilter.empty())
      urlstr += '?' + AttributeString(ldapattributes, ',');

    if ((ldapscope != base) || !ldapfilter.empty()) {
      switch (ldapscope) {
      case base:
        urlstr += "?base";
        break;

      case onelevel:
        urlstr += "?one";
        break;

      case subtree:
        urlstr += "?sub";
        break;
      }
    }

    if (!ldapfilter.empty())
      urlstr += '?' + ldapfilter;

    if (!metadataoptions.empty())
      urlstr += ':' + OptionString(metadataoptions, ':');

    return urlstr;
  }

Here is the call graph for this function:

const std::string & Arc::URL::Username ( ) const

Returns the username of the URL.

Definition at line 459 of file URL.cpp.

                                       {
    return username;
  }

Here is the caller graph for this function:


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const URL u 
) [friend]

Overloaded operator << to print a URL.

Definition at line 891 of file URL.cpp.

                                                          {
    return (out << url.str());
  }

Member Data Documentation

std::map<std::string, std::string> Arc::URL::commonlocoptions [protected]

common location options for index server URLs.

Definition at line 265 of file URL.h.

std::string Arc::URL::host [protected]

hostname of the url.

Definition at line 232 of file URL.h.

std::map<std::string, std::string> Arc::URL::httpoptions [protected]

HTTP options of the url.

Definition at line 244 of file URL.h.

bool Arc::URL::ip6addr [protected]

if host is IPv6 numerical address notation.

Definition at line 235 of file URL.h.

std::list<std::string> Arc::URL::ldapattributes [protected]

LDAP attributes of the url.

Definition at line 250 of file URL.h.

std::string Arc::URL::ldapfilter [protected]

LDAP filter of the url.

Definition at line 256 of file URL.h.

LDAP scope of the url.

Definition at line 253 of file URL.h.

std::list<URLLocation> Arc::URL::locations [protected]

locations for index server URLs.

Definition at line 262 of file URL.h.

std::map<std::string, std::string> Arc::URL::metadataoptions [protected]

Meta data options.

Definition at line 247 of file URL.h.

std::string Arc::URL::passwd [protected]

password of the url.

Definition at line 229 of file URL.h.

std::string Arc::URL::path [protected]

the url path.

Definition at line 241 of file URL.h.

int Arc::URL::port [protected]

portnumber of the url.

Definition at line 238 of file URL.h.

std::string Arc::URL::protocol [protected]

the url protocol.

Definition at line 223 of file URL.h.

std::map<std::string, std::string> Arc::URL::urloptions [protected]

options of the url.

Definition at line 259 of file URL.h.

std::string Arc::URL::username [protected]

username of the url.

Definition at line 226 of file URL.h.

bool Arc::URL::valid [protected]

flag to describe validity of URL

Reimplemented in SRMURL.

Definition at line 268 of file URL.h.


The documentation for this class was generated from the following files: