]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/main.cpp
Initial check of the LDAP C++ SDK written by Ralf Haferkamp <rhafer@suse.de>
[openldap] / contrib / ldapc++ / src / main.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 #include<iostream.h>
7 #include<strstream>
8 #include"LDAPAsynConnection.h"
9 #include "LDAPConstraints.h"
10 #include"LDAPResult.h"
11 #include"LDAPSearchResult.h"
12 #include"LDAPSearchReference.h"
13 #include"LDAPAttribute.h"
14 #include"LDAPAttributeList.h"
15 #include"LDAPEntry.h"
16 #include"LDAPException.h"
17 #include"LDAPModification.h"
18 #include"debug.h"
19
20 int main(){
21         LDAPAsynConnection *lc=new LDAPAsynConnection("localhost",9009);
22     cout << "----------------------doing bind...." <<  endl;
23     try{
24         LDAPMessageQueue *q=lc->bind("cn=Manager,o=Organisation,c=DE" ,
25                 "secret"); 
26         LDAPMsg *res=q->getNext();
27         if( ((LDAPResult*)res)->getResultCode() == LDAPResult::SUCCESS){
28             cout << "--------------------...successfully bound" << endl;
29         }
30     }catch (LDAPException e){
31         cout << "-------------------------...error during bind" << endl;
32         cout << e << endl;
33     }
34     cout << "--------------------starting search" << endl;
35     try{
36         LDAPMessageQueue *q=lc->search("");
37                 LDAPMsg *res=q->getNext();
38         bool cont=true;
39                 while( cont  ) {
40             switch(res->getMessageType()){
41                 LDAPSearchResult *res2;
42                 LDAPEntry *entry;
43                 case LDAP_RES_SEARCH_ENTRY :
44                     res2= (LDAPSearchResult*)res;
45                     entry=  res2->getEntry();
46                     cout << "Entry:            " << *entry << endl; 
47                     delete res;
48                     res=q->getNext();
49                 break;
50                 case LDAP_RES_SEARCH_REFERENCE :
51                     delete res;
52                     res=q->getNext();
53                 break;
54                 default :
55                             cout << ( *(LDAPResult*) res) << endl;
56                     delete res;
57                     cout  << "-----------------search done" << endl;
58                     cont=false;
59                 break;
60             }
61                 }
62         delete q;
63         }catch (LDAPException e){
64         cout << "----------------error during search" << endl;
65                 cout << e << endl;
66         }
67 }
68