LDAPRequest.cpp 3.9 KB
Newer Older
1
// $OpenLDAP$
2
/*
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
3
 * Copyright 2000-2018 The OpenLDAP Foundation, All Rights Reserved.
4
5
6
7
8
9
10
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */


#include "debug.h"
#include "LDAPRequest.h"

11
12
using namespace std;

13
LDAPRequest::LDAPRequest(){
14
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest()" << endl);
15
16
17
}

LDAPRequest::LDAPRequest(const LDAPRequest& req){
18
19
20
21
22
23
24
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPRequest::LDAPRequest(&)" << endl);
    m_isReferral=req.m_isReferral;
    m_cons = new LDAPConstraints(*(req.m_cons));
    m_connection = req.m_connection;
    m_parent = req.m_parent;
    m_hopCount = req.m_hopCount;
    m_msgID = req.m_msgID;
25
26
}

27
28
29
LDAPRequest::LDAPRequest(LDAPAsynConnection* con, 
       const LDAPConstraints* cons,bool isReferral, const LDAPRequest* parent){
    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPRequest::LDAPRequest()" << endl);
30
31
    m_connection=con;
    if(cons == 0){
32
33
34
35
36
37
38
39
40
41
42
        m_cons=new LDAPConstraints( *(con->getConstraints()) );
    }else{
        m_cons=new LDAPConstraints( *cons);
    }
    m_isReferral=isReferral; 
    if(m_isReferral){
        m_hopCount = (parent->getHopCount()+1);
        m_parent= parent;
    }else{
        m_hopCount=0;
        m_parent=0;
43
44
45
46
    }
}

LDAPRequest::~LDAPRequest(){
47
    DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::~LDAPRequest()" << endl);
48
49
50
    delete m_cons;
}

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
LDAPMsg* LDAPRequest::getNextMessage() const 
{
    DEBUG(LDAP_DEBUG_DESTROY,"LDAPRequest::getNextMessage()" << endl);
    int res;
    LDAPMessage *msg;

    res=ldap_result(this->m_connection->getSessionHandle(),
            this->m_msgID,0,0,&msg);

    if (res <= 0){
        if(msg != 0){
            ldap_msgfree(msg);
        }
        throw  LDAPException(this->m_connection);
    }else{	
        LDAPMsg *ret=0;
        //this can  throw an exception (Decoding Error)
        ret = LDAPMsg::create(this,msg);
        ldap_msgfree(msg);
        return ret;
    }
}

Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
74
75
76
77
78
79
80
LDAPRequest* LDAPRequest::followReferral(LDAPMsg* /*urls*/){
    DEBUG(LDAP_DEBUG_TRACE,"LDAPBindRequest::followReferral()" << endl);
    DEBUG(LDAP_DEBUG_TRACE,
            "ReferralChasing not implemented for this operation" << endl);
    return 0;
}

81
82
const LDAPConstraints* LDAPRequest::getConstraints() const{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConstraints()" << endl);
83
84
85
    return m_cons;
}

86
87
const LDAPAsynConnection* LDAPRequest::getConnection() const{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getConnection()" << endl);
88
89
90
91
    return m_connection;
}

int LDAPRequest::getType() const {
92
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getType()" << endl);
93
94
95
96
    return m_requestType;
}

int LDAPRequest::getMsgID() const {
97
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getMsgId()" << endl);
98
99
100
    return m_msgID;
}

101
102
103
104
105
106
107
108
109
110
int LDAPRequest::getHopCount() const {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getHopCount()" << endl);
    return m_hopCount;
}

const LDAPRequest* LDAPRequest::getParent() const{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::getParent()" << endl);
    return m_parent;
}

111
bool LDAPRequest::isReferral() const {
112
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isReferral()" << endl);
113
114
115
    return m_isReferral;
}

116
117
118
119
120
121
122
123
bool LDAPRequest::equals(const LDAPRequest* req) const{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::equals()" << endl);
    if( (this->m_requestType == req->getType()) && 
        (this->m_connection->getHost() == req->m_connection->getHost()) && 
        (this->m_connection->getPort() == req->m_connection->getPort())
      ){
        return true;
    }return false;        
124
125
}

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
bool LDAPRequest::isCycle() const{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::isCycle()" << endl);
    const LDAPRequest* parent=m_parent;
    if(parent != 0){
        do{
            if(this->equals(parent)){
                return true;
            }else{
                parent=parent->getParent();
            }
        }
        while(parent != 0);
    }
    return false;
}

void LDAPRequest::unbind() const{
    DEBUG(LDAP_DEBUG_TRACE,"LDAPRequest::unbind()" << endl);
    m_connection->unbind();
}