diff options
Diffstat (limited to 'apps/open_plugin.c')
-rw-r--r-- | apps/open_plugin.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/apps/open_plugin.c b/apps/open_plugin.c index 61778e1ce7..7448018ed9 100644 --- a/apps/open_plugin.c +++ b/apps/open_plugin.c | |||
@@ -27,6 +27,11 @@ | |||
27 | #include "splash.h" | 27 | #include "splash.h" |
28 | #include "lang.h" | 28 | #include "lang.h" |
29 | 29 | ||
30 | #define ROCK_EXT "rock" | ||
31 | #define ROCK_LEN 5 | ||
32 | #define OP_EXT "opx" | ||
33 | #define OP_LEN 4 | ||
34 | |||
30 | struct open_plugin_entry_t open_plugin_entry; | 35 | struct open_plugin_entry_t open_plugin_entry; |
31 | 36 | ||
32 | static const int op_entry_sz = sizeof(struct open_plugin_entry_t); | 37 | static const int op_entry_sz = sizeof(struct open_plugin_entry_t); |
@@ -34,9 +39,11 @@ static const int op_entry_sz = sizeof(struct open_plugin_entry_t); | |||
34 | uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) | 39 | uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *parameter) |
35 | { | 40 | { |
36 | int len; | 41 | int len; |
42 | bool is_valid = false; | ||
37 | uint32_t hash; | 43 | uint32_t hash; |
38 | char *pos; | 44 | char *pos; |
39 | int fd = 0; | 45 | int fd = 0; |
46 | int fd1 = 0; | ||
40 | 47 | ||
41 | /*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/ | 48 | /*strlcpy(plug_entry.key, key, sizeof(plug_entry.key));*/ |
42 | open_plugin_entry.lang_id = P2ID((unsigned char*)key); | 49 | open_plugin_entry.lang_id = P2ID((unsigned char*)key); |
@@ -52,12 +59,9 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p | |||
52 | pos = "\0"; | 59 | pos = "\0"; |
53 | 60 | ||
54 | len = strlcpy(open_plugin_entry.name, pos, OPEN_PLUGIN_NAMESZ); | 61 | len = strlcpy(open_plugin_entry.name, pos, OPEN_PLUGIN_NAMESZ); |
55 | 62 | if (len > ROCK_LEN && strcasecmp(&(pos[len-ROCK_LEN]), "." ROCK_EXT) == 0) | |
56 | if(len > 5 && strcasecmp(&(pos[len-5]), ".rock") == 0) | ||
57 | { | 63 | { |
58 | fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); | 64 | is_valid = true; |
59 | if (!fd) | ||
60 | return 0; | ||
61 | 65 | ||
62 | /* path */ | 66 | /* path */ |
63 | strlcpy(open_plugin_entry.path, plugin, OPEN_PLUGIN_BUFSZ); | 67 | strlcpy(open_plugin_entry.path, plugin, OPEN_PLUGIN_BUFSZ); |
@@ -66,9 +70,26 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p | |||
66 | strlcpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ); | 70 | strlcpy(open_plugin_entry.param, parameter, OPEN_PLUGIN_BUFSZ); |
67 | else | 71 | else |
68 | open_plugin_entry.param[0] = '\0'; | 72 | open_plugin_entry.param[0] = '\0'; |
73 | } | ||
74 | else if (len > OP_LEN && strcasecmp(&(pos[len-OP_LEN]), "." OP_EXT) == 0) | ||
75 | { | ||
76 | is_valid = true; | ||
77 | /* path */ | ||
78 | strlcpy(open_plugin_entry.path, | ||
79 | VIEWERS_DATA_DIR "/open_plugins." ROCK_EXT, OPEN_PLUGIN_BUFSZ); | ||
80 | /* parameter */ | ||
81 | strlcpy(open_plugin_entry.param, plugin, OPEN_PLUGIN_BUFSZ); | ||
69 | 82 | ||
70 | write(fd, &open_plugin_entry, op_entry_sz); | 83 | write(fd, &open_plugin_entry, op_entry_sz); |
71 | } | 84 | } |
85 | |||
86 | if (is_valid) | ||
87 | { | ||
88 | fd = open(OPEN_PLUGIN_DAT ".tmp", O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
89 | if (!fd) | ||
90 | return 0; | ||
91 | write(fd, &open_plugin_entry, op_entry_sz); | ||
92 | } | ||
72 | else | 93 | else |
73 | { | 94 | { |
74 | if (open_plugin_entry.lang_id != LANG_SHORTCUTS) | 95 | if (open_plugin_entry.lang_id != LANG_SHORTCUTS) |
@@ -77,7 +98,7 @@ uint32_t open_plugin_add_path(const char *key, const char *plugin, const char *p | |||
77 | } | 98 | } |
78 | } | 99 | } |
79 | 100 | ||
80 | int fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); | 101 | fd1 = open(OPEN_PLUGIN_DAT, O_RDONLY); |
81 | if (fd1) | 102 | if (fd1) |
82 | { | 103 | { |
83 | while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz) | 104 | while (read(fd1, &open_plugin_entry, op_entry_sz) == op_entry_sz) |