1/* $NetBSD: LDAPUrl.h,v 1.1.1.3 2010/12/12 15:18:48 adam Exp $ */ 2 3// OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPUrl.h,v 1.6.8.5 2010/04/14 23:50:44 quanah Exp 4/* 5 * Copyright 2000-2006, OpenLDAP Foundation, All Rights Reserved. 6 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file 7 */ 8 9 10#ifndef LDAP_URL_H 11#define LDAP_URL_H 12 13#include <StringList.h> 14 15class LDAPUrlException; 16/** 17 * This class is used to analyze and store LDAP-Urls as returned by a 18 * LDAP-Server as Referrals and Search References. LDAP-URLs are defined 19 * in RFC1959 and have the following format: <BR> 20 * <code> 21 * ldap://host:port/baseDN[?attr[?scope[?filter]]] <BR> 22 * </code> 23 */ 24class LDAPUrl{ 25 26 public : 27 /** 28 * Create a new object from a string that contains a LDAP-Url 29 * @param url The URL String 30 */ 31 LDAPUrl(const std::string &url=""); 32 33 /** 34 * Destructor 35 */ 36 ~LDAPUrl(); 37 38 /** 39 * @return The part of the URL that is representing the network 40 * port 41 */ 42 int getPort() const; 43 44 /** 45 * Set the port value of the URL 46 * @param dn The port value 47 */ 48 void setPort(int port); 49 50 /** 51 * @return The scope part of the URL is returned. 52 */ 53 int getScope() const; 54 55 /** 56 * Set the Scope part of the URL 57 * @param scope The new scope 58 */ 59 void setScope(const std::string& scope); 60 61 /** 62 * @return The complete URL as a string 63 */ 64 const std::string& getURLString() const; 65 66 /** 67 * Set the URL member attribute 68 * @param url The URL String 69 */ 70 void setURLString(const std::string &url); 71 72 /** 73 * @return The hostname or IP-Address of the destination host. 74 */ 75 const std::string& getHost() const; 76 77 /** 78 * Set the Host part of the URL 79 * @param host The new host part 80 */ 81 void setHost( const std::string &host); 82 83 /** 84 * @return The Protocol Scheme of the URL. 85 */ 86 const std::string& getScheme() const; 87 88 /** 89 * Set the Protocol Scheme of the URL 90 * @param host The Protcol scheme. Allowed values are 91 * ldap,ldapi,ldaps and cldap 92 */ 93 void setScheme( const std::string &scheme ); 94 95 /** 96 * @return The Base-DN part of the URL 97 */ 98 const std::string& getDN() const; 99 100 /** 101 * Set the DN part of the URL 102 * @param dn The new DN part 103 */ 104 void setDN( const std::string &dn); 105 106 107 /** 108 * @return The Filter part of the URL 109 */ 110 const std::string& getFilter() const; 111 112 /** 113 * Set the Filter part of the URL 114 * @param filter The new Filter 115 */ 116 void setFilter( const std::string &filter); 117 118 /** 119 * @return The List of attributes that was in the URL 120 */ 121 const StringList& getAttrs() const; 122 123 /** 124 * Set the Attributes part of the URL 125 * @param attrs StringList constaining the List of Attributes 126 */ 127 void setAttrs( const StringList &attrs); 128 void setExtensions( const StringList &ext); 129 const StringList& getExtensions() const; 130 131 /** 132 * Percent-decode a string 133 * @param src The string that is to be decoded 134 * @param dest The decoded result string 135 */ 136 void percentDecode( const std::string& src, std::string& dest ); 137 138 /** 139 * Percent-encoded a string 140 * @param src The string that is to be encoded 141 * @param dest The encoded result string 142 * @param flags 143 */ 144 std::string& percentEncode( const std::string& src, 145 std::string& dest, 146 int flags=0 ) const; 147 148 protected : 149 /** 150 * Split the url string that is associated with this Object into 151 * it components. The compontens of the URL can be access via the 152 * get...() methods. 153 * (this function is mostly for internal use and gets called 154 * automatically whenever necessary) 155 */ 156 void parseUrl(); 157 158 /** 159 * Generate an URL string from the components that were set with 160 * the various set...() methods 161 * (this function is mostly for internal use and gets called 162 * automatically whenever necessary) 163 */ 164 void components2Url() const; 165 166 void string2list(const std::string &src, StringList& sl, 167 bool percentDecode=false); 168 169 protected : 170 mutable bool regenerate; 171 int m_Port; 172 int m_Scope; 173 std::string m_Host; 174 std::string m_DN; 175 std::string m_Filter; 176 StringList m_Attrs; 177 StringList m_Extensions; 178 mutable std::string m_urlString; 179 std::string m_Scheme; 180 enum mode { base, attrs, scope, filter, extensions }; 181}; 182 183/// @cond 184struct code2string_s { 185 int code; 186 const char* string; 187}; 188/// @endcond 189 190class LDAPUrlException { 191 public : 192 LDAPUrlException(int code, const std::string &msg="" ); 193 194 int getCode() const; 195 const std::string getErrorMessage() const; 196 const std::string getAdditionalInfo() const; 197 198 static const int INVALID_SCHEME = 1; 199 static const int INVALID_PORT = 2; 200 static const int INVALID_SCOPE = 3; 201 static const int INVALID_URL = 4; 202 static const int URL_DECODING_ERROR = 5; 203 static const code2string_s code2string[]; 204 205 private: 206 int m_code; 207 std::string m_addMsg; 208}; 209#endif //LDAP_URL_H 210