1// $OpenLDAP$
2/*
3 * Copyright 2000-2011 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5 */
6
7
8#ifndef LDAP_CONTROL_H
9#define LDAP_CONTROL_H
10#include <string>
11#include <ldap.h>
12
13/**
14 * This class is used to store Controls. Controls are a mechanism to extend
15 * and modify LDAP-Operations.
16 */
17class LDAPCtrl{
18    public :
19        /**
20         * Constructor.
21         * @param oid:  The Object Identifier of the Control
22         * @param critical: "true" if the Control should be handled
23         *                  critical by the server.
24         * @param data: If there is data for the control, put it here.
25         * @param length: The length of the data field
26         */
27        LDAPCtrl(const char *oid, bool critical=false, const char *data=0,
28                int length=0);
29
30        /**
31         * Constructor.
32         * @param oid:  The Object Identifier of the Control
33         * @param critical: "true" if the Control should be handled
34         *                  critical by the server.
35         * @param data: If there is data for the control, put it here.
36         */
37        LDAPCtrl(const std::string& oid, bool critical,
38                 const std::string& data);
39
40        /**
41         * Creates a copy of the Control that "ctrl is pointing to
42         */
43        LDAPCtrl(const LDAPControl* ctrl);
44
45        /**
46         * Destructor
47         */
48        ~LDAPCtrl();
49
50        /**
51         * @return The OID of the control
52         */
53        std::string getOID() const;
54
55        /**
56         * @return true if there is no "Control Value" (there is a
57         * difference between no and an empty control value)
58         */
59        bool hasData() const;
60
61        /**
62         * @return The Data of the control as a std::string-Object
63         */
64        std::string getData() const;
65
66        /**
67         * @return "true" if the control is critical
68         */
69        bool isCritical() const;
70
71        /**
72         * For internal use only.
73         *
74         * Translates the control to a LDAPControl-structure as needed by
75         * the C-API
76         */
77        LDAPControl* getControlStruct() const;
78	static void freeLDAPControlStruct(LDAPControl *ctrl);
79
80    private :
81        std::string m_oid;
82        std::string m_data;
83        bool m_isCritical;
84        bool m_noData;
85};
86
87#endif //LDAP_CONTROL_H
88