]> git.sur5r.net Git - openldap/blob - contrib/gtk-tool/main.cc
Annoying little son of a `free' BUG fixed.
[openldap] / contrib / gtk-tool / main.cc
1 #include "cpluscommon.h"
2 #include "gtk.h"
3 #include <lber.h>
4 #include <ldap.h>
5 #include <My_Window.h>
6 #include <Gtk_LdapItem.h>
7 #include <Gtk_LdapServer.h>
8
9 int main(int argc, char **argv) {
10         My_Window *window;
11         Gtk_LdapItem *treeresult;
12         Gtk_Tree *tree, *subtree;
13         Gtk_Tree *machine, *machinetree;
14         Gtk_LdapServer *treeitem;
15         Gtk_Viewport *viewport;
16         char *host = NULL, *prt = NULL;
17         char *base_dn = NULL;
18         int c, port = 0;
19         G_List<char> *hosts;
20         int host_count = 0;
21         char *pair[2];
22
23         hosts = new G_List<char>();
24         while ((c = getopt(argc, argv, "s:p:h")) != -1) {
25                 switch (c) {
26                         case 's':
27                         debug("host\n");
28                                 hosts = hosts->append(strdup(optarg));
29                                 break;
30                         case 'p':
31                                 port = atoi(optarg); break;
32                         case 'h':
33                         default:
34                                 fprintf(stderr, "Usage: %s ([-s server[:port]])*\n", argv[0]);
35                                 exit(-1);
36                 }
37         }
38         debug("%i hosts\n", hosts->length());
39         for (int f=0; f<hosts->length(); f++) {
40                 debug("%s\n", hosts->nth_data(f));
41         }
42         if (hosts->length() == 0) {
43 #ifdef LDAP_GET_OPT
44                 printf("Supply me with a host please (hint: use -s\n");
45                 exit(0);
46 #else
47                 ldap_get_option(NULL, LDAP_OPT_HOST_NAME, host);
48                 hosts = hosts->append(host);
49 #endif /* LDAP_GET_OPT */
50         }       
51         if (port == 0) port = LDAP_PORT;
52
53         Gtk_Main m(&argc, &argv);
54
55         window = new My_Window(GTK_WINDOW_TOPLEVEL);
56
57 //      viewport = new Gtk_Viewport();
58         if (hosts!=NULL) {
59                 tree = new Gtk_Tree();
60                 for (int f=0; f<hosts->length(); f++) {
61                         host = strtok(hosts->nth_data(f), ":");
62                         prt = strtok(NULL, "\0");
63                         if (prt != NULL) port = atoi(prt);
64                         else port = LDAP_PORT;
65                         treeitem = new Gtk_LdapServer(window, host, port);
66                         subtree = treeitem->getSubtree();
67                         tree->append(*treeitem);
68                         treeitem->set_subtree(*subtree);
69                         treeitem->show();
70                 }
71                 window->viewport->add(tree);
72                 tree->show();
73         }
74
75 //      window->scroller->add(viewport);
76         window->viewport->show();
77         window->scroller->show();
78
79         window->set_title("gtk-tool");
80         window->activate();
81         window->set_usize(600, 500);
82         window->show();
83
84         m.run();
85         return 0;
86 }