Open Plugins Ignore hash for lang Ids
no need to look up a hash when we have another searchable field remove some un-needed checks Change-Id: I394e5f796a164aa4bcb68a56ca02cd6a7f18d332
This commit is contained in:
parent
789b2e089e
commit
36d319b084
|
@ -42,10 +42,6 @@ static const uint32_t open_plugin_csum = OPEN_PLUGIN_CHECKSUM;
|
||||||
|
|
||||||
static const int op_entry_sz = sizeof(struct open_plugin_entry_t);
|
static const int op_entry_sz = sizeof(struct open_plugin_entry_t);
|
||||||
|
|
||||||
static int open_plugin_hash_get_entry(uint32_t hash,
|
|
||||||
struct open_plugin_entry_t *entry,
|
|
||||||
const char* dat_file);
|
|
||||||
|
|
||||||
static const char* strip_rockbox_root(const char *path)
|
static const char* strip_rockbox_root(const char *path)
|
||||||
{
|
{
|
||||||
int dlen = strlen(ROCKBOX_DIR);
|
int dlen = strlen(ROCKBOX_DIR);
|
||||||
|
@ -64,7 +60,7 @@ static inline void op_clear_entry(struct open_plugin_entry_t *entry)
|
||||||
|
|
||||||
static int op_entry_checksum(struct open_plugin_entry_t *entry)
|
static int op_entry_checksum(struct open_plugin_entry_t *entry)
|
||||||
{
|
{
|
||||||
if (!entry || entry->checksum != open_plugin_csum)
|
if (entry == NULL || entry->checksum != open_plugin_csum)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -73,38 +69,43 @@ static int op_find_entry(int fd, struct open_plugin_entry_t *entry,
|
||||||
uint32_t hash, int32_t lang_id)
|
uint32_t hash, int32_t lang_id)
|
||||||
{
|
{
|
||||||
int ret = OPEN_PLUGIN_NOT_FOUND;
|
int ret = OPEN_PLUGIN_NOT_FOUND;
|
||||||
int record = -1;
|
int record = 0;
|
||||||
if (fd >= 0 && entry != NULL)
|
if (hash == 0)
|
||||||
|
hash = OPEN_PLUGIN_SEED;
|
||||||
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
logf("OP find_entry *Searching* hash: %x lang_id: %d", hash, lang_id);
|
logf("OP find_entry *Searching* hash: %x lang_id: %d", hash, lang_id);
|
||||||
|
|
||||||
while (read(fd, entry, op_entry_sz) == op_entry_sz)
|
while (read(fd, entry, op_entry_sz) == op_entry_sz)
|
||||||
{
|
{
|
||||||
record++;
|
if (entry->lang_id == lang_id || entry->hash == hash ||
|
||||||
if (entry->lang_id == lang_id ||
|
|
||||||
(entry->hash == hash && hash != 0) ||
|
|
||||||
(lang_id == OPEN_PLUGIN_LANG_IGNOREALL))/* return first entry found */
|
(lang_id == OPEN_PLUGIN_LANG_IGNOREALL))/* return first entry found */
|
||||||
{
|
{
|
||||||
/* sanity check */
|
ret = record;
|
||||||
if (op_entry_checksum(entry) <= 0)
|
|
||||||
{
|
|
||||||
splashf(HZ * 2, "OpenPlugin Invalid entry");
|
|
||||||
ret = OPEN_PLUGIN_NOT_FOUND;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* NULL terminate fields NOTE -- all are actually +1 larger */
|
/* NULL terminate fields NOTE -- all are actually +1 larger */
|
||||||
entry->name[OPEN_PLUGIN_NAMESZ] = '\0';
|
entry->name[OPEN_PLUGIN_NAMESZ] = '\0';
|
||||||
/*entry->key[OPEN_PLUGIN_BUFSZ] = '\0';*/
|
/*entry->key[OPEN_PLUGIN_BUFSZ] = '\0';*/
|
||||||
entry->path[OPEN_PLUGIN_BUFSZ] = '\0';
|
entry->path[OPEN_PLUGIN_BUFSZ] = '\0';
|
||||||
entry->param[OPEN_PLUGIN_BUFSZ] = '\0';
|
entry->param[OPEN_PLUGIN_BUFSZ] = '\0';
|
||||||
ret = record;
|
|
||||||
logf("OP find_entry *Found* hash: %x lang_id: %d",
|
logf("OP find_entry *Found* hash: %x lang_id: %d",
|
||||||
entry->hash, entry->lang_id);
|
entry->hash, entry->lang_id);
|
||||||
logf("OP find_entry rec: %d name: %s %s %s", record,
|
logf("OP find_entry rec: %d name: %s %s %s", record,
|
||||||
entry->name, entry->path, entry->param);
|
entry->name, entry->path, entry->param);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
record++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* sanity check */
|
||||||
|
if (ret > OPEN_PLUGIN_NOT_FOUND && op_entry_checksum(entry) <= 0)
|
||||||
|
{
|
||||||
|
splash(HZ * 2, "OpenPlugin Invalid entry");
|
||||||
|
ret = OPEN_PLUGIN_NOT_FOUND;
|
||||||
|
}
|
||||||
|
if (ret == OPEN_PLUGIN_NOT_FOUND)
|
||||||
|
op_clear_entry(entry);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ static int op_update_dat(struct open_plugin_entry_t *entry, bool clear)
|
||||||
int fd;
|
int fd;
|
||||||
uint32_t hash;
|
uint32_t hash;
|
||||||
int32_t lang_id;
|
int32_t lang_id;
|
||||||
if (!entry || entry->hash == 0)
|
if (entry == NULL|| entry->hash == 0)
|
||||||
{
|
{
|
||||||
logf("OP update *No entry*");
|
logf("OP update *No entry*");
|
||||||
return OPEN_PLUGIN_NOT_FOUND;
|
return OPEN_PLUGIN_NOT_FOUND;
|
||||||
|
@ -178,8 +179,7 @@ static int op_update_dat(struct open_plugin_entry_t *entry, bool clear)
|
||||||
{
|
{
|
||||||
logf("OP update *Loading original entry*");
|
logf("OP update *Loading original entry*");
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
int opret = op_find_entry(fd, entry, hash, lang_id);
|
op_find_entry(fd, entry, hash, lang_id);
|
||||||
clear = (opret == OPEN_PLUGIN_NOT_FOUND);
|
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
|
rename(OPEN_PLUGIN_DAT ".tmp", OPEN_PLUGIN_DAT);
|
||||||
|
@ -194,6 +194,41 @@ static int op_update_dat(struct open_plugin_entry_t *entry, bool clear)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int op_get_entry(uint32_t hash, int32_t lang_id,
|
||||||
|
struct open_plugin_entry_t *entry, const char *dat_file)
|
||||||
|
{
|
||||||
|
int opret = OPEN_PLUGIN_NOT_FOUND;
|
||||||
|
|
||||||
|
if (entry != NULL)
|
||||||
|
{
|
||||||
|
/* Is the entry we want already loaded? */
|
||||||
|
if(hash != 0 && entry->hash == hash)
|
||||||
|
return OPEN_PLUGIN_NEEDS_FLUSHED;
|
||||||
|
|
||||||
|
if(lang_id <= OPEN_PLUGIN_LANG_INVALID)
|
||||||
|
{
|
||||||
|
lang_id = OPEN_PLUGIN_LANG_IGNORE;
|
||||||
|
if (hash == 0)/* no hash or langid -- returns first entry found */
|
||||||
|
lang_id = OPEN_PLUGIN_LANG_IGNOREALL;
|
||||||
|
}
|
||||||
|
else if(entry->lang_id == lang_id)
|
||||||
|
{
|
||||||
|
return OPEN_PLUGIN_NEEDS_FLUSHED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if another entry is loaded; flush it to disk before we destroy it */
|
||||||
|
op_update_dat(&open_plugin_entry, true);
|
||||||
|
|
||||||
|
logf("OP get_entry hash: %x lang id: %d db: %s", hash, lang_id, dat_file);
|
||||||
|
|
||||||
|
int fd = open(dat_file, O_RDONLY);
|
||||||
|
opret = op_find_entry(fd, entry, hash, lang_id);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return opret;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter)
|
uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
@ -201,7 +236,7 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
|
||||||
int32_t lang_id;
|
int32_t lang_id;
|
||||||
char *pos = "\0";
|
char *pos = "\0";
|
||||||
|
|
||||||
if(!key)
|
if(key == NULL)
|
||||||
{
|
{
|
||||||
logf("OP add_path No Key, *Clearing entry*");
|
logf("OP add_path No Key, *Clearing entry*");
|
||||||
op_clear_entry(&open_plugin_entry);
|
op_clear_entry(&open_plugin_entry);
|
||||||
|
@ -242,7 +277,7 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p
|
||||||
}
|
}
|
||||||
else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0)
|
else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0)
|
||||||
{
|
{
|
||||||
open_plugin_hash_get_entry(0, &open_plugin_entry, plugin);
|
op_get_entry(0, OPEN_PLUGIN_LANG_IGNORE, &open_plugin_entry, plugin);
|
||||||
goto retnhash;
|
goto retnhash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,72 +320,17 @@ void open_plugin_browse(const char *key)
|
||||||
open_plugin_add_path(key, tmp_buf, NULL);
|
open_plugin_add_path(key, tmp_buf, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int op_get_entry(uint32_t hash, int32_t lang_id,
|
|
||||||
struct open_plugin_entry_t *entry, const char *dat_file)
|
|
||||||
{
|
|
||||||
int opret = OPEN_PLUGIN_NOT_FOUND;
|
|
||||||
|
|
||||||
if (entry)
|
|
||||||
{
|
|
||||||
/* Is the entry we want already loaded? */
|
|
||||||
if(hash != 0 && entry->hash == hash)
|
|
||||||
return OPEN_PLUGIN_NEEDS_FLUSHED;
|
|
||||||
|
|
||||||
if(lang_id <= OPEN_PLUGIN_LANG_INVALID)
|
|
||||||
{
|
|
||||||
lang_id = OPEN_PLUGIN_LANG_IGNORE;
|
|
||||||
if (hash == 0)/* no hash or langid -- returns first entry found */
|
|
||||||
lang_id = OPEN_PLUGIN_LANG_IGNOREALL;
|
|
||||||
}
|
|
||||||
else if(entry->lang_id == lang_id)
|
|
||||||
{
|
|
||||||
return OPEN_PLUGIN_NEEDS_FLUSHED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if another entry is loaded; flush it to disk before we destroy it */
|
|
||||||
op_update_dat(&open_plugin_entry, true);
|
|
||||||
|
|
||||||
logf("OP get_entry hash: %x lang id: %d db: %s", hash, lang_id, dat_file);
|
|
||||||
|
|
||||||
int fd = open(dat_file, O_RDONLY);
|
|
||||||
opret = op_find_entry(fd, entry, hash, lang_id);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (opret < 0) /* nothing found */
|
|
||||||
{
|
|
||||||
op_clear_entry(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return opret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0 //unused
|
|
||||||
static int open_plugin_langid_get_entry(int32_t lang_id,
|
|
||||||
struct open_plugin_entry_t *entry,
|
|
||||||
const char *dat_file)
|
|
||||||
{
|
|
||||||
return op_get_entry(0, lang_id, entry, dat_file);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int open_plugin_hash_get_entry(uint32_t hash,
|
|
||||||
struct open_plugin_entry_t *entry,
|
|
||||||
const char *dat_file)
|
|
||||||
{
|
|
||||||
return op_get_entry(hash, OPEN_PLUGIN_LANG_IGNORE, entry, dat_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry)
|
int open_plugin_get_entry(const char *key, struct open_plugin_entry_t *entry)
|
||||||
{
|
{
|
||||||
if (!key || !entry)
|
if (key == NULL || entry == NULL)
|
||||||
return OPEN_PLUGIN_NOT_FOUND;
|
return OPEN_PLUGIN_NOT_FOUND;
|
||||||
int opret;
|
int opret;
|
||||||
uint32_t hash;
|
uint32_t hash = 0;
|
||||||
int32_t lang_id = P2ID((unsigned char *)key);
|
int32_t lang_id = P2ID((unsigned char *)key);
|
||||||
const char* skey = P2STR((unsigned char *)key); /* string|LANGPTR => string */
|
const char* skey = P2STR((unsigned char *)key); /* string|LANGPTR => string */
|
||||||
|
|
||||||
open_plugin_get_hash(strip_rockbox_root(skey), &hash); /* in open_plugin.h */
|
if (lang_id <= OPEN_PLUGIN_LANG_INVALID)
|
||||||
|
open_plugin_get_hash(strip_rockbox_root(skey), &hash); /* in open_plugin.h */
|
||||||
|
|
||||||
opret = op_get_entry(hash, lang_id, entry, OPEN_PLUGIN_DAT);
|
opret = op_get_entry(hash, lang_id, entry, OPEN_PLUGIN_DAT);
|
||||||
logf("OP entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey);
|
logf("OP entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey);
|
||||||
|
|
|
@ -67,11 +67,12 @@ struct open_plugin_entry_t
|
||||||
offsetof(struct open_plugin_entry_t, path) + \
|
offsetof(struct open_plugin_entry_t, path) + \
|
||||||
offsetof(struct open_plugin_entry_t, param))
|
offsetof(struct open_plugin_entry_t, param))
|
||||||
|
|
||||||
|
#define OPEN_PLUGIN_SEED 0x811C9DC5; //seed, 2166136261;
|
||||||
inline static void open_plugin_get_hash(const char *key, uint32_t *hash)
|
inline static void open_plugin_get_hash(const char *key, uint32_t *hash)
|
||||||
{
|
{
|
||||||
/* Calculate modified FNV1a hash of string */
|
/* Calculate modified FNV1a hash of string */
|
||||||
const uint32_t p = 16777619;
|
const uint32_t p = 16777619;
|
||||||
*hash = 0x811C9DC5; //seed, 2166136261;
|
*hash = OPEN_PLUGIN_SEED;
|
||||||
while(*key)
|
while(*key)
|
||||||
*hash = (*key++ ^ *hash) * p;
|
*hash = (*key++ ^ *hash) * p;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue