1 // $OpenLDAP$
2 /*
3 * Copyright 2000-2021 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5 */
6
7
8 #include "debug.h"
9 #include "LDAPRequest.h"
10
11 using namespace std;
12
LDAPRequest()13 LDAPRequest::LDAPRequest(){
14 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest()" << endl);
15 }
16
LDAPRequest(const LDAPRequest & req)17 LDAPRequest::LDAPRequest(const LDAPRequest& req){
18 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest(&)" << endl);
19 m_isReferral=req.m_isReferral;
20 m_cons = new LDAPConstraints(*(req.m_cons));
21 m_connection = req.m_connection;
22 m_parent = req.m_parent;
23 m_hopCount = req.m_hopCount;
24 m_msgID = req.m_msgID;
25 }
26
LDAPRequest(LDAPAsynConnection * con,const LDAPConstraints * cons,bool isReferral,const LDAPRequest * parent)27 LDAPRequest::LDAPRequest(LDAPAsynConnection* con,
28 const LDAPConstraints* cons,bool isReferral, const LDAPRequest* parent){
29 DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRequest::LDAPRequest()" << endl);
30 m_connection=con;
31 if(cons == 0){
32 m_cons=new LDAPConstraints( *(con->getConstraints()) );
33 }else{
34 m_cons=new LDAPConstraints( *cons);
35 }
36 m_isReferral=isReferral;
37 if(m_isReferral){
38 m_hopCount = (parent->getHopCount()+1);
39 m_parent= parent;
40 }else{
41 m_hopCount=0;
42 m_parent=0;
43 }
44 }
45
~LDAPRequest()46 LDAPRequest::~LDAPRequest(){
47 DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::~LDAPRequest()" << endl);
48 delete m_cons;
49 }
50
getNextMessage() const51 LDAPMsg* LDAPRequest::getNextMessage() const
52 {
53 DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::getNextMessage()" << endl);
54 int res;
55 LDAPMessage *msg;
56
57 res=ldap_result(this->m_connection->getSessionHandle(),
58 this->m_msgID,0,0,&msg);
59
60 if (res <= 0){
61 if(msg != 0){
62 ldap_msgfree(msg);
63 }
64 throw LDAPException(this->m_connection);
65 }else{
66 LDAPMsg *ret=0;
67 //this can throw an exception (Decoding Error)
68 ret = LDAPMsg::create(this,msg);
69 ldap_msgfree(msg);
70 return ret;
71 }
72 }
73
followReferral(LDAPMsg *)74 LDAPRequest* LDAPRequest::followReferral(LDAPMsg* /*urls*/){
75 DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::followReferral()" << endl);
76 DEBUG(LDAP_DEBUG_TRACE,
77 "ReferralChasing not implemented for this operation" << endl);
78 return 0;
79 }
80
getConstraints() const81 const LDAPConstraints* LDAPRequest::getConstraints() const{
82 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConstraints()" << endl);
83 return m_cons;
84 }
85
getConnection() const86 const LDAPAsynConnection* LDAPRequest::getConnection() const{
87 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConnection()" << endl);
88 return m_connection;
89 }
90
getType() const91 int LDAPRequest::getType() const {
92 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getType()" << endl);
93 return m_requestType;
94 }
95
getMsgID() const96 int LDAPRequest::getMsgID() const {
97 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getMsgId()" << endl);
98 return m_msgID;
99 }
100
getHopCount() const101 int LDAPRequest::getHopCount() const {
102 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getHopCount()" << endl);
103 return m_hopCount;
104 }
105
getParent() const106 const LDAPRequest* LDAPRequest::getParent() const{
107 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getParent()" << endl);
108 return m_parent;
109 }
110
isReferral() const111 bool LDAPRequest::isReferral() const {
112 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isReferral()" << endl);
113 return m_isReferral;
114 }
115
equals(const LDAPRequest * req) const116 bool LDAPRequest::equals(const LDAPRequest* req) const{
117 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::equals()" << endl);
118 if( (this->m_requestType == req->getType()) &&
119 (this->m_connection->getHost() == req->m_connection->getHost()) &&
120 (this->m_connection->getPort() == req->m_connection->getPort())
121 ){
122 return true;
123 }return false;
124 }
125
isCycle() const126 bool LDAPRequest::isCycle() const{
127 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isCycle()" << endl);
128 const LDAPRequest* parent=m_parent;
129 if(parent != 0){
130 do{
131 if(this->equals(parent)){
132 return true;
133 }else{
134 parent=parent->getParent();
135 }
136 }
137 while(parent != 0);
138 }
139 return false;
140 }
141
unbind() const142 void LDAPRequest::unbind() const{
143 DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::unbind()" << endl);
144 m_connection->unbind();
145 }
146