diff options
author | teuf <teuf@f01d2545-417e-4e96-918e-98f8d0dbbcb6> | 2008-02-03 18:53:45 +0000 |
---|---|---|
committer | teuf <teuf@f01d2545-417e-4e96-918e-98f8d0dbbcb6> | 2008-02-03 18:53:45 +0000 |
commit | db0e04b3a478d53a622e1ab3f9c7df7aad880a4c (patch) | |
tree | 26f76d75438534b743abf75bf9d98ce84b995830 /src | |
parent | 1ac42a5cd781a2e281b60408d8b7ca5c285c0abe (diff) | |
download | libgpod-tmz-db0e04b3a478d53a622e1ab3f9c7df7aad880a4c.tar.gz libgpod-tmz-db0e04b3a478d53a622e1ab3f9c7df7aad880a4c.tar.xz libgpod-tmz-db0e04b3a478d53a622e1ab3f9c7df7aad880a4c.zip |
Factorize mhod_type_3 and mhod_type_1 handling
MHOD in an ArtworkDB can only have 2 types, either they contain a string
or they are some kind of container. The code had an arbitrary separation
between mhod type 3 and mhod type 1 which both contained strings. This
consolidates that code in a parse_mhod_string function
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1947 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'src')
-rw-r--r-- | src/db-artwork-debug.h | 3 | ||||
-rw-r--r-- | src/db-artwork-parser.c | 150 | ||||
-rw-r--r-- | src/db-artwork-writer.c | 4 | ||||
-rw-r--r-- | src/db-itunes-parser.h | 2 |
4 files changed, 85 insertions, 74 deletions
diff --git a/src/db-artwork-debug.h b/src/db-artwork-debug.h index 604ea84..c5c7565 100644 --- a/src/db-artwork-debug.h +++ b/src/db-artwork-debug.h @@ -44,8 +44,7 @@ extern G_GNUC_INTERNAL void dump_mhba (MhbaHeader *mhba); #else #define dump_mhif(x) #define dump_mhia(x) -#define dump_mhod_type_1(x) -#define dump_mhod_type_3(x) +#define dump_mhod_string(x) #define dump_mhni(x) #define dump_mhod(x) #define dump_mhii(x) diff --git a/src/db-artwork-parser.c b/src/db-artwork-parser.c index cf74777..038d558 100644 --- a/src/db-artwork-parser.c +++ b/src/db-artwork-parser.c @@ -113,53 +113,71 @@ get_utf16_string (void* buffer, gint length, guint byte_order) } -static char * -mhod3_get_ithmb_filename (DBParseContext *ctx, - ArtworkDB_MhodHeaderString *mhod3) -{ - char *filename=NULL; - - g_assert (mhod3 != NULL); - - if (mhod3->encoding == 2) - filename = get_utf16_string ((gunichar2 *)mhod3->string, - get_gint32 (mhod3->string_len, ctx->byte_order), - ctx->byte_order); - else if ((mhod3->encoding == 0) || - (mhod3->encoding == 1)) - filename = g_strndup (mhod3->string, - get_gint32 (mhod3->string_len, ctx->byte_order)); - else - g_warning (_("Unexpected mhod3 string type: %d\n"), - mhod3->encoding); - return filename; -} +struct ParsedMhodString { + enum MhodType mhod_type; + char *mhod_string; +}; - -static int -parse_mhod_3 (DBParseContext *ctx, - Itdb_Thumb *thumb, GError *error) +static struct ParsedMhodString * +parse_mhod_string (DBParseContext *ctx, GError *error) { + struct ParsedMhodString *result; + ArtworkDB_MhodHeaderString *mhod_string; ArtworkDB_MhodHeader *mhod; - ArtworkDB_MhodHeaderString *mhod3; - gint32 mhod3_type; - + gint len; mhod = db_parse_context_get_m_header (ctx, ArtworkDB_MhodHeader, "mhod"); if (mhod == NULL) { - return -1; + return NULL; } db_parse_context_set_total_len (ctx, get_gint32 (mhod->total_len, ctx->byte_order)); - + if (get_gint32 (mhod->total_len, ctx->byte_order) < sizeof (ArtworkDB_MhodHeaderString)){ + return NULL; + } + + result = g_new0 (struct ParsedMhodString, 1); + if (result == NULL) { + return NULL; + } + + mhod_string = (ArtworkDB_MhodHeaderString*)mhod; + result->mhod_type = get_gint16 (mhod_string->type, ctx->byte_order); + len = get_gint32 (mhod_string->string_len, ctx->byte_order); + switch (mhod_string->encoding) { + case 2: + result->mhod_string = get_utf16_string ((gunichar2 *)mhod_string->string, + len, ctx->byte_order); + break; + case 0: + case 1: + result->mhod_string = g_strndup (mhod_string->string, len); + break; + default: + g_warning (_("Unexpected mhod string type: %d\n"), + mhod_string->encoding); + break; + } + dump_mhod_string (mhod_string); + return result; +} + +static int +parse_mhod_3 (DBParseContext *ctx, + Itdb_Thumb *thumb, GError *error) +{ + struct ParsedMhodString *mhod; + mhod = parse_mhod_string (ctx, error); + if (mhod == NULL) { return -1; } - mhod3 = (ArtworkDB_MhodHeaderString*)mhod; - mhod3_type = get_gint16 (mhod3->type, ctx->byte_order); - if (mhod3_type != MHOD_ARTWORK_TYPE_FILE_NAME) { + if (mhod->mhod_type != MHOD_ARTWORK_TYPE_FILE_NAME) { + g_free (mhod->mhod_string); + g_free (mhod); return -1; } - thumb->filename = mhod3_get_ithmb_filename (ctx, mhod3); - dump_mhod_type_3 (mhod3); + + thumb->filename = mhod->mhod_string; + g_free (mhod); return 0; } @@ -209,11 +227,7 @@ parse_photo_mhod (DBParseContext *ctx, Itdb_Artwork *artwork, GError *error) type = get_gint16 (mhod->type, ctx->byte_order); - if ( type == MHOD_ARTWORK_TYPE_ALBUM_NAME) { - dump_mhod_type_1 ((MhodHeaderArtworkType1 *)mhod); - } else { - dump_mhod (mhod); - } + dump_mhod (mhod); /* if this is a container... */ if (type == MHOD_ARTWORK_TYPE_THUMBNAIL) { @@ -318,6 +332,7 @@ static int parse_mhba (DBParseContext *ctx, GError *error) { MhbaHeader *mhba; + DBParseContext *mhod_ctx; DBParseContext *mhia_ctx; Itdb_PhotoAlbum *album; Itdb_PhotoDB *photodb; @@ -354,37 +369,34 @@ parse_mhba (DBParseContext *ctx, GError *error) cur_offset = ctx->header_len; num_children = get_gint32 (mhba->num_mhods, ctx->byte_order); - while (num_children > 0) - { - ArtworkDB_MhodHeaderString *mhod1; - ArtworkDB_MhodHeader *mhod; - DBParseContext *mhod_ctx; - mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); - /* FIXME: First mhod is album name, whats the others for? */ - mhod = db_parse_context_get_m_header (mhod_ctx, - ArtworkDB_MhodHeader, "mhod"); - if (mhod == NULL) { + mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + while ((num_children > 0) && (mhod_ctx != NULL)) { + struct ParsedMhodString *mhod; + + mhod = parse_mhod_string (mhod_ctx, error); + if (mhod == NULL) { + break; + } + switch (mhod->mhod_type) + { /* FIXME: type==1 is album name. type==2 seems to be + * the transtition type between photos, + * e.g. "Dissolve". Not handled yet. */ + case MHOD_ARTWORK_TYPE_ALBUM_NAME: + g_free (album->name); + album->name = mhod->mhod_string; + g_free (mhod); + break; + default: + g_free (mhod->mhod_string); + g_free (mhod); + break; + } + cur_offset += mhod_ctx->total_len; g_free (mhod_ctx); - return -1; - } - db_parse_context_set_total_len (mhod_ctx, - get_gint32(mhod->total_len, ctx->byte_order)); - mhod1 = (ArtworkDB_MhodHeaderString*)mhod; - switch (mhod1->type) - { /* FIXME: type==1 is album name. type==2 seems to be - * the transtition type between photos, - * e.g. "Dissolve". Not handled yet. */ - case MHOD_ARTWORK_TYPE_ALBUM_NAME: - album->name = g_strndup ((gchar *)mhod1->string, - get_gint32(mhod1->string_len, ctx->byte_order)); - dump_mhod_type_1 (mhod1); - break; - } - cur_offset += mhod_ctx->total_len; - g_free (mhod_ctx); - num_children--; - } + num_children--; + mhod_ctx = db_parse_context_get_sub_context (ctx, cur_offset); + } mhia_ctx = db_parse_context_get_sub_context (ctx, cur_offset); num_children = get_gint32 (mhba->num_mhias, ctx->byte_order); diff --git a/src/db-artwork-writer.c b/src/db-artwork-writer.c index 4d4088b..21b6a91 100644 --- a/src/db-artwork-writer.c +++ b/src/db-artwork-writer.c @@ -261,7 +261,7 @@ write_mhod_type_1 (gchar *string, iPodBuffer *buffer) total_bytes += len + padding; mhod->total_len = get_gint32 (total_bytes, buffer->byte_order); - dump_mhod_type_1 (mhod); + dump_mhod_string (mhod); return total_bytes; } @@ -351,7 +351,7 @@ write_mhod_type_3 (gchar *string, iPodBuffer *buffer) } mhod->total_len = get_gint32 (total_bytes, buffer->byte_order); - dump_mhod_type_3 (mhod); + dump_mhod_string (mhod); return total_bytes; } diff --git a/src/db-itunes-parser.h b/src/db-itunes-parser.h index 728ce2b..7cb0cf9 100644 --- a/src/db-itunes-parser.h +++ b/src/db-itunes-parser.h @@ -364,7 +364,7 @@ struct _ArtworkDB_MhodHeaderString { unsigned char header_id[4]; gint32 header_len; gint32 total_len; - gint16 type; /* 3 */ + gint16 type; gint8 unknown13; gint8 padding_len; gint32 unknown1; |