Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

open_plugins add name when plugin can't open & check LANG_LAST_INDEX_IN_ARRAY

can't open '' was confusing for users so pass the key to open plugin
in theory you could have a plugin that defaulted to these lang_ids
run but its good enough to tell the user what failed to open IMO

lang_id changes mess with open_plugin since it uses them as look-up keys
so add checks for LANG_LAST_INDEX_IN_ARRAY to the checksum

the plugin now removes entries with an invalid checksum

devices with harddrives only append their .dat file so have them skip entries
with invalid checksums and only notify user if a valid entry wasn't found
(these users can run the open_plugins plugin to remove invalid entries)

Change-Id: Icf157675beaccda785643d5a9ed032a7cde30f12

+50 -20
+26 -6
apps/open_plugin.c
··· 28 28 #include "lang.h" 29 29 30 30 /* Define LOGF_ENABLE to enable logf output in this file */ 31 - //#define LOGF_ENABLE 31 + /*#define LOGF_ENABLE*/ 32 32 #include "logf.h" 33 33 34 34 #define ROCK_EXT "rock" ··· 60 60 61 61 static int op_entry_checksum(struct open_plugin_entry_t *entry) 62 62 { 63 - if (entry == NULL || entry->checksum != open_plugin_csum) 63 + if (entry == NULL || entry->checksum != open_plugin_csum + 64 + (entry->lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY)) 65 + { 66 + logf("OP entry bad checksum"); 64 67 return 0; 68 + } 65 69 return 1; 66 70 } 67 71 ··· 81 85 if (entry->lang_id == lang_id || entry->hash == hash || 82 86 (lang_id == OPEN_PLUGIN_LANG_IGNOREALL))/* return first entry found */ 83 87 { 88 + #if (CONFIG_STORAGE & STORAGE_ATA) 89 + /* may have invalid entries but we append the file so continue looking*/ 90 + if (op_entry_checksum(entry) <= 0) 91 + { 92 + ret = OPEN_PLUGIN_INVALID_ENTRY; 93 + continue; 94 + } 95 + #endif 84 96 ret = record; 85 97 /* NULL terminate fields NOTE -- all are actually +1 larger */ 86 98 entry->name[OPEN_PLUGIN_NAMESZ] = '\0'; ··· 98 110 } 99 111 100 112 /* sanity check */ 101 - if (ret > OPEN_PLUGIN_NOT_FOUND && op_entry_checksum(entry) <= 0) 113 + #if (CONFIG_STORAGE & STORAGE_ATA) 114 + if (ret == OPEN_PLUGIN_INVALID_ENTRY || 115 + #else 116 + if( 117 + #endif 118 + (ret > OPEN_PLUGIN_NOT_FOUND && op_entry_checksum(entry) <= 0)) 102 119 { 103 120 splash(HZ * 2, "OpenPlugin Invalid entry"); 104 121 ret = OPEN_PLUGIN_NOT_FOUND; ··· 144 161 hash_langid_csum[2] == open_plugin_csum) 145 162 { 146 163 logf("OP update *Entry Exists* hash: %x langid: %d", 147 - hash_langid_csum[0], (int32_t)hash_langid[1]); 164 + hash_langid_csum[0], (int32_t)hash_langid_csum[1]); 148 165 lseek(fd, 0-hlc_sz, SEEK_CUR);/* back to the start of record */ 149 166 break; 150 167 } ··· 261 278 { 262 279 open_plugin_entry.hash = hash; 263 280 open_plugin_entry.lang_id = lang_id; 264 - open_plugin_entry.checksum = open_plugin_csum; 281 + open_plugin_entry.checksum = open_plugin_csum + 282 + (lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY); 265 283 /* name */ 266 284 if (path_basename(plugin, (const char **)&pos) == 0) 267 285 pos = "\0"; ··· 337 355 opret = op_get_entry(hash, lang_id, entry, OPEN_PLUGIN_DAT); 338 356 logf("OP entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey); 339 357 340 - if (opret == OPEN_PLUGIN_NOT_FOUND && lang_id > OPEN_PLUGIN_LANG_INVALID) 358 + if (opret == OPEN_PLUGIN_NOT_FOUND && lang_id > OPEN_PLUGIN_LANG_INVALID) 341 359 { /* try rb defaults */ 342 360 opret = op_get_entry(hash, lang_id, entry, OPEN_RBPLUGIN_DAT); 343 361 logf("OP rb_entry hash: %x lang id: %d ret: %d key: %s", hash, lang_id, opret, skey); ··· 364 382 365 383 if (param[0] == '\0') 366 384 param = NULL; 385 + if (path[0] == '\0' && key) 386 + path = P2STR((unsigned char *)key); 367 387 368 388 ret = plugin_load(path, param); 369 389
+3 -2
apps/open_plugin.h
··· 40 40 OPEN_PLUGIN_LANG_INVALID = (-1), 41 41 OPEN_PLUGIN_LANG_IGNORE = (-2), 42 42 OPEN_PLUGIN_LANG_IGNOREALL = (-3), 43 - OPEN_PLUGIN_NOT_FOUND = (-1), 44 - OPEN_PLUGIN_NEEDS_FLUSHED = (-2), 43 + OPEN_PLUGIN_INVALID_ENTRY = (-1), 44 + OPEN_PLUGIN_NOT_FOUND = (-2), 45 + OPEN_PLUGIN_NEEDS_FLUSHED = (-3), 45 46 }; 46 47 47 48 struct open_plugin_entry_t
+19 -12
apps/plugins/open_plugins.c
··· 87 87 *nameptr = q; 88 88 return r - q; 89 89 } 90 + static int op_entry_checksum(void) 91 + { 92 + if (op_entry.checksum != open_plugin_csum + 93 + (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY)) 94 + { 95 + return 0; 96 + } 97 + return 1; 98 + } 90 99 91 100 static bool op_entry_read(int fd, int selected_item, off_t data_sz) 92 101 { ··· 94 103 op_entry.lang_id = -1; 95 104 return ((selected_item >= 0) && 96 105 (rb->lseek(fd, selected_item * op_entry_sz, SEEK_SET) >= 0) && 97 - (rb->read(fd, &op_entry, data_sz) == data_sz)); 106 + (rb->read(fd, &op_entry, data_sz) == data_sz) && op_entry_checksum() > 0); 98 107 } 99 108 100 109 static bool op_entry_read_name(int fd, int selected_item) ··· 102 111 return op_entry_read(fd, selected_item, op_name_sz); 103 112 } 104 113 105 - static int op_entry_checksum(void) 106 - { 107 - if (op_entry.checksum != open_plugin_csum) 108 - { 109 - return 0; 110 - } 111 - return 1; 112 - } 113 - 114 114 static int op_entry_read_opx(const char *path) 115 115 { 116 116 int ret = -1; ··· 174 174 175 175 static void op_entry_set_checksum(void) 176 176 { 177 - op_entry.checksum = open_plugin_csum; 177 + op_entry.checksum = open_plugin_csum + 178 + (op_entry.lang_id <= OPEN_PLUGIN_LANG_INVALID ? 0 : LANG_LAST_INDEX_IN_ARRAY); 178 179 } 179 180 180 181 static void op_entry_set_name(void) ··· 466 467 while (resave == false && 467 468 rb->read(fd_dat, &op_entry, op_entry_sz) == op_entry_sz) 468 469 { 469 - if (op_entry.hash == 0) 470 + if (op_entry.hash == 0 || !op_entry_checksum()) 470 471 resave = true; 471 472 } 472 473 } ··· 837 838 } 838 839 } 839 840 }/* OP_EXT */ 841 + } 842 + 843 + for (int i = items - 1; i > 0 && !exit; i--) 844 + { 845 + if (!op_entry_read(fd_dat, i, op_entry_sz)) 846 + items--; 840 847 } 841 848 842 849 if (items < 1 && !exit)
+2
apps/root_menu.c
··· 730 730 char *param = open_plugin_entry.param; 731 731 if (param[0] == '\0') 732 732 param = NULL; 733 + if (path[0] == '\0' && key) 734 + path = P2STR((unsigned char *)key); 733 735 734 736 int ret = plugin_load(path, param); 735 737