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