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>
13 #include <anna/core/tracing/Logger.hpp>
15 #include <anna/xml/Node.hpp>
17 #include <anna/ldap/Search.hpp>
18 #include <anna/ldap/Session.hpp>
22 using namespace anna::ldap;
24 Search::attribute_pool Search::st_attributes;
29 a_scope = Scope::Base;
36 void Search::clearAttributes()
38 for(attribute_iterator ii = attribute_begin(), maxii = attribute_end(); ii != maxii; ii ++)
39 st_attributes.release(&attribute(ii));
44 IdMessage Search::send(Session& session) const
47 LDAP* ldap = (LDAP*) session.getLDAP();
51 case Scope::Base: scope = LDAP_SCOPE_BASE; break;
52 case Scope::OneLevel: scope = LDAP_SCOPE_ONELEVEL; break;
53 case Scope::SubTree: scope = LDAP_SCOPE_SUBTREE; break;
54 case Scope::None: return result; break;
57 int maxi = attribute_size() + 1;
58 char** attributes = NULL;
61 attributes = new char* [maxi];
64 for(const_attribute_iterator ii = attribute_begin(), maxii = attribute_end(); ii != maxii; ii ++)
65 attributes [i ++] = const_cast <char*>(attribute(ii).c_str());
67 attributes [i] = NULL;
70 result = ldap_search(ldap, a_base.c_str(), scope, asCString(a_filter), attributes, a_onlyType);
72 string msg("ldap::Search::send | Scope: ");
73 msg += functions::asString(scope);
76 msg += " | Attributes: ";
78 if(attributes != NULL) {
79 for(int ii = 0; attributes [ii] != NULL; ii ++) {
80 msg += attributes [ii];
85 Logger::debug(msg, ANNA_FILE_LOCATION);
92 string Search::asString() const
94 string result("ldap::Search { ");
95 result += Request::asString();
96 result += " | Base: ";
98 result += " | Scope: ";
99 result += Scope::asText(a_scope);
100 result += " | Filter: ";
101 result += asText(a_filter);
102 result += functions::asText(" | OnlyType: ", a_onlyType);
103 result += functions::asText(" | SizeLimit: ", a_sizeLimit);
104 return result += " }";
107 xml::Node* Search::asXML(xml::Node* parent) const
109 parent = Request::asXML(parent);
110 parent->createAttribute("Base", a_base);
111 parent->createAttribute("Scope", Scope::asText(a_scope));
112 parent->createAttribute("Filter", asText(a_filter));
113 parent->createAttribute("OnlyType", functions::asString(a_onlyType));
114 parent->createAttribute("SizeLimit", a_sizeLimit);