mirror of
https://github.com/altlinux/admc.git
synced 2025-01-18 18:03:44 +03:00
add entry_get_attribute_or_none
This commit is contained in:
parent
31dfebd211
commit
1db1308e6e
@ -68,7 +68,7 @@ gboolean containers_filter_func(
|
||||
|
||||
void containers_populate_model_recursive(GtkTreeStore* model, char* node_dn, GtkTreeIter* parent) {
|
||||
// Populate model with name's of entries
|
||||
|
||||
|
||||
entry* e = shget(entries, node_dn);
|
||||
|
||||
// Skip if entry is not a container
|
||||
@ -79,13 +79,14 @@ void containers_populate_model_recursive(GtkTreeStore* model, char* node_dn, Gtk
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: handle no name?
|
||||
STR_ARRAY name = entry_get_attribute(e, "name");
|
||||
|
||||
GtkTreeIter this_node;
|
||||
gtk_tree_store_append(model, &this_node, parent);
|
||||
|
||||
gtk_tree_store_set(model, &this_node, CONTAINERS_COLUMN_DN, node_dn, -1);
|
||||
gtk_tree_store_set(model, &this_node, CONTAINERS_COLUMN_NAME, name[0], -1);
|
||||
|
||||
char name[DN_LENGTH_MAX];
|
||||
first_element_in_dn(name, node_dn, DN_LENGTH_MAX);
|
||||
gtk_tree_store_set(model, &this_node, CONTAINERS_COLUMN_NAME, name, -1);
|
||||
|
||||
// Recurse into entry's children
|
||||
for (int i = 0; i < arrlen(e->children); i++) {
|
||||
|
@ -85,30 +85,20 @@ void contents_populate_model(const char* new_root_dn) {
|
||||
GtkTreeIter this_node;
|
||||
gtk_tree_store_append(model, &this_node, NULL);
|
||||
|
||||
// DN
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_DN, child->dn, -1);
|
||||
char* dn = child->dn;
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_DN, dn, -1);
|
||||
|
||||
// Name
|
||||
STR_ARRAY name = entry_get_attribute(child, "name");
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_NAME, name[0], -1);
|
||||
char name[DN_LENGTH_MAX];
|
||||
first_element_in_dn(name, dn, DN_LENGTH_MAX);
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_NAME, name, -1);
|
||||
|
||||
// Category
|
||||
STR_ARRAY category_dn = entry_get_attribute(child, "objectCategory");
|
||||
if (category_dn == NULL) {
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_DESCRIPTION, "none", -1);
|
||||
} else {
|
||||
char short_category[DN_LENGTH_MAX];
|
||||
first_element_in_dn(short_category, category_dn[0], DN_LENGTH_MAX);
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_CATEGORY, short_category, -1);
|
||||
}
|
||||
char* category_dn = entry_get_attribute_or_none(child, "objectCategory");
|
||||
char category[DN_LENGTH_MAX];
|
||||
first_element_in_dn(category, category_dn, DN_LENGTH_MAX);
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_CATEGORY, category, -1);
|
||||
|
||||
// Description
|
||||
STR_ARRAY description = entry_get_attribute(child, "description");
|
||||
if (description == NULL) {
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_DESCRIPTION, "none", -1);
|
||||
} else {
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_DESCRIPTION, description[0], -1);
|
||||
}
|
||||
char* description = entry_get_attribute_or_none(child, "description");
|
||||
gtk_tree_store_set(model, &this_node, CONTENTS_COLUMN_DESCRIPTION, description, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
19
src/entry.c
19
src/entry.c
@ -97,6 +97,16 @@ STR_ARRAY entry_get_attribute(entry* e, const char* key) {
|
||||
return shget(e->attributes, key);
|
||||
}
|
||||
|
||||
char* entry_get_attribute_or_none(entry* e, const char* key) {
|
||||
static char* none_str = "none";
|
||||
STR_ARRAY attribute_array = entry_get_attribute(e, key);
|
||||
if (attribute_array != NULL) {
|
||||
return attribute_array[0];
|
||||
} else {
|
||||
return none_str;
|
||||
}
|
||||
}
|
||||
|
||||
bool entry_attribute_exists(entry* e, const char* key, const char* value) {
|
||||
STR_ARRAY values = shget(e->attributes, key);
|
||||
|
||||
@ -166,7 +176,13 @@ bool entry_is_container(entry* e) {
|
||||
|
||||
// "OU=Something,CN=Blah,CN=Bleh" => "Something"
|
||||
void first_element_in_dn(char* buffer, const char* dn, size_t buffer_size) {
|
||||
if (buffer == NULL || dn == NULL) {
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
*buffer = '\0';
|
||||
|
||||
if (dn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -264,6 +280,7 @@ void entry_init_fake() {
|
||||
entry* dave = make_fake_entry("dave", head, true, "Person");
|
||||
make_fake_entry("daves_dog", dave, false, "Robot");
|
||||
make_fake_entry("daves_car", dave, false, "Robot");
|
||||
add_fake_attribute(dave, "description", "dave is a cool dude");
|
||||
|
||||
entry* mark = make_fake_entry("mark", head, true, "Person");
|
||||
make_fake_entry("marks_son", mark, false, "Robot");
|
||||
|
@ -31,6 +31,7 @@ void entry_init();
|
||||
void entry_init_fake();
|
||||
void entry_load(const char* dn);
|
||||
STR_ARRAY entry_get_attribute(entry* e, const char* key);
|
||||
char* entry_get_attribute_or_none(entry* e, const char* key);
|
||||
void entry_delete(entry* e);
|
||||
bool entry_attribute_exists(entry* e, const char* key, const char* value);
|
||||
bool entry_is_container(entry* e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user