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