• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.14
  • kdepim
  • libkdepim
  • ldap
ldapqueryjob.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3  Author: Volker Krause <volker.krause@kdab.com>
4 
5  This library is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or (at your
8  option) any later version.
9 
10  This library is distributed in the hope that it will be useful, but WITHOUT
11  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  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 the
17  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  02110-1301, USA.
19 */
20 
21 #include "ldapqueryjob.h"
22 
23 #include <kldap/ldif.h>
24 #include <kldap/ldapcontrol.h>
25 #include <kldap/ldapdefs.h>
26 #include <kldap/ldapconnection.h>
27 #include <kldap/ldapdn.h>
28 
29 #include <KDebug>
30 
31 using namespace KLDAP;
32 
33 LdapQueryJob::LdapQueryJob( const LdapUrl& url, LdapSession* session ) :
34  KJob( 0 ), // to not break moveToThread
35  m_url( url ),
36  m_session( session )
37 {
38  setAutoDelete( false ); // auto-deletion is bad in combination with cross-thread queued connections
39 }
40 
41 void LdapQueryJob::triggerStart()
42 {
43  start();
44 }
45 
46 void LdapQueryJob::start()
47 {
48  kDebug();
49  m_op.setConnection( m_session->connection() );
50 
51  LdapControls serverctrls, clientctrls;
52  if ( m_session->server().pageSize() ) {
53  LdapControls ctrls = serverctrls;
54  ctrls.append( LdapControl::createPageControl( m_session->server().pageSize() ) );
55  kDebug() << "page size: " << m_session->server().pageSize();
56  m_op.setServerControls( ctrls );
57  } else {
58  m_op.setServerControls( serverctrls );
59  }
60  m_op.setClientControls( clientctrls );
61 
62  int ret, id;
63  if ( (id = m_op.search( m_url.dn(), m_url.scope(), m_url.filter(), m_url.attributes() )) == -1 ) {
64 // LDAPErr();
65  return;
66  }
67 
68  QByteArray result;
69  while( true ) {
70  ret = m_op.waitForResult( id, -1 );
71  if ( ret == -1 || m_session->connection().ldapErrorCode() != KLDAP_SUCCESS ) {
72 // LDAPErr();
73  return;
74  }
75  kDebug() << " ldap_result: " << ret;
76  if ( ret == LdapOperation::RES_SEARCH_RESULT ) {
77 
78  if ( m_session->server().pageSize() ) {
79  QByteArray cookie;
80  int estsize = -1;
81  for ( int i = 0; i < m_op.controls().count(); ++i ) {
82  kDebug() << " control oid: " << m_op.controls()[i].oid();
83  estsize = m_op.controls()[i].parsePageControl( cookie );
84  if ( estsize != -1 ) break;
85  }
86  kDebug() << " estimated size: " << estsize;
87  if ( estsize != -1 && !cookie.isEmpty() ) {
88  LdapControls ctrls;
89  ctrls = serverctrls;
90  kDebug() << "page size: " << m_session->server().pageSize() << " estimated size: " << estsize;
91  ctrls.append( LdapControl::createPageControl( m_session->server().pageSize(), cookie ) );
92  m_op.setServerControls( ctrls );
93  if ( (id = m_op.search( m_url.dn(), m_url.scope(), m_url.filter(), m_url.attributes() )) == -1 ) {
94 // LDAPErr();
95  return;
96  }
97  continue;
98  }
99  }
100  break;
101  }
102  if ( ret != LdapOperation::RES_SEARCH_ENTRY ) continue;
103 
104  QByteArray entry = m_op.object().toString().toUtf8() + '\n';
105  emit data(entry);
106  }
107 
108  emit data( QByteArray() );
109  emitResult();
110 }
111 
112 
KLDAP::LdapQueryJob::LdapQueryJob
LdapQueryJob(const LdapUrl &url, LdapSession *session)
Definition: ldapqueryjob.cpp:33
QByteArray
QByteArray::isEmpty
bool isEmpty() const
KLDAP::LdapSession::server
LdapServer server() const
Definition: ldapsession.cpp:142
KLDAP::LdapSession
Definition: ldapsession.h:37
KLDAP::LdapSession::connection
LdapConnection & connection()
Definition: ldapsession.cpp:147
KLDAP::LdapQueryJob::data
void data(const QByteArray &data)
KLDAP::LdapQueryJob::triggerStart
void triggerStart()
Definition: ldapqueryjob.cpp:41
KLDAP::LdapQueryJob::start
void start()
Definition: ldapqueryjob.cpp:46
KJob
ldapqueryjob.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal