]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/examples/readSchema.cpp
Silence compiler warnings
[openldap] / contrib / ldapc++ / examples / readSchema.cpp
1 #include<iostream>
2 #include<sstream>
3 #include "LDAPConnection.h"
4 #include "LDAPConstraints.h"
5 #include "LDAPSearchReference.h"
6 #include "LDAPSearchResults.h"
7 #include "LDAPAttribute.h"
8 #include "LDAPAttributeList.h"
9 #include "LDAPEntry.h"
10 #include "LDAPException.h"
11 #include "LDAPModification.h"
12 #include "LDAPReferralException.h"
13 #include "LDAPSchema.h"
14
15 #include"debug.h"
16
17 int main(){
18     LDAPConnection *lc=new LDAPConnection("192.168.3.128",389);
19     std::cout << "----------------------doing bind...." <<  std::endl;
20     try{
21         lc->bind("uid=admin,dc=home,dc=local" , "secret");
22         std::cout << lc->getHost() << std::endl;
23         StringList tmp;
24         tmp.add("subschemasubentry");
25         LDAPSearchResults* entries = lc->search("", 
26                         LDAPConnection::SEARCH_BASE,
27                         "(objectClass=*)",
28                         tmp );
29         LDAPEntry* rootDse = entries->getNext();
30         std::string schemabase="cn=subschema";
31
32         if(rootDse){
33             const LDAPAttribute* schemaAttr = rootDse->getAttributes()->getAttributeByName("subschemaSubentry");
34             schemabase = *(schemaAttr->getValues().begin());   
35         }
36         StringList attrs;
37         attrs.add("objectClasses");
38         attrs.add("attributeTypes");
39         entries = lc->search(schemabase, LDAPConnection::SEARCH_BASE, "(objectClass=*)",
40                         attrs);
41         if (entries != 0){
42             LDAPEntry* entry = entries->getNext();
43             if(entry != 0){
44                 const LDAPAttribute* oc = entry->getAttributes()->getAttributeByName("objectClasses");
45                 LDAPSchema schema;
46                 schema.setObjectClasses((oc->getValues()));
47                 LDAPObjClass test = schema.getObjectClassByName("inetOrgPerson");
48                 std::cout << test.getDesc() << std::endl;
49 //                StringList mustAttr = test.getMay();
50 //                for( StringList::const_iterator i = mustAttr.begin(); i != mustAttr.end(); i++ ){
51 //                    std::cout << *i << std::endl;
52 //                }
53                 StringList sup = test.getSup();
54                 for( StringList::const_iterator i = sup.begin(); i != sup.end(); i++ ){
55                     std::cout << *i << std::endl;
56                 }
57             }
58         }
59         
60         lc->unbind();
61         delete lc;
62    }catch (LDAPException e){
63         std::cout << "---------------- caught Exception ---------"<< std::endl;
64         std::cout << e << std::endl;
65     }
66
67 }
68