-Copyright 1998 Predrag Balorda, London, UK
+Copyright 1998,1999,2000 Predrag Balorda, London, UK
All rights reserved.
Redistribution and use in source and binary forms are permitted only
ChangeLog for gtk-tool
+03/01/2000 - Pele
+ * Fixed localtime() bug in Linux ?;)
+
+03/01/19100 - Pele
+ * Auto-select the first server if any supplied as arguments
+ * A visual bug in the former (deselect a bit messy)
+ * Follow aliases (not tested with leaf nodes though)
+ * "Show Debug Info" in "Options" menu
+
28/12/1999 - Pele
* Updated Gtk-- API from 1.0 to 1.1
* Added -d switch (for debugging info)
Gtk_Pixmap *xpm_icon;
Gtk_Label *label;
char *c = NULL;
- if (this->get_child() != NULL) {
- this->remove();
- /*
- //xpm_label = new Gtk_HBox(GTK_HBOX(this->get_child()->gtkobj()));
- xpm_label = new Gtk_HBox(this->get_child());
- xpm_label->remove_c(xpm_label->children()->nth_data(0));
- xpm_label->remove_c(xpm_label->children()->nth_data(0));
- */
- }
+ if (this->get_child() != NULL) this->remove();
xpm_label = new Gtk_HBox();
debug(this->hostname);
if (strcasecmp(this->hostname,"localhost") == 0)
- //xpm_icon=new Gtk_Pixmap(*xpm_label, local_server);
xpm_icon=new Gtk_Pixmap(local_server);
- else //xpm_icon=new Gtk_Pixmap(*xpm_label, remote_server);
- xpm_icon=new Gtk_Pixmap(remote_server);
+ else xpm_icon=new Gtk_Pixmap(remote_server);
// sprintf(c, "%s:%i", this->hostname, this->port);
// printf("%s\n", c);
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->get_child() == NULL) this->add(*xpm_label);
- //label->show();
- //xpm_label->show();
- //xpm_icon->show();
this->show_all();
}
debug("Have a notebook here");
if (par->viewport2->get_child() != NULL) {
debug(" and viewport has children");
- par->viewport2->remove(); //par->viewport2->get_child());
+ par->viewport2->remove();
debug(" which have been removed\n");
}
else debug(" and viewport without children\n");
par->viewport2->add(*this->notebook);
- //this->notebook->show();
- //par->viewport2->show();
- //return 0;
}
this->show_all();
debug("done\n");
return 0;
}
+int Gtk_LdapServer::getMonitor() {
+ debug("Gtk_LdapServer::getMonitor()\n");
+ 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=monitor", LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &result_identifier);
+ entriesCount = ldap_count_entries(this->ld, result_identifier);
+ if (entriesCount == 0) {
+ return 0;
+ }
+
+ debug("%i tree(s)\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)) {
+ debug("Attrib: %s\n", attribute);
+ if (strcasecmp(attribute, "database") == 0) {
+ debug("have database here\n");
+ this->databases = NULL;
+ t = ldap_get_values(this->ld, entry, attribute);
+ for (int i=0; i<ldap_count_values(t); i++) {
+ this->databases = g_list_append(this->databases, strdup(t[i]));
+ }
+ ldap_value_free(t);
+ debug("databases loaded\n");
+ GList *t;
+ for (int i=0;i>g_list_length(this->databases);i++) {
+ t = g_list_nth(this->databases, i);
+ debug("database(%i) %s\n", i, (char*) t->data);
+ }
+ }
+ }
+ debug("entry done\n");
+ }
+ return entriesCount;
+}
+
int Gtk_LdapServer::getConfig() {
debug("Gtk_LdapServer::getConfig()\n");
int error, entriesCount;
return 0;
}
- debug("%i entry\n", entriesCount);
+// debug("%i tree(s)\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)) {
debug("Attrib: %s\n", attribute);
if (strcasecmp(attribute, "database") == 0) {
debug("have database here\n");
- //this->databases = new GList<char>;
this->databases = NULL;
t = ldap_get_values(this->ld, entry, attribute);
for (int i=0; i<ldap_count_values(t); i++) {
this->databases = g_list_append(this->databases, strdup(t[i]));
- //this->databases->push_back(*strdup(t[i]));
}
+ this->databases = g_list_append(this->databases, "ldbm : cn=config");
+ this->databases = g_list_append(this->databases, "ldbm : cn=monitor");
ldap_value_free(t);
debug("databases loaded\n");
GList *t;
- for (int i=0;i>g_list_length(this->databases);i++) {
+ for (int i=0;i<g_list_length(this->databases);i++) {
t = g_list_nth(this->databases, i);
-// debug("database(%i) %s\n", i, ((gchar*) t->data));
+ debug("database(%i) %s\n", i, (char*) t->data);
}
}
}
debug("entry done\n");
}
-// debug("got %i entries\n", entriesCount);
return entriesCount;
}
Gtk_HScale *scale;
Gtk_Adjustment *adjustment;
char *description = NULL, *s_value = NULL;
- int i_value;
+// int i_value;
string label_string;
int things[10] = {
table = new Gtk_Table(10, 1, TRUE);
for (int i=0; i<10; i++) {
+ int i_value;
// debug("%i\n", i);
hbox = new Gtk_HBox(TRUE, 2);
hbox->set_border_width(2);
case 3:
ldap_get_option(this->ld, things[i], &i_value);
debug("i_value: %s\n", i_value);
- adjustment = new Gtk_Adjustment(i_value, 1.0, 20.0, 1.0, 1.0, 0.0);
+ adjustment = new Gtk_Adjustment(i_value, 0.0, 20.0, 1.0, 1.0, 0.0);
scale = new Gtk_HScale(*adjustment);
scale->set_update_policy(GTK_UPDATE_CONTINUOUS);
scale->set_value_pos(GTK_POS_TOP);
subtree = treeitem->getSubtree(this->ld, 1);
debug("inserting %s into %s\n", treeitem->rdn, this->hostname);
tree->append(*treeitem);
- treeitem->set_subtree(*subtree);
+ if (subtree != NULL) treeitem->set_subtree(*subtree);
treeitem->show();
// tree->show();
}
Gtk_LdapServer(GtkTreeItem *t);
~Gtk_LdapServer();
void setType(int t);
+ int getMonitor();
int getConfig();
Gtk_Tree* getSubtree();
#ifndef LDAP_GET_OPT
Gtk_LdapTree *tree;
Gtk_LdapTreeItem *item = NULL;
Gtk_LdapTree::ItemList &items = this->tree();
- Gtk_LdapTree::ItemList::iterator i = items.begin();
+ Gtk_LdapTree::ItemList::iterator i; // = items.begin();
debug("iterator\n");
- for (i=items.begin(); i!=items.end();i++) {
+ for (i=items.begin(); i!=items.end();++i) {
+// while (i!=items.end()) {
item = (Gtk_LdapTreeItem *)(*i);
debug("new item\n");
debug("#%s#\n", item->dn);
if (counter <= 0) return NULL;
if (this->gtkobj()->subtree != NULL) {
//return (Gtk_LdapTree *)GTK_TREE(this->gtkobj()->subtree);
+ debug("This item has a subtree\n");
return (Gtk_LdapTree *)this->get_subtree(); //gtkobj()->subtree);
}
counter--;
int entriesCount = 0, error;
this->ld = ld;
- error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_ONELEVEL, "objectclass=*", NULL, 0, &r_i);
+ if (this->dn == "cn=config" || this->dn == "cn=monitor") error = ldap_search_s(this->ld, this->dn, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, &r_i);
+ else {
+ if (strcasecmp(this->objectClass,"alias") == 0) error = ldap_search_s(this->ld, this->getAttribute("aliasedobjectname"), LDAP_SCOPE_ONELEVEL, "objectclass=*", NULL, 0, &r_i);
+ else 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);
tree->set_view_lines(false);
entry = ldap_first_entry(this->ld, r_i);
// float i = 1;
- // float percent = 100/entriesCount;
- // cout << "percent is " << percent << endl;
- // this->par->progress.update(0);
+ gfloat percent = 100/entriesCount;
+ cout << "percent is " << percent << endl;
+ // this->par->progress.set_percentage(percent/100);
// this->par->progress.show();
while (entry != NULL) {
subtreeitem = new Gtk_LdapTreeItem(ldap_get_dn(this->ld, entry), this->par, this->ld);
else if (strcasecmp(this->objectClass,"rfc822mailgroup") == 0)
//xpm_icon=new Gtk_Pixmap(*xpm_label, rfc822mailgroup_node);
xpm_icon=new Gtk_Pixmap(rfc822mailgroup_node);
+ else if (strcasecmp(this->objectClass,"LDAPsubentry") == 0)
+ xpm_icon=new Gtk_Pixmap(monitor);
else //xpm_icon=new Gtk_Pixmap(*xpm_label, general_node);
xpm_icon=new Gtk_Pixmap(general_node);
label = new Gtk_Label(this->rdn);
return 0;
}
+char* Gtk_LdapTreeItem::getAttribute(char *c) {
+ int entriesCount, error;
+ BerElement *ber;
+ LDAPMessage *entry;
+ char *attribute, **values;
+ 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;
+ for (entry = ldap_first_entry(ld, result_identifier); entry != NULL; entry = ldap_next_entry(ld, result_identifier)) {
+ for (attribute = ldap_first_attribute(ld, entry, &ber); attribute != NULL; attribute = ldap_next_attribute(ld, entry, ber)) {
+ values = ldap_get_values(ld, entry, attribute);
+ if (strcasecmp(attribute, "aliasedobjectname") == 0) {
+ this->aliasedObjectName = strdup(values[0]);
+ }
+ }
+ }
+ return this->aliasedObjectName;
+}
+
int Gtk_LdapTreeItem::getDetails() {
debug("Gtk_LdapTreeItem::getDetails()\n");
int error, entriesCount;
Gtk_CList *table;
Gtk_Label *label;
GList *child_list;
-// Gtk_Notebook *g;
Gtk_Viewport *viewport;
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);
#include "icons/alias_node.h"
#include "icons/rfc822mailgroup_node.h"
#include "icons/general_node.h"
+#include "icons/monitor.h"
#define ROOT_NODE 1
#define BRANCH_NODE 2
char *dn;
char *rdn;
char *objectClass;
+ char *aliasedObjectName;
LDAP *ld;
LDAPMessage *result_identifier;
My_Window *par;
Gtk_LdapTreeItem(char *c, My_Window *w, LDAP *ld);
Gtk_LdapTreeItem(GtkTreeItem *t);
~Gtk_LdapTreeItem();
+ gchar* getAttribute(char *c);
Gtk_LdapTree* getSubtree(LDAP *ld, int i);
void setType(int t);
int getDetails();
Please read this carefully
To copile gtk-tool, although OpenLDAP in itself is a very out-of-the-box
-straightforward piece of code to compile gtk-tool isn't. You will require the
-latest Gtk+/Gtk-- CVS trees on your machine - as of 11 February 1999 so your
-last weeks' checkout is more than likely allready useless - not my problem, they
-promise API freezes and then don't stick to it...what can I say...a hint for
-the gtk people - Java 1.1
+straightforward piece of code to compile gtk-tool isn't. You will require following:
+
+ Gtk+1.2.x
+ Gtk--1.1.x
So, latest gtk stuff and if you successfully compiled and installed all that it should be easy. If you didn't I really hope you can take some comfort in that I have provided you with some snapshots of what the thing actually looks like. I hope in the near future I would be able to provide you with a static binary..next week perhaps..I don't know, I'm looking for a job right now so no promises...
+(I'm no longer looking for a job but the situation with spare time seems even worse - I wish I could do this full-time guys, I really do...)
Pele
pele@openldap.org
menuitem->activate.connect(slot(this,&My_Window::addServer));
//connect_to_method(menuitem->activate, this, &addServer);
sub_menu->append(*menuitem);
- menuitem->show();
+// menuitem->show();
new_menu = new Gtk_MenuItem("New...");
new_menu->set_submenu(*sub_menu);
- sub_menu->show();
+// sub_menu->show();
menu->append(*new_menu);
- new_menu->show();
+// new_menu->show();
menuitem = new Gtk_MenuItem("Quit");
menuitem->activate.connect(Gtk_Main::quit.slot());
menu->append(*menuitem);
- menuitem->show();
+// menuitem->show();
this->menubar = new Gtk_MenuBar();
file_menu = new Gtk_MenuItem("File (?)");
file_menu->set_submenu(*menu);
this->menubar->append(*file_menu);
- menu->show();
+// menu->show();
menu = new Gtk_Menu();
check_menuitem = new Gtk_CheckMenuItem("Show Debug Info");
options_menu = new Gtk_MenuItem("Options");
options_menu->set_submenu(*menu);
this->menubar->append(*options_menu);
- menu->show();
+// menu->show();
- file_menu->show();
- options_menu->show();
+// file_menu->show();
+// options_menu->show();
// top_hbox->pack_start(*this->menubar, TRUE, TRUE, 1);
- this->menubar->show();
+// this->menubar->show();
this->urlfield = new Gtk_Entry();
top_hbox->pack_start(*this->urlfield, TRUE, TRUE, 1);
- this->urlfield->show();
+// this->urlfield->show();
this->display_button = new Gtk_Button("Query Server");
this->display_button->clicked.connect(slot(this, &My_Window::getHost));
//connect_to_method(this->display_button->clicked, this, &getHost);
top_hbox->pack_end(*this->display_button, FALSE, FALSE, 1);
- this->display_button->show();
+// this->display_button->show();
this->status = new Gtk_Statusbar();
+// this->progress = new Gtk_ProgressBar();
+// this->status->add(*progress);
+// this->progress->show();
bottom_hbox = new Gtk_VBox();
bottom_hbox->pack_start(*pane, TRUE, TRUE, 1);
bottom_hbox->pack_end(*status, FALSE, TRUE, 1);
pane->show();
- status->show();
+// status->show();
main_hbox = new Gtk_VBox();
main_hbox->pack_start(*this->menubar, FALSE, FALSE, 1);
this->add(*main_hbox);
this->destroy.connect(Gtk_Main::quit.slot());
main_hbox->show();
+// this->show_all();
}
My_Window::~My_Window() {
tree->show();
this->viewport->show();
this->scroller->show();
+ treeitem->select();
}
void My_Window::setDebug() {
Gtk_InputDialog *dialog;
Gtk_Paned *pane;
Gtk_MenuBar *menubar;
-// Gtk_ProgressBar progress;
+// Gtk_ProgressBar *progress;
Gtk_Statusbar *status;
My_Window(GtkWindowType t);
~My_Window();
-README for gtk-tool v0.6a
+README for gtk-tool v0.7a
-This package has been tested and run with the latest Gtk+/Gtk--
+This package has been tested and run with the latest Gtk+1.2/Gtk--1.1
OpenLDAP 2.0-devel. It should also compile (i.e. it is backward-compatible) with
the U-MICH (old) API but it has not been tested (read compiled) - however the siplicity of the "problem" and a few ifdefs lead me to believe everything should
be allright with gtk-tool now. This thing doesn't run as it should, please
etc...
It does not accept -b switch as it no longer needs it to aquire databases.
+There's also a -d <level> switch (try it with -d 1) for all the debug info.
But please feel free to add whatever else you consider neccessary to
understanding how this thing works. Enjoy, and I hope this can be useful to
you in some miniscule way.
Please someone test this with old U-MICH API - hopefully all is as it should be.
-Odd behaviour with tabbed panes - labels misteriously dissapear after you
-select a node for the second time 'round. Anyone any ideas on this?
-
Priorities:
Now that we have cn=config we can start using ldap_get_option propperly
and be able to run/stop server from the gtk-tool. Other things like
new entries would now come in handy.
Implement searches
- port to autoconf (anyone? it should be easy)
+ Integrate with OpenLDAP build - autoconf stuff (anyone?)
Optional:
comments in the source code
port it to NT so we can use it with the NT port of OpenLDAP
- (is there a NT port of Gtk+?)
+ (they say that there is an NT port of Gtk+?)
Pele
pele@openldap.org
int main(int argc, char **argv) {
My_Window *window;
Gtk_LdapItem *treeresult;
- Gtk_Tree *tree, *subtree;
+ Gtk_Tree *tree = NULL, *subtree = NULL;
Gtk_Tree *machine, *machinetree;
Gtk_LdapServer *server;
Gtk_Viewport *viewport;
port = atoi(optarg); break;
case 'h':
default:
- fprintf(stderr, "Usage: %s ([-s server[:port]])*\n", argv[0]);
+ fprintf(stderr, "Usage: %s [-d level] [-s server[:port]]*\n", argv[0]);
exit(-1);
}
fprintf(stderr,"b");
fprintf(stderr,"Why isn't your LDAP_OPT_HOST_NAME defined?\n");
#endif
fprintf(stderr,"Supply me with a host please (hint: use -s)\n");
- // exit(1);
}
} else {
for (int f=0; f<g_list_length(hosts); f++) {
window = new My_Window(GTK_WINDOW_TOPLEVEL);
-// viewport = new Gtk_Viewport();
if (hosts!=NULL) {
tree = new Gtk_Tree();
for (int f=0; f<g_list_length(hosts); f++) {
server->show();
}
window->viewport->add(*tree);
- tree->show();
+// tree->show();
}
-// window->scroller->add(viewport);
- window->viewport->show();
- window->scroller->show();
+// window->viewport->show();
+// window->scroller->show();
+
+ //Select first server
+ if (tree != NULL) {
+ Gtk_LdapTree::ItemList &items = tree->tree();
+ Gtk_LdapTree::ItemList::iterator i = items.begin();
+ server = (Gtk_LdapServer *)(* i);
+ server->select_impl();
+ }
window->set_title("gtk-tool");
window->activate();
window->set_usize(600, 500);
- window->show();
+ window->show_all();
m.run();
return 0;