summaryrefslogtreecommitdiffstats
path: root/contrib/ldapc++/src/LDAPSearchResults.cpp
blob: 134825a017687d99d1bca214984077a84b8fdc84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// $OpenLDAP$
/*
 * Copyright 2000-2024 The OpenLDAP Foundation, All Rights Reserved.
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */


#include "LDAPException.h"
#include "LDAPSearchResult.h"
#include "LDAPResult.h"

#include "LDAPSearchResults.h"

LDAPSearchResults::LDAPSearchResults(){
    entryPos = entryList.begin();
    refPos = refList.begin();
}

LDAPResult* LDAPSearchResults::readMessageQueue(LDAPMessageQueue* msg){
    if(msg != 0){
        LDAPMsg* res=0;
        for(;;){
            try{
                res = msg->getNext();
            }catch (LDAPException e){
                throw;
            }
            switch(res->getMessageType()){ 
                case LDAPMsg::SEARCH_ENTRY :
                    entryList.addEntry(*((LDAPSearchResult*)res)->getEntry());
                break;
                case LDAPMsg::SEARCH_REFERENCE :
                    refList.addReference(*((LDAPSearchReference*)res));
                break;
                default:
                    entryPos=entryList.begin();
                    refPos=refList.begin();
                    return ((LDAPResult*) res);
            }
            delete res;
            res=0;
        }
    }
    return 0;
}

LDAPEntry* LDAPSearchResults::getNext(){
    if( entryPos != entryList.end() ){
        LDAPEntry* ret= new LDAPEntry(*entryPos);
        entryPos++;
        return ret;
    }
    if( refPos != refList.end() ){
        LDAPUrlList urls= refPos->getUrls();
        refPos++;
        throw(LDAPReferralException(urls));
    }
    return 0;
}