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