[yast-commit] r48618 - in /trunk/ldap-server/src: LdapServer.pm agent/SlapdConfigAgent.cc agent/SlapdConfigAgent.h lib/backConfigTest.cpp lib/backConfigTest.h tree_structure.ycp widgets.ycp
Author: rhafer Date: Fri Jun 27 15:58:36 2008 New Revision: 48618 URL: http://svn.opensuse.org/viewcvs/yast?rev=48618&view=rev Log: initial work on index support Modified: trunk/ldap-server/src/LdapServer.pm trunk/ldap-server/src/agent/SlapdConfigAgent.cc trunk/ldap-server/src/agent/SlapdConfigAgent.h trunk/ldap-server/src/lib/backConfigTest.cpp trunk/ldap-server/src/lib/backConfigTest.h trunk/ldap-server/src/tree_structure.ycp trunk/ldap-server/src/widgets.ycp Modified: trunk/ldap-server/src/LdapServer.pm URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/LdapServer.pm?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/LdapServer.pm (original) +++ trunk/ldap-server/src/LdapServer.pm Fri Jun 27 15:58:36 2008 @@ -556,6 +556,16 @@ return $rc; } +BEGIN { $TYPEINFO {GetDatabaseIndexes} = ["function", [ "map" , "string", [ "map", "string", "boolean" ] ], "integer" ]; } +sub GetDatabaseIndexes +{ + my ($self, $index) = @_; + y2milestone("GetDatabase ".$index); + my $rc = SCR->Read(".ldapserver.database.{".$index."}.indexes" ); + y2milestone( "Indexes: ".Data::Dumper->Dump([$rc]) ); + return $rc; +} + BEGIN { $TYPEINFO {GetSchemaList} = ["function", [ "list" , "string"] ]; } sub GetSchemaList { Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.cc?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.cc (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.cc Fri Jun 27 15:58:36 2008 @@ -74,9 +74,13 @@ } else if ( path->component_str(0) == "schemaList" ) { - y2milestone("read databases"); + y2milestone("read schemalist"); return ReadSchemaList(path->at(1), arg, opt); } + else if ( path->component_str(0) == "schema" ) + { + return ReadSchema( path->at(1), arg, opt ); + } else if ( path->component_str(0) == "database" ) { y2milestone("read database"); @@ -340,6 +344,7 @@ y2milestone("Path %s Length %ld ", path->toString().c_str(), path->length()); std::string dbIndexStr = path->component_str(0); + y2milestone("Component %s ", dbIndexStr.c_str()); int dbIndex = -2; if ( dbIndexStr[0] == '{' ) { @@ -363,14 +368,92 @@ if ( (*i)->getIndex() == dbIndex ) { YCPMap resMap; - resMap.add( YCPString("suffix"), - YCPString( (*i)->getStringValue("olcSuffix") )); - resMap.add( YCPString("directory"), - YCPString( (*i)->getStringValue("olcDbDirectory") )); - resMap.add( YCPString("rootdn"), - YCPString( (*i)->getStringValue("olcRootDn") )); - return resMap; + if ( path->length() == 1 ) + { + resMap.add( YCPString("suffix"), + YCPString( (*i)->getStringValue("olcSuffix") )); + resMap.add( YCPString("directory"), + YCPString( (*i)->getStringValue("olcDbDirectory") )); + resMap.add( YCPString("rootdn"), + YCPString( (*i)->getStringValue("olcRootDn") )); + return resMap; + } else { + std::string dbComponent = path->component_str(1); + y2milestone("Component %s ", dbComponent.c_str()); + IndexMap idx = (*i)->getIndexes(); + IndexMap::const_iterator j = idx.begin(); + for ( ; j != idx.end(); j++ ) + { + YCPMap ycpIdx; + y2milestone("indexed Attribute: \"%s\"", j->first.c_str() ); + std::vector<IndexType>::const_iterator k = j->second.begin(); + for ( ; k != j->second.end(); k++ ) + { + if ( *k == Eq ) + ycpIdx.add(YCPString("eq"), YCPBoolean(true) ); + } + resMap.add( YCPString(j->first), ycpIdx ); + } + return resMap; + } + } + } + return YCPNull(); +} + +bool comparesAttrTypes( const LDAPAttrType& a1, const LDAPAttrType& a2 ) +{ + return ( a1.getName() < a2.getName() ); +} + +YCPValue SlapdConfigAgent::ReadSchema( const YCPPath &path, + const YCPValue &arg, + const YCPValue &opt) +{ + if ( path->length() !=1 ) + { + y2milestone("Unsupported Path: %s", path->toString().c_str() ); + return YCPNull(); + } + else if ( path->component_str(0) == "attributeTypes" ) + { + if ( schema.size() == 0 ) + { + schema = olc.getSchemaNames(); + } + OlcSchemaList::const_iterator i; + YCPList resList; + for (i = schema.begin(); i != schema.end(); i++ ) + { + y2milestone("Schema: %s", (*i)->getName().c_str() ); + std::vector<LDAPAttrType> types = (*i)->getAttributeTypes(); + std::sort( types.begin(), types.end(), comparesAttrTypes ); + std::vector<LDAPAttrType>::const_iterator j; + for ( j = types.begin(); j != types.end(); j++ ) + { + YCPMap attrMap; + attrMap.add( YCPString("name"), YCPString( j->getName() ) ); + if ( j->getEqualityOid() != "" ) + { + attrMap.add( YCPString("equality"), YCPBoolean( true ) ); + } else { + attrMap.add( YCPString("equality"), YCPBoolean( false ) ); + } + if ( j->getSubstringOid() != "" ) + { + attrMap.add( YCPString("substring"), YCPBoolean( true ) ); + } else { + attrMap.add( YCPString("substring"), YCPBoolean( false ) ); + } + attrMap.add( YCPString("presence"), YCPBoolean( true ) ); + + // FIXME: how should "approx" indexing be handled, create + // whitelist based upon syntaxes? + + resList.add( attrMap ); + } } + return resList; } return YCPNull(); } Modified: trunk/ldap-server/src/agent/SlapdConfigAgent.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/agent/SlapdConfigAgent.h?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/agent/SlapdConfigAgent.h (original) +++ trunk/ldap-server/src/agent/SlapdConfigAgent.h Fri Jun 27 15:58:36 2008 @@ -51,6 +51,11 @@ YCPValue ReadDatabase( const YCPPath &path, const YCPValue &arg = YCPNull(), const YCPValue &opt = YCPNull()); + + YCPValue ReadSchema( const YCPPath &path, + const YCPValue &arg = YCPNull(), + const YCPValue &opt = YCPNull()); + YCPBoolean WriteGlobal( const YCPPath &path, const YCPValue &arg = YCPNull(), const YCPValue &opt = YCPNull()); Modified: trunk/ldap-server/src/lib/backConfigTest.cpp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.cpp?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.cpp (original) +++ trunk/ldap-server/src/lib/backConfigTest.cpp Fri Jun 27 15:58:36 2008 @@ -65,11 +65,15 @@ OlcBdbDatabase::OlcBdbDatabase( const LDAPEntry& le) : OlcDatabase(le) { } -OlcBdbDatabase::IndexMap OlcBdbDatabase::getIndexes() +IndexMap OlcBdbDatabase::getIndexes() const { - const LDAPAttributeList *al = m_dbEntry.getAttributes(); + const LDAPAttributeList *al = m_dbEntryChanged.getAttributes(); const LDAPAttribute *attr = al->getAttributeByName("olcdbindex"); - OlcBdbDatabase::IndexMap res; + IndexMap res; + if (! attr ) { + return res; + }; + StringList sl = attr->getValues(); StringList::const_iterator i; for (i = sl.begin(); i != sl.end(); i++ ) { @@ -84,7 +88,7 @@ indexes = i->substr( pos, std::string::npos ); std::cout << "Indexes: <" << indexes << ">" << std::endl; std::string::size_type oldpos = 0; - std::vector<OlcBdbDatabase::IndexType> idx; + std::vector<IndexType> idx; do { pos = indexes.find( ',', oldpos ); std::string index = indexes.substr( oldpos, @@ -92,23 +96,23 @@ std::cout << "Index: <" << index << ">" << std::endl; oldpos = indexes.find_first_not_of( ", ", pos ); if ( index == "pres" ) { - idx.push_back(OlcBdbDatabase::Present); + idx.push_back(Present); } else if (index == "eq" ) { - idx.push_back(OlcBdbDatabase::Eq); + idx.push_back(Eq); } else if (index == "approx" ) { - idx.push_back(OlcBdbDatabase::Approx); + idx.push_back(Approx); } else if (index == "sub" ) { - idx.push_back(OlcBdbDatabase::Sub); + idx.push_back(Sub); } else if (index == "subinital" ) { - idx.push_back(OlcBdbDatabase::SpecialSubInitial); + idx.push_back(SpecialSubInitial); } else if (index == "subany" ) { - idx.push_back(OlcBdbDatabase::SpecialSubAny); + idx.push_back(SpecialSubAny); } else if (index == "subfinal" ) { - idx.push_back(OlcBdbDatabase::SpecialSubFinal); + idx.push_back(SpecialSubFinal); } else if (index == "nolang" ) { - idx.push_back(OlcBdbDatabase::SpecialNoLang); + idx.push_back(SpecialNoLang); } else if (index == "nosubtypes" ) { - idx.push_back(OlcBdbDatabase::SpecialNoSubTypes); + idx.push_back(SpecialNoSubTypes); } } while (pos != std::string::npos); res.insert(make_pair(attrType, idx)); @@ -296,6 +300,26 @@ return m_name; } +const std::vector<LDAPAttrType> OlcSchemaConfig::getAttributeTypes() const +{ + std::vector<LDAPAttrType> res; + StringList types = this->getStringValues("olcAttributeTypes"); + StringList::const_iterator j; + for ( j = types.begin(); j != types.end(); j++ ) + { + LDAPAttrType currentAttr; + if ( (*j)[0] == '{' ) + { + std::string::size_type pos = j->find('}'); + currentAttr = LDAPAttrType( j->substr( pos+1, std::string::npos ) ); + } else { + currentAttr = LDAPAttrType( *j ); + } + res.push_back(currentAttr); + } + return res; +} + OlcTlsSettings OlcGlobalConfig::getTlsSettings() const { std::cout << "OlcTlsSettings OlcGlobalConfig::getTlsSettings() const " << std::endl; @@ -780,9 +804,8 @@ OlcSchemaList res; try { StringList attrs; - attrs.add("cn"); LDAPSearchResults *sr = m_lc->search( "cn=schema,cn=config", - LDAPConnection::SEARCH_ONE, "objectclass=olcSchemaConfig", attrs ); + LDAPConnection::SEARCH_SUB, "objectclass=olcSchemaConfig" ); LDAPEntry *entry; while ( entry = sr->getNext() ) { Modified: trunk/ldap-server/src/lib/backConfigTest.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/lib/backConfigTest.h?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/lib/backConfigTest.h (original) +++ trunk/ldap-server/src/lib/backConfigTest.h Fri Jun 27 15:58:36 2008 @@ -8,6 +8,7 @@ #include <map> #include <vector> #include <LDAPEntry.h> +#include <LDAPAttrType.h> #include <boost/shared_ptr.hpp> class OlcConfigEntry @@ -61,6 +62,21 @@ LDAPEntry m_dbEntryChanged; }; +enum IndexType { + Default, + Present, + Eq, + Approx, + Sub, + SpecialSubInitial, + SpecialSubAny, + SpecialSubFinal, + SpecialNoLang, + SpecialNoSubTypes, +}; + +typedef std::map<std::string, std::vector<IndexType> > IndexMap; + class OlcDatabase : public OlcConfigEntry { public : @@ -79,6 +95,8 @@ const std::string getType() const; virtual std::map<std::string, std::list<std::string> > toMap() const; + virtual IndexMap getIndexes() const {}; + protected: virtual void updateEntryDn(); @@ -94,21 +112,8 @@ virtual std::map<std::string, std::list<std::string> > toMap() const; void setDirectory( const std::string &dir); - enum IndexType { - Default, - Present, - Eq, - Approx, - Sub, - SpecialSubInitial, - SpecialSubAny, - SpecialSubFinal, - SpecialNoLang, - SpecialNoSubTypes, - }; - typedef std::map<std::string, std::vector<OlcBdbDatabase::IndexType> > IndexMap; - IndexMap getIndexes(); + virtual IndexMap getIndexes() const; }; class OlcTlsSettings; @@ -141,6 +146,7 @@ OlcSchemaConfig(const LDAPEntry &e1, const LDAPEntry &e2); virtual void clearChangedEntry(); const std::string& getName() const; + const std::vector<LDAPAttrType> getAttributeTypes() const; private: std::string m_name; Modified: trunk/ldap-server/src/tree_structure.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/tree_structure.ycp?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/tree_structure.ycp (original) +++ trunk/ldap-server/src/tree_structure.ycp Fri Jun 27 15:58:36 2008 @@ -985,6 +985,40 @@ return true; } +define boolean cb_read_bdb_index() +{ + integer index = (integer) widget_map[current_tree_item, "index"]:nil; + y2milestone("cb_read_bdb_index current item: %1, index %2", current_tree_item, index); + map<string, map<string, boolean> > idxMap = LdapServer::GetDatabaseIndexes( index ); + integer i=0; + list newItems = []; + foreach( string attr, map<string, boolean> idx, idxMap, { + string eqIdx = _("No"); + string presIdx = _("No"); + string substrIdx = _("No"); + string approxIdx = _("No"); + y2milestone("index attr: %1", attr); + if ( idx["eq"]:false ) + { + y2milestone("eq index"); + eqIdx = _("Yes"); + } + newItems = add( newItems, `item( `id(i), attr, presIdx, eqIdx, substrIdx, approxIdx ) ); + } ); + UI::ChangeWidget( `tab_idx, `Items , newItems ); + + return true; +} + +define boolean cb_input_bdb_index() +{ + y2milestone("cb_input_bdb_index, handlercmd: %1", handler_cmd); + if ( handler_cmd == `pb_idx_add ) + { + AddIndexPopup(); + } + return true; +} /***************************************** ** tree structure definition ** @@ -1063,9 +1097,16 @@ void addDatabaseWidgetMap( string suffix, string item_name, integer index, boolean new_db ) { if( haskey( widget_map, item_name ) ) return; - + map<string, any> dbIndex = $[ + "name" : _("Index Configuration"), + "widget" : editBdbIndexes, + "index" : index, + "cb_read" : ``(cb_read_bdb_index() ), + "cb_input" : ``(cb_input_bdb_index() ) + ]; map<string,any> item_map = $[ "name" : suffix, + "children" : [ item_name + "_index" ], "index" : index, "widget" : editBdbDatabase, "new_db" : new_db, @@ -1078,6 +1119,8 @@ ]; y2milestone( "adding database item '%1' as '%2'", suffix, item_name ); widget_map[item_name] = item_map; + widget_map[item_name + "_index"] = dbIndex; + widget_map["databases","children"] = add( widget_map["databases","children"]:[], item_name ); } Modified: trunk/ldap-server/src/widgets.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ldap-server/src/widgets.ycp?rev=48618&r1=48617&r2=48618&view=diff ============================================================================== --- trunk/ldap-server/src/widgets.ycp (original) +++ trunk/ldap-server/src/widgets.ycp Fri Jun 27 15:58:36 2008 @@ -1,6 +1,7 @@ { textdomain "ldap-server"; + map<string, any> firewall_settings = $[ "services": [ "ldap" , "ldaps" ], "display_details": true, @@ -329,6 +330,22 @@ generalDbWidget ); + term editBdbIndexes = + `VBox( + `Heading( _("Edit Index Configuration") ), + `Table( + `id( `tab_idx ), + `header( "Attrbute", "pres", "eq", "sub", "approx"), + [ ] + ), + `HSquash( + `HBox( + `PushButton( `id( `pb_idx_add ), _("Add") ), + `PushButton( `id( `pb_idx_edit ), _("Edit") ), + `PushButton( `id( `pb_idx_del ), _("Delete") ) + ) + ) + ); term editPolicy = `VBox( `VSpacing( 1 ), @@ -372,5 +389,39 @@ ) ) ); -} + define boolean AddIndexPopup() + { + term content = + `VBox( + `Heading( _("Add Index") ), + `ComboBox( `id( `cb_attrs ), `opt( `hstretch ), "Attributetypes" ), + `HBox( + `PushButton( `id( `pb_ok ), Label::OKButton() ), + `PushButton( `id( `pb_cancel ), Label::CancelButton() ) + ) + ); + list<map<string,any> > attrTypes = (list<map <string,any> >) SCR::Read( .ldapserver.schema.attributeTypes ); + list<string> items = []; + foreach( map<string,any> attr, attrTypes, { + items = add( items, (string)attr["name"]:"" ); + y2milestone( "%1 (eq:%2)", (string)attr["name"]:"", (boolean)attr["equality"]:false ); + } ); + UI::OpenDialog( `opt(`decorated), content ); + UI::ChangeWidget( `cb_attrs, `Items, items ); + while (true) + { + any ret = UI::UserInput(); + if (ret == `pb_cancel ) + { + break; + } + if (ret == `pb_ok ) + { + break; + } + } + UI::CloseDialog(); + return true; + } +} -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rhafer@svn.opensuse.org