[gq-commit] gq/src browse-dnd.c,1.6,1.6.2.1 browse.c,1.52,1.52.2.1 ldif.c,1.11,1.11.2.1 ldif.h,1.4,1
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2002-08-02 06:17:21
|
Update of /cvsroot/gqclient/gq/src In directory usw-pr-cvs1:/tmp/cvs-serv9113 Modified Files: Tag: gq_0_6_0-patches browse-dnd.c browse.c ldif.c ldif.h Log Message: * Backported: Fixed a bug crashing gq when exporting form Netscape-Directory-Server to LDIF. Reported by Cord Beermann <cor...@me...>. Index: browse-dnd.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/browse-dnd.c,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -C2 -d -r1.6 -r1.6.2.1 *** browse-dnd.c 18 Jun 2002 22:07:14 -0000 1.6 --- browse-dnd.c 2 Aug 2002 06:17:18 -0000 1.6.2.1 *************** *** 830,833 **** --- 830,835 ---- gboolean ok = FALSE; + int ctx = error_new_context(_("Getting selection string")); + #ifdef DEBUG_DND printf("get_selection_string\n"); *************** *** 844,855 **** if (rc == LDAP_SERVER_DOWN) { server->server_down = 1; goto fail; } - if (rc != LDAP_SUCCESS) goto fail; - out = g_string_new(""); for(e = ldap_first_entry(ld, msg); e ; e = ldap_next_entry(ld, e)) { ! ldif_entry_out(out, ld, e); } --- 846,866 ---- if (rc == LDAP_SERVER_DOWN) { server->server_down = 1; + error_push(ctx, + _("Server down. Export may be incomplete!")); + push_ldap_addl_error(ld, ctx); + + goto fail; + } + if (rc != LDAP_SUCCESS) { + error_push(ctx, + _("LDAP error. Export may be incomplete!")); + push_ldap_addl_error(ld, ctx); + goto fail; } out = g_string_new(""); for(e = ldap_first_entry(ld, msg); e ; e = ldap_next_entry(ld, e)) { ! ldif_entry_out(out, ld, e, ctx); } *************** *** 877,880 **** --- 888,893 ---- if (msg) ldap_msgfree(msg); close_connection(server, FALSE); + + error_flush(ctx); return; } Index: browse.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/browse.c,v retrieving revision 1.52 retrieving revision 1.52.2.1 diff -C2 -d -r1.52 -r1.52.2.1 *** browse.c 21 Jun 2002 00:34:32 -0000 1.52 --- browse.c 2 Aug 2002 06:17:18 -0000 1.52.2.1 *************** *** 1102,1106 **** GString *bigmessage = NULL; int written; ! char message[128]; entry = gtk_object_get_data(GTK_OBJECT(filesel), "entry"); --- 1102,1109 ---- GString *bigmessage = NULL; int written; ! char message[512]; ! int ctx; ! ! ctx = error_new_context(_("Dump subtree")); entry = gtk_object_get_data(GTK_OBJECT(filesel), "entry"); *************** *** 1119,1123 **** if(g_list_length(bases) == 0) { ! return; } --- 1122,1127 ---- if(g_list_length(bases) == 0) { ! error_push(ctx, _("Nothing to dump!")); ! goto fail; } *************** *** 1128,1132 **** if( (outfile = fopen(filename, "w")) == NULL) { ! error_popup(_("Save failed"), strerror(errno)); } else { /* AFAIK, the UMich LDIF format doesn't take comments or a --- 1132,1142 ---- if( (outfile = fopen(filename, "w")) == NULL) { ! snprintf(message, sizeof(message), ! _("Could not open output file: %s"), ! strerror(errno)); ! error_push(ctx, message); ! ! goto fail; ! /* error_popup(_("Save failed"), strerror(errno)); */ } else { /* AFAIK, the UMich LDIF format doesn't take comments or a *************** *** 1135,1139 **** g_string_truncate(out, 0); - prepend_ldif_header(out, server, bases); --- 1145,1148 ---- *************** *** 1141,1147 **** if(written != out->len) { snprintf(message, sizeof(message), ! _("%d of %d bytes written"), written, out->len); ! error_popup(_("Save failed"), message); goto fail; /* sometimes goto is useful */ } --- 1150,1156 ---- if(written != out->len) { snprintf(message, sizeof(message), ! _("Save failed: Only %d of %d bytes written"), written, out->len); ! error_push(ctx, message); goto fail; /* sometimes goto is useful */ } *************** *** 1149,1152 **** --- 1158,1163 ---- if( (ld = open_connection(server)) == NULL) { + /* no extra error, open_connection does error reporting + itself... */ goto fail; } *************** *** 1163,1167 **** for(e = ldap_first_entry(ld, res); e; e = ldap_next_entry(ld, e)) { g_string_truncate(out, 0); ! ldif_entry_out(out, ld, e); num_entries++; --- 1174,1178 ---- for(e = ldap_first_entry(ld, res); e; e = ldap_next_entry(ld, e)) { g_string_truncate(out, 0); ! ldif_entry_out(out, ld, e, ctx); num_entries++; *************** *** 1183,1190 **** server->server_down++; ldap_msgfree(res); /* is this correct? */ } else { /* report error */ ! statusbar_msg(ldap_err2string(ldap_result2error(ld, ! res, 1))); goto fail; } --- 1194,1209 ---- server->server_down++; ldap_msgfree(res); /* is this correct? */ + + error_push(ctx, + _("Server down. Export may be incomplete!")); + push_ldap_addl_error(ld, ctx); + goto fail; } else { /* report error */ ! error_push(ctx, ! _("LDAP error. Export may be incomplete!")); ! push_ldap_addl_error(ld, ctx); ! /* statusbar_msg(ldap_err2string(ldap_result2error(ld, */ ! /* res, 1))); */ goto fail; } *************** *** 1200,1210 **** } ! fail: if (outfile) fclose(outfile); ! for (I = g_list_first(bases) ; I ; I = g_list_next(I)) { ! free(I->data); } - if (bases) g_list_free(bases); set_normalcursor(); --- 1219,1231 ---- } ! fail: /* labels are only good for cleaning up, really */ if (outfile) fclose(outfile); ! if (bases) { ! for (I = g_list_first(bases) ; I ; I = g_list_next(I)) { ! free(I->data); ! } ! g_list_free(bases); } set_normalcursor(); *************** *** 1214,1217 **** --- 1235,1240 ---- gtk_widget_destroy(filesel); + + error_flush(ctx); } Index: ldif.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/ldif.c,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -C2 -d -r1.11 -r1.11.2.1 *** ldif.c 8 Jun 2002 05:46:44 -0000 1.11 --- ldif.c 2 Aug 2002 06:17:18 -0000 1.11.2.1 *************** *** 25,28 **** --- 25,29 ---- #include <stdlib.h> #include <string.h> /* strlen */ + #include <stdio.h> /* snprintf */ #include <ctype.h> #include <time.h> *************** *** 37,41 **** #include "util.h" #include "ldif.h" ! void prepend_ldif_header(GString *out, struct ldapserver *server, GList *bases) --- 38,43 ---- #include "util.h" #include "ldif.h" ! #include "i18n.h" ! #include "errorchain.h" void prepend_ldif_header(GString *out, struct ldapserver *server, GList *bases) *************** *** 65,69 **** ! gboolean ldif_entry_out(GString *out, LDAP *ld, LDAPMessage *msg) { BerElement *berptr; --- 67,72 ---- ! gboolean ldif_entry_out(GString *out, LDAP *ld, LDAPMessage *msg, ! int error_context) { BerElement *berptr; *************** *** 74,78 **** dn = ldap_get_dn(ld, msg); ! ldif_line_out(out, "dn", dn, strlen(dn)); g_string_append(out, "\n"); free(dn); --- 77,90 ---- dn = ldap_get_dn(ld, msg); ! ! if (!dn) { ! /* an error occurred */ ! ! error_push(error_context, _("Cannot retrieve DN of entry.\n")); ! push_ldap_addl_error(ld, error_context); ! return FALSE; ! } ! ! ldif_line_out(out, "dn", dn, strlen(dn), error_context); g_string_append(out, "\n"); free(dn); *************** *** 86,90 **** /* should work for ;binary as-is */ value = vals[i]; ! ldif_line_out(out, attr, value->bv_val, value->bv_len); g_string_append(out, "\n"); } --- 98,104 ---- /* should work for ;binary as-is */ value = vals[i]; ! ldif_line_out(out, attr, ! value->bv_val, value->bv_len, ! error_context); g_string_append(out, "\n"); } *************** *** 103,110 **** ! gboolean ldif_line_out(GString *out, char *attr, char *value, int vlen) { GString *tmp; int i, w, do_base64; g_string_append(out, attr); --- 117,148 ---- ! gboolean ldif_line_out(GString *out, char *attr, char *value, int vlen, ! int error_context) { GString *tmp; int i, w, do_base64; + /* char message[256]; */ + + if (attr == NULL) { + /* NULL attributes make no sense */ + error_push(error_context, + _("NULL attribute name - cannot write such an attribute...")); + return FALSE; + } + + if (value == NULL) { + /* NULL seems to be normal, at least with Netscape LDAP + servers, tested with help from Cord Beermann + <cor...@me...> */ + + /* + snprintf(message, sizeof(message), + _("NULL value for attribute %s - writing empty string instead..."), + attr); + error_push(error_context, message); + */ + value = ""; + vlen = 0; + } g_string_append(out, attr); Index: ldif.h =================================================================== RCS file: /cvsroot/gqclient/gq/src/ldif.h,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -C2 -d -r1.4 -r1.4.2.1 *** ldif.h 5 Jun 2002 15:40:32 -0000 1.4 --- ldif.h 2 Aug 2002 06:17:18 -0000 1.4.2.1 *************** *** 27,32 **** void prepend_ldif_header(GString *out, struct ldapserver *server, GList *bases); ! gboolean ldif_entry_out(GString *out, LDAP *ld, LDAPMessage *msg); ! gboolean ldif_line_out(GString *out, char *attr, char *value, int vlen); void b64_encode(GString *out, char *value, int vlen); void b64_decode(GByteArray *out, const char *value, int vlen); --- 27,34 ---- void prepend_ldif_header(GString *out, struct ldapserver *server, GList *bases); ! gboolean ldif_entry_out(GString *out, LDAP *ld, LDAPMessage *msg, ! int error_context); ! gboolean ldif_line_out(GString *out, char *attr, char *value, int vlen, ! int error_context); void b64_encode(GString *out, char *value, int vlen); void b64_decode(GByteArray *out, const char *value, int vlen); |