Commit 463f4f97 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Update contrib to latest -devel.

parent e02de533
ChangeLog for gtk-tool ChangeLog for gtk-tool
29/11/1998 - Pele
* Added Gtk_LdapServer class
* Started using cn=config, ldap_get_option (not sure about get_option
though, cn=config looks much nicer for the future-proofing)
* Can traverse, display and serve two (or possibly/hopefully) more
databases on the local machine - remote machines also possible -
need to use "-s hostname"
* The program needs the "-s" switch! Without it it won't run (temporary
"feature")
28/11/1998 - Pele 28/11/1998 - Pele
* Fixes, enhancements, started using ldap utility api * Fixes, enhancements, started using ldap utility api
* It now traverses the whole tree at startup, not sure if it's smart * It now traverses the whole tree at startup, not sure if it's smart
......
#include "Gtk_LdapItem.h"
Gtk_LdapItem::Gtk_LdapItem() : Gtk_TreeItem() {
cout << "Gtk_LdapItem()" << endl;
}
Gtk_LdapItem::Gtk_LdapItem(char *c) : Gtk_TreeItem() {
cout << "Gtk_LdapItem(" << c << ")" << endl;
this->dn = c;
}
Gtk_LdapItem::Gtk_LdapItem(Gtk_TreeItem *item) : Gtk_TreeItem(*item) {
cout << "Gtk_LdapItem(*item)" << endl;
}
Gtk_LdapItem::Gtk_LdapItem(Gtk_TreeItem &item) : Gtk_TreeItem(item) {
cout << "Gtk_LdapItem(&item)" << endl;
}
void Gtk_LdapItem::expand_impl() {
cout << this->dn << " expanded" << endl;
}
void Gtk_LdapItem::collapse_impl() {
cout << this->dn << " collapsed" << endl;
}
void Gtk_LdapItem::select_impl() {
cout << this->dn << " selected" << endl;
}
void Gtk_LdapItem::deselect_impl() {
cout << this->dn << " deselected" << endl;
}
void Gtk_LdapItem::toggle_impl() {
cout << this->dn << " toggled" << endl;
}
...@@ -9,5 +9,9 @@ class Gtk_LdapItem { ...@@ -9,5 +9,9 @@ class Gtk_LdapItem {
public: public:
Gtk_Tree *tree; Gtk_Tree *tree;
Gtk_LdapTreeItem *treeitem; Gtk_LdapTreeItem *treeitem;
G_List<gchar> *value_list;
char *attribute_name;
G_List<Gtk_LdapItem> *attribute_list;
char *entry_name;
}; };
#endif #endif
#include "Gtk_LdapServer.h"
#include <gtk--/base.h>
Gtk_LdapServer::Gtk_LdapServer() : Gtk_TreeItem() {
this->hostname = NULL;
this->par = NULL;
this->base_dn = NULL;
this->port = 0;
}
Gtk_LdapServer::Gtk_LdapServer(My_Window *w, char *h, int p) : Gtk_TreeItem() {
this->par = w;
this->hostname = h;
this->port = p;
cout << this->hostname << this->port << endl;
this->getConfig();
}
Gtk_LdapServer::Gtk_LdapServer(GtkTreeItem *t) : Gtk_TreeItem(t) {
}
Gtk_LdapServer::~Gtk_LdapServer() {
cout << "Bye" << endl;
delete this;
}
void Gtk_LdapServer::setType(int t) {
cout << "Gtk_LdapServer::setType(" << t << ")" << endl;
Gtk_Pixmap *xpm_icon;
Gtk_Label *label;
if (this->getchild() != NULL) {
xpm_label = new Gtk_HBox(GTK_HBOX(this->getchild()->gtkobj()));
xpm_label->remove_c(xpm_label->children()->nth_data(0));
xpm_label->remove_c(xpm_label->children()->nth_data(0));
}
else xpm_label = new Gtk_HBox();
cout << this->hostname << endl;
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);
label = new Gtk_Label(this->hostname);
xpm_label->pack_start(*xpm_icon, false, false, 1);
xpm_label->pack_start(*label, false, false, 1);
if (this->getchild() == NULL) this->add(xpm_label);
label->show();
xpm_label->show();
xpm_icon->show();
}
int Gtk_LdapServer::showDetails() {
cout << "Gtk_LdapServer::showDetails()" << endl;
this->getDetails();
/*
if (this->notebook != NULL) {
if (par->viewport->getchild() != NULL) {
par->viewport->remove_c(par->viewport->getchild()->gtkobj());
}
par->viewport->add(this->notebook);
this->notebook->show();
par->viewport->show();
return 0;
}
else this->getDetails();
this->showDetails();
*/
return 0;
}
int Gtk_LdapServer::getConfig() {
cout << "Gtk_LdapServer::getConfig()" << endl;
int error, entriesCount;
LDAPMessage *entry, *result_identifier;
BerElement *ber;
char *attribute, **t;
if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
perror("connection");
}
error = ldap_search_s(this->ld, "cn=config", LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
entriesCount = ldap_count_entries(this->ld, result_identifier);
if (entriesCount == 0) {
return 0;
}
cout << entriesCount << " entry" << endl;
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;
if (strcasecmp(attribute, "database") == 0) {
cout << "have database here" << endl;
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;
for (int i=0; i<this->databases->length(); i++) {
cout << "database(" << i << ") " << this->databases->nth_data(i) << endl;
}
}
}
cout << "entry done" << endl;
}
// cout << "got " << entriesCount << " entries" << endl;
return entriesCount;
}
int Gtk_LdapServer::getDetails() {
cout << "Gtk_LdapServer::getDetails()" << endl;
Gtk_HBox *hbox;
Gtk_VBox *vbox;
Gtk_Label *label;
Gtk_RadioButton *radio1, *radio2;
char *val;
int ival;
if (GTK_TREE_ITEM(this->gtkobj())->subtree == NULL) {
this->getSubtree();
}
/*
cout << "getting ldap options";
vbox = new Gtk_VBox();
opt_util = new LdapOpts();
for (int i=0; i<sizeof(things); i++) {
cout << i << endl;
hbox = new Gtk_HBox();
label = new Gtk_Label(LdapOpts->getOption(things[i]);
hbox->pack_start(*label);
label->show();
int tipus = opt_util->getType(things[i]);
switch (tipus) {
case 0:
ldap_get_option(NULL, things[i], &val);
label = new Gtk_Label(val);
break;
case 1:
ldap_get_option(NULL, numerals[i], &ival);
sprintf(val, "%i", ival);
label = new Gtk_Label(val);
break;
case 2:
ldap_get_option(NULL, booleans[i], &ival);
sprintf(val, "%s", ival == (int) LDAP_OPT_ON ? "on" : "off");
label = new Gtk_Label(val);
break;
default:
break;
}
hbox->pack_start(*label);
label->show();
vbox->pack_start(*hbox);
hbox->show();
}
vbox->border_width(2);
this->notebook = new Gtk_Viewport();
this->notebook->add(*vbox);
vbox->show();
*/
this->setType(1);
return 0;
}
int Gtk_LdapServer::getSubtree() {
cout << "Gtk_LdapServer::getSubtree()" << endl;
Gtk_LdapItem *treeresult;
Gtk_Tree *tree, *subtree;
Gtk_LdapTreeItem *treeitem;
int entries;
cout << "this->hostname=" << this->hostname << endl;
cout << "this->port=" << this->port << endl;
/* if ((this->ld = ldap_open(this->hostname, this->port)) == NULL) {
perror("connection");
}
*/
char *c;
char *tok;
int len = this->databases->length();
cout << "this->databases->length()=" << len << endl;
tree = new Gtk_Tree();
for (int i=0; i<len; i++) {
tok = strdup(this->databases->nth_data(i));
tok = strtok(tok, ":");
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);
tree->append(*treeitem);
if (treeresult->tree != NULL) {
subtree = new Gtk_Tree(*treeresult->tree);
treeitem->set_subtree(*subtree);
}
treeitem->show();
// tree->show();
}
this->set_subtree(*tree);
cout << "getTree() done" << endl;
return 0;
}
void Gtk_LdapServer::select_impl() {
cout << this->hostname << " selected" << endl;
// 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;
sig->select(GTK_ITEM(gtkobj()));
this->showDetails();
}
void Gtk_LdapServer::collapse_impl() {
// cout << this->dn << " collapsed" << endl;
Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
if (!sig->collapse) return;
sig->collapse(GTK_TREE_ITEM(gtkobj()));
// gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
}
void Gtk_LdapServer::expand_impl() {
// cout << this->dn << " expanded" << endl;
Gtk_c_signals_TreeItem *sig=(Gtk_c_signals_TreeItem *)internal_getsignalbase();
if (!sig->expand) return;
sig->expand(GTK_TREE_ITEM(gtkobj()));
// Gtk_Tree *t;
// t = new Gtk_Tree(GTK_TREE(GTK_TREE_ITEM(this->gtkobj())->subtree));
// bool vis = t->visible();
// if (vis == false) {
// gtk_widget_show(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
// cout << this->dn << " expanded" << endl;
// }
// else {
// gtk_widget_hide(GTK_WIDGET(GTK_TREE(GTK_TREE_ITEM (this->gtkobj())->subtree)));
// cout << this->dn << " collapsed" << endl;
// }
}
#ifndef GTK_LDAPSERVER_H
#define GTK_LDAPSERVER_H
#include "gtk.h"
#include <My_Window.h>
/*#include <LdapOpts.h>*/
#include <Gtk_LdapItem.h>
#include <Gtk_LdapTreeItem.h>
#include <lber.h>
#include <ldap.h>
#include "icons/local_server.h"
#include "icons/remote_server.h"
#define LOCAL_SERVER 1
#define REMOTE_SERVER 2
class My_Window;
class Gtk_LdapServer : public Gtk_TreeItem {
public:
char *dn;
char *hostname;
LDAPMessage **thing;
LDAP *ld;
char *host;
char *base_dn;
int c, port;
My_Window *par;
// Gtk_Notebook *notebook;
Gtk_Viewport *notebook;
Gtk_HBox *xpm_label;
// Gtk_Tree *subtree;
G_List<char> *databases;
Gtk_LdapServer();
Gtk_LdapServer(My_Window *w, char *c, int p);
Gtk_LdapServer(GtkTreeItem *t);
~Gtk_LdapServer();
void setType(int t);
int getConfig();
int getSubtree();
int getDetails();
int showDetails();
void select_impl();
void collapse_impl();
void expand_impl();
};
#endif
...@@ -20,7 +20,7 @@ Gtk_LdapTreeItem::~Gtk_LdapTreeItem() { ...@@ -20,7 +20,7 @@ Gtk_LdapTreeItem::~Gtk_LdapTreeItem() {
} }
void Gtk_LdapTreeItem::setType(int t) { void Gtk_LdapTreeItem::setType(int t) {
cout << "Gtk_LdapTreeItem::setType(" << t << ")" << endl; // cout << "Gtk_LdapTreeItem::setType(" << t << ")" << endl;
Gtk_Pixmap *xpm_icon; Gtk_Pixmap *xpm_icon;
Gtk_Label *label; Gtk_Label *label;
if (this->getchild() != NULL) { if (this->getchild() != NULL) {
...@@ -46,7 +46,7 @@ void Gtk_LdapTreeItem::setType(int t) { ...@@ -46,7 +46,7 @@ void Gtk_LdapTreeItem::setType(int t) {
} }
int Gtk_LdapTreeItem::showDetails() { int Gtk_LdapTreeItem::showDetails() {
cout << "Gtk_LdapTreeItem::showDetails()" << endl; // cout << "Gtk_LdapTreeItem::showDetails()" << endl;
if (this->notebook != NULL) { if (this->notebook != NULL) {
if (par->viewport->getchild() != NULL) { if (par->viewport->getchild() != NULL) {
par->viewport->remove_c(par->viewport->getchild()->gtkobj()); par->viewport->remove_c(par->viewport->getchild()->gtkobj());
...@@ -58,10 +58,11 @@ int Gtk_LdapTreeItem::showDetails() { ...@@ -58,10 +58,11 @@ int Gtk_LdapTreeItem::showDetails() {
} }
else this->getDetails(); else this->getDetails();
this->showDetails(); this->showDetails();
return 0;
} }
int Gtk_LdapTreeItem::getDetails() { int Gtk_LdapTreeItem::getDetails() {
cout << "Gtk_LdapTreeItem::getDetails()" << endl; // cout << "Gtk_LdapTreeItem::getDetails()" << endl;
int error, entriesCount; int error, entriesCount;
BerElement *ber; BerElement *ber;
LDAPMessage *entry; LDAPMessage *entry;
...@@ -99,7 +100,7 @@ int Gtk_LdapTreeItem::getDetails() { ...@@ -99,7 +100,7 @@ int Gtk_LdapTreeItem::getDetails() {
} }
} }
this->setType(1); this->setType(1);
cout << "."; // cout << ".";
return 0; return 0;
} }
void Gtk_LdapTreeItem::select_impl() { void Gtk_LdapTreeItem::select_impl() {
......
#include "LdapEntry.h"
LdapEntry* LdapEntry::get_entries(LDAP *ld, char *base_dn, int level,char *filter) {
printf("get_entries(%s)\n", base_dn);
LDAPMessage **result, *entry;
Entry *thing;
char *pele;
int res;
res = ldap_search(ld, base_dn, level, filter, NULL, 0);
res = ldap_result(ld, res, 1, NULL, result);
printf("%s\n", ldap_err2string(ldap_result2error(ld, *result, 1)));
int num_entries = ldap_count_entries(ld, *result);
printf("%i results\n", num_entries);
int i=0;
entry = ldap_first_entry(ld, *result);
thing->dn = ldap_get_dn(ld, entry);
pele = ldap_get_dn(ld, entry);
printf("%s\n", thing->dn);
while (entry) {
printf("Child %i\n", i);
thing->child[i] = get_entries(ld, pele, LDAP_SCOPE_ONELEVEL, filter);
i++;
entry = ldap_next_entry(ld, entry);
}
return thing;
}
Gtk_Tree *LdapEntry::make_tree(Entry *thing) {
Gtk_Tree *tree, **subtree;
Gtk_TreeItem *treeitem;
gchar *c;
tree = new Gtk_Tree();
tree->set_selection_mode(GTK_SELECTION_BROWSE);
tree->set_view_mode(GTK_TREE_VIEW_ITEM);
tree->set_view_lines(false);
c = g_strdup_printf("%s", thing->dn);
printf("%s\n", c);
treeitem = new Gtk_TreeItem(c);
tree->append(treeitem);
treeitem->show();
int i=0;
while (thing->child[i]) {
subtree[i] = make_tree(thing->child[i]);
treeitem->set_subtree(subtree[i]);
i++;
}
tree->show();
return tree;
}
#ifdef MY_LDAP_ENTRY_H
#define MY_LDAP_ENTRY_H
#include "common.h"
#include "gtk.h"
#include <lber.h>
#include <ldap.h>
class LdapEntry {
public:
char *dn;
LdapEntry **children;
LdapEntry* get_entries(LDAP *ld, char *base_dn, int level, char *filter);
Gtk_Tree* make_tree(LdapEntry *thing);
}
#endif
...@@ -8,8 +8,8 @@ LIBS=-lXext -lgtkmm -lX11 -lXt -lXxf86dga ...@@ -8,8 +8,8 @@ LIBS=-lXext -lgtkmm -lX11 -lXt -lXxf86dga
.EXPORT_ALL_VARIABLES: .EXPORT_ALL_VARIABLES:
SOURCES= My_Window.cc Gtk_LdapTreeItem.cc main.cc SOURCES= My_Window.cc Gtk_LdapTreeItem.cc Gtk_LdapServer.cc main.cc
OBJECTS= My_Window.o Gtk_LdapTreeItem.o main.o OBJECTS= My_Window.o Gtk_LdapTreeItem.o Gtk_LdapServer.o main.o
################################################################################ ################################################################################
......
#include "My_Scroller.h"
#include <gtk--/container.h>
void My_Scroller::remove_child(int i) {
cout << "Unparenting child[" << i << "]" << endl;
this->children[i]->unparent();
cout << "Deleting child[" << i << "] from children" << endl;
// this->remove(children()->first());
delete this->children[i];
cout << "done" << endl;
}
void My_Scroller::add_child(Gtk_Widget *w) {
cout << "My_Scroller::add_child()" << endl;
// w->reparent(this);
this->add(w);
cout << "done" << endl;
this->children[0] = w;
}
#ifndef MY_SCROLLER_H
#define MY_SCROLLER_H
#include <gtk--/container.h>
#include "gtk.h"
class My_Scroller : public Gtk_ScrolledWindow {
public:
Gtk_Widget *children[2];
void add_child(Gtk_Widget *w);
void remove_child(int i);
};
#endif
...@@ -4,6 +4,8 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) { ...@@ -4,6 +4,8 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) {
cout << "My_Window(t)" << endl; cout << "My_Window(t)" << endl;
Gtk_VBox *main_hbox; Gtk_VBox *main_hbox;
Gtk_HBox *top_hbox; Gtk_HBox *top_hbox;
Gtk_Menu *menu;
Gtk_MenuItem *file_menu, *menuitem;
pane = new Gtk_HPaned(); pane = new Gtk_HPaned();
this->scroller = new Gtk_ScrolledWindow(); this->scroller = new Gtk_ScrolledWindow();
...@@ -21,6 +23,18 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) { ...@@ -21,6 +23,18 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) {
this->scroller2->show(); this->scroller2->show();
top_hbox = new Gtk_HBox(); top_hbox = new Gtk_HBox();
menu = new Gtk_Menu();
menuitem = new Gtk_MenuItem("Quit");
menu->append(*menuitem);
this->menubar = new Gtk_MenuBar();
file_menu = new Gtk_MenuItem("File");
file_menu->set_submenu(menu);
this->menubar->append(*file_menu);
menuitem->show();
menu->show();
file_menu->show();
// top_hbox->pack_start(*this->menubar, TRUE, TRUE, 1);
this->menubar->show();
this->urlfield = new Gtk_Entry(); this->urlfield = new Gtk_Entry();
top_hbox->pack_start(*this->urlfield, TRUE, TRUE, 1); top_hbox->pack_start(*this->urlfield, TRUE, TRUE, 1);
this->urlfield->show(); this->urlfield->show();
...@@ -30,6 +44,7 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) { ...@@ -30,6 +44,7 @@ My_Window::My_Window(GtkWindowType t) : Gtk_Window(t) {
this->display_button->show(); this->display_button->show();
main_hbox = new Gtk_VBox(); main_hbox = new Gtk_VBox();
main_hbox->pack_start(*this->menubar, FALSE, FALSE, 1);
main_hbox->pack_start(*top_hbox, FALSE, TRUE, 1); main_hbox->pack_start(*top_hbox, FALSE, TRUE, 1);
main_hbox->pack_end(*pane, TRUE, TRUE, 1); main_hbox->pack_end(*pane, TRUE, TRUE, 1);
top_hbox->show(); top_hbox->show();
...@@ -54,7 +69,7 @@ void My_Window::expand(Gtk_TreeItem *t) { ...@@ -54,7 +69,7 @@ void My_Window::expand(Gtk_TreeItem *t) {
g_print("%s selected\n", name); g_print("%s selected\n", name);
} }
gint My_Window::delete_event_impl(GdkEventAny *) { gint My_Window::delete_event_impl(GdkEventAny*) {
Gtk_Main::instance()->quit(); Gtk_Main::instance()->quit();
return 0; return 0;
} }
......
...@@ -19,6 +19,7 @@ public: ...@@ -19,6 +19,7 @@ public:
Gtk_Entry *urlfield; Gtk_Entry *urlfield;
Gtk_Button *display_button; Gtk_Button *display_button;
Gtk_Paned *pane;