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;
56 int maxi = attribute_size() + 1;
57 char** attributes = NULL;
60 attributes = new char* [maxi];
63 for(const_attribute_iterator ii = attribute_begin(), maxii = attribute_end(); ii != maxii; ii ++)
64 attributes [i ++] = const_cast <char*>(attribute(ii).c_str());
66 attributes [i] = NULL;
69 result = ldap_search(ldap, a_base.c_str(), scope, asCString(a_filter), attributes, a_onlyType);
71 string msg("ldap::Search::send | Scope: ");
72 msg += functions::asString(scope);
75 msg += " | Attributes: ";
77 if(attributes != NULL) {
78 for(int ii = 0; attributes [ii] != NULL; ii ++) {
79 msg += attributes [ii];
84 Logger::debug(msg, ANNA_FILE_LOCATION);
91 string Search::asString() const
93 string result("ldap::Search { ");
94 result += Request::asString();
95 result += " | Base: ";
97 result += " | Scope: ";
98 result += Scope::asText(a_scope);
99 result += " | Filter: ";
100 result += asText(a_filter);
101 result += functions::asText(" | OnlyType: ", a_onlyType);
102 result += functions::asText(" | SizeLimit: ", a_sizeLimit);
103 return result += " }";
106 xml::Node* Search::asXML(xml::Node* parent) const
108 parent = Request::asXML(parent);
109 parent->createAttribute("Base", a_base);
110 parent->createAttribute("Scope", Scope::asText(a_scope));
111 parent->createAttribute("Filter", asText(a_filter));
112 parent->createAttribute("OnlyType", functions::asString(a_onlyType));
113 parent->createAttribute("SizeLimit", a_sizeLimit);