ChangeLog for gtk-tool
+02/12/1998 - Pele
+ * Added Gtk_LdapTree class
+ * Added utils (with debug only)
+ * "Smart" traversing of ldap tree (only 2-deep, then add 2 subtrees as
+ the tree gets expanded)
+ * Lots of updates and bug-fixes
+
29/11/1998 - Pele
* Added Gtk_LdapServer class
* Started using cn=config, ldap_get_option (not sure about get_option
this->par = w;
this->hostname = h;
this->port = p;
- cout << this->hostname << this->port << endl;
+ debug("%s %i\n", this->hostname, this->port);
this->getConfig();
}
}
Gtk_LdapServer::~Gtk_LdapServer() {
- cout << "Bye" << endl;
+ debug("Bye\n");
delete this;
}
void Gtk_LdapServer::setType(int t) {
- cout << "Gtk_LdapServer::setType(" << t << ")" << endl;
+ debug("Gtk_LdapServer::setType(%i)\n", t);
Gtk_Pixmap *xpm_icon;
Gtk_Label *label;
if (this->getchild() != NULL) {
xpm_label->remove_c(xpm_label->children()->nth_data(0));
}
else xpm_label = new Gtk_HBox();
- cout << this->hostname << endl;
+ debug(this->hostname);
if (strcasecmp(this->hostname,"localhost") == 0)
xpm_icon=new Gtk_Pixmap(*xpm_label, local_server);
else xpm_icon=new Gtk_Pixmap(*xpm_label, remote_server);
}
int Gtk_LdapServer::showDetails() {
- cout << "Gtk_LdapServer::showDetails()" << endl;
+ debug("Gtk_LdapServer::showDetails()\n");
this->getDetails();
/*
if (this->notebook != NULL) {
}
int Gtk_LdapServer::getConfig() {
- cout << "Gtk_LdapServer::getConfig()" << endl;
+ debug("Gtk_LdapServer::getConfig()\n");
int error, entriesCount;
LDAPMessage *entry, *result_identifier;
BerElement *ber;
return 0;
}
- cout << entriesCount << " entry" << endl;
+ debug("%i entry\n", entriesCount);
for (entry = ldap_first_entry(this->ld, result_identifier); entry != NULL; entry = ldap_next_entry(this->ld, result_identifier)) {
for (attribute = ldap_first_attribute(this->ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(this->ld, entry, ber)) {
- cout << "Attrib: " << attribute << endl;
+ debug("Attrib: %s\n", attribute);
if (strcasecmp(attribute, "database") == 0) {
- cout << "have database here" << endl;
+ debug("have database here\n");
this->databases = new G_List<char>;
t = ldap_get_values(this->ld, entry, attribute);
for (int i=0; i<ldap_count_values(t); i++) {
this->databases->append(strdup(t[i]));
}
ldap_value_free(t);
- cout << "databases loaded" << endl;
+ debug("databases loaded\n");
for (int i=0; i<this->databases->length(); i++) {
- cout << "database(" << i << ") " << this->databases->nth_data(i) << endl;
+ debug("database(%i) %s\n", i, this->databases->nth_data(i));
}
}
}
- cout << "entry done" << endl;
+ debug("entry done\n");
}
-// cout << "got " << entriesCount << " entries" << endl;
+// debug("got %i entries\n", entriesCount);
return entriesCount;
}
int Gtk_LdapServer::getDetails() {
- cout << "Gtk_LdapServer::getDetails()" << endl;
+ debug("Gtk_LdapServer::getDetails()\n");
Gtk_HBox *hbox;
Gtk_VBox *vbox;
Gtk_Label *label;
return 0;
}
-int Gtk_LdapServer::getSubtree() {
- cout << "Gtk_LdapServer::getSubtree()" << endl;
+Gtk_Tree* Gtk_LdapServer::getSubtree() {
+ debug("Gtk_LdapServer::getSubtree()\n");
Gtk_LdapItem *treeresult;
- Gtk_Tree *tree, *subtree;
+ Gtk_LdapTree *tree, *subtree;
Gtk_LdapTreeItem *treeitem;
int entries;
- cout << "this->hostname=" << this->hostname << endl;
- cout << "this->port=" << this->port << endl;
+ debug("this->hostname=%s\n", this->hostname);
+ debug("this->port=%i", this->port);
/* if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
perror("connection");
}
char *tok;
int len = this->databases->length();
- cout << "this->databases->length()=" << len << endl;
+ debug("this->databases->length()=%i\n", len);
- tree = new Gtk_Tree();
+ tree = new Gtk_LdapTree();
for (int i=0; i<len; i++) {
tok = strdup(this->databases->nth_data(i));
tok = strtok(tok, ":");
+ // c = strtok(NULL, " ");
c = strtok(NULL, "\0");
- cout << "database " << i << " " << c << endl;
- treeresult = this->par->make_tree(this->par, this->ld, c);
- treeitem = new Gtk_LdapTreeItem(*treeresult->treeitem);
+ debug("database %i %s\n", i, c);
+ treeitem = new Gtk_LdapTreeItem(c, this->par, this->ld);
+ subtree = treeitem->getSubtree(this->ld, 1);
+ debug("inserting %s into %s\n", treeitem->rdn, this->hostname);
tree->append(*treeitem);
- if (treeresult->tree != NULL) {
- subtree = new Gtk_Tree(*treeresult->tree);
- treeitem->set_subtree(*subtree);
- }
+ treeitem->set_subtree(*subtree);
treeitem->show();
// tree->show();
}
- this->set_subtree(*tree);
- cout << "getTree() done" << endl;
- return 0;
+// this->set_subtree(*tree);
+ debug("getTree() done\n");
+ return tree;
}
void Gtk_LdapServer::select_impl() {
- cout << this->hostname << " selected" << endl;
+ debug("%s selected\n", this->hostname);
// gtk_item_select(GTK_ITEM(GTK_TREE_ITEM(this->gtkobj())));
Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
if (!sig->select) return;
}
void Gtk_LdapServer::collapse_impl() {
-// cout << this->dn << " collapsed" << endl;
+ debug("%s collapsed\n", this->hostname);
Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
if (!sig->collapse) return;
sig->collapse(GTK_TREE_ITEM(gtkobj()));
}
void Gtk_LdapServer::expand_impl() {
-// cout << this->dn << " expanded" << endl;
+ debug("%s expanded\n", this->hostname);
Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
if (!sig->expand) return;
sig->expand(GTK_TREE_ITEM(gtkobj()));
#ifndef GTK_LDAPSERVER_H
#define GTK_LDAPSERVER_H
#include "gtk.h"
+#include "utils.h"
#include <My_Window.h>
-/*#include <LdapOpts.h>*/
-#include <Gtk_LdapItem.h>
+#include <Gtk_LdapTree.h>
#include <Gtk_LdapTreeItem.h>
#include <lber.h>
#include <ldap.h>
~Gtk_LdapServer();
void setType(int t);
int getConfig();
- int getSubtree();
+ Gtk_Tree* getSubtree();
int getDetails();
int showDetails();
void select_impl();
this->objectClass = NULL;
}
-Gtk_LdapTreeItem::Gtk_LdapTreeItem(char *c, My_Window *w) : Gtk_TreeItem() {
- this->rdn = c;
+Gtk_LdapTreeItem::Gtk_LdapTreeItem(char *c, My_Window *w, LDAP *ld) : Gtk_TreeItem() {
+ debug("Gtk_LdapTreeItem::Gtk_LdapTreeItem(%s)\n", c);
+ char **s;
+ this->dn = c;
+ s = ldap_explode_dn(this->dn, 1);
+ this->rdn = g_strdup_printf("%s", s[0]);
this->par = w;
+ this->ld = ld;
this->objectClass = NULL;
+ this->getDetails();
}
Gtk_LdapTreeItem::Gtk_LdapTreeItem(GtkTreeItem *t) : Gtk_TreeItem(t) {
delete this;
}
+Gtk_LdapTree* Gtk_LdapTreeItem::getSubtree(LDAP *ld, int counter) {
+ debug("Gtk_LdapTreeItem::getSubtree(%s)\n", this->dn);
+ if (counter <= 0) return NULL;
+ if (this->gtkobj()->subtree != NULL) {
+ return (Gtk_LdapTree *)GTK_TREE(this->gtkobj()->subtree);
+ }
+ counter--;
+ Gtk_LdapTree *subtree = NULL, *tree = NULL;
+ Gtk_LdapTreeItem *subtreeitem = NULL;
+ LDAPMessage *r_i = NULL, *entry = NULL;
+ gchar *c;
+ char **s;
+ int entriesCount = 0, error;
+
+ this->ld = ld;
+ error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_ONELEVEL, "objectclass=*", NULL, 0, &r_i);
+// printf("%s\n", ldap_err2string(error));
+ entriesCount = ldap_count_entries(this->ld, r_i);
+ debug("%i results\n", entriesCount);
+ if (entriesCount != 0) {
+ tree = new Gtk_LdapTree();
+ tree->set_selection_mode(GTK_SELECTION_BROWSE);
+ tree->set_view_mode(GTK_TREE_VIEW_ITEM);
+ tree->set_view_lines(false);
+ entry = ldap_first_entry(this->ld, r_i);
+ while (entry != NULL) {
+ subtreeitem = new Gtk_LdapTreeItem(ldap_get_dn(this->ld, entry), this->par, this->ld);
+ subtree = subtreeitem->getSubtree(this->ld, counter);
+ debug("inserting %s into %s\n",subtreeitem->rdn,this->rdn);
+ tree->append(*subtreeitem);
+ subtreeitem->show();
+ if (subtree != NULL) subtreeitem->set_subtree(*subtree);
+ debug("done\n");
+ entry = ldap_next_entry(this->ld, entry);
+ }
+ // this->set_subtree(*tree);
+ }
+// this->getDetails();
+ debug("done\n");
+ return tree;
+}
+
void Gtk_LdapTreeItem::setType(int t) {
-// cout << "Gtk_LdapTreeItem::setType(" << t << ")" << endl;
+ debug("Gtk_LdapTreeItem::setType(%i)\n", t);
Gtk_Pixmap *xpm_icon;
Gtk_Label *label;
if (this->getchild() != NULL) {
}
int Gtk_LdapTreeItem::showDetails() {
-// cout << "Gtk_LdapTreeItem::showDetails()" << endl;
+ debug("Gtk_LdapTreeItem::showDetails()\n");
if (this->notebook != NULL) {
if (par->viewport->getchild() != NULL) {
par->viewport->remove_c(par->viewport->getchild()->gtkobj());
}
int Gtk_LdapTreeItem::getDetails() {
-// cout << "Gtk_LdapTreeItem::getDetails()" << endl;
+ debug("Gtk_LdapTreeItem::getDetails()\n");
int error, entriesCount;
BerElement *ber;
LDAPMessage *entry;
GList *child_list;
Gtk_Notebook *g;
Gtk_Viewport *viewport;
- error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
- entriesCount = ldap_count_entries(ld, result_identifier);
+ error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &this->result_identifier);
+ entriesCount = ldap_count_entries(this->ld, this->result_identifier);
if (entriesCount == 0) return 0;
notebook = new Gtk_Notebook();
notebook->set_tab_pos(GTK_POS_LEFT);
}
}
this->setType(1);
-// cout << ".";
+ debug("done\n");
return 0;
}
+
+void Gtk_LdapTreeItem::show_impl() {
+ debug("%s showed\n", this->dn);
+ Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
+ sig->show(GTK_WIDGET(gtkobj()));
+}
+
void Gtk_LdapTreeItem::select_impl() {
-// cout << this->dn << " selected" << endl;
+ debug("%s selected\n", this->dn);
// gtk_item_select(GTK_ITEM(GTK_TREE_ITEM(this->gtkobj())));
Gtk_c_signals_Item *sig=(Gtk_c_signals_Item *)internal_getsignalbase();
if (!sig->select) return;
}
void Gtk_LdapTreeItem::collapse_impl() {
-// cout << this->dn << " collapsed" << endl;
+ debug("%s collapsed\n", this->dn);
Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
if (!sig->collapse) return;
sig->collapse(GTK_TREE_ITEM(gtkobj()));
}
void Gtk_LdapTreeItem::expand_impl() {
-// cout << this->dn << " expanded" << endl;
+ debug("%s expanded\n",this->dn);
+ Gtk_LdapTreeItem *item;
+ G_List<GtkWidget> *list;
+ Gtk_Tree *tree;
Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
if (!sig->expand) return;
sig->expand(GTK_TREE_ITEM(gtkobj()));
#ifndef GTK_LDAPTREEITEM_H
#define GTK_LDAPTREEITEM_H
#include "gtk.h"
+#include "utils.h"
#include <My_Window.h>
+#include <Gtk_LdapTree.h>
#include <lber.h>
#include <ldap.h>
-/*#include "XPMLabelBox.h"*/
#include "icons/root_node.h"
#include "icons/branch_node.h"
#include "icons/leaf_node.h"
#define LEAF_NODE 3
class My_Window;
+class Gtk_LdapTree;
class Gtk_LdapTreeItem : public Gtk_TreeItem {
public:
Gtk_Notebook *notebook;
Gtk_HBox *xpm_label;
Gtk_LdapTreeItem();
- Gtk_LdapTreeItem(char *c, My_Window *w);
+ Gtk_LdapTreeItem(char *c, My_Window *w, LDAP *ld);
Gtk_LdapTreeItem(GtkTreeItem *t);
~Gtk_LdapTreeItem();
+ Gtk_LdapTree* getSubtree(LDAP *ld, int i);
void setType(int t);
int getDetails();
int showDetails();
+ void show_impl();
void select_impl();
void collapse_impl();
void expand_impl();
HOME_LOCATION=$(shell pwd)
CC= gcc
CPLUS= g++
-OPTS=-g -DmyDEBUG
+OPTS=-g
INCLUDES=`gtkmm-config --cflags` -I.
LDFLAGS=`gtkmm-config --libs` -L/usr/lib -L/usr/X11/lib -L/usr/local/gnome/lib -L/usr/local/ldap/lib -lldap -llber -L/usr/local/kerberos/lib -lkrb5 -lkrb4
LIBS=-lXext -lgtkmm -lX11 -lXt -lXxf86dga
.EXPORT_ALL_VARIABLES:
-SOURCES= My_Window.cc Gtk_LdapTreeItem.cc Gtk_LdapServer.cc main.cc
-OBJECTS= My_Window.o Gtk_LdapTreeItem.o Gtk_LdapServer.o main.o
+SOURCES= My_Window.cc Gtk_LdapTree.cc Gtk_LdapTreeItem.cc Gtk_LdapServer.cc utils.cc main.cc
+OBJECTS= My_Window.o Gtk_LdapTree.o Gtk_LdapTreeItem.o Gtk_LdapServer.o utils.o main.o
################################################################################
// printf("%i results\n", entriesCount);
s = ldap_explode_dn(b_d, 1);
c = g_strdup_printf("%s", s[0]);
- treeitem = new Gtk_LdapTreeItem(c, p);
+ treeitem = new Gtk_LdapTreeItem(c, p, l_i);
treeitem->dn = b_d; treeitem->ld = l_i;
treeresult = new Gtk_LdapItem();
treeitem->getDetails();
tree = new Gtk_Tree();
treeitem = new Gtk_LdapServer(window, host, port);
+ subtree = treeitem->getSubtree();
tree->append(*treeitem);
+ treeitem->set_subtree(*subtree);
treeitem->show();
viewport = new Gtk_Viewport();
viewport->add(tree);