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