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