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