From: <ny...@us...> - 2006-12-24 02:42:41
|
Revision: 194 http://svn.sourceforge.net/pmplib/?rev=194&view=rev Author: nyaochi Date: 2006-12-23 18:42:41 -0800 (Sat, 23 Dec 2006) Log Message: ----------- - Initial attempt to support iriver E10 (and possibly S10/S7) - Directory lib/pmp_iriverplus3 was added - The database structure was mostly figured out - PMPlib interface follows later - No POSIX support until database writer is ready Modified Paths: -------------- trunk/pmplib/pmp.sln Added Paths: ----------- trunk/pmplib/lib/pmp_iriverplus3/ trunk/pmplib/lib/pmp_iriverplus3/dat.c trunk/pmplib/lib/pmp_iriverplus3/dat.h trunk/pmplib/lib/pmp_iriverplus3/dic.c trunk/pmplib/lib/pmp_iriverplus3/dic.h trunk/pmplib/lib/pmp_iriverplus3/idx.c trunk/pmplib/lib/pmp_iriverplus3/idx.h trunk/pmplib/lib/pmp_iriverplus3/ip3db.c trunk/pmplib/lib/pmp_iriverplus3/ip3db.h trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.vcproj trunk/pmplib/lib/pmp_iriverplus3/serialize.c trunk/pmplib/lib/pmp_iriverplus3/serialize.h trunk/pmplib/lib/pmp_iriverplus3/util.c trunk/pmplib/lib/pmp_iriverplus3/util.h Added: trunk/pmplib/lib/pmp_iriverplus3/dat.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dat.c (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/dat.c 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,318 @@ +/* + * Low-level library for db.dat. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +/* +Brief summary of db.dat structure: +- 0x00000000-0x0001FFFF: object (path name) chunk +- 0x00020000-0x0003FFFF: music (media information) chunk +- Each chunk has a 16-bytes header at the beginning +- Each chunk has an array of offsets to actual entries at the end (backward) +- Field names in db.dat seem to be defined in db.dic (Music and Objects) +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> +#include <ucs2char.h> + +#include "serialize.h" +#include "util.h" +#include "dat.h" + +static void dat_object_finish(dat_object_t* entry) +{ + ucs2free(entry->object_name); + ucs2free(entry->name); +} + +static void dat_objects_init(dat_objects_t* objects) +{ + memset(objects, 0, sizeof(dat_objects_t)); +} + +static void dat_objects_finish(dat_objects_t* objects) +{ + uint32_t i; + for (i = 0;i < objects->num_entries;++i) { + dat_object_finish(&objects->entries[i]); + } + free(objects->entries); + free(objects->offsets); + dat_objects_init(objects); +} + +static size_t dat_objects_serialize(uint8_t* buffer, dat_objects_t* objects, int is_storing) +{ + uint32_t i; + uint8_t *p = buffer; + uint8_t *q = buffer + 0x00020000 - sizeof(uint32_t); + + p += serialize_uint32be(p, &objects->size, is_storing); + p += serialize_uint32be(p, &objects->num_entries, is_storing); + p += serialize_uint32be(p, &objects->unknown1, is_storing); + p += serialize_uint32be(p, &objects->unknown2, is_storing); + + if (!is_storing) { + free(objects->entries); + free(objects->offsets); + objects->entries = (dat_object_t*)calloc(objects->num_entries, sizeof(dat_object_t)); + objects->offsets = (uint32_t*)calloc(objects->num_entries, sizeof(uint32_t)); + } + + for (i = 0;i < objects->num_entries;++i) { + dat_object_t* entry = &objects->entries[i]; + + /* Read an element in the offset table. */ + q -= serialize_uint32be(q, &objects->offsets[i], is_storing); + + /* Read an entry. */ + p += serialize_uint32be(p, &entry->uid, is_storing); + p += serialize_uint32be(p, &entry->parent_uid, is_storing); + p += serialize_uint8(p, &entry->properties, is_storing); + p += serialize_uint16be(p, &entry->filetype, is_storing); + if (is_storing) { + p += (serialize_ucs2be_string_var(p, entry->object_name, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->name, is_storing) + 1) * sizeof(ucs2char_t); + } else { + p += (serialize_ucs2be_string_var_alloc(p, &entry->object_name) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->name) + 1) * sizeof(ucs2char_t); + } + p += serialize_uint32be(p, &entry->filesize, is_storing); + p += serialize_uint32be(p, &entry->datecrea, is_storing); + p += serialize_uint32be(p, &entry->rawid, is_storing); + p += serialize_uint32be(p, &entry->puoid1, is_storing); + p += serialize_uint32be(p, &entry->puoid2, is_storing); + } + + return (size_t)(p - buffer); +} + +static void dat_objects_dump(FILE *fp, dat_objects_t* objects) +{ + uint32_t i; + + fprintf(fp, "OBJECTS {\n"); + fprintf(fp, " size: 0x%08X\n", objects->size); + fprintf(fp, " num_entries: %d\n", objects->num_entries); + fprintf(fp, " unknown1: 0x%08X\n", objects->unknown1); + fprintf(fp, " unknown2: 0x%08X\n", objects->unknown2); + + for (i = 0;i < objects->num_entries;++i) { + dat_object_t* entry = &objects->entries[i]; + fprintf(fp, " ENTRY %d (0x%08X) = {\n", i, objects->offsets[i]); + fprintf(fp, " uid: %d\n", entry->uid); + fprintf(fp, " parent_uid: %d\n", entry->parent_uid); + fprintf(fp, " properties: 0x%02X\n", entry->properties); + fprintf(fp, " filetype: 0x%04X\n", entry->filetype); + fprints(fp, " object_name: %s\n", entry->object_name); + fprints(fp, " name: %s\n", entry->name); + fprintf(fp, " filesize: %d\n", entry->filesize); + fprintf(fp, " datecrea: %d\n", entry->datecrea); + fprintf(fp, " rawid: %d\n", entry->rawid); + fprintf(fp, " puoid1: %d\n", entry->puoid1); + fprintf(fp, " puoid2: %d\n", entry->puoid2); + fprintf(fp, " }\n"); + } + fprintf(fp, "}\n"); +} + + + +static void dat_music_finish(dat_music_t* entry) +{ + ucs2free(entry->artist); + ucs2free(entry->album); + ucs2free(entry->genre); + ucs2free(entry->title); + ucs2free(entry->filepath); + ucs2free(entry->filename); + ucs2free(entry->release); + ucs2free(entry->album_artist); +} + +static void dat_musics_init(dat_musics_t* musics) +{ + memset(musics, 0, sizeof(dat_musics_t)); +} + +static void dat_musics_finish(dat_musics_t* musics) +{ + uint32_t i; + for (i = 0;i < musics->num_entries;++i) { + dat_music_finish(&musics->entries[i]); + } + free(musics->entries); + free(musics->offsets); + dat_musics_init(musics); +} + +static size_t dat_musics_serialize(uint8_t* buffer, dat_musics_t* musics, int is_storing) +{ + uint32_t i; + uint8_t *p = buffer; + uint8_t *q = buffer + 0x00020000 - sizeof(uint32_t); + + p += serialize_uint32be(p, &musics->size, is_storing); + p += serialize_uint32be(p, &musics->num_entries, is_storing); + p += serialize_uint32be(p, &musics->unknown1, is_storing); + p += serialize_uint32be(p, &musics->unknown2, is_storing); + + if (!is_storing) { + free(musics->entries); + free(musics->offsets); + musics->entries = (dat_music_t*)calloc(musics->num_entries, sizeof(dat_music_t)); + musics->offsets = (uint32_t*)calloc(musics->num_entries, sizeof(uint32_t)); + } + + for (i = 0;i < musics->num_entries;++i) { + dat_music_t* entry = &musics->entries[i]; + + /* Read an element in the offset table. */ + q -= serialize_uint32be(q, &musics->offsets[i], is_storing); + + /* Read an entry. */ + if (is_storing) { + p += (serialize_ucs2be_string_var(p, entry->artist, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->album, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->genre, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->title, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->filepath, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->filename, is_storing) + 1) * sizeof(ucs2char_t); + } else { + p += (serialize_ucs2be_string_var_alloc(p, &entry->artist) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->album) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->genre) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->title) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->filepath) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->filename) + 1) * sizeof(ucs2char_t); + } + p += serialize_uint32be(p, &entry->duration, is_storing); + p += serialize_uint16be(p, &entry->rating, is_storing); + p += serialize_uint32be(p, &entry->use_count, is_storing); + p += serialize_uint16be(p, &entry->format, is_storing); + p += serialize_uint16be(p, &entry->tracknumber, is_storing); + p += serialize_uint8(p, &entry->drm, is_storing); + p += serialize_uint8(p, &entry->lyric, is_storing); + p += serialize_uint8(p, &entry->purchase, is_storing); + p += serialize_uint16be(p, &entry->protection, is_storing); + p += serialize_uint32be(p, &entry->samplerate, is_storing); + p += serialize_uint32be(p, &entry->bitrate, is_storing); + p += serialize_uint8(p, &entry->changed_flag, is_storing); + p += serialize_uint32be(p, &entry->codec, is_storing); + p += serialize_uint32be(p, &entry->clusm, is_storing); + p += serialize_uint32be(p, &entry->clusa, is_storing); + p += serialize_uint32be(p, &entry->albumart_pos, is_storing); + if (is_storing) { + p += (serialize_ucs2be_string_var(p, entry->release, is_storing) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var(p, entry->album_artist, is_storing) + 1) * sizeof(ucs2char_t); + } else { + p += (serialize_ucs2be_string_var_alloc(p, &entry->release) + 1) * sizeof(ucs2char_t); + p += (serialize_ucs2be_string_var_alloc(p, &entry->album_artist) + 1) * sizeof(ucs2char_t); + } + p += serialize_uint32be(p, &entry->object_uid, is_storing); + p += serialize_uint32be(p, &entry->ratingtime, is_storing); + } + + return (size_t)(p - buffer); +} + +static void dat_musics_dump(FILE *fp, dat_musics_t* musics) +{ + uint32_t i; + + fprintf(fp, "MUSICS {\n"); + fprintf(fp, " size: 0x%08X\n", musics->size); + fprintf(fp, " num_entries: %d\n", musics->num_entries); + fprintf(fp, " unknown1: 0x%08X\n", musics->unknown1); + fprintf(fp, " unknown2: 0x%08X\n", musics->unknown2); + + for (i = 0;i < musics->num_entries;++i) { + dat_music_t* entry = &musics->entries[i]; + + fprintf(fp, " ENTRY %d (0x%08X) = {\n", i, musics->offsets[i]); + fprints(fp, " artist: %s\n", entry->artist); + fprints(fp, " album: %s\n", entry->album); + fprints(fp, " genre: %s\n", entry->genre); + fprints(fp, " title: %s\n", entry->title); + fprints(fp, " filepath: %s\n", entry->filepath); + fprints(fp, " filename: %s\n", entry->filename); + fprintf(fp, " duration: %d\n", entry->duration); + fprintf(fp, " rating: %d\n", entry->rating); + fprintf(fp, " use_count: %d\n", entry->use_count); + fprintf(fp, " format: 0x%04X\n", entry->format); + fprintf(fp, " tracknumber: %d\n", entry->tracknumber); + fprintf(fp, " drm: 0x%02X\n", entry->drm); + fprintf(fp, " lyric: 0x%02X\n", entry->lyric); + fprintf(fp, " purchase: 0x%02X\n", entry->purchase); + fprintf(fp, " protection: 0x%04X\n", entry->protection); + fprintf(fp, " samplerate: %d\n", entry->samplerate); + fprintf(fp, " bitrate: %d\n", entry->bitrate); + fprintf(fp, " changed_flag: 0x%02X\n", entry->changed_flag); + fprintf(fp, " codec: 0x%08X\n", entry->codec); + fprintf(fp, " clusm: 0x%08X\n", entry->clusm); + fprintf(fp, " clusa: 0x%08X\n", entry->clusa); + fprintf(fp, " albumart_pos: 0x%08X\n", entry->albumart_pos); + fprints(fp, " release: %s\n", entry->release); + fprints(fp, " album_artist: %s\n", entry->album_artist); + fprintf(fp, " object_uid: %d\n", entry->object_uid); + fprintf(fp, " ratingtime: %d\n", entry->ratingtime); + fprintf(fp, " }\n"); + } + fprintf(fp, "}\n"); +} + +dat_t* dat_new() +{ + dat_t* dat = (dat_t*)malloc(sizeof(dat_t)); + if (dat) { + dat_objects_init(&dat->objects); + dat_musics_init(&dat->musics); + } + return dat; +} + +void dat_finish(dat_t* dat) +{ + dat_objects_finish(&dat->objects); + dat_musics_finish(&dat->musics); + free(dat); +} + +size_t dat_serialize(uint8_t* buffer, dat_t* dat, int is_storing) +{ + dat_objects_serialize(buffer, &dat->objects, is_storing); + dat_musics_serialize(buffer + 0x00020000, &dat->musics, is_storing); + return 0; +} + +void dat_dump(FILE *fp, dat_t* dat) +{ + fprintf(fp, "===== db.dat =====\n"); + dat_objects_dump(fp, &dat->objects); + dat_musics_dump(fp, &dat->musics); +} Property changes on: trunk/pmplib/lib/pmp_iriverplus3/dat.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/dat.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dat.h (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/dat.h 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,99 @@ +/* + * Low-level library for db.dat. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +#ifndef __IP3DB_DAT_H__ +#define __IP3DB_DAT_H__ + +typedef struct { + uint32_t uid; + uint32_t parent_uid; + uint8_t properties; + uint16_t filetype; + ucs2char_t* object_name; + ucs2char_t* name; + uint32_t filesize; + uint32_t datecrea; + uint32_t rawid; + uint32_t puoid1; + uint32_t puoid2; +} dat_object_t; + +typedef struct { + uint32_t size; + uint32_t num_entries; + uint32_t unknown1; + uint32_t unknown2; + dat_object_t* entries; + uint32_t* offsets; +} dat_objects_t; + +typedef struct { + ucs2char_t* artist; + ucs2char_t* album; + ucs2char_t* genre; + ucs2char_t* title; + ucs2char_t* filepath; + ucs2char_t* filename; + uint32_t duration; + uint16_t rating; + uint32_t use_count; + uint16_t format; + uint16_t tracknumber; + uint8_t drm; + uint8_t lyric; + uint8_t purchase; + uint16_t protection; + uint32_t samplerate; + uint32_t bitrate; + uint8_t changed_flag; + uint32_t codec; + uint32_t clusm; + uint32_t clusa; + uint32_t albumart_pos; + ucs2char_t* release; + ucs2char_t* album_artist; + uint32_t object_uid; + uint32_t ratingtime; +} dat_music_t; + +typedef struct { + uint32_t size; + uint32_t num_entries; + uint32_t unknown1; + uint32_t unknown2; + dat_music_t* entries; + uint32_t* offsets; +} dat_musics_t; + +struct tag_dat_t { + dat_objects_t objects; + dat_musics_t musics; +}; +typedef struct tag_dat_t dat_t; + +dat_t* dat_new(); +void dat_finish(dat_t* dat); +size_t dat_serialize(uint8_t* buffer, dat_t* dat, int is_storing); +void dat_dump(FILE *fp, dat_t* dat); + +#endif/*__IP3DB_DAT_H__*/ Property changes on: trunk/pmplib/lib/pmp_iriverplus3/dat.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/dic.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dic.c (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/dic.c 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,59 @@ +/* + * Low-level library for db.dic. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +/* +Some important findings from db.dic: +- This file seems to define field names/types in a database. +- This file stores offset addresses of root nodes in db.idx. +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> +#include <ucs2char.h> + +#include "serialize.h" +#include "ip3db.h" + +/* +typedef struct { + uint32_t next; + uint32_t type; + uint32_t idx_root; + ucs2char_t* name; +} dic_entry_t; +*/ + +uint32_t dic_get_idxroot(uint8_t *buffer, int field) +{ + uint32_t value; + ip3db_index_param_t* index_param = ip3db_get_indexparam(field); + uint8_t *p = buffer + index_param->dic_offset; + serialize_uint32be(p + sizeof(uint32_t) * 2, &value, 0); + return value; +} Property changes on: trunk/pmplib/lib/pmp_iriverplus3/dic.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/dic.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/dic.h (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/dic.h 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,29 @@ +/* + * Low-level library for db.dic. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +#ifndef __IP3DB_DIC_H__ +#define __IP3DB_DIC_H__ + +uint32_t dic_get_idxroot(uint8_t *buffer, int field); + +#endif/*__IP3DB_DIC_H__*/ Property changes on: trunk/pmplib/lib/pmp_iriverplus3/dic.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/idx.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.c (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.c 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,292 @@ +/* + * Low-level library for db.idx. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +/* +Brief summary of db.idx structure: +- This file seems to have 12-bytes header +- Indices consist of multiple binary search trees +- The offset addresses to the root nodes are specified in db.dic +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <stdio.h> +#include <stdlib.h> +#include <memory.h> +#include <ucs2char.h> + +#include "serialize.h" +#include "util.h" +#include "ip3db.h" +#include "dic.h" + +typedef struct { + uint32_t size; + uint32_t unknown1; + uint32_t unknown2; +} header_t; + +typedef struct { + uint32_t left; + uint32_t right; + uint32_t height; + uint32_t leaf; +} node_t; + +typedef struct { + uint32_t dat_offset; + uint32_t next; +} tail_t; + +typedef struct { + uint32_t type; + union { + uint8_t byte; + uint16_t word; + uint32_t dword; + ucs2char_t* str; + } value; +} variant_t; + +static size_t idx_serialize_header(uint8_t *block, header_t *header, int is_storing) +{ + uint8_t *p = block; + p += serialize_uint32be(p, &header->size, is_storing); + p += serialize_uint32be(p, &header->unknown1, is_storing); + p += serialize_uint32be(p, &header->unknown2, is_storing); + return sizeof(header_t); +} + +static size_t idx_serialize_node(uint8_t *block, node_t *node, int is_storing) +{ + uint8_t *p = block; + p += serialize_uint32be(p, &node->left, 0); + p += serialize_uint32be(p, &node->right, 0); + p += serialize_uint32be(p, &node->height, 0); + p += serialize_uint32be(p, &node->leaf, 0); + return sizeof(node_t); +} + +static size_t idx_serialize_tail(uint8_t *block, tail_t* tail, int is_storing) +{ + uint8_t *p = block; + p += serialize_uint32be(p, &tail->dat_offset, is_storing); + p += serialize_uint32be(p, &tail->next, is_storing); + return sizeof(tail_t); +} + +void variant_init(variant_t* var, int type) +{ + memset(var, 0, sizeof(*var)); + var->type = type; +} + +void variant_finish(variant_t* var) +{ + if (var->type == IP3DBVT_STRING) { + ucs2free(var->value.str); + } + variant_init(var, IP3DBVT_NONE); +} + +/** + * Prototype definition of a callback function for idx_walk. + * @param buffer The pointer to the index buffer. + * @param offset The offset address of the current node. + * @param node The information of the node. + * @param key The key value of the node. + * @param types The key types. + * @param level The current key level. + * @param flag + * @param instance The instance value. + */ +typedef int (*idx_walk_callback_t)( + uint8_t* buffer, + uint32_t offset, + node_t* node, + variant_t* key, + int* types, + int level, + int flag, + void *instance + ); + +void idx_walk( + uint8_t *buffer, + uint32_t offset, + int *types, + int level, + idx_walk_callback_t callback, + void *instance + ) +{ + node_t node; + variant_t key; + int type = types[level]; + uint8_t* p = buffer + offset; + + /* Read the node information. */ + p += idx_serialize_node(p, &node, 0); + + /* Descend to left children. */ + if (node.left) { + idx_walk(buffer, node.left, types, level, callback, instance); + } + + /* Read the key value. */ + variant_init(&key, type); + switch (type) { + case IP3DBVT_BYTE: + p += serialize_uint8(p, &key.value.byte, 0); + break; + case IP3DBVT_WORD: + p += serialize_uint16be(p, &key.value.word, 0); + break; + case IP3DBVT_DWORD: + p += serialize_uint32be(p, &key.value.dword, 0); + break; + case IP3DBVT_STRING: + p += serialize_ucs2be_string_var_alloc(p, &key.value.str) * sizeof(ucs2char_t); + break; + } + + /* Invoke the callback function. */ + if (callback && type) { + callback(buffer, offset, &node, &key, types, level, 1, instance); + } + + /* Descend to the next key level if necessary. */ + if (level+1 < IP3DBIDX_MAX_KEYLEVEL && types[level+1]) { + idx_walk(buffer, node.leaf, types, level+1, callback, instance); + } + + /* Invoke the callback function. */ + if (callback && type) { + callback(buffer, offset, &node, &key, types, level, 0, instance); + } + + /* Descend to right children. */ + if (node.right) { + idx_walk(buffer, node.right, types, level, callback, instance); + } +} + +static void fprinti(FILE *fp, int n) +{ + while (n--) fputc(' ', fp); +} + +int idx_walkcb_dump( + uint8_t* buffer, + uint32_t offset, + node_t* node, + variant_t* key, + int* types, + int level, + int flag, + void *instance + ) +{ + FILE *fp = (FILE*)instance; + int indent = 2 * (level + 1); + + if (flag) { + fprinti(fp, indent); + fprintf(fp, "NODE (0x%08X) = {\n", offset); + fprinti(fp, indent); + fprintf(fp, " left: 0x%08X\n", node->left); + fprinti(fp, indent); + fprintf(fp, " right: 0x%08X\n", node->right); + fprinti(fp, indent); + fprintf(fp, " data: 0x%08X\n", node->leaf); + + fprinti(fp, indent); + fprintf(fp, " key: "); + switch (key->type) { + case IP3DBVT_BYTE: + fprintf(fp, "0x%02X", key->value.byte); + break; + case IP3DBVT_WORD: + fprintf(fp, "0x%04X", key->value.word); + break; + case IP3DBVT_DWORD: + fprintf(fp, "0x%08X", key->value.dword); + break; + case IP3DBVT_STRING: + fprints(fp, "%s", key->value.str); + break; + } + fprintf(fp, "\n"); + + if (IP3DBIDX_MAX_KEYLEVEL <= level+1 || !types[level+1]) { + tail_t tail; + + memset(&tail, 0, sizeof(tail)); + tail.next = node->leaf; + + fprinti(fp, indent); + fprintf(fp, " dat_offset: [\n", node->left); + while (tail.next) { + uint8_t *p = buffer + tail.next; + idx_serialize_tail(p, &tail, 0); + fprinti(fp, indent); + fprintf(fp, " 0x%08X\n", tail.dat_offset); + } + fprinti(fp, indent); + fprintf(fp, " ]\n", node->left); + } + } else { + fprinti(fp, indent); + fprintf(fp, "}\n"); + } + + return 0; +} + +int idx_dump(FILE *fpo, ip3db_t* db) +{ + int i; + header_t header; + + fprintf(fpo, "===== db.idx =====\n"); + + /* Dump the header. */ + idx_serialize_header(db->idx_buffer, &header, 0); + fprintf(fpo, "size: 0x%08X\n", header.size); + fprintf(fpo, "unknown1: 0x%08X\n", header.unknown1); + fprintf(fpo, "unknown2: 0x%08X\n", header.unknown2); + + /* Dump the binary search trees. */ + for (i = 0;i < IP3DBIDX_LAST;++i) { + ip3db_index_param_t* index_param = ip3db_get_indexparam(i); + uint32_t idx_root = dic_get_idxroot(db->dic_buffer, i); + fprintf(fpo, "[%s]\n", index_param->name); + idx_walk(db->idx_buffer, idx_root, index_param->types, 0, idx_walkcb_dump, (void*)stdout); + } + + fprintf(fpo, "\n"); + return 0; +} Property changes on: trunk/pmplib/lib/pmp_iriverplus3/idx.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/idx.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/idx.h (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/idx.h 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,28 @@ +/* + * Low-level library for db.idx. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +#ifndef __IP3DB_IDX_H__ +#define __IP3DB_IDX_H__ + + +#endif/*__IP3DB_IDX_H__*/ Property changes on: trunk/pmplib/lib/pmp_iriverplus3/idx.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/ip3db.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/ip3db.c (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/ip3db.c 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,127 @@ +/* + * Media database reader/writer for iriver E10. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <stdio.h> +#include <stdlib.h> +#include <ucs2char.h> + +#include "util.h" +#include "dat.h" +#include "ip3db.h" + +static ip3db_index_param_t ip3db_index_param[IP3DBIDX_LAST] = { + {"Music.Title", 0x0086, {IP3DBVT_STRING, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Music.Rating", 0x00F8, {IP3DBVT_WORD, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Music.TrackNumber", 0x0152, {IP3DBVT_WORD, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Music.ChangedFlag", 0x022C, {IP3DBVT_BYTE, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Music.ClusM", 0x027A, {IP3DBVT_DWORD, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Music.UID", 0x031C, {IP3DBVT_DWORD, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Music.Genre-Artist-Title", 0x0352, {IP3DBVT_STRING, IP3DBVT_STRING, IP3DBVT_STRING}}, + {"Music.Artist-Album-TrackNumber", 0x0384, {IP3DBVT_STRING, IP3DBVT_STRING, IP3DBVT_WORD}}, + {"Music.Artist-TrackNumber", 0x03C2, {IP3DBVT_STRING, IP3DBVT_WORD, IP3DBVT_NONE}}, + {"Music.Artist-Title", 0x03F4, {IP3DBVT_STRING, IP3DBVT_STRING, IP3DBVT_NONE}}, + {"Music.Genre-Title", 0x041A, {IP3DBVT_STRING, IP3DBVT_STRING, IP3DBVT_NONE}}, + {"Music.Album-TrackNumber", 0x043E, {IP3DBVT_STRING, IP3DBVT_WORD, IP3DBVT_NONE}}, + {"Object.UID", 0x099A, {IP3DBVT_DWORD, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Object.FileType", 0x09F0, {IP3DBVT_WORD, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Object.ObjectName", 0x0A0E, {IP3DBVT_STRING, IP3DBVT_NONE, IP3DBVT_NONE}}, + {"Object.FileType-ParentUid-Properties", 0x0ACE, {IP3DBVT_WORD, IP3DBVT_DWORD, IP3DBVT_BYTE}}, +}; + +ip3db_index_param_t* ip3db_get_indexparam(int field) +{ + return &ip3db_index_param[field]; +} + +void ip3db_init(ip3db_t* db) +{ + memset(db, 0, sizeof(*db)); +} + +void ip3db_finish(ip3db_t* db) +{ + free(db->dat_buffer); + free(db->dic_buffer); + free(db->idx_buffer); + ip3db_init(db); +} + +static const ucs2char_t g_ucs2cs_datdb[] = {'d','b','.','d','a','t',0}; +static const ucs2char_t g_ucs2cs_dicdb[] = {'d','b','.','d','i','c',0}; +static const ucs2char_t g_ucs2cs_idxdb[] = {'d','b','.','i','d','x',0}; + +result_t ip3db_load(ip3db_t* db, const ucs2char_t* path) +{ + FILE *fp = 0; + ucs2char_t filename[MAX_PATH]; + + ucs2cpy(filename, path); + ucs2cat(filename, g_ucs2cs_datdb); + fp = ucs2fopen(filename, "rb"); + if (!fp) { + ip3db_finish(db); + return 1; + } + fread_all(fp, &db->dat_buffer, &db->dat_size); + fclose(fp); + + ucs2cpy(filename, path); + ucs2cat(filename, g_ucs2cs_dicdb); + fp = ucs2fopen(filename, "rb"); + if (!fp) { + ip3db_finish(db); + return 1; + } + fread_all(fp, &db->dic_buffer, &db->dic_size); + fclose(fp); + + ucs2cpy(filename, path); + ucs2cat(filename, g_ucs2cs_idxdb); + fp = ucs2fopen(filename, "rb"); + if (!fp) { + ip3db_finish(db); + return 1; + } + fread_all(fp, &db->idx_buffer, &db->idx_size); + fclose(fp); + + return 0; +} + +result_t ip3db_dump(FILE *fpo, ip3db_t* db) +{ + /* Dump db.dat */ + dat_t* dat = dat_new(); + dat_serialize(db->dat_buffer, dat, 0); + dat_dump(fpo, dat); + dat_finish(dat); + + /* Dump db.idx */ + idx_dump(fpo, db); + return 0; +} \ No newline at end of file Property changes on: trunk/pmplib/lib/pmp_iriverplus3/ip3db.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/ip3db.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/ip3db.h (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/ip3db.h 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,88 @@ +/* + * Media database reader/writer for iriver E10. + * + * Copyright (c) 2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id:$ */ + +#ifndef __IP3DB_IP3DB_H__ +#define __IP3DB_IP3DB_H__ + +enum { + IP3DBIDX_MUSIC_TITLE, + IP3DBIDX_MUSIC_RATING, + IP3DBIDX_MUSIC_TRACKNUMBER, + IP3DBIDX_MUSIC_CHANGEDFLAG, + IP3DBIDX_MUSIC_CLUSM, + IP3DBIDX_MUSIC_UID, + IP3DBIDX_MUSIC_GENRE_ARTIST_TITLE, + IP3DBIDX_MUSIC_ARTIST_ALBUM_TRACKNUMBER, + IP3DBIDX_MUSIC_ARTIST_TRACKNUMBER, + IP3DBIDX_MUSIC_ARTIST_TITLE, + IP3DBIDX_MUSIC_GENRE_TITLE, + IP3DBIDX_MUSIC_ALBUM_TRACKNUMBER, + IP3DBIDX_OBJECT_UID, + IP3DBIDX_OBJECT_FILETYPE, + IP3DBIDX_OBJECT_OBJECTNAME, + IP3DBIDX_OBJECT_FILETYPE_PARENTUID_PROP, + IP3DBIDX_LAST +}; + +enum { + IP3DBIDX_MAX_KEYLEVEL = 3, +}; + +enum { + IP3DBVT_NONE, + IP3DBVT_BYTE, + IP3DBVT_WORD, + IP3DBVT_DWORD, + IP3DBVT_STRING, +}; + + +typedef struct { + const char* name; + uint32_t dic_offset; + int types[IP3DBIDX_MAX_KEYLEVEL]; +} ip3db_index_param_t; + +struct tag_dat_t; typedef struct tag_dat_t dat_t; + +typedef struct { + uint8_t* dat_buffer; + long dat_size; + uint8_t* dic_buffer; + long dic_size; + uint8_t* idx_buffer; + long idx_size; + + dat_t* dat; +} ip3db_t; + +int idx_dump(FILE *fpo, ip3db_t* db); + +ip3db_index_param_t* ip3db_get_indexparam(int field); + +void ip3db_init(ip3db_t* db); +void ip3db_finish(ip3db_t* db); +result_t ip3db_load(ip3db_t* db, const ucs2char_t* path); +result_t ip3db_dump(FILE *fpo, ip3db_t* db); + +#endif /*_IP3DB_IP3DB_H__*/ Property changes on: trunk/pmplib/lib/pmp_iriverplus3/ip3db.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.vcproj =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.vcproj (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/pmp_iriverplus3.vcproj 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,243 @@ +<?xml version="1.0" encoding="shift_jis"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="pmp_iriverplus3" + ProjectGUID="{C74FE9C9-B5C4-438A-B157-9BCB6C8A7546}" + RootNamespace="pmp_iriverplus3" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="$(SolutionDir)include" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PMP_IRIVERPLUS3_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="$(SolutionDir)include" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;PMP_IRIVERPLUS3_EXPORTS" + RuntimeLibrary="2" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="\x83\\x81[\x83X \x83t\x83@\x83C\x83\x8B" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\dat.c" + > + </File> + <File + RelativePath=".\dic.c" + > + </File> + <File + RelativePath=".\idx.c" + > + </File> + <File + RelativePath=".\ip3db.c" + > + </File> + <File + RelativePath=".\serialize.c" + > + </File> + <File + RelativePath=".\util.c" + > + </File> + </Filter> + <Filter + Name="\x83w\x83b\x83_\x81[ \x83t\x83@\x83C\x83\x8B" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\dat.h" + > + </File> + <File + RelativePath=".\dic.h" + > + </File> + <File + RelativePath=".\idx.h" + > + </File> + <File + RelativePath=".\ip3db.h" + > + </File> + <File + RelativePath=".\serialize.h" + > + </File> + <File + RelativePath=".\util.h" + > + </File> + </Filter> + <Filter + Name="\x83\x8A\x83\\x81[\x83X \x83t\x83@\x83C\x83\x8B" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> Added: trunk/pmplib/lib/pmp_iriverplus3/serialize.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/serialize.c (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/serialize.c 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,155 @@ +/* + * Data serializer (with byte-order consideration). + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <memory.h> +#include <stddef.h> +#include <ucs2char.h> + +#include "serialize.h" + +size_t serialize_uint8(uint8_t* buffer, uint8_t* value, int is_storing) +{ + if (is_storing) { + *buffer = *value; + } else { + *value = *buffer; + } + return 1; +} + +size_t serialize_uint8_array(uint8_t* buffer, uint8_t* array, size_t length, int is_storing) +{ + size_t i; + for (i = 0;i < length;i++) { + buffer += serialize_uint8(buffer, array++, is_storing); + } + return length; +} + +size_t serialize_uint16be(uint8_t* buffer, uint16_t* value, int is_storing) +{ + if (is_storing) { + buffer[0] = (uint8_t)(*value >> 8); + buffer[1] = (uint8_t)(*value & 0xFF); + } else { + *value = (uint16_t)buffer[0] << 8 | (uint16_t)buffer[1]; + } + return sizeof(uint16_t); +} + +size_t serialize_uint16le(uint8_t* buffer, uint16_t* value, int is_storing) +{ + if (is_storing) { + buffer[1] = (uint8_t)(*value >> 8); + buffer[0] = (uint8_t)(*value & 0xFF); + } else { + *value = (uint16_t)buffer[1] << 8 | (uint16_t)buffer[0]; + } + return sizeof(uint16_t); +} + +size_t serialize_uint32be(uint8_t* buffer, uint32_t* value, int is_storing) +{ + if (is_storing) { + buffer[0] = (uint8_t)(*value >> 24); + buffer[1] = (uint8_t)(*value >> 16); + buffer[2] = (uint8_t)(*value >> 8); + buffer[3] = (uint8_t)(*value & 0xFF); + } else { + *value = + (uint32_t)buffer[0] << 24 | (uint32_t)buffer[1] << 16 | + (uint32_t)buffer[2] << 8 | (uint32_t)buffer[3]; + } + return sizeof(uint32_t); +} + +size_t serialize_uint32le(uint8_t* buffer, uint32_t* value, int is_storing) +{ + if (is_storing) { + buffer[3] = (uint8_t)(*value >> 24); + buffer[2] = (uint8_t)(*value >> 16); + buffer[1] = (uint8_t)(*value >> 8); + buffer[0] = (uint8_t)(*value & 0xFF); + } else { + *value = + (uint32_t)buffer[3] << 24 | (uint32_t)buffer[2] << 16 | + (uint32_t)buffer[1] << 8 | (uint32_t)buffer[0]; + } + return sizeof(uint32_t); +} + +size_t serialize_ucs2be(uint8_t* buffer, ucs2char_t* value, int is_storing) +{ + serialize_uint16be(buffer, (uint16_t*)value, is_storing); + return sizeof(ucs2char_t); +} + +size_t serialize_ucs2be_string_fixed(uint8_t* buffer, ucs2char_t* str, size_t length, int is_storing) +{ + size_t i; + for (i = 0;i < length;i++) { + serialize_ucs2be(buffer, str, is_storing); + buffer += sizeof(ucs2char_t); + ++str; + } + return length; +} + +size_t serialize_ucs2be_string_var(uint8_t* buffer, ucs2char_t* str, int is_storing) +{ + size_t length = 0; + while (serialize_ucs2be(buffer, str, is_storing), *str) { + ++length; + ++str; + buffer += sizeof(ucs2char_t); + } + return length; +} + +size_t serialize_ucs2be_string_var_alloc(uint8_t* buffer, ucs2char_t** str) +{ + ucs2char_t c; + size_t length = 0; + uint8_t* p = buffer; + + /* Measure the length of the string. */ + while (serialize_ucs2be(p, &c, 0), c) { + ++length; + p += sizeof(ucs2char_t); + } + + /* Allocate a string buffer. */ + ucs2free(*str); + *str = ucs2malloc(sizeof(ucs2char_t) * (length+1)); + memset(*str, 0, sizeof(ucs2char_t) * (length+1)); + + /* Read the string. */ + serialize_ucs2be_string_fixed(buffer, *str, length, 0); + + return length; +} Property changes on: trunk/pmplib/lib/pmp_iriverplus3/serialize.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/serialize.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/serialize.h (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/serialize.h 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,38 @@ +/* + * Data serializer (with byte-order consideration). + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifndef __IP2DB_SERIALIZE_H__ +#define __IP2DB_SERIALIZE_H__ + +size_t serialize_uint8(uint8_t* buffer, uint8_t* value, int is_storing); +size_t serialize_uint8_array(uint8_t* buffer, uint8_t* array, size_t length, int is_storing); +size_t serialize_uint16le(uint8_t* buffer, uint16_t* value, int is_storing); +size_t serialize_uint32le(uint8_t* buffer, uint32_t* value, int is_storing); +size_t serialize_uint16be(uint8_t* buffer, uint16_t* value, int is_storing); +size_t serialize_uint32be(uint8_t* buffer, uint32_t* value, int is_storing); +size_t serialize_ucs2be(uint8_t* buffer, ucs2char_t* value, int is_storing); +size_t serialize_ucs2be_string_fixed(uint8_t* buffer, ucs2char_t* str, size_t length, int is_storing); +size_t serialize_ucs2be_string_var(uint8_t* buffer, ucs2char_t* str, int is_storing); +size_t serialize_ucs2be_string_var_alloc(uint8_t* buffer, ucs2char_t** str); + +#endif/*__IP2DB_SERIALIZE_H__*/ Property changes on: trunk/pmplib/lib/pmp_iriverplus3/serialize.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/util.c =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/util.c (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/util.c 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,150 @@ +/* + * Miscellaneous utilities. + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif/*HAVE_CONFIG_H*/ + +#include <os.h> +#include <stdio.h> +#include <stdlib.h> +#include <ucs2char.h> +#include <malloc.h> + +#include "util.h" + +int is_all_value(uint8_t* array, size_t size, uint8_t value) +{ + size_t i; + for (i = 0;i < size;i++) { + if (array[0] != value) { + return 0; + } + } + return 1; +} + +void fprints(FILE *fp, const char *format, const ucs2char_t* value) +{ + fprints_fixed(fp, format, value, ucs2len(value)); +} + +void fprints_fixed(FILE *fp, const char *format, const ucs2char_t* value, size_t length) +{ + char *mbs = NULL; + ucs2char_t* tmp = alloca(sizeof(ucs2char_t) * (length+1)); + memset(tmp, 0, sizeof(ucs2char_t) * (length+1)); + ucs2ncpy(tmp, value, length); + mbs = ucs2dupmbs(tmp); + if (mbs) { + fprintf(fp, format, mbs); + ucs2free(mbs); + } +} + +void prints_fixed(FILE *fp, const ucs2char_t* value, size_t length) +{ + size_t i; + + for (i = 0;i < length;++i) { + if (value[i]) { + char mbs[8]; + memset(mbs, 0, sizeof(mbs)); + ucs2tombs(mbs, sizeof(mbs), &value[i], 1); + fprintf(fp, mbs); + } else { + fprintf(fp, " "); + } + } +} + +void fprintt(FILE *fp, const char *format, uint32_t value) +{ + static time_t basetime = 0; /* Basetime (static variable). */ + time_t timer = 0; + + /* Initialize basetime (Sat Jan 01 00:00:00 2000) for the first time. */ + if (basetime == 0) { + struct tm bt; + memset(&bt, 0, sizeof(bt)); + bt.tm_year = 2000 - 1900; + bt.tm_mon = 1 - 1; + bt.tm_mday = 1; + bt.tm_hour = 0; + bt.tm_min = 0; + bt.tm_sec = 0; + basetime = mktime(&bt); + } + + timer = basetime + (time_t)value; + fprintf(fp, format, asctime(gmtime(&timer))); +} + +void print_keystr(FILE *fp, const ucs2char_t* value, size_t length) +{ + size_t i; + + for (i = 0;i < length;++i) { + if (value[i] != 0xFFFF) { + break; + } + } + if (i < length) { + fprintf(fp, "\""); + prints_fixed(fp, value, length); + fprintf(fp, "\""); + } else { + fprintf(fp, "LAST"); + } +} + +void print_next(FILE *fp, const uint32_t value, uint8_t height) +{ + fprintf(fp, "%s%d", (height > 0 ? "@" : ""), value); +} + +int fread_all(FILE *fp, uint8_t** ptr_buffer, long* ptr_size) +{ + uint8_t* buffer = NULL; + long size = 0; + + /* Obtain the stream size. */ + if (fseek(fp, 0, SEEK_END) != 0) { + return 1; + } + if ((size = ftell(fp)) == -1) { + return 1; + } + if (fseek(fp, 0, SEEK_SET) != 0) { + return 1; + } + + /* */ + buffer = (uint8_t*)malloc(size); + + fread(buffer, 1, size, fp); + + *ptr_buffer = buffer; + *ptr_size = size; + return 0; +} Property changes on: trunk/pmplib/lib/pmp_iriverplus3/util.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/pmplib/lib/pmp_iriverplus3/util.h =================================================================== --- trunk/pmplib/lib/pmp_iriverplus3/util.h (rev 0) +++ trunk/pmplib/lib/pmp_iriverplus3/util.h 2006-12-24 02:42:41 UTC (rev 194) @@ -0,0 +1,38 @@ +/* + * Miscellaneous utilities. + * + * Copyright (c) 2005-2006 Nyaochi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/* $Id$ */ + +#ifndef __IP3DB_UTIL_H__ +#define __IP3DB_UTIL_H__ + +int is_all_value(uint8_t* array, size_t size, uint8_t value); + +void fprints(FILE *fp, const char *format, const ucs2char_t* value); +void fprints_fixed(FILE *fp, const char *format, const ucs2char_t* value, size_t length); +void prints_fixed(FILE *fp, const ucs2char_t* value, size_t length); +void fprintt(FILE *fp, const char *format, uint32_t value); +void print_keystr(FILE *fp, const ucs2char_t* value, size_t length); +void print_next(FILE *fp, const uint32_t value, uint8_t height); + +int fread_all(FILE *fp, uint8_t** ptr_buffer, long* ptr_size); + +#endif/*__IP3DB_UTIL_H__*/ Property changes on: trunk/pmplib/lib/pmp_iriverplus3/util.h ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/pmplib/pmp.sln =================================================================== --- trunk/pmplib/pmp.sln 2006-12-24 01:56:05 UTC (rev 193) +++ trunk/pmplib/pmp.sln 2006-12-24 02:42:41 UTC (rev 194) @@ -9,63 +9,70 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gmi", "lib\gmi\gmi.vcproj", "{3575EFC2-9051-467A-BEB4-E71E2F8664D7}" ProjectSection(ProjectDependencies) = postProject + {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} - {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmp", "lib\pmp\pmp.vcproj", "{8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A}" ProjectSection(ProjectDependencies) = postProject + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmp_irivnavi", "lib\pmp_irivnavi\pmp_irivnavi.vcproj", "{2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1}" ProjectSection(ProjectDependencies) = postProject + {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} - {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmp_iriverplus2", "lib\pmp_iriverplus2\pmp_iriverplus2.vcproj", "{E393575C-6B10-43BD-B2C0-63C5040A49F7}" ProjectSection(ProjectDependencies) = postProject + {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} - {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "playlist", "lib\playlist\playlist.vcproj", "{3419FA86-F518-4D3B-94C6-B05436439102}" ProjectSection(ProjectDependencies) = postProject + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "easypmp_cui", "frontend\easypmp\cui\easypmp_cui.vcproj", "{FA1F30D4-6100-4379-8506-6CFE023B0AE7}" ProjectSection(ProjectDependencies) = postProject + {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} + {3575EFC2-9051-467A-BEB4-E71E2F8664D7} = {3575EFC2-9051-467A-BEB4-E71E2F8664D7} + {544769C2-6989-452F-B626-E442CAC6553B} = {544769C2-6989-452F-B626-E442CAC6553B} + {3419FA86-F518-4D3B-94C6-B05436439102} = {3419FA86-F518-4D3B-94C6-B05436439102} + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} + {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} = {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} + {E393575C-6B10-43BD-B2C0-63C5040A49F7} = {E393575C-6B10-43BD-B2C0-63C5040A49F7} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {E393575C-6B10-43BD-B2C0-63C5040A49F7} = {E393575C-6B10-43BD-B2C0-63C5040A49F7} - {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} = {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} - {3419FA86-F518-4D3B-94C6-B05436439102} = {3419FA86-F518-4D3B-94C6-B05436439102} - {544769C2-6989-452F-B626-E442CAC6553B} = {544769C2-6989-452F-B626-E442CAC6553B} - {3575EFC2-9051-467A-BEB4-E71E2F8664D7} = {3575EFC2-9051-467A-BEB4-E71E2F8664D7} - {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "easypmp_win32gui", "frontend\easypmp\win32gui\easypmp_win32gui.vcproj", "{45CCFC7B-42B4-4FF9-AF43-FC3626B1672F}" ProjectSection(ProjectDependencies) = postProject + {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} + {3575EFC2-9051-467A-BEB4-E71E2F8664D7} = {3575EFC2-9051-467A-BEB4-E71E2F8664D7} + {3419FA86-F518-4D3B-94C6-B05436439102} = {3419FA86-F518-4D3B-94C6-B05436439102} + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} + {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} = {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} + {E393575C-6B10-43BD-B2C0-63C5040A49F7} = {E393575C-6B10-43BD-B2C0-63C5040A49F7} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} - {E393575C-6B10-43BD-B2C0-63C5040A49F7} = {E393575C-6B10-43BD-B2C0-63C5040A49F7} - {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} = {2548F270-FFCF-43B4-BB9D-D5AAD5B5FEF1} - {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} - {3419FA86-F518-4D3B-94C6-B05436439102} = {3419FA86-F518-4D3B-94C6-B05436439102} - {3575EFC2-9051-467A-BEB4-E71E2F8664D7} = {3575EFC2-9051-467A-BEB4-E71E2F8664D7} - {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmp_portalplayer1", "lib\pmp_portalplayer1\pmp_portalplayer1.vcproj", "{544769C2-6989-452F-B626-E442CAC6553B}" ProjectSection(ProjectDependencies) = postProject + {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} = {8BFE7DD6-F825-42BA-A7D7-EFCDCC9D686A} + {FA6E7B73-7CF8-47DD-A016-77382A1FD904} = {FA6E7B73-7CF8-47DD-A016-77382A1FD904} {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1-22352962426D} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pmp_iriverplus3", "lib\pmp_iriverplus3\pmp_iriverplus3.vcproj", "{C74FE9C9-B5C4-438A-B157-9BCB6C8A7546}" + ProjectSection(ProjectDependencies) = postProject + {AA8DA82B-C209-4ABE-ABA1-22352962426D} = {AA8DA82B-C209-4ABE-ABA1... [truncated message content] |