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