KLdap

ldapconnection.h
1/*
2 This file is part of libkldap.
3 SPDX-FileCopyrightText: 2004-2006 Szombathelyi György <gyurco@freemail.hu>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include <QString>
11#include <memory>
12
13#include "kldap_core_export.h"
14#include "ldapserver.h"
15#include "ldapurl.h"
16
17namespace KLDAPCore
18{
19/**
20 * @brief
21 * This class represents a connection to an LDAP server.
22 */
23class KLDAP_CORE_EXPORT LdapConnection
24{
25public:
26 enum SASL_Fields { SASL_Authname = 0x1, SASL_Authzid = 0x2, SASL_Realm = 0x4, SASL_Password = 0x8 };
27
28 /** Constructs an LdapConnection object */
30 /** Constructs an LdapConnection with the parameters given in url */
31 explicit LdapConnection(const LdapUrl &url);
32 /** Constructs an LdapConnection with the parameters given in server */
33 explicit LdapConnection(const LdapServer &server);
34
36
37 /**
38 * Sets the connection parameters via the specified url. After this,
39 * you need to call connect() to connect with the new parameters.
40 * @param url the URL containing the connection parameters
41 */
42 void setUrl(const LdapUrl &url);
43 /**
44 * Returns the connection parameters which was specified with an LDAP Url
45 * or a LdapServer structure.
46 */
47 const LdapServer &server() const;
48 /**
49 * Sets the connection parameters via the specified server structure. After
50 * this, you need to call connect() to connect with the new parameters.
51 * @param server the server object containing the connection parameters
52 */
53 void setServer(const LdapServer &server);
54
55 /**
56 * Sets up the connection parameters with creating a handle to the LDAP server.
57 * Also sets sizelimit and timelimit and starts TLS if it is requested.
58 * Returns 0 if successful, else returns an LDAP error code, and an error
59 * string which is available via connectionError().
60 */
61 int connect();
62 /**
63 * Returns a translated error string if connect() failed.
64 */
65 [[nodiscard]] QString connectionError() const;
66 /**
67 * Closes the LDAP connection.
68 */
69 void close();
70
71 /** Sets the size limit for the connection.
72 * @param sizelimit the connection size limit to set
73 */
74 [[nodiscard]] bool setSizeLimit(int sizelimit);
75 /** Returns the current size limit. */
76 [[nodiscard]] int sizeLimit() const;
77
78 /** Sets the time limit for the connection.
79 * @param timelimit the connection time limit to set
80 */
81 [[nodiscard]] bool setTimeLimit(int timelimit);
82 /** Returns the current time limit. */
83 [[nodiscard]] int timeLimit() const;
84
85 /** Gets an option from the connection. The option value can be client
86 * library specific, so avoid this function if possible
87 * @param option the connection option to return
88 * @param value the value of option to get
89 */
90 int getOption(int option, void *value) const;
91 /** Sets an option in the connection. The option value can be client
92 * library specific, so avoid this function if possible */
93 int setOption(int option, void *value);
94
95 /** Returns the LDAP error code from the last operation */
96 [[nodiscard]] int ldapErrorCode() const;
97 /** Returns the LDAP error string from the last operation */
98 [[nodiscard]] QString ldapErrorString() const;
99 /** Returns a translated error message from the specified LDAP error code */
100 [[nodiscard]] static QString errorString(int code);
101
102 /** Returns the SASL error string from the last SASL operation */
103 [[nodiscard]] QString saslErrorString() const;
104
105 /**
106 * Returns the opaqe client-library specific LDAP object.
107 * Avoid its usage if you can.
108 */
109 void *handle() const;
110
111 /**
112 * Returns the opaqe sasl-library specific SASL object.
113 * Avoid its usage if you can.
114 */
115 void *saslHandle() const;
116
117private:
118 class LdapConnectionPrivate;
119 std::unique_ptr<LdapConnectionPrivate> const d;
120
121 Q_DISABLE_COPY(LdapConnection)
122};
123}
This class represents a connection to an LDAP server.
A class that contains LDAP server connection settings.
Definition ldapserver.h:27
A special url class for LDAP.
Definition ldapurl.h:30
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.