[PATCH 1/2] Add unzip support to divelogs.de exports
Miika Turkia
miika.turkia at gmail.com
Wed Feb 20 10:27:31 PST 2013
On Wed, Feb 20, 2013 at 11:37 PM, Dirk Hohndel <dirk at hohndel.org> wrote:
>
> How does this respond if it gets a random zip file?
Nice red alert at the bottom saying: Failed to parse 'ZIP file'
And OK button to get rid of it.
There is also some text on the terminal what started Subsurface:
---8<---
Failed to parse 'ZIP file'.
ZIP file:1: parser error : Start tag expected, '<' not found
=begin
^
---8<---
So nothing major problems with random files.
> What is inside the zip file? Is there some more sanity checking that
> should happen before this is just handed over to parse_xml_buffer?
>
> The existing code literally does this:
>
> static void suunto_read(struct zip_file *file, GError **error)
> {
> int size = 1024, n, read = 0;
> char *mem = malloc(size);
>
> while ((n = zip_fread(file, mem+read, size-read)) > 0) {
> read += n;
> size = read * 3 / 2;
> mem = realloc(mem, size);
> }
> parse_xml_buffer(_("SDE file"), mem, read, &dive_table, error);
> free(mem);
> }
>
> so it reads in the file and hands it off to parse_xml_buffer - so it
> seems there is no "directory" information, zip is just use to compress a
> single XML file?
It reads multiple XML files, the loop is in the calling function
(try_to_open_suunto):
for (index = 0; ;index++) {
struct zip_file *file = zip_fopen_index(zip, index, 0);
if (!file)
break;
suunto_read(file, error);
zip_fclose(file);
success++;
}
> Maybe someone could send me such a file so I can play with it?
Yeah, me too. (I did have a couple of XML files to work with, but no zip)
miika
> subsurface at henrik.synth.no writes:
>
>> From: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
>>
>> Finalize divelog.de import, used with Miiko's divelog.de xslt transform
>>
>> Signed-off-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
>> ---
>> file.c | 14 +++++++++-----
>> gtk-gui.c | 2 ++
>> 2 files changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/file.c b/file.c
>> index cdad961..967afb8 100644
>> --- a/file.c
>> +++ b/file.c
>> @@ -62,7 +62,7 @@ out:
>> #ifdef LIBZIP
>> #include <zip.h>
>>
>> -static void suunto_read(struct zip_file *file, GError **error)
>> +static void zip_read(struct zip_file *file, GError **error)
>> {
>> int size = 1024, n, read = 0;
>> char *mem = malloc(size);
>> @@ -72,12 +72,12 @@ static void suunto_read(struct zip_file *file, GError **error)
>> size = read * 3 / 2;
>> mem = realloc(mem, size);
>> }
>> - parse_xml_buffer(_("SDE file"), mem, read, &dive_table, error);
>> + parse_xml_buffer(_("ZIP file"), mem, read, &dive_table, error);
>> free(mem);
>> }
>> #endif
>>
>> -static int try_to_open_suunto(const char *filename, struct memblock *mem, GError **error)
>> +static int try_to_open_zip(const char *filename, struct memblock *mem, GError **error)
>> {
>> int success = 0;
>> #ifdef LIBZIP
>> @@ -90,7 +90,7 @@ static int try_to_open_suunto(const char *filename, struct memblock *mem, GError
>> struct zip_file *file = zip_fopen_index(zip, index, 0);
>> if (!file)
>> break;
>> - suunto_read(file, error);
>> + zip_read(file, error);
>> zip_fclose(file);
>> success++;
>> }
>> @@ -225,7 +225,11 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
>> {
>> /* Suunto Dive Manager files: SDE */
>> if (!strcasecmp(fmt, "SDE"))
>> - return try_to_open_suunto(filename, mem, error);
>> + return try_to_open_zip(filename, mem, error);
>> +
>> + /* divelogs.de files: divelogsData.zip */
>> + if (!strcasecmp(fmt, "ZIP"))
>> + return try_to_open_zip(filename, mem, error);
>>
>> /* Truly nasty intentionally obfuscated Cochran Anal software */
>> if (!strcasecmp(fmt, "CAN"))
>> diff --git a/gtk-gui.c b/gtk-gui.c
>> index 40954ba..65a308c 100644
>> --- a/gtk-gui.c
>> +++ b/gtk-gui.c
>> @@ -126,6 +126,8 @@ static GtkFileFilter *setup_filter(void)
>> #ifdef LIBZIP
>> gtk_file_filter_add_pattern(filter, "*.sde");
>> gtk_file_filter_add_pattern(filter, "*.SDE");
>> + gtk_file_filter_add_pattern(filter, "*.zip");
>> + gtk_file_filter_add_pattern(filter, "*.ZIP");
>> #endif
>> gtk_file_filter_add_mime_type(filter, "text/xml");
>> gtk_file_filter_set_name(filter, _("XML file"));
>> --
>> 1.8.1.2
>>
>> _______________________________________________
>> subsurface mailing list
>> subsurface at hohndel.org
>> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
>
> --
> Dirk Hohndel
> Intel Open Source Technology Center
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
More information about the subsurface
mailing list