LDAPSchema.cpp 2.28 KB
Newer Older
Ralf Haferkamp's avatar
Ralf Haferkamp committed
1
// $OpenLDAP$
2
/*
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
3
 * Copyright 2003-2021 The OpenLDAP Foundation, All Rights Reserved.
4
5
6
7
8
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */

#include "LDAPSchema.h"

9
#include <ctype.h>
10
11
12
13
14
#include <ldap.h>

#include "debug.h"
#include "StringList.h"

15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using namespace std;

LDAPSchema::LDAPSchema(){
    DEBUG(LDAP_DEBUG_CONSTRUCT,
            "LDAPSchema::LDAPSchema( )" << endl);
}

LDAPSchema::~LDAPSchema() {
    DEBUG(LDAP_DEBUG_DESTROY,"LDAPSchema::~LDAPSchema()" << endl);
}

void LDAPSchema::setObjectClasses (const StringList &ocs) {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPSchema::setObjectClasses()" << endl);
    
    // parse the stringlist and save it to global map...
    StringList::const_iterator i,j;
    for (i = ocs.begin(); i != ocs.end(); i++) {
	LDAPObjClass oc ( (*i) );
	StringList names = oc.getNames();
	// there could be more names for one object...
	for (j = names.begin(); j != names.end(); j++) {
37
38
39
40
41
42
            string lc_name = *j;
            string::iterator k;
            for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
                (*k) = tolower(*k); 
            }
	    object_classes [lc_name] = LDAPObjClass (oc);
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	}
    }
}

void LDAPSchema::setAttributeTypes (const StringList &ats) {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPSchema::setAttributeTypes()" << endl);
    
    // parse the stringlist and save it to global map...
    StringList::const_iterator i,j;
    for (i = ats.begin(); i != ats.end(); i++) {
	LDAPAttrType at ( (*i) );
	StringList names = at.getNames();
	// there could be more names for one object...
	for (j = names.begin(); j != names.end(); j++) {
57
58
59
60
61
62
            string lc_name = *j;
            string::iterator k;
            for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
                (*k) = tolower(*k); 
            }
	    attr_types [lc_name] = LDAPAttrType (at);
63
64
65
66
67
	}
    }
}

LDAPObjClass LDAPSchema::getObjectClassByName (string name) {
68
69
70
71
72
73
    string lc_name = name;
    string::iterator k;
    for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
        (*k) = tolower(*k); 
    }
    return object_classes [lc_name];
74
75
76
}

LDAPAttrType LDAPSchema::getAttributeTypeByName (string name) {
77
78
79
80
81
    string lc_name = name;
    string::iterator k;
    for ( k = lc_name.begin(); k != lc_name.end(); k++ ) {
        (*k) = tolower(*k); 
    }
82

83
    return attr_types [lc_name];
84
}