1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
12 #include <anna/core/functions.hpp>
14 #include <anna/ldap/ResultCode.hpp>
15 #include <anna/ldap/Session.hpp>
19 #define DoErrorCode(methodName,macroName) \
20 bool anna::ldap::ResultCode::methodName () const \
23 return a_value == (macroName); \
26 DoErrorCode(isOperationsError, LDAP_OPERATIONS_ERROR)
27 DoErrorCode(isInvalidCredential, LDAP_INVALID_CREDENTIALS)
28 DoErrorCode(isProtocolError, LDAP_PROTOCOL_ERROR)
29 DoErrorCode(isTimeLimitExceeded, LDAP_TIMELIMIT_EXCEEDED)
30 DoErrorCode(isSizeLimitExceeded, LDAP_SIZELIMIT_EXCEEDED)
31 DoErrorCode(isAuthMethodNotSupported, LDAP_AUTH_METHOD_NOT_SUPPORTED)
32 DoErrorCode(isStrongAuthRequired, LDAP_STRONG_AUTH_REQUIRED)
33 DoErrorCode(isSASLBindInProgress, LDAP_SASL_BIND_IN_PROGRESS)
34 DoErrorCode(isTimeout, LDAP_TIMEOUT)
35 DoErrorCode(isUnavailable, LDAP_UNAVAILABLE)
36 DoErrorCode(isServerDown, LDAP_SERVER_DOWN)
37 DoErrorCode(isLocalError, LDAP_LOCAL_ERROR)
38 DoErrorCode(isDecodingError, LDAP_DECODING_ERROR)
39 DoErrorCode(isFilterError, LDAP_FILTER_ERROR)
40 DoErrorCode(isConnectError, LDAP_CONNECT_ERROR)
42 #define DoErrorRange(methodName,rangeName) \
43 bool anna::ldap::ResultCode::methodName () const \
46 return rangeName (a_value) != 0; \
49 DoErrorRange(isAttrError, LDAP_ATTR_ERROR)
50 DoErrorRange(isNameError, LDAP_NAME_ERROR)
51 DoErrorRange(isSecurityError, LDAP_SECURITY_ERROR)
52 DoErrorRange(isServiceError, LDAP_SERVICE_ERROR)
54 anna::ldap::ResultCode::ResultCode(const int ldap_method_result) :
55 a_value(ldap_method_result) {
56 if(ldap_method_result != LDAP_SUCCESS) {
57 const char* text = ldap_err2string(ldap_method_result);
58 a_text = (text == NULL) ? "<undefined>" : text;
64 * Al invocar a un método que devuelva el resultado y además haya que pasar una variable
65 * donde contener el error pasaremos ldap::ResultCode::extraError, para que vuelve ahí el
67 + Una vez hecho eso, el código de error "real" será el máximo de los dos. Por es posible
68 * que el método invicado devuelva 0, pero indique el código de error el extraError.
70 anna::ldap::ResultCode& anna::ldap::ResultCode::operator= (const int ldap_method_result)
72 if((a_value = ldap_method_result) != LDAP_SUCCESS) {
73 const char* text = ldap_err2string(ldap_method_result);
74 a_text = (text == NULL) ? "<undefined>" : text;
80 void anna::ldap::ResultCode::setValue(const int ldap_method_result, const int ldap_method_error)
82 if(ldap_method_result != LDAP_SUCCESS)
83 operator= (ldap_method_result);
85 operator= (ldap_method_error);
88 const string anna::ldap::ResultCode::asString() const
90 string result(functions::asText("ldap::ResultCode { Value: ", a_value));
92 if(a_text.empty() == false) {
93 result += " | Text: ";
97 return result += " }";
100 bool anna::ldap::ResultCode::extractResultCode(const Session* session)
102 LDAP* handle = (LDAP*)((Session*) session)->getLDAP();
105 if(ldap_get_option(handle, LDAP_OPT_RESULT_CODE, &result) == LDAP_OPT_SUCCESS) {