writephonebook fix + MyX-2 support
Raphaël <[email protected]>
| Newsgroups | gmane.linux.drivers.gnokii |
|---|---|
| Message-ID | <20130307234646.GA15966@b1b1> |
Hi, when using --writephonebook, both vCard and ldif parsers returns at the end of file (as every file has an end), but the return value is treated as GN_ERR_WRONGDATAFORMAT by writephonebook(). Thus after multiple entries have been written, a failure message appears after the very last entry (successfully) stored. Moreover, as the location integer changes meanwhile, the warning does not reference a useful location. This patch attempt to fix this by skipping entirely this warning which is (always ?) wrong in the first place. Side note: I got useful working features with the good old Sagem MyX-2 (no-slider model = no breakage). Tips are documented here [1] though nothing really new as this model was already supported by gammu. But media AT commands (of limited use in these models) seem proprietary and WAP has not been tested. Unrelated question: is there any existing plan to enhance the "find-free" option of writephonebook ? It's a pain to use as it starts the location counter back to 2 for each entry. So in the best case `--writephonebook -f` ends up testing 85! (factorial) locations in order store 85 entries. Trying (prev_entry_location + 1) could be a best guess to try before going into this costly loop. regards [1] http://wiki.gnokii.org/index.php/Sagem_MyX-2 _______________________________________________ gnokii-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/gnokii-users
writephonebook-eof.patch
(text/x-diff, 2.1 KB)
commit aba5d6fd5232a5aa23a2215ae558efcb7eead9ca Author: Raphaël Droz <[email protected]> Date: Thu Mar 7 17:52:06 2013 +0100 ldif and vcard parsers: don't return end-of-file as an error and avoid unecessary roundtrips and warnings in writephonebook(). diff --git a/common/ldif.c b/common/ldif.c index 6e40313..aa82fc2 100644 --- a/common/ldif.c +++ b/common/ldif.c @@ -174,7 +174,7 @@ GNOKII_API int gn_ldif2phonebook(FILE *f, gn_phonebook_entry *entry) while (1) { if (!fgets(buf, 1024, f)) - return -1; + return 1; if (BEGINS("dn:")) break; } diff --git a/common/vcard.c b/common/vcard.c index a1887de..937208f 100644 --- a/common/vcard.c +++ b/common/vcard.c @@ -348,7 +348,7 @@ GNOKII_API int gn_vcard2phonebook(FILE *f, gn_phonebook_entry *entry) while (1) { if (!fgets(buf, 1024, f)) - return -1; + return 1; if (BEGINS("BEGIN:VCARD")) break; } diff --git a/gnokii/gnokii-phonebook.c b/gnokii/gnokii-phonebook.c index ba05a23..79f4482 100644 --- a/gnokii/gnokii-phonebook.c +++ b/gnokii/gnokii-phonebook.c @@ -280,6 +280,7 @@ gn_error writephonebook(int argc, char *argv[], gn_data *data, struct gn_statema */ char *line, oline[MAX_INPUT_LINE_LEN]; int i; + int parser_ret_val; struct option options[] = { { "overwrite", 0, NULL, 'o'}, @@ -340,13 +341,17 @@ gn_error writephonebook(int argc, char *argv[], gn_data *data, struct gn_statema entry.location = default_location; switch (type) { case 1: - if (gn_vcard2phonebook(stdin, &entry)) - error = GN_ERR_WRONGDATAFORMAT; + parser_ret_val = gn_vcard2phonebook(stdin, &entry); + if(parser_ret_val < 0) error = GN_ERR_WRONGDATAFORMAT; + else if(parser_ret_val == 1) goto out; // no more entry break; + case 2: - if (gn_ldif2phonebook(stdin, &entry)) - error = GN_ERR_WRONGDATAFORMAT; + parser_ret_val = gn_ldif2phonebook(stdin, &entry); + if(parser_ret_val < 0) error = GN_ERR_WRONGDATAFORMAT; + else if(parser_ret_val == 1) goto out; // no more entry break; + default: if (!gn_line_get(stdin, line, MAX_INPUT_LINE_LEN)) goto out; /* it means we read an empty line, but that's not an error */