]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPSchema.cpp
Added ldif_countlines()
[openldap] / contrib / ldapc++ / src / LDAPSchema.cpp
1 /*
2  * Copyright 2003, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 #include "debug.h"
7 #include "StringList.h"
8 #include "LDAPSchema.h"
9
10 #include <ctype.h>
11
12 using namespace std;
13
14 LDAPSchema::LDAPSchema(){
15     DEBUG(LDAP_DEBUG_CONSTRUCT,
16             "LDAPSchema::LDAPSchema( )" << endl);
17 }
18
19 LDAPSchema::~LDAPSchema() {
20     DEBUG(LDAP_DEBUG_DESTROY,"LDAPSchema::~LDAPSchema()" << endl);
21 }
22
23 void LDAPSchema::setObjectClasses (const StringList &ocs) {
24     DEBUG(LDAP_DEBUG_TRACE,"LDAPSchema::setObjectClasses()" << endl);
25     
26     // parse the stringlist and save it to global map...
27     StringList::const_iterator i,j;
28     for (i = ocs.begin(); i != ocs.end(); i++) {
29         LDAPObjClass oc ( (*i) );
30         StringList names = oc.getNames();
31         // there could be more names for one object...
32         for (j = names.begin(); j != names.end(); j++) {
33             string lc_name = *j;
34             string::iterator k;
35             for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
36                 (*k) = tolower(*k); 
37             }
38             object_classes [lc_name] = LDAPObjClass (oc);
39         }
40     }
41 }
42
43 void LDAPSchema::setAttributeTypes (const StringList &ats) {
44     DEBUG(LDAP_DEBUG_TRACE,"LDAPSchema::setAttributeTypes()" << endl);
45     
46     // parse the stringlist and save it to global map...
47     StringList::const_iterator i,j;
48     for (i = ats.begin(); i != ats.end(); i++) {
49         LDAPAttrType at ( (*i) );
50         StringList names = at.getNames();
51         // there could be more names for one object...
52         for (j = names.begin(); j != names.end(); j++) {
53             string lc_name = *j;
54             string::iterator k;
55             for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
56                 (*k) = tolower(*k); 
57             }
58             attr_types [lc_name] = LDAPAttrType (at);
59         }
60     }
61 }
62
63 LDAPObjClass LDAPSchema::getObjectClassByName (string name) {
64     string lc_name = name;
65     string::iterator k;
66     for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
67         (*k) = tolower(*k); 
68     }
69     return object_classes [lc_name];
70 }
71
72 LDAPAttrType LDAPSchema::getAttributeTypeByName (string name) {
73     string lc_name = name;
74     string::iterator k;
75     for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
76         (*k) = tolower(*k); 
77     }
78
79     return attr_types [lc_name];
80 }