1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_ldap_Response_hpp
38 #define anna_ldap_Response_hpp
40 #include <anna/core/util/Recycler.hpp>
41 #include <anna/core/Allocator.hpp>
43 #include <anna/ldap/defines.hpp>
44 #include <anna/ldap/ClassCode.hpp>
45 #include <anna/ldap/ResultCode.hpp>
57 Modela las respuesta que podemos recibir de un servidor LDAP.
59 La respuesta correspondiente a una peticion se genera automaticamente al invocar a ldap::Session::send.
60 El nucleo de ANNA.ldap notifica el resultado de la operacion solicitada mediante la invocacion
61 al metodo-menejador ldap::Session::eventResponse de nuestra sesion.
65 typedef Recycler<Attribute> attribute_container;
66 typedef attribute_container::iterator attribute_iterator;
67 typedef attribute_container::const_iterator const_attribute_iterator;
69 typedef Recycler<std::string> referral_container;
70 typedef referral_container::const_iterator const_referral_iterator;
73 Devuelve el tipo de la clase de esta respuesta.
74 \return El tipo de la clase de esta respuesta.
76 ClassCode::_v getClassCode() const throw() { return a_classCode; }
79 Devuelve la identificacion del mensaje LDAP.
80 Esta identificacion sera generada automaticamente al enviar la peticion.
81 \return Identificacion del mensaje asociado a esta peticion/respuesta.
82 \see ldap::Session::send
84 IdMessage getIdMessage() const throw() { return a_idMessage; }
87 Devuelve la sesion que genera esta respuesta.
88 \return La instancia de la sesion que genera esta respuesta.
90 const Session* getSession() const throw() { return a_session; }
93 Devuelve el resultado de la peticion LDAP solicitada.
94 \return El resultado de la peticion LDAP solicitada.
96 const ResultCode& getResultCode() const throw() { return a_resultCode; }
99 Devuelve el nombre del DN asociado a esta peticion.
100 \return El nombre del DN asociado a esta peticion.
102 const std::string& getName() const throw() { return a_name; }
105 Devuelve la peticion que origino la creacion de esta respuesta.
106 \return La peticion que origino la creacion de esta respuesta.
107 \see ldap::Session::send
109 const Request* getRequest()const throw() { return a_request; }
112 Devuelve la sesion que origino la creacion de esta respuesta.
113 \return La sesion que origino la creacion de esta respuesta.
115 Session* getSession() throw() { return a_session; }
118 * Devuelve el nº de atributos que contiene la respuesta.
119 * \return el nº de atributos que contiene la respuesta.
121 int attribute_size() const throw() { return a_attributes.size(); }
124 Devuelve el iterador al comienzo de la lista de atributos asociados a esta respuesta.
125 \return El iterador al comienzo de la lista de atributos asociados a esta respuesta.
127 const_attribute_iterator attribute_begin() const throw() { return a_attributes.begin(); }
130 Devuelve el iterador al final de la lista de atributos asociados a esta respuesta.
131 \return El iterador al final de la lista de atributos asociados a esta respuesta.
133 const_attribute_iterator attribute_end() const throw() { return a_attributes.end(); }
136 * Devuelve el nº de referencias que contiene la respuesta.
137 * \return el nº de referencias que contiene la respuesta.
139 int referral_size() const throw() { return a_referrals.size(); }
142 Devuelve el iterador al comienzo de la lista de referencias asociados a esta respuesta.
143 \return El iterador al comienzo de la lista de referencias asociados a esta respuesta.
145 const_referral_iterator referral_begin() const throw() { return a_referrals.begin(); }
148 Devuelve el iterador al final de la lista de referencias asociados a esta respuesta.
149 \return El iterador al final de la lista de referencias asociados a esta respuesta.
151 const_referral_iterator referral_end() const throw() { return a_referrals.end(); }
154 Devuelve el atributo asociado al iterador recibido como parametro.
155 \param ii Instancia del iterador usado para recorrer los datos. Estara comprendido
156 entre [#attribute_begin, #attribute_end).
157 \return El atributo referenciado por el iterador.
159 static const Attribute* attribute(const_attribute_iterator ii) throw() { return attribute_container::data(ii); }
162 Devuelve la referencia asociada al iterador recibido como parametro.
163 \param ii Instancia del iterador usado para recorrer los datos. Estara comprendido
164 entre [#referral_begin, #referral_end).
165 \return La referencia apuntada por el iterador.
167 static const std::string& referral(const_referral_iterator ii) throw() { return *referral_container::data(ii); }
170 Devuelve una cadena con la informacion relevante sobre esta instancia.
171 \return Una cadena con la informacion relevante sobre esta instancia.
173 std::string asString() const throw();
176 ClassCode::_v a_classCode;
177 IdMessage a_idMessage;
179 ResultCode a_resultCode;
181 attribute_container a_attributes;
182 referral_container a_referrals;
184 const Request* a_request;
186 typedef Recycler<Response> response_pool;
187 static response_pool st_responses;
191 static Response* instance(const ClassCode::_v, const IdMessage) throw(RuntimeException);
192 static void release(Response* response) throw();
194 void clear() throw();
196 void setName(const std::string& name) throw() { a_name = name; }
197 void setSession(Session* session) throw() { a_session = session; }
198 void setRequest(const Request* request) throw() { a_request = request; }
199 void activateTimer() throw(RuntimeException);
200 void cancelTimer() throw();
201 void setResultCode(const ResultCode& resultCode) throw() { a_resultCode = resultCode; }
203 Attribute* createAttribute(const std::string& name) throw(RuntimeException);
205 void createReferral(const char* value) throw(RuntimeException) {
206 std::string* newReferral = a_referrals.create();
207 *newReferral = value;
211 attribute_iterator attribute_begin() throw() { return a_attributes.begin(); }
212 attribute_iterator attribute_end() throw() { return a_attributes.end(); }
213 static Attribute* attribute(attribute_iterator ii) throw() { return attribute_container::data(ii); }
215 friend class Session;
216 friend class Allocator<Response>;