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