1 | #ifndef GLOBAL_H |
---|
2 | #define GLOBAL_H |
---|
3 | |
---|
4 | //flag 0: video+gui+freez |
---|
5 | //flag 1: video+gui |
---|
6 | //flag 2: video |
---|
7 | //flag 3: gui |
---|
8 | void screenshoot(int flag) |
---|
9 | { |
---|
10 | char* cmd = NULL; |
---|
11 | if(flag == 0 || flag == 2) |
---|
12 | { |
---|
13 | videofreeze(status.aktservice->videodev); |
---|
14 | sleep(1); |
---|
15 | } |
---|
16 | |
---|
17 | if(flag == 0 || flag == 1) |
---|
18 | cmd = ostrcat("grab -j 100 -r 960", NULL, 0, 0); |
---|
19 | else if(flag == 2) |
---|
20 | cmd = ostrcat("grab -v -j 100 -r 960", NULL, 0, 0); |
---|
21 | else if(flag == 3) |
---|
22 | cmd = ostrcat("grab -o -j 100 -r 960", NULL, 0, 0); |
---|
23 | |
---|
24 | if(cmd != NULL) |
---|
25 | system(cmd); |
---|
26 | |
---|
27 | if(flag == 0 || flag == 2) |
---|
28 | videocontinue(status.aktservice->videodev); |
---|
29 | |
---|
30 | free(cmd), cmd = NULL; |
---|
31 | } |
---|
32 | |
---|
33 | //flag 0: playerstart |
---|
34 | //flag 1: playerstop |
---|
35 | void set_player_sound(int flag) |
---|
36 | { |
---|
37 | #ifdef SH4 |
---|
38 | char* vol = NULL, *cmd = NULL; |
---|
39 | |
---|
40 | if(flag == 0) |
---|
41 | vol = ostrcat(getconfig("vol_playerstart", NULL), NULL, 0, 0); |
---|
42 | else if(flag == 1) |
---|
43 | vol = ostrcat(getconfig("vol_playerstop", NULL), NULL, 0, 0); |
---|
44 | |
---|
45 | cmd = ostrcat("amixer -c 1 set Analog playback '", vol, 0, 0); |
---|
46 | if(status.mute == 1) |
---|
47 | cmd = ostrcat(cmd, "%' mute &", 1, 0); |
---|
48 | else |
---|
49 | cmd = ostrcat(cmd, "%' unmute &", 1, 0); |
---|
50 | system(cmd); |
---|
51 | free(cmd), cmd = NULL; |
---|
52 | |
---|
53 | cmd = ostrcat("amixer -c 1 set SPDIF playback '", vol, 0, 0); |
---|
54 | if(status.mute == 1) |
---|
55 | cmd = ostrcat(cmd, "%' mute &", 1, 0); |
---|
56 | else |
---|
57 | cmd = ostrcat(cmd, "%' unmute &", 1, 0); |
---|
58 | system(cmd); |
---|
59 | free(cmd), cmd = NULL; |
---|
60 | |
---|
61 | cmd = ostrcat("amixer -c 1 set HDMI playback '", vol, 0, 0); |
---|
62 | if(status.mute == 1) |
---|
63 | cmd = ostrcat(cmd, "%' mute &", 1, 0); |
---|
64 | else |
---|
65 | cmd = ostrcat(cmd, "%' unmute &", 1, 0); |
---|
66 | system(cmd); |
---|
67 | free(cmd), cmd = NULL; |
---|
68 | free(vol), vol = NULL; |
---|
69 | #endif |
---|
70 | } |
---|
71 | |
---|
72 | //flag 0: with wait message |
---|
73 | //flag 1: without wait message |
---|
74 | void waitmsgbar(int sec, int exit, char* text, int flag) |
---|
75 | { |
---|
76 | if(sec < 1) return; |
---|
77 | int maxsec = sec, rcret = -1; |
---|
78 | |
---|
79 | char* tmpstr = NULL; |
---|
80 | struct skin* waitmsgbar = getscreen("waitmsgbar"); |
---|
81 | struct skin* load = getscreen("loading"); |
---|
82 | |
---|
83 | waitmsgbar->progresssize = 0; |
---|
84 | if(text == NULL) |
---|
85 | tmpstr = ostrcat("0%", NULL, 0, 0); |
---|
86 | else |
---|
87 | tmpstr = ostrcat(text, " (0%)", 0, 0); |
---|
88 | changetext(waitmsgbar, tmpstr); |
---|
89 | free(tmpstr); tmpstr = NULL; |
---|
90 | |
---|
91 | if(flag == 0) drawscreen(load, 0, 0); |
---|
92 | |
---|
93 | while(sec > 0) |
---|
94 | { |
---|
95 | drawscreen(waitmsgbar, 0, 0); |
---|
96 | |
---|
97 | if(exit == 0) |
---|
98 | sleep(1); |
---|
99 | else |
---|
100 | { |
---|
101 | rcret = waitrc(0, 1000, 0); |
---|
102 | if(rcret == getrcconfigint("rcexit", NULL)) |
---|
103 | break; |
---|
104 | |
---|
105 | if(rcret != RCTIMEOUT) continue; |
---|
106 | } |
---|
107 | |
---|
108 | sec--; |
---|
109 | waitmsgbar->progresssize = ((maxsec - sec) * 100) / maxsec; |
---|
110 | |
---|
111 | if(text == NULL) |
---|
112 | tmpstr = ostrcat(oitoa(waitmsgbar->progresssize), "%", 1, 0); |
---|
113 | else |
---|
114 | { |
---|
115 | tmpstr = ostrcat(text, " (", 0, 0); |
---|
116 | tmpstr = ostrcat(tmpstr, oitoa(waitmsgbar->progresssize), 1, 1); |
---|
117 | tmpstr = ostrcat(tmpstr, "%)", 1, 0); |
---|
118 | } |
---|
119 | changetext(waitmsgbar, tmpstr); |
---|
120 | free(tmpstr); tmpstr = NULL; |
---|
121 | } |
---|
122 | |
---|
123 | free(tmpstr); tmpstr = NULL; |
---|
124 | if(flag == 0) clearscreen(load); |
---|
125 | clearscreen(waitmsgbar); |
---|
126 | drawscreen(skin, 0, 0); |
---|
127 | } |
---|
128 | |
---|
129 | //flag 0: get pluginpath an add text |
---|
130 | //flag 1: get pluginpath and change "%pluginpath%/" |
---|
131 | char* createpluginpath(char* text, int flag) |
---|
132 | { |
---|
133 | char* tmpstr = NULL; |
---|
134 | if(text == NULL) return NULL; |
---|
135 | |
---|
136 | if(flag == 0) |
---|
137 | { |
---|
138 | tmpstr = ostrcat(getconfig("pluginpath", NULL), text, 0, 0); |
---|
139 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
140 | |
---|
141 | free(tmpstr); tmpstr = NULL; |
---|
142 | tmpstr = ostrcat(getconfig("pluginpath1", NULL), text, 0, 0); |
---|
143 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
144 | |
---|
145 | free(tmpstr); tmpstr = NULL; |
---|
146 | tmpstr = ostrcat(getconfig("pluginpath2", NULL), text, 0, 0); |
---|
147 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | if(strlen(text) < 13) return NULL; |
---|
152 | |
---|
153 | tmpstr = ostrcat(getconfig("pluginpath", NULL), &text[12], 0, 0); |
---|
154 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
155 | |
---|
156 | free(tmpstr); tmpstr = NULL; |
---|
157 | tmpstr = ostrcat(getconfig("pluginpath1", NULL), &text[12], 0, 0); |
---|
158 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
159 | |
---|
160 | free(tmpstr); tmpstr = NULL; |
---|
161 | tmpstr = ostrcat(getconfig("pluginpath2", NULL), &text[12], 0, 0); |
---|
162 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
163 | } |
---|
164 | |
---|
165 | free(tmpstr); tmpstr = NULL; |
---|
166 | return NULL; |
---|
167 | } |
---|
168 | |
---|
169 | int osystem(char* cmd, int timeout) |
---|
170 | { |
---|
171 | int ret = 0; |
---|
172 | char* tmpstr = NULL; |
---|
173 | |
---|
174 | tmpstr = ostrcat(tmpstr, "timeout -t ", 1, 0); |
---|
175 | tmpstr = ostrcat(tmpstr, oitoa(timeout), 1, 1); |
---|
176 | tmpstr = ostrcat(tmpstr, " -s 9 ", 1, 0); |
---|
177 | tmpstr = ostrcat(tmpstr, cmd, 1, 0); |
---|
178 | ret = system(tmpstr); |
---|
179 | free(tmpstr); tmpstr = NULL; |
---|
180 | |
---|
181 | return ret; |
---|
182 | } |
---|
183 | |
---|
184 | int wlanlinkquality() |
---|
185 | { |
---|
186 | char dev[20]; |
---|
187 | int tmp = 0, linkquality = 0; |
---|
188 | FILE *fd = NULL; |
---|
189 | char *fileline = NULL; |
---|
190 | |
---|
191 | struct inetwork* wlandev = getinetworkfirstwlan(); |
---|
192 | if(wlandev == NULL) return 0; |
---|
193 | |
---|
194 | fileline = malloc(MINMALLOC); |
---|
195 | if(fileline == NULL) |
---|
196 | { |
---|
197 | err("no mem"); |
---|
198 | return 0; |
---|
199 | } |
---|
200 | |
---|
201 | fd = fopen("/proc/net/wireless", "r"); |
---|
202 | if(fd == NULL) |
---|
203 | { |
---|
204 | perr("can't open /proc/net/wireless"); |
---|
205 | free(fileline); |
---|
206 | return 0; |
---|
207 | } |
---|
208 | |
---|
209 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
210 | { |
---|
211 | if(ostrstr(fileline, wlandev->device) != NULL) |
---|
212 | sscanf(fileline, "%[^:]: %d %d", dev, &tmp, &linkquality); |
---|
213 | } |
---|
214 | |
---|
215 | free(fileline); |
---|
216 | fclose(fd); |
---|
217 | return linkquality; |
---|
218 | } |
---|
219 | |
---|
220 | char* getispip() |
---|
221 | { |
---|
222 | char* tmpstr = NULL; |
---|
223 | char* ip = NULL; |
---|
224 | tmpstr = gethttp("checkip.dyndns.org", "", 80, NULL, NULL, 10000, NULL, 0); |
---|
225 | |
---|
226 | if(oregex(".*<body>Current IP Address: ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})</body>.*", tmpstr)) |
---|
227 | { |
---|
228 | ip = oregex(".*<body>Current IP Address: ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})</body>.*", tmpstr); |
---|
229 | } |
---|
230 | free(tmpstr), tmpstr = NULL; |
---|
231 | return ip; |
---|
232 | } |
---|
233 | |
---|
234 | //flag 0: leave standby |
---|
235 | //flag 1: set standby |
---|
236 | int setcecstandby(int flag) |
---|
237 | { |
---|
238 | if(getconfigint("usecec", NULL) == 1 || getconfigint("cec_on", NULL) == 1) |
---|
239 | { |
---|
240 | #ifndef MIPSEL |
---|
241 | if(flag == 0) |
---|
242 | writesys("/proc/stb/cec/onetouchplay", "0", 1); |
---|
243 | else |
---|
244 | { |
---|
245 | char* tmpstr = readsys("/proc/stb/cec/state_cecaddress", 1); |
---|
246 | char* tmpstr1 = readsys("/proc/stb/cec/state_activesource", 1); |
---|
247 | |
---|
248 | if(ostrcmp(tmpstr, tmpstr1) == 0) |
---|
249 | writesys("/proc/stb/cec/systemstandby", "0", 1); |
---|
250 | |
---|
251 | free(tmpstr); tmpstr = NULL; |
---|
252 | free(tmpstr1); tmpstr1 = NULL; |
---|
253 | } |
---|
254 | #else |
---|
255 | if(flag == 0) |
---|
256 | cecwakeup(); |
---|
257 | else |
---|
258 | cecstandby(); |
---|
259 | #endif |
---|
260 | } |
---|
261 | |
---|
262 | return 0; |
---|
263 | } |
---|
264 | |
---|
265 | char* mask(char* input, int count, char* maskchar) |
---|
266 | { |
---|
267 | char* tmpstr = NULL; |
---|
268 | int i = 0; |
---|
269 | |
---|
270 | tmpstr = ostrcat(input, NULL, 1, 0); |
---|
271 | |
---|
272 | if(tmpstr != NULL) |
---|
273 | { |
---|
274 | int len = strlen(tmpstr); |
---|
275 | for(i = 0; i < count - len; i++) |
---|
276 | tmpstr = ostrcat(maskchar, tmpstr, 0, 1); |
---|
277 | } |
---|
278 | else |
---|
279 | { |
---|
280 | for(i = 0; i < count; i++) |
---|
281 | tmpstr = ostrcat(maskchar, tmpstr, 0, 1); |
---|
282 | } |
---|
283 | |
---|
284 | return tmpstr; |
---|
285 | } |
---|
286 | |
---|
287 | int checkinternet() |
---|
288 | { |
---|
289 | int skip = 0, i = 0; |
---|
290 | char* tmp = NULL, *cmd = NULL; |
---|
291 | |
---|
292 | cmd = ostrcat(cmd, "google.de", 1, 0); |
---|
293 | |
---|
294 | //if(system(cmd) != 0) |
---|
295 | for(i = 0; i < 3; i++) |
---|
296 | { |
---|
297 | free(tmp); tmp = NULL; |
---|
298 | tmp = gethttp(cmd, "/", 80, NULL, NULL, 5000, NULL, 0); |
---|
299 | if(tmp != NULL) break; |
---|
300 | } |
---|
301 | if(tmp == NULL) |
---|
302 | skip = 1; |
---|
303 | |
---|
304 | free(tmp); tmp = NULL; |
---|
305 | free(cmd), cmd = NULL; |
---|
306 | |
---|
307 | return skip; |
---|
308 | } |
---|
309 | |
---|
310 | int checkpng(char* filename) |
---|
311 | { |
---|
312 | FILE* fd = NULL; |
---|
313 | int ret = 0; |
---|
314 | png_bytep sig = NULL; |
---|
315 | |
---|
316 | fd = fopen(filename, "rb"); |
---|
317 | if(fd == NULL) |
---|
318 | { |
---|
319 | perr("open file %s", filename); |
---|
320 | return 0; |
---|
321 | } |
---|
322 | |
---|
323 | sig = malloc(8); |
---|
324 | if(sig == NULL) |
---|
325 | { |
---|
326 | err("no mem"); |
---|
327 | fclose(fd); |
---|
328 | return 0; |
---|
329 | } |
---|
330 | |
---|
331 | fread(sig, 1, 8, fd); |
---|
332 | ret = png_check_sig(sig, 8); |
---|
333 | if(ret == 0) |
---|
334 | { |
---|
335 | free(sig); |
---|
336 | fclose(fd); |
---|
337 | return 0; |
---|
338 | } |
---|
339 | |
---|
340 | free(sig); |
---|
341 | fclose(fd); |
---|
342 | return 1; |
---|
343 | } |
---|
344 | |
---|
345 | char **str_split(char *string, char *delim) |
---|
346 | { |
---|
347 | char **tokens = NULL; |
---|
348 | char *working = NULL; |
---|
349 | char *token = NULL; |
---|
350 | int idx = 0; |
---|
351 | |
---|
352 | if(string == NULL) return NULL; |
---|
353 | |
---|
354 | tokens = malloc(sizeof(char*) * MAXTOKENS); |
---|
355 | if(tokens == NULL) |
---|
356 | return NULL; |
---|
357 | |
---|
358 | working = malloc(sizeof(char) * strlen(string) + 1); |
---|
359 | if(working == NULL) |
---|
360 | return NULL; |
---|
361 | |
---|
362 | /* to make sure, copy string to a safe place */ |
---|
363 | strcpy(working, string); |
---|
364 | for(idx = 0; idx < MAXTOKENS; idx++) |
---|
365 | tokens[idx] = NULL; |
---|
366 | |
---|
367 | token = strtok(working, delim); |
---|
368 | idx = 0; |
---|
369 | |
---|
370 | /* always keep the last entry NULL termindated */ |
---|
371 | while(idx < (MAXTOKENS - 1) && token != NULL) |
---|
372 | { |
---|
373 | tokens[idx] = malloc(sizeof(char) * strlen(token) + 1); |
---|
374 | if(tokens[idx] != NULL) |
---|
375 | { |
---|
376 | strcpy(tokens[idx], token); |
---|
377 | idx++; |
---|
378 | token = strtok(NULL, delim); |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | free(working); |
---|
383 | return tokens; |
---|
384 | } |
---|
385 | |
---|
386 | char* readfromlinetoline(char* str, int start, int end, int flag) |
---|
387 | { |
---|
388 | if(str == NULL) return str; |
---|
389 | |
---|
390 | char* tmpstr = NULL; |
---|
391 | int count = 0; |
---|
392 | int i = 0; |
---|
393 | struct splitstr* ret = NULL; |
---|
394 | ret = strsplit(str, "\n", &count); |
---|
395 | |
---|
396 | for(i = 0; i < count; i++) |
---|
397 | { |
---|
398 | if(i >= start && i <= end) |
---|
399 | { |
---|
400 | tmpstr = ostrcat(tmpstr, (&ret[i])->part, 1, 0); |
---|
401 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
402 | } |
---|
403 | } |
---|
404 | free(ret), ret = NULL; |
---|
405 | |
---|
406 | if(flag == 1) |
---|
407 | { |
---|
408 | free(str), str = NULL; |
---|
409 | } |
---|
410 | return tmpstr; |
---|
411 | } |
---|
412 | |
---|
413 | char* ltostr(char* str, long val, unsigned base) |
---|
414 | { |
---|
415 | ldiv_t r; |
---|
416 | |
---|
417 | if(base > 36 || str == NULL) |
---|
418 | return NULL; |
---|
419 | |
---|
420 | if(val < 0) *str++ = '-'; |
---|
421 | r = ldiv(labs(val), base); |
---|
422 | |
---|
423 | if(r.quot > 0) str = ltostr(str, r.quot, base); |
---|
424 | |
---|
425 | *str++ = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem]; |
---|
426 | *str = '\0'; |
---|
427 | return str; |
---|
428 | } |
---|
429 | |
---|
430 | char* oltostr(long val, unsigned base) |
---|
431 | { |
---|
432 | char* str = NULL; |
---|
433 | |
---|
434 | str = calloc(1, MINMALLOC); |
---|
435 | if(str == NULL) |
---|
436 | { |
---|
437 | err("no mem"); |
---|
438 | return NULL; |
---|
439 | } |
---|
440 | |
---|
441 | ltostr(str, val, base); |
---|
442 | |
---|
443 | return ostrshrink(str); |
---|
444 | } |
---|
445 | |
---|
446 | char* unhexlify(char *hexstr) |
---|
447 | { |
---|
448 | int len = 0, tmpint = 0; |
---|
449 | char *p, *q, *binstr = NULL; |
---|
450 | |
---|
451 | if(hexstr == NULL) return NULL; |
---|
452 | |
---|
453 | len = strlen(hexstr); |
---|
454 | if(len == 0 || len % 2 != 0) return NULL; |
---|
455 | |
---|
456 | binstr = calloc(1, (len / 2) + 1); |
---|
457 | if(binstr == NULL) |
---|
458 | { |
---|
459 | err("no mem"); |
---|
460 | return NULL; |
---|
461 | } |
---|
462 | |
---|
463 | for(p = hexstr, q = binstr; *p; p += 2, q++) |
---|
464 | { |
---|
465 | sscanf(p, "%2x", &tmpint); |
---|
466 | *q = tmpint; |
---|
467 | } |
---|
468 | |
---|
469 | return binstr; |
---|
470 | } |
---|
471 | |
---|
472 | int getsupermagic(char* filename) |
---|
473 | { |
---|
474 | struct statfs64 s; |
---|
475 | |
---|
476 | if(statfs64(filename, &s) >= 0) |
---|
477 | return s.f_type; |
---|
478 | |
---|
479 | return 0; |
---|
480 | } |
---|
481 | |
---|
482 | int getrandom(int max) |
---|
483 | { |
---|
484 | srand(time(NULL)); |
---|
485 | return (rand() % max); |
---|
486 | } |
---|
487 | |
---|
488 | char* delmountpart(char* filename, int free1) |
---|
489 | { |
---|
490 | struct mntent ent; |
---|
491 | FILE *fd = NULL; |
---|
492 | char* ret = NULL, *buf = NULL, *treffer = NULL, *rpath = NULL; |
---|
493 | int mntdirlen = 0; |
---|
494 | |
---|
495 | if(filename == NULL) return NULL; |
---|
496 | |
---|
497 | buf = malloc(MINMALLOC); |
---|
498 | if(buf == NULL) |
---|
499 | { |
---|
500 | err("no mem"); |
---|
501 | return NULL; |
---|
502 | } |
---|
503 | |
---|
504 | rpath = realpath(filename, NULL); |
---|
505 | if(rpath == NULL) return NULL; |
---|
506 | |
---|
507 | fd = setmntent("/proc/mounts", "r"); |
---|
508 | if(fd != NULL) |
---|
509 | { |
---|
510 | while(getmntent_r(fd, &ent, buf, MINMALLOC) != 0) |
---|
511 | { |
---|
512 | if(ent.mnt_dir != NULL) |
---|
513 | { |
---|
514 | mntdirlen = strlen(ent.mnt_dir); |
---|
515 | if(mntdirlen > 1 && ostrstr(rpath, ent.mnt_dir) == rpath) |
---|
516 | { |
---|
517 | if(treffer == NULL || strlen(treffer) < mntdirlen) |
---|
518 | { |
---|
519 | free(treffer); treffer = NULL; |
---|
520 | treffer = ostrcat(ent.mnt_dir, NULL, 0, 0); |
---|
521 | } |
---|
522 | } |
---|
523 | } |
---|
524 | } |
---|
525 | } |
---|
526 | |
---|
527 | if(treffer != NULL) |
---|
528 | ret = string_replace(treffer, NULL, rpath, 0); |
---|
529 | |
---|
530 | endmntent(fd); |
---|
531 | if(free1 == 1) free(filename); |
---|
532 | free(buf); |
---|
533 | free(treffer); |
---|
534 | free(rpath); |
---|
535 | return ret; |
---|
536 | } |
---|
537 | |
---|
538 | char* addmountpart(char* filename, int free1) |
---|
539 | { |
---|
540 | struct mntent ent; |
---|
541 | FILE *fd = NULL; |
---|
542 | char* ret = NULL, *buf = NULL; |
---|
543 | |
---|
544 | if(filename == NULL) return NULL; |
---|
545 | |
---|
546 | buf = malloc(MINMALLOC); |
---|
547 | if(buf == NULL) |
---|
548 | { |
---|
549 | err("no mem"); |
---|
550 | return NULL; |
---|
551 | } |
---|
552 | |
---|
553 | fd = setmntent("/proc/mounts", "r"); |
---|
554 | if(fd != NULL) |
---|
555 | { |
---|
556 | while(getmntent_r(fd, &ent, buf, MINMALLOC)) |
---|
557 | { |
---|
558 | if(ent.mnt_dir != NULL && strlen(ent.mnt_dir) > 1) |
---|
559 | { |
---|
560 | ret = ostrcat(ent.mnt_dir, filename, 0, 0); |
---|
561 | if(file_exist(ret)) |
---|
562 | { |
---|
563 | if(free1 == 1) free(filename); |
---|
564 | endmntent(fd); |
---|
565 | free(buf); |
---|
566 | return ret; |
---|
567 | } |
---|
568 | free(ret); ret = NULL; |
---|
569 | } |
---|
570 | } |
---|
571 | } |
---|
572 | |
---|
573 | endmntent(fd); |
---|
574 | free(buf); |
---|
575 | return ret; |
---|
576 | } |
---|
577 | |
---|
578 | unsigned int gethash(char* str) |
---|
579 | { |
---|
580 | unsigned int hash = 0; |
---|
581 | int c = 0; |
---|
582 | |
---|
583 | if(str == NULL) return 0; |
---|
584 | |
---|
585 | while((c = *str++)) |
---|
586 | hash = ((hash << 5) + hash) ^ c; |
---|
587 | |
---|
588 | return hash; |
---|
589 | } |
---|
590 | |
---|
591 | void freeregexstruct(struct regex* node) |
---|
592 | { |
---|
593 | if(node == NULL) return; |
---|
594 | |
---|
595 | free(node->match1); node->match1 = NULL; |
---|
596 | free(node->match2); node->match2 = NULL; |
---|
597 | free(node->match3); node->match3 = NULL; |
---|
598 | free(node->match4); node->match4 = NULL; |
---|
599 | free(node->match5); node->match5 = NULL; |
---|
600 | free(node->match6); node->match6 = NULL; |
---|
601 | free(node->match7); node->match7 = NULL; |
---|
602 | free(node->match8); node->match8 = NULL; |
---|
603 | free(node->match9); node->match9 = NULL; |
---|
604 | free(node->match10); node->match10 = NULL; |
---|
605 | |
---|
606 | free(node); node = NULL; |
---|
607 | } |
---|
608 | |
---|
609 | struct regex* regexstruct(char* regex, char* str) |
---|
610 | { |
---|
611 | regex_t preg = {NULL}; |
---|
612 | regmatch_t pmatch[11] = {{0}}; |
---|
613 | size_t rm = 0, i = 0, len = 0; |
---|
614 | char* ret = NULL; |
---|
615 | struct regex* node = NULL; |
---|
616 | |
---|
617 | if(regex == NULL || str == NULL) return NULL; |
---|
618 | |
---|
619 | rm = regcomp(&preg, regex, REG_EXTENDED); |
---|
620 | if(rm != 0) //error in regex |
---|
621 | { |
---|
622 | regfree(&preg); |
---|
623 | return NULL; |
---|
624 | } |
---|
625 | |
---|
626 | rm = regexec(&preg, str, 11, pmatch, 0); |
---|
627 | if(rm != 0) //no match |
---|
628 | { |
---|
629 | regfree(&preg); |
---|
630 | return NULL; |
---|
631 | } |
---|
632 | |
---|
633 | node = (struct regex*)calloc(1, sizeof(struct regex)); |
---|
634 | if(node == NULL) |
---|
635 | { |
---|
636 | err("no mem"); |
---|
637 | regfree(&preg); |
---|
638 | return NULL; |
---|
639 | } |
---|
640 | |
---|
641 | for(i = 1; !rm && i <= preg.re_nsub; i++) |
---|
642 | { |
---|
643 | len = pmatch[i].rm_eo - pmatch[i].rm_so; |
---|
644 | if(len < 1) continue; |
---|
645 | |
---|
646 | ret = malloc(len + 1); |
---|
647 | if(ret != NULL) |
---|
648 | { |
---|
649 | memcpy(ret, str + pmatch[i].rm_so, len); |
---|
650 | ret[len] = '\0'; |
---|
651 | } |
---|
652 | |
---|
653 | if(i == 1) node->match1 = ret; |
---|
654 | else if(i == 2) node->match2 = ret; |
---|
655 | else if(i == 3) node->match3 = ret; |
---|
656 | else if(i == 4) node->match4 = ret; |
---|
657 | else if(i == 5) node->match5 = ret; |
---|
658 | else if(i == 6) node->match6 = ret; |
---|
659 | else if(i == 7) node->match7 = ret; |
---|
660 | else if(i == 8) node->match8 = ret; |
---|
661 | else if(i == 9) node->match9 = ret; |
---|
662 | else if(i == 10) node->match10 = ret; |
---|
663 | |
---|
664 | ret = NULL; |
---|
665 | } |
---|
666 | |
---|
667 | regfree(&preg); |
---|
668 | return node; |
---|
669 | } |
---|
670 | |
---|
671 | char* oregex(char* regex, char* str) |
---|
672 | { |
---|
673 | regex_t preg = {NULL}; |
---|
674 | regmatch_t pmatch[2] = {{0}}; |
---|
675 | size_t rm = 0, len = 0; |
---|
676 | char* ret = NULL; |
---|
677 | |
---|
678 | if(regex == NULL || str == NULL) return NULL; |
---|
679 | |
---|
680 | rm = regcomp(&preg, regex, REG_EXTENDED); |
---|
681 | if(rm != 0) //error in regex |
---|
682 | { |
---|
683 | regfree(&preg); |
---|
684 | return NULL; |
---|
685 | } |
---|
686 | |
---|
687 | rm = regexec(&preg, str, 2, pmatch, 0); |
---|
688 | if(rm != 0) //no match |
---|
689 | { |
---|
690 | regfree(&preg); |
---|
691 | return NULL; |
---|
692 | } |
---|
693 | |
---|
694 | len = pmatch[1].rm_eo - pmatch[1].rm_so; |
---|
695 | if(len < 1) |
---|
696 | { |
---|
697 | regfree(&preg); |
---|
698 | return NULL; |
---|
699 | } |
---|
700 | |
---|
701 | ret = malloc(len + 1); |
---|
702 | if(ret != NULL) |
---|
703 | { |
---|
704 | memcpy(ret, str + pmatch[1].rm_so, len); |
---|
705 | ret[len] = '\0'; |
---|
706 | } |
---|
707 | |
---|
708 | regfree(&preg); |
---|
709 | return ret; |
---|
710 | } |
---|
711 | |
---|
712 | int oregexint(char* regex, char* str) |
---|
713 | { |
---|
714 | int iret = 0; |
---|
715 | char* ret = NULL; |
---|
716 | |
---|
717 | ret = oregex(regex, str); |
---|
718 | if(ret != NULL) iret = atoi(ret); |
---|
719 | free(ret); |
---|
720 | |
---|
721 | return iret; |
---|
722 | } |
---|
723 | |
---|
724 | struct splitstr* oregexsplit(char* regex, char *str, char *tok, int* count) |
---|
725 | { |
---|
726 | char *tmpstr = NULL; |
---|
727 | struct splitstr *array = NULL, *tmparray = NULL; |
---|
728 | *count = 0; |
---|
729 | |
---|
730 | if(str == NULL || tok == NULL) |
---|
731 | return NULL; |
---|
732 | |
---|
733 | tmpstr = strtok(str, tok); |
---|
734 | while(tmpstr != NULL) |
---|
735 | { |
---|
736 | *count = *count + 1; |
---|
737 | tmparray = array; array = (struct splitstr*)realloc(array, sizeof(struct splitstr*) * (*count)); |
---|
738 | if(array == NULL) |
---|
739 | { |
---|
740 | err("no mem"); |
---|
741 | free(tmparray); |
---|
742 | return NULL; |
---|
743 | } |
---|
744 | |
---|
745 | (&array[(*count) - 1])->part = oregex(regex, tmpstr); |
---|
746 | tmpstr = strtok(NULL, tok); |
---|
747 | } |
---|
748 | |
---|
749 | return array; |
---|
750 | } |
---|
751 | |
---|
752 | void freeoregexsplit(struct splitstr* tmparray, int len) |
---|
753 | { |
---|
754 | if(tmparray == NULL) return; |
---|
755 | int i = 0; |
---|
756 | |
---|
757 | for(i = 0; i < len; i++) |
---|
758 | { |
---|
759 | free(tmparray[i].part); |
---|
760 | tmparray[i].part = NULL; |
---|
761 | } |
---|
762 | |
---|
763 | free(tmparray); |
---|
764 | } |
---|
765 | |
---|
766 | int getmaxsat(char* feshortname) |
---|
767 | { |
---|
768 | char *tmpstr = NULL; |
---|
769 | int maxsat = 1; |
---|
770 | |
---|
771 | if(feshortname != NULL) |
---|
772 | { |
---|
773 | tmpstr = ostrcat(feshortname, "_maxsat", 0, 0); |
---|
774 | maxsat = getconfigint(tmpstr, NULL); |
---|
775 | free(tmpstr); tmpstr = NULL; |
---|
776 | } |
---|
777 | if(maxsat < 0) maxsat = 1; |
---|
778 | |
---|
779 | return maxsat; |
---|
780 | } |
---|
781 | |
---|
782 | void autochangechannelname() |
---|
783 | { |
---|
784 | uint8_t lastsecnr = 0xff; |
---|
785 | int secnr = 0; |
---|
786 | unsigned char* buf = NULL; |
---|
787 | |
---|
788 | if(status.aktservice->fedev == NULL) return; |
---|
789 | |
---|
790 | while(secnr <= lastsecnr && secnr <= 256) |
---|
791 | { |
---|
792 | buf = dvbgetsdt(status.aktservice->fedev, secnr, 2000000); |
---|
793 | if(buf != NULL) |
---|
794 | findchannel(status.aktservice->fedev, NULL, buf, &lastsecnr, NULL, NULL, 1, 1); |
---|
795 | else |
---|
796 | break; |
---|
797 | free(buf); buf = NULL; |
---|
798 | secnr++; |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | int isbase64(char c) |
---|
803 | { |
---|
804 | if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=') |
---|
805 | return 1; |
---|
806 | return 0; |
---|
807 | } |
---|
808 | |
---|
809 | char decodebase64(char c) |
---|
810 | { |
---|
811 | if(c >= 'A' && c <= 'Z') return(c - 'A'); |
---|
812 | if(c >= 'a' && c <= 'z') return(c - 'a' + 26); |
---|
813 | if(c >= '0' && c <= '9') return(c - '0' + 52); |
---|
814 | if(c == '+') return(62); |
---|
815 | return 63; |
---|
816 | } |
---|
817 | |
---|
818 | int b64dec(char* dest, char* src) |
---|
819 | { |
---|
820 | if(src && *src) |
---|
821 | { |
---|
822 | char* p = dest; |
---|
823 | int k, l = strlen(src) + 1; |
---|
824 | char* buf = NULL; |
---|
825 | |
---|
826 | buf = malloc(l); |
---|
827 | if(buf == NULL) return 0; |
---|
828 | |
---|
829 | for(k = 0, l = 0; src[k]; k++) |
---|
830 | { |
---|
831 | if(isbase64(src[k])) |
---|
832 | buf[l++] = src[k]; |
---|
833 | } |
---|
834 | |
---|
835 | for(k = 0; k < l; k += 4) |
---|
836 | { |
---|
837 | char c1 = 'A', c2 = 'A', c3 = 'A', c4 = 'A'; |
---|
838 | char b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
---|
839 | |
---|
840 | c1 = buf[k]; |
---|
841 | if(k + 1 < l) |
---|
842 | c2 = buf[k + 1]; |
---|
843 | if(k + 2 < l) |
---|
844 | c3 = buf[k + 2]; |
---|
845 | if(k + 3 < l) |
---|
846 | c4 = buf[k + 3]; |
---|
847 | |
---|
848 | b1 = decodebase64(c1); |
---|
849 | b2 = decodebase64(c2); |
---|
850 | b3 = decodebase64(c3); |
---|
851 | b4 = decodebase64(c4); |
---|
852 | |
---|
853 | *p++ = ((b1 << 2) | (b2 >> 4)); |
---|
854 | |
---|
855 | if(c3 != '=') |
---|
856 | *p++ = (((b2 & 0xf) << 4) | (b3 >> 2)); |
---|
857 | if(c4 != '=') |
---|
858 | *p++ = (((b3 & 0x3) << 6) | b4); |
---|
859 | |
---|
860 | } |
---|
861 | |
---|
862 | free(buf); |
---|
863 | return(p - dest); |
---|
864 | } |
---|
865 | return 0; |
---|
866 | } |
---|
867 | |
---|
868 | void changechannellist(struct channel* chnode, char* channellist) |
---|
869 | { |
---|
870 | char* tmpstr = NULL; |
---|
871 | |
---|
872 | if(chnode == NULL || status.aktservice->channel == NULL) return; |
---|
873 | |
---|
874 | if(chnode->servicetype != 99) status.servicetype = chnode->servicetype; |
---|
875 | if(status.servicetype == 0) |
---|
876 | { |
---|
877 | if(channellist != NULL) |
---|
878 | { |
---|
879 | tmpstr = ostrcat(channellist, NULL, 0, 0); |
---|
880 | free(status.aktservice->channellist); |
---|
881 | status.aktservice->channellist = tmpstr; |
---|
882 | addconfig("channellist", tmpstr); |
---|
883 | } |
---|
884 | tmpstr = oitoa(status.aktservice->channel->serviceid); |
---|
885 | addconfig("serviceid", tmpstr); |
---|
886 | free(tmpstr); tmpstr = NULL; |
---|
887 | tmpstr = ollutoa(status.aktservice->channel->transponderid); |
---|
888 | addconfig("transponderid", tmpstr); |
---|
889 | free(tmpstr); tmpstr = NULL; |
---|
890 | } |
---|
891 | else |
---|
892 | { |
---|
893 | if(channellist != NULL) |
---|
894 | { |
---|
895 | tmpstr = ostrcat(channellist, NULL, 0, 0); |
---|
896 | free(status.aktservice->channellist); |
---|
897 | status.aktservice->channellist = tmpstr; |
---|
898 | addconfig("rchannellist", tmpstr); |
---|
899 | } |
---|
900 | tmpstr = oitoa(status.aktservice->channel->serviceid); |
---|
901 | addconfig("rserviceid", tmpstr); |
---|
902 | free(tmpstr); tmpstr = NULL; |
---|
903 | tmpstr = ollutoa(status.aktservice->channel->transponderid); |
---|
904 | addconfig("rtransponderid", tmpstr); |
---|
905 | free(tmpstr); tmpstr = NULL; |
---|
906 | } |
---|
907 | } |
---|
908 | |
---|
909 | //flag 0: normal picons |
---|
910 | //flag 1: alternate picons |
---|
911 | char* createpiconpath(struct channel* chnode, int flag) |
---|
912 | { |
---|
913 | char* tmpstr = NULL, *picon = NULL; |
---|
914 | |
---|
915 | if(chnode != NULL) |
---|
916 | { |
---|
917 | picon = ostrcat("/", oitoa(chnode->serviceid), 0, 1); |
---|
918 | picon = ostrcat(picon, "-", 1, 0); |
---|
919 | picon = ostrcat(picon, ollutoa(chnode->transponderid), 1, 1); |
---|
920 | picon = ostrcat(picon, ".png", 1, 0); |
---|
921 | |
---|
922 | if(flag == 1) |
---|
923 | tmpstr = ostrcat("/mnt/swapextensions/usr/local/share/titan/picons/alternate", picon, 0, 0); |
---|
924 | else |
---|
925 | tmpstr = ostrcat("/mnt/swapextensions/usr/local/share/titan/picons", picon, 0, 0); |
---|
926 | if(isfile(tmpstr)) |
---|
927 | { |
---|
928 | free(picon); |
---|
929 | return tmpstr; |
---|
930 | } |
---|
931 | |
---|
932 | free(tmpstr); tmpstr = NULL; |
---|
933 | if(flag == 1) |
---|
934 | tmpstr = ostrcat("/var/swap/usr/local/share/titan/picons/alternate", picon, 0, 0); |
---|
935 | else |
---|
936 | tmpstr = ostrcat("/var/swap/usr/local/share/titan/picons", picon, 0, 0); |
---|
937 | if(isfile(tmpstr)) |
---|
938 | { |
---|
939 | free(picon); |
---|
940 | return tmpstr; |
---|
941 | } |
---|
942 | |
---|
943 | free(tmpstr); tmpstr = NULL; |
---|
944 | if(flag == 1) |
---|
945 | tmpstr = ostrcat("/var/usr/local/share/titan/picons/alternate", picon, 0, 0); |
---|
946 | else |
---|
947 | tmpstr = ostrcat("/var/usr/local/share/titan/picons", picon, 0, 0); |
---|
948 | if(isfile(tmpstr)) |
---|
949 | { |
---|
950 | free(picon); |
---|
951 | return tmpstr; |
---|
952 | } |
---|
953 | } |
---|
954 | |
---|
955 | free(tmpstr); tmpstr = NULL; |
---|
956 | tmpstr = ostrcat(tmpstr, getconfig("defskinpath", NULL), 1, 0); |
---|
957 | tmpstr = ostrcat(tmpstr, "/skin/", 1, 0); |
---|
958 | tmpstr = ostrcat(tmpstr, "defpicon.png", 1, 0); |
---|
959 | |
---|
960 | free(picon); |
---|
961 | return tmpstr; |
---|
962 | } |
---|
963 | |
---|
964 | int checkskin() |
---|
965 | { |
---|
966 | int ret = 0; |
---|
967 | char* defskinpath = NULL; |
---|
968 | char* defskinconfig = NULL; |
---|
969 | char* defskinfile = NULL; |
---|
970 | |
---|
971 | if(file_exist(getconfig("skinpath", NULL)) == 0) |
---|
972 | ret = 1; |
---|
973 | else if(file_exist(getconfig("skinconfig", NULL)) == 0) |
---|
974 | ret = 2; |
---|
975 | else if(file_exist(getconfig("skinfile", NULL)) == 0) |
---|
976 | ret = 3; |
---|
977 | |
---|
978 | if(ret != 0) |
---|
979 | { |
---|
980 | err("skin not found code=%d, change to default", ret); |
---|
981 | |
---|
982 | defskinpath = getconfig("defskinpath", NULL); |
---|
983 | if(defskinpath != NULL) addconfig("skinpath", defskinpath); |
---|
984 | defskinconfig = getconfig("defskinconfig", NULL); |
---|
985 | if(defskinconfig != NULL) addconfig("skinconfig", defskinconfig); |
---|
986 | defskinfile = getconfig("defskinfile", NULL); |
---|
987 | if(defskinfile != NULL) addconfig("skinfile", defskinfile); |
---|
988 | |
---|
989 | ret = 0; |
---|
990 | if(file_exist(getconfig("skinpath", NULL)) == 0) |
---|
991 | ret = 1; |
---|
992 | else if(file_exist(getconfig("skinconfig", NULL)) == 0) |
---|
993 | ret = 2; |
---|
994 | else if(file_exist(getconfig("skinfile", NULL)) == 0) |
---|
995 | ret = 3; |
---|
996 | } |
---|
997 | |
---|
998 | if(ret != 0) |
---|
999 | { |
---|
1000 | err("default skin not found code=%d", ret); |
---|
1001 | } |
---|
1002 | |
---|
1003 | return ret; |
---|
1004 | } |
---|
1005 | |
---|
1006 | int getaktvideosize() |
---|
1007 | { |
---|
1008 | //wait 3 sek after zap, befor videsize is valid |
---|
1009 | //driver takes a little time |
---|
1010 | if(status.videosizevalid == 1) |
---|
1011 | return 0; |
---|
1012 | else if(status.videosizevalid + 3 > time(NULL)) |
---|
1013 | return 1; |
---|
1014 | else |
---|
1015 | { |
---|
1016 | #ifndef SIMULATE |
---|
1017 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
1018 | #endif |
---|
1019 | { |
---|
1020 | status.videosizevalid = 1; |
---|
1021 | return 0; |
---|
1022 | } |
---|
1023 | } |
---|
1024 | |
---|
1025 | return 1; |
---|
1026 | } |
---|
1027 | |
---|
1028 | int ostrftime(char* buf, int count, char* format, struct tm* t) |
---|
1029 | { |
---|
1030 | int ret = -1; |
---|
1031 | |
---|
1032 | if(buf == NULL || t == NULL) return ret; |
---|
1033 | |
---|
1034 | if(format != NULL) |
---|
1035 | ret = strftime(buf, count, format, t); |
---|
1036 | else |
---|
1037 | ret = strftime(buf, count, "%d-%m-%Y %H:%M", t); |
---|
1038 | |
---|
1039 | return ret; |
---|
1040 | } |
---|
1041 | |
---|
1042 | //flag 0 = write all |
---|
1043 | //flag 1 = don't write epg |
---|
1044 | //flag 2 = only write epg |
---|
1045 | //flag 3 = only write config |
---|
1046 | int writeallconfig(int flag) |
---|
1047 | { |
---|
1048 | char* tmpstr = NULL; |
---|
1049 | int ret = 0; |
---|
1050 | |
---|
1051 | if(flag == 0 || flag == 1) |
---|
1052 | { |
---|
1053 | if(status.writerectimer == 1) |
---|
1054 | if(writerectimer(getconfig("rectimerfile", NULL), 0) != 0) |
---|
1055 | ret = 1; |
---|
1056 | if(status.writesat == 1) |
---|
1057 | if(writesat(getconfig("satfile", NULL)) != 0) |
---|
1058 | ret = 1; |
---|
1059 | if(status.writeplaylist == 1) |
---|
1060 | if(writeallplaylist() != 0) |
---|
1061 | ret = 1; |
---|
1062 | if(status.writemainplaylist == 1) |
---|
1063 | if(writemainplaylist(getconfig("playlistfile", NULL)) != 0) |
---|
1064 | ret = 1; |
---|
1065 | if(status.writebouquet == 1) |
---|
1066 | if(writeallbouquet() != 0) |
---|
1067 | ret = 1; |
---|
1068 | if(status.writemainbouquet == 1) |
---|
1069 | if(writemainbouquet(getconfig("bouquetfile", NULL)) != 0) |
---|
1070 | ret = 1; |
---|
1071 | if(status.writechannel == 1) |
---|
1072 | if(writechannel(getconfig("channelfile", NULL)) != 0) |
---|
1073 | ret = 1; |
---|
1074 | if(status.writetransponder == 1) |
---|
1075 | if(writetransponder(getconfig("transponderfile", NULL)) != 0) |
---|
1076 | ret = 1; |
---|
1077 | if(status.writeprovider == 1) |
---|
1078 | if(writeprovider(getconfig("providerfile", NULL)) != 0) |
---|
1079 | ret = 1; |
---|
1080 | if(status.writeownconfig == 1) |
---|
1081 | if(writeownconfig(getconfig("ownconfig", NULL)) != 0) |
---|
1082 | ret = 1; |
---|
1083 | if(status.writeepgscanlist == 1) |
---|
1084 | if(writeepgscanlist(getconfig("epgchannelfile", NULL)) != 0) |
---|
1085 | ret = 1; |
---|
1086 | if(status.writercconfig == 1) |
---|
1087 | if(writercconfig(getconfig("rcconfig", NULL)) != 0) |
---|
1088 | ret = 1; |
---|
1089 | if(status.writeskinconfig == 1) |
---|
1090 | if(writeskinconfig(getconfig("skinconfig", NULL)) != 0) |
---|
1091 | ret = 1; |
---|
1092 | if(status.writemostzap == 1) |
---|
1093 | if(writemostzap(getconfig("mostzapfile", NULL)) != 0) |
---|
1094 | ret = 1; |
---|
1095 | if(status.writelastsubtitle == 1) |
---|
1096 | if(writelastsubtitle(getconfig("lastsubtitle", NULL)) != 0) |
---|
1097 | ret = 1; |
---|
1098 | if(status.writechannelslot == 1) |
---|
1099 | if(writechannelslot(getconfig("channelslotfile", NULL)) != 0) |
---|
1100 | ret = 1; |
---|
1101 | } |
---|
1102 | if(flag == 0 || flag == 1 || flag == 3) |
---|
1103 | { |
---|
1104 | if(status.writeconfig == 1) |
---|
1105 | { |
---|
1106 | addconfigint("vol", getvol()); |
---|
1107 | if(writeconfig(status.configfile) != 0) |
---|
1108 | ret = 1; |
---|
1109 | } |
---|
1110 | } |
---|
1111 | if((flag == 0 || flag == 2) && time(NULL) > 1072224000) // 01.01.2004 |
---|
1112 | { |
---|
1113 | tmpstr = createpath(getconfig("epg_path", NULL), "epg.dat"); |
---|
1114 | if(writeepg(tmpstr) != 0) |
---|
1115 | ret = 1; |
---|
1116 | free(tmpstr); tmpstr = NULL; |
---|
1117 | } |
---|
1118 | |
---|
1119 | sync(); |
---|
1120 | |
---|
1121 | return ret; |
---|
1122 | } |
---|
1123 | |
---|
1124 | void* writeallconfigthread0() |
---|
1125 | { |
---|
1126 | writeallconfig(0); |
---|
1127 | pthread_exit(NULL); |
---|
1128 | } |
---|
1129 | |
---|
1130 | void* writeallconfigthread1() |
---|
1131 | { |
---|
1132 | writeallconfig(1); |
---|
1133 | pthread_exit(NULL); |
---|
1134 | } |
---|
1135 | |
---|
1136 | void initmutex(int flag) |
---|
1137 | { |
---|
1138 | if(flag == 1) |
---|
1139 | { |
---|
1140 | pthread_mutex_init(&status.drawingmutex, NULL); |
---|
1141 | pthread_mutex_init(&status.rectimermutex, NULL); |
---|
1142 | pthread_mutex_init(&status.servicemutex, NULL); |
---|
1143 | pthread_mutex_init(&status.epgmutex, NULL); |
---|
1144 | pthread_mutex_init(&status.vfdmutex, NULL); |
---|
1145 | pthread_mutex_init(&status.channelmutex, NULL); |
---|
1146 | pthread_mutex_init(&status.timerthreadmutex, NULL); |
---|
1147 | pthread_mutex_init(&status.audiotrackmutex, NULL); |
---|
1148 | pthread_mutex_init(&status.subtitlemutex, NULL); |
---|
1149 | pthread_mutex_init(&status.dmxdevmutex, NULL); |
---|
1150 | pthread_mutex_init(&status.rcmutex, NULL); |
---|
1151 | pthread_mutex_init(&status.queuemutex, NULL); |
---|
1152 | pthread_mutex_init(&status.clistmutex, NULL); |
---|
1153 | pthread_mutex_init(&status.hddmutex, NULL); |
---|
1154 | pthread_mutex_init(&status.linkedchannelmutex, NULL); |
---|
1155 | pthread_mutex_init(&status.tsseekmutex, NULL); |
---|
1156 | pthread_mutex_init(&status.accelfbmutex, NULL); |
---|
1157 | pthread_mutex_init(&status.mediadbmutex, NULL); |
---|
1158 | pthread_mutex_init(&status.oldentrymutex, NULL); |
---|
1159 | pthread_mutex_init(&status.newslettermutex, NULL); |
---|
1160 | pthread_mutex_init(&status.tithekmutex, NULL); |
---|
1161 | pthread_mutex_init(&status.inetworkmutex, NULL); |
---|
1162 | pthread_mutex_init(&status.textboxmutex, NULL); |
---|
1163 | pthread_mutex_init(&status.setaktresmutex, NULL); |
---|
1164 | pthread_mutex_init(&status.waitrcmutex, NULL); |
---|
1165 | pthread_mutex_init(&status.oledmutex, NULL); |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | pthread_mutex_destroy(&status.drawingmutex); |
---|
1170 | pthread_mutex_destroy(&status.rectimermutex); |
---|
1171 | pthread_mutex_destroy(&status.servicemutex); |
---|
1172 | pthread_mutex_destroy(&status.epgmutex); |
---|
1173 | pthread_mutex_destroy(&status.vfdmutex); |
---|
1174 | pthread_mutex_destroy(&status.channelmutex); |
---|
1175 | pthread_mutex_destroy(&status.timerthreadmutex); |
---|
1176 | pthread_mutex_destroy(&status.audiotrackmutex); |
---|
1177 | pthread_mutex_destroy(&status.subtitlemutex); |
---|
1178 | pthread_mutex_destroy(&status.dmxdevmutex); |
---|
1179 | pthread_mutex_destroy(&status.rcmutex); |
---|
1180 | pthread_mutex_destroy(&status.queuemutex); |
---|
1181 | pthread_mutex_destroy(&status.clistmutex); |
---|
1182 | pthread_mutex_destroy(&status.hddmutex); |
---|
1183 | pthread_mutex_destroy(&status.linkedchannelmutex); |
---|
1184 | pthread_mutex_destroy(&status.tsseekmutex); |
---|
1185 | pthread_mutex_destroy(&status.accelfbmutex); |
---|
1186 | pthread_mutex_destroy(&status.mediadbmutex); |
---|
1187 | pthread_mutex_destroy(&status.oldentrymutex); |
---|
1188 | pthread_mutex_destroy(&status.newslettermutex); |
---|
1189 | pthread_mutex_destroy(&status.tithekmutex); |
---|
1190 | pthread_mutex_destroy(&status.inetworkmutex); |
---|
1191 | pthread_mutex_destroy(&status.textboxmutex); |
---|
1192 | pthread_mutex_destroy(&status.setaktresmutex); |
---|
1193 | pthread_mutex_destroy(&status.waitrcmutex); |
---|
1194 | pthread_mutex_destroy(&status.oledmutex); |
---|
1195 | } |
---|
1196 | } |
---|
1197 | |
---|
1198 | int hexit(char c) |
---|
1199 | { |
---|
1200 | if(c >= '0' && c <= '9') |
---|
1201 | return c - '0'; |
---|
1202 | if(c >= 'a' && c <= 'f') |
---|
1203 | return c - 'a' + 10; |
---|
1204 | if(c >= 'A' && c <= 'F') |
---|
1205 | return c - 'A' + 10; |
---|
1206 | |
---|
1207 | return 0; |
---|
1208 | } |
---|
1209 | |
---|
1210 | char* htmlencode(char* from) |
---|
1211 | { |
---|
1212 | int buflen = 0; |
---|
1213 | char* buf = NULL, *to = NULL; |
---|
1214 | |
---|
1215 | buf = calloc(1, MINMALLOC); |
---|
1216 | if(buf == NULL) |
---|
1217 | { |
---|
1218 | err("no mem"); |
---|
1219 | return NULL; |
---|
1220 | } |
---|
1221 | to = buf; |
---|
1222 | |
---|
1223 | for(buflen = 0; *from != '\0' && buflen < MINMALLOC; ++from) |
---|
1224 | { |
---|
1225 | if(isalnum(*from) || strchr("/_.-~", *from) != NULL) |
---|
1226 | { |
---|
1227 | *to = *from; |
---|
1228 | ++to; |
---|
1229 | ++buflen; |
---|
1230 | } |
---|
1231 | else |
---|
1232 | { |
---|
1233 | sprintf(to, "%%%02x", (int)*from & 0xff); |
---|
1234 | to += 3; |
---|
1235 | buflen += 3; |
---|
1236 | } |
---|
1237 | } |
---|
1238 | *to = '\0'; |
---|
1239 | |
---|
1240 | buf = ostrshrink(buf); |
---|
1241 | return buf; |
---|
1242 | } |
---|
1243 | |
---|
1244 | void htmldecode(char* to, char* from) |
---|
1245 | { |
---|
1246 | if(to == NULL || from == NULL) return; |
---|
1247 | |
---|
1248 | for(; *from != '\0'; ++to, ++from) |
---|
1249 | { |
---|
1250 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
1251 | { |
---|
1252 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
1253 | from += 2; |
---|
1254 | } |
---|
1255 | else |
---|
1256 | *to = *from; |
---|
1257 | } |
---|
1258 | *to = '\0'; |
---|
1259 | } |
---|
1260 | |
---|
1261 | void htmldecode2(char* to, char* from) |
---|
1262 | { |
---|
1263 | if(to == NULL || from == NULL) return; |
---|
1264 | |
---|
1265 | for(; *from != '\0'; ++to, ++from) |
---|
1266 | { |
---|
1267 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4])) |
---|
1268 | { |
---|
1269 | *to = hexit(from[1]) * 16 + hexit(from[2]) * 16 + hexit(from[3]) * 16 + hexit(from[4]); |
---|
1270 | from += 4; |
---|
1271 | } |
---|
1272 | else if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]) && isxdigit(from[3])) |
---|
1273 | { |
---|
1274 | *to = hexit(from[1]) * 16 + hexit(from[2]) * 16 + hexit(from[3]); |
---|
1275 | from += 3; |
---|
1276 | } |
---|
1277 | else if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
1278 | { |
---|
1279 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
1280 | from += 2; |
---|
1281 | } |
---|
1282 | else |
---|
1283 | *to = *from; |
---|
1284 | } |
---|
1285 | *to = '\0'; |
---|
1286 | } |
---|
1287 | |
---|
1288 | void htmldecode3(char* to, char* from) |
---|
1289 | { |
---|
1290 | if(to == NULL || from == NULL) return; |
---|
1291 | |
---|
1292 | for(; *from != '\0'; ++to, ++from) |
---|
1293 | { |
---|
1294 | if(from[0] == '\\' && from[1] == 'u' && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4]) && isxdigit(from[5]) && isxdigit(from[6]) && isxdigit(from[7])) |
---|
1295 | { |
---|
1296 | *to = hexit(from[2]) * 1048576 + hexit(from[3]) * 65536 + hexit(from[4]) * 4096 + hexit(from[5]) * 256 + hexit(from[6]) * 16 + hexit(from[7]); |
---|
1297 | from += 7; |
---|
1298 | } |
---|
1299 | if(from[0] == '\\' && from[1] == 'u' && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4]) && isxdigit(from[5])) |
---|
1300 | { |
---|
1301 | *to = hexit(from[2]) * 4096 + hexit(from[3]) * 256 + hexit(from[4]) * 16 + hexit(from[5]); |
---|
1302 | from += 5; |
---|
1303 | } |
---|
1304 | else |
---|
1305 | *to = *from; |
---|
1306 | } |
---|
1307 | *to = '\0'; |
---|
1308 | } |
---|
1309 | |
---|
1310 | void setosdtransparent(int value) |
---|
1311 | { |
---|
1312 | int ret = 255; |
---|
1313 | if(value < 0) value = 0; |
---|
1314 | if(value > 100) value = 100; |
---|
1315 | |
---|
1316 | ret -= value * 2.55; |
---|
1317 | |
---|
1318 | setfbtransparent(ret); |
---|
1319 | } |
---|
1320 | |
---|
1321 | struct tm* olocaltime(time_t *value) |
---|
1322 | { |
---|
1323 | struct tm *loctime, *loctime1 = NULL; |
---|
1324 | |
---|
1325 | loctime1 = (struct tm*)malloc(sizeof(struct tm)); |
---|
1326 | if(loctime1 == NULL) |
---|
1327 | { |
---|
1328 | err("no mem"); |
---|
1329 | return NULL; |
---|
1330 | } |
---|
1331 | loctime = localtime_r(value, loctime1); |
---|
1332 | |
---|
1333 | return loctime; |
---|
1334 | } |
---|
1335 | |
---|
1336 | int setwakeuptimer(time_t waketime) |
---|
1337 | { |
---|
1338 | char* wakeuptimerprog = NULL; |
---|
1339 | struct tm *loctime = NULL; |
---|
1340 | char *buf = NULL; |
---|
1341 | int ret = -1; |
---|
1342 | |
---|
1343 | wakeuptimerprog = getconfig("wakeuptimerprog", NULL); |
---|
1344 | |
---|
1345 | if(wakeuptimerprog == NULL) |
---|
1346 | { |
---|
1347 | err("NULL detect"); |
---|
1348 | return ret; |
---|
1349 | } |
---|
1350 | |
---|
1351 | buf = malloc(MINMALLOC); |
---|
1352 | if(buf == NULL) |
---|
1353 | { |
---|
1354 | err("no mem"); |
---|
1355 | return ret; |
---|
1356 | } |
---|
1357 | |
---|
1358 | loctime = olocaltime(&waketime); |
---|
1359 | |
---|
1360 | if(loctime != NULL) |
---|
1361 | ostrftime(buf, MINMALLOC, wakeuptimerprog, loctime); |
---|
1362 | |
---|
1363 | if(buf != NULL) |
---|
1364 | { |
---|
1365 | debug(10, "set wake up timer (%s)", buf); |
---|
1366 | ret = system(buf); |
---|
1367 | } |
---|
1368 | |
---|
1369 | free(loctime); |
---|
1370 | free(buf); |
---|
1371 | return ret; |
---|
1372 | } |
---|
1373 | |
---|
1374 | int autoresolution() |
---|
1375 | { |
---|
1376 | char *hotpluginfo = NULL; |
---|
1377 | char *value = NULL; |
---|
1378 | |
---|
1379 | if(getconfig("av_videomode", NULL) != NULL || getconfig("av_colorformat", NULL)) |
---|
1380 | return 1; |
---|
1381 | |
---|
1382 | hotpluginfo = getconfig("hotpluginfo", NULL); |
---|
1383 | |
---|
1384 | if(hotpluginfo == NULL) |
---|
1385 | { |
---|
1386 | err("NULL detect"); |
---|
1387 | return 1; |
---|
1388 | } |
---|
1389 | |
---|
1390 | value = readsys(hotpluginfo, 1); |
---|
1391 | if(value == NULL) |
---|
1392 | { |
---|
1393 | err("NULL detect"); |
---|
1394 | return 1; |
---|
1395 | } |
---|
1396 | |
---|
1397 | if(value[0] == 'y') |
---|
1398 | { |
---|
1399 | setvideomode("720p50", 0); |
---|
1400 | changefbresolution("720p50", 0); |
---|
1401 | setcolorformat("hdmi_rgb", 0); |
---|
1402 | } |
---|
1403 | else |
---|
1404 | { |
---|
1405 | setvideomode("576i50", 0); |
---|
1406 | changefbresolution("576i50", 0); |
---|
1407 | setcolorformat("rgb", 1); |
---|
1408 | } |
---|
1409 | |
---|
1410 | free(value); |
---|
1411 | return 0; |
---|
1412 | } |
---|
1413 | |
---|
1414 | //TODO: can remove if new function work |
---|
1415 | /* |
---|
1416 | int writelengthfield(unsigned char *buf, unsigned int len) |
---|
1417 | { |
---|
1418 | if(len < 127) |
---|
1419 | { |
---|
1420 | *buf++ = len; |
---|
1421 | return 1; |
---|
1422 | } |
---|
1423 | else if(len < 256) |
---|
1424 | { |
---|
1425 | *buf++ = 0x81; |
---|
1426 | *buf++ = len; |
---|
1427 | return 2; |
---|
1428 | } |
---|
1429 | else if(len < 65535) |
---|
1430 | { |
---|
1431 | *buf++ = 0x82; |
---|
1432 | *buf++ = len >> 8; |
---|
1433 | *buf++ = len; |
---|
1434 | return 3; |
---|
1435 | } |
---|
1436 | |
---|
1437 | return 0; |
---|
1438 | } |
---|
1439 | */ |
---|
1440 | |
---|
1441 | size_t writelengthfield(unsigned char * buf, unsigned int len) |
---|
1442 | { |
---|
1443 | if(buf == NULL) return 0; |
---|
1444 | |
---|
1445 | if(len < 128) |
---|
1446 | { |
---|
1447 | buf[0] = len; |
---|
1448 | return 1; |
---|
1449 | } |
---|
1450 | else |
---|
1451 | { |
---|
1452 | unsigned int pos = 0; |
---|
1453 | unsigned int shiftby = 8; |
---|
1454 | unsigned char lenfieldsize = 1; |
---|
1455 | |
---|
1456 | while((len >> shiftby) != 0) |
---|
1457 | { |
---|
1458 | lenfieldsize++; |
---|
1459 | shiftby += 8; |
---|
1460 | } |
---|
1461 | |
---|
1462 | buf[pos++] = ((1 << 7) | lenfieldsize); |
---|
1463 | |
---|
1464 | while(shiftby != 0) |
---|
1465 | { |
---|
1466 | shiftby -= 8; |
---|
1467 | buf[pos++] = len >> shiftby; |
---|
1468 | } |
---|
1469 | return pos; |
---|
1470 | } |
---|
1471 | } |
---|
1472 | |
---|
1473 | //flag 0: del non alpha/num |
---|
1474 | //flag 1: change all / |
---|
1475 | //flag 2: change all non filename conform chars |
---|
1476 | //flag 3: replace non alpha/num with _ |
---|
1477 | void delspezchar(char* text, int flag) |
---|
1478 | { |
---|
1479 | char* tmpstr = text; |
---|
1480 | |
---|
1481 | if(text == NULL) return; |
---|
1482 | |
---|
1483 | while(*tmpstr != '\0') |
---|
1484 | { |
---|
1485 | if(flag == 1 || flag == 2) |
---|
1486 | { |
---|
1487 | if(tmpstr[0] == '/') tmpstr[0] = '-'; |
---|
1488 | if(flag == 2) |
---|
1489 | { |
---|
1490 | if(tmpstr[0] == 'Â') tmpstr[0] = '-'; |
---|
1491 | if(tmpstr[0] == '<') tmpstr[0] = '-'; |
---|
1492 | if(tmpstr[0] == '>') tmpstr[0] = '-'; |
---|
1493 | if(tmpstr[0] == ':') tmpstr[0] = '-'; |
---|
1494 | if(tmpstr[0] == '"') tmpstr[0] = '-'; |
---|
1495 | if(tmpstr[0] == '\\') tmpstr[0] = '-'; |
---|
1496 | if(tmpstr[0] == '|') tmpstr[0] = '-'; |
---|
1497 | if(tmpstr[0] == '*') tmpstr[0] = '-'; |
---|
1498 | if(tmpstr[0] == '?') tmpstr[0] = '-'; |
---|
1499 | if(tmpstr[0] == '[') tmpstr[0] = '-'; |
---|
1500 | if(tmpstr[0] == ']') tmpstr[0] = '-'; |
---|
1501 | if(tmpstr[0] == '=') tmpstr[0] = '-'; |
---|
1502 | if(tmpstr[0] == '%') tmpstr[0] = '-'; |
---|
1503 | if(tmpstr[0] == '$') tmpstr[0] = '-'; |
---|
1504 | if(tmpstr[0] == ',') tmpstr[0] = '-'; |
---|
1505 | if(tmpstr[0] == ';') tmpstr[0] = '-'; |
---|
1506 | if(tmpstr[0] == '~') tmpstr[0] = '-'; |
---|
1507 | } |
---|
1508 | } |
---|
1509 | else if(flag == 3) |
---|
1510 | { |
---|
1511 | if(!isalnum(tmpstr[0]) && tmpstr[0] != '-') |
---|
1512 | tmpstr[0] = '_'; |
---|
1513 | } |
---|
1514 | else |
---|
1515 | { |
---|
1516 | if(!isalnum(tmpstr[0]) && tmpstr[0] != '-' && tmpstr[0] != '.') |
---|
1517 | tmpstr[0] = ' '; |
---|
1518 | } |
---|
1519 | tmpstr++; |
---|
1520 | } |
---|
1521 | } |
---|
1522 | |
---|
1523 | void m_lock(pthread_mutex_t *mutex, int flag) |
---|
1524 | { |
---|
1525 | switch(flag) |
---|
1526 | { |
---|
1527 | case 0: debug(900, "drawingmutex lock"); break; |
---|
1528 | case 1: debug(900, "rectimermutex lock"); break; |
---|
1529 | case 2: debug(900, "servicemutex lock"); break; |
---|
1530 | case 3: debug(900, "vfdmutex lock"); break; |
---|
1531 | case 4: debug(900, "epgmutex lock"); break; |
---|
1532 | case 5: debug(900, "channelmutex lock"); break; |
---|
1533 | case 6: debug(900, "timerthreadmutex lock"); break; |
---|
1534 | case 7: debug(900, "audiotrackmutex lock"); break; |
---|
1535 | case 8: debug(900, "subtitlemutex lock"); break; |
---|
1536 | case 9: debug(900, "dmxdevmutex lock"); break; |
---|
1537 | case 10: debug(900, "rcmutex lock"); break; |
---|
1538 | case 11: debug(900, "queuemutex lock"); break; |
---|
1539 | case 12: debug(900, "clistmutex lock"); break; |
---|
1540 | case 13: debug(900, "hddmutex lock"); break; |
---|
1541 | case 14: debug(900, "linkedchannelmutex lock"); break; |
---|
1542 | case 15: debug(900, "tsseekmutex lock"); break; |
---|
1543 | case 16: debug(900, "accelfbmutex lock"); break; |
---|
1544 | case 17: debug(900, "mediadbmutex lock"); break; |
---|
1545 | case 18: debug(900, "oldentrymutex lock"); break; |
---|
1546 | case 19: debug(900, "newslettermutex lock"); break; |
---|
1547 | case 20: debug(900, "tithekmutex lock"); break; |
---|
1548 | case 21: debug(900, "inetworkmutex lock"); break; |
---|
1549 | case 22: debug(900, "textboxmutex lock"); break; |
---|
1550 | case 23: debug(900, "setaktresmutex lock"); break; |
---|
1551 | case 24: debug(900, "waitrcmutex lock"); break; |
---|
1552 | case 25: debug(900, "oledmutex lock"); break; |
---|
1553 | default: debug(900, "unknown mutex lock"); break; |
---|
1554 | } |
---|
1555 | pthread_mutex_lock(mutex); |
---|
1556 | } |
---|
1557 | |
---|
1558 | void m_unlock(pthread_mutex_t *mutex, int flag) |
---|
1559 | { |
---|
1560 | switch(flag) |
---|
1561 | { |
---|
1562 | case 0: debug(900, "drawingmutex unlock"); break; |
---|
1563 | case 1: debug(900, "rectimermutex unlock"); break; |
---|
1564 | case 2: debug(900, "servicemutex unlock"); break; |
---|
1565 | case 3: debug(900, "vfdmutex unlock"); break; |
---|
1566 | case 4: debug(900, "epgmutex unlock"); break; |
---|
1567 | case 5: debug(900, "channelmutex unlock"); break; |
---|
1568 | case 6: debug(900, "timerthreadmutex unlock"); break; |
---|
1569 | case 7: debug(900, "audiotrackmutex unlock"); break; |
---|
1570 | case 8: debug(900, "subtitlemutex unlock"); break; |
---|
1571 | case 9: debug(900, "dmxdevmutex unlock"); break; |
---|
1572 | case 10: debug(900, "rcmutex unlock"); break; |
---|
1573 | case 11: debug(900, "queuemutex unlock"); break; |
---|
1574 | case 12: debug(900, "clistmutex unlock"); break; |
---|
1575 | case 13: debug(900, "hddmutex unlock"); break; |
---|
1576 | case 14: debug(900, "linkedchannelmutex unlock"); break; |
---|
1577 | case 15: debug(900, "tsseekmutex unlock"); break; |
---|
1578 | case 16: debug(900, "accelfbmutex unlock"); break; |
---|
1579 | case 17: debug(900, "mediadbmutex unlock"); break; |
---|
1580 | case 18: debug(900, "oldentrymutex unlock"); break; |
---|
1581 | case 19: debug(900, "newslettermutex unlock"); break; |
---|
1582 | case 20: debug(900, "tithekmutex unlock"); break; |
---|
1583 | case 21: debug(900, "inetworkmutex unlock"); break; |
---|
1584 | case 22: debug(900, "textboxmutex unlock"); break; |
---|
1585 | case 23: debug(900, "setaktresmutex unlock"); break; |
---|
1586 | case 24: debug(900, "waitrcmutex unlock"); break; |
---|
1587 | case 25: debug(900, "oledmutex unlock"); break; |
---|
1588 | default: debug(900, "unknown mutex unlock"); break; |
---|
1589 | } |
---|
1590 | pthread_mutex_unlock(mutex); |
---|
1591 | } |
---|
1592 | |
---|
1593 | void debugstack(int sig, void* address, void* address1) |
---|
1594 | { |
---|
1595 | Dl_info info, info1; |
---|
1596 | void* trace[20]; |
---|
1597 | size_t size; |
---|
1598 | size = backtrace(trace, 20); |
---|
1599 | |
---|
1600 | FILE* fd = NULL; |
---|
1601 | void* akttrace[2]; |
---|
1602 | int i = 0; |
---|
1603 | char **strings; |
---|
1604 | char **aktstring; |
---|
1605 | time_t rawtime; |
---|
1606 | #ifdef BETA |
---|
1607 | int y = 0; |
---|
1608 | Dl_info info2; |
---|
1609 | #endif |
---|
1610 | |
---|
1611 | char* imgversion = NULL; |
---|
1612 | struct stimerthread* tnode = NULL; |
---|
1613 | |
---|
1614 | if(isfile(getconfig("imagenamefile", NULL)) != 0) |
---|
1615 | imgversion = readsys(getconfig("imagenamefile", NULL), 1); |
---|
1616 | else |
---|
1617 | imgversion = ostrcat("unknown", NULL, 0, 0); |
---|
1618 | |
---|
1619 | tnode = gettimerbythread(pthread_self()); |
---|
1620 | if(tnode != NULL) |
---|
1621 | dladdr(tnode->func, &info); |
---|
1622 | |
---|
1623 | dladdr(address, &info1); |
---|
1624 | |
---|
1625 | strings = backtrace_symbols(trace, size); |
---|
1626 | akttrace[0] = (void*)address1; |
---|
1627 | akttrace[1] = (void*)address; |
---|
1628 | aktstring = backtrace_symbols(akttrace, 2); //get fault funktion name |
---|
1629 | |
---|
1630 | fprintf(stderr, "--------------------------------------\n"); |
---|
1631 | fprintf(stderr, "Box: %s\n", getboxtype()); |
---|
1632 | fprintf(stderr, "Image: %s\n", imgversion); |
---|
1633 | fprintf(stderr, "Signal: %d (%s)\n", sig, strsignal(sig)); |
---|
1634 | if(info1.dli_fname != NULL) |
---|
1635 | fprintf(stderr, "Error in File: %s\n", info1.dli_fname); |
---|
1636 | fprintf(stderr, "MainThread: %x\n", (unsigned int)status.mainthread); |
---|
1637 | if(tnode != NULL && info.dli_sname != NULL) |
---|
1638 | fprintf(stderr, "Error in Thread: %x (%s)\n", (unsigned int)pthread_self(), info.dli_sname); |
---|
1639 | else |
---|
1640 | fprintf(stderr, "Error in Thread: %x\n", (unsigned int)pthread_self()); |
---|
1641 | |
---|
1642 | fprintf(stderr, "\nObtaining %zd stack frames:\n\n", size); |
---|
1643 | for(i = 0; i < size; i++) |
---|
1644 | fprintf(stderr, "%s\n", strings[i]); |
---|
1645 | |
---|
1646 | fprintf(stderr, "\nLast functions:\n\n"); |
---|
1647 | fprintf(stderr, "%s\n", aktstring[0]); |
---|
1648 | fprintf(stderr, "%s\n", aktstring[1]); |
---|
1649 | |
---|
1650 | #ifdef BETA |
---|
1651 | for(i = 0; i < MAXSTACKTRACE; i++) |
---|
1652 | { |
---|
1653 | if(stacktrace[i].pos > 0) |
---|
1654 | { |
---|
1655 | fprintf(stderr, "\nObtaining %d Thread Stack frames [%p]:\n\n", stacktrace[i].pos, (void*)stacktrace[i].thread); |
---|
1656 | for(y = stacktrace[i].pos - 1; y >= 0; y--) |
---|
1657 | { |
---|
1658 | dladdr(stacktrace[i].func[y], &info2); |
---|
1659 | fprintf(stderr, "%s(%s) [%p]\n", info2.dli_fname, info2.dli_sname, stacktrace[i].func[y]); |
---|
1660 | } |
---|
1661 | } |
---|
1662 | } |
---|
1663 | #endif |
---|
1664 | |
---|
1665 | fprintf(stderr, "--------------------------------------\n"); |
---|
1666 | |
---|
1667 | char* logdir = ostrcat(getconfig("tracelog", NULL), NULL, 0, 0); |
---|
1668 | if(logdir != NULL) |
---|
1669 | { |
---|
1670 | char* tmplogdir = dirname(logdir); |
---|
1671 | if(tmplogdir != NULL) |
---|
1672 | { |
---|
1673 | if(!file_exist(tmplogdir)) |
---|
1674 | mkdir(tmplogdir, 0777); |
---|
1675 | } |
---|
1676 | free(logdir); logdir = NULL; |
---|
1677 | } |
---|
1678 | |
---|
1679 | //del file if greater 100KB |
---|
1680 | if(getfilesize(getconfig("tracelog", NULL)) > 102400) |
---|
1681 | unlink(getconfig("tracelog", NULL)); |
---|
1682 | |
---|
1683 | fd = fopen(getconfig("tracelog", NULL), "a"); |
---|
1684 | if(fd != NULL) |
---|
1685 | { |
---|
1686 | time(&rawtime); |
---|
1687 | fprintf(fd, "Date: %s", ctime(&rawtime)); |
---|
1688 | fprintf(fd, "Box: %s\n", getboxtype()); |
---|
1689 | fprintf(fd, "Image: %s\n", imgversion); |
---|
1690 | fprintf(fd, "Signal: %d (%s)\n", sig, strsignal(sig)); |
---|
1691 | if(info1.dli_fname != NULL) |
---|
1692 | fprintf(fd, "Error in File: %s\n", info1.dli_fname); |
---|
1693 | fprintf(fd, "MainThread: %x\n", (unsigned int)status.mainthread); |
---|
1694 | if(tnode != NULL && info.dli_sname != NULL) |
---|
1695 | fprintf(fd, "Error in Thread: %x (%s)\n", (unsigned int)pthread_self(), info.dli_sname); |
---|
1696 | else |
---|
1697 | fprintf(fd, "Error in Thread: %x\n", (unsigned int)pthread_self()); |
---|
1698 | |
---|
1699 | fprintf(fd, "\nObtaining %zd stack frames:\n\n", size); |
---|
1700 | for(i = 0; i < size; i++) |
---|
1701 | fprintf(fd, "%s\n", strings[i]); |
---|
1702 | |
---|
1703 | fprintf(fd, "\nLast functions:\n\n"); |
---|
1704 | fprintf(fd, "%s\n", aktstring[0]); |
---|
1705 | fprintf(fd, "%s\n", aktstring[1]); |
---|
1706 | |
---|
1707 | #ifdef BETA |
---|
1708 | for(i = 0; i < MAXSTACKTRACE; i++) |
---|
1709 | { |
---|
1710 | if(stacktrace[i].pos > 0) |
---|
1711 | { |
---|
1712 | fprintf(fd, "\nObtaining %d Thread Stack frames [%p]:\n\n", stacktrace[i].pos, (void*)stacktrace[i].thread); |
---|
1713 | for(y = stacktrace[i].pos - 1; y >= 0; y--) |
---|
1714 | { |
---|
1715 | dladdr(stacktrace[i].func[y], &info2); |
---|
1716 | fprintf(fd, "%s(%s) [%p]\n", info2.dli_fname, info2.dli_sname, stacktrace[i].func[y]); |
---|
1717 | } |
---|
1718 | } |
---|
1719 | } |
---|
1720 | #endif |
---|
1721 | |
---|
1722 | fprintf(fd, "--------------------------------------\n\n"); |
---|
1723 | fclose(fd); |
---|
1724 | sync(); |
---|
1725 | } |
---|
1726 | else |
---|
1727 | perr("open %s", getconfig("tracelog", NULL)); |
---|
1728 | |
---|
1729 | free(imgversion); |
---|
1730 | free(strings); |
---|
1731 | free(aktstring); |
---|
1732 | } |
---|
1733 | |
---|
1734 | int mountauto(const char *file, const char *dir, unsigned long int flag, const void *data) |
---|
1735 | { |
---|
1736 | int ret = -1; |
---|
1737 | char* saveptr = NULL, *filesystems = NULL, *tmpfilesystems = NULL, *token = NULL; |
---|
1738 | |
---|
1739 | filesystems = getconfig("filesystems", NULL); |
---|
1740 | tmpfilesystems = ostrcat(tmpfilesystems, filesystems, 0, 0); |
---|
1741 | |
---|
1742 | token = strtok_r(tmpfilesystems, ";", &saveptr); |
---|
1743 | while(token != NULL) |
---|
1744 | { |
---|
1745 | ret = mount(file, dir, token, flag, data); |
---|
1746 | if(ret == 0) break; |
---|
1747 | token = strtok_r(NULL, ";", &saveptr); |
---|
1748 | } |
---|
1749 | |
---|
1750 | free(tmpfilesystems); |
---|
1751 | return ret; |
---|
1752 | } |
---|
1753 | |
---|
1754 | int setwaswakuptimer(int value) |
---|
1755 | { |
---|
1756 | char *waswakeuptimerdev = NULL, *tmpstr = NULL; |
---|
1757 | int ret = 0; |
---|
1758 | |
---|
1759 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
1760 | |
---|
1761 | if(waswakeuptimerdev != NULL) |
---|
1762 | { |
---|
1763 | debug(100, "set %s to %d", waswakeuptimerdev, value); |
---|
1764 | tmpstr = oitoa(value); |
---|
1765 | ret = writesys(waswakeuptimerdev, tmpstr, 0); |
---|
1766 | free(tmpstr); tmpstr = NULL; |
---|
1767 | return ret; |
---|
1768 | } |
---|
1769 | |
---|
1770 | return 0; |
---|
1771 | } |
---|
1772 | |
---|
1773 | int getwaswakuptimer() |
---|
1774 | { |
---|
1775 | int ret = 0; |
---|
1776 | char *waswakeuptimerdev = NULL; |
---|
1777 | char *value = NULL; |
---|
1778 | |
---|
1779 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
1780 | |
---|
1781 | if(waswakeuptimerdev == NULL) |
---|
1782 | { |
---|
1783 | err("NULL detect"); |
---|
1784 | return 0; |
---|
1785 | } |
---|
1786 | |
---|
1787 | value = readsys(waswakeuptimerdev, 1); |
---|
1788 | if(value == NULL) |
---|
1789 | { |
---|
1790 | err("NULL detect"); |
---|
1791 | return 0; |
---|
1792 | } |
---|
1793 | |
---|
1794 | // start from timer |
---|
1795 | if(atoi(value) == 1) ret = 1; |
---|
1796 | |
---|
1797 | free(value); |
---|
1798 | return ret; |
---|
1799 | } |
---|
1800 | |
---|
1801 | int getrtctime() |
---|
1802 | { |
---|
1803 | int ret = 0; |
---|
1804 | char *rtctimedev = NULL; |
---|
1805 | char *value = NULL; |
---|
1806 | |
---|
1807 | rtctimedev = getconfig("rtctimedev", NULL); |
---|
1808 | |
---|
1809 | if(rtctimedev == NULL) |
---|
1810 | { |
---|
1811 | err("NULL detect"); |
---|
1812 | return 0; |
---|
1813 | } |
---|
1814 | |
---|
1815 | value = readsys(rtctimedev, 1); |
---|
1816 | if(value == NULL) |
---|
1817 | { |
---|
1818 | err("NULL detect"); |
---|
1819 | return 0; |
---|
1820 | } |
---|
1821 | |
---|
1822 | // start from timer |
---|
1823 | if(atoi(value) == 1) ret = 1; |
---|
1824 | |
---|
1825 | free(value); |
---|
1826 | return ret; |
---|
1827 | } |
---|
1828 | |
---|
1829 | void checkboxstart() |
---|
1830 | { |
---|
1831 | struct rectimer* node = rectimer; |
---|
1832 | int timediff = getconfigint("rectimer_timediff", NULL); |
---|
1833 | int test = 0; |
---|
1834 | |
---|
1835 | if(node == NULL) |
---|
1836 | { |
---|
1837 | setcecstandby(0); |
---|
1838 | return; //no record |
---|
1839 | } |
---|
1840 | |
---|
1841 | while(node != NULL) |
---|
1842 | { |
---|
1843 | if(node->status < 2 || node->status == 4) |
---|
1844 | { |
---|
1845 | time_t akttime = time(NULL); |
---|
1846 | time_t begin = node->begin - getconfigint("wakeuptimerdevdiff", NULL); |
---|
1847 | |
---|
1848 | debug(400, "begin=%ld akttime1=%ld akttime2=%ld", begin, akttime - timediff, akttime + timediff); |
---|
1849 | |
---|
1850 | if(begin > akttime - timediff && begin < akttime + timediff) |
---|
1851 | { |
---|
1852 | debug(400, "found rectimer who has start the box"); |
---|
1853 | setwaswakuptimer(1); |
---|
1854 | setcecstandby(1); |
---|
1855 | test = 1; |
---|
1856 | } |
---|
1857 | } |
---|
1858 | node = node->next; |
---|
1859 | } |
---|
1860 | if(test == 0) |
---|
1861 | setcecstandby(0); |
---|
1862 | } |
---|
1863 | |
---|
1864 | int setwakeuptimerdev(time_t value) |
---|
1865 | { |
---|
1866 | char* wakeuptimerdev, *tmpstr = NULL; |
---|
1867 | int ret = 0; |
---|
1868 | int diff = getconfigint("wakeuptimerdevdiff", NULL); |
---|
1869 | |
---|
1870 | if(value != 0x7FFFFFFF && value - diff > time(NULL)) |
---|
1871 | value -= diff; |
---|
1872 | |
---|
1873 | wakeuptimerdev = getconfig("wakeuptimerdev", NULL); |
---|
1874 | |
---|
1875 | if(wakeuptimerdev != NULL && value >= time(NULL)) |
---|
1876 | { |
---|
1877 | debug(10, "set %s to %ld", wakeuptimerdev, value); |
---|
1878 | tmpstr = olutoa(value); |
---|
1879 | ret = writesys(wakeuptimerdev, tmpstr, 0); |
---|
1880 | free(tmpstr); tmpstr = NULL; |
---|
1881 | return ret; |
---|
1882 | } |
---|
1883 | |
---|
1884 | return 0; |
---|
1885 | } |
---|
1886 | |
---|
1887 | int setrtctime(int value) |
---|
1888 | { |
---|
1889 | char *rtctimedev = NULL, *tmpstr = NULL; |
---|
1890 | int ret = 0; |
---|
1891 | |
---|
1892 | value += 7200; |
---|
1893 | |
---|
1894 | rtctimedev = getconfig("rtctimedev", NULL); |
---|
1895 | |
---|
1896 | if(rtctimedev != NULL) |
---|
1897 | { |
---|
1898 | debug(10, "set %s to %d", rtctimedev, value); |
---|
1899 | tmpstr = oitoa(value); |
---|
1900 | ret = writesys(rtctimedev, tmpstr, 0); |
---|
1901 | free(tmpstr); tmpstr = NULL; |
---|
1902 | return ret; |
---|
1903 | } |
---|
1904 | |
---|
1905 | return 0; |
---|
1906 | } |
---|
1907 | |
---|
1908 | int changepolicy() |
---|
1909 | { |
---|
1910 | char *tmppolicy = NULL, *tmpstr = NULL; |
---|
1911 | |
---|
1912 | tmppolicy = getpolicy(); |
---|
1913 | |
---|
1914 | #ifdef MIPSEL |
---|
1915 | char *aspect = NULL; |
---|
1916 | aspect = getaspect(); |
---|
1917 | |
---|
1918 | if(!ostrncmp("16:9", aspect, 4)) |
---|
1919 | { |
---|
1920 | if(ostrcmp("16:9_set_bestfit_to_policy_show_justscale", tmppolicy) == 0) |
---|
1921 | tmpstr = ostrcat("16:9_set_letterbox_to_policy_show_panscan", NULL, 0, 0); |
---|
1922 | else if(ostrcmp("16:9_set_letterbox_to_policy_show_panscan", tmppolicy) == 0) |
---|
1923 | tmpstr = ostrcat("16:9_set_panscan_to_policy_show_pillarbox", NULL, 0, 0); |
---|
1924 | else if(ostrcmp("16:9_set_panscan_to_policy_show_pillarbox", tmppolicy) == 0) |
---|
1925 | tmpstr = ostrcat("16:9_set_bestfit_to_policy_show_justscale", NULL, 0, 0); |
---|
1926 | |
---|
1927 | } |
---|
1928 | else |
---|
1929 | { |
---|
1930 | if(ostrcmp("4:3_set_bestfit_to_policy2_show_justscale", tmppolicy) == 0) |
---|
1931 | tmpstr = ostrcat("4:3_set_letterbox_to_policy2_show_letterbox", NULL, 0, 0); |
---|
1932 | else if(ostrcmp("4:3_set_letterbox_to_policy2_show_letterbox", tmppolicy) == 0) |
---|
1933 | tmpstr = ostrcat("4:3_set_panscan_to_policy2_show_panscan", NULL, 0, 0); |
---|
1934 | else if(ostrcmp("16:9_set_panscan_to_policy_show_pillarbox", tmppolicy) == 0) |
---|
1935 | tmpstr = ostrcat("4:3_set_bestfit_to_policy2_show_justscale", NULL, 0, 0); |
---|
1936 | } |
---|
1937 | |
---|
1938 | #else |
---|
1939 | if(!ostrncmp("letterbox", tmppolicy, 8)) |
---|
1940 | tmpstr = ostrcat(tmpstr, "panscan", 1, 0); |
---|
1941 | else if(!ostrncmp("panscan", tmppolicy, 7)) |
---|
1942 | tmpstr = ostrcat(tmpstr, "non", 1, 0); |
---|
1943 | else if(!ostrncmp("non", tmppolicy, 3)) |
---|
1944 | tmpstr = ostrcat(tmpstr, "bestfit", 1, 0); |
---|
1945 | else if(!ostrncmp("bestfit", tmppolicy, 7)) |
---|
1946 | tmpstr = ostrcat(tmpstr, "letterbox", 1, 0); |
---|
1947 | #endif |
---|
1948 | |
---|
1949 | setpolicy(tmpstr); |
---|
1950 | |
---|
1951 | free(tmpstr); tmpstr = NULL; |
---|
1952 | free(tmppolicy); tmppolicy = NULL; |
---|
1953 | return 0; |
---|
1954 | } |
---|
1955 | |
---|
1956 | char* getmac(char* dev) |
---|
1957 | { |
---|
1958 | int sock = -1, i = 0; |
---|
1959 | struct ifreq buf; |
---|
1960 | char* tmpstr = NULL; |
---|
1961 | char tmpbuf[4] = {}; |
---|
1962 | |
---|
1963 | if(dev == NULL) return NULL; |
---|
1964 | |
---|
1965 | sock = socket(PF_INET, SOCK_DGRAM, 0); |
---|
1966 | if(sock >= 0) |
---|
1967 | { |
---|
1968 | memset(&buf, 0x00, sizeof(buf)); |
---|
1969 | strcpy(buf.ifr_name, dev); |
---|
1970 | ioctl(sock, SIOCGIFHWADDR, &buf); |
---|
1971 | close(sock); |
---|
1972 | |
---|
1973 | for(i = 0; i < 6; i++) |
---|
1974 | { |
---|
1975 | snprintf(tmpbuf, 4, "%.2X:", (unsigned char)buf.ifr_hwaddr.sa_data[i]); |
---|
1976 | tmpstr = ostrcat(tmpstr, tmpbuf, 1, 0); |
---|
1977 | } |
---|
1978 | if(tmpbuf != NULL) |
---|
1979 | tmpstr[strlen(tmpstr) - 1] = '\0'; |
---|
1980 | } |
---|
1981 | |
---|
1982 | return tmpstr; |
---|
1983 | } |
---|
1984 | |
---|
1985 | char* getdefaultgw() |
---|
1986 | { |
---|
1987 | char* name = NULL; |
---|
1988 | unsigned long def, gw, m; |
---|
1989 | int flags, ref, use, metric, mtu, win, ir; |
---|
1990 | struct in_addr ip; |
---|
1991 | |
---|
1992 | FILE *fd = fopen("/proc/net/route", "r"); |
---|
1993 | if(fd == NULL) |
---|
1994 | return NULL; |
---|
1995 | |
---|
1996 | if(fscanf(fd, "%*[^\n]\n") < 0) |
---|
1997 | { |
---|
1998 | fclose(fd); |
---|
1999 | return NULL; |
---|
2000 | } |
---|
2001 | |
---|
2002 | name = malloc(64); |
---|
2003 | if(name == NULL) |
---|
2004 | { |
---|
2005 | err("no mem"); |
---|
2006 | return NULL; |
---|
2007 | } |
---|
2008 | |
---|
2009 | while(1) |
---|
2010 | { |
---|
2011 | int r = fscanf(fd, "%63s%lx%lx%x%d%d%d%lx%d%d%d\n", name, &def, &gw, &flags, &ref, &use, &metric, &m, &mtu, &win, &ir); |
---|
2012 | if(def == 0) break; |
---|
2013 | if(r != 11) |
---|
2014 | { |
---|
2015 | fclose(fd); |
---|
2016 | free(name); |
---|
2017 | return NULL; |
---|
2018 | } |
---|
2019 | if(!(flags & 0x0001)) continue; //is interface down |
---|
2020 | } |
---|
2021 | |
---|
2022 | fclose(fd); |
---|
2023 | free(name); |
---|
2024 | |
---|
2025 | ip.s_addr = gw; |
---|
2026 | if(def == 0) |
---|
2027 | return inet_ntoa(ip); |
---|
2028 | |
---|
2029 | return NULL; |
---|
2030 | } |
---|
2031 | |
---|
2032 | char* changefilenameext(char* filename, char* ext) |
---|
2033 | { |
---|
2034 | char* newfilename = NULL; |
---|
2035 | char* zeichen = NULL; |
---|
2036 | |
---|
2037 | if(filename == NULL) return NULL; |
---|
2038 | |
---|
2039 | newfilename = ostrcat(filename, NULL, 0, 0); |
---|
2040 | |
---|
2041 | zeichen = strrchr(newfilename, '.'); |
---|
2042 | if(zeichen != NULL) |
---|
2043 | { |
---|
2044 | zeichen[0] = '\0'; |
---|
2045 | newfilename = ostrcat(newfilename, ext, 1, 0); |
---|
2046 | } |
---|
2047 | |
---|
2048 | return newfilename; |
---|
2049 | } |
---|
2050 | |
---|
2051 | int cmpfilenameext(char* filename, char* ext) |
---|
2052 | { |
---|
2053 | char* zeichen = NULL; |
---|
2054 | |
---|
2055 | if(filename == NULL) return 1; |
---|
2056 | |
---|
2057 | zeichen = strrchr(filename, '.'); |
---|
2058 | if(zeichen != NULL) |
---|
2059 | { |
---|
2060 | if(ostrcasecmp(zeichen, ext) == 0) return 0; |
---|
2061 | } |
---|
2062 | |
---|
2063 | return 1; |
---|
2064 | } |
---|
2065 | |
---|
2066 | char* getfilenameext(char* filename) |
---|
2067 | { |
---|
2068 | char* zeichen = NULL; |
---|
2069 | |
---|
2070 | if(filename == NULL) return NULL; |
---|
2071 | |
---|
2072 | zeichen = strrchr(filename, '.'); |
---|
2073 | if(zeichen != NULL) |
---|
2074 | { |
---|
2075 | return ostrcat(zeichen + 1, NULL, 0, 0); |
---|
2076 | } |
---|
2077 | |
---|
2078 | return NULL; |
---|
2079 | } |
---|
2080 | |
---|
2081 | char* getfilenamepng(char* filename) |
---|
2082 | { |
---|
2083 | char* tmpstr = NULL; |
---|
2084 | |
---|
2085 | if(filename == NULL) return NULL; |
---|
2086 | |
---|
2087 | if(!filelistflt(".avi .dat .divx .flv .mkv .m4v .mp4 .mov .mpg .mpeg .mts .m2ts .trp .ts .vdr .vob .wmv .rm", filename)) |
---|
2088 | tmpstr = ostrcat("movie", NULL, 0, 0); |
---|
2089 | else if(!filelistflt(".mp3 .flac .ogg .wma .ra .wav", filename)) |
---|
2090 | tmpstr = ostrcat("musik", NULL, 0, 0); |
---|
2091 | else if(!filelistflt(".jpg .png", filename)) |
---|
2092 | tmpstr = ostrcat("picture", NULL, 0, 0); |
---|
2093 | else |
---|
2094 | tmpstr = ostrcat(getfilenameext(filename), NULL, 1, 0); |
---|
2095 | |
---|
2096 | if(tmpstr != NULL) |
---|
2097 | { |
---|
2098 | return tmpstr; |
---|
2099 | } |
---|
2100 | |
---|
2101 | return NULL; |
---|
2102 | } |
---|
2103 | |
---|
2104 | char* getcurrentdir(char* path) |
---|
2105 | { |
---|
2106 | char* zeichen = NULL; |
---|
2107 | |
---|
2108 | if(path == NULL) return NULL; |
---|
2109 | |
---|
2110 | zeichen = strrchr(path, '/'); |
---|
2111 | if(zeichen != NULL) |
---|
2112 | { |
---|
2113 | return ostrcat(zeichen + 1, NULL, 0, 0); |
---|
2114 | } |
---|
2115 | |
---|
2116 | return NULL; |
---|
2117 | } |
---|
2118 | |
---|
2119 | char* convert_timesec(int sec) |
---|
2120 | { |
---|
2121 | int hour = 0, min = 0, seconds = 0; |
---|
2122 | char* buf = NULL; |
---|
2123 | |
---|
2124 | buf = malloc(9); |
---|
2125 | if(buf == NULL) |
---|
2126 | { |
---|
2127 | err("no mem"); |
---|
2128 | return NULL; |
---|
2129 | } |
---|
2130 | |
---|
2131 | seconds = sec % 60; |
---|
2132 | min = (sec / 60) % 60; |
---|
2133 | hour = sec / 3600; |
---|
2134 | |
---|
2135 | if(seconds < 0) seconds = 0; |
---|
2136 | if(min < 0) min = 0; |
---|
2137 | if(hour < 0 || hour > 23) |
---|
2138 | { |
---|
2139 | hour = 0; |
---|
2140 | min = 0; |
---|
2141 | seconds = 0; |
---|
2142 | } |
---|
2143 | |
---|
2144 | snprintf(buf, 9, "%02d:%02d:%02d", hour, min, seconds); |
---|
2145 | |
---|
2146 | return buf; |
---|
2147 | } |
---|
2148 | |
---|
2149 | int checkdate() |
---|
2150 | { |
---|
2151 | time_t dvbtime = 0; |
---|
2152 | |
---|
2153 | if(time(NULL) < 1072224000 || status.timeupdatecount > 3600) // 01.01.2004 |
---|
2154 | { |
---|
2155 | if(dvbgetdate(&dvbtime, 10000000) == 0) //10 sek |
---|
2156 | { |
---|
2157 | setsystime(&dvbtime); |
---|
2158 | #ifdef MIPSEL |
---|
2159 | setrtctimemips(); |
---|
2160 | #endif |
---|
2161 | status.timeupdatecount = 0; |
---|
2162 | return 0; |
---|
2163 | } |
---|
2164 | return 1; |
---|
2165 | } |
---|
2166 | return 0; |
---|
2167 | } |
---|
2168 | |
---|
2169 | void closeonexec(int fd) |
---|
2170 | { |
---|
2171 | if(fd > -1) |
---|
2172 | fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
---|
2173 | } |
---|
2174 | |
---|
2175 | void startnewsletter(flag) |
---|
2176 | { |
---|
2177 | if(flag == 1) |
---|
2178 | { |
---|
2179 | if(getconfigint("newsletter", NULL) == 1 && status.newsletterthread == NULL) |
---|
2180 | status.newsletterthread = addtimer(&newsletterthreadfunc, START, 1000, 1, NULL, NULL, NULL); |
---|
2181 | } |
---|
2182 | else if(status.newsletterthread != NULL) |
---|
2183 | { |
---|
2184 | status.newsletterthread->aktion = STOP; |
---|
2185 | status.newsletterthread = NULL; |
---|
2186 | } |
---|
2187 | } |
---|
2188 | |
---|
2189 | void startthumb(flag) |
---|
2190 | { |
---|
2191 | if(flag == 1) |
---|
2192 | { |
---|
2193 | if(getconfigint("createthumb", NULL) == 1 && status.thumbthread == NULL) |
---|
2194 | status.thumbthread = addtimer(&thumbthread, START, 1000, 1, NULL, NULL, NULL); |
---|
2195 | } |
---|
2196 | else if(status.thumbthread != NULL) |
---|
2197 | { |
---|
2198 | status.thumbthread->aktion = STOP; |
---|
2199 | status.thumbthread = NULL; |
---|
2200 | } |
---|
2201 | } |
---|
2202 | |
---|
2203 | void starthttpd(flag) |
---|
2204 | { |
---|
2205 | if(flag == 1) |
---|
2206 | { |
---|
2207 | if(getconfigint("httpdstart", NULL) == 1 && status.httpthread == NULL) |
---|
2208 | { |
---|
2209 | status.httpthread = addtimer(&httpdthreadfunc, START, 10000, -1, NULL, NULL, NULL); |
---|
2210 | if(status.httpthread != NULL) |
---|
2211 | status.httpthread->flag = setbit(status.httpthread->flag, 0); |
---|
2212 | } |
---|
2213 | } |
---|
2214 | else if(status.httpthread != NULL) |
---|
2215 | { |
---|
2216 | status.httpthread->aktion = STOP; |
---|
2217 | status.httpthread = NULL; |
---|
2218 | } |
---|
2219 | } |
---|
2220 | |
---|
2221 | void startrguid(flag) |
---|
2222 | { |
---|
2223 | if(flag == 1) |
---|
2224 | { |
---|
2225 | if(getconfigint("rguidstart", NULL) == 1 && status.rguithread == NULL) |
---|
2226 | { |
---|
2227 | status.rguithread = addtimer(&rguidthreadfunc, START, 10000, -1, NULL, NULL, NULL); |
---|
2228 | if(status.rguithread != NULL) |
---|
2229 | status.rguithread->flag = setbit(status.rguithread->flag, 0); |
---|
2230 | } |
---|
2231 | } |
---|
2232 | else if(status.rguithread != NULL) |
---|
2233 | { |
---|
2234 | status.rguithread->aktion = STOP; |
---|
2235 | status.rguithread = NULL; |
---|
2236 | } |
---|
2237 | } |
---|
2238 | |
---|
2239 | int setoverclockfreq(int mode) |
---|
2240 | { |
---|
2241 | // mode 0 = Set Standby Freq |
---|
2242 | // mode 1 = Set Freq |
---|
2243 | |
---|
2244 | if(ostrcmp(getownconfig("standby_overclock"), "0") == 0) |
---|
2245 | return 1; |
---|
2246 | |
---|
2247 | if(isfile("/proc/cpu_frequ/pll0_ndiv_mdiv") == 0) |
---|
2248 | return 1; |
---|
2249 | |
---|
2250 | char* tmpstr = NULL; |
---|
2251 | |
---|
2252 | if(mode == 0) |
---|
2253 | tmpstr = getownconfig("standby_freq"); |
---|
2254 | else |
---|
2255 | tmpstr = getownconfig("pll0_ndiv_mdiv"); |
---|
2256 | |
---|
2257 | return writesys("/proc/cpu_frequ/pll0_ndiv_mdiv", tmpstr, 1); |
---|
2258 | } |
---|
2259 | |
---|
2260 | /* |
---|
2261 | int checkdev(char* dev) |
---|
2262 | { |
---|
2263 | char* cmd = NULL; |
---|
2264 | cmd = ostrcat(cmd, "cat ", 1, 0); |
---|
2265 | cmd = ostrcat(cmd, dev, 1, 0); |
---|
2266 | |
---|
2267 | char* tmpstr = NULL; |
---|
2268 | tmpstr = string_newline(command(cmd)); |
---|
2269 | free(cmd), cmd = NULL; |
---|
2270 | |
---|
2271 | if(tmpstr == NULL) |
---|
2272 | { |
---|
2273 | return 0; |
---|
2274 | } |
---|
2275 | |
---|
2276 | if(ostrcmp(tmpstr, "Segmentation fault") == 0) |
---|
2277 | { |
---|
2278 | return 0; |
---|
2279 | } |
---|
2280 | |
---|
2281 | free(tmpstr), tmpstr = NULL; |
---|
2282 | return 1; |
---|
2283 | } |
---|
2284 | */ |
---|
2285 | |
---|
2286 | int setsaturation(int value) |
---|
2287 | { |
---|
2288 | char* saturationdev; |
---|
2289 | |
---|
2290 | saturationdev = getconfig("saturationdev", NULL); |
---|
2291 | |
---|
2292 | if(saturationdev != NULL /*&& checkdev(saturationdev)*/) |
---|
2293 | { |
---|
2294 | debug(100, "set %s to %d", saturationdev, value); |
---|
2295 | return writesysint(saturationdev, value, 1); |
---|
2296 | } |
---|
2297 | |
---|
2298 | return 0; |
---|
2299 | } |
---|
2300 | |
---|
2301 | int setbrightness(int value) |
---|
2302 | { |
---|
2303 | char* brightnessdev; |
---|
2304 | |
---|
2305 | brightnessdev = getconfig("brightnessdev", NULL); |
---|
2306 | |
---|
2307 | if(brightnessdev != NULL /*&& checkdev(brightnessdev)*/) |
---|
2308 | { |
---|
2309 | debug(100, "set %s to %d", brightnessdev, value); |
---|
2310 | return writesysint(brightnessdev, value, 1); |
---|
2311 | } |
---|
2312 | |
---|
2313 | return 0; |
---|
2314 | } |
---|
2315 | |
---|
2316 | int setcontrast(int value) |
---|
2317 | { |
---|
2318 | char* contrastdev; |
---|
2319 | |
---|
2320 | contrastdev = getconfig("contrastdev", NULL); |
---|
2321 | |
---|
2322 | if(contrastdev != NULL /*&& checkdev(contrastdev)*/) |
---|
2323 | { |
---|
2324 | debug(100, "set %s to %d", contrastdev, value); |
---|
2325 | return writesysint(contrastdev, value, 1); |
---|
2326 | } |
---|
2327 | |
---|
2328 | return 0; |
---|
2329 | } |
---|
2330 | |
---|
2331 | int settint(int value) |
---|
2332 | { |
---|
2333 | char* tintdev; |
---|
2334 | |
---|
2335 | tintdev = getconfig("tintdev", NULL); |
---|
2336 | |
---|
2337 | if(tintdev != NULL /*&& checkdev(tintdev)*/) |
---|
2338 | { |
---|
2339 | debug(100, "set %s to %d", tintdev, value); |
---|
2340 | return writesysint(tintdev, value, 1); |
---|
2341 | } |
---|
2342 | |
---|
2343 | return 0; |
---|
2344 | } |
---|
2345 | |
---|
2346 | int ozip(char* inbuf, int inlen, char** outbuf, int* outlen, int level) |
---|
2347 | { |
---|
2348 | int ret = 0; |
---|
2349 | z_stream stream; |
---|
2350 | |
---|
2351 | if(inbuf == NULL || outbuf == NULL || inlen == 0) return 1; |
---|
2352 | |
---|
2353 | stream.zalloc = Z_NULL; |
---|
2354 | stream.zfree = Z_NULL; |
---|
2355 | stream.opaque = Z_NULL; |
---|
2356 | stream.avail_in = 0; |
---|
2357 | stream.next_in = Z_NULL; |
---|
2358 | stream.avail_out = 0; |
---|
2359 | stream.next_out = Z_NULL; |
---|
2360 | |
---|
2361 | ret = deflateInit(&stream, level); |
---|
2362 | if(ret != Z_OK) |
---|
2363 | return 1; |
---|
2364 | |
---|
2365 | *outbuf = malloc(inlen); |
---|
2366 | if(*outbuf == NULL) |
---|
2367 | { |
---|
2368 | err("no mem"); |
---|
2369 | (void)deflateEnd(&stream); |
---|
2370 | return 1; |
---|
2371 | } |
---|
2372 | |
---|
2373 | stream.avail_in = inlen; |
---|
2374 | stream.next_in = (void*)inbuf; |
---|
2375 | |
---|
2376 | do |
---|
2377 | { |
---|
2378 | stream.avail_out = inlen; |
---|
2379 | stream.next_out = (void*)*outbuf; |
---|
2380 | |
---|
2381 | ret = deflate(&stream, Z_FINISH); |
---|
2382 | if(ret == Z_STREAM_ERROR) |
---|
2383 | { |
---|
2384 | free(*outbuf); *outbuf = NULL; |
---|
2385 | (void)deflateEnd(&stream); |
---|
2386 | return 1; |
---|
2387 | } |
---|
2388 | } |
---|
2389 | while(stream.avail_out == 0); |
---|
2390 | |
---|
2391 | char* tmpoutbuf = *outbuf; |
---|
2392 | *outlen = inlen - stream.avail_out; |
---|
2393 | *outbuf = realloc(*outbuf, *outlen); |
---|
2394 | if(*outbuf == NULL) |
---|
2395 | { |
---|
2396 | if(*outlen > 0) |
---|
2397 | { |
---|
2398 | err("no mem"); |
---|
2399 | free(tmpoutbuf); |
---|
2400 | } |
---|
2401 | *outlen = 0; |
---|
2402 | (void)deflateEnd(&stream); |
---|
2403 | return 1; |
---|
2404 | } |
---|
2405 | |
---|
2406 | (void)deflateEnd(&stream); |
---|
2407 | return 0; |
---|
2408 | } |
---|
2409 | |
---|
2410 | //flag 0: malloc mem |
---|
2411 | //flag 1: don't malloc mem |
---|
2412 | //flag 2: malloc mem (gzip) |
---|
2413 | //flag 3: don't malloc mem (gzip) |
---|
2414 | int ounzip(char* inbuf, int inlen, char** outbuf, int* outlen, int maxbuf, int flag) |
---|
2415 | { |
---|
2416 | int ret = 0; |
---|
2417 | z_stream stream; |
---|
2418 | |
---|
2419 | if(inbuf == NULL || outbuf == NULL || maxbuf == 0) return 1; |
---|
2420 | if(flag == 1 && *outbuf == NULL) return 1; |
---|
2421 | |
---|
2422 | stream.zalloc = Z_NULL; |
---|
2423 | stream.zfree = Z_NULL; |
---|
2424 | stream.opaque = Z_NULL; |
---|
2425 | stream.avail_in = 0; |
---|
2426 | stream.next_in = Z_NULL; |
---|
2427 | stream.avail_out = 0; |
---|
2428 | stream.next_out = Z_NULL; |
---|
2429 | |
---|
2430 | if(flag == 2 || flag == 3) |
---|
2431 | { |
---|
2432 | ret = inflateInit2(&stream, 16 + MAX_WBITS); |
---|
2433 | if(flag == 2) flag = 0; |
---|
2434 | else if(flag == 3) flag = 1; |
---|
2435 | } |
---|
2436 | else |
---|
2437 | ret = inflateInit(&stream); |
---|
2438 | if(ret != Z_OK) |
---|
2439 | return 1; |
---|
2440 | |
---|
2441 | if(flag == 0) |
---|
2442 | { |
---|
2443 | *outbuf = malloc(maxbuf); |
---|
2444 | if(*outbuf == NULL) |
---|
2445 | { |
---|
2446 | err("no mem"); |
---|
2447 | (void)inflateEnd(&stream); |
---|
2448 | return 1; |
---|
2449 | } |
---|
2450 | } |
---|
2451 | |
---|
2452 | stream.avail_in = inlen; |
---|
2453 | stream.next_in = (void*)inbuf; |
---|
2454 | |
---|
2455 | int round = 0; |
---|
2456 | do |
---|
2457 | { |
---|
2458 | stream.avail_out = maxbuf; |
---|
2459 | |
---|
2460 | if(flag == 0 && round > 0) |
---|
2461 | { |
---|
2462 | char* tmpoutbuf = *outbuf; |
---|
2463 | *outbuf = realloc(*outbuf, maxbuf * (round + 1)); |
---|
2464 | if(*outbuf == NULL) |
---|
2465 | { |
---|
2466 | err("no mem"); |
---|
2467 | free(tmpoutbuf); |
---|
2468 | (void)inflateEnd(&stream); |
---|
2469 | return 1; |
---|
2470 | } |
---|
2471 | stream.next_out = (void*)(*outbuf) + maxbuf * round; |
---|
2472 | } |
---|
2473 | else |
---|
2474 | stream.next_out = (void*)*outbuf; |
---|
2475 | |
---|
2476 | ret = inflate(&stream, Z_NO_FLUSH); |
---|
2477 | if(ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) |
---|
2478 | { |
---|
2479 | if(flag == 0) |
---|
2480 | { |
---|
2481 | free(*outbuf); |
---|
2482 | *outbuf = NULL; |
---|
2483 | } |
---|
2484 | (void)inflateEnd(&stream); |
---|
2485 | return 1; |
---|
2486 | } |
---|
2487 | |
---|
2488 | round++; |
---|
2489 | } |
---|
2490 | while(stream.avail_out == 0); |
---|
2491 | |
---|
2492 | if(flag == 0) |
---|
2493 | { |
---|
2494 | char* tmpoutbuf = *outbuf; |
---|
2495 | *outlen = (maxbuf * round) - stream.avail_out; |
---|
2496 | *outbuf = realloc(*outbuf, *outlen); |
---|
2497 | if(*outbuf == NULL) |
---|
2498 | { |
---|
2499 | err("no mem"); |
---|
2500 | if(*outlen > 0) free(tmpoutbuf); |
---|
2501 | *outlen = 0; |
---|
2502 | (void)inflateEnd(&stream); |
---|
2503 | return 1; |
---|
2504 | } |
---|
2505 | } |
---|
2506 | else |
---|
2507 | *outlen = maxbuf - stream.avail_out; |
---|
2508 | |
---|
2509 | (void)inflateEnd(&stream); |
---|
2510 | return 0; |
---|
2511 | } |
---|
2512 | |
---|
2513 | void endianswapshort(unsigned short* value) |
---|
2514 | { |
---|
2515 | *value = (*value >> 8) | (*value << 8); |
---|
2516 | } |
---|
2517 | |
---|
2518 | int rcnumber(int rcret) |
---|
2519 | { |
---|
2520 | if(rcret == getrcconfigint("rc0", NULL) || |
---|
2521 | rcret == getrcconfigint("rc1", NULL) || |
---|
2522 | rcret == getrcconfigint("rc2", NULL) || |
---|
2523 | rcret == getrcconfigint("rc3", NULL) || |
---|
2524 | rcret == getrcconfigint("rc4", NULL) || |
---|
2525 | rcret == getrcconfigint("rc5", NULL) || |
---|
2526 | rcret == getrcconfigint("rc6", NULL) || |
---|
2527 | rcret == getrcconfigint("rc7", NULL) || |
---|
2528 | rcret == getrcconfigint("rc8", NULL) || |
---|
2529 | rcret == getrcconfigint("rc9", NULL)) |
---|
2530 | return rcret; |
---|
2531 | else |
---|
2532 | return -9999; |
---|
2533 | } |
---|
2534 | |
---|
2535 | int checkdirext(char* dir, char* ext) |
---|
2536 | { |
---|
2537 | struct dirent *dirent = NULL; |
---|
2538 | DIR *pdir = NULL; |
---|
2539 | |
---|
2540 | pdir = opendir(dir); |
---|
2541 | if(pdir != NULL) |
---|
2542 | { |
---|
2543 | while((dirent = readdir(pdir)) != NULL) |
---|
2544 | { |
---|
2545 | if(ostrcmp(".", dirent->d_name) != 0 && ostrcmp("..", dirent->d_name) != 0) |
---|
2546 | { |
---|
2547 | if(ostrstr(dirent->d_name, ext) != NULL) |
---|
2548 | { |
---|
2549 | closedir(pdir); |
---|
2550 | return 1; |
---|
2551 | } |
---|
2552 | } |
---|
2553 | } |
---|
2554 | |
---|
2555 | closedir(pdir); |
---|
2556 | } |
---|
2557 | |
---|
2558 | return 0; |
---|
2559 | } |
---|
2560 | |
---|
2561 | int delallfiles(char* dir, char* ext) |
---|
2562 | { |
---|
2563 | struct dirent *dirent = NULL; |
---|
2564 | DIR *pdir = NULL; |
---|
2565 | char* tmpstr = NULL; |
---|
2566 | |
---|
2567 | pdir = opendir(dir); |
---|
2568 | if(pdir != NULL) |
---|
2569 | { |
---|
2570 | while((dirent = readdir(pdir)) != NULL) |
---|
2571 | { |
---|
2572 | if(ostrcmp(".", dirent->d_name) != 0 && ostrcmp("..", dirent->d_name) != 0) |
---|
2573 | { |
---|
2574 | if(ext == NULL || ostrstr(dirent->d_name, ext) != NULL) |
---|
2575 | { |
---|
2576 | tmpstr = ostrcat(dir, "/", 0, 0); |
---|
2577 | tmpstr = ostrcat(tmpstr, dirent->d_name, 1, 0); |
---|
2578 | unlink(tmpstr); |
---|
2579 | free(tmpstr); tmpstr = NULL; |
---|
2580 | } |
---|
2581 | } |
---|
2582 | } |
---|
2583 | |
---|
2584 | closedir(pdir); |
---|
2585 | } |
---|
2586 | |
---|
2587 | return 0; |
---|
2588 | } |
---|
2589 | |
---|
2590 | unsigned long getfilecount(char* dir) |
---|
2591 | { |
---|
2592 | unsigned long count = 0; |
---|
2593 | struct dirent *dirent = NULL; |
---|
2594 | DIR *pdir = NULL; |
---|
2595 | |
---|
2596 | pdir = opendir(dir); |
---|
2597 | if(pdir != NULL) |
---|
2598 | { |
---|
2599 | while((dirent = readdir(pdir)) != NULL) |
---|
2600 | count++; |
---|
2601 | |
---|
2602 | closedir(pdir); |
---|
2603 | } |
---|
2604 | |
---|
2605 | return count; |
---|
2606 | } |
---|
2607 | |
---|
2608 | int getfiletype(char* filename) |
---|
2609 | { |
---|
2610 | struct stat64 s; |
---|
2611 | |
---|
2612 | if(filename == NULL) return -1; |
---|
2613 | |
---|
2614 | if(stat64(filename, &s) >= 0) |
---|
2615 | { |
---|
2616 | if(S_ISREG(s.st_mode)) return DT_REG; |
---|
2617 | if(S_ISDIR(s.st_mode)) return DT_DIR; |
---|
2618 | if(S_ISCHR(s.st_mode)) return DT_CHR; |
---|
2619 | if(S_ISBLK(s.st_mode)) return DT_BLK; |
---|
2620 | if(S_ISFIFO(s.st_mode)) return DT_FIFO; |
---|
2621 | if(S_ISLNK(s.st_mode)) return DT_LNK; |
---|
2622 | } |
---|
2623 | |
---|
2624 | return DT_UNKNOWN; |
---|
2625 | } |
---|
2626 | |
---|
2627 | int getlfiletype(char* filename) |
---|
2628 | { |
---|
2629 | struct stat64 s; |
---|
2630 | |
---|
2631 | if(filename == NULL) return -1; |
---|
2632 | |
---|
2633 | if(lstat64(filename, &s) >= 0) |
---|
2634 | { |
---|
2635 | if(S_ISREG(s.st_mode)) return DT_REG; |
---|
2636 | if(S_ISDIR(s.st_mode)) return DT_DIR; |
---|
2637 | if(S_ISCHR(s.st_mode)) return DT_CHR; |
---|
2638 | if(S_ISBLK(s.st_mode)) return DT_BLK; |
---|
2639 | if(S_ISFIFO(s.st_mode)) return DT_FIFO; |
---|
2640 | if(S_ISLNK(s.st_mode)) return DT_LNK; |
---|
2641 | } |
---|
2642 | |
---|
2643 | return DT_UNKNOWN; |
---|
2644 | } |
---|
2645 | |
---|
2646 | unsigned long long getfullspace(char* dir) |
---|
2647 | { |
---|
2648 | struct statfs64 s; |
---|
2649 | unsigned long long fullsize = 0; |
---|
2650 | |
---|
2651 | if(statfs64(dir, &s) >= 0) |
---|
2652 | { |
---|
2653 | fullsize = s.f_blocks; |
---|
2654 | fullsize *= s.f_bsize; |
---|
2655 | } |
---|
2656 | |
---|
2657 | return fullsize; |
---|
2658 | } |
---|
2659 | |
---|
2660 | unsigned long long getfreespace(char* dir) |
---|
2661 | { |
---|
2662 | struct statfs64 s; |
---|
2663 | unsigned long long freesize = 0; |
---|
2664 | |
---|
2665 | if(statfs64(dir, &s) >= 0) |
---|
2666 | { |
---|
2667 | freesize = s.f_bfree; |
---|
2668 | freesize *= s.f_bsize; |
---|
2669 | } |
---|
2670 | |
---|
2671 | return freesize; |
---|
2672 | } |
---|
2673 | |
---|
2674 | int checkbit(int value, int bitpos) |
---|
2675 | { |
---|
2676 | int ret = 0; |
---|
2677 | |
---|
2678 | ret = value & (1 << bitpos) ? 1: 0; |
---|
2679 | return ret; |
---|
2680 | } |
---|
2681 | |
---|
2682 | int tooglebit(int value, int bitpos) |
---|
2683 | { |
---|
2684 | value ^= 1 << bitpos; |
---|
2685 | return value; |
---|
2686 | } |
---|
2687 | |
---|
2688 | int clearbit(int value, int bitpos) |
---|
2689 | { |
---|
2690 | value &= ~(1 << bitpos); |
---|
2691 | return value; |
---|
2692 | } |
---|
2693 | |
---|
2694 | int setbit(int value, int bitpos) |
---|
2695 | { |
---|
2696 | value |= 1 << bitpos; |
---|
2697 | return value; |
---|
2698 | } |
---|
2699 | |
---|
2700 | int setsystime(time_t* newtime) |
---|
2701 | { |
---|
2702 | if (stime(newtime)) |
---|
2703 | { |
---|
2704 | err("can't set system time"); |
---|
2705 | return 1; |
---|
2706 | } |
---|
2707 | return 0; |
---|
2708 | } |
---|
2709 | |
---|
2710 | off64_t getfilesize(char* name) |
---|
2711 | { |
---|
2712 | struct stat64 sbuf; |
---|
2713 | |
---|
2714 | if(lstat64(name, &sbuf) == -1) |
---|
2715 | return 0; |
---|
2716 | |
---|
2717 | return sbuf.st_size; |
---|
2718 | } |
---|
2719 | |
---|
2720 | time_t getfiletime(char* name, int type) |
---|
2721 | { |
---|
2722 | struct stat64 sbuf; |
---|
2723 | |
---|
2724 | if(lstat64(name, &sbuf) == -1) |
---|
2725 | return 0; |
---|
2726 | |
---|
2727 | switch(type) |
---|
2728 | { |
---|
2729 | case 1: return sbuf.st_mtime; |
---|
2730 | case 2: return sbuf.st_ctime; |
---|
2731 | default: return sbuf.st_atime; |
---|
2732 | } |
---|
2733 | } |
---|
2734 | |
---|
2735 | int isfile(char* name) |
---|
2736 | { |
---|
2737 | struct stat64 sbuf; |
---|
2738 | |
---|
2739 | if(lstat64(name, &sbuf) == -1) |
---|
2740 | return 0; |
---|
2741 | |
---|
2742 | if(S_ISREG(sbuf.st_mode)) |
---|
2743 | return 1; |
---|
2744 | |
---|
2745 | return 0; |
---|
2746 | } |
---|
2747 | |
---|
2748 | int isdir(char* name) |
---|
2749 | { |
---|
2750 | struct stat64 sbuf; |
---|
2751 | char *rpath = NULL; |
---|
2752 | |
---|
2753 | if(lstat64(name, &sbuf) == -1) |
---|
2754 | return 0; |
---|
2755 | |
---|
2756 | if(S_ISDIR(sbuf.st_mode)) |
---|
2757 | return 1; |
---|
2758 | |
---|
2759 | if(S_ISLNK(sbuf.st_mode)) |
---|
2760 | { |
---|
2761 | rpath = realpath(name, NULL); |
---|
2762 | if(lstat64(rpath, &sbuf) == -1) |
---|
2763 | { |
---|
2764 | free(rpath); |
---|
2765 | return 0; |
---|
2766 | } |
---|
2767 | free(rpath); |
---|
2768 | if(S_ISDIR(sbuf.st_mode)) |
---|
2769 | return 1; |
---|
2770 | } |
---|
2771 | |
---|
2772 | return 0; |
---|
2773 | } |
---|
2774 | |
---|
2775 | char* getmaxsatstring(int maxsat) |
---|
2776 | { |
---|
2777 | char* tmpstr = NULL, *tmpnr = NULL; |
---|
2778 | int i; |
---|
2779 | |
---|
2780 | tmpstr = ostrcat(tmpstr, "1", 1, 0); |
---|
2781 | for(i = 2; i <= maxsat; i++) |
---|
2782 | { |
---|
2783 | tmpnr = oitoa(i); |
---|
2784 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
2785 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
2786 | } |
---|
2787 | return tmpstr; |
---|
2788 | } |
---|
2789 | |
---|
2790 | void ostrcatbig(char** value1, char* value2, int* maxlen, int* pos) |
---|
2791 | { |
---|
2792 | int len = 0; |
---|
2793 | |
---|
2794 | if(value2 == NULL) |
---|
2795 | return; |
---|
2796 | |
---|
2797 | len = strlen(value2) + 1; |
---|
2798 | |
---|
2799 | if(*value1 != NULL && maxlen == 0) |
---|
2800 | *maxlen = strlen(*value1); |
---|
2801 | |
---|
2802 | if(*value1 == NULL || *pos + len > *maxlen) |
---|
2803 | { |
---|
2804 | *maxlen = *maxlen + len + (MINMALLOC * 10); |
---|
2805 | *value1 = realloc(*value1, *maxlen); |
---|
2806 | if(*value1 == NULL) |
---|
2807 | { |
---|
2808 | err("no mem"); |
---|
2809 | return; |
---|
2810 | } |
---|
2811 | } |
---|
2812 | |
---|
2813 | memcpy(*value1 + *pos, value2, len); |
---|
2814 | *pos = *pos + (len - 1); |
---|
2815 | } |
---|
2816 | |
---|
2817 | char* ostrshrink(char* value) |
---|
2818 | { |
---|
2819 | int len = 0; |
---|
2820 | char* buf = NULL; |
---|
2821 | |
---|
2822 | if(value == NULL) return NULL; |
---|
2823 | |
---|
2824 | len = strlen(value); |
---|
2825 | if(len == 0) return value; |
---|
2826 | |
---|
2827 | buf = malloc(len + 1); |
---|
2828 | if(buf == NULL) |
---|
2829 | return value; |
---|
2830 | |
---|
2831 | memcpy(buf, value, len); |
---|
2832 | free(value); |
---|
2833 | buf[len] = '\0'; |
---|
2834 | |
---|
2835 | return buf; |
---|
2836 | } |
---|
2837 | |
---|
2838 | char* ostrcat(char* value1, char* value2, int free1, int free2) |
---|
2839 | { |
---|
2840 | int len = 0, len1 = 0, len2 = 0; |
---|
2841 | char* buf = NULL; |
---|
2842 | |
---|
2843 | if(value1 == NULL && value2 == NULL) return NULL; |
---|
2844 | |
---|
2845 | if(value1 != NULL) len1 = strlen(value1); |
---|
2846 | if(value2 != NULL) len2 = strlen(value2); |
---|
2847 | |
---|
2848 | len = len1 + len2 + 1; |
---|
2849 | |
---|
2850 | if(free1 == 1) |
---|
2851 | buf = realloc(value1, len); |
---|
2852 | else |
---|
2853 | buf = malloc(len); |
---|
2854 | if(buf == NULL) |
---|
2855 | { |
---|
2856 | if(free1 == 1) free(value1); |
---|
2857 | if(free2 == 1) free(value2); |
---|
2858 | return NULL; |
---|
2859 | } |
---|
2860 | |
---|
2861 | if(free1 == 0 && len1 > 0) memcpy(buf, value1, len1); |
---|
2862 | if(len2 > 0) memcpy(buf + len1, value2, len2); |
---|
2863 | buf[len - 1] = '\0'; |
---|
2864 | |
---|
2865 | if(free2 == 1) free(value2); |
---|
2866 | |
---|
2867 | //helpfull for memleak detect |
---|
2868 | //if(buf != NULL && strlen(buf) == 0x0b - 0x01) |
---|
2869 | // printf("******** memleak string (%s) (%p) ********\n", buf, buf); |
---|
2870 | |
---|
2871 | return buf; |
---|
2872 | } |
---|
2873 | |
---|
2874 | char* ollutoa(uint64_t value) |
---|
2875 | { |
---|
2876 | char *buf = NULL; |
---|
2877 | |
---|
2878 | buf = malloc(MINMALLOC); |
---|
2879 | if(buf == NULL) |
---|
2880 | { |
---|
2881 | err("no mem"); |
---|
2882 | return NULL; |
---|
2883 | } |
---|
2884 | |
---|
2885 | sprintf(buf, "%llu", value); |
---|
2886 | buf = ostrshrink(buf); |
---|
2887 | |
---|
2888 | return buf; |
---|
2889 | } |
---|
2890 | |
---|
2891 | char* olutoa(unsigned long value) |
---|
2892 | { |
---|
2893 | char *buf = NULL; |
---|
2894 | |
---|
2895 | buf = malloc(MINMALLOC); |
---|
2896 | if(buf == NULL) |
---|
2897 | { |
---|
2898 | err("no mem"); |
---|
2899 | return NULL; |
---|
2900 | } |
---|
2901 | |
---|
2902 | sprintf(buf, "%lu", value); |
---|
2903 | buf = ostrshrink(buf); |
---|
2904 | |
---|
2905 | return buf; |
---|
2906 | } |
---|
2907 | |
---|
2908 | char* oitoax(int value) |
---|
2909 | { |
---|
2910 | char *buf = NULL; |
---|
2911 | |
---|
2912 | buf = malloc(MINMALLOC); |
---|
2913 | if(buf == NULL) |
---|
2914 | { |
---|
2915 | err("no mem"); |
---|
2916 | return NULL; |
---|
2917 | } |
---|
2918 | |
---|
2919 | sprintf(buf, "%x", value); |
---|
2920 | buf = ostrshrink(buf); |
---|
2921 | |
---|
2922 | return buf; |
---|
2923 | } |
---|
2924 | |
---|
2925 | char* oitoa(int value) |
---|
2926 | { |
---|
2927 | char *buf = NULL; |
---|
2928 | |
---|
2929 | buf = malloc(MINMALLOC); |
---|
2930 | if(buf == NULL) |
---|
2931 | { |
---|
2932 | err("no mem"); |
---|
2933 | return NULL; |
---|
2934 | } |
---|
2935 | |
---|
2936 | sprintf(buf, "%d", value); |
---|
2937 | buf = ostrshrink(buf); |
---|
2938 | |
---|
2939 | return buf; |
---|
2940 | } |
---|
2941 | |
---|
2942 | char* oitoa64(off64_t value) |
---|
2943 | { |
---|
2944 | char *buf = NULL; |
---|
2945 | |
---|
2946 | buf = malloc(MINMALLOC); |
---|
2947 | if(buf == NULL) |
---|
2948 | { |
---|
2949 | err("no mem"); |
---|
2950 | return NULL; |
---|
2951 | } |
---|
2952 | |
---|
2953 | sprintf(buf, "%lld", value); |
---|
2954 | buf = ostrshrink(buf); |
---|
2955 | |
---|
2956 | return buf; |
---|
2957 | } |
---|
2958 | |
---|
2959 | char* oftoa64(double value, char* count) |
---|
2960 | { |
---|
2961 | char *buf = NULL; |
---|
2962 | char* tmpstr = NULL; |
---|
2963 | |
---|
2964 | buf = malloc(MINMALLOC); |
---|
2965 | if(buf == NULL) |
---|
2966 | { |
---|
2967 | err("no mem"); |
---|
2968 | return NULL; |
---|
2969 | } |
---|
2970 | |
---|
2971 | tmpstr = ostrcat("%.", count, 0, 0); |
---|
2972 | tmpstr = ostrcat(tmpstr, "f", 1, 0); |
---|
2973 | |
---|
2974 | sprintf(buf, tmpstr, value); |
---|
2975 | buf = ostrshrink(buf); |
---|
2976 | |
---|
2977 | free(tmpstr); |
---|
2978 | return buf; |
---|
2979 | } |
---|
2980 | |
---|
2981 | int ostrncmp(char* value1, char* value2, int count) |
---|
2982 | { |
---|
2983 | int ret = 1; |
---|
2984 | |
---|
2985 | if(value1 != NULL && value2 != NULL) |
---|
2986 | ret = strncmp(value1, value2, count); |
---|
2987 | |
---|
2988 | return ret; |
---|
2989 | } |
---|
2990 | |
---|
2991 | int ostrcmp(char* value1, char* value2) |
---|
2992 | { |
---|
2993 | int ret = 1; |
---|
2994 | |
---|
2995 | if(value1 != NULL && value2 != NULL) |
---|
2996 | ret = strcmp(value1, value2); |
---|
2997 | |
---|
2998 | return ret; |
---|
2999 | } |
---|
3000 | |
---|
3001 | int ostrcasecmp(char* value1, char* value2) |
---|
3002 | { |
---|
3003 | int ret = 1; |
---|
3004 | |
---|
3005 | if(value1 != NULL && value2 != NULL) |
---|
3006 | ret = strcasecmp(value1, value2); |
---|
3007 | |
---|
3008 | return ret; |
---|
3009 | } |
---|
3010 | |
---|
3011 | char* createpath(char* dir, char* file) |
---|
3012 | { |
---|
3013 | char *absdir = NULL; |
---|
3014 | char *pos = NULL; |
---|
3015 | char* tmpdir = NULL; |
---|
3016 | |
---|
3017 | if(dir == NULL || file == NULL) |
---|
3018 | { |
---|
3019 | err("NULL detect"); |
---|
3020 | return NULL; |
---|
3021 | } |
---|
3022 | |
---|
3023 | tmpdir = ostrcat(dir, NULL, 0, 0); |
---|
3024 | if(tmpdir == NULL) |
---|
3025 | { |
---|
3026 | err("NULL detect"); |
---|
3027 | return NULL; |
---|
3028 | } |
---|
3029 | |
---|
3030 | while((tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] != '.') || tmpdir[strlen(tmpdir) - 1] == '/') |
---|
3031 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
3032 | |
---|
3033 | while(tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] == '.') |
---|
3034 | { |
---|
3035 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
3036 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
3037 | if(tmpdir[strlen(tmpdir) - 1] == '/') |
---|
3038 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
3039 | pos = strrchr(tmpdir, '/'); |
---|
3040 | if(pos != NULL) |
---|
3041 | pos[0] = '\0'; |
---|
3042 | } |
---|
3043 | |
---|
3044 | absdir = malloc(strlen(tmpdir) + strlen(file) + 2); |
---|
3045 | if(absdir == NULL) |
---|
3046 | { |
---|
3047 | free(tmpdir); |
---|
3048 | err("no mem"); |
---|
3049 | return NULL; |
---|
3050 | } |
---|
3051 | |
---|
3052 | if(strlen(file) > 0 || strlen(tmpdir) == 0) |
---|
3053 | sprintf(absdir, "%s/%s", tmpdir, file); |
---|
3054 | else |
---|
3055 | sprintf(absdir, "%s", tmpdir); |
---|
3056 | |
---|
3057 | free(tmpdir); |
---|
3058 | return absdir; |
---|
3059 | } |
---|
3060 | |
---|
3061 | int settimezone(char* zone) |
---|
3062 | { |
---|
3063 | int ret = 0; |
---|
3064 | char* tmpzone = NULL, *zonepath = NULL; |
---|
3065 | |
---|
3066 | zonepath = getconfig("zonepath", NULL); |
---|
3067 | if(zonepath == NULL) |
---|
3068 | { |
---|
3069 | err("config zonepath not defined"); |
---|
3070 | return 1; |
---|
3071 | } |
---|
3072 | |
---|
3073 | tmpzone = createpath(zonepath, zone); |
---|
3074 | if(tmpzone == NULL) |
---|
3075 | return 1; |
---|
3076 | |
---|
3077 | setenv("TZ", zone, 1); |
---|
3078 | |
---|
3079 | ret = unlink(getconfig("localtimefile", NULL)); |
---|
3080 | if(ret != 0) |
---|
3081 | perr("unlink"); |
---|
3082 | ret = symlink(tmpzone, getconfig("localtimefile", NULL)); |
---|
3083 | if(ret != 0) |
---|
3084 | perr("link"); |
---|
3085 | |
---|
3086 | free(tmpzone); |
---|
3087 | return ret; |
---|
3088 | } |
---|
3089 | |
---|
3090 | int delchar(char** text, int pos) |
---|
3091 | { |
---|
3092 | char *tmptext = NULL; |
---|
3093 | int i = 0, y = 0, len = 0; |
---|
3094 | |
---|
3095 | if(text == NULL || *text == NULL) |
---|
3096 | return pos; |
---|
3097 | |
---|
3098 | len = strlen(*text); |
---|
3099 | if(len == 0) return pos; |
---|
3100 | |
---|
3101 | tmptext = malloc(strlen(*text)); |
---|
3102 | if(tmptext == NULL) |
---|
3103 | { |
---|
3104 | err("no mem"); |
---|
3105 | return pos; |
---|
3106 | } |
---|
3107 | |
---|
3108 | for(i = 0; i < strlen(*text); i++) |
---|
3109 | { |
---|
3110 | if(i == pos - 1) |
---|
3111 | y++; |
---|
3112 | |
---|
3113 | tmptext[i] = (*text)[y]; |
---|
3114 | y++; |
---|
3115 | } |
---|
3116 | |
---|
3117 | if(i > 0) tmptext[i - 1] = '\0'; |
---|
3118 | if(pos >= strlen(tmptext)) pos = strlen(tmptext); |
---|
3119 | |
---|
3120 | free(*text); |
---|
3121 | *text = tmptext; |
---|
3122 | return pos; |
---|
3123 | } |
---|
3124 | |
---|
3125 | |
---|
3126 | int insertchar(char** text, char zeichen, int pos) |
---|
3127 | { |
---|
3128 | char *tmptext = NULL; |
---|
3129 | int i, y = 0; |
---|
3130 | |
---|
3131 | if(text == NULL || *text == NULL) |
---|
3132 | return pos; |
---|
3133 | |
---|
3134 | tmptext = malloc(strlen(*text) + 2); |
---|
3135 | if(tmptext == NULL) |
---|
3136 | { |
---|
3137 | err("no mem"); |
---|
3138 | return pos; |
---|
3139 | } |
---|
3140 | |
---|
3141 | if(strlen(*text) == 0) |
---|
3142 | { |
---|
3143 | tmptext[0] = zeichen; |
---|
3144 | i = 1; |
---|
3145 | pos = 0; |
---|
3146 | } |
---|
3147 | else |
---|
3148 | { |
---|
3149 | for(i = 0; i < strlen(*text) + 1; i++) |
---|
3150 | { |
---|
3151 | if(i == pos) |
---|
3152 | tmptext[i] = zeichen; |
---|
3153 | else |
---|
3154 | { |
---|
3155 | tmptext[i] = (*text)[y]; |
---|
3156 | y++; |
---|
3157 | } |
---|
3158 | } |
---|
3159 | } |
---|
3160 | tmptext[i] = '\0'; |
---|
3161 | |
---|
3162 | free(*text); |
---|
3163 | *text = tmptext; |
---|
3164 | return pos + 1; |
---|
3165 | } |
---|
3166 | |
---|
3167 | void calctext(char* buf, char* buf1, unsigned int* linecount, unsigned int* pagecount, unsigned int* poscount, int pagelen, int page) |
---|
3168 | { |
---|
3169 | unsigned int tmpposcount = 0; |
---|
3170 | unsigned int pagepagelen = 0; |
---|
3171 | |
---|
3172 | *poscount = 0; |
---|
3173 | *linecount = 1; |
---|
3174 | *pagecount = 1; |
---|
3175 | |
---|
3176 | page--; |
---|
3177 | if(page < 0) page = 0; |
---|
3178 | pagepagelen = pagelen * page; |
---|
3179 | |
---|
3180 | if(buf != NULL) |
---|
3181 | { |
---|
3182 | while(*buf != '\0') |
---|
3183 | { |
---|
3184 | if(*buf == '\n') |
---|
3185 | { |
---|
3186 | if(*(buf + 1) == '\0') break; |
---|
3187 | (*linecount)++; |
---|
3188 | |
---|
3189 | if(*linecount - 1 == pagepagelen) |
---|
3190 | *poscount = tmpposcount + 1; |
---|
3191 | } |
---|
3192 | buf++; |
---|
3193 | tmpposcount++; |
---|
3194 | } |
---|
3195 | } |
---|
3196 | |
---|
3197 | if(buf1 != NULL) |
---|
3198 | { |
---|
3199 | while(*buf1 != '\0') |
---|
3200 | { |
---|
3201 | if(*buf1 == '\n') |
---|
3202 | { |
---|
3203 | if(*(buf1 + 1) == '\0') break; |
---|
3204 | (*linecount)++; |
---|
3205 | |
---|
3206 | if(*linecount - 1 == pagepagelen) |
---|
3207 | *poscount = tmpposcount + 1; |
---|
3208 | } |
---|
3209 | buf1++; |
---|
3210 | tmpposcount++; |
---|
3211 | } |
---|
3212 | } |
---|
3213 | |
---|
3214 | if(pagelen > 0) |
---|
3215 | *pagecount = (int)ceil(((float)*linecount / pagelen)); |
---|
3216 | } |
---|
3217 | |
---|
3218 | int initlocale(char *localepath) |
---|
3219 | { |
---|
3220 | setlocale(LC_ALL, ""); |
---|
3221 | if(bindtextdomain(PROGNAME, localepath) == NULL) |
---|
3222 | { |
---|
3223 | err("set bindtextdomain"); |
---|
3224 | return 1; |
---|
3225 | } |
---|
3226 | if(textdomain(PROGNAME) == NULL) |
---|
3227 | { |
---|
3228 | err("set textdomain"); |
---|
3229 | return 1; |
---|
3230 | } |
---|
3231 | return 0; |
---|
3232 | } |
---|
3233 | |
---|
3234 | //for langage you must |
---|
3235 | //mkdir /usr/lib/locale |
---|
3236 | //ln -s %titanpath%/po /usr/lib/locale/po |
---|
3237 | //copy SYS_LC_MESSAGES from other language into LC_MESSAGE |
---|
3238 | int setlang(char *lang) |
---|
3239 | { |
---|
3240 | char *ret; |
---|
3241 | |
---|
3242 | setenv("LANG", lang, 1); |
---|
3243 | setenv("LANGUAGE", lang, 1); |
---|
3244 | ret = setlocale(LC_MESSAGES, lang); |
---|
3245 | if(ret == NULL) |
---|
3246 | { |
---|
3247 | err("can't set LC_MESSAGES to %s", lang); |
---|
3248 | return 1; |
---|
3249 | } |
---|
3250 | return 0; |
---|
3251 | } |
---|
3252 | |
---|
3253 | unsigned long readsysul(const char *filename, int line) |
---|
3254 | { |
---|
3255 | int i = 0, len = 0; |
---|
3256 | unsigned long ret = 0; |
---|
3257 | FILE *fd = NULL; |
---|
3258 | char *fileline = NULL; |
---|
3259 | char *buf1 = NULL; |
---|
3260 | |
---|
3261 | fileline = malloc(MINMALLOC); |
---|
3262 | if(fileline == NULL) |
---|
3263 | { |
---|
3264 | err("no mem"); |
---|
3265 | return 0; |
---|
3266 | } |
---|
3267 | |
---|
3268 | fd = fopen(filename, "r"); |
---|
3269 | if(fd == NULL) |
---|
3270 | { |
---|
3271 | perr("can't open %s", filename); |
---|
3272 | free(fileline); |
---|
3273 | return 0; |
---|
3274 | } |
---|
3275 | |
---|
3276 | for(i = 0; i < line; i++) |
---|
3277 | { |
---|
3278 | memset(fileline, 0, MINMALLOC); |
---|
3279 | fgets(fileline, MINMALLOC, fd); |
---|
3280 | } |
---|
3281 | |
---|
3282 | len = strlen(fileline) - 1; |
---|
3283 | if(len >= 0 && fileline[len] == '\n') |
---|
3284 | fileline[len] = '\0'; |
---|
3285 | buf1 = ostrshrink(fileline); |
---|
3286 | |
---|
3287 | fclose(fd); |
---|
3288 | |
---|
3289 | if(buf1 != NULL) |
---|
3290 | { |
---|
3291 | ret = strtoul(buf1, NULL, 10); |
---|
3292 | free(buf1); buf1 = NULL; |
---|
3293 | } |
---|
3294 | |
---|
3295 | return ret; |
---|
3296 | } |
---|
3297 | |
---|
3298 | unsigned long long readsysull(const char *filename, int line) |
---|
3299 | { |
---|
3300 | int i = 0, len = 0; |
---|
3301 | unsigned long long ret = 0; |
---|
3302 | FILE *fd = NULL; |
---|
3303 | char *fileline = NULL; |
---|
3304 | char *buf1 = NULL; |
---|
3305 | |
---|
3306 | fileline = malloc(MINMALLOC); |
---|
3307 | if(fileline == NULL) |
---|
3308 | { |
---|
3309 | err("no mem"); |
---|
3310 | return 0; |
---|
3311 | } |
---|
3312 | |
---|
3313 | fd = fopen(filename, "r"); |
---|
3314 | if(fd == NULL) |
---|
3315 | { |
---|
3316 | perr("can't open %s", filename); |
---|
3317 | free(fileline); |
---|
3318 | return 0; |
---|
3319 | } |
---|
3320 | |
---|
3321 | for(i = 0; i < line; i++) |
---|
3322 | { |
---|
3323 | memset(fileline, 0, MINMALLOC); |
---|
3324 | fgets(fileline, MINMALLOC, fd); |
---|
3325 | } |
---|
3326 | |
---|
3327 | len = strlen(fileline) - 1; |
---|
3328 | if(len >= 0 && fileline[len] == '\n') |
---|
3329 | fileline[len] = '\0'; |
---|
3330 | buf1 = ostrshrink(fileline); |
---|
3331 | |
---|
3332 | fclose(fd); |
---|
3333 | |
---|
3334 | if(buf1 != NULL) |
---|
3335 | { |
---|
3336 | ret = strtoull(buf1, NULL, 10); |
---|
3337 | free(buf1); buf1 = NULL; |
---|
3338 | } |
---|
3339 | |
---|
3340 | return ret; |
---|
3341 | } |
---|
3342 | |
---|
3343 | char* readsys(const char *filename, int line) |
---|
3344 | { |
---|
3345 | int i = 0, len = 0; |
---|
3346 | FILE *fd = NULL; |
---|
3347 | char *fileline = NULL; |
---|
3348 | char *buf1 = NULL; |
---|
3349 | |
---|
3350 | fileline = malloc(MINMALLOC); |
---|
3351 | if(fileline == NULL) |
---|
3352 | { |
---|
3353 | err("no mem"); |
---|
3354 | return NULL; |
---|
3355 | } |
---|
3356 | |
---|
3357 | fd = fopen(filename, "r"); |
---|
3358 | if(fd == NULL) |
---|
3359 | { |
---|
3360 | perr("can't open %s", filename); |
---|
3361 | free(fileline); |
---|
3362 | return NULL; |
---|
3363 | } |
---|
3364 | |
---|
3365 | for(i = 0; i < line; i++) |
---|
3366 | { |
---|
3367 | memset(fileline, 0, MINMALLOC); |
---|
3368 | fgets(fileline, MINMALLOC, fd); |
---|
3369 | } |
---|
3370 | |
---|
3371 | len = strlen(fileline) - 1; |
---|
3372 | if(len >= 0 && fileline[len] == '\n') |
---|
3373 | fileline[len] = '\0'; |
---|
3374 | buf1 = ostrshrink(fileline); |
---|
3375 | |
---|
3376 | fclose(fd); |
---|
3377 | return buf1; |
---|
3378 | } |
---|
3379 | |
---|
3380 | //flag 0: without \n |
---|
3381 | //flag 1: with \n |
---|
3382 | //flag 2: append without \n |
---|
3383 | //flag 3: append with \n |
---|
3384 | int writesys(const char *filename, char *value, int flag) |
---|
3385 | { |
---|
3386 | FILE *fd = NULL; |
---|
3387 | char* tmpstr = NULL; |
---|
3388 | int ret; |
---|
3389 | |
---|
3390 | if(value == NULL) |
---|
3391 | { |
---|
3392 | err("NULL detect"); |
---|
3393 | return 1; |
---|
3394 | } |
---|
3395 | |
---|
3396 | if(flag == 2 || flag == 3) |
---|
3397 | fd = fopen(filename, "a"); |
---|
3398 | else |
---|
3399 | fd = fopen(filename, "w"); |
---|
3400 | if(fd == NULL) |
---|
3401 | { |
---|
3402 | perr("can't open %s", filename); |
---|
3403 | return 1; |
---|
3404 | } |
---|
3405 | |
---|
3406 | if(flag == 1 || flag == 3) |
---|
3407 | tmpstr = ostrcat(value, "\n", 0, 0); |
---|
3408 | else |
---|
3409 | tmpstr = ostrcat(value, NULL, 0, 0); |
---|
3410 | |
---|
3411 | ret = fwrite(tmpstr, strlen(tmpstr), 1, fd); |
---|
3412 | if(ret != 1) |
---|
3413 | { |
---|
3414 | perr("writting to %s", filename); |
---|
3415 | free(tmpstr); |
---|
3416 | fclose(fd); |
---|
3417 | return 1; |
---|
3418 | } |
---|
3419 | |
---|
3420 | free(tmpstr); |
---|
3421 | fclose(fd); |
---|
3422 | return 0; |
---|
3423 | } |
---|
3424 | |
---|
3425 | //flag 0: without \n |
---|
3426 | //flag 1: with \n |
---|
3427 | //flag 2: append without \n |
---|
3428 | //flag 3: append with \n |
---|
3429 | int writesysint(const char *filename, int value, int flag) |
---|
3430 | { |
---|
3431 | char* tmpstr = NULL; |
---|
3432 | int ret = 0; |
---|
3433 | |
---|
3434 | tmpstr = oitoa(value); |
---|
3435 | ret = writesys(filename, tmpstr, flag); |
---|
3436 | |
---|
3437 | free(tmpstr); |
---|
3438 | return ret; |
---|
3439 | } |
---|
3440 | |
---|
3441 | char* getdevcontent(char* devconfig) |
---|
3442 | { |
---|
3443 | char *dev = NULL; |
---|
3444 | char *value = NULL; |
---|
3445 | |
---|
3446 | dev = getconfig(devconfig, NULL); |
---|
3447 | |
---|
3448 | if(dev == NULL) |
---|
3449 | { |
---|
3450 | err("NULL detect"); |
---|
3451 | return NULL; |
---|
3452 | } |
---|
3453 | |
---|
3454 | value = readsys(dev, 1); |
---|
3455 | if(value == NULL) |
---|
3456 | { |
---|
3457 | err("NULL detect"); |
---|
3458 | return NULL; |
---|
3459 | } |
---|
3460 | |
---|
3461 | return value; |
---|
3462 | } |
---|
3463 | |
---|
3464 | char* convertspacetolf(char* value) |
---|
3465 | { |
---|
3466 | int i = 0; |
---|
3467 | |
---|
3468 | while(value[i] != '\0') |
---|
3469 | { |
---|
3470 | if(value[i] == ' ') |
---|
3471 | value[i] = '\n'; |
---|
3472 | i++; |
---|
3473 | } |
---|
3474 | |
---|
3475 | return value; |
---|
3476 | } |
---|
3477 | |
---|
3478 | //flag 0: all |
---|
3479 | //flag 1: hdmi |
---|
3480 | //flag 2: not hdmi |
---|
3481 | char* getcolorformatchoices(int flag) |
---|
3482 | { |
---|
3483 | char *colorformatchoicesdev = NULL; |
---|
3484 | char *value = NULL; |
---|
3485 | |
---|
3486 | colorformatchoicesdev = getconfig("colorformatchoicesdev", NULL); |
---|
3487 | |
---|
3488 | if(colorformatchoicesdev == NULL) |
---|
3489 | { |
---|
3490 | err("NULL detect"); |
---|
3491 | return NULL; |
---|
3492 | } |
---|
3493 | |
---|
3494 | value = readsys(colorformatchoicesdev, 1); |
---|
3495 | if(value == NULL) |
---|
3496 | { |
---|
3497 | err("NULL detect"); |
---|
3498 | return NULL; |
---|
3499 | } |
---|
3500 | |
---|
3501 | if(flag == 1) |
---|
3502 | { |
---|
3503 | value = string_replace("rgb", NULL, value, 1); |
---|
3504 | value = string_replace(" ", " ", value, 1); |
---|
3505 | value = string_replace("cvbs", NULL, value, 1); |
---|
3506 | value = string_replace(" ", " ", value, 1); |
---|
3507 | value = string_replace("svideo", NULL, value, 1); |
---|
3508 | value = string_replace(" ", " ", value, 1); |
---|
3509 | value = string_replace("yuv", NULL, value, 1); |
---|
3510 | value = string_replace(" ", " ", value, 1); |
---|
3511 | } |
---|
3512 | else if(flag == 2) |
---|
3513 | { |
---|
3514 | value = string_replace("hdmi_rgb", NULL, value, 1); |
---|
3515 | value = string_replace(" ", " ", value, 1); |
---|
3516 | value = string_replace("hdmi_yuv", NULL, value, 1); |
---|
3517 | value = string_replace(" ", " ", value, 1); |
---|
3518 | value = string_replace("hdmi_422", NULL, value, 1); |
---|
3519 | value = string_replace(" ", " ", value, 1); |
---|
3520 | } |
---|
3521 | |
---|
3522 | value = strstrip(value); |
---|
3523 | value = convertspacetolf(value); |
---|
3524 | |
---|
3525 | return value; |
---|
3526 | } |
---|
3527 | |
---|
3528 | char* getaudiosourcechoices() |
---|
3529 | { |
---|
3530 | char *audiosourcechoicesdev = NULL; |
---|
3531 | char *value = NULL; |
---|
3532 | |
---|
3533 | audiosourcechoicesdev = getconfig("audiosourcechoicesdev", NULL); |
---|
3534 | |
---|
3535 | if(audiosourcechoicesdev == NULL) |
---|
3536 | { |
---|
3537 | err("NULL detect"); |
---|
3538 | return NULL; |
---|
3539 | } |
---|
3540 | |
---|
3541 | value = readsys(audiosourcechoicesdev, 1); |
---|
3542 | if(value == NULL) |
---|
3543 | { |
---|
3544 | err("NULL detect"); |
---|
3545 | return NULL; |
---|
3546 | } |
---|
3547 | |
---|
3548 | value = convertspacetolf(value); |
---|
3549 | |
---|
3550 | return value; |
---|
3551 | } |
---|
3552 | |
---|
3553 | char* getac3choices() |
---|
3554 | { |
---|
3555 | char *ac3choicesdev = NULL; |
---|
3556 | char *value = NULL; |
---|
3557 | |
---|
3558 | ac3choicesdev = getconfig("ac3choicesdev", NULL); |
---|
3559 | |
---|
3560 | if(ac3choicesdev == NULL) |
---|
3561 | { |
---|
3562 | err("NULL detect"); |
---|
3563 | return NULL; |
---|
3564 | } |
---|
3565 | |
---|
3566 | value = readsys(ac3choicesdev, 1); |
---|
3567 | if(value == NULL) |
---|
3568 | { |
---|
3569 | err("NULL detect"); |
---|
3570 | return NULL; |
---|
3571 | } |
---|
3572 | |
---|
3573 | value = convertspacetolf(value); |
---|
3574 | |
---|
3575 | return value; |
---|
3576 | } |
---|
3577 | |
---|
3578 | char* getaacchoices() |
---|
3579 | { |
---|
3580 | char *aacchoicesdev = NULL; |
---|
3581 | char *value = NULL; |
---|
3582 | |
---|
3583 | aacchoicesdev = getconfig("aacchoicesdev", NULL); |
---|
3584 | |
---|
3585 | if(aacchoicesdev == NULL) |
---|
3586 | { |
---|
3587 | err("NULL detect"); |
---|
3588 | return NULL; |
---|
3589 | } |
---|
3590 | |
---|
3591 | value = readsys(aacchoicesdev, 1); |
---|
3592 | if(value == NULL) |
---|
3593 | { |
---|
3594 | err("NULL detect"); |
---|
3595 | return NULL; |
---|
3596 | } |
---|
3597 | |
---|
3598 | value = convertspacetolf(value); |
---|
3599 | |
---|
3600 | return value; |
---|
3601 | } |
---|
3602 | |
---|
3603 | char* getwsschoices() |
---|
3604 | { |
---|
3605 | char *wsschoicesdev = NULL; |
---|
3606 | char *value = NULL; |
---|
3607 | |
---|
3608 | wsschoicesdev = getconfig("wsschoicesdev", NULL); |
---|
3609 | |
---|
3610 | if(wsschoicesdev == NULL) |
---|
3611 | { |
---|
3612 | err("NULL detect"); |
---|
3613 | return NULL; |
---|
3614 | } |
---|
3615 | |
---|
3616 | value = readsys(wsschoicesdev, 1); |
---|
3617 | if(value == NULL) |
---|
3618 | { |
---|
3619 | err("NULL detect"); |
---|
3620 | return NULL; |
---|
3621 | } |
---|
3622 | |
---|
3623 | value = convertspacetolf(value); |
---|
3624 | |
---|
3625 | return value; |
---|
3626 | } |
---|
3627 | |
---|
3628 | int setciclock(int slotnr, char* value) |
---|
3629 | { |
---|
3630 | char* ciclockdev = NULL, *tmpstr = NULL; |
---|
3631 | int ret = 0; |
---|
3632 | |
---|
3633 | ciclockdev = getconfig("ciclockdev", NULL); |
---|
3634 | |
---|
3635 | if(ciclockdev != NULL && value != NULL) |
---|
3636 | { |
---|
3637 | tmpstr = malloc(MINMALLOC); |
---|
3638 | if(tmpstr == NULL) |
---|
3639 | { |
---|
3640 | err("no mem"); |
---|
3641 | return 1; |
---|
3642 | } |
---|
3643 | |
---|
3644 | snprintf(tmpstr, MINMALLOC, ciclockdev, slotnr); |
---|
3645 | debug(100, "set %s to %s", tmpstr, value); |
---|
3646 | ret = writesys(tmpstr, value, 0); |
---|
3647 | |
---|
3648 | free(tmpstr); tmpstr = NULL; |
---|
3649 | return ret; |
---|
3650 | } |
---|
3651 | |
---|
3652 | return 0; |
---|
3653 | } |
---|
3654 | |
---|
3655 | //routes stream from tuner to ci or ci to ci |
---|
3656 | int setciinput(int slotnr, char* value) |
---|
3657 | { |
---|
3658 | char* ciinputdev = NULL, *tmpstr = NULL; |
---|
3659 | int ret = 0; |
---|
3660 | |
---|
3661 | ciinputdev = getconfig("ciinputdev", NULL); |
---|
3662 | |
---|
3663 | if(ciinputdev != NULL && value != NULL) |
---|
3664 | { |
---|
3665 | tmpstr = malloc(MINMALLOC); |
---|
3666 | if(tmpstr == NULL) |
---|
3667 | { |
---|
3668 | err("no mem"); |
---|
3669 | return 1; |
---|
3670 | } |
---|
3671 | |
---|
3672 | snprintf(tmpstr, MINMALLOC, ciinputdev, slotnr); |
---|
3673 | debug(100, "set %s to %s", tmpstr, value); |
---|
3674 | ret = writesys(tmpstr, value, 0); |
---|
3675 | |
---|
3676 | free(tmpstr); tmpstr = NULL; |
---|
3677 | return ret; |
---|
3678 | } |
---|
3679 | |
---|
3680 | return 0; |
---|
3681 | } |
---|
3682 | |
---|
3683 | //routes stream from tuner or ci to linux |
---|
3684 | int setcisource(int tunernr, char* value) |
---|
3685 | { |
---|
3686 | char* cisourcedev = NULL, *tmpstr = NULL; |
---|
3687 | int ret = 0; |
---|
3688 | |
---|
3689 | cisourcedev = getconfig("cisourcedev", NULL); |
---|
3690 | |
---|
3691 | if(cisourcedev != NULL && value != NULL) |
---|
3692 | { |
---|
3693 | tmpstr = malloc(MINMALLOC); |
---|
3694 | if(tmpstr == NULL) |
---|
3695 | { |
---|
3696 | err("no mem"); |
---|
3697 | return 1; |
---|
3698 | } |
---|
3699 | |
---|
3700 | snprintf(tmpstr, MINMALLOC, cisourcedev, tunernr); |
---|
3701 | debug(100, "set %s to %s", tmpstr, value); |
---|
3702 | ret = writesys(tmpstr, value, 0); |
---|
3703 | |
---|
3704 | free(tmpstr); tmpstr = NULL; |
---|
3705 | return ret; |
---|
3706 | } |
---|
3707 | |
---|
3708 | return 0; |
---|
3709 | } |
---|
3710 | |
---|
3711 | int setinput(char* value) |
---|
3712 | { |
---|
3713 | char* inputdev = NULL; |
---|
3714 | int ret = 0; |
---|
3715 | |
---|
3716 | inputdev = getconfig("inputdev", NULL); |
---|
3717 | |
---|
3718 | if(inputdev != NULL && value != NULL) |
---|
3719 | { |
---|
3720 | debug(100, "set %s to %s", inputdev, value); |
---|
3721 | ret = writesys(inputdev, value, 0); |
---|
3722 | return ret; |
---|
3723 | } |
---|
3724 | |
---|
3725 | return 0; |
---|
3726 | } |
---|
3727 | |
---|
3728 | char* getinput() |
---|
3729 | { |
---|
3730 | char *inputdev = NULL; |
---|
3731 | char *value = NULL; |
---|
3732 | |
---|
3733 | inputdev = getconfig("inputdev", NULL); |
---|
3734 | |
---|
3735 | if(inputdev == NULL) |
---|
3736 | { |
---|
3737 | err("NULL detect"); |
---|
3738 | return NULL; |
---|
3739 | } |
---|
3740 | |
---|
3741 | value = readsys(inputdev, 1); |
---|
3742 | if(value == NULL) |
---|
3743 | { |
---|
3744 | err("NULL detect"); |
---|
3745 | return NULL; |
---|
3746 | } |
---|
3747 | |
---|
3748 | return value; |
---|
3749 | } |
---|
3750 | |
---|
3751 | int setac3(char* value) |
---|
3752 | { |
---|
3753 | char* ac3dev = NULL; |
---|
3754 | int ret = 0; |
---|
3755 | |
---|
3756 | ac3dev = getconfig("ac3dev", NULL); |
---|
3757 | |
---|
3758 | if(ac3dev != NULL && value != NULL) |
---|
3759 | { |
---|
3760 | debug(100, "set %s to %s", ac3dev, value); |
---|
3761 | ret = writesys(ac3dev, value, 0); |
---|
3762 | if(ret == 0) addconfig("av_ac3mode", value); |
---|
3763 | return ret; |
---|
3764 | } |
---|
3765 | |
---|
3766 | return 0; |
---|
3767 | } |
---|
3768 | |
---|
3769 | int setaac(char* value) |
---|
3770 | { |
---|
3771 | char* aacdev = NULL; |
---|
3772 | int ret = 0; |
---|
3773 | |
---|
3774 | aacdev = getconfig("aacdev", NULL); |
---|
3775 | |
---|
3776 | if(aacdev != NULL && value != NULL) |
---|
3777 | { |
---|
3778 | debug(100, "set %s to %s", aacdev, value); |
---|
3779 | ret = writesys(aacdev, value, 0); |
---|
3780 | if(ret == 0) addconfig("av_aacmode", value); |
---|
3781 | return ret; |
---|
3782 | } |
---|
3783 | |
---|
3784 | return 0; |
---|
3785 | } |
---|
3786 | |
---|
3787 | int setwss(char* value) |
---|
3788 | { |
---|
3789 | char* wssdev = NULL; |
---|
3790 | int ret = 0; |
---|
3791 | |
---|
3792 | wssdev = getconfig("wssdev", NULL); |
---|
3793 | |
---|
3794 | if(wssdev != NULL && value != NULL) |
---|
3795 | { |
---|
3796 | debug(100, "set %s to %s", wssdev, value); |
---|
3797 | ret = writesys(wssdev, value, 0); |
---|
3798 | if(ret == 0) addconfig("av_wssmode", value); |
---|
3799 | return ret; |
---|
3800 | } |
---|
3801 | else if(wssdev != NULL && value == NULL) |
---|
3802 | { |
---|
3803 | debug(100, "set %s to %s", wssdev, "auto"); |
---|
3804 | ret = writesys(wssdev, "auto", 0); |
---|
3805 | return ret; |
---|
3806 | } |
---|
3807 | |
---|
3808 | return 0; |
---|
3809 | } |
---|
3810 | |
---|
3811 | char* getac3() |
---|
3812 | { |
---|
3813 | char *ac3dev = NULL; |
---|
3814 | char *value = NULL; |
---|
3815 | |
---|
3816 | ac3dev = getconfig("ac3dev", NULL); |
---|
3817 | |
---|
3818 | if(ac3dev == NULL) |
---|
3819 | { |
---|
3820 | err("NULL detect"); |
---|
3821 | return NULL; |
---|
3822 | } |
---|
3823 | |
---|
3824 | value = readsys(ac3dev, 1); |
---|
3825 | if(value == NULL) |
---|
3826 | { |
---|
3827 | err("NULL detect"); |
---|
3828 | return NULL; |
---|
3829 | } |
---|
3830 | |
---|
3831 | return value; |
---|
3832 | } |
---|
3833 | |
---|
3834 | char* getaac() |
---|
3835 | { |
---|
3836 | char *aacdev = NULL; |
---|
3837 | char *value = NULL; |
---|
3838 | |
---|
3839 | aacdev = getconfig("aacdev", NULL); |
---|
3840 | |
---|
3841 | if(aacdev == NULL) |
---|
3842 | { |
---|
3843 | err("NULL detect"); |
---|
3844 | return NULL; |
---|
3845 | } |
---|
3846 | |
---|
3847 | value = readsys(aacdev, 1); |
---|
3848 | if(value == NULL) |
---|
3849 | { |
---|
3850 | err("NULL detect"); |
---|
3851 | return NULL; |
---|
3852 | } |
---|
3853 | |
---|
3854 | return value; |
---|
3855 | } |
---|
3856 | |
---|
3857 | char* getwss() |
---|
3858 | { |
---|
3859 | char *wssdev = NULL; |
---|
3860 | char *value = NULL; |
---|
3861 | |
---|
3862 | wssdev = getconfig("wssdev", NULL); |
---|
3863 | |
---|
3864 | if(wssdev == NULL) |
---|
3865 | { |
---|
3866 | err("NULL detect"); |
---|
3867 | return NULL; |
---|
3868 | } |
---|
3869 | |
---|
3870 | value = readsys(wssdev, 1); |
---|
3871 | if(value == NULL) |
---|
3872 | { |
---|
3873 | err("NULL detect"); |
---|
3874 | return NULL; |
---|
3875 | } |
---|
3876 | |
---|
3877 | return value; |
---|
3878 | } |
---|
3879 | |
---|
3880 | int setaudiodelaybitstream(char* value) |
---|
3881 | { |
---|
3882 | char* audiodelaybitstreamdev = NULL; |
---|
3883 | int ret = 0; |
---|
3884 | |
---|
3885 | audiodelaybitstreamdev = getconfig("audiodelaybitstreamdev", NULL); |
---|
3886 | |
---|
3887 | if(audiodelaybitstreamdev != NULL && value != NULL) |
---|
3888 | { |
---|
3889 | debug(100, "set %s to %s", audiodelaybitstreamdev, value); |
---|
3890 | ret = writesys(audiodelaybitstreamdev, value, 0); |
---|
3891 | if(ret == 0) addconfig("audiodelaybitstream", value); |
---|
3892 | return ret; |
---|
3893 | } |
---|
3894 | |
---|
3895 | return 0; |
---|
3896 | } |
---|
3897 | |
---|
3898 | char* getaudiodelaybitstream() |
---|
3899 | { |
---|
3900 | char *audiodelaybitstreamdev = NULL; |
---|
3901 | char *value = NULL; |
---|
3902 | |
---|
3903 | audiodelaybitstreamdev = getconfig("audiodelaybitstreamdev", NULL); |
---|
3904 | |
---|
3905 | if(audiodelaybitstreamdev == NULL) |
---|
3906 | { |
---|
3907 | err("NULL detect"); |
---|
3908 | return NULL; |
---|
3909 | } |
---|
3910 | |
---|
3911 | value = readsys(audiodelaybitstreamdev, 1); |
---|
3912 | if(value == NULL) |
---|
3913 | { |
---|
3914 | err("NULL detect"); |
---|
3915 | return NULL; |
---|
3916 | } |
---|
3917 | |
---|
3918 | return value; |
---|
3919 | } |
---|
3920 | |
---|
3921 | char* getpolicychoices() |
---|
3922 | { |
---|
3923 | char *policychoicesdev = NULL; |
---|
3924 | char *value = NULL; |
---|
3925 | |
---|
3926 | policychoicesdev = getconfig("policychoicesdev", NULL); |
---|
3927 | |
---|
3928 | if(policychoicesdev == NULL) |
---|
3929 | { |
---|
3930 | err("NULL detect"); |
---|
3931 | return NULL; |
---|
3932 | } |
---|
3933 | |
---|
3934 | value = readsys(policychoicesdev, 1); |
---|
3935 | if(value == NULL) |
---|
3936 | { |
---|
3937 | err("NULL detect"); |
---|
3938 | return NULL; |
---|
3939 | } |
---|
3940 | |
---|
3941 | #ifdef MIPSEL |
---|
3942 | free(value), value = NULL; |
---|
3943 | // value = ostrcat("16:9_set_bestfit_to_policy_show_justscale 16:9_set_letterbox_to_policy_show_panscan 16:9_set_panscan_to_policy_show_pillarbox 4:3_set_bestfit_to_policy2_show_justscale 4:3_set_letterbox_to_policy2_show_letterbox 4:3_set_panscan_to_policy2_show_panscan", NULL, 0, 0); |
---|
3944 | |
---|
3945 | value = ostrcat(_("16:9_set_bestfit_to_policy_show_justscale"), NULL, 0, 0); |
---|
3946 | value = ostrcat(value, " ", 1, 0); |
---|
3947 | value = ostrcat(value, _("16:9_set_letterbox_to_policy_show_panscan"), 1, 0); |
---|
3948 | value = ostrcat(value, " ", 1, 0); |
---|
3949 | value = ostrcat(value, _("16:9_set_panscan_to_policy_show_pillarbox"), 1, 0); |
---|
3950 | value = ostrcat(value, " ", 1, 0); |
---|
3951 | value = ostrcat(value, _("4:3_set_bestfit_to_policy2_show_justscale"), 1, 0); |
---|
3952 | value = ostrcat(value, " ", 1, 0); |
---|
3953 | value = ostrcat(value, _("4:3_set_letterbox_to_policy2_show_letterbox"), 1, 0); |
---|
3954 | value = ostrcat(value, " ", 1, 0); |
---|
3955 | value = ostrcat(value, _("4:3_set_panscan_to_policy2_show_panscan"), 1, 0); |
---|
3956 | |
---|
3957 | #endif |
---|
3958 | |
---|
3959 | value = convertspacetolf(value); |
---|
3960 | |
---|
3961 | return value; |
---|
3962 | } |
---|
3963 | |
---|
3964 | char* getpolicy() |
---|
3965 | { |
---|
3966 | char *policydev = NULL; |
---|
3967 | char *value = NULL; |
---|
3968 | |
---|
3969 | policydev = getconfig("policydev", NULL); |
---|
3970 | |
---|
3971 | if(policydev == NULL) |
---|
3972 | { |
---|
3973 | err("NULL detect"); |
---|
3974 | return NULL; |
---|
3975 | } |
---|
3976 | |
---|
3977 | value = readsys(policydev, 1); |
---|
3978 | |
---|
3979 | #ifdef MIPSEL |
---|
3980 | char *aspect = NULL; |
---|
3981 | aspect = getaspect(); |
---|
3982 | if(!ostrncmp("16:9", aspect, 4)) |
---|
3983 | { |
---|
3984 | if(ostrcmp("bestfit", value) == 0) |
---|
3985 | { |
---|
3986 | free(value), value = NULL; |
---|
3987 | value = ostrcat("16:9_set_bestfit_to_policy_show_justscale", NULL, 0, 0); |
---|
3988 | } |
---|
3989 | else if(ostrcmp("letterbox", value) == 0) |
---|
3990 | { |
---|
3991 | free(value), value = NULL; |
---|
3992 | value = ostrcat("16:9_set_letterbox_to_policy_show_panscan", NULL, 0, 0); |
---|
3993 | } |
---|
3994 | else if(ostrcmp("panscan", value) == 0) |
---|
3995 | { |
---|
3996 | free(value), value = NULL; |
---|
3997 | value = ostrcat("16:9_set_panscan_to_policy_show_pillarbox", NULL, 0, 0); |
---|
3998 | } |
---|
3999 | } |
---|
4000 | else |
---|
4001 | { |
---|
4002 | policydev = getconfig("policy2dev", NULL); |
---|
4003 | value = readsys(policydev, 1); |
---|
4004 | |
---|
4005 | if(ostrcmp("bestfit", value) == 0) |
---|
4006 | { |
---|
4007 | free(value), value = NULL; |
---|
4008 | value = ostrcat("4:3_set_bestfit_to_policy2_show_justscale", NULL, 0, 0); |
---|
4009 | } |
---|
4010 | else if(ostrcmp("letterbox", value) == 0) |
---|
4011 | { |
---|
4012 | free(value), value = NULL; |
---|
4013 | value = ostrcat("4:3_set_letterbox_to_policy2_show_letterbox", NULL, 0, 0); |
---|
4014 | } |
---|
4015 | else if(ostrcmp("panscan", value) == 0) |
---|
4016 | { |
---|
4017 | free(value), value = NULL; |
---|
4018 | value = ostrcat("4:3_set_panscan_to_policy2_show_panscan", NULL, 0, 0); |
---|
4019 | } |
---|
4020 | } |
---|
4021 | free(aspect), aspect = NULL; |
---|
4022 | |
---|
4023 | #endif |
---|
4024 | |
---|
4025 | if(value == NULL) |
---|
4026 | { |
---|
4027 | err("NULL detect"); |
---|
4028 | return NULL; |
---|
4029 | } |
---|
4030 | |
---|
4031 | return value; |
---|
4032 | } |
---|
4033 | |
---|
4034 | int setpolicy(char* value) |
---|
4035 | { |
---|
4036 | char* policydev, *tmpstr = NULL; |
---|
4037 | int ret = 0; |
---|
4038 | |
---|
4039 | policydev = getconfig("policydev", NULL); |
---|
4040 | |
---|
4041 | if(policydev != NULL && value != NULL) |
---|
4042 | { |
---|
4043 | debug(10, "set %s to %s", policydev, value); |
---|
4044 | tmpstr = ostrcat(value, NULL, 0, 0); |
---|
4045 | |
---|
4046 | #ifdef MIPSEL |
---|
4047 | if(ostrcmp("16:9_set_bestfit_to_policy_show_justscale", tmpstr) == 0) |
---|
4048 | { |
---|
4049 | free(tmpstr), tmpstr = NULL; |
---|
4050 | tmpstr = ostrcat("bestfit", NULL, 0, 0); |
---|
4051 | setaspect("set_16:9"); |
---|
4052 | } |
---|
4053 | else if(ostrcmp("16:9_set_letterbox_to_policy_show_panscan", tmpstr) == 0) |
---|
4054 | { |
---|
4055 | free(tmpstr), tmpstr = NULL; |
---|
4056 | tmpstr = ostrcat("letterbox", NULL, 0, 0); |
---|
4057 | setaspect("set_16:9"); |
---|
4058 | } |
---|
4059 | else if(ostrcmp("16:9_set_panscan_to_policy_show_pillarbox", tmpstr) == 0) |
---|
4060 | { |
---|
4061 | free(tmpstr), tmpstr = NULL; |
---|
4062 | tmpstr = ostrcat("panscan", NULL, 0, 0); |
---|
4063 | setaspect("set_16:9"); |
---|
4064 | } |
---|
4065 | else if(ostrcmp("4:3_set_bestfit_to_policy2_show_justscale", tmpstr) == 0) |
---|
4066 | { |
---|
4067 | policydev = getconfig("policy2dev", NULL); |
---|
4068 | free(tmpstr), tmpstr = NULL; |
---|
4069 | tmpstr = ostrcat("bestfit", NULL, 0, 0); |
---|
4070 | setaspect("set_4:3"); |
---|
4071 | } |
---|
4072 | else if(ostrcmp("4:3_set_letterbox_to_policy2_show_letterbox", tmpstr) == 0) |
---|
4073 | { |
---|
4074 | policydev = getconfig("policy2dev", NULL); |
---|
4075 | free(tmpstr), tmpstr = NULL; |
---|
4076 | tmpstr = ostrcat("letterbox", NULL, 0, 0); |
---|
4077 | setaspect("set_4:3"); |
---|
4078 | } |
---|
4079 | else if(ostrcmp("4:3_set_panscan_to_policy2_show_panscan", tmpstr) == 0) |
---|
4080 | { |
---|
4081 | policydev = getconfig("policy2dev", NULL); |
---|
4082 | free(tmpstr), tmpstr = NULL; |
---|
4083 | tmpstr = ostrcat("panscan", NULL, 0, 0); |
---|
4084 | setaspect("set_4:3"); |
---|
4085 | } |
---|
4086 | #endif |
---|
4087 | debug(10, "set change %s to %s", policydev, tmpstr); |
---|
4088 | ret = writesys(policydev, tmpstr, 0); |
---|
4089 | |
---|
4090 | if(ret == 0) addconfig("av_policy", value); |
---|
4091 | |
---|
4092 | free(tmpstr), tmpstr = NULL; |
---|
4093 | return ret; |
---|
4094 | } |
---|
4095 | |
---|
4096 | return 0; |
---|
4097 | } |
---|
4098 | |
---|
4099 | char* getaspectchoices() |
---|
4100 | { |
---|
4101 | char *aspectchoicesdev = NULL; |
---|
4102 | char *value = NULL; |
---|
4103 | |
---|
4104 | aspectchoicesdev = getconfig("aspectchoicesdev", NULL); |
---|
4105 | |
---|
4106 | if(aspectchoicesdev == NULL) |
---|
4107 | { |
---|
4108 | err("NULL detect"); |
---|
4109 | return NULL; |
---|
4110 | } |
---|
4111 | |
---|
4112 | value = readsys(aspectchoicesdev, 1); |
---|
4113 | if(value == NULL) |
---|
4114 | { |
---|
4115 | err("NULL detect"); |
---|
4116 | return NULL; |
---|
4117 | } |
---|
4118 | |
---|
4119 | value = convertspacetolf(value); |
---|
4120 | |
---|
4121 | return value; |
---|
4122 | } |
---|
4123 | |
---|
4124 | char* getaspect() |
---|
4125 | { |
---|
4126 | char *aspectdev = NULL; |
---|
4127 | char *value = NULL; |
---|
4128 | |
---|
4129 | aspectdev = getconfig("aspectdev", NULL); |
---|
4130 | |
---|
4131 | if(aspectdev == NULL) |
---|
4132 | { |
---|
4133 | err("NULL detect"); |
---|
4134 | return NULL; |
---|
4135 | } |
---|
4136 | |
---|
4137 | value = readsys(aspectdev, 1); |
---|
4138 | if(value == NULL) |
---|
4139 | { |
---|
4140 | err("NULL detect"); |
---|
4141 | return NULL; |
---|
4142 | } |
---|
4143 | |
---|
4144 | return value; |
---|
4145 | } |
---|
4146 | |
---|
4147 | int setaspect(char* value) |
---|
4148 | { |
---|
4149 | char* aspectdev; |
---|
4150 | int ret = 0; |
---|
4151 | |
---|
4152 | aspectdev = getconfig("aspectdev", NULL); |
---|
4153 | |
---|
4154 | if(aspectdev != NULL && value != NULL) |
---|
4155 | { |
---|
4156 | debug(10, "set %s to %s", aspectdev, value); |
---|
4157 | |
---|
4158 | if(!ostrncmp("set_", value, 4)) |
---|
4159 | { |
---|
4160 | char* tmpstr = NULL; |
---|
4161 | tmpstr = ostrcat(value, NULL, 0, 0); |
---|
4162 | tmpstr = string_replace("set_", "", tmpstr, 1); |
---|
4163 | debug(10, "change %s to %s", aspectdev, tmpstr); |
---|
4164 | ret = writesys(aspectdev, tmpstr, 0); |
---|
4165 | if(ret == 0) addconfig("av_aspect", tmpstr); |
---|
4166 | free(tmpstr); tmpstr = NULL; |
---|
4167 | return ret; |
---|
4168 | } |
---|
4169 | else |
---|
4170 | { |
---|
4171 | ret = writesys(aspectdev, value, 0); |
---|
4172 | |
---|
4173 | if(ret == 0) |
---|
4174 | { |
---|
4175 | addconfig("av_aspect", value); |
---|
4176 | |
---|
4177 | //set policy new after change aspect |
---|
4178 | char* tmpstr = getpolicy(); |
---|
4179 | setpolicy(tmpstr); |
---|
4180 | free(tmpstr); tmpstr = NULL; |
---|
4181 | } |
---|
4182 | } |
---|
4183 | return ret; |
---|
4184 | } |
---|
4185 | |
---|
4186 | return 0; |
---|
4187 | } |
---|
4188 | |
---|
4189 | char* getvideomodechoices() |
---|
4190 | { |
---|
4191 | char *videomodechoicesdev = NULL; |
---|
4192 | char *value = NULL; |
---|
4193 | |
---|
4194 | videomodechoicesdev = getconfig("videomodechoicesdev", NULL); |
---|
4195 | |
---|
4196 | if(videomodechoicesdev == NULL) |
---|
4197 | { |
---|
4198 | err("NULL detect"); |
---|
4199 | return NULL; |
---|
4200 | } |
---|
4201 | |
---|
4202 | value = readsys(videomodechoicesdev, 1); |
---|
4203 | if(value == NULL) |
---|
4204 | { |
---|
4205 | err("NULL detect"); |
---|
4206 | return NULL; |
---|
4207 | } |
---|
4208 | |
---|
4209 | value = string_replace("pal", NULL, value, 1); |
---|
4210 | value = string_replace(" ", " ", value, 1); |
---|
4211 | |
---|
4212 | if(status.mcaktiv == 0) |
---|
4213 | { |
---|
4214 | value = string_replace("1080p60", NULL, value, 1); |
---|
4215 | value = string_replace(" ", " ", value, 1); |
---|
4216 | value = string_replace("1080p59", NULL, value, 1); |
---|
4217 | value = string_replace(" ", " ", value, 1); |
---|
4218 | value = string_replace("1080p30", NULL, value, 1); |
---|
4219 | value = string_replace(" ", " ", value, 1); |
---|
4220 | value = string_replace("1080p29", NULL, value, 1); |
---|
4221 | value = string_replace(" ", " ", value, 1); |
---|
4222 | value = string_replace("1080p25", NULL, value, 1); |
---|
4223 | value = string_replace(" ", " ", value, 1); |
---|
4224 | value = string_replace("1080p24", NULL, value, 1); |
---|
4225 | value = string_replace(" ", " ", value, 1); |
---|
4226 | value = string_replace("1080p23", NULL, value, 1); |
---|
4227 | value = string_replace(" ", " ", value, 1); |
---|
4228 | value = string_replace("1080i60", NULL, value, 1); |
---|
4229 | value = string_replace(" ", " ", value, 1); |
---|
4230 | value = string_replace("1080i59", NULL, value, 1); |
---|
4231 | value = string_replace(" ", " ", value, 1); |
---|
4232 | value = string_replace("1080i60", NULL, value, 1); |
---|
4233 | value = string_replace(" ", " ", value, 1); |
---|
4234 | value = string_replace("720p60", NULL, value, 1); |
---|
4235 | value = string_replace(" ", " ", value, 1); |
---|
4236 | value = string_replace("576p50", NULL, value, 1); |
---|
4237 | value = string_replace(" ", " ", value, 1); |
---|
4238 | value = string_replace("1280x1024_75", NULL, value, 1); |
---|
4239 | value = string_replace(" ", " ", value, 1); |
---|
4240 | value = string_replace("1280x1024_70", NULL, value, 1); |
---|
4241 | value = string_replace(" ", " ", value, 1); |
---|
4242 | value = string_replace("1280x1024_60", NULL, value, 1); |
---|
4243 | value = string_replace(" ", " ", value, 1); |
---|
4244 | value = string_replace("1600x1200_60", NULL, value, 1); |
---|
4245 | value = string_replace(" ", " ", value, 1); |
---|
4246 | value = string_replace("1024x768_100", NULL, value, 1); |
---|
4247 | value = string_replace(" ", " ", value, 1); |
---|
4248 | value = string_replace("1024x768_90", NULL, value, 1); |
---|
4249 | value = string_replace(" ", " ", value, 1); |
---|
4250 | value = string_replace("1024x768_75", NULL, value, 1); |
---|
4251 | value = string_replace(" ", " ", value, 1); |
---|
4252 | value = string_replace("1024x768_70", NULL, value, 1); |
---|
4253 | value = string_replace(" ", " ", value, 1); |
---|
4254 | value = string_replace("1024x768_60", NULL, value, 1); |
---|
4255 | value = string_replace(" ", " ", value, 1); |
---|
4256 | } |
---|
4257 | |
---|
4258 | value = strstrip(value); |
---|
4259 | value = convertspacetolf(value); |
---|
4260 | |
---|
4261 | return value; |
---|
4262 | } |
---|
4263 | |
---|
4264 | char* getmode3dchoices() |
---|
4265 | { |
---|
4266 | char *mode3dchoicesdev = NULL; |
---|
4267 | char *value = NULL; |
---|
4268 | |
---|
4269 | mode3dchoicesdev = getconfig("mode3dchoicesdev", NULL); |
---|
4270 | |
---|
4271 | if(mode3dchoicesdev == NULL) |
---|
4272 | { |
---|
4273 | return ostrcat("off\nsbs\ntab", "", 0, 0); |
---|
4274 | } |
---|
4275 | |
---|
4276 | value = readsys(mode3dchoicesdev, 1); |
---|
4277 | if(value == NULL) |
---|
4278 | { |
---|
4279 | err("NULL detect"); |
---|
4280 | return NULL; |
---|
4281 | } |
---|
4282 | |
---|
4283 | value = convertspacetolf(value); |
---|
4284 | |
---|
4285 | return value; |
---|
4286 | } |
---|
4287 | |
---|
4288 | char* getmode3d() |
---|
4289 | { |
---|
4290 | char *mode3ddev = NULL; |
---|
4291 | char *value = NULL; |
---|
4292 | |
---|
4293 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
4294 | |
---|
4295 | if(mode3ddev == NULL) |
---|
4296 | { |
---|
4297 | err("NULL detect"); |
---|
4298 | return NULL; |
---|
4299 | } |
---|
4300 | |
---|
4301 | value = readsys(mode3ddev, 1); |
---|
4302 | if(value == NULL) |
---|
4303 | { |
---|
4304 | err("NULL detect"); |
---|
4305 | return NULL; |
---|
4306 | } |
---|
4307 | |
---|
4308 | return value; |
---|
4309 | } |
---|
4310 | |
---|
4311 | int setmode3d(char* value) |
---|
4312 | { |
---|
4313 | char* mode3ddev; |
---|
4314 | int ret = 0; |
---|
4315 | |
---|
4316 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
4317 | |
---|
4318 | if(mode3ddev != NULL && value != NULL) |
---|
4319 | { |
---|
4320 | debug(100, "set %s to %s", mode3ddev, value); |
---|
4321 | ret = writesys(mode3ddev, value, 0); |
---|
4322 | if(ret == 0) addconfig("av_mode3d", value); |
---|
4323 | return ret; |
---|
4324 | } |
---|
4325 | |
---|
4326 | return 0; |
---|
4327 | } |
---|
4328 | |
---|
4329 | char* getvideomode() |
---|
4330 | { |
---|
4331 | char *videomodedev = NULL; |
---|
4332 | char *value = NULL; |
---|
4333 | |
---|
4334 | videomodedev = getconfig("videomodedev", NULL); |
---|
4335 | |
---|
4336 | if(videomodedev == NULL) |
---|
4337 | { |
---|
4338 | err("NULL detect"); |
---|
4339 | return NULL; |
---|
4340 | } |
---|
4341 | |
---|
4342 | value = readsys(videomodedev, 1); |
---|
4343 | if(value == NULL) |
---|
4344 | { |
---|
4345 | err("NULL detect"); |
---|
4346 | return NULL; |
---|
4347 | } |
---|
4348 | |
---|
4349 | return value; |
---|
4350 | } |
---|
4351 | |
---|
4352 | void switchvideomode() |
---|
4353 | { |
---|
4354 | int rcret = 0; |
---|
4355 | char* tmpstr = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL; |
---|
4356 | tmpstr = getvideomode(); |
---|
4357 | struct skin* playpolicy = getscreen("playpolicy"); |
---|
4358 | tmpstr2 = getcolorformat(2); |
---|
4359 | |
---|
4360 | if(tmpstr != NULL) |
---|
4361 | { |
---|
4362 | if((ostrcmp("pal", tmpstr) == 0 || ostrncmp("576", tmpstr, 3) == 0) && ostrncmp("yuv", tmpstr2, 3) == 0) |
---|
4363 | { |
---|
4364 | setvideomode("720p50", 0); |
---|
4365 | changefbresolution("720p50", 0); |
---|
4366 | changetext(playpolicy, "720p50 (rgb)"); |
---|
4367 | writevfdmenu("720p50 (rgb)"); |
---|
4368 | setcolorformat("rgb", 1); |
---|
4369 | unlink("/var/etc/.scart"); |
---|
4370 | } |
---|
4371 | else if((ostrcmp("pal", tmpstr) == 0 || ostrncmp("576", tmpstr, 3) == 0) && ostrncmp("rgb", tmpstr2, 3) == 0) |
---|
4372 | { |
---|
4373 | setvideomode("720p50", 0); |
---|
4374 | changefbresolution("720p50", 0); |
---|
4375 | changetext(playpolicy, "720p50 (yuv)"); |
---|
4376 | writevfdmenu("720p50 (yuv)"); |
---|
4377 | setcolorformat("yuv", 1); |
---|
4378 | unlink("/var/etc/.scart"); |
---|
4379 | } |
---|
4380 | else if(ostrncmp("720", tmpstr, 3) == 0) |
---|
4381 | { |
---|
4382 | setvideomode("1080i50", 0); |
---|
4383 | changefbresolution("1080i50", 0); |
---|
4384 | tmpstr3 = ostrcat("1080i50 (", tmpstr2, 0, 0); |
---|
4385 | tmpstr3 = ostrcat(tmpstr3, ")", 1, 0); |
---|
4386 | changetext(playpolicy, tmpstr3); |
---|
4387 | writevfdmenu(tmpstr3); |
---|
4388 | unlink("/var/etc/.scart"); |
---|
4389 | } |
---|
4390 | else if(ostrncmp("1080", tmpstr, 4) == 0) |
---|
4391 | { |
---|
4392 | setvideomode("576i50", 0); |
---|
4393 | changefbresolution("576i50", 0); |
---|
4394 | changetext(playpolicy, "576i50 (rgb)"); |
---|
4395 | writevfdmenu("576i50 (rgb)"); |
---|
4396 | setcolorformat("rgb", 1); |
---|
4397 | writesys("/var/etc/.scart", "0", 0); |
---|
4398 | } |
---|
4399 | /* |
---|
4400 | int ret = textbox(_("Message"), _("Is this Videomode ok ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
4401 | if(ret == 1 || ret == 2) |
---|
4402 | { |
---|
4403 | setvideomode(tmpstr, 0); |
---|
4404 | changefbresolution(tmpstr, 0); |
---|
4405 | } |
---|
4406 | */ |
---|
4407 | drawscreen(playpolicy, 0, 0); |
---|
4408 | while(1) |
---|
4409 | { |
---|
4410 | rcret = waitrc(playpolicy, 5000, 0); |
---|
4411 | break; |
---|
4412 | } |
---|
4413 | clearscreen(playpolicy); |
---|
4414 | } |
---|
4415 | free(tmpstr); |
---|
4416 | free(tmpstr2); |
---|
4417 | free(tmpstr3); |
---|
4418 | } |
---|
4419 | |
---|
4420 | //flag 0: write videomode to config |
---|
4421 | //flag 1: don't write videomode to config |
---|
4422 | int setvideomode(char* value, int flag) |
---|
4423 | { |
---|
4424 | char* videomodedev; |
---|
4425 | int ret = 0; |
---|
4426 | |
---|
4427 | videomodedev = getconfig("videomodedev", NULL); |
---|
4428 | |
---|
4429 | if(videomodedev != NULL && value != NULL) |
---|
4430 | { |
---|
4431 | debug(100, "set %s to %s", videomodedev, value); |
---|
4432 | ret = writesys(videomodedev, value, 0); |
---|
4433 | if(ret == 0 && flag == 0) addconfig("av_videomode", value); |
---|
4434 | return ret; |
---|
4435 | } |
---|
4436 | |
---|
4437 | return 0; |
---|
4438 | } |
---|
4439 | |
---|
4440 | //flag 0 = hdmi |
---|
4441 | //flag 1 = scart |
---|
4442 | int setcolorformat(char* value, int flag) |
---|
4443 | { |
---|
4444 | char* colorformatdev; |
---|
4445 | int ret = 0; |
---|
4446 | |
---|
4447 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
4448 | |
---|
4449 | if(colorformatdev != NULL && value != NULL) |
---|
4450 | { |
---|
4451 | debug(100, "set %s to %s", colorformatdev, value); |
---|
4452 | ret = writesys(colorformatdev, value, 0); |
---|
4453 | if(ret == 0) |
---|
4454 | { |
---|
4455 | if(flag == 0) |
---|
4456 | addconfig("av_colorformat", value); |
---|
4457 | else |
---|
4458 | addconfig("av_colorformatscart", value); |
---|
4459 | } |
---|
4460 | return ret; |
---|
4461 | } |
---|
4462 | |
---|
4463 | return 0; |
---|
4464 | } |
---|
4465 | |
---|
4466 | char* getcolorformat(int line) |
---|
4467 | { |
---|
4468 | char *colorformatdev = NULL; |
---|
4469 | char *value = NULL; |
---|
4470 | |
---|
4471 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
4472 | |
---|
4473 | if(colorformatdev == NULL) |
---|
4474 | { |
---|
4475 | err("NULL detect"); |
---|
4476 | return NULL; |
---|
4477 | } |
---|
4478 | |
---|
4479 | value = readsys(colorformatdev, line); |
---|
4480 | if(value == NULL) |
---|
4481 | { |
---|
4482 | err("NULL detect"); |
---|
4483 | return NULL; |
---|
4484 | } |
---|
4485 | |
---|
4486 | return value; |
---|
4487 | } |
---|
4488 | |
---|
4489 | int setaudiosource(char* value) |
---|
4490 | { |
---|
4491 | char* audiosourcedev; |
---|
4492 | int ret = 1; |
---|
4493 | |
---|
4494 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
4495 | |
---|
4496 | if(audiosourcedev != NULL && value != NULL) |
---|
4497 | { |
---|
4498 | debug(100, "set %s to %s", audiosourcedev, value); |
---|
4499 | ret = writesys(audiosourcedev, value, 0); |
---|
4500 | if(ret == 0) addconfig("av_audiosource", value); |
---|
4501 | return ret; |
---|
4502 | } |
---|
4503 | |
---|
4504 | return 0; |
---|
4505 | } |
---|
4506 | |
---|
4507 | char* getaudiosource() |
---|
4508 | { |
---|
4509 | char *audiosourcedev = NULL; |
---|
4510 | char *value = NULL; |
---|
4511 | |
---|
4512 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
4513 | |
---|
4514 | if(audiosourcedev == NULL) |
---|
4515 | { |
---|
4516 | err("NULL detect"); |
---|
4517 | return NULL; |
---|
4518 | } |
---|
4519 | |
---|
4520 | value = readsys(audiosourcedev, 1); |
---|
4521 | if(value == NULL) |
---|
4522 | { |
---|
4523 | err("NULL detect"); |
---|
4524 | return NULL; |
---|
4525 | } |
---|
4526 | |
---|
4527 | return value; |
---|
4528 | } |
---|
4529 | |
---|
4530 | char* getsataswitch() |
---|
4531 | { |
---|
4532 | char *sataswitchdev = NULL; |
---|
4533 | char *value = NULL; |
---|
4534 | |
---|
4535 | sataswitchdev = getconfig("sataswitchdev", NULL); |
---|
4536 | |
---|
4537 | if(sataswitchdev == NULL) |
---|
4538 | { |
---|
4539 | err("NULL detect"); |
---|
4540 | return NULL; |
---|
4541 | } |
---|
4542 | |
---|
4543 | value = readsys(sataswitchdev, 1); |
---|
4544 | if(value == NULL) |
---|
4545 | { |
---|
4546 | err("NULL detect"); |
---|
4547 | return NULL; |
---|
4548 | } |
---|
4549 | |
---|
4550 | return value; |
---|
4551 | } |
---|
4552 | |
---|
4553 | int setsataswitch(char* value) |
---|
4554 | { |
---|
4555 | char* sataswitchdev; |
---|
4556 | int ret = 1; |
---|
4557 | |
---|
4558 | sataswitchdev = getconfig("sataswitchdev", NULL); |
---|
4559 | |
---|
4560 | if(sataswitchdev != NULL && value != NULL) |
---|
4561 | { |
---|
4562 | debug(100, "set %s to %s", sataswitchdev, value); |
---|
4563 | ret = writesys(sataswitchdev, value, 0); |
---|
4564 | return ret; |
---|
4565 | } |
---|
4566 | |
---|
4567 | return 0; |
---|
4568 | } |
---|
4569 | |
---|
4570 | int setprogress(value) |
---|
4571 | { |
---|
4572 | char *progressdev; |
---|
4573 | |
---|
4574 | progressdev = getconfig("progressdev", NULL); |
---|
4575 | |
---|
4576 | if(progressdev != NULL) |
---|
4577 | { |
---|
4578 | debug(100, "set %s to %d",progressdev, value); |
---|
4579 | return writesysint(progressdev, value, 0); |
---|
4580 | } |
---|
4581 | |
---|
4582 | return 0; |
---|
4583 | } |
---|
4584 | |
---|
4585 | int setmute(int value) |
---|
4586 | { |
---|
4587 | char* mutedev; |
---|
4588 | int tmpvol, ret = 0; |
---|
4589 | |
---|
4590 | //don't set mute 2x |
---|
4591 | if(value == 1 && status.mute == 1) return 0; |
---|
4592 | |
---|
4593 | // printf("mute value: %d\n", value); |
---|
4594 | |
---|
4595 | if(value == 2) |
---|
4596 | { |
---|
4597 | tmpvol = getvol(); |
---|
4598 | tmpvol = tmpvol * 50 / 100; |
---|
4599 | status.mute = value; |
---|
4600 | setvol(tmpvol); |
---|
4601 | } |
---|
4602 | else |
---|
4603 | { |
---|
4604 | mutedev = getconfig("mutedev", NULL); |
---|
4605 | |
---|
4606 | if(mutedev != NULL) |
---|
4607 | { |
---|
4608 | debug(100, "set %s to %d", mutedev, value); |
---|
4609 | //if(status.volautochangevalue != 0 && value == 0) setvol(getvol()); |
---|
4610 | #ifdef MIPSEL |
---|
4611 | struct dvbdev *audionode = NULL; |
---|
4612 | int openaudio = 0; |
---|
4613 | if(status.aktservice != NULL) |
---|
4614 | { |
---|
4615 | if(status.aktservice->audiodev == NULL) |
---|
4616 | { |
---|
4617 | audionode = audioopen(0); //we must open the audio device for set mute in external player |
---|
4618 | openaudio = 1; |
---|
4619 | } |
---|
4620 | else |
---|
4621 | audionode = status.aktservice->audiodev; |
---|
4622 | } |
---|
4623 | ret = audiosetmute(audionode, value); |
---|
4624 | if(openaudio == 1) |
---|
4625 | audioclose(audionode, -1); |
---|
4626 | #else |
---|
4627 | ret = writesysint(mutedev, value, 0); |
---|
4628 | #endif |
---|
4629 | |
---|
4630 | if(ret == 0) status.mute = value; |
---|
4631 | if(status.volautochangevalue != 0 && value == 0) setvol(getvol()); |
---|
4632 | // if(value == 1) |
---|
4633 | // { |
---|
4634 | // printf("mute\n"); |
---|
4635 | // system("amixer -c 1 set HDMI mute &"); |
---|
4636 | // system("amixer -c 1 set Analog mute &"); |
---|
4637 | // system("amixer -c 1 set SPDIF mute &"); |
---|
4638 | // sleep(1); |
---|
4639 | // } |
---|
4640 | // else |
---|
4641 | // { |
---|
4642 | // printf("unmute\n"); |
---|
4643 | // system("amixer -c 1 set HDMI unmute &"); |
---|
4644 | // system("amixer -c 1 set Analog unmute &"); |
---|
4645 | // system("amixer -c 1 set SPDIF unmute &"); |
---|
4646 | // } |
---|
4647 | |
---|
4648 | return ret; |
---|
4649 | } |
---|
4650 | } |
---|
4651 | return 0; |
---|
4652 | } |
---|
4653 | |
---|
4654 | int setvol(int value) |
---|
4655 | { |
---|
4656 | char* voldev; |
---|
4657 | int ret = 0, tmpvol = value; |
---|
4658 | |
---|
4659 | voldev = getconfig("voldev", NULL); |
---|
4660 | |
---|
4661 | if(voldev != NULL) |
---|
4662 | { |
---|
4663 | if(value > 100) value = 100; |
---|
4664 | if(value < 0) value = 0; |
---|
4665 | if(status.volautochangevalue != 0 && value != 0) |
---|
4666 | { |
---|
4667 | if(status.volautochange == 0) |
---|
4668 | value = value - (status.volautochangevalue * value / 100); |
---|
4669 | } |
---|
4670 | value = 63 - value * 63 / 100; |
---|
4671 | debug(100, "set %s to %d", voldev, value); |
---|
4672 | ret = 0; |
---|
4673 | if(status.mute == 1) |
---|
4674 | status.volmute = value; |
---|
4675 | else |
---|
4676 | { |
---|
4677 | status.volmute = -1; |
---|
4678 | ret = writesysint(voldev, value, 0); |
---|
4679 | |
---|
4680 | #ifdef MIPSEL |
---|
4681 | struct dvbdev *audionode = NULL; |
---|
4682 | int openaudio = 0; |
---|
4683 | |
---|
4684 | if(ret == 0 && status.aktservice != NULL) |
---|
4685 | { |
---|
4686 | if(status.aktservice->audiodev == NULL) |
---|
4687 | { |
---|
4688 | audionode = audioopen(0); //we must open the audio device for change volume in external player |
---|
4689 | openaudio = 1; |
---|
4690 | } |
---|
4691 | else |
---|
4692 | audionode = status.aktservice->audiodev; |
---|
4693 | |
---|
4694 | if(ret == 0 && audionode != NULL) |
---|
4695 | ret = setmixer(audionode, value, value); |
---|
4696 | |
---|
4697 | if(openaudio == 1) |
---|
4698 | audioclose(audionode, -1); |
---|
4699 | } |
---|
4700 | #else |
---|
4701 | if(ret == 0 && status.aktservice != NULL) |
---|
4702 | ret = setmixer(status.aktservice->audiodev, value, value); |
---|
4703 | #endif |
---|
4704 | } |
---|
4705 | if(ret == 0 && status.mute != 2) addconfigint("vol", tmpvol); |
---|
4706 | return ret; |
---|
4707 | } |
---|
4708 | |
---|
4709 | return 0; |
---|
4710 | } |
---|
4711 | |
---|
4712 | int getvol() |
---|
4713 | { |
---|
4714 | char *voldev = NULL; |
---|
4715 | char *value = NULL; |
---|
4716 | int tmpvol = -1; |
---|
4717 | |
---|
4718 | voldev = getconfig("voldev", NULL); |
---|
4719 | |
---|
4720 | if(voldev == NULL) |
---|
4721 | { |
---|
4722 | err("NULL detect"); |
---|
4723 | return 0; |
---|
4724 | } |
---|
4725 | if(status.volmute == -1) |
---|
4726 | value = readsys(voldev, 1); |
---|
4727 | else |
---|
4728 | tmpvol = status.volmute; |
---|
4729 | if(value == NULL && tmpvol == -1) |
---|
4730 | { |
---|
4731 | err("NULL detect"); |
---|
4732 | return 0; |
---|
4733 | } |
---|
4734 | if(status.volmute == -1) |
---|
4735 | tmpvol = atoi(value); |
---|
4736 | free(value); |
---|
4737 | tmpvol = 100 - tmpvol * 100 / 63; |
---|
4738 | if(status.volautochangevalue != 0) |
---|
4739 | { |
---|
4740 | if(status.volautochange == 0 && status.volautochangevalue < 100) |
---|
4741 | tmpvol = tmpvol + ((tmpvol * status.volautochangevalue) / (100 - status.volautochangevalue)); |
---|
4742 | } |
---|
4743 | return tmpvol; |
---|
4744 | } |
---|
4745 | |
---|
4746 | void setdebuglevel() |
---|
4747 | { |
---|
4748 | debug_level = getconfigint("debuglevel", NULL); |
---|
4749 | debug(0, "set debug level to %d", debug_level); |
---|
4750 | } |
---|
4751 | |
---|
4752 | char* getxmlentry(char *line, char *searchstr) |
---|
4753 | { |
---|
4754 | char *buf = NULL, *buf1 = NULL, *buf2 = NULL; |
---|
4755 | |
---|
4756 | buf = ostrstr(line, searchstr); |
---|
4757 | if(buf == NULL) |
---|
4758 | return NULL; |
---|
4759 | |
---|
4760 | buf = buf + strlen(searchstr); |
---|
4761 | if(buf[0] == '"') |
---|
4762 | { |
---|
4763 | buf = buf + 1; |
---|
4764 | buf2 = strchr(buf, '"'); |
---|
4765 | if(buf2 == NULL) |
---|
4766 | { |
---|
4767 | err("strchr returns NULL"); |
---|
4768 | return NULL; |
---|
4769 | } |
---|
4770 | buf1 = strndup(buf, buf2 - buf); |
---|
4771 | if(buf1 == NULL) |
---|
4772 | { |
---|
4773 | err("strndup failed"); |
---|
4774 | return NULL; |
---|
4775 | } |
---|
4776 | } |
---|
4777 | else |
---|
4778 | { |
---|
4779 | buf2 = strchr(buf, ' '); |
---|
4780 | if(buf2 == NULL) |
---|
4781 | { |
---|
4782 | buf2 = ostrstr(buf, "/>"); |
---|
4783 | if(buf2 == NULL) |
---|
4784 | { |
---|
4785 | buf2 = strchr(buf, '>'); |
---|
4786 | if(buf2 == NULL) |
---|
4787 | { |
---|
4788 | err("strchr returns NULL"); |
---|
4789 | return NULL; |
---|
4790 | } |
---|
4791 | } |
---|
4792 | } |
---|
4793 | buf1 = strndup(buf, buf2 - buf); |
---|
4794 | if(buf1 == NULL) |
---|
4795 | { |
---|
4796 | err("strndup failed"); |
---|
4797 | return NULL; |
---|
4798 | } |
---|
4799 | } |
---|
4800 | |
---|
4801 | return buf1; |
---|
4802 | } |
---|
4803 | |
---|
4804 | char* readbintomem(const char* filename, size_t size) |
---|
4805 | { |
---|
4806 | FILE *fd = NULL; |
---|
4807 | char *fileline = NULL; |
---|
4808 | |
---|
4809 | fileline = calloc(1, size + 1); |
---|
4810 | if(fileline == NULL) |
---|
4811 | { |
---|
4812 | err("no mem"); |
---|
4813 | return NULL; |
---|
4814 | } |
---|
4815 | |
---|
4816 | fd = fopen(filename, "rb"); |
---|
4817 | if(fd == NULL) |
---|
4818 | { |
---|
4819 | perr("can't open %s", filename); |
---|
4820 | free(fileline); |
---|
4821 | return NULL; |
---|
4822 | } |
---|
4823 | |
---|
4824 | fread(fileline, size, 1, fd); |
---|
4825 | |
---|
4826 | fclose(fd); |
---|
4827 | return fileline; |
---|
4828 | } |
---|
4829 | |
---|
4830 | char* readfiletomem(const char* filename, int flag) |
---|
4831 | { |
---|
4832 | FILE *fd = NULL; |
---|
4833 | char *fileline = NULL, *buf = NULL, *tmpbuf = NULL; |
---|
4834 | int bufsize = 0, bufoldsize = 0; |
---|
4835 | |
---|
4836 | fileline = malloc(MINMALLOC); |
---|
4837 | if(fileline == NULL) |
---|
4838 | { |
---|
4839 | err("no mem"); |
---|
4840 | return NULL; |
---|
4841 | } |
---|
4842 | |
---|
4843 | fd = fopen(filename, "r"); |
---|
4844 | if(fd == NULL) |
---|
4845 | { |
---|
4846 | perr("can't open %s", filename); |
---|
4847 | free(fileline); |
---|
4848 | return NULL; |
---|
4849 | } |
---|
4850 | |
---|
4851 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
4852 | { |
---|
4853 | if(flag == 1) |
---|
4854 | if(fileline[0] == '#' || fileline[0] == '\n') |
---|
4855 | continue; |
---|
4856 | |
---|
4857 | bufoldsize = bufsize; |
---|
4858 | bufsize += strlen(fileline); |
---|
4859 | tmpbuf = buf; buf = realloc(buf, bufsize + 1); |
---|
4860 | if(buf == NULL) |
---|
4861 | { |
---|
4862 | err("no mem"); |
---|
4863 | free(fileline); |
---|
4864 | free(tmpbuf); |
---|
4865 | fclose(fd); |
---|
4866 | return NULL; |
---|
4867 | } |
---|
4868 | |
---|
4869 | sprintf(buf + bufoldsize, "%s", fileline); |
---|
4870 | } |
---|
4871 | |
---|
4872 | free(fileline); |
---|
4873 | fclose(fd); |
---|
4874 | return buf; |
---|
4875 | } |
---|
4876 | |
---|
4877 | char* readeittomem(const char* filename) |
---|
4878 | { |
---|
4879 | unsigned char byte; |
---|
4880 | FILE *fil = NULL; |
---|
4881 | char *zeichen = NULL, *buf = NULL, *buf1 = NULL, *tmpbuf1 = NULL; |
---|
4882 | int buf1size = 0, buf1oldsize = 0; |
---|
4883 | int Beschreibung; |
---|
4884 | int len; |
---|
4885 | |
---|
4886 | zeichen = malloc(255); |
---|
4887 | if(zeichen == NULL) |
---|
4888 | { |
---|
4889 | err("no mem"); |
---|
4890 | return NULL; |
---|
4891 | } |
---|
4892 | buf = malloc(255); |
---|
4893 | if(buf == NULL) |
---|
4894 | { |
---|
4895 | free(zeichen); |
---|
4896 | err("no mem"); |
---|
4897 | return NULL; |
---|
4898 | } |
---|
4899 | |
---|
4900 | fil = fopen(filename, "r"); |
---|
4901 | if(fil == NULL) |
---|
4902 | { |
---|
4903 | err("can't open %s", filename); |
---|
4904 | free(zeichen); |
---|
4905 | free(buf); |
---|
4906 | return NULL; |
---|
4907 | } |
---|
4908 | Beschreibung = 0; |
---|
4909 | fseek(fil, 12, SEEK_SET); //ersten 12 Byte nicht relevant |
---|
4910 | while(!feof(fil)) |
---|
4911 | { |
---|
4912 | byte = fgetc(fil); |
---|
4913 | |
---|
4914 | if(byte == 0x4D) |
---|
4915 | { |
---|
4916 | fseek(fil, 4,SEEK_CUR); |
---|
4917 | byte = fgetc(fil); |
---|
4918 | len = byte + 0; |
---|
4919 | byte = fgetc(fil); |
---|
4920 | fgets(zeichen, len, fil); |
---|
4921 | if(byte != 0x05) |
---|
4922 | sprintf(buf, "%c%s\n", byte, zeichen); |
---|
4923 | else |
---|
4924 | sprintf(buf, "%s\n", zeichen); |
---|
4925 | |
---|
4926 | buf1oldsize = buf1size; |
---|
4927 | buf1size += strlen(buf); |
---|
4928 | tmpbuf1 = buf1; buf1 = realloc(buf1, buf1size + 1); |
---|
4929 | if(buf1 == NULL) |
---|
4930 | { |
---|
4931 | err("no mem"); |
---|
4932 | free(zeichen); |
---|
4933 | free(buf); |
---|
4934 | free(tmpbuf1); |
---|
4935 | fclose(fil); |
---|
4936 | return NULL; |
---|
4937 | } |
---|
4938 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
4939 | |
---|
4940 | //printf("T %s\n", zeichen); |
---|
4941 | byte = fgetc(fil); |
---|
4942 | len = byte + 0; |
---|
4943 | byte = fgetc(fil); |
---|
4944 | fgets(zeichen, len, fil); |
---|
4945 | if(byte != 0x05) |
---|
4946 | sprintf(buf,"%c%s\n\n", byte, zeichen); |
---|
4947 | else |
---|
4948 | sprintf(buf,"%s\n\n", zeichen); |
---|
4949 | |
---|
4950 | buf1oldsize = buf1size; |
---|
4951 | buf1size += strlen(buf); |
---|
4952 | tmpbuf1 = buf1; buf1 = realloc(buf1, buf1size + 1); |
---|
4953 | if(buf1 == NULL) |
---|
4954 | { |
---|
4955 | err("no mem"); |
---|
4956 | free(zeichen); |
---|
4957 | free(buf); |
---|
4958 | free(tmpbuf1); |
---|
4959 | fclose(fil); |
---|
4960 | return NULL; |
---|
4961 | } |
---|
4962 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
4963 | |
---|
4964 | } |
---|
4965 | else if(byte == 0x4E) |
---|
4966 | { |
---|
4967 | fseek(fil, 6, SEEK_CUR); |
---|
4968 | byte = fgetc(fil); |
---|
4969 | len = byte; |
---|
4970 | byte = fgetc(fil); |
---|
4971 | fgets(zeichen, len, fil); |
---|
4972 | if(Beschreibung == 0) |
---|
4973 | { |
---|
4974 | if(byte != 0x05) |
---|
4975 | sprintf(buf, "%c%s", byte, zeichen); |
---|
4976 | else |
---|
4977 | sprintf(buf, "%s", zeichen); |
---|
4978 | Beschreibung = 1; |
---|
4979 | } |
---|
4980 | else |
---|
4981 | { |
---|
4982 | if(byte != 0x05) |
---|
4983 | sprintf(buf, "%c%s", byte, zeichen); |
---|
4984 | else |
---|
4985 | sprintf(buf, "%s", zeichen); |
---|
4986 | } |
---|
4987 | |
---|
4988 | buf1oldsize = buf1size; |
---|
4989 | buf1size += strlen(buf); |
---|
4990 | tmpbuf1 = buf1; buf1 = realloc(buf1, buf1size + 1); |
---|
4991 | if(buf1 == NULL) |
---|
4992 | { |
---|
4993 | err("no mem"); |
---|
4994 | free(zeichen); |
---|
4995 | free(buf); |
---|
4996 | free(tmpbuf1); |
---|
4997 | fclose(fil); |
---|
4998 | return NULL; |
---|
4999 | } |
---|
5000 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
5001 | |
---|
5002 | } |
---|
5003 | else |
---|
5004 | { |
---|
5005 | byte = fgetc(fil); |
---|
5006 | len= byte; |
---|
5007 | fgets(zeichen, len + 1, fil); |
---|
5008 | } |
---|
5009 | } |
---|
5010 | free(zeichen); |
---|
5011 | free(buf); |
---|
5012 | fclose(fil); |
---|
5013 | return buf1; |
---|
5014 | } |
---|
5015 | |
---|
5016 | char* command(char* input) |
---|
5017 | { |
---|
5018 | int maxlen = 0, pos = 0; |
---|
5019 | char* tmpstr = NULL, *fileline = NULL; |
---|
5020 | FILE *iopipe = NULL; |
---|
5021 | |
---|
5022 | if(input == NULL) return NULL; |
---|
5023 | |
---|
5024 | fileline = malloc(MINMALLOC); |
---|
5025 | if(fileline == NULL) |
---|
5026 | { |
---|
5027 | err("no mem"); |
---|
5028 | return NULL; |
---|
5029 | } |
---|
5030 | |
---|
5031 | if((iopipe = popen(input, "r")) == NULL) |
---|
5032 | { |
---|
5033 | free(fileline); |
---|
5034 | return NULL; |
---|
5035 | } |
---|
5036 | |
---|
5037 | while(!feof(iopipe)) |
---|
5038 | { |
---|
5039 | if(fgets(fileline, MINMALLOC, iopipe) != NULL) |
---|
5040 | ostrcatbig(&tmpstr, fileline, &maxlen, &pos); |
---|
5041 | } |
---|
5042 | |
---|
5043 | if(pos > 0) |
---|
5044 | { |
---|
5045 | char* tmp = tmpstr; |
---|
5046 | tmpstr = realloc(tmpstr, pos + 1); |
---|
5047 | if(tmpstr == NULL) |
---|
5048 | tmpstr = tmp; |
---|
5049 | } |
---|
5050 | |
---|
5051 | free(fileline); |
---|
5052 | pclose(iopipe); |
---|
5053 | return tmpstr; |
---|
5054 | } |
---|
5055 | |
---|
5056 | char* string_tolower(char *str) |
---|
5057 | { |
---|
5058 | /* |
---|
5059 | char *p1 = str; |
---|
5060 | |
---|
5061 | if(str == NULL) return NULL; |
---|
5062 | |
---|
5063 | while(*p1 != '\0') |
---|
5064 | *p1++ = tolower(*p1); |
---|
5065 | |
---|
5066 | return str; |
---|
5067 | */ |
---|
5068 | if(str == NULL) return NULL; |
---|
5069 | |
---|
5070 | int i=0; |
---|
5071 | while (str[i]) |
---|
5072 | { |
---|
5073 | str[i] = tolower(str[i]); |
---|
5074 | i++; |
---|
5075 | } |
---|
5076 | return str; |
---|
5077 | } |
---|
5078 | |
---|
5079 | char* string_toupper(char *str) |
---|
5080 | { |
---|
5081 | /* |
---|
5082 | char *p1 = str; |
---|
5083 | |
---|
5084 | if(str == NULL) return NULL; |
---|
5085 | |
---|
5086 | while(*p1 != '\0') |
---|
5087 | *p1++ = toupper(*p1); |
---|
5088 | |
---|
5089 | */ |
---|
5090 | if(str == NULL) return NULL; |
---|
5091 | |
---|
5092 | int i=0; |
---|
5093 | while (str[i]) |
---|
5094 | { |
---|
5095 | str[i] = toupper(str[i]); |
---|
5096 | i++; |
---|
5097 | } |
---|
5098 | return str; |
---|
5099 | } |
---|
5100 | |
---|
5101 | char* stringreplacecharonce(char *str, char c1, char c2) |
---|
5102 | { |
---|
5103 | char *p1 = str; |
---|
5104 | |
---|
5105 | if(str == NULL) return NULL; |
---|
5106 | |
---|
5107 | while(*p1 != '\0') |
---|
5108 | { |
---|
5109 | if(*p1 == c1) |
---|
5110 | { |
---|
5111 | *p1 = c2; |
---|
5112 | break; |
---|
5113 | } |
---|
5114 | p1++; |
---|
5115 | } |
---|
5116 | |
---|
5117 | return str; |
---|
5118 | } |
---|
5119 | |
---|
5120 | char* stringreplacechar(char *str, char c1, char c2) |
---|
5121 | { |
---|
5122 | char *p1 = str; |
---|
5123 | |
---|
5124 | if(str == NULL) return NULL; |
---|
5125 | |
---|
5126 | while(*p1 != '\0') |
---|
5127 | { |
---|
5128 | if(*p1 == c1) *p1 = c2; |
---|
5129 | p1++; |
---|
5130 | } |
---|
5131 | |
---|
5132 | return str; |
---|
5133 | } |
---|
5134 | |
---|
5135 | |
---|
5136 | char* string_removechar(char *str) |
---|
5137 | { |
---|
5138 | char *p1 = str; |
---|
5139 | |
---|
5140 | if(str == NULL) return NULL; |
---|
5141 | |
---|
5142 | while(*p1 != '\0') |
---|
5143 | { |
---|
5144 | if(*p1 == '.') *p1 = ' '; |
---|
5145 | else if(*p1 == '-') *p1 = ' '; |
---|
5146 | else if(*p1 == '_') *p1 = ' '; |
---|
5147 | else if(*p1 == '/') *p1 = ' '; |
---|
5148 | p1++; |
---|
5149 | } |
---|
5150 | |
---|
5151 | return str; |
---|
5152 | } |
---|
5153 | |
---|
5154 | char* string_withchars2return(char *str) |
---|
5155 | { |
---|
5156 | char *p1 = str; |
---|
5157 | |
---|
5158 | if(str == NULL) return NULL; |
---|
5159 | |
---|
5160 | while(*p1 != '\0') |
---|
5161 | { |
---|
5162 | if(*p1 == ' ') *p1 = '\n'; |
---|
5163 | p1++; |
---|
5164 | } |
---|
5165 | |
---|
5166 | return str; |
---|
5167 | } |
---|
5168 | |
---|
5169 | char* string_remove_whitechars(char *text) |
---|
5170 | { |
---|
5171 | char *p1 = text, *p2 = text; |
---|
5172 | |
---|
5173 | if(text == NULL) return NULL; |
---|
5174 | |
---|
5175 | while(*p1 != '\0') |
---|
5176 | { |
---|
5177 | if(*p1 == ' ') |
---|
5178 | ++p1; |
---|
5179 | else |
---|
5180 | *p2++ = *p1++; |
---|
5181 | } |
---|
5182 | *p2 = '\0'; |
---|
5183 | |
---|
5184 | return text; |
---|
5185 | } |
---|
5186 | |
---|
5187 | char* strstrip(char *text) |
---|
5188 | { |
---|
5189 | char* tmpstr = text; |
---|
5190 | |
---|
5191 | if(text == NULL) return NULL; |
---|
5192 | int len = strlen(text); |
---|
5193 | |
---|
5194 | while(isspace(tmpstr[len - 1])) tmpstr[--len] = '\0'; |
---|
5195 | while(*tmpstr && isspace(*tmpstr)) ++tmpstr, --len; |
---|
5196 | |
---|
5197 | if(text != tmpstr) memmove(text, tmpstr, len + 1); |
---|
5198 | |
---|
5199 | return text; |
---|
5200 | } |
---|
5201 | |
---|
5202 | char* string_strip_whitechars(char *text) |
---|
5203 | { |
---|
5204 | char *p1 = text, *p2 = text; |
---|
5205 | |
---|
5206 | if(text == NULL) |
---|
5207 | return NULL; |
---|
5208 | |
---|
5209 | while(*p1 != '\0') |
---|
5210 | { |
---|
5211 | if(*p1 == ' ' && *(p1 + 1) == ' ') |
---|
5212 | ++p1; |
---|
5213 | else |
---|
5214 | *p2++ = *p1++; |
---|
5215 | } |
---|
5216 | *p2 = '\0'; |
---|
5217 | |
---|
5218 | return text; |
---|
5219 | } |
---|
5220 | |
---|
5221 | char* string_replace_all(char *search, char *replace, char *string, int free1) |
---|
5222 | { |
---|
5223 | char* tmpstr = NULL; |
---|
5224 | char* searchpos = NULL; |
---|
5225 | |
---|
5226 | if(string == NULL || search == NULL) |
---|
5227 | { |
---|
5228 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5229 | if(free1 == 1) free(string); |
---|
5230 | return tmpstr; |
---|
5231 | } |
---|
5232 | |
---|
5233 | searchpos = strstr(string, search); |
---|
5234 | if(searchpos == NULL) |
---|
5235 | { |
---|
5236 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5237 | if(free1 == 1) free(string); |
---|
5238 | return tmpstr; |
---|
5239 | } |
---|
5240 | |
---|
5241 | int count = 0; |
---|
5242 | int stringlen = strlen(string); |
---|
5243 | int searchlen = strlen(search); |
---|
5244 | int replacelen = strlen(replace); |
---|
5245 | |
---|
5246 | while(searchpos != NULL) |
---|
5247 | { |
---|
5248 | count++; |
---|
5249 | searchpos = strstr(searchpos + searchlen, search); |
---|
5250 | } |
---|
5251 | |
---|
5252 | int len = stringlen - (searchlen * count) + (replacelen * count); |
---|
5253 | tmpstr = calloc(1, len + 1); |
---|
5254 | if(tmpstr == NULL) |
---|
5255 | { |
---|
5256 | err("no mem"); |
---|
5257 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5258 | if(free1 == 1) free(string); |
---|
5259 | return tmpstr; |
---|
5260 | } |
---|
5261 | |
---|
5262 | len = 0; |
---|
5263 | char* str = string; |
---|
5264 | char* tmp = tmpstr; |
---|
5265 | searchpos = strstr(str, search); |
---|
5266 | while(searchpos != NULL) |
---|
5267 | { |
---|
5268 | len = searchpos - str; |
---|
5269 | memcpy(tmp, str, len); |
---|
5270 | memcpy(tmp + len, replace, replacelen); |
---|
5271 | tmp += len + replacelen; |
---|
5272 | str += len + searchlen; |
---|
5273 | searchpos = strstr(str, search); |
---|
5274 | } |
---|
5275 | memcpy(tmp, str, strlen(str)); |
---|
5276 | |
---|
5277 | if(free1 == 1) free(string); |
---|
5278 | |
---|
5279 | return tmpstr; |
---|
5280 | } |
---|
5281 | |
---|
5282 | char* string_replace_remove_last_chars(char *search, char *replace, char *string, int free1) |
---|
5283 | { |
---|
5284 | char* searchpos = NULL; |
---|
5285 | char* tmpstr = NULL; |
---|
5286 | |
---|
5287 | if(string == NULL || search == NULL) |
---|
5288 | { |
---|
5289 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5290 | if(free1 == 1) free(string); |
---|
5291 | return tmpstr; |
---|
5292 | } |
---|
5293 | |
---|
5294 | searchpos = ostrstr(string, search); |
---|
5295 | |
---|
5296 | if(searchpos == NULL) |
---|
5297 | { |
---|
5298 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5299 | if(free1 == 1) free(string); |
---|
5300 | return tmpstr; |
---|
5301 | } |
---|
5302 | |
---|
5303 | tmpstr = strndup(string, searchpos - string); |
---|
5304 | if(replace != NULL) |
---|
5305 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
5306 | |
---|
5307 | if(free1 == 1) free(string); |
---|
5308 | |
---|
5309 | return tmpstr; |
---|
5310 | } |
---|
5311 | |
---|
5312 | char* string_replace(char *search, char *replace, char *string, int free1) |
---|
5313 | { |
---|
5314 | char* searchpos = NULL; |
---|
5315 | char* tmpstr = NULL; |
---|
5316 | |
---|
5317 | if(string == NULL || search == NULL) |
---|
5318 | { |
---|
5319 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5320 | if(free1 == 1) free(string); |
---|
5321 | return tmpstr; |
---|
5322 | } |
---|
5323 | |
---|
5324 | searchpos = ostrstr(string, search); |
---|
5325 | |
---|
5326 | if(searchpos == NULL) |
---|
5327 | { |
---|
5328 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
5329 | if(free1 == 1) free(string); |
---|
5330 | return tmpstr; |
---|
5331 | } |
---|
5332 | |
---|
5333 | tmpstr = strndup(string, searchpos - string); |
---|
5334 | if(replace != NULL) |
---|
5335 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
5336 | tmpstr = ostrcat(tmpstr, string + (searchpos - string) + strlen(search), 1, 0); |
---|
5337 | |
---|
5338 | if(free1 == 1) free(string); |
---|
5339 | |
---|
5340 | return tmpstr; |
---|
5341 | } |
---|
5342 | |
---|
5343 | //flag 0: search full str |
---|
5344 | //flag 1: search only end of string |
---|
5345 | char* ostrrstrcase(char* str, char* search, int len, int flag) |
---|
5346 | { |
---|
5347 | int slen = 0; |
---|
5348 | char* tmpstr = NULL; |
---|
5349 | |
---|
5350 | if(str == NULL || search == NULL) return NULL; |
---|
5351 | |
---|
5352 | if(len == -1) len = strlen(str); |
---|
5353 | slen = strlen(search); |
---|
5354 | if(slen > len) return NULL; |
---|
5355 | |
---|
5356 | for(tmpstr = str + len - slen; tmpstr >= str; tmpstr--) |
---|
5357 | { |
---|
5358 | if(strncasecmp(tmpstr, search, slen) == 0) |
---|
5359 | return tmpstr; |
---|
5360 | if(flag == 1) return NULL; |
---|
5361 | } |
---|
5362 | |
---|
5363 | return NULL; |
---|
5364 | } |
---|
5365 | |
---|
5366 | //flag 0: search full str |
---|
5367 | //flag 1: search only end of string |
---|
5368 | char* ostrrstr(char* str, char* search, int len, int flag) |
---|
5369 | { |
---|
5370 | int slen = 0; |
---|
5371 | char* tmpstr = NULL; |
---|
5372 | |
---|
5373 | if(str == NULL || search == NULL) return NULL; |
---|
5374 | |
---|
5375 | if(len == -1) len = strlen(str); |
---|
5376 | slen = strlen(search); |
---|
5377 | if(slen > len) return NULL; |
---|
5378 | |
---|
5379 | for(tmpstr = str + len - slen; tmpstr >= str; tmpstr--) |
---|
5380 | { |
---|
5381 | if(strncmp(tmpstr, search, slen) == 0) |
---|
5382 | return tmpstr; |
---|
5383 | if(flag == 1) return NULL; |
---|
5384 | } |
---|
5385 | |
---|
5386 | return NULL; |
---|
5387 | } |
---|
5388 | |
---|
5389 | char* ostrstr(char* str, char* search) |
---|
5390 | { |
---|
5391 | char* ret = NULL; |
---|
5392 | |
---|
5393 | if(str == NULL || search == NULL) return NULL; |
---|
5394 | ret = strstr(str, search); |
---|
5395 | |
---|
5396 | return ret; |
---|
5397 | } |
---|
5398 | |
---|
5399 | int file_exist(char* filename) |
---|
5400 | { |
---|
5401 | if(access(filename, F_OK) == 0) |
---|
5402 | return 1; |
---|
5403 | else |
---|
5404 | return 0; |
---|
5405 | } |
---|
5406 | |
---|
5407 | char* string_newline(char* str) |
---|
5408 | { |
---|
5409 | if(str == NULL) return NULL; |
---|
5410 | |
---|
5411 | int size = strlen(str); |
---|
5412 | |
---|
5413 | if(str[size - 1] == '\n') |
---|
5414 | str[size - 1] = '\0'; |
---|
5415 | |
---|
5416 | return str; |
---|
5417 | } |
---|
5418 | |
---|
5419 | char* string_quote(char* str) |
---|
5420 | { |
---|
5421 | char* tmpstr = NULL; |
---|
5422 | |
---|
5423 | tmpstr = ostrcat("\"", str, 0, 0); |
---|
5424 | tmpstr = ostrcat(tmpstr, "\"", 1, 0); |
---|
5425 | |
---|
5426 | return tmpstr; |
---|
5427 | } |
---|
5428 | |
---|
5429 | struct splitstr* strsplit(char *str, char *tok, int* count) |
---|
5430 | { |
---|
5431 | char *tmpstr = NULL; |
---|
5432 | struct splitstr *array = NULL, *tmparray = NULL; |
---|
5433 | *count = 0; |
---|
5434 | |
---|
5435 | if(str == NULL || tok == NULL) |
---|
5436 | return NULL; |
---|
5437 | |
---|
5438 | tmpstr = strtok(str, tok); |
---|
5439 | while(tmpstr != NULL) |
---|
5440 | { |
---|
5441 | *count = *count + 1; |
---|
5442 | tmparray = array; array = (struct splitstr*)realloc(array, sizeof(struct splitstr*) * (*count)); |
---|
5443 | if(array == NULL) |
---|
5444 | { |
---|
5445 | err("no mem"); |
---|
5446 | free(tmparray); |
---|
5447 | return NULL; |
---|
5448 | } |
---|
5449 | |
---|
5450 | (&array[(*count) - 1])->part = tmpstr; |
---|
5451 | tmpstr = strtok(NULL, tok); |
---|
5452 | } |
---|
5453 | |
---|
5454 | return array; |
---|
5455 | } |
---|
5456 | |
---|
5457 | char* string_shortname(char *tmpfilename, int mode) |
---|
5458 | { |
---|
5459 | debug(50, "in %s", tmpfilename); |
---|
5460 | |
---|
5461 | // char replacelist[] = "avi mkv x264 se disc0 disc1 disc2 disc3 disc4 0disc 1disc 2disc 3disc 4disc season0 season1 season2 season3 season4 season5 season6 season7 season8 season9 hdtv 720p 1080i 1080p uncut cd0 cd1 cd2 cd3 cd4 cd5 cd6 cd7 cd8 cd9 dvd0 dvd1 dvd2 dvd3 dvd4 ac3d ac3 bdrip bluray cam camrip complete custom cut dc directors dl doku dts dvdr dvdrip dvdscr dvdscreener extended french finnish german hd hddvd hddvdrip hdtv int internal int ld limited multi multisubs nordic ntsc pal pl r1 r5 recut remastered repack rip screener se see special.edition sse stv subbed swedish staffel tc telecine telesync ts unrated ws xxx italian"; |
---|
5462 | char* str = NULL; |
---|
5463 | |
---|
5464 | if(mode==1) |
---|
5465 | { |
---|
5466 | char* replacelist = "avi mkv x264 xvid se uncut ac3d ac3hd ac3 bdrip bluray cam camrip complete custom cut dc directors dl doku dts dvdr dvdrip dvdscr dvdscreener ecc extended french finnish german hd hddvd hddvdrip hdtv int internal int ld limited multi multisubs nordic ntsc pal pl r1 r5 recut remastered repack rip screener se see sse stv subbed swedish staffel tc telecine telesync ts unrated ws xxx italian"; |
---|
5467 | str = ostrcat(str, replacelist, 1, 0); |
---|
5468 | } |
---|
5469 | else if(mode==2) |
---|
5470 | { |
---|
5471 | char* replacelist = "1080i 1080p 720p ac3 ac3d ac3hd avi bdrip bluray cam camrip complete custom cut dat dc directors divx dl doku dts dvdr dvdrip dvdscr dvdscreener ecc ed extended finnish flv french german hd hddvd hddvdrip hdtv int internal ld limited linedubbed m2ts m4v md mkv mov mp4 mpeg mpg mts multi multisubs nordic ntsc pal pl proper r1 r3 r5 recut remastered repack rip rm screener se sse staffel stv subbed svcd swedish tc telecine telesync trp ts uc uncut unrated ur vcd vdr vob wmv ws x264 xvid xxx"; |
---|
5472 | str = ostrcat(str, replacelist, 1, 0); |
---|
5473 | } |
---|
5474 | else |
---|
5475 | { |
---|
5476 | char* replacelist = "disc0 disc1 disc2 disc3 disc4 0disc 1disc 2disc 3disc 4disc season0 season1 season2 season3 season4 season5 season6 season7 season8 season9 hdtv 720p 1080i 1080p cd0 cd1 cd2 cd3 cd4 cd5 cd6 cd7 cd8 cd9 dvd0 dvd1 dvd2 dvd3 dvd4"; |
---|
5477 | str = ostrcat(str, replacelist, 1, 0); |
---|
5478 | } |
---|
5479 | |
---|
5480 | char* replace = NULL; |
---|
5481 | struct splitstr* ret1 = NULL; |
---|
5482 | int count = 0; |
---|
5483 | int i = 0; |
---|
5484 | ret1 = strsplit(str, " ", &count); |
---|
5485 | int max = count - 1; |
---|
5486 | int first = 1; |
---|
5487 | |
---|
5488 | for(i = 0; i < max; i++) |
---|
5489 | { |
---|
5490 | struct splitstr* ret2 = NULL; |
---|
5491 | int count2 = 0; |
---|
5492 | int j = 0; |
---|
5493 | char *tmpstr = NULL; |
---|
5494 | tmpstr = ostrcat(tmpstr, tmpfilename, 1, 0); |
---|
5495 | ret2 = strsplit(tmpstr, " ,.-_", &count2); |
---|
5496 | |
---|
5497 | for(j = 0; j < count2; j++) |
---|
5498 | { |
---|
5499 | if(j > 0) |
---|
5500 | { |
---|
5501 | if(ostrcmp((&ret1[i])->part, (&ret2[j])->part) == 0) |
---|
5502 | { |
---|
5503 | if(mode==1) |
---|
5504 | { |
---|
5505 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
5506 | continue; |
---|
5507 | } |
---|
5508 | else if(mode==2) |
---|
5509 | { |
---|
5510 | tmpfilename = string_replace_remove_last_chars((&ret2[j])->part, replace, tmpfilename, 1); |
---|
5511 | //break; |
---|
5512 | continue; |
---|
5513 | } |
---|
5514 | else |
---|
5515 | { |
---|
5516 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
5517 | continue; |
---|
5518 | } |
---|
5519 | } |
---|
5520 | else if(first == 1 && mode == 2) |
---|
5521 | { |
---|
5522 | // printf("zahl: %s\n", (&ret2[j])->part); |
---|
5523 | int theCharacter = atoi((&ret2[j])->part); |
---|
5524 | if(theCharacter != 0) |
---|
5525 | { |
---|
5526 | // printf("found zahl: %s\n", (&ret2[j])->part); |
---|
5527 | if(theCharacter > 1800 && theCharacter < 2100) |
---|
5528 | { |
---|
5529 | // printf("found year: %s\n", (&ret2[j])->part); |
---|
5530 | tmpfilename = string_replace_remove_last_chars((&ret2[j])->part, "", tmpfilename, 1); |
---|
5531 | break; |
---|
5532 | } |
---|
5533 | } |
---|
5534 | } |
---|
5535 | } |
---|
5536 | } |
---|
5537 | free(ret2); ret2 = NULL; |
---|
5538 | first = 0; |
---|
5539 | free(tmpstr), tmpstr = NULL; |
---|
5540 | } |
---|
5541 | |
---|
5542 | free(ret1); ret1 = NULL; |
---|
5543 | free(replace); replace = NULL; |
---|
5544 | free(str); str = NULL; |
---|
5545 | |
---|
5546 | debug(50, "out %s", tmpfilename); |
---|
5547 | return tmpfilename; |
---|
5548 | } |
---|
5549 | |
---|
5550 | char* get_uuid(char* device) |
---|
5551 | { |
---|
5552 | debug(60, "in %s", device); |
---|
5553 | char* cmd = NULL, *tmpstr = NULL; |
---|
5554 | |
---|
5555 | if(device == NULL) return NULL; |
---|
5556 | #ifdef MIPSEL |
---|
5557 | cmd = ostrcat(cmd, "blkid -w /dev/null -c /dev/null -s UUID /dev/", 1, 0); |
---|
5558 | #else |
---|
5559 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s UUID /dev/", 1, 0); |
---|
5560 | #endif |
---|
5561 | cmd = ostrcat(cmd, device, 1, 0); |
---|
5562 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
5563 | |
---|
5564 | tmpstr = string_newline(command(cmd)); |
---|
5565 | |
---|
5566 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
5567 | { |
---|
5568 | free(tmpstr); tmpstr = NULL; |
---|
5569 | } |
---|
5570 | |
---|
5571 | debug(60, "out %s", cmd); |
---|
5572 | free(cmd); cmd = NULL; |
---|
5573 | return tmpstr; |
---|
5574 | } |
---|
5575 | |
---|
5576 | char* get_label(char* device) |
---|
5577 | { |
---|
5578 | debug(60, "in %s", device); |
---|
5579 | char* cmd = NULL, *tmpstr = NULL; |
---|
5580 | |
---|
5581 | if(device == NULL) return NULL; |
---|
5582 | #ifdef MIPSEL |
---|
5583 | cmd = ostrcat(cmd, "blkid -w /dev/null -c /dev/null -s LABEL /dev/", 1, 0); |
---|
5584 | #else |
---|
5585 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s LABEL /dev/", 1, 0); |
---|
5586 | #endif |
---|
5587 | cmd = ostrcat(cmd, device, 1, 0); |
---|
5588 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
5589 | |
---|
5590 | tmpstr = string_newline(command(cmd)); |
---|
5591 | |
---|
5592 | if(tmpstr == NULL) |
---|
5593 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
5594 | |
---|
5595 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
5596 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
5597 | |
---|
5598 | debug(60, "out %s", cmd); |
---|
5599 | free(cmd); cmd = NULL; |
---|
5600 | return tmpstr; |
---|
5601 | } |
---|
5602 | |
---|
5603 | char* get_filesystem(char* device) |
---|
5604 | { |
---|
5605 | debug(60, "in %s", device); |
---|
5606 | char* cmd = NULL, *tmpstr = NULL; |
---|
5607 | |
---|
5608 | if(device == NULL) return NULL; |
---|
5609 | #ifdef MIPSEL |
---|
5610 | cmd = ostrcat(cmd, "blkid -w /dev/null -c /dev/null -s TYPE /dev/", 1, 0); |
---|
5611 | #else |
---|
5612 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s TYPE /dev/", 1, 0); |
---|
5613 | #endif |
---|
5614 | cmd = ostrcat(cmd, device, 1, 0); |
---|
5615 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
5616 | |
---|
5617 | tmpstr = string_newline(command(cmd)); |
---|
5618 | |
---|
5619 | if(tmpstr == NULL) |
---|
5620 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
5621 | |
---|
5622 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
5623 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
5624 | |
---|
5625 | debug(60, "out %s", cmd); |
---|
5626 | free(cmd); cmd = NULL; |
---|
5627 | return tmpstr; |
---|
5628 | } |
---|
5629 | |
---|
5630 | //flag 0: convert ip to 000.000.000.000 |
---|
5631 | //flag 1: convert ip to 0.0.0.0 |
---|
5632 | char* fixip(char* ipinput, int flag) |
---|
5633 | { |
---|
5634 | debug(60, "in %s", ipinput); |
---|
5635 | int ret = 0; |
---|
5636 | char* ipout = NULL; |
---|
5637 | unsigned char ip[4]; |
---|
5638 | |
---|
5639 | ip[0] = 0; |
---|
5640 | ip[1] = 0; |
---|
5641 | ip[2] = 0; |
---|
5642 | ip[3] = 0; |
---|
5643 | |
---|
5644 | if(ipinput == NULL) return NULL; |
---|
5645 | ret = sscanf(ipinput, "%hhu.%hhu.%hhu.%hhu", &ip[0], &ip[1], &ip[2], &ip[3]); |
---|
5646 | if(ret != 4) return NULL; |
---|
5647 | |
---|
5648 | ipout = malloc(16); |
---|
5649 | if(ipout == NULL) |
---|
5650 | { |
---|
5651 | err("no mem"); |
---|
5652 | return NULL; |
---|
5653 | } |
---|
5654 | |
---|
5655 | if(flag == 1) |
---|
5656 | snprintf(ipout, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
---|
5657 | else |
---|
5658 | snprintf(ipout, 16, "%03d.%03d.%03d.%03d", ip[0], ip[1], ip[2], ip[3]); |
---|
5659 | |
---|
5660 | return ipout; |
---|
5661 | } |
---|
5662 | |
---|
5663 | void setfanspeed(int speed, int aktion) |
---|
5664 | { |
---|
5665 | char* speedWert = NULL; |
---|
5666 | char* speedSet = NULL; |
---|
5667 | int base = 0; |
---|
5668 | |
---|
5669 | if(checkbox("UFS922") == 1) |
---|
5670 | base = 100; |
---|
5671 | else |
---|
5672 | base = -15; |
---|
5673 | |
---|
5674 | |
---|
5675 | if(speed < 0) |
---|
5676 | { |
---|
5677 | if(speed == -1) |
---|
5678 | speedWert = getconfig("fanspeed", NULL); |
---|
5679 | else |
---|
5680 | speedWert = getconfig("fanspeedstandby", NULL); |
---|
5681 | if(speedWert == NULL) |
---|
5682 | speedSet = ostrcat(speedSet, oitoa(base + 70), 1, 1); |
---|
5683 | else |
---|
5684 | speedSet = ostrcat(speedSet, speedWert, 1, 0); |
---|
5685 | } |
---|
5686 | else |
---|
5687 | { |
---|
5688 | if(speed == 0) |
---|
5689 | speedSet = ostrcat(speedSet, oitoa(base + 15), 1, 1); |
---|
5690 | else if(speed == 25) |
---|
5691 | speedSet = ostrcat(speedSet, oitoa(base + 30), 1, 1); |
---|
5692 | else if(speed == 50) |
---|
5693 | speedSet = ostrcat(speedSet, oitoa(base + 45), 1, 1); |
---|
5694 | else if(speed == 75) |
---|
5695 | speedSet = ostrcat(speedSet, oitoa(base + 55), 1, 1); |
---|
5696 | else |
---|
5697 | speedSet = ostrcat(speedSet, oitoa(base + 70), 1, 1); |
---|
5698 | } |
---|
5699 | |
---|
5700 | if(checkbox("UFS922") == 1) |
---|
5701 | writesys("/proc/stb/fan/fan_ctrl", speedSet, 1); |
---|
5702 | else |
---|
5703 | writesys("/proc/stb/fp/fan_pwm", speedSet, 1); |
---|
5704 | |
---|
5705 | if(aktion == 1) |
---|
5706 | addconfig("fanspeed", speedSet); |
---|
5707 | else if(aktion == 2) |
---|
5708 | addconfig("fanspeedstandby", speedSet); |
---|
5709 | |
---|
5710 | free(speedSet); speedSet=NULL; |
---|
5711 | } |
---|
5712 | |
---|
5713 | void setaktres() |
---|
5714 | { |
---|
5715 | int m_width = 0; |
---|
5716 | char* res = NULL; |
---|
5717 | char* res_akt = NULL; |
---|
5718 | char* res_sd = NULL; |
---|
5719 | int count = 1; |
---|
5720 | int sec = 0; |
---|
5721 | |
---|
5722 | m_lock(&status.setaktresmutex, 23); |
---|
5723 | |
---|
5724 | if(status.restimer == NULL) |
---|
5725 | goto end; |
---|
5726 | |
---|
5727 | sec = (int)status.restimer->param1; |
---|
5728 | |
---|
5729 | if(sec > 0) |
---|
5730 | { |
---|
5731 | while(status.restimer->aktion == START && count <= (sec * 10)) |
---|
5732 | { |
---|
5733 | usleep(100000); |
---|
5734 | if(status.restimer->aktion != START) |
---|
5735 | goto end; |
---|
5736 | count++; |
---|
5737 | } |
---|
5738 | } |
---|
5739 | if(status.restimer->aktion != START) goto end; |
---|
5740 | |
---|
5741 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
5742 | { |
---|
5743 | if(status.restimer->aktion != START) goto end; |
---|
5744 | m_width = status.videosize.w; |
---|
5745 | if(m_width == 720) |
---|
5746 | { |
---|
5747 | res_sd = getconfig("av_videomode_autores_sd", NULL); |
---|
5748 | if(res_sd == NULL) |
---|
5749 | res = ostrcat(res, "576i50", 1, 0); |
---|
5750 | else |
---|
5751 | res = ostrcat(res, res_sd, 1, 0); |
---|
5752 | } |
---|
5753 | else if (m_width == 1280) |
---|
5754 | res = ostrcat(res, "720p50", 1, 0); |
---|
5755 | else if (m_width == 1920) |
---|
5756 | res = ostrcat(res, "1080i50", 1, 0); |
---|
5757 | else |
---|
5758 | m_width = 0; |
---|
5759 | |
---|
5760 | if(m_width > 0) |
---|
5761 | { |
---|
5762 | if(status.restimer->aktion != START) goto end; |
---|
5763 | res_akt = getvideomode(); |
---|
5764 | if(status.restimer->aktion != START) goto end; |
---|
5765 | if(ostrcmp(res_akt, res) != 0) |
---|
5766 | { |
---|
5767 | if(status.restimer->aktion != START) goto end; |
---|
5768 | setvideomode(res, 1); |
---|
5769 | changefbresolution(res, 1); |
---|
5770 | /* |
---|
5771 | if(status.restimer->aktion != START) goto end; |
---|
5772 | |
---|
5773 | count = 0; |
---|
5774 | while(status.restimer->aktion == START && count < 10) |
---|
5775 | { |
---|
5776 | usleep(100000); |
---|
5777 | if(status.restimer->aktion != START) |
---|
5778 | goto end; |
---|
5779 | count++; |
---|
5780 | } |
---|
5781 | |
---|
5782 | if(status.restimer->aktion != START) goto end; |
---|
5783 | */ |
---|
5784 | screenautores(res, 5, 0); |
---|
5785 | } |
---|
5786 | } |
---|
5787 | } |
---|
5788 | else |
---|
5789 | { |
---|
5790 | if(status.restimer->aktion != START) goto end; |
---|
5791 | if(status.servicetype == 0) |
---|
5792 | textbox(_("Message"), _("ERROR cant read res"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
5793 | } |
---|
5794 | |
---|
5795 | end: |
---|
5796 | free(res); res = NULL; |
---|
5797 | status.restimer = NULL; |
---|
5798 | m_unlock(&status.setaktresmutex, 23); |
---|
5799 | return; |
---|
5800 | } |
---|
5801 | |
---|
5802 | char* gettimestamp() |
---|
5803 | { |
---|
5804 | char* timestamp = NULL; |
---|
5805 | struct timeval numtime; |
---|
5806 | |
---|
5807 | gettimeofday(&numtime, 0); |
---|
5808 | timestamp = ostrcat(timestamp, olutoa(numtime.tv_sec), 1, 1); |
---|
5809 | timestamp = ostrcat(timestamp, olutoa(numtime.tv_usec), 1, 1); |
---|
5810 | |
---|
5811 | return timestamp; |
---|
5812 | } |
---|
5813 | |
---|
5814 | char* string_decode(char* input, int flag) |
---|
5815 | { |
---|
5816 | if(input == NULL) return input; |
---|
5817 | |
---|
5818 | while(ostrstr(input, "\\u00") != NULL) |
---|
5819 | { |
---|
5820 | debug(210, "input: %s", input); |
---|
5821 | input = string_replace("\\u00", "%", input, 1); |
---|
5822 | debug(210, "input: %s", input); |
---|
5823 | } |
---|
5824 | |
---|
5825 | while(ostrstr(input, "&") != NULL) |
---|
5826 | { |
---|
5827 | debug(210, "input: %s", input); |
---|
5828 | input = string_replace("&", "und", input, 1); |
---|
5829 | debug(210, "input: %s", input); |
---|
5830 | } |
---|
5831 | |
---|
5832 | while(ostrstr(input, ">") != NULL) |
---|
5833 | { |
---|
5834 | debug(210, "input: %s", input); |
---|
5835 | input = string_replace(">", ">", input, 1); |
---|
5836 | debug(210, "input: %s", input); |
---|
5837 | } |
---|
5838 | |
---|
5839 | while(ostrstr(input, "<") != NULL) |
---|
5840 | { |
---|
5841 | debug(210, "input: %s", input); |
---|
5842 | input = string_replace("<", "<", input, 1); |
---|
5843 | debug(210, "input: %s", input); |
---|
5844 | } |
---|
5845 | |
---|
5846 | while(ostrstr(input, """) != NULL) |
---|
5847 | { |
---|
5848 | debug(210, "input: %s", input); |
---|
5849 | input = string_replace(""", "\"", input, 1); |
---|
5850 | debug(210, "input: %s", input); |
---|
5851 | } |
---|
5852 | |
---|
5853 | while(ostrstr(input, "&#x") != NULL) |
---|
5854 | { |
---|
5855 | debug(210, "out %s", input); |
---|
5856 | input = string_replace("&#x", "%", input, 1); |
---|
5857 | debug(210, "input: %s", input); |
---|
5858 | } |
---|
5859 | |
---|
5860 | while(ostrstr(input, "&#") != NULL) |
---|
5861 | { |
---|
5862 | debug(210, "input: %s", input); |
---|
5863 | input = string_replace("&#", "%", input, 1); |
---|
5864 | debug(210, "input: %s", input); |
---|
5865 | } |
---|
5866 | |
---|
5867 | if(flag == 1) |
---|
5868 | htmldecode2(input, input); |
---|
5869 | else |
---|
5870 | htmldecode(input, input); |
---|
5871 | |
---|
5872 | while(ostrstr(input, ";") != NULL) |
---|
5873 | { |
---|
5874 | debug(210, "input: %s", input); |
---|
5875 | input = string_replace(";", NULL, input, 1); |
---|
5876 | debug(210, "input: %s", input); |
---|
5877 | } |
---|
5878 | |
---|
5879 | return input; |
---|
5880 | } |
---|
5881 | |
---|
5882 | char* string_deltags(char* str) |
---|
5883 | { |
---|
5884 | int i = 0, y = 0, len = 0; |
---|
5885 | |
---|
5886 | if(str == NULL) return 0; |
---|
5887 | |
---|
5888 | len = strlen(str); |
---|
5889 | |
---|
5890 | int skip = 0; |
---|
5891 | for(i = 0; i < len; i++) |
---|
5892 | { |
---|
5893 | if(str[i] == '<') |
---|
5894 | skip = 1; |
---|
5895 | else if(str[i] == '>') |
---|
5896 | skip = 0; |
---|
5897 | |
---|
5898 | if(skip == 0 && str[i] != '>') |
---|
5899 | { |
---|
5900 | str[y] = str[i]; |
---|
5901 | y++; |
---|
5902 | } |
---|
5903 | } |
---|
5904 | str[y] = '\0'; |
---|
5905 | |
---|
5906 | return str; |
---|
5907 | } |
---|
5908 | |
---|
5909 | char* string_striptags(char* str) |
---|
5910 | { |
---|
5911 | int i = 0, len = 0; |
---|
5912 | |
---|
5913 | if(str == NULL) return 0; |
---|
5914 | |
---|
5915 | len = strlen(str); |
---|
5916 | |
---|
5917 | int skip = 0; |
---|
5918 | for(i = 0; i < len; i++) |
---|
5919 | { |
---|
5920 | if(str[i] == '<') |
---|
5921 | skip = 1; |
---|
5922 | else if(str[i] == '>') |
---|
5923 | { |
---|
5924 | skip = 0; |
---|
5925 | str[i] = ' '; |
---|
5926 | } |
---|
5927 | if(skip == 1) |
---|
5928 | str[i] = ' '; |
---|
5929 | } |
---|
5930 | |
---|
5931 | return strstrip(str); |
---|
5932 | } |
---|
5933 | |
---|
5934 | char* string_resub(char* str, char* str2, char* input, int dir) |
---|
5935 | { |
---|
5936 | char* tmpstr = NULL, *pos = NULL, *pos2 = NULL; |
---|
5937 | |
---|
5938 | if(str == NULL || str2 == NULL || input == NULL) return NULL; |
---|
5939 | |
---|
5940 | if(dir == 0) |
---|
5941 | { |
---|
5942 | pos = ostrstr(input, str); |
---|
5943 | if(pos == NULL) return NULL; |
---|
5944 | pos += strlen(str); |
---|
5945 | |
---|
5946 | pos2 = ostrstr(pos, str2); |
---|
5947 | if(pos2 == NULL) return NULL; |
---|
5948 | } |
---|
5949 | else |
---|
5950 | { |
---|
5951 | pos2 = ostrstr(input, str2); |
---|
5952 | if(pos2 == NULL) return NULL; |
---|
5953 | |
---|
5954 | pos = ostrrstr(input, str, pos2 - input, 0); |
---|
5955 | if(pos == NULL) return NULL; |
---|
5956 | pos += strlen(str); |
---|
5957 | } |
---|
5958 | |
---|
5959 | tmpstr = strndup(pos, pos2 - pos); |
---|
5960 | |
---|
5961 | return strstrip(tmpstr); |
---|
5962 | } |
---|
5963 | |
---|
5964 | char* ostrstrcase(char* str, char* sub) |
---|
5965 | { |
---|
5966 | size_t len = 0; |
---|
5967 | |
---|
5968 | if(str == NULL || sub == NULL) return NULL; |
---|
5969 | |
---|
5970 | len = strlen(sub); |
---|
5971 | while(*str) |
---|
5972 | { |
---|
5973 | if(toupper(*str) == toupper(*sub) && strncasecmp(str, sub, len) == 0) |
---|
5974 | return str; |
---|
5975 | ++str; |
---|
5976 | } |
---|
5977 | return NULL; |
---|
5978 | } |
---|
5979 | |
---|
5980 | //flag 0: convert port to 00021 |
---|
5981 | //flag 1: convert port to 21 |
---|
5982 | char* fixport(char* input, int flag) |
---|
5983 | { |
---|
5984 | char* tmpstr = NULL; |
---|
5985 | |
---|
5986 | if(flag == 0) |
---|
5987 | { |
---|
5988 | int plen = strlen(input); |
---|
5989 | if(plen < 5) |
---|
5990 | { |
---|
5991 | int i; |
---|
5992 | for(i = 0; i < 5 - plen; i++) |
---|
5993 | tmpstr = ostrcat(tmpstr, "0", 1, 0); |
---|
5994 | } |
---|
5995 | tmpstr = ostrcat(tmpstr, input, 1, 0); |
---|
5996 | } |
---|
5997 | else |
---|
5998 | { |
---|
5999 | while (*input && *input == '0') |
---|
6000 | input++; |
---|
6001 | |
---|
6002 | tmpstr = ostrcat(tmpstr, input, 1, 0); |
---|
6003 | } |
---|
6004 | return tmpstr; |
---|
6005 | } |
---|
6006 | |
---|
6007 | //flag 0: Mon > Montag |
---|
6008 | //flag 1: Mon > Mon |
---|
6009 | char* translate_time(char* input, int flag) |
---|
6010 | { |
---|
6011 | char* tmpstr = NULL; |
---|
6012 | if(input == NULL) return tmpstr; |
---|
6013 | tmpstr = ostrcat(tmpstr, input, 1, 1); |
---|
6014 | |
---|
6015 | if(flag == 0) |
---|
6016 | { |
---|
6017 | tmpstr = string_replace_all("Mon", _("Monday"), tmpstr, 1); |
---|
6018 | tmpstr = string_replace_all("Tue", _("Tuesday"), tmpstr, 1); |
---|
6019 | tmpstr = string_replace_all("Wed", _("Wednesday"), tmpstr, 1); |
---|
6020 | tmpstr = string_replace_all("Thu", _("Thursday"), tmpstr, 1); |
---|
6021 | tmpstr = string_replace_all("Fri", _("Friday"), tmpstr, 1); |
---|
6022 | tmpstr = string_replace_all("Sat", _("Saturday"), tmpstr, 1); |
---|
6023 | tmpstr = string_replace_all("Sun", _("Sunday"), tmpstr, 1); |
---|
6024 | } |
---|
6025 | else |
---|
6026 | { |
---|
6027 | tmpstr = string_replace("Mon", _("Mon"), tmpstr, 1); |
---|
6028 | tmpstr = string_replace("Tue", _("Tue"), tmpstr, 1); |
---|
6029 | tmpstr = string_replace("Wed", _("Wed"), tmpstr, 1); |
---|
6030 | tmpstr = string_replace("Thu", _("Thu"), tmpstr, 1); |
---|
6031 | tmpstr = string_replace("Fri", _("Fri"), tmpstr, 1); |
---|
6032 | tmpstr = string_replace("Sat", _("Sat"), tmpstr, 1); |
---|
6033 | tmpstr = string_replace("Sun", _("Sun"), tmpstr, 1); |
---|
6034 | } |
---|
6035 | |
---|
6036 | return tmpstr; |
---|
6037 | } |
---|
6038 | |
---|
6039 | char* gethypridtunerchoices(int dev) |
---|
6040 | { |
---|
6041 | char *hypridtunerchoices = NULL; |
---|
6042 | char *value = NULL; |
---|
6043 | char *tmpstr = NULL; |
---|
6044 | char *tmpstr1 = NULL; |
---|
6045 | char *tmpstr2 = NULL; |
---|
6046 | char *tmpstr3 = NULL; |
---|
6047 | char* start = NULL; |
---|
6048 | |
---|
6049 | hypridtunerchoices = getconfig("hypridtunerchoices", NULL); |
---|
6050 | |
---|
6051 | if(hypridtunerchoices == NULL) |
---|
6052 | { |
---|
6053 | err("NULL detect"); |
---|
6054 | return NULL; |
---|
6055 | } |
---|
6056 | |
---|
6057 | tmpstr = readfiletomem(hypridtunerchoices, 1); |
---|
6058 | if(tmpstr == NULL) |
---|
6059 | { |
---|
6060 | err("NULL detect"); |
---|
6061 | return NULL; |
---|
6062 | } |
---|
6063 | |
---|
6064 | start = ostrcat("NIM Socket ", oitoa(dev), 0, 0); |
---|
6065 | start = ostrcat(start, ":", 1, 0); |
---|
6066 | |
---|
6067 | tmpstr1 = string_resub(start, "I2C_Device", tmpstr, 0); |
---|
6068 | tmpstr2 = string_resub("Mode ", ":", tmpstr1, 0); |
---|
6069 | tmpstr3 = oregex(".*Mode ([0-9]{1}):.*", tmpstr1); |
---|
6070 | |
---|
6071 | if(tmpstr2 != NULL) |
---|
6072 | value = ostrcat(tmpstr2, "\n", 0, 0); |
---|
6073 | if(tmpstr3 != NULL) |
---|
6074 | value = ostrcat(value, tmpstr3, 1, 0); |
---|
6075 | |
---|
6076 | free(start), start = NULL; |
---|
6077 | free(tmpstr), tmpstr = NULL; |
---|
6078 | free(tmpstr1), tmpstr1 = NULL; |
---|
6079 | free(tmpstr2), tmpstr2 = NULL; |
---|
6080 | free(tmpstr3), tmpstr3 = NULL; |
---|
6081 | |
---|
6082 | return value; |
---|
6083 | } |
---|
6084 | |
---|
6085 | char* gethypridtunerchoicesvalue(int dev) |
---|
6086 | { |
---|
6087 | char* hypridtunerchoices = NULL, *value = NULL, *tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *hypridlist = NULL, *start = NULL; |
---|
6088 | |
---|
6089 | hypridtunerchoices = getconfig("hypridtunerchoices", NULL); |
---|
6090 | |
---|
6091 | if(hypridtunerchoices == NULL) |
---|
6092 | { |
---|
6093 | err("NULL detect"); |
---|
6094 | return NULL; |
---|
6095 | } |
---|
6096 | |
---|
6097 | tmpstr = readfiletomem(hypridtunerchoices, 1); |
---|
6098 | if(tmpstr == NULL) |
---|
6099 | { |
---|
6100 | err("NULL detect"); |
---|
6101 | return NULL; |
---|
6102 | } |
---|
6103 | |
---|
6104 | start = ostrcat("NIM Socket ", oitoa(dev), 0, 0); |
---|
6105 | start = ostrcat(start, ":", 1, 0); |
---|
6106 | tmpstr1 = string_resub(start, "I2C_Device", tmpstr, 0); |
---|
6107 | free(start), start = NULL; |
---|
6108 | |
---|
6109 | hypridlist = gethypridtunerchoices(dev); |
---|
6110 | |
---|
6111 | int count = 0; |
---|
6112 | int i = 0; |
---|
6113 | struct splitstr* ret1 = NULL; |
---|
6114 | ret1 = strsplit(hypridlist, "\n", &count); |
---|
6115 | |
---|
6116 | if(ret1 != NULL) |
---|
6117 | { |
---|
6118 | int max = count; |
---|
6119 | for(i = 0; i < max; i++) |
---|
6120 | { |
---|
6121 | start = ostrcat("Mode ", ret1[i].part, 0, 0); |
---|
6122 | start = ostrcat(start, ":", 1, 0); |
---|
6123 | tmpstr2 = string_resub(start, "\n", tmpstr1, 0); |
---|
6124 | |
---|
6125 | if(i > 0) |
---|
6126 | value = ostrcat(value, "\n", 1, 0); |
---|
6127 | |
---|
6128 | if(tmpstr2 != NULL) |
---|
6129 | value = ostrcat(value, tmpstr2, 1, 0); |
---|
6130 | |
---|
6131 | free(tmpstr2), tmpstr2 = NULL; |
---|
6132 | free(start), start = NULL; |
---|
6133 | } |
---|
6134 | } |
---|
6135 | free(ret1), ret1 = NULL; |
---|
6136 | free(tmpstr1), tmpstr1 = NULL; |
---|
6137 | free(hypridlist), hypridlist = NULL; |
---|
6138 | |
---|
6139 | return value; |
---|
6140 | } |
---|
6141 | |
---|
6142 | char* gethypridtunerchoicesvaluename(int dev, char* hyprid) |
---|
6143 | { |
---|
6144 | char* hypridtunerchoices = NULL, *value = NULL, *tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *start = NULL; |
---|
6145 | |
---|
6146 | hypridtunerchoices = getconfig("hypridtunerchoices", NULL); |
---|
6147 | |
---|
6148 | if(hypridtunerchoices == NULL) |
---|
6149 | { |
---|
6150 | err("NULL detect"); |
---|
6151 | return NULL; |
---|
6152 | } |
---|
6153 | |
---|
6154 | tmpstr = readfiletomem(hypridtunerchoices, 1); |
---|
6155 | if(tmpstr == NULL) |
---|
6156 | { |
---|
6157 | err("NULL detect"); |
---|
6158 | return NULL; |
---|
6159 | } |
---|
6160 | |
---|
6161 | start = ostrcat("NIM Socket ", oitoa(dev), 0, 0); |
---|
6162 | start = ostrcat(start, ":", 1, 0); |
---|
6163 | tmpstr1 = string_resub(start, "I2C_Device", tmpstr, 0); |
---|
6164 | free(start), start = NULL; |
---|
6165 | |
---|
6166 | start = ostrcat("Mode ", hyprid, 0, 0); |
---|
6167 | start = ostrcat(start, ":", 1, 0); |
---|
6168 | |
---|
6169 | tmpstr2 = string_resub(start, "\n", tmpstr1, 0); |
---|
6170 | |
---|
6171 | if(tmpstr2 != NULL) |
---|
6172 | value = ostrcat(value, tmpstr2, 1, 0); |
---|
6173 | |
---|
6174 | free(tmpstr1), tmpstr1 = NULL; |
---|
6175 | free(tmpstr2), tmpstr2 = NULL; |
---|
6176 | free(start), start = NULL; |
---|
6177 | |
---|
6178 | return value; |
---|
6179 | } |
---|
6180 | |
---|
6181 | int sethypridtuner(int dev, char* value) |
---|
6182 | { |
---|
6183 | char* buf = NULL, *hypridtuner = NULL, *tmpstr = NULL; |
---|
6184 | int ret = 0; |
---|
6185 | |
---|
6186 | hypridtuner = getconfig("hypridtuner", NULL); |
---|
6187 | |
---|
6188 | if(hypridtuner != NULL) |
---|
6189 | { |
---|
6190 | buf = malloc(MINMALLOC); |
---|
6191 | if(buf == NULL) |
---|
6192 | { |
---|
6193 | err("no memory"); |
---|
6194 | return 0; |
---|
6195 | } |
---|
6196 | } |
---|
6197 | |
---|
6198 | sprintf(buf, hypridtuner, dev); |
---|
6199 | if(buf != NULL) |
---|
6200 | { |
---|
6201 | printf("set %s to %s\n", buf, value); |
---|
6202 | ret = writesys(buf, value, 0); |
---|
6203 | free(tmpstr); tmpstr = NULL; |
---|
6204 | return ret; |
---|
6205 | } |
---|
6206 | |
---|
6207 | return 0; |
---|
6208 | } |
---|
6209 | |
---|
6210 | int phpkit_userauth(char* link, char* user, char* pass) |
---|
6211 | { |
---|
6212 | debug(99, "phpkit user: %s", user); |
---|
6213 | debug(99, "phpkit pass: %s", pass); |
---|
6214 | debug(99, "phpkit url: %s", link); |
---|
6215 | |
---|
6216 | int skip = 0; |
---|
6217 | char* ip = NULL, *tmphost = NULL, *tmppath = NULL, *tmpstr = NULL, *send = NULL, *hash = NULL, *cookie1 = NULL, *cookie2 = NULL, *tmplink = NULL, *pos = NULL, *path = NULL, *hashlen = NULL; |
---|
6218 | |
---|
6219 | tmplink = ostrcat(link, NULL, 0, 0); |
---|
6220 | |
---|
6221 | tmphost = string_replace("http://", "", tmplink, 0); |
---|
6222 | free(tmplink) , tmplink = NULL; |
---|
6223 | |
---|
6224 | if(tmphost != NULL) |
---|
6225 | pos = strchr(tmphost, '/'); |
---|
6226 | if(pos != NULL) |
---|
6227 | { |
---|
6228 | pos[0] = '\0'; |
---|
6229 | path = pos + 1; |
---|
6230 | } |
---|
6231 | |
---|
6232 | tmppath = ostrcat("/", path, 0, 0); |
---|
6233 | |
---|
6234 | send = ostrcat(send, "GET ", 1, 0); |
---|
6235 | send = ostrcat(send, tmppath, 1, 0); |
---|
6236 | send = ostrcat(send, " HTTP/1.1\r\nHost: ", 1, 0); |
---|
6237 | send = ostrcat(send, tmphost, 1, 0); |
---|
6238 | send = ostrcat(send, "\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.99 Safari/535.1\r\nConnection: close\r\nAccept-Encoding: gzip\r\n\r\n", 1, 0); |
---|
6239 | debug(99, "#############################################################################################################"); |
---|
6240 | debug(99, "send1: %s", send); |
---|
6241 | debug(99, "#############################################################################################################"); |
---|
6242 | |
---|
6243 | tmpstr = gethttpreal(tmphost, tmppath, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 1); |
---|
6244 | debug(99, "tmpstr: %s", tmpstr); |
---|
6245 | |
---|
6246 | free(send), send = NULL; |
---|
6247 | free(tmpstr), tmpstr = NULL; |
---|
6248 | |
---|
6249 | if(user == NULL || pass == NULL || link == NULL) return 1; |
---|
6250 | |
---|
6251 | hash = ostrcat("login=1&user=", user, 0, 0); |
---|
6252 | hash = ostrcat(hash, "&userpw=", 1, 0); |
---|
6253 | hash = ostrcat(hash, pass, 1, 1); |
---|
6254 | hashlen = oitoa(strlen(hash)); |
---|
6255 | |
---|
6256 | send = ostrcat(send, "POST ", 1, 0); |
---|
6257 | send = ostrcat(send, tmppath, 1, 0); |
---|
6258 | send = ostrcat(send, " HTTP/1.1\r\nContent-Length: ", 1, 0); |
---|
6259 | send = ostrcat(send, hashlen, 1, 0); |
---|
6260 | send = ostrcat(send, "\r\nAccept-Encoding: gzip\r\nConnection: close\r\nUser-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.99 Safari/535.1\r\nHost: ", 1, 0); |
---|
6261 | send = ostrcat(send, tmphost, 1, 0); |
---|
6262 | send = ostrcat(send, "\r\nCookie: pageredir=", 1, 0); |
---|
6263 | send = ostrcat(send, cookie1, 1, 0); |
---|
6264 | send = ostrcat(send, "; PHPSESSID=", 1, 0); |
---|
6265 | send = ostrcat(send, cookie2, 1, 0); |
---|
6266 | send = ostrcat(send, "\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n", 1, 0); |
---|
6267 | send = ostrcat(send, hash, 1, 0); |
---|
6268 | free(hash); hash = NULL; |
---|
6269 | free(hashlen); hashlen = NULL; |
---|
6270 | |
---|
6271 | debug(99, "#############################################################################################################"); |
---|
6272 | debug(99, "send1: %s", send); |
---|
6273 | debug(99, "#############################################################################################################"); |
---|
6274 | |
---|
6275 | tmpstr = gethttpreal(tmphost, tmppath, 80, NULL, NULL, NULL, 0, send, NULL, 5000, 1); |
---|
6276 | debug(99, "tmpstr: %s", tmpstr); |
---|
6277 | |
---|
6278 | free(cookie1); cookie1 = NULL; |
---|
6279 | free(cookie2); cookie2 = NULL; |
---|
6280 | free(tmphost); tmphost = NULL; |
---|
6281 | free(send); send = NULL; |
---|
6282 | free(ip); ip = NULL; |
---|
6283 | if(tmpstr == NULL) skip = 1; |
---|
6284 | free(tmpstr); tmpstr = NULL; |
---|
6285 | if(skip == 1) return 1; |
---|
6286 | return 0; |
---|
6287 | } |
---|
6288 | |
---|
6289 | void changetunername(struct skin* tunernode, int adapter, int devnr, char* name, char* fehyprid) |
---|
6290 | { |
---|
6291 | char* tmpnr = NULL, *tmpstr = NULL; |
---|
6292 | tmpnr = oitoa(adapter); |
---|
6293 | tmpstr = ostrcat(_("Tuner "), tmpnr, 0, 1); |
---|
6294 | tmpstr = ostrcat(tmpstr, "/", 1, 0); |
---|
6295 | tmpnr = oitoa(devnr); |
---|
6296 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
6297 | tmpstr = ostrcat(tmpstr, ": ", 1, 0); |
---|
6298 | tmpstr = ostrcat(tmpstr, name, 1, 0); |
---|
6299 | if(fehyprid != NULL) |
---|
6300 | { |
---|
6301 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
6302 | tmpstr = ostrcat(tmpstr, _("Multituner adjustable"), 1, 0); |
---|
6303 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
6304 | } |
---|
6305 | changetext(tunernode, tmpstr); |
---|
6306 | free(tmpstr); tmpstr = NULL; |
---|
6307 | } |
---|
6308 | |
---|
6309 | char* gethypridtunername(int dev, char* hyprid) |
---|
6310 | { |
---|
6311 | char* hypridtunerchoices = NULL, *value = NULL, *tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *start = NULL; |
---|
6312 | |
---|
6313 | hypridtunerchoices = getconfig("hypridtunerchoices", NULL); |
---|
6314 | |
---|
6315 | if(hypridtunerchoices == NULL) |
---|
6316 | { |
---|
6317 | err("NULL detect"); |
---|
6318 | return NULL; |
---|
6319 | } |
---|
6320 | |
---|
6321 | tmpstr = readfiletomem(hypridtunerchoices, 1); |
---|
6322 | if(tmpstr == NULL) |
---|
6323 | { |
---|
6324 | err("NULL detect"); |
---|
6325 | return NULL; |
---|
6326 | } |
---|
6327 | |
---|
6328 | start = ostrcat("NIM Socket ", oitoa(dev), 0, 0); |
---|
6329 | start = ostrcat(start, ":", 1, 0); |
---|
6330 | tmpstr1 = string_resub(start, "I2C_Device", tmpstr, 0); |
---|
6331 | free(start), start = NULL; |
---|
6332 | |
---|
6333 | tmpstr2 = string_resub("Name: ", "\n", tmpstr1, 0); |
---|
6334 | |
---|
6335 | if(tmpstr2 != NULL) |
---|
6336 | value = ostrcat(value, tmpstr2, 1, 0); |
---|
6337 | |
---|
6338 | free(tmpstr1), tmpstr1 = NULL; |
---|
6339 | free(tmpstr2), tmpstr2 = NULL; |
---|
6340 | free(start), start = NULL; |
---|
6341 | |
---|
6342 | return value; |
---|
6343 | } |
---|
6344 | |
---|
6345 | void convertsettings() |
---|
6346 | { |
---|
6347 | struct menulist* mlist = NULL, *mbox = NULL; |
---|
6348 | struct skin* load = getscreen("loading"); |
---|
6349 | int flag = 0, ret = 0; |
---|
6350 | char* tmpstr = NULL; |
---|
6351 | |
---|
6352 | addmenulist(&mlist, "Create Transponder (Sat)", _("Create Transponder (Sat)"), NULL, 0, 0); |
---|
6353 | addmenulist(&mlist, "Create Transponder (Cable)", _("Create Transponder (Cable)"), NULL, 0, 0); |
---|
6354 | addmenulist(&mlist, "Create Transponder (Terrestrial)", _("Create Transponder (Terrestrial)"), NULL, 0, 0); |
---|
6355 | addmenulist(&mlist, "Create Transponder (All)", _("Create Transponder (All)"), NULL, 0, 0); |
---|
6356 | |
---|
6357 | mbox = menulistbox(mlist, "createsettings", _("Select Your Serach Modus"), NULL, NULL, NULL, 1, 0); |
---|
6358 | if(mbox != NULL) tmpstr = mbox->name; |
---|
6359 | |
---|
6360 | if(ostrcmp(tmpstr, "Create Transponder (Sat)") == 0) |
---|
6361 | flag = 0; |
---|
6362 | else if(ostrcmp(tmpstr, "Create Transponder (Cable)") == 0) |
---|
6363 | flag = 1; |
---|
6364 | else if(ostrcmp(tmpstr, "Create Transponder (Terrestrial)") == 0) |
---|
6365 | flag = 2; |
---|
6366 | else if(ostrcmp(tmpstr, "Create Transponder (All)") == 0) |
---|
6367 | flag = 3; |
---|
6368 | else |
---|
6369 | { |
---|
6370 | freemenulist(mlist, 1); mlist = NULL; |
---|
6371 | return; |
---|
6372 | } |
---|
6373 | |
---|
6374 | freemenulist(mlist, 1); mlist = NULL; |
---|
6375 | |
---|
6376 | drawscreen(load, 0, 0); |
---|
6377 | |
---|
6378 | if(flag == 0) |
---|
6379 | { |
---|
6380 | ret = converte2settings(0); |
---|
6381 | if(ret == 0) return; |
---|
6382 | system("cp -a /tmp/satellites.sat /mnt/settings/satellites"); |
---|
6383 | system("cp -a /tmp/transponder.sat /mnt/settings/transponder"); |
---|
6384 | } |
---|
6385 | else if(flag == 1) |
---|
6386 | { |
---|
6387 | ret = converte2settings(1); |
---|
6388 | if(ret == 0) return; |
---|
6389 | system("cp -a /tmp/satellites.cable /mnt/settings/satellites"); |
---|
6390 | system("cp -a /tmp/transponder.cable /mnt/settings/transponder"); |
---|
6391 | } |
---|
6392 | else if(flag == 2) |
---|
6393 | { |
---|
6394 | converte2settings(2); |
---|
6395 | system("cp -a /tmp/satellites.ter /mnt/settings/satellites"); |
---|
6396 | system("cp -a /tmp/transponder.ter /mnt/settings/transponder"); |
---|
6397 | } |
---|
6398 | else if(flag == 3) |
---|
6399 | { |
---|
6400 | ret = converte2settings(0); |
---|
6401 | if(ret == 0) return; |
---|
6402 | ret = converte2settings(1); |
---|
6403 | if(ret == 0) return; |
---|
6404 | ret = converte2settings(2); |
---|
6405 | if(ret == 0) return; |
---|
6406 | system("cp -a /tmp/satellites.sat /mnt/settings/satellites"); |
---|
6407 | system("cp -a /tmp/transponder.sat /mnt/settings/transponder"); |
---|
6408 | |
---|
6409 | system("cat /tmp/satellites.cable >> /mnt/settings/satellites"); |
---|
6410 | system("cat /tmp/transponder.cable >> /mnt/settings/transponder"); |
---|
6411 | |
---|
6412 | system("cat /tmp/satellites.ter >> /mnt/settings/satellites"); |
---|
6413 | system("cat /tmp/transponder.ter >> /mnt/settings/transponder"); |
---|
6414 | } |
---|
6415 | |
---|
6416 | // free(tmpstr), tmpstr = NULL; |
---|
6417 | if(textbox(_("Message"), _("Transponder/Satellite Convert done, please use channel search on next Boot.\nYour System will reboot !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0) == 1) |
---|
6418 | { |
---|
6419 | //write only config file |
---|
6420 | system("sync"); |
---|
6421 | writeallconfig(3); |
---|
6422 | oshutdown(2,2); |
---|
6423 | system("init 6"); |
---|
6424 | } |
---|
6425 | } |
---|
6426 | |
---|
6427 | // flag 0 = sat |
---|
6428 | // flag 1 = cable |
---|
6429 | // flag 2 = ter |
---|
6430 | int converte2settings(int flag) |
---|
6431 | { |
---|
6432 | char* path = NULL, *buf = NULL, *tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *line = NULL, *name = NULL, *orbitalpos = NULL, *fetype = NULL, *flags = NULL, *outfile = NULL, *start = NULL, *end = NULL, *filename = NULL, *transponderfile = NULL, *satfile = NULL; |
---|
6433 | int incount = 0; |
---|
6434 | |
---|
6435 | if(flag == 0) |
---|
6436 | { |
---|
6437 | system("rm -rf /tmp/transponder.sat"); |
---|
6438 | system("rm -rf /tmp/satellites.sat"); |
---|
6439 | system("cp -a /var/etc/tuxbox/satellites.xml /tmp/satellites.xml"); |
---|
6440 | start = ostrcat("<sat ", NULL, 0, 0); |
---|
6441 | end = ostrcat("</sat>", NULL, 0, 0); |
---|
6442 | filename = ostrcat("/tmp/satellites.xml", NULL, 0, 0); |
---|
6443 | path = ostrcat("/transponder/satellites.xml", NULL, 0, 0); |
---|
6444 | transponderfile = ostrcat("/tmp/transponder.sat", NULL, 0, 0); |
---|
6445 | satfile = ostrcat("/tmp/satellites.sat", NULL, 0, 0); |
---|
6446 | fetype = ostrcat("0", NULL, 0, 0); |
---|
6447 | } |
---|
6448 | else if(flag == 1) |
---|
6449 | { |
---|
6450 | system("rm -rf /tmp/transponder.cable"); |
---|
6451 | system("rm -rf /tmp/satellites.cable"); |
---|
6452 | system("cp -a /var/etc/tuxbox/cables.xml /tmp/cables.xml"); |
---|
6453 | start = ostrcat("<cable ", NULL, 0, 0); |
---|
6454 | end = ostrcat("</cable>", NULL, 0, 0); |
---|
6455 | filename = ostrcat("/tmp/cables.xml", NULL, 0, 0); |
---|
6456 | path = ostrcat("/transponder/cables.xml", NULL, 0, 0); |
---|
6457 | transponderfile = ostrcat("/tmp/transponder.cable", NULL, 0, 0); |
---|
6458 | satfile = ostrcat("/tmp/satellites.cable", NULL, 0, 0); |
---|
6459 | fetype = ostrcat("1", NULL, 0, 0); |
---|
6460 | incount = 4999; |
---|
6461 | } |
---|
6462 | else if(flag == 2) |
---|
6463 | { |
---|
6464 | system("rm -rf /tmp/transponder.ter"); |
---|
6465 | system("rm -rf /tmp/satellites.ter"); |
---|
6466 | system("cp -a /var/etc/tuxbox/terrestrial.xml /tmp/terrestrial.xml"); |
---|
6467 | start = ostrcat("<terrestrial ", NULL, 0, 0); |
---|
6468 | end = ostrcat("</terrestrial>", NULL, 0, 0); |
---|
6469 | filename = ostrcat("/tmp/terrestrial.xml", NULL, 0, 0); |
---|
6470 | path = ostrcat("/transponder/terrestrial.xml", NULL, 0, 0); |
---|
6471 | transponderfile = ostrcat("/tmp/transponder.ter", NULL, 0, 0); |
---|
6472 | satfile = ostrcat("/tmp/satellites.ter", NULL, 0, 0); |
---|
6473 | fetype = ostrcat("2", NULL, 0, 0); |
---|
6474 | incount = 9999; |
---|
6475 | } |
---|
6476 | |
---|
6477 | if(!file_exist(filename)) |
---|
6478 | gethttp("atemio.dyndns.tv", path, 80, filename, HTTPAUTH, 5000, NULL, 0); |
---|
6479 | |
---|
6480 | char* tmptext = NULL; |
---|
6481 | tmptext = ostrcat(_("Error: Transponder Source file not found"), "\nfilename: ", 0, 0); |
---|
6482 | tmptext = ostrcat(tmptext, transponderfile, 1, 0); |
---|
6483 | |
---|
6484 | if(!file_exist(filename)) |
---|
6485 | { |
---|
6486 | textbox(_("Message"), tmptext, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0); |
---|
6487 | free(tmptext), tmptext = NULL; |
---|
6488 | free(path), path = NULL; |
---|
6489 | free(filename), filename = NULL; |
---|
6490 | free(satfile), satfile = NULL; |
---|
6491 | free(fetype), fetype = NULL; |
---|
6492 | free(start), start = NULL; |
---|
6493 | free(end), end = NULL; |
---|
6494 | free(transponderfile), transponderfile = NULL; |
---|
6495 | return 0; |
---|
6496 | } |
---|
6497 | free(tmptext), tmptext = NULL; |
---|
6498 | |
---|
6499 | buf = readfiletomem(filename, 1); |
---|
6500 | if(buf == NULL) |
---|
6501 | { |
---|
6502 | printf("buf: %s\n", buf); |
---|
6503 | tmptext = ostrcat(_("Error: Transponder Source file no data"), "\nfilename: ", 0, 0); |
---|
6504 | tmptext = ostrcat(tmptext, transponderfile, 1, 0); |
---|
6505 | textbox(_("Message"), tmptext, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0); |
---|
6506 | free(tmptext), tmptext = NULL; |
---|
6507 | free(path), path = NULL; |
---|
6508 | free(filename), filename = NULL; |
---|
6509 | free(satfile), satfile = NULL; |
---|
6510 | free(fetype), fetype = NULL; |
---|
6511 | free(start), start = NULL; |
---|
6512 | free(end), end = NULL; |
---|
6513 | free(transponderfile), transponderfile = NULL; |
---|
6514 | return 0; |
---|
6515 | } |
---|
6516 | |
---|
6517 | // writesys("/tmp/convert.log", buf, 1); |
---|
6518 | |
---|
6519 | while(ostrstr(buf, start) != NULL) |
---|
6520 | { |
---|
6521 | incount++; |
---|
6522 | tmpstr = string_resub(start, end, buf, 0); |
---|
6523 | tmpstr1 = ostrcat(tmpstr, NULL, 0, 0); |
---|
6524 | |
---|
6525 | //printf("name: %s\n", getxmlentry(ret1[i].part, "name=")); |
---|
6526 | //printf("position: %s\n", getxmlentry(ret1[i].part, "position=")); |
---|
6527 | |
---|
6528 | name = getxmlentry(tmpstr, "name="); |
---|
6529 | if(flag == 0) |
---|
6530 | orbitalpos = getxmlentry(tmpstr, "position="); |
---|
6531 | else |
---|
6532 | orbitalpos = ostrcat(oitoa(incount), NULL, 1, 0); |
---|
6533 | |
---|
6534 | flags = getxmlentry(tmpstr, "flags="); |
---|
6535 | //string_decode(name, 0); |
---|
6536 | name = string_replace_all("&", "und", name, 1); |
---|
6537 | |
---|
6538 | line = ostrcat(line, name, 1, 0); //name |
---|
6539 | line = ostrcat(line, "#", 1, 0); |
---|
6540 | // line = ostrcat(line, flags, 1, 0); //flag |
---|
6541 | // 0 for all sat/ter/cab ??? |
---|
6542 | line = ostrcat(line, "0", 1, 0); |
---|
6543 | line = ostrcat(line, "#", 1, 0); |
---|
6544 | line = ostrcat(line, orbitalpos, 1, 0); //orbitalpos |
---|
6545 | line = ostrcat(line, "#", 1, 0); |
---|
6546 | line = ostrcat(line, fetype, 1, 0); //fetype |
---|
6547 | printf("%s: %s\n", satfile, line); |
---|
6548 | writesys(satfile, line, 3); |
---|
6549 | free(line), line = NULL; |
---|
6550 | |
---|
6551 | int count = 0; |
---|
6552 | |
---|
6553 | int i = 0; |
---|
6554 | struct splitstr* ret1 = NULL; |
---|
6555 | ret1 = strsplit(tmpstr1, "\n", &count); |
---|
6556 | if(ret1 != NULL) |
---|
6557 | { |
---|
6558 | int max = count; |
---|
6559 | for(i = 0; i < max; i++) |
---|
6560 | { |
---|
6561 | if(i == 0) continue; |
---|
6562 | line = ostrcat(line, "0", 1, 0); //id |
---|
6563 | line = ostrcat(line, "#", 1, 0); |
---|
6564 | |
---|
6565 | line = ostrcat(line, fetype, 1, 0); //fetype |
---|
6566 | line = ostrcat(line, "#", 1, 0); |
---|
6567 | |
---|
6568 | if(ostrstr((ret1[i]).part, "frequency=") != NULL) |
---|
6569 | line = ostrcat(line, getxmlentry(ret1[i].part, "frequency="), 1, 0); //frequency |
---|
6570 | else |
---|
6571 | line = ostrcat(line, "-1", 1, 0); |
---|
6572 | line = ostrcat(line, "#", 1, 0); |
---|
6573 | |
---|
6574 | if(ostrstr((ret1[i]).part, "polarization=") != NULL) |
---|
6575 | line = ostrcat(line, getxmlentry(ret1[i].part, "polarization="), 1, 0); //polarization |
---|
6576 | else |
---|
6577 | line = ostrcat(line, "-1", 1, 0); //polarization |
---|
6578 | |
---|
6579 | line = ostrcat(line, "#", 1, 0); |
---|
6580 | if(orbitalpos != NULL) |
---|
6581 | line = ostrcat(line, orbitalpos, 1, 0); //orbitalpos |
---|
6582 | else |
---|
6583 | line = ostrcat(line, "-1", 1, 0); //orbitalpos |
---|
6584 | line = ostrcat(line, "#", 1, 0); |
---|
6585 | |
---|
6586 | if(ostrstr((ret1[i]).part, "symbol_rate=") != NULL) |
---|
6587 | line = ostrcat(line, getxmlentry(ret1[i].part, "symbol_rate="), 1, 0); //symbolrate |
---|
6588 | else |
---|
6589 | line = ostrcat(line, "-1", 1, 0); |
---|
6590 | line = ostrcat(line, "#", 1, 0); |
---|
6591 | |
---|
6592 | if(ostrstr((ret1[i]).part, "modulation=") != NULL) |
---|
6593 | line = ostrcat(line, getxmlentry(ret1[i].part, "modulation="), 1, 0); //modulation |
---|
6594 | else |
---|
6595 | { |
---|
6596 | if(flag == 2) |
---|
6597 | line = ostrcat(line, "3", 1, 0); |
---|
6598 | else |
---|
6599 | line = ostrcat(line, "0", 1, 0); |
---|
6600 | } |
---|
6601 | line = ostrcat(line, "#", 1, 0); |
---|
6602 | |
---|
6603 | if(ostrstr((ret1[i]).part, "fec_inner=") != NULL) |
---|
6604 | line = ostrcat(line, getxmlentry(ret1[i].part, "fec_inner="), 1, 0); //fec |
---|
6605 | else |
---|
6606 | { |
---|
6607 | if(flag == 2) |
---|
6608 | line = ostrcat(line, "5", 1, 0); |
---|
6609 | else |
---|
6610 | line = ostrcat(line, "0", 1, 0); |
---|
6611 | } |
---|
6612 | line = ostrcat(line, "#", 1, 0); |
---|
6613 | |
---|
6614 | if(checkbox("UFS910") == 1) |
---|
6615 | line = ostrcat(line, "1", 1, 0); //pilot |
---|
6616 | else |
---|
6617 | line = ostrcat(line, "2", 1, 0); //pilot |
---|
6618 | line = ostrcat(line, "#", 1, 0); |
---|
6619 | |
---|
6620 | if(checkbox("UFS910") == 1) |
---|
6621 | line = ostrcat(line, "0", 1, 0); //rolloff |
---|
6622 | else |
---|
6623 | line = ostrcat(line, "3", 1, 0); //rolloff |
---|
6624 | line = ostrcat(line, "#", 1, 0); |
---|
6625 | |
---|
6626 | line = ostrcat(line, "2", 1, 0); //inversion |
---|
6627 | line = ostrcat(line, "#", 1, 0); |
---|
6628 | |
---|
6629 | if(ostrstr((ret1[i]).part, "system=") != NULL) |
---|
6630 | line = ostrcat(line, getxmlentry(ret1[i].part, "system="), 1, 0); //system |
---|
6631 | else |
---|
6632 | line = ostrcat(line, "0", 1, 0); //system |
---|
6633 | line = ostrcat(line, "\n", 1, 0); |
---|
6634 | } |
---|
6635 | } |
---|
6636 | |
---|
6637 | tmpstr2 = ostrcat(start, tmpstr, 0, 0); |
---|
6638 | |
---|
6639 | buf = string_replace(tmpstr2, NULL, buf, 1); |
---|
6640 | |
---|
6641 | // outfile = ostrcat("/tmp/convert.", oitoa(incount), 0, 1); |
---|
6642 | // outfile = ostrcat(outfile, ".log", 1, 0); |
---|
6643 | // writesys(outfile, buf, 2); |
---|
6644 | // writesys("/tmp/convert.log", buf, 3); |
---|
6645 | |
---|
6646 | writesys(transponderfile, line, 2); |
---|
6647 | free(line), line = NULL; |
---|
6648 | |
---|
6649 | free(tmpstr), tmpstr = NULL; |
---|
6650 | free(tmpstr1), tmpstr1 = NULL; |
---|
6651 | free(tmpstr2), tmpstr2 = NULL; |
---|
6652 | free(ret1), ret1 = NULL; |
---|
6653 | free(name), name = NULL; |
---|
6654 | free(orbitalpos), orbitalpos = NULL; |
---|
6655 | free(flags), flags = NULL; |
---|
6656 | free(outfile), outfile = NULL; |
---|
6657 | } |
---|
6658 | |
---|
6659 | free(path), path = NULL; |
---|
6660 | free(filename), filename = NULL; |
---|
6661 | free(satfile), satfile = NULL; |
---|
6662 | free(transponderfile), transponderfile = NULL; |
---|
6663 | |
---|
6664 | free(buf), buf = NULL; |
---|
6665 | free(start), start = NULL; |
---|
6666 | free(end), end = NULL; |
---|
6667 | free(fetype), fetype = NULL; |
---|
6668 | |
---|
6669 | return 1; |
---|
6670 | } |
---|
6671 | |
---|
6672 | void createfav() |
---|
6673 | { |
---|
6674 | struct skin* load = getscreen("loading"); |
---|
6675 | drawscreen(load, 0, 0); |
---|
6676 | |
---|
6677 | system("rm -rf /mnt/settings/bouquets*"); |
---|
6678 | system("cp -a /etc/titan.restore/mnt/settings/bouquets* /mnt/settings"); |
---|
6679 | |
---|
6680 | if(textbox(_("Message"), _("Standard favorites have been successfully applied.\nYour System will reboot !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1000, 200, 0, 0) == 1) |
---|
6681 | { |
---|
6682 | //write only config file |
---|
6683 | system("sync"); |
---|
6684 | writeallconfig(3); |
---|
6685 | oshutdown(2,2); |
---|
6686 | system("init 6"); |
---|
6687 | } |
---|
6688 | } |
---|
6689 | |
---|
6690 | char* system_infos(int mode) |
---|
6691 | { |
---|
6692 | char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL; |
---|
6693 | |
---|
6694 | if(mode == 0) |
---|
6695 | { |
---|
6696 | tmpstr1 = ostrcat("Date = ", "", 0, 0); |
---|
6697 | tmpstr1 = ostrcat(tmpstr1, gettime(NULL, "%d %B %Y"), 1, 1); |
---|
6698 | tmpstr = ostrcat(tmpstr, tmpstr1, 1, 1); |
---|
6699 | |
---|
6700 | tmpstr1 = ostrcat("\nTime = ", "", 0, 0); |
---|
6701 | tmpstr1 = ostrcat(tmpstr1, gettime(NULL, "%H:%M:%S"), 1, 1); |
---|
6702 | tmpstr = ostrcat(tmpstr, tmpstr1, 1, 1); |
---|
6703 | |
---|
6704 | tmpstr1 = ostrcat("\nUptime = ", "", 0, 0); |
---|
6705 | tmpstr2 = command("uptime"); |
---|
6706 | if(tmpstr2 != NULL) tmpstr2 = strtok(tmpstr2, ","); |
---|
6707 | tmpstr1 = ostrcat(tmpstr1, tmpstr2, 1, 1); |
---|
6708 | tmpstr = ostrcat(tmpstr, tmpstr1, 1, 1); |
---|
6709 | |
---|
6710 | tmpstr1 = ostrcat("\nBoxtype = ", "", 0, 0); |
---|
6711 | tmpstr2 = string_toupper(command("cat /etc/model")); |
---|
6712 | tmpstr1 = ostrcat(tmpstr1, tmpstr2, 1, 1); |
---|
6713 | tmpstr = ostrcat(tmpstr, tmpstr1, 1, 1); |
---|
6714 | |
---|
6715 | tmpstr1 = ostrcat("\nLoad = ", "", 0, 0); |
---|
6716 | tmpstr2 = command("cat /proc/loadavg"); |
---|
6717 | tmpstr1 = ostrcat(tmpstr1, tmpstr2, 1, 1); |
---|
6718 | tmpstr = ostrcat(tmpstr, tmpstr1, 1, 1); |
---|
6719 | } |
---|
6720 | |
---|
6721 | if(mode == 1) |
---|
6722 | { |
---|
6723 | system("ls /media/usb/* >/dev/null"); |
---|
6724 | system("ls /media/net/* >/dev/null"); |
---|
6725 | system("ls /var/swap/* >/dev/null"); |
---|
6726 | system("ls /mnt/swapextension/* >/dev/null"); |
---|
6727 | system("ls /var/backup/* >/dev/null"); |
---|
6728 | system("ls /media/hdd/* >/dev/null"); |
---|
6729 | tmpstr = command("df -h"); |
---|
6730 | } |
---|
6731 | |
---|
6732 | if(mode == 2) |
---|
6733 | tmpstr = command("cat /proc/version"); |
---|
6734 | |
---|
6735 | if(mode == 3) |
---|
6736 | { |
---|
6737 | system("ls /media/usb/* >/dev/null"); |
---|
6738 | system("ls /media/net/* >/dev/null"); |
---|
6739 | system("ls /var/swap/* >/dev/null"); |
---|
6740 | system("ls /mnt/swapextension/* >/dev/null"); |
---|
6741 | system("ls /var/backup/* >/dev/null"); |
---|
6742 | system("ls /media/hdd/* >/dev/null"); |
---|
6743 | tmpstr = command("mount"); |
---|
6744 | } |
---|
6745 | |
---|
6746 | if(mode == 4) |
---|
6747 | { |
---|
6748 | tmpstr1 = command("ifconfig"); |
---|
6749 | tmpstr2 = command("route -n"); |
---|
6750 | tmpstr = ostrcat(tmpstr1, tmpstr2, 1, 1); |
---|
6751 | } |
---|
6752 | |
---|
6753 | if(mode == 5) |
---|
6754 | tmpstr = command("free"); |
---|
6755 | |
---|
6756 | return tmpstr; |
---|
6757 | } |
---|
6758 | |
---|
6759 | char* system_infos_sysinfo(int mode) |
---|
6760 | { |
---|
6761 | char* tmpstr = NULL; |
---|
6762 | |
---|
6763 | if(mode == 0) |
---|
6764 | tmpstr = command("cat /proc/cpuinfo | sed 's/\t\t/\t/'"); |
---|
6765 | else if(mode == 1) |
---|
6766 | tmpstr = command("cat /proc/meminfo"); |
---|
6767 | else if(mode == 2) |
---|
6768 | tmpstr = command("cat /proc/mtd"); |
---|
6769 | else if(mode == 3) |
---|
6770 | tmpstr = command("cat /proc/modules"); |
---|
6771 | else if(mode == 4) |
---|
6772 | tmpstr = command("cat /proc/devices"); |
---|
6773 | else if(mode == 5) |
---|
6774 | { |
---|
6775 | char* tmpstr1 = NULL, **tmpstr2 = NULL, **tmpstr3 = NULL; |
---|
6776 | int i = 0, ii = 0; |
---|
6777 | char* swap[] = {"Name: ", "Type: ", "Size: ", "Used: ", "Prio: "}; |
---|
6778 | |
---|
6779 | tmpstr1 = command("cat /proc/swaps | sed 's/\t/ /g; s/[ ]* / /g'"); |
---|
6780 | tmpstr2 = str_split(tmpstr1, "\n"); |
---|
6781 | if(tmpstr2 != NULL) |
---|
6782 | { |
---|
6783 | free(tmpstr2[0]); tmpstr2[0] = NULL; |
---|
6784 | |
---|
6785 | for(i = 1; tmpstr2[i] != NULL; i++) |
---|
6786 | { |
---|
6787 | tmpstr3 = str_split(tmpstr2[i], " "); |
---|
6788 | if(tmpstr3 != NULL) |
---|
6789 | { |
---|
6790 | |
---|
6791 | for(ii = 0; tmpstr3[ii] != NULL; ii++) |
---|
6792 | { |
---|
6793 | tmpstr = ostrcat(tmpstr, swap[ii], 1, 0); |
---|
6794 | tmpstr = ostrcat(tmpstr, tmpstr3[ii], 1, 1); |
---|
6795 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
6796 | } |
---|
6797 | } |
---|
6798 | |
---|
6799 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
6800 | free(tmpstr2[i]); tmpstr2[i] = NULL; |
---|
6801 | free(tmpstr3); tmpstr3 = NULL; |
---|
6802 | } |
---|
6803 | } |
---|
6804 | |
---|
6805 | free(tmpstr3); tmpstr3 = NULL; |
---|
6806 | free(tmpstr2); tmpstr2 = NULL; |
---|
6807 | free(tmpstr1); tmpstr1 = NULL; |
---|
6808 | } |
---|
6809 | else if(mode == 6) |
---|
6810 | tmpstr = command("top -b -n1"); |
---|
6811 | else if(mode == 7) |
---|
6812 | tmpstr = command("ps"); |
---|
6813 | else if(mode == 8) |
---|
6814 | tmpstr = command("cat /proc/bus/usb/devices"); |
---|
6815 | |
---|
6816 | return tmpstr; |
---|
6817 | } |
---|
6818 | |
---|
6819 | char* system_logs(int mode) |
---|
6820 | { |
---|
6821 | char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL, *path = NULL, *boxversion = NULL; |
---|
6822 | |
---|
6823 | if(mode == 0) |
---|
6824 | { |
---|
6825 | tmpstr1 = readfiletomem("/etc/motd", 0); |
---|
6826 | if(tmpstr1 != NULL) tmpstr2 = strstr(tmpstr1, "wElc0me"); |
---|
6827 | tmpstr3 = readfiletomem("/etc/imageinfo", 0); |
---|
6828 | if(tmpstr2 == NULL) |
---|
6829 | tmpstr = ostrcat(tmpstr3, NULL, 1, 0); |
---|
6830 | else |
---|
6831 | tmpstr = ostrcat(tmpstr2, tmpstr3, 1, 1); |
---|
6832 | } |
---|
6833 | else if(mode == 1) |
---|
6834 | { |
---|
6835 | if(isfile("/etc/model") == 0) return NULL; |
---|
6836 | boxversion = string_tolower(readsys("/etc/model", 1)); |
---|
6837 | |
---|
6838 | // if(file_exist("/etc/.beta")) |
---|
6839 | path = ostrcat(path, "/svn/image-beta/changelog.", 1, 0); |
---|
6840 | // else |
---|
6841 | // path = ostrcat(path, "/svn/image/changelog.", 1, 0); |
---|
6842 | |
---|
6843 | path = ostrcat(path, boxversion, 1, 0); |
---|
6844 | path = ostrcat(path, ".titan", 1, 0); |
---|
6845 | |
---|
6846 | // if(file_exist("/etc/.beta")) |
---|
6847 | tmpstr1 = gethttp("beta.dyndns.tv", path, 80, NULL, HTTPAUTH, 5000, NULL, 0); |
---|
6848 | // else |
---|
6849 | // tmpstr1 = gethttp("atemio.dyndns.tv", path, 80, NULL, HTTPAUTH, 5000, NULL, 0); |
---|
6850 | |
---|
6851 | tmpstr = readfromlinetoline(tmpstr1, 37, 537, 1); |
---|
6852 | } |
---|
6853 | else if(mode == 2) |
---|
6854 | { |
---|
6855 | // if(file_exist("/etc/.beta")) |
---|
6856 | #ifdef MIPSEL |
---|
6857 | path = ostrcat(path, "/svn/image-beta/changelog.git.mipsel", 1, 0); |
---|
6858 | #else |
---|
6859 | path = ostrcat(path, "/svn/image-beta/changelog.git.sh4", 1, 0); |
---|
6860 | #endif |
---|
6861 | // else |
---|
6862 | // path = ostrcat(path, "/svn/image/changelog.git", 1, 0); |
---|
6863 | |
---|
6864 | // if(file_exist("/etc/.beta")) |
---|
6865 | tmpstr1 = gethttp("beta.dyndns.tv", path, 80, NULL, HTTPAUTH, 5000, NULL, 0); |
---|
6866 | // else |
---|
6867 | // tmpstr1 = gethttp("atemio.dyndns.tv", path, 80, NULL, HTTPAUTH, 5000, NULL, 0); |
---|
6868 | |
---|
6869 | tmpstr = readfromlinetoline(tmpstr1, 0, 500, 1); |
---|
6870 | } |
---|
6871 | else if(mode == 3) |
---|
6872 | { |
---|
6873 | tmpstr = readfiletomem(getconfig("tracelog", NULL), 0); |
---|
6874 | } |
---|
6875 | |
---|
6876 | free(path), path = NULL; |
---|
6877 | free(boxversion), boxversion = NULL; |
---|
6878 | // free(tmpstr1), tmpstr1 = NULL; |
---|
6879 | // free(tmpstr2), tmpstr2 = NULL; |
---|
6880 | // free(tmpstr3), tmpstr3 = NULL; |
---|
6881 | |
---|
6882 | return tmpstr; |
---|
6883 | } |
---|
6884 | |
---|
6885 | char* getabout() |
---|
6886 | { |
---|
6887 | char* text = NULL, *tmpstr = NULL, *imgversion = NULL; |
---|
6888 | struct dvbdev* dvbnode = dvbdev; |
---|
6889 | |
---|
6890 | if(isfile(getconfig("imagenamefile", NULL)) != 0) |
---|
6891 | imgversion = readsys(getconfig("imagenamefile", NULL), 1); |
---|
6892 | else |
---|
6893 | imgversion = ostrcat("unknown", NULL, 0, 0); |
---|
6894 | |
---|
6895 | text = ostrcat(_("Image"), ": ", 0, 0); |
---|
6896 | text = ostrcat(text, PROGNAME, 1, 0); |
---|
6897 | text = ostrcat(text, "\n", 1, 0); |
---|
6898 | text = ostrcat(text, _("Version"), 1, 0); |
---|
6899 | text = ostrcat(text, ": ", 1, 0); |
---|
6900 | text = ostrcat(text, OVERSION, 1, 0); |
---|
6901 | text = ostrcat(text, "\n", 1, 0); |
---|
6902 | text = ostrcat(text, _("Installed:"), 1, 0); |
---|
6903 | text = ostrcat(text, " ", 1, 0); |
---|
6904 | text = ostrcat(text, imgversion, 1, 1); |
---|
6905 | text = ostrcat(text, "\n", 1, 0); |
---|
6906 | text = ostrcat(text, _("Copyright"), 1, 0); |
---|
6907 | text = ostrcat(text, ": ", 1, 0); |
---|
6908 | text = ostrcat(text, COPYRIGHT, 1, 0); |
---|
6909 | text = ostrcat(text, "\n\n", 1, 0); |
---|
6910 | |
---|
6911 | while(dvbnode != NULL) |
---|
6912 | { |
---|
6913 | if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL) |
---|
6914 | { |
---|
6915 | text = ostrcat(text, _("Tuner"), 1, 0); |
---|
6916 | text = ostrcat(text, ": ", 1, 0); |
---|
6917 | if(dvbnode->feinfo->name != NULL) |
---|
6918 | text = ostrcat(text, dvbnode->feinfo->name, 1, 0); |
---|
6919 | else |
---|
6920 | text = ostrcat(text, _("unknown"), 1, 0); |
---|
6921 | text = ostrcat(text, "\n", 1, 0); |
---|
6922 | text = ostrcat(text, _("Tunertype"), 1, 0); |
---|
6923 | text = ostrcat(text, ": ", 1, 0); |
---|
6924 | |
---|
6925 | tmpstr = fegettypestr(dvbnode); |
---|
6926 | text = ostrcat(text, tmpstr, 1, 1); |
---|
6927 | text = ostrcat(text, "\n\n", 1, 0); |
---|
6928 | } |
---|
6929 | dvbnode = dvbnode->next; |
---|
6930 | } |
---|
6931 | |
---|
6932 | char* flog = readfiletomem("/tmp/.firmware.log", 0); |
---|
6933 | text = ostrcat(text, flog, 1, 1); |
---|
6934 | |
---|
6935 | return text; |
---|
6936 | } |
---|
6937 | |
---|
6938 | char* getimgnamereal() |
---|
6939 | { |
---|
6940 | char* tmpstr = NULL; |
---|
6941 | |
---|
6942 | tmpstr = readfiletomem(getconfig("imagenamefile", NULL), 1); |
---|
6943 | |
---|
6944 | return tmpstr; |
---|
6945 | } |
---|
6946 | |
---|
6947 | char* getmoviedev() |
---|
6948 | { |
---|
6949 | char* tmpstr = NULL, *buf = NULL; |
---|
6950 | |
---|
6951 | tmpstr = readfiletomem("/tmp/.moviedev", 1); |
---|
6952 | printf("tmpstr: %s\n", tmpstr); |
---|
6953 | |
---|
6954 | buf = oregex("sd([a-z]{1,1}).*", tmpstr); |
---|
6955 | printf("buf: %s\n", buf); |
---|
6956 | |
---|
6957 | free(tmpstr), tmpstr = NULL; |
---|
6958 | |
---|
6959 | return buf; |
---|
6960 | } |
---|
6961 | |
---|
6962 | void wakeup_record_device() |
---|
6963 | { |
---|
6964 | char* cmd = NULL, *dev = NULL; |
---|
6965 | |
---|
6966 | dev = getmoviedev(); |
---|
6967 | if(dev == NULL) |
---|
6968 | cmd = ostrcat("ls -al ", getconfig("rec_path", NULL), 0, 0); |
---|
6969 | else |
---|
6970 | cmd = ostrcat("sdparm -C START /dev/sd", dev, 0, 0); |
---|
6971 | |
---|
6972 | // cmd = ostrcat(cmd, " >/dev/null", 1, 0); |
---|
6973 | printf("cmd: %s\n", cmd); |
---|
6974 | system(cmd); |
---|
6975 | free(dev), dev = NULL; |
---|
6976 | free(cmd), cmd = NULL; |
---|
6977 | } |
---|
6978 | |
---|
6979 | #endif |
---|