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 {
27 SASL_Authname = 0x1,
28 SASL_Authzid = 0x2,
29 SASL_Realm = 0x4,
30 SASL_Password = 0x8,
31 };
32
33 /** Constructs an LdapConnection object */
35 /** Constructs an LdapConnection with the parameters given in url */
36 explicit LdapConnection(const LdapUrl &url);
37 /** Constructs an LdapConnection with the parameters given in server */
38 explicit LdapConnection(const LdapServer &server);
39
41
42 /**
43 * Sets the connection parameters via the specified url. After this,
44 * you need to call connect() to connect with the new parameters.
45 * @param url the URL containing the connection parameters
46 */
47 void setUrl(const LdapUrl &url);
48 /**
49 * Returns the connection parameters which was specified with an LDAP Url
50 * or a LdapServer structure.
51 */
52 const LdapServer &server() const;
53 /**
54 * Sets the connection parameters via the specified server structure. After
55 * this, you need to call connect() to connect with the new parameters.
56 * @param server the server object containing the connection parameters
57 */
58 void setServer(const LdapServer &server);
59
60 /**
61 * Sets up the connection parameters with creating a handle to the LDAP server.
62 * Also sets sizelimit and timelimit and starts TLS if it is requested.
63 * Returns 0 if successful, else returns an LDAP error code, and an error
64 * string which is available via connectionError().
65 */
66 int connect();
67 /**
68 * Returns a translated error string if connect() failed.
69 */
70 [[nodiscard]] QString connectionError() const;
71 /**
72 * Closes the LDAP connection.
73 */
74 void close();
75
76 /** Sets the size limit for the connection.
77 * @param sizelimit the connection size limit to set
78 */
79 [[nodiscard]] bool setSizeLimit(int sizelimit);
80 /** Returns the current size limit. */
81 [[nodiscard]] int sizeLimit() const;
82
83 /** Sets the time limit for the connection.
84 * @param timelimit the connection time limit to set
85 */
86 [[nodiscard]] bool setTimeLimit(int timelimit);
87 /** Returns the current time limit. */
88 [[nodiscard]] int timeLimit() const;
89
90 /** Gets an option from the connection. The option value can be client
91 * library specific, so avoid this function if possible
92 * @param option the connection option to return
93 * @param value the value of option to get
94 */
95 [[nodiscard]] int getOption(int option, void *value) const;
96 /** Sets an option in the connection. The option value can be client
97 * library specific, so avoid this function if possible */
98 int setOption(int option, void *value);
99
100 /** Returns the LDAP error code from the last operation */
101 [[nodiscard]] int ldapErrorCode() const;
102 /** Returns the LDAP error string from the last operation */
103 [[nodiscard]] QString ldapErrorString() const;
104 /** Returns a translated error message from the specified LDAP error code */
105 [[nodiscard]] static QString errorString(int code);
106
107 /** Returns the SASL error string from the last SASL operation */
108 [[nodiscard]] QString saslErrorString() const;
109
110 /**
111 * Returns the opaqe client-library specific LDAP object.
112 * Avoid its usage if you can.
113 */
114 void *handle() const;
115
116 /**
117 * Returns the opaqe sasl-library specific SASL object.
118 * Avoid its usage if you can.
119 */
120 void *saslHandle() const;
121
122private:
123 class LdapConnectionPrivate;
124 std::unique_ptr<LdapConnectionPrivate> const d;
125
126 Q_DISABLE_COPY(LdapConnection)
127};
128}
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 Mon Nov 18 2024 12:16:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.