[gq-commit] gq/src template.c,1.10,1.11 template.h,1.3,1.4
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2003-10-05 13:49:34
|
Update of /cvsroot/gqclient/gq/src In directory sc8-pr-cvs1:/tmp/cvs-serv9519 Modified Files: template.c template.h Log Message: * Got rid of many, many fixed size buffers. These might have been problematic with variable length characters (as in the standard UTF-8 encoding) * Many object types now have constructors and destructors of the form new_<type> and free_<type>. Use them instead of self-allocating and freeing memory as it was done before. Removed all such old style object handling * Got rid of most hand-knit linked list implementations, replaced them with GLists (errorchains, config->ldapservers, etc.) Index: template.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/template.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** template.c 4 Oct 2003 09:59:09 -0000 1.10 --- template.c 5 Oct 2003 13:49:29 -0000 1.11 *************** *** 50,57 **** extern GtkWidget *current_template_clist; ! static GtkWidget *templatewin; void create_template_edit_window(struct ldapserver *server, --- 50,78 ---- extern GtkWidget *current_template_clist; + static GtkWidget *templatewin; + + /* malloc and init gq_template struct */ + struct gq_template *new_template(void) + { + struct gq_template *tmpl; + tmpl = g_malloc0(sizeof(struct gq_template)); ! tmpl->name = g_strdup(""); ! tmpl->objectclasses = NULL; ! ! return tmpl; ! } + void free_template(struct gq_template *tmpl) + { + g_free_if(tmpl->name); + + if (tmpl->objectclasses) { + g_list_foreach(tmpl->objectclasses, (GFunc) g_free, NULL); + } + g_list_free(tmpl->objectclasses); + g_free(tmpl); + } void create_template_edit_window(struct ldapserver *server, *************** *** 549,574 **** } else { ! /* update existing template */ old_tmpl = find_template_by_name(old_template_name); if(old_tmpl) { ! ! g_list_free(old_tmpl->objectclasses); ! old_tmpl->objectclasses = tmpl->objectclasses; ! ! if(strcmp(old_template_name, tmpl->name)) { ! /* template name was changed too */ ! strncpy(old_tmpl->name, tmpl->name, 128); ! } ! ! /* tmpl is not inserted into global config, so we don't need it any more */ ! FREE(tmpl, "struct gq_template"); ! ! } ! else { /* hmmmm... template was deleted while editing it. Just add it in then */ config->templates = g_list_append(config->templates, tmpl); } - } --- 570,590 ---- } else { ! GList *l; /* update existing template */ old_tmpl = find_template_by_name(old_template_name); + + /* In order to encapsulate knowledge about the internal + structure of a template object, updating is done via + delete/insert. This is less optimal than the old + behaviour to change the filter in-place + */ if(old_tmpl) { ! l = g_list_find(config->templates, old_tmpl); ! free_template(old_tmpl); ! l->data = tmpl; ! } else { /* hmmmm... template was deleted while editing it. Just add it in then */ config->templates = g_list_append(config->templates, tmpl); } } *************** *** 593,596 **** --- 609,613 ---- int i; char *objectclass; + const char *c; if( (templatelist = gtk_object_get_data(GTK_OBJECT(window), "templatelist")) == NULL) *************** *** 600,607 **** return(NULL); ! if( (tmpl = MALLOC(sizeof(struct gq_template), "struct gq_template")) == NULL) return(NULL); ! strncpy(tmpl->name, gtk_entry_get_text(GTK_ENTRY(templatenamebox)), 128); list = NULL; --- 617,626 ---- return(NULL); ! if( (tmpl = new_template()) == NULL) return(NULL); ! ! c = gtk_entry_get_text(GTK_ENTRY(templatenamebox)); ! g_free_and_dup(tmpl->name, c); list = NULL; *************** *** 684,685 **** --- 703,710 ---- #endif /* HAVE_LDAP_STR2OBJECTCLASS */ + + /* + Local Variables: + c-basic-offset: 5 + End: + */ Index: template.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/template.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** template.h 29 Sep 2003 19:24:17 -0000 1.3 --- template.h 5 Oct 2003 13:49:29 -0000 1.4 *************** *** 31,37 **** struct gq_template { ! char name[128]; ! GList *objectclasses; }; void create_template_edit_window(struct ldapserver *server, --- 31,40 ---- struct gq_template { ! char *name; ! GList *objectclasses; }; + + struct gq_template *new_template(void); + void free_template(struct gq_template *); void create_template_edit_window(struct ldapserver *server, |