• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
ldapurl.cpp
1 /*
2  This file is part of libtdeabc.
3  Copyright (c) 2004 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 #include <kdebug.h>
22 #include <tqstringlist.h>
23 #include <tqdir.h>
24 
25 #include "ldapurl.h"
26 
27 using namespace TDEABC;
28 
29 LDAPUrl::LDAPUrl()
30 {
31  m_scope = Base;
32 }
33 
34 LDAPUrl::LDAPUrl(const KURL &_url)
35  : KURL(_url), m_extensions()
36 {
37  m_dn = path();
38  if ( !TQDir::isRelativePath(m_dn) )
39 #ifdef Q_WS_WIN
40  m_dn.remove(0,3); // e.g. "c:/"
41 #else
42  m_dn.remove(0,1);
43 #endif
44  parseQuery();
45 }
46 
47 void LDAPUrl::setDn( const TQString &dn)
48 {
49  m_dn = dn;
50  if ( !TQDir::isRelativePath(m_dn) )
51 #ifdef Q_WS_WIN
52  m_dn.remove(0,3); // e.g. "c:/"
53 #else
54  m_dn.remove(0,1);
55 #endif
56  setPath(m_dn);
57 }
58 
59 bool LDAPUrl::hasExtension( const TQString &key ) const
60 {
61  return m_extensions.contains( key );
62 }
63 
64 LDAPUrl::Extension LDAPUrl::extension( const TQString &key ) const
65 {
66  TQMap<TQString, Extension>::const_iterator it;
67 
68  it = m_extensions.find( key );
69  if ( it != m_extensions.constEnd() )
70  return (*it);
71  else {
72  Extension ext;
73  ext.value = "";
74  ext.critical = false;
75  return ext;
76  }
77 }
78 
79 TQString LDAPUrl::extension( const TQString &key, bool &critical ) const
80 {
81  Extension ext;
82 
83  ext = extension( key );
84  critical = ext.critical;
85  return ext.value;
86 }
87 
88 void LDAPUrl::setExtension( const TQString &key, const LDAPUrl::Extension &ext )
89 {
90  m_extensions[ key ] = ext;
91  updateQuery();
92 }
93 
94 void LDAPUrl::setExtension( const TQString &key, const TQString &value, bool critical )
95 {
96  Extension ext;
97  ext.value = value;
98  ext.critical = critical;
99  setExtension( key, ext );
100 }
101 
102 void LDAPUrl::removeExtension( const TQString &key )
103 {
104  m_extensions.remove( key );
105  updateQuery();
106 }
107 
108 void LDAPUrl::updateQuery()
109 {
110  Extension ext;
111  TQMap<TQString, Extension>::iterator it;
112  TQString q = "?";
113 
114  // set the attributes to query
115  if ( m_attributes.count() > 0 ) q += m_attributes.join(",");
116 
117  // set the scope
118  q += "?";
119  switch( m_scope ) {
120  case Sub:
121  q += "sub";
122  break;
123  case One:
124  q += "one";
125  break;
126  case Base:
127  q += "base";
128  break;
129  }
130 
131  // set the filter
132  q += "?";
133  if ( m_filter != "(objectClass=*)" && !m_filter.isEmpty() )
134  q += m_filter;
135 
136  // set the extensions
137  q += "?";
138  for ( it = m_extensions.begin(); it != m_extensions.end(); ++it ) {
139  if ( it.data().critical ) q += "!";
140  q += it.key();
141  if ( !it.data().value.isEmpty() )
142  q += "=" + it.data().value;
143  q += ",";
144  }
145  while ( q.endsWith("?") || q.endsWith(",") )
146  q.remove( q.length() - 1, 1 );
147 
148  setQuery(q);
149  kdDebug(5700) << "LDAP URL updateQuery(): " << prettyURL() << endl;
150 }
151 
152 void LDAPUrl::parseQuery()
153 {
154  Extension ext;
155  TQStringList extensions;
156  TQString q = query();
157  // remove first ?
158  if (q.startsWith("?"))
159  q.remove(0,1);
160 
161  // split into a list
162  TQStringList url_items = TQStringList::split("?", q, true);
163 
164  m_attributes.clear();
165  m_scope = Base;
166  m_filter = "(objectClass=*)";
167  m_extensions.clear();
168 
169  int i = 0;
170  for ( TQStringList::Iterator it = url_items.begin(); it != url_items.end(); ++it, i++ ) {
171  switch (i) {
172  case 0:
173  m_attributes = TQStringList::split(",", (*it), false);
174  break;
175  case 1:
176  if ( (*it) == "sub" ) m_scope = Sub; else
177  if ( (*it) == "one") m_scope = One;
178  break;
179  case 2:
180  m_filter = decode_string( *it );
181  break;
182  case 3:
183  extensions = TQStringList::split(",", (*it), false);
184  break;
185  }
186  }
187 
188  TQString name,value;
189  for ( TQStringList::Iterator it = extensions.begin(); it != extensions.end(); ++it ) {
190  ext.critical = false;
191  name = decode_string( (*it).section('=',0,0) ).lower();
192  value = decode_string( (*it).section('=',1) );
193  if ( name.startsWith("!") ) {
194  ext.critical = true;
195  name.remove(0, 1);
196  }
197  kdDebug(5700) << "LDAPUrl extensions name= " << name << " value: " << value << endl;
198  ext.value = value.replace( "%2", "," );
199  setExtension( name, ext );
200  }
201 }
KURL::setQuery
void setQuery(const TQString &_txt, int encoding_hint=0)
KURL
KURL::query
TQString query() const
kdDebug
kdbgstream kdDebug(int area=0)
TDEABC::LDAPUrl::setExtension
void setExtension(const TQString &key, const Extension &ext)
Sets the specified extension key with the value and criticality in ext.
Definition: ldapurl.cpp:88
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEABC::LDAPUrl::hasExtension
bool hasExtension(const TQString &key) const
Returns if the specified extension exists in the LDAP Url.
Definition: ldapurl.cpp:59
KURL::setPath
void setPath(const TQString &path)
TDEABC::LDAPUrl::dn
const TQString & dn() const
Returns the dn part of the LDAP Url (same as path(), but slash removed from the beginning).
Definition: ldapurl.h:62
KURL::decode_string
static TQString decode_string(const TQString &str, int encoding_hint=0)
TDEABC::LDAPUrl::extension
Extension extension(const TQString &key) const
Returns the specified extension.
Definition: ldapurl.cpp:64
KURL::path
TQString path() const
TDEABC::LDAPUrl::removeExtension
void removeExtension(const TQString &key)
Removes the specified extension.
Definition: ldapurl.cpp:102
endl
kndbgstream & endl(kndbgstream &s)
TDEABC::LDAPUrl::updateQuery
void updateQuery()
Updates the query component from the attributes, scope, filter and extensions.
Definition: ldapurl.cpp:108
TDEABC::LDAPUrl::LDAPUrl
LDAPUrl()
Constructs an empty KLDAPUrl.
Definition: ldapurl.cpp:29
TDEStdAccel::name
TQString name(StdAccel id)
TDEABC::LDAPUrl::setDn
void setDn(const TQString &dn)
Sets the the dn part of the LDAP Url.
Definition: ldapurl.cpp:47
KURL::prettyURL
TQString prettyURL(int _trailing=0) const

tdeabc

Skip menu "tdeabc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.8.8
This website is maintained by Timothy Pearson.