xref: /netbsd-src/external/bsd/openldap/dist/contrib/ldapc++/src/LDAPResult.h (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1 /*	$NetBSD: LDAPResult.h,v 1.3 2021/08/14 16:14:49 christos Exp $	*/
2 
3 // $OpenLDAP$
4 /*
5  * Copyright 2000-2021 The OpenLDAP Foundation, All Rights Reserved.
6  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7  */
8 
9 
10 #ifndef LDAP_RESULT_H
11 #define LDAP_RESULT_H
12 
13 #include<iostream>
14 #include<ldap.h>
15 #include <LDAPMessage.h>
16 #include <LDAPControlSet.h>
17 #include <LDAPUrlList.h>
18 
19 class LDAPRequest;
20 class LDAPAsynConnection;
21 
22 /**
23  * This class is for representing LDAP-Result-Messages.
24  *
25  * It represents all Messages that were returned
26  * from LDAP-Operations except for Messages of the Type
27  * LDAPMsg::SEARCH_ENTRY, LDAPMsg::SEARCH_REFERENCE and
28  * LDAPMsg::EXTENDED_RESPONSE. <BR>
29  * It defines a integer constant for every possible result type that can be
30  * returned by the server.
31  */
32 class LDAPResult : public LDAPMsg{
33     public :
34         //Error codes from RFC 2251
35         static const int SUCCESS                        = 0;
36         static const int OPERATIONS_ERROR               = 1;
37         static const int PROTOCOL_ERROR                 = 2;
38         static const int TIME_LIMIT_EXCEEDED            = 3;
39         static const int SIZE_LIMIT_EXCEEDED            = 4;
40         static const int COMPARE_FALSE                  = 5;
41         static const int COMPARE_TRUE                   = 6;
42         static const int AUTH_METHOD_NOT_SUPPORTED      = 7;
43         static const int STRONG_AUTH_REQUIRED           = 8;
44 
45         static const int REFERRAL                       = 10;
46         static const int ADMIN_LIMIT_EXCEEDED           = 11;
47         static const int UNAVAILABLE_CRITICAL_EXTENSION = 12;
48         static const int CONFIDENTIALITY_REQUIRED       = 13;
49         static const int SASL_BIND_IN_PROGRESS          = 14;
50 
51         static const int NO_SUCH_ATTRIBUTE              = 16;
52         static const int UNDEFINED_ATTRIBUTE_TYP        = 17;
53         static const int INAPPROPRIATE_MATCHING         = 18;
54         static const int CONSTRAINT_VIOLATION           = 19;
55         static const int ATTRIBUTE_OR_VALUE_EXISTS      = 20;
56         static const int INVALID_ATTRIBUTE_SYNTAX       = 21;
57 
58         static const int NO_SUCH_OBJECT                 = 32;
59         static const int ALIAS_PROBLEM                  = 33;
60         static const int INVALID_DN_SYNTAX              = 34;
61 
62         static const int ALIAS_DEREFERENCING_PROBLEM    = 36;
63 
64         static const int INAPPROPRIATE_AUTHENTICATION    = 48;
65         static const int INVALID_CREDENTIALS            = 49;
66         static const int INSUFFICIENT_ACCESS            = 50;
67         static const int BUSY                           = 51;
68         static const int UNAVAILABLE                    = 52;
69         static const int UNWILLING_TO_PERFORM           = 53;
70         static const int LOOP_DETECT                    = 54;
71 
72         static const int NAMING_VIOLATION               = 64;
73         static const int OBJECT_CLASS_VIOLATION         = 65;
74         static const int NOT_ALLOWED_ON_NONLEAF         = 66;
75         static const int NOT_ALLOWED_ON_RDN             = 67;
76         static const int ENTRY_ALREADY_EXISTS           = 68;
77         static const int OBJECT_CLASS_MODS_PROHIBITED   = 69;
78 
79         static const int AFFECTS_MULTIPLE_DSAS          = 71;
80 
81         // some Errorcodes defined in the LDAP C API DRAFT
82         static const int OTHER                          = 80;
83         static const int SERVER_DOWN                    = 81;
84         static const int LOCAL_ERROR                    = 82;
85         static const int ENCODING_ERROR                 = 83;
86         static const int DECODING_ERROR                 = 84;
87         static const int TIMEOUT                        = 85;
88         static const int AUTH_UNKNOWN                   = 86;
89         static const int FILTER_ERROR                   = 87;
90         static const int USER_CANCELLED                 = 88;
91         static const int PARAM_ERROR                    = 89;
92         static const int NO_MEMORY                      = 90;
93         static const int CONNECT_ERROR                  = 91;
94         static const int NOT_SUPPORTED                  = 92;
95         static const int CONTROL_NOT_FOUND              = 93;
96         static const int NO_RESULTS_RETURNED            = 94;
97         static const int MORE_RESULTS_TO_RETURN         = 95;
98         static const int CLIENT_LOOP                    = 96;
99         static const int REFERRAL_LIMIT_EXCEEDED        = 97;
100 
101         /**
102          * This constructor is called by the LDAPMsg::create method in
103          * order to parse a LDAPResult-Message
104          * @param req   The request the result is associated with.
105          * @param msg   The LDAPMessage-structure that contains the
106          *              Message.
107          */
108         LDAPResult(const LDAPRequest *req, LDAPMessage *msg);
109         LDAPResult(int type, int resultCode, const std::string &msg);
110 
111         /**
112          * The destructor.
113          */
114         virtual ~LDAPResult();
115 
116         /**
117          * @returns The result code of the Message. Possible values are the
118          *      integer constants defined in this class.
119          */
120         int getResultCode() const;
121 
122         /**
123          * This method transforms the result code to a human-readable
124          * result message.
125          * @returns A std::string containing the result message.
126          */
127         std::string resToString() const;
128 
129         /**
130          * In some case of error the server may return additional error
131          * messages.
132          * @returns The additional error message returned by the server.
133          */
134         const std::string& getErrMsg() const;
135 
136         /**
137          * For messages with a result code of: NO_SUCH_OBJECT,
138          * ALIAS_PROBLEM, ALIAS_DEREFERENCING_PROBLEM or INVALID_DN_SYNTAX
139          * the server returns the DN of deepest entry in the DIT that could
140          * be found for this operation.
141          * @returns The Matched-DN value that was returned by the server.
142          */
143         const std::string& getMatchedDN() const;
144 
145         /**
146          * @returns If the result code is REFERRAL this method returns the
147          *      URLs of the referral that was sent by the server.
148          */
149         const LDAPUrlList& getReferralUrls() const;
150 
151     private :
152         int m_resCode;
153         std::string m_matchedDN;
154         std::string m_errMsg;
155         LDAPUrlList m_referrals;
156 
157     /**
158      * This method can be used to dump the data of a LDAPResult-Object.
159      * It is only useful for debugging purposes at the moment
160      */
161     friend  std::ostream& operator<<(std::ostream &s,LDAPResult &l);
162 };
163 #endif //LDAP_RESULT_H
164 
165