[gq-commit] gq/src common.h,1.28,1.29 configfile.c,1.43,1.44 configfile.h,1.30,1.31 gq-xml.c,1.5,1.6
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-17 06:52:50
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv30556 Modified Files: common.h configfile.c configfile.h gq-xml.c prefs.c util.c util.h Log Message: * Added a "canonical name" to the struct ldapserver. This is the LDAP URL of the server inclluding the port. It is always possible to generate such a canonical name. This makes it possible to find the proper user settings for a server a referral points to if the referred-to server is one that is used by the user anyway. To maintain the internal state of the ldapserver struct the canonicalize_ldapserver function should be called whenever the data concerning the ldapserver change. Index: common.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/common.h,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** common.h 17 Oct 2003 05:47:49 -0000 1.28 --- common.h 17 Oct 2003 06:52:39 -0000 1.29 *************** *** 1,5 **** /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2001 Bert Vermeulen This program is released under the Gnu General Public License with --- 1,6 ---- /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2003 Bert Vermeulen ! Copyright (C) 2002-2003 Peter Stamfest This program is released under the Gnu General Public License with *************** *** 89,92 **** --- 90,101 ---- int show_ref; int hide_internal; + + /* the canonical name of the host. Essentially this is the + corresponding LDAP URI for the ldaphost/port combination - + maintained through canonicalize_ldapserver() */ + char *canon_name; + + /* a flag indicating if ldaphost seems to be a URI or not */ + int is_uri; LDAP *connection; Index: configfile.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/configfile.c,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** configfile.c 17 Oct 2003 06:40:25 -0000 1.43 --- configfile.c 17 Oct 2003 06:52:39 -0000 1.44 *************** *** 101,104 **** --- 101,109 ---- newserver->hide_internal = DEFAULT_HIDE_INTERNAL; newserver->show_ref = DEFAULT_SHOW_REF; + + /* dynamic information */ + newserver->canon_name = g_strdup(""); + newserver->is_uri = 0; + newserver->connection = NULL; newserver->incarnation = 0; *************** *** 112,115 **** --- 117,175 ---- } + /* saves typing */ + #define DEEPCOPY(t,s,n) t->n = s->n ? g_strdup(s->n) : NULL + #define SHALLOWCOPY(t,s,n) t->n = s->n + void copy_ldapserver(struct ldapserver *target, + const struct ldapserver *source) + { + DEEPCOPY (target, source, name); + DEEPCOPY (target, source, ldaphost); + SHALLOWCOPY(target, source, ldapport); + DEEPCOPY (target, source, basedn); + DEEPCOPY (target, source, binddn); + DEEPCOPY (target, source, bindpw); + DEEPCOPY (target, source, pwencoding); + DEEPCOPY (target, source, enteredpw); + SHALLOWCOPY(target, source, bindtype); + DEEPCOPY (target, source, saslmechanism); + DEEPCOPY (target, source, searchattr); + SHALLOWCOPY(target, source, maxentries); + SHALLOWCOPY(target, source, cacheconn); + SHALLOWCOPY(target, source, enabletls); + SHALLOWCOPY(target, source, local_cache_timeout); + SHALLOWCOPY(target, source, ask_pw); + SHALLOWCOPY(target, source, hide_internal); + SHALLOWCOPY(target, source, show_ref); + + DEEPCOPY (target, source, canon_name); + SHALLOWCOPY(target, source, is_uri); + + target->connection = NULL; + target->incarnation = 0; + target->missing_closes = 0; + target->ss = NULL; + target->flags = 0; + target->version = LDAP_VERSION2; + target->server_down = 0; + } + + void canonicalize_ldapserver(struct ldapserver *server) + { + /* FIXME: should use better URI check */ + server->is_uri = g_utf8_strchr(server->ldaphost, -1, ':') != NULL; + + if (server->is_uri) { + g_free_and_dup(server->canon_name, server->ldaphost); + } else { + /* construct an LDAP URI */ + GString *str = g_string_sized_new(100); + g_string_sprintf(str, "ldap://%s:%d/", + server->ldaphost, server->ldapport); + g_free_if(server->canon_name); + server->canon_name = str->str; + g_string_free(str, FALSE); + } + } + void free_ldapserver(struct ldapserver *server) { *************** *** 127,130 **** --- 187,192 ---- g_free_if(server->saslmechanism); g_free_if(server->searchattr); + + g_free_if(server->canon_name); g_free(server); Index: configfile.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/configfile.h,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** configfile.h 17 Oct 2003 06:40:27 -0000 1.30 --- configfile.h 17 Oct 2003 06:52:39 -0000 1.31 *************** *** 152,156 **** --- 152,167 ---- struct ldapserver *new_ldapserver(void); + void copy_ldapserver(struct ldapserver *target, + const struct ldapserver *source); void free_ldapserver(struct ldapserver *server); + + /* canonicalize_ldapserver - to be called whenever the server-related + information gets changed for the server in order to recalculate + some dependent information. Eg. a change to the ldaphost might + change the fact that a server get specified via an ldap URI or + not. Another example is the change of the ldaphost causing a change + to the canonical name of the server. This is where the name + originated. */ + void canonicalize_ldapserver(struct ldapserver *server); char *homedir(void); Index: gq-xml.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/gq-xml.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** gq-xml.c 11 Oct 2003 21:47:51 -0000 1.5 --- gq-xml.c 17 Oct 2003 06:52:39 -0000 1.6 *************** *** 291,295 **** } ! c->servers = g_list_append(c->servers, e->data); e->data = NULL; --- 291,296 ---- } ! canonicalize_ldapserver(server); ! c->servers = g_list_append(c->servers, server); e->data = NULL; Index: prefs.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/prefs.c,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** prefs.c 13 Oct 2003 07:31:45 -0000 1.42 --- prefs.c 17 Oct 2003 06:52:39 -0000 1.43 *************** *** 327,330 **** --- 327,331 ---- cached connection */ close_connection(server, TRUE); + canonicalize_ldapserver(server); if(server_name_changed) { Index: util.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/util.c,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** util.c 17 Oct 2003 05:26:23 -0000 1.72 --- util.c 17 Oct 2003 06:52:39 -0000 1.73 *************** *** 1,7 **** /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2001 Bert Vermeulen ! Parts: Copyright (C) 2002 Bert Vermeulen and ! Peter Stamfest <pe...@st...> This program is released under the Gnu General Public License with --- 1,6 ---- /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2003 Bert Vermeulen ! Copyright (C) 2002-2003 Peter Stamfest This program is released under the Gnu General Public License with *************** *** 842,845 **** --- 841,867 ---- } + + /* + * return pointer to (struct ldapserver *) matching the canonical name + */ + struct ldapserver *server_by_canon_name(const char *name) + { + struct ldapserver *server; + GList *I; + + if(name == NULL || name[0] == '\0') + return NULL; + + for (I = config->servers ; I ; I = g_list_next(I)) { + server = (struct ldapserver *) I->data; + if(!strcmp(server->canon_name, name)) + return(server); + } + return NULL; + } + + gboolean is_transient_server(const struct ldapserver *server) { + return g_list_find(config->servers, server) == NULL; + } /* Index: util.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/util.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** util.h 9 Oct 2003 05:26:20 -0000 1.24 --- util.h 17 Oct 2003 06:52:39 -0000 1.25 *************** *** 1,6 **** /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2001 Bert Vermeulen ! Copyright (C) 2002 Bert Vermeulen and Peter Stamfest <pe...@st...> This program is released under the Gnu General Public License with --- 1,6 ---- /* GQ -- a GTK-based LDAP client ! Copyright (C) 1998-2003 Bert Vermeulen ! Copyright (C) 2002-2003 Peter Stamfest This program is released under the Gnu General Public License with *************** *** 82,85 **** --- 82,90 ---- struct ldapserver *server_by_name(const char *name); + struct ldapserver *server_by_canon_name(const char *name); + + /* returns TRUE if server is NOT in the config ldapserver list */ + gboolean is_transient_server(const struct ldapserver *server); + int is_leaf_entry(struct ldapserver *server, char *dn); gboolean is_direct_parent(char *child, char *possible_parent); |