[gq-commit] gq/src browse.c,1.57,1.58 input.c,1.45,1.46 input.h,1.6,1.7 util.c,1.44,1.45
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2002-08-10 06:06:41
|
Update of /cvsroot/gqclient/gq/src In directory usw-pr-cvs1:/tmp/cvs-serv25701 Modified Files: browse.c input.c input.h util.c Log Message: * Add a "Add as New" Button to the browser. Very convenient to copy entries to a new DN an changing values at the very same time. Started from a patch received by Árpád, Magosányi" <ma...@bu...>. Had to rewrite large portions of the patch, because it caused crashes. * Enhancements to the way DNs are exploded. Triggered by a SF bug report by Nalin Dahyabhai. Correct treatment of DNs must become a major TODO item, but unfortunately we use DNs all over the place... This may take a _long_ time. Index: browse.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/browse.c,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** browse.c 2 Aug 2002 06:08:00 -0000 1.57 --- browse.c 10 Aug 2002 06:06:38 -0000 1.58 *************** *** 95,102 **** char *dummy[] = { "dummy", NULL }; dn_browse_entry *new_entry; ! GtkCTreeNode *new_item, *added; ! /* explode DN */ exploded_dn = gq_ldap_explode_dn(dn, FALSE); labels[0] = decoded_string(exploded_dn[0]); --- 95,114 ---- char *dummy[] = { "dummy", NULL }; dn_browse_entry *new_entry; ! GtkCTreeNode *new_item, *added = NULL; ! int ctx; ! ! ctx = error_new_context(_("Exploding DN")); ! /* explode DN */ exploded_dn = gq_ldap_explode_dn(dn, FALSE); + + if (exploded_dn == NULL) { + /* problem with DN */ + /* printf("problem dn: %s\n", dn); */ + error_push(ctx, _("Cannot explode DN. Maybe problems with quoting or special characters. See RFC 2253 for details of DN syntax.")); + + goto fail; + } + labels[0] = decoded_string(exploded_dn[0]); *************** *** 122,129 **** NULL, NULL, NULL, NULL, TRUE, FALSE); ! ! free(labels[0]); gq_exploded_free(exploded_dn); return added; } --- 134,144 ---- NULL, NULL, NULL, NULL, TRUE, FALSE); ! ! fail: ! if (labels[0]) free(labels[0]); gq_exploded_free(exploded_dn); + error_flush(ctx); + return added; } *************** *** 1146,1149 **** --- 1161,1169 ---- exploded_dn = gq_ldap_explode_dn(e->dn, FALSE); + if (exploded_dn == NULL) { + /* parsing problem */ + } + + labels[0] = decoded_string(exploded_dn[0]); *************** *** 1257,1264 **** for(i = 0 ; dnparts[i] ; i++) { } ! for(i-- ; i >= 0 ; i--) { g_string_insert(s, 0, dnparts[i]); ! /* printf("try %s at %08lx\n", s->str, node); */ if (node) gtk_ctree_expand(tree, node); --- 1277,1285 ---- for(i = 0 ; dnparts[i] ; i++) { } ! for(i-- ; i >= 0 ; i--) { + if (*dnparts[i] == 0) continue; /* skip empty DN elements (ie always the last one???) - ah, forget to think about it. */ g_string_insert(s, 0, dnparts[i]); ! /* printf("try %s at %08lx\n", s->str, node); */ if (node) gtk_ctree_expand(tree, node); Index: input.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/input.c,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** input.c 2 Aug 2002 06:11:55 -0000 1.45 --- input.c 10 Aug 2002 06:06:38 -0000 1.46 *************** *** 54,57 **** --- 54,61 ---- void refresh_inputform(GHashTable *browsehash); + static void add_entry_from_formlist(GHashTable *hash); + static void add_entry_from_formlist_and_select(GHashTable *hash); + static int add_entry_from_formlist_no_close(GHashTable *hash); + void create_form_window(GHashTable *hash) *************** *** 185,188 **** --- 189,200 ---- gtk_widget_grab_default(button); + button = gtk_button_new_with_label(_("Add as new")); + gtk_widget_show(button); + gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, 0); + gtk_signal_connect_object(GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(add_entry_from_formlist_and_select), + (gpointer) hash); + GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); + button = gtk_button_new_with_label(_("Refresh")); /* gtk_widget_set_sensitive(button, FALSE); */ *************** *** 223,226 **** --- 235,251 ---- gtk_widget_grab_default(button); + /* PSt: Removed again, as the GUI is too confusing. What + does "OK" mean wrt "Apply"? Which Button does which? It + is not intuitive enough too keep this. AND it still has a + problem after Apply: The current DN does not get + changed. */ + + /* button = gtk_button_new_with_label(_("Apply")); */ + /* gtk_widget_show(button); */ + /* gtk_box_pack_start(GTK_BOX(hbox2), button, FALSE, FALSE, 0); */ + /* gtk_signal_connect_object(GTK_OBJECT(button), "clicked", */ + /* GTK_SIGNAL_FUNC(add_entry_from_formlist_no_close), */ + /* (gpointer) hash); */ + button = gtk_button_new_with_label(_("Cancel")); gtk_widget_show(button); *************** *** 842,846 **** ! void add_entry_from_formlist(GHashTable *hash) { LDAP *ld; --- 867,891 ---- ! static void add_entry_from_formlist(GHashTable *hash) ! { ! add_entry_from_formlist_no_close(hash); ! destroy_editwindow(hash); ! } ! ! static void add_entry_from_formlist_and_select(GHashTable *hash) ! { ! int rc = add_entry_from_formlist_no_close(hash); ! ! if (rc) { ! char *dn = g_hash_table_lookup(hash, "dn"); ! GtkCTree *tree = g_hash_table_lookup(hash, "ctreeroot"); ! ! if (dn && tree) { ! show_dn(tree, NULL, dn, TRUE); ! } ! } ! } ! ! static int add_entry_from_formlist_no_close(GHashTable *hash) { LDAP *ld; *************** *** 864,868 **** "Please notify be...@bi..."); error_flush(add_context); ! return; } server = g_hash_table_lookup(hash, "server"); --- 909,913 ---- "Please notify be...@bi..."); error_flush(add_context); ! return 0; } server = g_hash_table_lookup(hash, "server"); *************** *** 871,875 **** "Hmmm, no server! Please notify be...@bi..."); error_flush(add_context); ! return; } --- 916,920 ---- "Hmmm, no server! Please notify be...@bi..."); error_flush(add_context); ! return 0; } *************** *** 880,884 **** error_push(add_context, _("You must enter a DN for a new entry.")); error_flush(add_context); ! return; } --- 925,929 ---- error_push(add_context, _("You must enter a DN for a new entry.")); error_flush(add_context); ! return 0; } *************** *** 889,893 **** set_normalcursor(); error_flush(add_context); ! return; } --- 934,938 ---- set_normalcursor(); error_flush(add_context); ! return 0; } *************** *** 897,906 **** while(formlist) { form = (struct formfill *) formlist->data; ! ! if (g_list_length(form->values) > 0) { ! mod = form->dt_handler->buildLDAPMod(form, ! LDAP_MOD_ADD, ! form->values); ! mods[cmod++] = mod; } --- 942,953 ---- while(formlist) { form = (struct formfill *) formlist->data; ! ! if (! (form->flags & FLAG_NO_USER_MOD)) { ! if (g_list_length(form->values) > 0) { ! mod = form->dt_handler->buildLDAPMod(form, ! LDAP_MOD_ADD, ! form->values); ! mods[cmod++] = mod; ! } } *************** *** 913,916 **** --- 960,965 ---- if (res == LDAP_SERVER_DOWN) { + error_push(add_context, ldap_err2string(res)); + push_ldap_addl_error(ld, add_context); server->server_down++; } *************** *** 921,925 **** set_normalcursor(); close_connection(server, FALSE); ! return; } --- 970,974 ---- set_normalcursor(); close_connection(server, FALSE); ! return 0; } *************** *** 965,973 **** g_free(parentdn); - destroy_editwindow(hash); set_normalcursor(); close_connection(server, FALSE); } --- 1014,1023 ---- g_free(parentdn); set_normalcursor(); close_connection(server, FALSE); + + return 1; } *************** *** 985,988 **** --- 1035,1039 ---- GtkCTree *ctreeroot = NULL; int do_modrdn = 0; + int error = 0; update_formlist(hash); *************** *** 1031,1037 **** if((rc = change_rdn(hash, mod_context)) != 0) { /* printf("error %d\n", rc); */ ! error_flush(mod_context); ! g_string_free(message, TRUE); ! return; } statusbar_msg(message->str); --- 1082,1088 ---- if((rc = change_rdn(hash, mod_context)) != 0) { /* printf("error %d\n", rc); */ ! ! error = 1; ! goto done; } statusbar_msg(message->str); *************** *** 1074,1084 **** #endif error_flush(mod_context); close_connection(server, FALSE); ! g_string_free(message, TRUE); /* refresh visual if requested by browse mode */ ! if (do_modrdn && node) { refresh_subtree_new_dn(ctreeroot, node, dn, 0); } --- 1125,1136 ---- #endif + done: error_flush(mod_context); close_connection(server, FALSE); ! if (message) g_string_free(message, TRUE); /* refresh visual if requested by browse mode */ ! if (do_modrdn && node && !error) { refresh_subtree_new_dn(ctreeroot, node, dn, 0); } *************** *** 1088,1092 **** int change_rdn(GHashTable *hash, int context) { ! GString *message; LDAP *ld; struct ldapserver *server; --- 1140,1144 ---- int change_rdn(GHashTable *hash, int context) { ! GString *message = NULL; LDAP *ld; struct ldapserver *server; *************** *** 1108,1126 **** rdn = gq_ldap_explode_dn(dn, 0); ! message = g_string_sized_new(256); ! /* check if user really only attemps to change the RDN and not ! any other parts of the DN */ ! error = 0; ! for(i = 1; rdn[i]; i++) { ! if(oldrdn[i] == NULL || rdn[i] == NULL || ! (strcasecmp(oldrdn[i], rdn[i]) != 0)) { ! g_string_sprintf(message, ! _("You can only change the RDN of the DN (%s)"), ! c = decoded_string(oldrdn[0])); ! if (c) free(c); ! error_push(context, message->str); ! error = 1; ! break; } } --- 1160,1188 ---- rdn = gq_ldap_explode_dn(dn, 0); ! if (rdn == NULL) { ! /* parsing error */ ! error_push(context, _("Cannot explode DN. Maybe problems with quoting or special characters. See RFC 2253 for details of DN syntax.")); ! ! error = 1; ! } else { ! /* parsing OK */ ! ! message = g_string_sized_new(256); ! ! /* check if user really only attemps to change the RDN and not ! any other parts of the DN */ ! error = 0; ! for(i = 1; rdn[i]; i++) { ! if(oldrdn[i] == NULL || rdn[i] == NULL || ! (strcasecmp(oldrdn[i], rdn[i]) != 0)) { ! g_string_sprintf(message, ! _("You can only change the RDN of the DN (%s)"), ! c = decoded_string(oldrdn[0])); ! if (c) free(c); ! error_push(context, message->str); ! error = 1; ! break; ! } } } *************** *** 1176,1185 **** } ! gq_exploded_free(oldrdn); ! gq_exploded_free(rdn); ! ! g_string_free(message, TRUE); close_connection(server, FALSE); return(error); } --- 1238,1247 ---- } ! if (oldrdn) gq_exploded_free(oldrdn); ! if (rdn) gq_exploded_free(rdn); ! if (message) g_string_free(message, TRUE); close_connection(server, FALSE); + return(error); } Index: input.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/input.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** input.h 4 Apr 2002 14:33:11 -0000 1.6 --- input.h 10 Aug 2002 06:06:38 -0000 1.7 *************** *** 41,45 **** void update_formlist(GHashTable *hash); void clear_table(GHashTable *hash); - void add_entry_from_formlist(GHashTable *hash); void mod_entry_from_formlist(GHashTable *hash); int change_rdn(GHashTable *hash, int context); --- 41,44 ---- Index: util.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/util.c,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** util.c 23 Jul 2002 13:47:57 -0000 1.44 --- util.c 10 Aug 2002 06:06:38 -0000 1.45 *************** *** 1541,1549 **** char **gq_ldap_explode_dn(const char *dn, int dummy) { ! int i; LDAPDN *parts; char **v = 0; ! ldap_str2dn(dn, &parts, LDAP_DN_FORMAT_LDAP); /* count DN elements */ for( i = 0 ; parts[i] ; i++ ) ; --- 1541,1552 ---- char **gq_ldap_explode_dn(const char *dn, int dummy) { ! int i, rc; LDAPDN *parts; char **v = 0; ! rc = ldap_str2dn(dn, &parts, LDAP_DN_FORMAT_LDAPV3); ! ! if (rc != LDAP_SUCCESS || parts == NULL) return NULL; ! /* count DN elements */ for( i = 0 ; parts[i] ; i++ ) ; *************** *** 1559,1563 **** void gq_exploded_free(char **exploded_dn) { ! free(exploded_dn); } --- 1562,1566 ---- void gq_exploded_free(char **exploded_dn) { ! if (exploded_dn) free(exploded_dn); } |