1 | #ifndef PLUGIN_H |
---|
2 | #define PLUGIN_H |
---|
3 | |
---|
4 | int delplugin(char *pluginname) |
---|
5 | { |
---|
6 | struct skin* plugin = getscreen("plugin"); |
---|
7 | struct skin* listbox = getscreennode(plugin, "listbox"); |
---|
8 | struct skin* child = getscreennode(plugin, pluginname); |
---|
9 | void (*deinitplugin)(void); |
---|
10 | |
---|
11 | if(plugin == NULL || child == NULL || listbox == NULL || child->pluginhandle == NULL) |
---|
12 | return 1; |
---|
13 | |
---|
14 | if(plugin == status.skinerr || child == status.skinerr || listbox == status.skinerr) |
---|
15 | return 1; |
---|
16 | |
---|
17 | deinitplugin = dlsym(child->pluginhandle, "deinit"); |
---|
18 | if(deinitplugin != NULL) |
---|
19 | deinitplugin(); |
---|
20 | |
---|
21 | dlclose(child->pluginhandle); |
---|
22 | delscreennode(plugin, pluginname); |
---|
23 | |
---|
24 | listbox->aktpage = 0; |
---|
25 | listbox->aktline = 0; |
---|
26 | listbox->select = NULL; |
---|
27 | |
---|
28 | return 0; |
---|
29 | } |
---|
30 | |
---|
31 | struct skin* getplugin(char* pluginname) |
---|
32 | { |
---|
33 | struct skin* plugin = getscreen("plugin"); |
---|
34 | struct skin* pluginnode = getscreennode(plugin, pluginname); |
---|
35 | |
---|
36 | if(pluginnode != status.skinerr) |
---|
37 | return pluginnode; |
---|
38 | else |
---|
39 | return NULL; |
---|
40 | } |
---|
41 | |
---|
42 | int addplugin(char *pluginname, char* plugindesc, char* pluginpic, char* pluginhandle, int hidden) |
---|
43 | { |
---|
44 | struct skin* plugin = getscreen("plugin"); |
---|
45 | struct skin* listbox = getscreennode(plugin, "listbox"); |
---|
46 | struct skin* child = NULL; |
---|
47 | char* tmpstr = NULL; |
---|
48 | char* tmppng = NULL; |
---|
49 | |
---|
50 | child = checkscreennode(plugin, pluginname); |
---|
51 | if(child != status.skinerr) |
---|
52 | { |
---|
53 | err("plugin %s exists, don't load it", pluginname); |
---|
54 | return 1; |
---|
55 | } |
---|
56 | child = NULL; |
---|
57 | |
---|
58 | child = addlistbox(plugin, listbox, child, 0); |
---|
59 | if(child != NULL) |
---|
60 | { |
---|
61 | char* defaultdir = NULL; |
---|
62 | defaultdir = ostrcat(getconfig("skinpath", NULL), "/skin/", 0, 0); |
---|
63 | |
---|
64 | tmppng = ostrcat("", pluginname, 0, 0); |
---|
65 | stringreplacechar(tmppng, ' ', '_'); |
---|
66 | stringreplacechar(tmppng, ':', '_'); |
---|
67 | string_tolower(tmppng); |
---|
68 | |
---|
69 | defaultdir = ostrcat(defaultdir, tmppng, 1, 0); |
---|
70 | defaultdir = ostrcat(defaultdir, ".png", 1, 0); |
---|
71 | if(file_exist(defaultdir)) |
---|
72 | changepic(child, defaultdir); |
---|
73 | else if(pluginpic != NULL) |
---|
74 | changepic(child, pluginpic); |
---|
75 | else |
---|
76 | { |
---|
77 | tmpstr = ostrcat(getconfig("skinpath", NULL), "/skin/plugin.png", 0, 0); |
---|
78 | changepic(child, tmpstr); |
---|
79 | free(tmpstr); tmpstr = NULL; |
---|
80 | } |
---|
81 | free(tmppng); tmppng = NULL; |
---|
82 | free(defaultdir), defaultdir = NULL; |
---|
83 | child->valign = MIDDLE; |
---|
84 | // child->height = listbox->fontsize + 30; |
---|
85 | child->hspace = 5; |
---|
86 | child->height = 50; |
---|
87 | if(hidden) child->hidden = YES; |
---|
88 | if(pluginname != NULL) |
---|
89 | { |
---|
90 | changename(child, pluginname); |
---|
91 | changetext(child, _(pluginname)); |
---|
92 | } |
---|
93 | // child->textposx = listbox->textposx; |
---|
94 | child->textposx = 120; |
---|
95 | child->pluginhandle = pluginhandle; |
---|
96 | child->del = PLUGINDELMARK; |
---|
97 | } |
---|
98 | |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|
102 | int readplugin(char *dir) |
---|
103 | { |
---|
104 | struct dirent **filelist; |
---|
105 | void *pluginhandle = NULL; |
---|
106 | int count = 0, ret = 0; |
---|
107 | char *pluginpath = NULL; |
---|
108 | char *pluginname = NULL; |
---|
109 | char *plugindesc = NULL; |
---|
110 | char *pluginpic = NULL; |
---|
111 | void **pluginmenu = NULL, **pluginmenu1 = NULL; |
---|
112 | int *pluginflag = NULL; |
---|
113 | int *pluginaktiv = NULL; |
---|
114 | int *pluginversion = NULL; |
---|
115 | void (*initplugin)(void); |
---|
116 | int nocheck = 0; |
---|
117 | |
---|
118 | count = scandir(dir, &filelist, 0, 0); |
---|
119 | if(count < 0) |
---|
120 | { |
---|
121 | perr("scandir"); |
---|
122 | return 1; |
---|
123 | } |
---|
124 | |
---|
125 | nocheck = getconfigint("nopluginversion", NULL); |
---|
126 | |
---|
127 | while(count--) |
---|
128 | { |
---|
129 | if(filelist[count]->d_type != DT_DIR && fnmatch("*.so", filelist[count]->d_name, FNM_CASEFOLD) == 0) |
---|
130 | { |
---|
131 | pluginpath = createpath(dir, filelist[count]->d_name); |
---|
132 | pluginhandle = dlopen(pluginpath, RTLD_LOCAL | RTLD_LAZY); |
---|
133 | if(pluginhandle == NULL) |
---|
134 | { |
---|
135 | perr("load plugin %s", pluginpath); |
---|
136 | free(pluginpath); pluginpath = NULL; |
---|
137 | free(filelist[count]); |
---|
138 | continue; |
---|
139 | } |
---|
140 | dlerror(); |
---|
141 | |
---|
142 | //check plugin version |
---|
143 | if(nocheck == 0) |
---|
144 | { |
---|
145 | pluginversion = dlsym(pluginhandle, "pluginversion"); |
---|
146 | // if(pluginversion == NULL || (*pluginversion != PLUGINVERSION && *pluginversion != 999999)) //999999 for plugins without titan dependent |
---|
147 | // allowed newer plugins as pluginversion |
---|
148 | if(pluginversion == NULL || (*pluginversion < PLUGINVERSION && *pluginversion != 999999)) //999999 for plugins without titan dependent |
---|
149 | { |
---|
150 | if(pluginversion == NULL) |
---|
151 | { |
---|
152 | err("pluginversion not ok titan=%d plugin=NULL (%s)", PLUGINVERSION, pluginpath); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | err("pluginversion not ok titan=%d plugin=%d (%s)", PLUGINVERSION, *pluginversion, pluginpath); |
---|
157 | } |
---|
158 | dlclose(pluginhandle); |
---|
159 | free(pluginpath); pluginpath = NULL; |
---|
160 | free(filelist[count]); |
---|
161 | continue; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | pluginname = dlsym(pluginhandle, "pluginname"); |
---|
166 | if(pluginname == NULL) |
---|
167 | { |
---|
168 | err("not a plugin -> pluginname not found: %s", pluginpath); |
---|
169 | dlclose(pluginhandle); |
---|
170 | free(pluginpath); pluginpath = NULL; |
---|
171 | free(filelist[count]); |
---|
172 | continue; |
---|
173 | } |
---|
174 | free(pluginpath); pluginpath = NULL; |
---|
175 | |
---|
176 | pluginflag = dlsym(pluginhandle, "pluginflag"); |
---|
177 | pluginaktiv = dlsym(pluginhandle, "pluginaktiv"); |
---|
178 | plugindesc = dlsym(pluginhandle, "plugindesc"); |
---|
179 | pluginpic = dlsym(pluginhandle, "pluginpic"); |
---|
180 | pluginflag = dlsym(pluginhandle, "pluginflag"); |
---|
181 | |
---|
182 | if(pluginaktiv != NULL && *pluginaktiv == 0) |
---|
183 | { |
---|
184 | if(pluginflag == NULL || *pluginflag == 0) |
---|
185 | ret = addplugin(pluginname, plugindesc, pluginpic, pluginhandle, 0); |
---|
186 | else |
---|
187 | ret = addplugin(pluginname, plugindesc, pluginpic, pluginhandle, 1); |
---|
188 | if(ret == 0) |
---|
189 | { |
---|
190 | initplugin = dlsym(pluginhandle, "init"); |
---|
191 | if(initplugin != NULL) |
---|
192 | initplugin(); |
---|
193 | |
---|
194 | pluginmenu = dlsym(pluginhandle, "pluginmenu"); |
---|
195 | if(pluginmenu != NULL && *pluginmenu != NULL) |
---|
196 | ((struct skin*)*pluginmenu)->pluginhandle = pluginhandle; |
---|
197 | pluginmenu1 = dlsym(pluginhandle, "pluginmenu1"); |
---|
198 | if(pluginmenu1 != NULL && *pluginmenu1 != NULL) |
---|
199 | ((struct skin*)*pluginmenu1)->pluginhandle = pluginhandle; |
---|
200 | } |
---|
201 | else |
---|
202 | dlclose(pluginhandle); |
---|
203 | } |
---|
204 | else |
---|
205 | dlclose(pluginhandle); |
---|
206 | } |
---|
207 | free(filelist[count]); |
---|
208 | } |
---|
209 | |
---|
210 | free(filelist); |
---|
211 | return 0; |
---|
212 | } |
---|
213 | |
---|
214 | int loadplugin() |
---|
215 | { |
---|
216 | struct dirent **filelist; |
---|
217 | int count = 0; |
---|
218 | char *pluginpath = NULL; |
---|
219 | char *tmpstr = NULL; |
---|
220 | char *tmppath = NULL; |
---|
221 | |
---|
222 | //pluginpath |
---|
223 | tmppath = getconfig("pluginpath", NULL); |
---|
224 | |
---|
225 | if(tmppath == NULL) |
---|
226 | return 1; |
---|
227 | |
---|
228 | count = scandir(tmppath, &filelist, 0, 0); |
---|
229 | if(count < 0) |
---|
230 | { |
---|
231 | perr("scandir"); |
---|
232 | return 1; |
---|
233 | } |
---|
234 | |
---|
235 | while(count--) |
---|
236 | { |
---|
237 | //check if link is a dir |
---|
238 | if(filelist[count]->d_type == DT_LNK || filelist[count]->d_type == DT_UNKNOWN) |
---|
239 | { |
---|
240 | tmpstr = createpath(tmppath, filelist[count]->d_name); |
---|
241 | if(isdir(tmpstr) == 1) |
---|
242 | filelist[count]->d_type = DT_DIR; |
---|
243 | |
---|
244 | free(tmpstr); tmpstr = NULL; |
---|
245 | } |
---|
246 | |
---|
247 | if(filelist[count]->d_type == DT_DIR && ostrcmp(filelist[count]->d_name, ".") != 0 && ostrcmp(filelist[count]->d_name, "..") != 0) |
---|
248 | { |
---|
249 | pluginpath = createpath(tmppath, filelist[count]->d_name); |
---|
250 | readplugin(pluginpath); |
---|
251 | free(pluginpath); pluginpath = NULL; |
---|
252 | } |
---|
253 | free(filelist[count]); |
---|
254 | } |
---|
255 | free(filelist); |
---|
256 | |
---|
257 | //pluginpath1 |
---|
258 | tmppath = getconfig("pluginpath1", NULL); |
---|
259 | |
---|
260 | if(tmppath == NULL) |
---|
261 | return 0; |
---|
262 | |
---|
263 | count = scandir(tmppath, &filelist, 0, 0); |
---|
264 | if(count < 0) |
---|
265 | { |
---|
266 | perr("scandir1"); |
---|
267 | return 0; |
---|
268 | } |
---|
269 | |
---|
270 | while(count--) |
---|
271 | { |
---|
272 | //check if link is a dir |
---|
273 | if(filelist[count]->d_type == DT_LNK || filelist[count]->d_type == DT_UNKNOWN) |
---|
274 | { |
---|
275 | tmpstr = createpath(tmppath, filelist[count]->d_name); |
---|
276 | if(isdir(tmpstr) == 1) |
---|
277 | filelist[count]->d_type = DT_DIR; |
---|
278 | |
---|
279 | free(tmpstr); tmpstr = NULL; |
---|
280 | } |
---|
281 | |
---|
282 | if(filelist[count]->d_type == DT_DIR && ostrcmp(filelist[count]->d_name, ".") != 0 && ostrcmp(filelist[count]->d_name, "..") != 0) |
---|
283 | { |
---|
284 | pluginpath = createpath(tmppath, filelist[count]->d_name); |
---|
285 | readplugin(pluginpath); |
---|
286 | free(pluginpath); pluginpath = NULL; |
---|
287 | } |
---|
288 | free(filelist[count]); |
---|
289 | } |
---|
290 | free(filelist); |
---|
291 | |
---|
292 | //pluginpath2 |
---|
293 | tmppath = getconfig("pluginpath2", NULL); |
---|
294 | |
---|
295 | if(tmppath == NULL) |
---|
296 | return 0; |
---|
297 | |
---|
298 | count = scandir(tmppath, &filelist, 0, 0); |
---|
299 | if(count < 0) |
---|
300 | { |
---|
301 | perr("scandir2"); |
---|
302 | return 0; |
---|
303 | } |
---|
304 | |
---|
305 | while(count--) |
---|
306 | { |
---|
307 | //check if link is a dir |
---|
308 | if(filelist[count]->d_type == DT_LNK || filelist[count]->d_type == DT_UNKNOWN) |
---|
309 | { |
---|
310 | tmpstr = createpath(tmppath, filelist[count]->d_name); |
---|
311 | if(isdir(tmpstr) == 1) |
---|
312 | filelist[count]->d_type = DT_DIR; |
---|
313 | |
---|
314 | free(tmpstr); tmpstr = NULL; |
---|
315 | } |
---|
316 | |
---|
317 | if(filelist[count]->d_type == DT_DIR && ostrcmp(filelist[count]->d_name, ".") != 0 && ostrcmp(filelist[count]->d_name, "..") != 0) |
---|
318 | { |
---|
319 | pluginpath = createpath(tmppath, filelist[count]->d_name); |
---|
320 | readplugin(pluginpath); |
---|
321 | free(pluginpath); pluginpath = NULL; |
---|
322 | } |
---|
323 | free(filelist[count]); |
---|
324 | } |
---|
325 | free(filelist); |
---|
326 | |
---|
327 | return 0; |
---|
328 | } |
---|
329 | |
---|
330 | void screenplugin() |
---|
331 | { |
---|
332 | int rcret = 0; |
---|
333 | void (*startplugin)(void); |
---|
334 | struct skin* plugin = getscreen("plugin"); |
---|
335 | struct skin* listbox = getscreennode(plugin, "listbox"); |
---|
336 | |
---|
337 | drawscreen(plugin, 0, 0); |
---|
338 | addscreenrc(plugin, listbox); |
---|
339 | |
---|
340 | while(1) |
---|
341 | { |
---|
342 | rcret = waitrc(plugin, 0, 0); |
---|
343 | |
---|
344 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
345 | if(rcret == getrcconfigint("rcok", NULL)) |
---|
346 | { |
---|
347 | if(listbox->select != NULL) |
---|
348 | { |
---|
349 | startplugin = dlsym(listbox->select->pluginhandle, "start"); |
---|
350 | if(startplugin != NULL) |
---|
351 | { |
---|
352 | clearscreen(plugin); |
---|
353 | resettvpic(); |
---|
354 | startplugin(); |
---|
355 | drawscreen(plugin, 0, 0); |
---|
356 | } |
---|
357 | } |
---|
358 | continue; |
---|
359 | } |
---|
360 | if(rcret == getrcconfigint("rcred", NULL)) |
---|
361 | { |
---|
362 | if(listbox->select != NULL) |
---|
363 | { |
---|
364 | delplugin(listbox->select->name); |
---|
365 | drawscreen(plugin, 0, 0); |
---|
366 | } |
---|
367 | continue; |
---|
368 | } |
---|
369 | if(rcret == getrcconfigint("rcblue", NULL)) |
---|
370 | { |
---|
371 | loadplugin(); |
---|
372 | drawscreen(plugin, 0, 0); |
---|
373 | continue; |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | delownerrc(plugin); |
---|
378 | clearscreen(plugin); |
---|
379 | } |
---|
380 | |
---|
381 | #endif |
---|