1 | /* |
2 | This file is part of libkldap. |
3 | Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef KLDAP_LDAPURL_H |
22 | #define KLDAP_LDAPURL_H |
23 | |
24 | #include <QtCore/QMap> |
25 | #include <QtCore/QStringList> |
26 | |
27 | #include <kurl.h> |
28 | |
29 | #include "ldapdn.h" |
30 | #include "kldap_export.h" |
31 | |
32 | namespace KLDAP { |
33 | |
34 | /** |
35 | * @short A special url class for LDAP. |
36 | * |
37 | * LdapUrl implements an RFC 2255 compliant LDAP Url parser, with minimal |
38 | * differences. LDAP Urls implemented by this class has the following format: |
39 | * ldap[s]://[user[:password]@]hostname[:port]["/" [dn ["?" [attributes] |
40 | * ["?" [scope] ["?" [filter] ["?" extensions]]]]]] |
41 | */ |
42 | class KLDAP_EXPORT LdapUrl : public KUrl |
43 | { |
44 | public: |
45 | |
46 | /** |
47 | * A class holding the extension name and state whether |
48 | * the extension is critical. |
49 | */ |
50 | typedef struct { |
51 | QString value; |
52 | bool critical; |
53 | } Extension; |
54 | |
55 | /** |
56 | * Describes the scope of the LDAP url. |
57 | */ |
58 | typedef enum { |
59 | Base, ///< Only the same level as the url. |
60 | One, ///< The level of the url and the one below. |
61 | Sub ///< All levels below the url's level. |
62 | } Scope; |
63 | |
64 | /** |
65 | * Constructs an empty LDAP url. |
66 | */ |
67 | LdapUrl(); |
68 | |
69 | /** |
70 | * Constructs a LDAP url from a KUrl @p url. |
71 | */ |
72 | explicit LdapUrl( const KUrl &url ); |
73 | |
74 | /** |
75 | * Constructs a LDAP url from an other url. |
76 | */ |
77 | LdapUrl( const LdapUrl &other ); |
78 | |
79 | /** |
80 | * Overwrites the values of the LDAP url with values |
81 | * from an @p other url. |
82 | */ |
83 | LdapUrl &operator=( const LdapUrl &other ); |
84 | |
85 | /** |
86 | * Destroys the LDAP url. |
87 | */ |
88 | virtual ~LdapUrl(); |
89 | |
90 | /** |
91 | * Sets the @p dn part of the LDAP url. |
92 | */ |
93 | void setDn( const LdapDN &dn ); |
94 | |
95 | /** |
96 | * Returns the dn part of the LDAP url. |
97 | * This is equal to path() with the slash removed from the beginning. |
98 | */ |
99 | LdapDN dn() const; |
100 | |
101 | /** |
102 | * Sets the @p attributes part of the LDAP url. |
103 | */ |
104 | void setAttributes( const QStringList &attributes ); |
105 | |
106 | /** |
107 | * Returns the attributes part of the LDAP url. |
108 | */ |
109 | QStringList attributes() const; |
110 | |
111 | /** |
112 | * Sets the scope part of the LDAP url. |
113 | */ |
114 | void setScope( Scope scope ); |
115 | |
116 | /** |
117 | * Returns the scope part of the LDAP url. |
118 | */ |
119 | Scope scope() const; |
120 | |
121 | /** |
122 | * Sets the filter part of the LDAP url. |
123 | */ |
124 | void setFilter( const QString &filter ); |
125 | |
126 | /** |
127 | * Returns the filter part of the LDAP url. |
128 | */ |
129 | QString filter() const; |
130 | |
131 | /** |
132 | * Returns whether the specified @p extension exists in the LDAP url. |
133 | */ |
134 | bool hasExtension( const QString &extension ) const; |
135 | |
136 | /** |
137 | * Returns the specified @p extension. |
138 | */ |
139 | Extension extension( const QString &extension ) const; |
140 | |
141 | /** |
142 | * Returns the specified @p extension. |
143 | */ |
144 | QString extension( const QString &extension, bool &critical ) const; |
145 | |
146 | /** |
147 | * Sets the specified extension @p key with the value and criticality in @p extension. |
148 | */ |
149 | void setExtension( const QString &key, const Extension &extension ); |
150 | |
151 | /** |
152 | * Sets the specified extension @p key with the @p value and criticality specified. |
153 | */ |
154 | void setExtension( const QString &key, const QString &value, bool critical = false ); |
155 | |
156 | /** |
157 | * Sets the specified extension @p key with the @p value and criticality specified. |
158 | */ |
159 | void setExtension( const QString &key, int value, bool critical = false ); |
160 | |
161 | /** |
162 | * Removes the specified @p extension. |
163 | */ |
164 | void removeExtension( const QString &extension ); |
165 | |
166 | /** |
167 | * Updates the query component from the attributes, scope, filter and extensions. |
168 | */ |
169 | void updateQuery(); |
170 | |
171 | /** |
172 | * Parses the query argument of the URL and makes it available via the |
173 | * attributes(), extension(), filter() and scope() methods |
174 | */ |
175 | void parseQuery(); |
176 | |
177 | private: |
178 | class LdapUrlPrivate; |
179 | LdapUrlPrivate *const d; |
180 | }; |
181 | |
182 | } |
183 | |
184 | #endif |
185 | |