2000-09-01 14:46:32 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "LDAPSearchRequest.h"
|
|
|
|
|
#include "LDAPException.h"
|
|
|
|
|
#include "LDAPSearchReference.h"
|
2000-10-03 14:25:34 -04:00
|
|
|
#include "LDAPResult.h"
|
2000-09-01 14:46:32 -04:00
|
|
|
#include "LDAPRequest.h"
|
|
|
|
|
#include "LDAPUrl.h"
|
|
|
|
|
|
|
|
|
|
LDAPSearchRequest::LDAPSearchRequest(const LDAPSearchRequest& req ) :
|
|
|
|
|
LDAPRequest (req){
|
2000-10-03 14:25:34 -04:00
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT,
|
|
|
|
|
"LDAPSearchRequest::LDAPSearchRequest(&)" << endl);
|
|
|
|
|
m_base=req.m_base;
|
|
|
|
|
m_scope=req.m_scope;
|
|
|
|
|
m_filter=req.m_filter;
|
|
|
|
|
m_attrs=req.m_attrs;
|
|
|
|
|
m_attrsOnly=req.m_attrsOnly;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
LDAPSearchRequest::LDAPSearchRequest(const string& base, int scope,
|
|
|
|
|
const string& filter, const StringList& attrs, bool attrsOnly,
|
|
|
|
|
LDAPAsynConnection *connect,
|
|
|
|
|
const LDAPConstraints* cons, bool isReferral,
|
|
|
|
|
const LDAPRequest* parent)
|
|
|
|
|
: LDAPRequest (connect,cons,isReferral,parent) {
|
2000-09-01 14:46:32 -04:00
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT,
|
|
|
|
|
"LDAPSearchRequest:LDAPSearchRequest()" << endl);
|
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT & LDAP_DEBUG_PARAMETER,
|
|
|
|
|
" base:" << base << endl << " scope:" << scope << endl
|
|
|
|
|
<< " filter:" << filter << endl);
|
2000-09-01 14:46:32 -04:00
|
|
|
m_requestType=LDAPRequest::SEARCH;
|
|
|
|
|
//insert some validating and copying here
|
2000-10-03 14:25:34 -04:00
|
|
|
m_base=base;
|
2000-09-01 14:46:32 -04:00
|
|
|
m_scope=scope;
|
2000-10-03 14:25:34 -04:00
|
|
|
if(filter == ""){
|
|
|
|
|
m_filter="objectClass=*";
|
2000-09-01 14:46:32 -04:00
|
|
|
}else{
|
2000-10-03 14:25:34 -04:00
|
|
|
m_filter=filter;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
2000-10-03 14:25:34 -04:00
|
|
|
m_attrs=attrs;
|
|
|
|
|
m_attrsOnly=attrsOnly;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LDAPSearchRequest::~LDAPSearchRequest(){
|
2000-10-03 14:25:34 -04:00
|
|
|
DEBUG(LDAP_DEBUG_DESTROY, "LDAPSearchRequest::~LDAPSearchRequest" << endl);
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LDAPMessageQueue* LDAPSearchRequest::sendRequest(){
|
|
|
|
|
int msgID;
|
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE, "LDAPSearchRequest::sendRequest()" << endl);
|
2000-10-03 14:25:34 -04:00
|
|
|
timeval* tmptime=m_cons->getTimeoutStruct();
|
|
|
|
|
char** tmpattrs=m_attrs.toCharArray();
|
|
|
|
|
LDAPControl** tmpSrvCtrl=m_cons->getSrvCtrlsArray();
|
|
|
|
|
LDAPControl** tmpClCtrl=m_cons->getClCtrlsArray();
|
|
|
|
|
int aliasDeref = m_cons->getAliasDeref();
|
|
|
|
|
ldap_set_option(m_connection->getSessionHandle(), LDAP_OPT_DEREF,
|
|
|
|
|
&aliasDeref);
|
|
|
|
|
int err=ldap_search_ext(m_connection->getSessionHandle(), m_base.c_str(),
|
|
|
|
|
m_scope, m_filter.c_str(), tmpattrs, m_attrsOnly, tmpSrvCtrl,
|
|
|
|
|
tmpClCtrl, tmptime, m_cons->getSizeLimit(), &msgID );
|
|
|
|
|
delete tmptime;
|
|
|
|
|
ldap_value_free(tmpattrs);
|
|
|
|
|
ldap_controls_free(tmpSrvCtrl);
|
|
|
|
|
ldap_controls_free(tmpClCtrl);
|
|
|
|
|
|
2000-09-01 14:46:32 -04:00
|
|
|
if (err != LDAP_SUCCESS){
|
|
|
|
|
throw LDAPException(err);
|
2000-10-03 14:25:34 -04:00
|
|
|
} else if (isReferral()){
|
|
|
|
|
m_msgID=msgID;
|
|
|
|
|
return 0;
|
|
|
|
|
}else{
|
2000-09-01 14:46:32 -04:00
|
|
|
m_msgID=msgID;
|
|
|
|
|
return new LDAPMessageQueue(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
LDAPRequest* LDAPSearchRequest::followReferral(LDAPMsg* ref){
|
2000-09-01 14:46:32 -04:00
|
|
|
DEBUG(LDAP_DEBUG_TRACE, "LDAPSearchRequest::followReferral()" << endl);
|
2000-10-03 14:25:34 -04:00
|
|
|
LDAPUrlList urls;
|
|
|
|
|
LDAPUrlList::const_iterator usedUrl;
|
|
|
|
|
LDAPAsynConnection* con;
|
|
|
|
|
string filter;
|
|
|
|
|
int scope;
|
|
|
|
|
if(ref->getMessageType() == LDAPMsg::SEARCH_REFERENCE){
|
|
|
|
|
urls = ((LDAPSearchReference *)ref)->getUrls();
|
|
|
|
|
}else{
|
|
|
|
|
urls = ((LDAPResult *)ref)->getReferralUrls();
|
|
|
|
|
}
|
|
|
|
|
con = getConnection()->referralConnect(urls,usedUrl,m_cons);
|
|
|
|
|
if(con != 0){
|
|
|
|
|
if((usedUrl->getFilter() != "") &&
|
|
|
|
|
(usedUrl->getFilter() != m_filter)){
|
|
|
|
|
filter=usedUrl->getFilter();
|
|
|
|
|
}else{
|
|
|
|
|
filter=m_filter;
|
|
|
|
|
}
|
|
|
|
|
if( (ref->getMessageType() == LDAPMsg::SEARCH_REFERENCE) &&
|
|
|
|
|
(m_scope == LDAPAsynConnection::SEARCH_ONE)
|
|
|
|
|
){
|
|
|
|
|
scope = LDAPAsynConnection::SEARCH_BASE;
|
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE," adjusted scope to BASE" << endl);
|
|
|
|
|
}else{
|
|
|
|
|
scope = m_scope;
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2000-10-03 14:25:34 -04:00
|
|
|
return new LDAPSearchRequest(usedUrl->getDN(), scope, filter,
|
|
|
|
|
m_attrs, m_attrsOnly, con, m_cons,true,this);
|
2000-09-01 14:46:32 -04:00
|
|
|
}
|
|
|
|
|
|
2000-10-03 14:25:34 -04:00
|
|
|
bool LDAPSearchRequest::equals(const LDAPRequest* req)const{
|
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPSearchRequest::equals()" << endl);
|
|
|
|
|
if( LDAPRequest::equals(req)){
|
|
|
|
|
LDAPSearchRequest* sreq = (LDAPSearchRequest*)req;
|
|
|
|
|
if ( (m_base == sreq->m_base) &&
|
|
|
|
|
(m_scope == sreq->m_scope)
|
|
|
|
|
){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|