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