]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPSearchResults.cpp
derive LDAPException from std::exception, merged ReferralException into the
[openldap] / contrib / ldapc++ / src / LDAPSearchResults.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7 #include "LDAPException.h"
8 #include "LDAPSearchResult.h"
9 #include "LDAPResult.h"
10
11 #include "LDAPSearchResults.h"
12
13 LDAPSearchResults::LDAPSearchResults(){
14     entryPos = entryList.begin();
15     refPos = refList.begin();
16 }
17
18 LDAPResult* LDAPSearchResults::readMessageQueue(LDAPMessageQueue* msg){
19     if(msg != 0){
20         LDAPMsg* res=0;
21         for(;;){
22             try{
23                 res = msg->getNext();
24             }catch (LDAPException e){
25                 throw;
26             }
27             switch(res->getMessageType()){ 
28                 case LDAPMsg::SEARCH_ENTRY :
29                     entryList.addEntry(*((LDAPSearchResult*)res)->getEntry());
30                 break;
31                 case LDAPMsg::SEARCH_REFERENCE :
32                     refList.addReference(*((LDAPSearchReference*)res));
33                 break;
34                 default:
35                     entryPos=entryList.begin();
36                     refPos=refList.begin();
37                     return ((LDAPResult*) res);
38             }
39             delete res;
40             res=0;
41         }
42     }
43     return 0;
44 }
45
46 LDAPEntry* LDAPSearchResults::getNext(){
47     if( entryPos != entryList.end() ){
48         LDAPEntry* ret= new LDAPEntry(*entryPos);
49         entryPos++;
50         return ret;
51     }
52     if( refPos != refList.end() ){
53         LDAPUrlList urls= refPos->getUrls();
54         refPos++;
55         throw(LDAPReferralException(urls));
56     }
57     return 0;
58 }
59