2 * Copyright 2000-2006, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <StringList.h>
12 class LDAPUrlException;
14 * This class is used to analyze and store LDAP-Urls as returned by a
15 * LDAP-Server as Referrals and Search References. LDAP-URLs are defined
16 * in RFC1959 and have the following format: <BR>
18 * ldap://host:port/baseDN[?attr[?scope[?filter]]] <BR>
25 * Create a new object from a string that contains a LDAP-Url
26 * @param url The URL String
28 LDAPUrl(const std::string &url="");
36 * @return The part of the URL that is representing the network
42 * Set the port value of the URL
43 * @param dn The port value
45 void setPort(int port);
48 * @return The scope part of the URL is returned.
53 * Set the Scope part of the URL
54 * @param scope The new scope
56 void setScope(const std::string& scope);
59 * @return The complete URL as a string
61 const std::string& getURLString();
64 * Set the URL member attribute
65 * @param url The URL String
67 void setURLString(const std::string &url);
70 * @return The hostname or IP-Address of the destination host.
72 const std::string& getHost() const;
75 * Set the Host part of the URL
76 * @param host The new host part
78 void setHost( const std::string &host);
81 * @return The Protocol Scheme of the URL.
83 const std::string& getScheme() const;
86 * Set the Protocol Scheme of the URL
87 * @param host The Protcol scheme. Allowed values are
88 * ldap,ldapi,ldaps and cldap
90 void setScheme( const std::string &scheme );
93 * @return The Base-DN part of the URL
95 const std::string& getDN() const;
98 * Set the DN part of the URL
99 * @param dn The new DN part
101 void setDN( const std::string &dn);
105 * @return The Filter part of the URL
107 const std::string& getFilter() const;
110 * Set the Filter part of the URL
111 * @param filter The new Filter
113 void setFilter( const std::string &filter);
116 * @return The List of attributes that was in the URL
118 const StringList& getAttrs() const;
121 * Set the Attributes part of the URL
122 * @param attrs StringList constaining the List of Attributes
124 void setAttrs( const StringList &attrs);
125 void setExtensions( const StringList &ext);
126 const StringList& getExtensions() const;
129 * Percent-decode a string
130 * @param src The string that is to be decoded
131 * @param dest The decoded result string
133 void percentDecode( const std::string& src, std::string& dest );
136 * Percent-encoded a string
137 * @param src The string that is to be encoded
138 * @param dest The encoded result string
141 void percentEncode( const std::string& src,
147 * Split the url string that is associated with this Object into
148 * it components. The compontens of the URL can be access via the
150 * (this function is mostly for internal use and gets called
151 * automatically whenever necessary)
156 * Generate an URL string from the components that were set with
157 * the various set...() methods
158 * (this function is mostly for internal use and gets called
159 * automatically whenever necessary)
161 void components2Url();
163 void string2list(const std::string &src, StringList& sl,
164 bool percentDecode=false);
172 std::string m_Filter;
174 StringList m_Extensions;
175 std::string m_urlString;
176 std::string m_Scheme;
177 enum mode { base, attrs, scope, filter, extensions };
180 struct code2string_s {
185 class LDAPUrlException {
187 LDAPUrlException(int code, const std::string &msg="" );
190 const std::string getErrorMessage() const;
191 const std::string getAdditionalInfo() const;
193 static const int INVALID_SCHEME = 1;
194 static const int INVALID_PORT = 2;
195 static const int INVALID_SCOPE = 3;
196 static const int INVALID_URL = 4;
197 static const int URL_DECODING_ERROR = 5;
198 static const code2string_s code2string[];
202 std::string m_addMsg;