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