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 and 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, 0); |
---|
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, "aXBrLUdaRmg6RkhaVkJHaG56ZnZFaEZERlRHenVpZjU2NzZ6aGpHVFVHQk5Iam0=", 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 | int writeallconfig(int flag) |
---|
947 | { |
---|
948 | debug(1000, "in"); |
---|
949 | char* tmpstr = NULL; |
---|
950 | int ret = 0; |
---|
951 | |
---|
952 | if(status.writerectimer == 1) |
---|
953 | if(writerectimer(getconfig("rectimerfile", NULL), 0) != 0) |
---|
954 | ret = 1; |
---|
955 | if(status.writesat == 1) |
---|
956 | if(writesat(getconfig("satfile", NULL)) != 0) |
---|
957 | ret = 1; |
---|
958 | if(status.writeplaylist == 1) |
---|
959 | if(writeallplaylist() != 0) |
---|
960 | ret = 1; |
---|
961 | if(status.writemainplaylist == 1) |
---|
962 | if(writemainplaylist(getconfig("playlistfile", NULL)) != 0) |
---|
963 | ret = 1; |
---|
964 | if(status.writebouquet == 1) |
---|
965 | if(writeallbouquet() != 0) |
---|
966 | ret = 1; |
---|
967 | if(status.writemainbouquet == 1) |
---|
968 | if(writemainbouquet(getconfig("bouquetfile", NULL)) != 0) |
---|
969 | ret = 1; |
---|
970 | if(status.writechannel == 1) |
---|
971 | if(writechannel(getconfig("channelfile", NULL)) != 0) |
---|
972 | ret = 1; |
---|
973 | if(status.writetransponder == 1) |
---|
974 | if(writetransponder(getconfig("transponderfile", NULL)) != 0) |
---|
975 | ret = 1; |
---|
976 | if(status.writeprovider == 1) |
---|
977 | if(writeprovider(getconfig("providerfile", NULL)) != 0) |
---|
978 | ret = 1; |
---|
979 | if(status.writeownconfig == 1) |
---|
980 | if(writeownconfig(getconfig("ownconfig", NULL)) != 0) |
---|
981 | ret = 1; |
---|
982 | if(status.writeepgscanlist == 1) |
---|
983 | if(writeepgscanlist(getconfig("epgchannelfile", NULL)) != 0) |
---|
984 | ret = 1; |
---|
985 | if(status.writercconfig == 1) |
---|
986 | if(writercconfig(getconfig("rcconfig", NULL)) != 0) |
---|
987 | ret = 1; |
---|
988 | if(status.writeskinconfig == 1) |
---|
989 | if(writeskinconfig(getconfig("skinconfig", NULL)) != 0) |
---|
990 | ret = 1; |
---|
991 | if(status.writeconfig == 1) |
---|
992 | if(writeconfig(status.configfile) != 0) |
---|
993 | ret = 1; |
---|
994 | if(flag == 0 && time(NULL) > 1072224000) // 01.01.2004 |
---|
995 | { |
---|
996 | tmpstr = createpath(getconfig("epg_path", NULL), "epg.dat"); |
---|
997 | if(writeepg(tmpstr) != 0) |
---|
998 | ret = 1; |
---|
999 | free(tmpstr); tmpstr = NULL; |
---|
1000 | } |
---|
1001 | |
---|
1002 | sync(); |
---|
1003 | |
---|
1004 | debug(1000, "out"); |
---|
1005 | return ret; |
---|
1006 | } |
---|
1007 | |
---|
1008 | void initmutex(int flag) |
---|
1009 | { |
---|
1010 | if(flag == 1) |
---|
1011 | { |
---|
1012 | pthread_mutex_init(&status.drawingmutex, NULL); |
---|
1013 | pthread_mutex_init(&status.rectimermutex, NULL); |
---|
1014 | pthread_mutex_init(&status.servicemutex, NULL); |
---|
1015 | pthread_mutex_init(&status.epgmutex, NULL); |
---|
1016 | pthread_mutex_init(&status.vfdmutex, NULL); |
---|
1017 | pthread_mutex_init(&status.channelmutex, NULL); |
---|
1018 | pthread_mutex_init(&status.timerthreadmutex, NULL); |
---|
1019 | pthread_mutex_init(&status.audiotrackmutex, NULL); |
---|
1020 | pthread_mutex_init(&status.subtitlemutex, NULL); |
---|
1021 | pthread_mutex_init(&status.dmxdevmutex, NULL); |
---|
1022 | pthread_mutex_init(&status.rcmutex, NULL); |
---|
1023 | pthread_mutex_init(&status.queuemutex, NULL); |
---|
1024 | pthread_mutex_init(&status.clistmutex, NULL); |
---|
1025 | pthread_mutex_init(&status.hddmutex, NULL); |
---|
1026 | pthread_mutex_init(&status.linkedchannelmutex, NULL); |
---|
1027 | pthread_mutex_init(&status.tsseekmutex, NULL); |
---|
1028 | } |
---|
1029 | else |
---|
1030 | { |
---|
1031 | pthread_mutex_destroy(&status.drawingmutex); |
---|
1032 | pthread_mutex_destroy(&status.rectimermutex); |
---|
1033 | pthread_mutex_destroy(&status.servicemutex); |
---|
1034 | pthread_mutex_destroy(&status.epgmutex); |
---|
1035 | pthread_mutex_destroy(&status.vfdmutex); |
---|
1036 | pthread_mutex_destroy(&status.channelmutex); |
---|
1037 | pthread_mutex_destroy(&status.timerthreadmutex); |
---|
1038 | pthread_mutex_destroy(&status.audiotrackmutex); |
---|
1039 | pthread_mutex_destroy(&status.subtitlemutex); |
---|
1040 | pthread_mutex_destroy(&status.dmxdevmutex); |
---|
1041 | pthread_mutex_destroy(&status.rcmutex); |
---|
1042 | pthread_mutex_destroy(&status.queuemutex); |
---|
1043 | pthread_mutex_destroy(&status.clistmutex); |
---|
1044 | pthread_mutex_destroy(&status.hddmutex); |
---|
1045 | pthread_mutex_destroy(&status.linkedchannelmutex); |
---|
1046 | pthread_mutex_destroy(&status.tsseekmutex); |
---|
1047 | } |
---|
1048 | } |
---|
1049 | |
---|
1050 | int hexit(char c) |
---|
1051 | { |
---|
1052 | if(c >= '0' && c <= '9') |
---|
1053 | return c - '0'; |
---|
1054 | if(c >= 'a' && c <= 'f') |
---|
1055 | return c - 'a' + 10; |
---|
1056 | if(c >= 'A' && c <= 'F') |
---|
1057 | return c - 'A' + 10; |
---|
1058 | |
---|
1059 | return 0; |
---|
1060 | } |
---|
1061 | |
---|
1062 | char* htmlencode(char* from) |
---|
1063 | { |
---|
1064 | int buflen = 0; |
---|
1065 | char* buf = NULL, *to = NULL; |
---|
1066 | |
---|
1067 | buf = malloc(MINMALLOC); |
---|
1068 | if(buf == NULL) |
---|
1069 | { |
---|
1070 | err("no mem"); |
---|
1071 | return NULL; |
---|
1072 | } |
---|
1073 | memset(buf, 0, MINMALLOC); |
---|
1074 | to = buf; |
---|
1075 | |
---|
1076 | for(buflen = 0; *from != '\0' && buflen < MINMALLOC; ++from) |
---|
1077 | { |
---|
1078 | if(isalnum(*from) || strchr("/_.-~", *from) != NULL) |
---|
1079 | { |
---|
1080 | *to = *from; |
---|
1081 | ++to; |
---|
1082 | ++buflen; |
---|
1083 | } |
---|
1084 | else |
---|
1085 | { |
---|
1086 | sprintf(to, "%%%02x", (int)*from & 0xff); |
---|
1087 | to += 3; |
---|
1088 | buflen += 3; |
---|
1089 | } |
---|
1090 | } |
---|
1091 | *to = '\0'; |
---|
1092 | |
---|
1093 | buf = ostrcat(buf, NULL, 1, 0); |
---|
1094 | return buf; |
---|
1095 | } |
---|
1096 | |
---|
1097 | void htmldecode(char* to, char* from) |
---|
1098 | { |
---|
1099 | for(; *from != '\0'; ++to, ++from) |
---|
1100 | { |
---|
1101 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
1102 | { |
---|
1103 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
1104 | from += 2; |
---|
1105 | } |
---|
1106 | else |
---|
1107 | *to = *from; |
---|
1108 | } |
---|
1109 | *to = '\0'; |
---|
1110 | } |
---|
1111 | |
---|
1112 | void htmldecode2(char* to, char* from) |
---|
1113 | { |
---|
1114 | for(; *from != '\0'; ++to, ++from) |
---|
1115 | { |
---|
1116 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4])) |
---|
1117 | { |
---|
1118 | *to = hexit(from[1]) * 16 + hexit(from[2]) * 16 + hexit(from[3]) * 16 + hexit(from[4]); |
---|
1119 | from += 4; |
---|
1120 | } |
---|
1121 | else if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]) && isxdigit(from[3])) |
---|
1122 | { |
---|
1123 | *to = hexit(from[1]) * 16 + hexit(from[2]) * 16 + hexit(from[3]); |
---|
1124 | from += 3; |
---|
1125 | } |
---|
1126 | else if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
1127 | { |
---|
1128 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
1129 | from += 2; |
---|
1130 | } |
---|
1131 | else |
---|
1132 | *to = *from; |
---|
1133 | } |
---|
1134 | *to = '\0'; |
---|
1135 | } |
---|
1136 | |
---|
1137 | void setosdtransparent(int value) |
---|
1138 | { |
---|
1139 | int ret = 255; |
---|
1140 | if(value < 0) value = 0; |
---|
1141 | if(value > 100) value = 100; |
---|
1142 | |
---|
1143 | ret -= value * 2.55; |
---|
1144 | |
---|
1145 | setfbtransparent(ret); |
---|
1146 | } |
---|
1147 | |
---|
1148 | struct tm* olocaltime(time_t *value) |
---|
1149 | { |
---|
1150 | struct tm *loctime, *loctime1 = NULL; |
---|
1151 | |
---|
1152 | loctime1 = (struct tm*)malloc(sizeof(struct tm)); |
---|
1153 | if(loctime1 == NULL) |
---|
1154 | { |
---|
1155 | err("no mem"); |
---|
1156 | return NULL; |
---|
1157 | } |
---|
1158 | loctime = localtime_r(value, loctime1); |
---|
1159 | |
---|
1160 | return loctime; |
---|
1161 | } |
---|
1162 | |
---|
1163 | int setwakeuptimer(time_t waketime) |
---|
1164 | { |
---|
1165 | debug(1000, "in"); |
---|
1166 | char* wakeuptimerprog = NULL; |
---|
1167 | struct tm *loctime = NULL; |
---|
1168 | char *buf = NULL; |
---|
1169 | int ret = -1; |
---|
1170 | |
---|
1171 | wakeuptimerprog = getconfig("wakeuptimerprog", NULL); |
---|
1172 | |
---|
1173 | if(wakeuptimerprog == NULL) |
---|
1174 | { |
---|
1175 | debug(1000, "out -> NULL detect"); |
---|
1176 | return ret; |
---|
1177 | } |
---|
1178 | |
---|
1179 | buf = malloc(MINMALLOC); |
---|
1180 | if(buf == NULL) |
---|
1181 | { |
---|
1182 | err("no memory"); |
---|
1183 | return ret; |
---|
1184 | } |
---|
1185 | |
---|
1186 | loctime = olocaltime(&waketime); |
---|
1187 | |
---|
1188 | if(loctime != NULL) |
---|
1189 | ostrftime(buf, MINMALLOC, wakeuptimerprog, loctime); |
---|
1190 | |
---|
1191 | if(buf != NULL) |
---|
1192 | { |
---|
1193 | debug(100, "set wake up timer (%s)", buf); |
---|
1194 | ret = system(buf); |
---|
1195 | } |
---|
1196 | |
---|
1197 | free(loctime); |
---|
1198 | free(buf); |
---|
1199 | debug(1000, "out"); |
---|
1200 | return ret; |
---|
1201 | } |
---|
1202 | |
---|
1203 | int autoresolution() |
---|
1204 | { |
---|
1205 | debug(1000, "in"); |
---|
1206 | char *hotpluginfo = NULL; |
---|
1207 | char *value = NULL; |
---|
1208 | |
---|
1209 | if(getconfig("av_videomode", NULL) != NULL || getconfig("av_colorformat", NULL)) |
---|
1210 | return 1; |
---|
1211 | |
---|
1212 | hotpluginfo = getconfig("hotpluginfo", NULL); |
---|
1213 | |
---|
1214 | if(hotpluginfo == NULL) |
---|
1215 | { |
---|
1216 | debug(1000, "out -> NULL detect"); |
---|
1217 | return 1; |
---|
1218 | } |
---|
1219 | |
---|
1220 | value = readsys(hotpluginfo, 1); |
---|
1221 | if(value == NULL) |
---|
1222 | { |
---|
1223 | debug(1000, "out -> NULL detect"); |
---|
1224 | return 1; |
---|
1225 | } |
---|
1226 | |
---|
1227 | if(value[0] == 'y') |
---|
1228 | { |
---|
1229 | setvideomode("720p50", 0); |
---|
1230 | changefbresolution("720p50"); |
---|
1231 | setcolorformat("hdmi_rgb"); |
---|
1232 | } |
---|
1233 | else |
---|
1234 | { |
---|
1235 | setvideomode("576i50", 0); |
---|
1236 | changefbresolution("576i50"); |
---|
1237 | setcolorformat("rgb"); |
---|
1238 | } |
---|
1239 | |
---|
1240 | free(value); |
---|
1241 | debug(1000, "out"); |
---|
1242 | return 0; |
---|
1243 | } |
---|
1244 | |
---|
1245 | //TODO: can remove if new function work |
---|
1246 | /* |
---|
1247 | int writelengthfield(unsigned char *buf, unsigned int len) |
---|
1248 | { |
---|
1249 | if(len < 127) |
---|
1250 | { |
---|
1251 | *buf++ = len; |
---|
1252 | return 1; |
---|
1253 | } |
---|
1254 | else if(len < 256) |
---|
1255 | { |
---|
1256 | *buf++ = 0x81; |
---|
1257 | *buf++ = len; |
---|
1258 | return 2; |
---|
1259 | } |
---|
1260 | else if(len < 65535) |
---|
1261 | { |
---|
1262 | *buf++ = 0x82; |
---|
1263 | *buf++ = len >> 8; |
---|
1264 | *buf++ = len; |
---|
1265 | return 3; |
---|
1266 | } |
---|
1267 | |
---|
1268 | return 0; |
---|
1269 | } |
---|
1270 | */ |
---|
1271 | |
---|
1272 | size_t writelengthfield(unsigned char * buf, unsigned int len) |
---|
1273 | { |
---|
1274 | if(buf == NULL) return 0; |
---|
1275 | |
---|
1276 | if(len < 128) |
---|
1277 | { |
---|
1278 | buf[0] = len; |
---|
1279 | return 1; |
---|
1280 | } |
---|
1281 | else |
---|
1282 | { |
---|
1283 | unsigned int pos = 0; |
---|
1284 | unsigned int shiftby = 8; |
---|
1285 | unsigned char lenfieldsize = 1; |
---|
1286 | |
---|
1287 | while((len >> shiftby) != 0) |
---|
1288 | { |
---|
1289 | lenfieldsize++; |
---|
1290 | shiftby += 8; |
---|
1291 | } |
---|
1292 | |
---|
1293 | buf[pos++] = ((1 << 7) | lenfieldsize); |
---|
1294 | |
---|
1295 | while(shiftby != 0) |
---|
1296 | { |
---|
1297 | shiftby -= 8; |
---|
1298 | buf[pos++] = len >> shiftby; |
---|
1299 | } |
---|
1300 | return pos; |
---|
1301 | } |
---|
1302 | } |
---|
1303 | |
---|
1304 | |
---|
1305 | //flag 0: del non alpha/num |
---|
1306 | //flag 1: change all / |
---|
1307 | void delspezchar(char* text, int flag) |
---|
1308 | { |
---|
1309 | char* tmpstr = text; |
---|
1310 | |
---|
1311 | while(*tmpstr != '\0') |
---|
1312 | { |
---|
1313 | if(flag == 1) |
---|
1314 | { |
---|
1315 | if(tmpstr[0] == '/') |
---|
1316 | tmpstr[0] = '-'; |
---|
1317 | } |
---|
1318 | else |
---|
1319 | { |
---|
1320 | if(!isalnum(tmpstr[0]) && tmpstr[0] != '-' && tmpstr[0] != '.') |
---|
1321 | tmpstr[0] = ' '; |
---|
1322 | } |
---|
1323 | tmpstr++; |
---|
1324 | } |
---|
1325 | } |
---|
1326 | |
---|
1327 | void m_lock(pthread_mutex_t *mutex, int flag) |
---|
1328 | { |
---|
1329 | switch(flag) |
---|
1330 | { |
---|
1331 | case 0: debug(900, "drawingmutex lock"); break; |
---|
1332 | case 1: debug(900, "rectimermutex lock"); break; |
---|
1333 | case 2: debug(900, "servicemutex lock"); break; |
---|
1334 | case 3: debug(900, "vfdmutex lock"); break; |
---|
1335 | case 4: debug(900, "epgmutex lock"); break; |
---|
1336 | case 5: debug(900, "channelmutex lock"); break; |
---|
1337 | case 6: debug(900, "timerthreadmutex lock"); break; |
---|
1338 | case 7: debug(900, "audiotrackmutex lock"); break; |
---|
1339 | case 8: debug(900, "subtitlemutex lock"); break; |
---|
1340 | case 9: debug(900, "dmxdevmutex lock"); break; |
---|
1341 | case 10: debug(900, "rcmutex lock"); break; |
---|
1342 | case 11: debug(900, "queuemutex lock"); break; |
---|
1343 | case 12: debug(900, "clistmutex lock"); break; |
---|
1344 | case 13: debug(900, "hddmutex lock"); break; |
---|
1345 | case 14: debug(900, "linkedchannelmutex lock"); break; |
---|
1346 | case 15: debug(900, "tsseekmutex lock"); break; |
---|
1347 | default: debug(900, " unknown mutex lock"); break; |
---|
1348 | } |
---|
1349 | pthread_mutex_lock(mutex); |
---|
1350 | } |
---|
1351 | |
---|
1352 | void m_unlock(pthread_mutex_t *mutex, int flag) |
---|
1353 | { |
---|
1354 | switch(flag) |
---|
1355 | { |
---|
1356 | case 0: debug(900, "drawingmutex unlock"); break; |
---|
1357 | case 1: debug(900, "rectimermutex unlock"); break; |
---|
1358 | case 2: debug(900, "servicemutex unlock"); break; |
---|
1359 | case 3: debug(900, "vfdmutex unlock"); break; |
---|
1360 | case 4: debug(900, "epgmutex unlock"); break; |
---|
1361 | case 5: debug(900, "channelmutex unlock"); break; |
---|
1362 | case 6: debug(900, "timerthreadmutex unlock"); break; |
---|
1363 | case 7: debug(900, "audiotrackmutex unlock"); break; |
---|
1364 | case 8: debug(900, "subtitlemutex unlock"); break; |
---|
1365 | case 9: debug(900, "dmxdevmutex unlock"); break; |
---|
1366 | case 10: debug(900, "rcmutex unlock"); break; |
---|
1367 | case 11: debug(900, "queuemutex unlock"); break; |
---|
1368 | case 12: debug(900, "clistmutex unlock"); break; |
---|
1369 | case 13: debug(900, "hddmutex unlock"); break; |
---|
1370 | case 14: debug(900, "linkedchannelmutex unlock"); break; |
---|
1371 | case 15: debug(900, "tsseekmutex unlock"); break; |
---|
1372 | default: debug(900, "unknown mutex unlock"); break; |
---|
1373 | } |
---|
1374 | pthread_mutex_unlock(mutex); |
---|
1375 | } |
---|
1376 | |
---|
1377 | void debugstack(void* address, void* address1) |
---|
1378 | { |
---|
1379 | void* trace[10]; |
---|
1380 | size_t size; |
---|
1381 | size = backtrace(trace, 10); |
---|
1382 | |
---|
1383 | FILE* fd = NULL; |
---|
1384 | void* akttrace[2]; |
---|
1385 | int i; |
---|
1386 | char **strings; |
---|
1387 | char **aktstring; |
---|
1388 | time_t rawtime; |
---|
1389 | |
---|
1390 | strings = backtrace_symbols(trace, size); |
---|
1391 | akttrace[0] = (void*)address1; |
---|
1392 | akttrace[1] = (void*)address; |
---|
1393 | aktstring = backtrace_symbols(akttrace, 2); //get fault funktion name |
---|
1394 | |
---|
1395 | printf("--------------------------------------\n"); |
---|
1396 | printf("Obtaining %zd stack frames:\n\n", size); |
---|
1397 | |
---|
1398 | for(i = 0; i < size; i++) |
---|
1399 | printf("%s\n", strings[i]); |
---|
1400 | |
---|
1401 | printf("\nLast functions:\n\n"); |
---|
1402 | printf("%s\n", aktstring[0]); |
---|
1403 | printf("%s\n", aktstring[1]); |
---|
1404 | |
---|
1405 | printf("--------------------------------------\n"); |
---|
1406 | |
---|
1407 | fd = fopen(getconfig("tracelog", NULL), "a"); |
---|
1408 | if(fd != NULL) |
---|
1409 | { |
---|
1410 | time(&rawtime); |
---|
1411 | fprintf(fd, "Date: %s", ctime(&rawtime)); |
---|
1412 | fprintf(fd, "Obtaining %zd stack frames:\n\n", size); |
---|
1413 | for(i = 1; i < size; i++) |
---|
1414 | fprintf(fd, "%s\n", strings[i]); |
---|
1415 | fprintf(fd, "\nLast functions:\n\n"); |
---|
1416 | fprintf(fd, "%s\n", aktstring[0]); |
---|
1417 | fprintf(fd, "%s\n", aktstring[1]); |
---|
1418 | fprintf(fd, "--------------------------------------\n\n"); |
---|
1419 | fclose(fd); |
---|
1420 | sync(); |
---|
1421 | } |
---|
1422 | else |
---|
1423 | perr("open %s", getconfig("tracelog", NULL)); |
---|
1424 | |
---|
1425 | free(strings); |
---|
1426 | free(aktstring); |
---|
1427 | } |
---|
1428 | |
---|
1429 | int mountauto(const char *file, const char *dir, unsigned long int flag, const void *data) |
---|
1430 | { |
---|
1431 | int ret = -1; |
---|
1432 | char* saveptr = NULL, *filesystems = NULL, *tmpfilesystems = NULL, *token = NULL; |
---|
1433 | |
---|
1434 | filesystems = getconfig("filesystems", NULL); |
---|
1435 | tmpfilesystems = ostrcat(tmpfilesystems, filesystems, 0, 0); |
---|
1436 | |
---|
1437 | token = strtok_r(tmpfilesystems, ";" , &saveptr); |
---|
1438 | while(token != NULL) |
---|
1439 | { |
---|
1440 | ret = mount(file, dir, token, flag, data); |
---|
1441 | if(ret == 0) break; |
---|
1442 | token = strtok_r(NULL, ";" , &saveptr); |
---|
1443 | } |
---|
1444 | |
---|
1445 | free(tmpfilesystems); |
---|
1446 | return ret; |
---|
1447 | } |
---|
1448 | |
---|
1449 | int setwaswakuptimer(int value) |
---|
1450 | { |
---|
1451 | debug(1000, "in"); |
---|
1452 | char *waswakeuptimerdev = NULL, *tmpstr = NULL; |
---|
1453 | int ret = 0; |
---|
1454 | |
---|
1455 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
1456 | |
---|
1457 | if(waswakeuptimerdev != NULL) |
---|
1458 | { |
---|
1459 | debug(100, "set %s to %d", waswakeuptimerdev, value); |
---|
1460 | tmpstr = oitoa(value); |
---|
1461 | ret = writesys(waswakeuptimerdev, tmpstr, 0); |
---|
1462 | free(tmpstr); tmpstr = NULL; |
---|
1463 | return ret; |
---|
1464 | } |
---|
1465 | |
---|
1466 | debug(1000, "out"); |
---|
1467 | return 0; |
---|
1468 | } |
---|
1469 | |
---|
1470 | int getwaswakuptimer() |
---|
1471 | { |
---|
1472 | debug(1000, "in"); |
---|
1473 | int ret = 0; |
---|
1474 | char *waswakeuptimerdev = NULL; |
---|
1475 | char *value = NULL; |
---|
1476 | |
---|
1477 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
1478 | |
---|
1479 | if(waswakeuptimerdev == NULL) |
---|
1480 | { |
---|
1481 | debug(1000, "out -> NULL detect"); |
---|
1482 | return 0; |
---|
1483 | } |
---|
1484 | |
---|
1485 | value = readsys(waswakeuptimerdev, 1); |
---|
1486 | if(value == NULL) |
---|
1487 | { |
---|
1488 | debug(1000, "out -> NULL detect"); |
---|
1489 | return 0; |
---|
1490 | } |
---|
1491 | |
---|
1492 | // start from timer |
---|
1493 | if(atoi(value) == 1) ret = 1; |
---|
1494 | |
---|
1495 | free(value); |
---|
1496 | debug(1000, "out"); |
---|
1497 | return ret; |
---|
1498 | } |
---|
1499 | |
---|
1500 | void checkboxstartthread(struct stimerthread* self) |
---|
1501 | { |
---|
1502 | struct rectimer* node = rectimer; |
---|
1503 | int timediff = getconfigint("rectimer_timediff", NULL); |
---|
1504 | |
---|
1505 | if(node == NULL) return; //no record |
---|
1506 | |
---|
1507 | debug(400, "boxstart rectimer thread start"); |
---|
1508 | |
---|
1509 | //wait for right time |
---|
1510 | while(self->aktion != STOP && time(NULL) < 1072224000) // 01.01.2004 |
---|
1511 | sleep(5); |
---|
1512 | |
---|
1513 | while(node != NULL) |
---|
1514 | { |
---|
1515 | if(node->status < 2) |
---|
1516 | { |
---|
1517 | time_t akttime = time(NULL); |
---|
1518 | time_t begin = node->begin - getconfigint("wakeuptimerdevdiff", NULL); |
---|
1519 | if(begin > akttime - timediff && begin < akttime + timediff) |
---|
1520 | { |
---|
1521 | debug(400, "found rectimer who has start the box"); |
---|
1522 | setwaswakuptimer(1); |
---|
1523 | } |
---|
1524 | } |
---|
1525 | node = node->next; |
---|
1526 | } |
---|
1527 | |
---|
1528 | debug(400, "boxstart rectimer thread end"); |
---|
1529 | } |
---|
1530 | |
---|
1531 | int setwakeuptimerdev(time_t value) |
---|
1532 | { |
---|
1533 | debug(1000, "in"); |
---|
1534 | char* wakeuptimerdev, *tmpstr = NULL; |
---|
1535 | int ret = 0; |
---|
1536 | int diff = getconfigint("wakeuptimerdevdiff", NULL); |
---|
1537 | |
---|
1538 | if(value != 0x7FFFFFFF && value - diff > time(NULL)) |
---|
1539 | value -= diff; |
---|
1540 | |
---|
1541 | wakeuptimerdev = getconfig("wakeuptimerdev", NULL); |
---|
1542 | |
---|
1543 | if(wakeuptimerdev != NULL && value >= time(NULL)) |
---|
1544 | { |
---|
1545 | debug(100, "set %s to %ld", wakeuptimerdev, value); |
---|
1546 | tmpstr = olutoa(value); |
---|
1547 | ret = writesys(wakeuptimerdev, tmpstr, 0); |
---|
1548 | free(tmpstr); tmpstr = NULL; |
---|
1549 | return ret; |
---|
1550 | } |
---|
1551 | |
---|
1552 | debug(1000, "out"); |
---|
1553 | return 0; |
---|
1554 | } |
---|
1555 | |
---|
1556 | int changepolicy() |
---|
1557 | { |
---|
1558 | debug(1000, "in"); |
---|
1559 | char *tmppolicy = NULL, *tmpstr = NULL; |
---|
1560 | |
---|
1561 | tmppolicy = getpolicy(); |
---|
1562 | |
---|
1563 | if(!ostrncmp("letterbox", tmppolicy, 8)) |
---|
1564 | tmpstr = ostrcat(tmpstr, "panscan", 1, 0); |
---|
1565 | else if(!ostrncmp("panscan", tmppolicy, 7)) |
---|
1566 | tmpstr = ostrcat(tmpstr, "non", 1, 0); |
---|
1567 | else if(!ostrncmp("non", tmppolicy, 3)) |
---|
1568 | tmpstr = ostrcat(tmpstr, "bestfit", 1, 0); |
---|
1569 | else if(!ostrncmp("bestfit", tmppolicy, 7)) |
---|
1570 | tmpstr = ostrcat(tmpstr, "letterbox", 1, 0); |
---|
1571 | |
---|
1572 | setpolicy(tmpstr); |
---|
1573 | |
---|
1574 | free(tmpstr); tmpstr = NULL; |
---|
1575 | free(tmppolicy); tmppolicy = NULL; |
---|
1576 | debug(1000, "out"); |
---|
1577 | return 0; |
---|
1578 | } |
---|
1579 | |
---|
1580 | char* getdefaultgw() |
---|
1581 | { |
---|
1582 | char* name = NULL; |
---|
1583 | unsigned long def, gw, m; |
---|
1584 | int flags, ref, use, metric, mtu, win, ir; |
---|
1585 | struct in_addr ip; |
---|
1586 | |
---|
1587 | FILE *fd = fopen("/proc/net/route", "r"); |
---|
1588 | if(fd == NULL) |
---|
1589 | return NULL; |
---|
1590 | |
---|
1591 | if(fscanf(fd, "%*[^\n]\n") < 0) |
---|
1592 | { |
---|
1593 | fclose(fd); |
---|
1594 | return NULL; |
---|
1595 | } |
---|
1596 | |
---|
1597 | name = malloc(64); |
---|
1598 | if(name == NULL) |
---|
1599 | { |
---|
1600 | err("no mem"); |
---|
1601 | return NULL; |
---|
1602 | } |
---|
1603 | |
---|
1604 | while(1) |
---|
1605 | { |
---|
1606 | 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); |
---|
1607 | if(def == 0) break; |
---|
1608 | if(r != 11) |
---|
1609 | { |
---|
1610 | fclose(fd); |
---|
1611 | free(name); |
---|
1612 | return NULL; |
---|
1613 | } |
---|
1614 | if(!(flags & 0x0001)) continue; //is interface down |
---|
1615 | } |
---|
1616 | |
---|
1617 | fclose(fd); |
---|
1618 | free(name); |
---|
1619 | |
---|
1620 | ip.s_addr = gw; |
---|
1621 | if(def == 0) |
---|
1622 | return inet_ntoa(ip); |
---|
1623 | |
---|
1624 | return NULL; |
---|
1625 | } |
---|
1626 | |
---|
1627 | char* changefilenameext(char* filename, char* ext) |
---|
1628 | { |
---|
1629 | char* newfilename = NULL; |
---|
1630 | char* zeichen = NULL; |
---|
1631 | |
---|
1632 | if(filename == NULL) return NULL; |
---|
1633 | |
---|
1634 | newfilename = ostrcat(filename, "", 0, 0); |
---|
1635 | |
---|
1636 | zeichen = strrchr(newfilename, '.'); |
---|
1637 | if(zeichen != NULL) |
---|
1638 | { |
---|
1639 | zeichen[0] = '\0'; |
---|
1640 | newfilename = ostrcat(newfilename, ext, 1, 0); |
---|
1641 | } |
---|
1642 | |
---|
1643 | return newfilename; |
---|
1644 | } |
---|
1645 | |
---|
1646 | int cmpfilenameext(char* filename, char* ext) |
---|
1647 | { |
---|
1648 | char* zeichen = NULL; |
---|
1649 | |
---|
1650 | if(filename == NULL) return 1; |
---|
1651 | |
---|
1652 | zeichen = strrchr(filename, '.'); |
---|
1653 | if(zeichen != NULL) |
---|
1654 | { |
---|
1655 | if(ostrcasecmp(zeichen, ext) == 0) return 0; |
---|
1656 | } |
---|
1657 | |
---|
1658 | return 1; |
---|
1659 | } |
---|
1660 | |
---|
1661 | char* convert_timesec(int sec) |
---|
1662 | { |
---|
1663 | int hour = 0, min = 0, seconds = 0; |
---|
1664 | char* buf = NULL; |
---|
1665 | |
---|
1666 | buf = malloc(9); |
---|
1667 | if(buf == NULL) |
---|
1668 | { |
---|
1669 | err("no mem"); |
---|
1670 | return NULL; |
---|
1671 | } |
---|
1672 | |
---|
1673 | seconds = sec % 60; |
---|
1674 | min = (sec / 60) % 60; |
---|
1675 | hour = sec / 3600; |
---|
1676 | |
---|
1677 | if(seconds < 0) seconds = 0; |
---|
1678 | if(min < 0) min = 0; |
---|
1679 | if(hour < 0 || hour > 23) |
---|
1680 | { |
---|
1681 | hour = 0; |
---|
1682 | min = 0; |
---|
1683 | seconds = 0; |
---|
1684 | } |
---|
1685 | |
---|
1686 | snprintf(buf, 9, "%02d:%02d:%02d", hour, min, seconds); |
---|
1687 | |
---|
1688 | return buf; |
---|
1689 | } |
---|
1690 | |
---|
1691 | int checkdate() |
---|
1692 | { |
---|
1693 | time_t dvbtime = 0; |
---|
1694 | |
---|
1695 | if(time(NULL) < 1072224000 || status.timeupdatecount > 3600) // 01.01.2004 |
---|
1696 | { |
---|
1697 | if(dvbgetdate(&dvbtime, 10000000) == 0) //10 sek |
---|
1698 | { |
---|
1699 | setsystime(&dvbtime); |
---|
1700 | status.timeupdatecount = 0; |
---|
1701 | return 0; |
---|
1702 | } |
---|
1703 | return 1; |
---|
1704 | } |
---|
1705 | return 0; |
---|
1706 | } |
---|
1707 | |
---|
1708 | void closeonexec(fd) |
---|
1709 | { |
---|
1710 | if(fd > -1) |
---|
1711 | fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
---|
1712 | } |
---|
1713 | |
---|
1714 | void starthttpd(flag) |
---|
1715 | { |
---|
1716 | if(flag == 1) |
---|
1717 | { |
---|
1718 | if(getconfigint("httpdstart", NULL) == 1 && status.httpthread == NULL) |
---|
1719 | { |
---|
1720 | status.httpthread = addtimer(&httpdthreadfunc, START, 10000, -1, NULL, NULL, NULL); |
---|
1721 | if(status.httpthread != NULL) |
---|
1722 | status.httpthread->flag = setbit(status.httpthread->flag, 0); |
---|
1723 | } |
---|
1724 | } |
---|
1725 | else if(status.httpthread != NULL) |
---|
1726 | { |
---|
1727 | status.httpthread->aktion = STOP; |
---|
1728 | status.httpthread = NULL; |
---|
1729 | } |
---|
1730 | } |
---|
1731 | |
---|
1732 | int checkbox(char* box) |
---|
1733 | { |
---|
1734 | char* boxversion = NULL; |
---|
1735 | int ret = 0; |
---|
1736 | |
---|
1737 | if(status.boxtype == NULL) |
---|
1738 | { |
---|
1739 | if(isfile("/etc/model") == 0) return 0; |
---|
1740 | boxversion = string_toupper(readsys("/etc/model", 1)); |
---|
1741 | } |
---|
1742 | else |
---|
1743 | boxversion = status.boxtype; |
---|
1744 | |
---|
1745 | if(ostrcmp(boxversion, box) == 0) |
---|
1746 | { |
---|
1747 | status.boxtype = boxversion; |
---|
1748 | ret = 1; |
---|
1749 | } |
---|
1750 | |
---|
1751 | box = ostrcat(box, "\n", 0, 0); |
---|
1752 | if(ostrcmp(boxversion, box) == 0) |
---|
1753 | { |
---|
1754 | status.boxtype = boxversion; |
---|
1755 | ret = 1; |
---|
1756 | } |
---|
1757 | |
---|
1758 | if(status.boxtype == NULL) |
---|
1759 | free(boxversion); boxversion = NULL; |
---|
1760 | free(box); box = NULL; |
---|
1761 | |
---|
1762 | return ret; |
---|
1763 | } |
---|
1764 | |
---|
1765 | int setoverclockfreq(int mode) |
---|
1766 | { |
---|
1767 | // mode 0 = Set Standby Freq |
---|
1768 | // mode 1 = Set Freq |
---|
1769 | |
---|
1770 | if(ostrcmp(getownconfig("standby_overclock"), "0") == 0) |
---|
1771 | return 1; |
---|
1772 | |
---|
1773 | if(isfile("/proc/cpu_frequ/pll0_ndiv_mdiv") == 0) |
---|
1774 | return 1; |
---|
1775 | |
---|
1776 | char* tmpstr = NULL; |
---|
1777 | |
---|
1778 | if(mode == 0) |
---|
1779 | tmpstr = getownconfig("standby_freq"); |
---|
1780 | else |
---|
1781 | tmpstr = getownconfig("pll0_ndiv_mdiv"); |
---|
1782 | |
---|
1783 | return writesys("/proc/cpu_frequ/pll0_ndiv_mdiv", tmpstr, 1); |
---|
1784 | } |
---|
1785 | |
---|
1786 | int setsaturation(int value) |
---|
1787 | { |
---|
1788 | debug(1000, "in"); |
---|
1789 | char* saturationdev; |
---|
1790 | |
---|
1791 | saturationdev = getconfig("saturationdev", NULL); |
---|
1792 | |
---|
1793 | if(saturationdev != NULL) |
---|
1794 | { |
---|
1795 | debug(100, "set %s to %d", saturationdev, value); |
---|
1796 | return writesysint(saturationdev, value, 1); |
---|
1797 | } |
---|
1798 | |
---|
1799 | debug(1000, "out"); |
---|
1800 | return 0; |
---|
1801 | } |
---|
1802 | |
---|
1803 | int setbrightness(int value) |
---|
1804 | { |
---|
1805 | debug(1000, "in"); |
---|
1806 | char* brightnessdev; |
---|
1807 | |
---|
1808 | brightnessdev = getconfig("brightnessdev", NULL); |
---|
1809 | |
---|
1810 | if(brightnessdev != NULL) |
---|
1811 | { |
---|
1812 | debug(100, "set %s to %d", brightnessdev, value); |
---|
1813 | return writesysint(brightnessdev, value, 1); |
---|
1814 | } |
---|
1815 | |
---|
1816 | debug(1000, "out"); |
---|
1817 | return 0; |
---|
1818 | } |
---|
1819 | |
---|
1820 | int setvmpeg(struct dvbdev* node, int value, int flag) |
---|
1821 | { |
---|
1822 | debug(1000, "in"); |
---|
1823 | char* vmpegdev = NULL, *tmpstr = NULL, *buf = NULL; |
---|
1824 | int ret = 0; |
---|
1825 | |
---|
1826 | if(node == NULL) return 1; |
---|
1827 | if(flag == 0) vmpegdev = getconfig("vmpegleftdev", NULL); |
---|
1828 | if(flag == 1) vmpegdev = getconfig("vmpegtopdev", NULL); |
---|
1829 | if(flag == 2) vmpegdev = getconfig("vmpegwidthdev", NULL); |
---|
1830 | if(flag == 3) vmpegdev = getconfig("vmpegheightdev", NULL); |
---|
1831 | |
---|
1832 | if(vmpegdev != NULL) |
---|
1833 | { |
---|
1834 | buf = malloc(MINMALLOC); |
---|
1835 | if(buf == NULL) |
---|
1836 | { |
---|
1837 | err("no mem"); |
---|
1838 | return 1; |
---|
1839 | } |
---|
1840 | |
---|
1841 | tmpstr = malloc(10); |
---|
1842 | if(tmpstr == NULL) |
---|
1843 | { |
---|
1844 | err("no mem"); |
---|
1845 | free(buf); |
---|
1846 | return 1; |
---|
1847 | } |
---|
1848 | |
---|
1849 | snprintf(buf, MINMALLOC, vmpegdev, node->devnr); |
---|
1850 | snprintf(tmpstr, 10, "%x", value); |
---|
1851 | debug(100, "set %s to %s", buf, tmpstr); |
---|
1852 | status.tvpic = 1; |
---|
1853 | ret = writesys(buf, tmpstr, 1); |
---|
1854 | |
---|
1855 | free(tmpstr); |
---|
1856 | free(buf); |
---|
1857 | return ret; |
---|
1858 | } |
---|
1859 | |
---|
1860 | debug(1000, "out"); |
---|
1861 | return 0; |
---|
1862 | } |
---|
1863 | |
---|
1864 | //flag 0: wh = width |
---|
1865 | //flag 1: wh = height |
---|
1866 | int setvmpegrect(struct dvbdev* node, int left, int top, int wh, int flag) |
---|
1867 | { |
---|
1868 | int ret = 0; |
---|
1869 | |
---|
1870 | if(flag == 0) |
---|
1871 | { |
---|
1872 | ret = setvmpeg(node, wh, 2); |
---|
1873 | ret = setvmpeg(node, wh / 1.4, 3); |
---|
1874 | } |
---|
1875 | if(flag == 1) |
---|
1876 | { |
---|
1877 | ret = setvmpeg(node, wh, 3); |
---|
1878 | ret = setvmpeg(node, wh * 1.3, 2); |
---|
1879 | } |
---|
1880 | |
---|
1881 | ret = setvmpeg(node, left, 0); |
---|
1882 | ret = setvmpeg(node, top, 1); |
---|
1883 | |
---|
1884 | return ret; |
---|
1885 | } |
---|
1886 | |
---|
1887 | int resetvmpeg(struct dvbdev* node) |
---|
1888 | { |
---|
1889 | int ret = 0; |
---|
1890 | |
---|
1891 | ret = setvmpeg(node, 0, 0); |
---|
1892 | ret = setvmpeg(node, 0, 1); |
---|
1893 | ret = setvmpeg(node, 0, 2); |
---|
1894 | ret = setvmpeg(node, 0, 3); |
---|
1895 | |
---|
1896 | return ret; |
---|
1897 | } |
---|
1898 | |
---|
1899 | void resettvpic() |
---|
1900 | { |
---|
1901 | if(status.tvpic == 1 && status.aktservice != NULL) |
---|
1902 | { |
---|
1903 | status.tvpic = 0; |
---|
1904 | resetvmpeg(status.aktservice->videodev); |
---|
1905 | } |
---|
1906 | } |
---|
1907 | |
---|
1908 | int setcontrast(int value) |
---|
1909 | { |
---|
1910 | debug(1000, "in"); |
---|
1911 | char* contrastdev; |
---|
1912 | |
---|
1913 | contrastdev = getconfig("contrastdev", NULL); |
---|
1914 | |
---|
1915 | if(contrastdev != NULL) |
---|
1916 | { |
---|
1917 | debug(100, "set %s to %d", contrastdev, value); |
---|
1918 | return writesysint(contrastdev, value, 1); |
---|
1919 | } |
---|
1920 | |
---|
1921 | debug(1000, "out"); |
---|
1922 | return 0; |
---|
1923 | } |
---|
1924 | |
---|
1925 | int settint(int value) |
---|
1926 | { |
---|
1927 | debug(1000, "in"); |
---|
1928 | char* tintdev; |
---|
1929 | |
---|
1930 | tintdev = getconfig("tintdev", NULL); |
---|
1931 | |
---|
1932 | if(tintdev != NULL) |
---|
1933 | { |
---|
1934 | debug(100, "set %s to %d", tintdev, value); |
---|
1935 | return writesysint(tintdev, value, 1); |
---|
1936 | } |
---|
1937 | |
---|
1938 | debug(1000, "out"); |
---|
1939 | return 0; |
---|
1940 | } |
---|
1941 | |
---|
1942 | int zip(char* inbuf, int inlen, char** outbuf, int* outlen, int level) |
---|
1943 | { |
---|
1944 | int ret = 0; |
---|
1945 | z_stream stream; |
---|
1946 | |
---|
1947 | if(inlen > MINMALLOC) |
---|
1948 | return 1; |
---|
1949 | |
---|
1950 | stream.zalloc = Z_NULL; |
---|
1951 | stream.zfree = Z_NULL; |
---|
1952 | stream.opaque = Z_NULL; |
---|
1953 | |
---|
1954 | ret = deflateInit(&stream, level); |
---|
1955 | if(ret != Z_OK) |
---|
1956 | return 1; |
---|
1957 | |
---|
1958 | *outbuf = malloc(inlen); |
---|
1959 | if(*outbuf == NULL) |
---|
1960 | { |
---|
1961 | err("no mem"); |
---|
1962 | (void)deflateEnd(&stream); |
---|
1963 | return 1; |
---|
1964 | } |
---|
1965 | |
---|
1966 | stream.avail_in = inlen; |
---|
1967 | stream.next_in = (void*)inbuf; |
---|
1968 | |
---|
1969 | do |
---|
1970 | { |
---|
1971 | stream.avail_out = inlen; |
---|
1972 | stream.next_out = (void*)*outbuf; |
---|
1973 | |
---|
1974 | ret = deflate(&stream, Z_FINISH); |
---|
1975 | if(ret == Z_STREAM_ERROR) |
---|
1976 | { |
---|
1977 | free(*outbuf); *outbuf = NULL; |
---|
1978 | (void)deflateEnd(&stream); |
---|
1979 | return 1; |
---|
1980 | } |
---|
1981 | |
---|
1982 | } |
---|
1983 | while(stream.avail_out == 0); |
---|
1984 | *outlen = inlen - stream.avail_out; |
---|
1985 | *outbuf = realloc(*outbuf, *outlen); |
---|
1986 | |
---|
1987 | (void)deflateEnd(&stream); |
---|
1988 | return 0; |
---|
1989 | } |
---|
1990 | |
---|
1991 | int ounzip(char* inbuf, int inlen, char** outbuf, int* outlen) |
---|
1992 | { |
---|
1993 | int ret = 0; |
---|
1994 | z_stream stream; |
---|
1995 | |
---|
1996 | stream.zalloc = Z_NULL; |
---|
1997 | stream.zfree = Z_NULL; |
---|
1998 | stream.opaque = Z_NULL; |
---|
1999 | stream.avail_in = 0; |
---|
2000 | stream.next_in = Z_NULL; |
---|
2001 | |
---|
2002 | ret = inflateInit(&stream); |
---|
2003 | if(ret != Z_OK) |
---|
2004 | return 1; |
---|
2005 | |
---|
2006 | *outbuf = malloc(MINMALLOC); |
---|
2007 | if(*outbuf == NULL) |
---|
2008 | { |
---|
2009 | err("no mem"); |
---|
2010 | (void)inflateEnd(&stream); |
---|
2011 | return 1; |
---|
2012 | } |
---|
2013 | |
---|
2014 | stream.avail_in = inlen; |
---|
2015 | stream.next_in = (void*)inbuf; |
---|
2016 | |
---|
2017 | do |
---|
2018 | { |
---|
2019 | stream.avail_out = MINMALLOC; |
---|
2020 | stream.next_out = (void*)*outbuf; |
---|
2021 | |
---|
2022 | ret = inflate(&stream, Z_NO_FLUSH); |
---|
2023 | if(ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) |
---|
2024 | { |
---|
2025 | free(*outbuf); *outbuf = NULL; |
---|
2026 | (void)inflateEnd(&stream); |
---|
2027 | return 1; |
---|
2028 | } |
---|
2029 | |
---|
2030 | } |
---|
2031 | while(stream.avail_out == 0); |
---|
2032 | *outlen = MINMALLOC - stream.avail_out; |
---|
2033 | *outbuf = realloc(*outbuf, *outlen); |
---|
2034 | |
---|
2035 | (void)inflateEnd(&stream); |
---|
2036 | return 0; |
---|
2037 | } |
---|
2038 | |
---|
2039 | void endianswapshort(unsigned short* value) |
---|
2040 | { |
---|
2041 | *value = (*value >> 8) | (*value << 8); |
---|
2042 | } |
---|
2043 | |
---|
2044 | int rcnumber(int rcret) |
---|
2045 | { |
---|
2046 | if(rcret == getrcconfigint("rc0", NULL) || |
---|
2047 | rcret == getrcconfigint("rc1", NULL) || |
---|
2048 | rcret == getrcconfigint("rc2", NULL) || |
---|
2049 | rcret == getrcconfigint("rc3", NULL) || |
---|
2050 | rcret == getrcconfigint("rc4", NULL) || |
---|
2051 | rcret == getrcconfigint("rc5", NULL) || |
---|
2052 | rcret == getrcconfigint("rc6", NULL) || |
---|
2053 | rcret == getrcconfigint("rc7", NULL) || |
---|
2054 | rcret == getrcconfigint("rc8", NULL) || |
---|
2055 | rcret == getrcconfigint("rc9", NULL)) |
---|
2056 | return rcret; |
---|
2057 | else |
---|
2058 | return -9999; |
---|
2059 | } |
---|
2060 | |
---|
2061 | int delallfiles(char* dir, char* ext) |
---|
2062 | { |
---|
2063 | struct dirent *dirent = NULL; |
---|
2064 | DIR *pdir = NULL; |
---|
2065 | char* tmpstr = NULL; |
---|
2066 | |
---|
2067 | pdir = opendir(dir); |
---|
2068 | if(pdir != NULL) |
---|
2069 | { |
---|
2070 | while((dirent = readdir(pdir)) != NULL) |
---|
2071 | { |
---|
2072 | if(ostrcmp(".", dirent->d_name) != 0 && ostrcmp("..", dirent->d_name) != 0) |
---|
2073 | { |
---|
2074 | if(ext == NULL || strstr(dirent->d_name, ext) != NULL) |
---|
2075 | { |
---|
2076 | tmpstr = ostrcat(dir, "/", 0, 0); |
---|
2077 | tmpstr = ostrcat(tmpstr, dirent->d_name, 1, 0); |
---|
2078 | unlink(tmpstr); |
---|
2079 | free(tmpstr); tmpstr = NULL; |
---|
2080 | } |
---|
2081 | } |
---|
2082 | } |
---|
2083 | |
---|
2084 | closedir(pdir); |
---|
2085 | } |
---|
2086 | |
---|
2087 | return 0; |
---|
2088 | } |
---|
2089 | |
---|
2090 | unsigned long getfilecount(char* dir) |
---|
2091 | { |
---|
2092 | unsigned long count = 0; |
---|
2093 | struct dirent *dirent = NULL; |
---|
2094 | DIR *pdir = NULL; |
---|
2095 | |
---|
2096 | pdir = opendir(dir); |
---|
2097 | if(pdir != NULL) |
---|
2098 | { |
---|
2099 | while((dirent = readdir(pdir)) != NULL) |
---|
2100 | count++; |
---|
2101 | |
---|
2102 | closedir(pdir); |
---|
2103 | } |
---|
2104 | |
---|
2105 | return count; |
---|
2106 | } |
---|
2107 | |
---|
2108 | long long getfreespace(char* dir) |
---|
2109 | { |
---|
2110 | struct statfs64 s; |
---|
2111 | long long freesize = 0; |
---|
2112 | |
---|
2113 | if(statfs64(dir, &s) >= 0) |
---|
2114 | { |
---|
2115 | freesize = s.f_bfree; |
---|
2116 | freesize *= s.f_bsize; |
---|
2117 | } |
---|
2118 | |
---|
2119 | return freesize; |
---|
2120 | } |
---|
2121 | |
---|
2122 | int checkbit(int value, int bitpos) |
---|
2123 | { |
---|
2124 | int ret = 0; |
---|
2125 | |
---|
2126 | ret = value & (1 << bitpos) ? 1: 0; |
---|
2127 | return ret; |
---|
2128 | } |
---|
2129 | |
---|
2130 | int tooglebit(int value, int bitpos) |
---|
2131 | { |
---|
2132 | value ^= 1 << bitpos; |
---|
2133 | return value; |
---|
2134 | } |
---|
2135 | |
---|
2136 | int clearbit(int value, int bitpos) |
---|
2137 | { |
---|
2138 | value &= ~(1 << bitpos); |
---|
2139 | return value; |
---|
2140 | } |
---|
2141 | |
---|
2142 | int setbit(int value, int bitpos) |
---|
2143 | { |
---|
2144 | value |= 1 << bitpos; |
---|
2145 | return value; |
---|
2146 | } |
---|
2147 | |
---|
2148 | int setsystime(time_t* newtime) |
---|
2149 | { |
---|
2150 | if (stime(newtime)) |
---|
2151 | { |
---|
2152 | err("can't set system time"); |
---|
2153 | return 1; |
---|
2154 | } |
---|
2155 | return 0; |
---|
2156 | } |
---|
2157 | |
---|
2158 | off64_t getfilesize(char* name) |
---|
2159 | { |
---|
2160 | struct stat64 sbuf; |
---|
2161 | |
---|
2162 | if(lstat64(name, &sbuf) == -1) |
---|
2163 | return 0; |
---|
2164 | |
---|
2165 | return sbuf.st_size; |
---|
2166 | } |
---|
2167 | |
---|
2168 | time_t getfiletime(char* name, int type) |
---|
2169 | { |
---|
2170 | struct stat64 sbuf; |
---|
2171 | |
---|
2172 | if(lstat64(name, &sbuf) == -1) |
---|
2173 | return 0; |
---|
2174 | |
---|
2175 | switch(type) |
---|
2176 | { |
---|
2177 | case 1: return sbuf.st_mtime; |
---|
2178 | case 2: return sbuf.st_ctime; |
---|
2179 | default: return sbuf.st_atime; |
---|
2180 | } |
---|
2181 | } |
---|
2182 | |
---|
2183 | int isfile(char* name) |
---|
2184 | { |
---|
2185 | struct stat64 sbuf; |
---|
2186 | |
---|
2187 | if(lstat64(name, &sbuf) == -1) |
---|
2188 | return 0; |
---|
2189 | |
---|
2190 | if(S_ISREG(sbuf.st_mode)) |
---|
2191 | return 1; |
---|
2192 | |
---|
2193 | return 0; |
---|
2194 | } |
---|
2195 | |
---|
2196 | int isdir(char* name) |
---|
2197 | { |
---|
2198 | struct stat64 sbuf; |
---|
2199 | char *rpath = NULL; |
---|
2200 | |
---|
2201 | if(lstat64(name, &sbuf) == -1) |
---|
2202 | return 0; |
---|
2203 | |
---|
2204 | if(S_ISDIR(sbuf.st_mode)) |
---|
2205 | return 1; |
---|
2206 | |
---|
2207 | if(S_ISLNK(sbuf.st_mode)) |
---|
2208 | { |
---|
2209 | rpath = realpath(name, NULL); |
---|
2210 | if(lstat64(rpath, &sbuf) == -1) |
---|
2211 | { |
---|
2212 | free(rpath); |
---|
2213 | return 0; |
---|
2214 | } |
---|
2215 | free(rpath); |
---|
2216 | if(S_ISDIR(sbuf.st_mode)) |
---|
2217 | return 1; |
---|
2218 | } |
---|
2219 | |
---|
2220 | return 0; |
---|
2221 | } |
---|
2222 | |
---|
2223 | char* getmaxsatstring(int maxsat) |
---|
2224 | { |
---|
2225 | char* tmpstr = NULL, *tmpnr = NULL; |
---|
2226 | int i; |
---|
2227 | |
---|
2228 | tmpstr = ostrcat(tmpstr, "1", 1, 0); |
---|
2229 | for(i = 2; i <= maxsat; i++) |
---|
2230 | { |
---|
2231 | tmpnr = oitoa(i); |
---|
2232 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
2233 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
2234 | } |
---|
2235 | return tmpstr; |
---|
2236 | } |
---|
2237 | |
---|
2238 | void ostrcatbig(char** value1, char* value2, int* maxlen, int* pos) |
---|
2239 | { |
---|
2240 | // debug(1000, "in"); |
---|
2241 | int len = 0; |
---|
2242 | |
---|
2243 | if(value2 == NULL) |
---|
2244 | { |
---|
2245 | debug(1000, "out -> NULL detect"); |
---|
2246 | return; |
---|
2247 | } |
---|
2248 | len = strlen(value2); |
---|
2249 | |
---|
2250 | if(len > MINMALLOC) |
---|
2251 | { |
---|
2252 | err("string to long"); |
---|
2253 | return; |
---|
2254 | } |
---|
2255 | |
---|
2256 | if(*value1 != NULL && maxlen == 0) |
---|
2257 | *maxlen = strlen(*value1); |
---|
2258 | |
---|
2259 | if(*value1 == NULL || *pos + len + 1 > *maxlen) |
---|
2260 | { |
---|
2261 | *maxlen = *maxlen + (MINMALLOC * 10); |
---|
2262 | *value1 = realloc(*value1, *maxlen); |
---|
2263 | if(*value1 == NULL) |
---|
2264 | { |
---|
2265 | err("no memory"); |
---|
2266 | return; |
---|
2267 | } |
---|
2268 | } |
---|
2269 | |
---|
2270 | memcpy(*value1 + *pos, value2, len + 1); |
---|
2271 | *pos = *pos + len; |
---|
2272 | |
---|
2273 | //debug(1000, "out"); |
---|
2274 | } |
---|
2275 | |
---|
2276 | char* ostrcat(char* value1, char* value2, int free1, int free2) |
---|
2277 | { |
---|
2278 | // debug(1000, "in"); |
---|
2279 | char* buf = NULL; |
---|
2280 | |
---|
2281 | if(value1 == NULL && value2 == NULL) return NULL; |
---|
2282 | |
---|
2283 | if(value2 == NULL) |
---|
2284 | { |
---|
2285 | value2 = malloc(1); |
---|
2286 | if(value2 == NULL) |
---|
2287 | { |
---|
2288 | err("no memory"); |
---|
2289 | return NULL; |
---|
2290 | } |
---|
2291 | free2 = 1; |
---|
2292 | value2[0] = '\0'; |
---|
2293 | } |
---|
2294 | |
---|
2295 | if(value1 == NULL) |
---|
2296 | { |
---|
2297 | value1 = malloc(1); |
---|
2298 | if(value1 == NULL) |
---|
2299 | { |
---|
2300 | err("no memory"); |
---|
2301 | return NULL; |
---|
2302 | } |
---|
2303 | free1 = 1; |
---|
2304 | value1[0] = '\0'; |
---|
2305 | } |
---|
2306 | |
---|
2307 | buf = malloc(strlen(value1) + strlen(value2) + 1); |
---|
2308 | if(buf == NULL) |
---|
2309 | { |
---|
2310 | err("no memory"); |
---|
2311 | return NULL; |
---|
2312 | } |
---|
2313 | |
---|
2314 | sprintf(buf, "%s%s", value1, value2); |
---|
2315 | |
---|
2316 | if(free1 == 1) {free(value1); value1 = NULL;} |
---|
2317 | if(free2 == 1) {free(value2); value2 = NULL;} |
---|
2318 | |
---|
2319 | //helpfull for memleak detect |
---|
2320 | //if(buf != NULL && strlen(buf) == 0x0b - 0x01) |
---|
2321 | // printf("******** memleak string (%s) (%p) ********\n", buf, buf); |
---|
2322 | |
---|
2323 | //debug(1000, "out"); |
---|
2324 | return buf; |
---|
2325 | } |
---|
2326 | |
---|
2327 | char* olutoa(unsigned long value) |
---|
2328 | { |
---|
2329 | debug(1000, "in"); |
---|
2330 | char *buf = NULL, *buf1 = NULL; |
---|
2331 | |
---|
2332 | buf = malloc(MINMALLOC); |
---|
2333 | if(buf == NULL) |
---|
2334 | { |
---|
2335 | err("no memory"); |
---|
2336 | return NULL; |
---|
2337 | } |
---|
2338 | |
---|
2339 | sprintf(buf, "%lu", value); |
---|
2340 | buf1 = ostrcat(buf, "", 1, 0); |
---|
2341 | |
---|
2342 | debug(1000, "out"); |
---|
2343 | return buf1; |
---|
2344 | } |
---|
2345 | |
---|
2346 | char* oitoa(int value) |
---|
2347 | { |
---|
2348 | debug(1000, "in"); |
---|
2349 | char *buf = NULL, *buf1 = NULL; |
---|
2350 | |
---|
2351 | buf = malloc(MINMALLOC); |
---|
2352 | if(buf == NULL) |
---|
2353 | { |
---|
2354 | err("no memory"); |
---|
2355 | return NULL; |
---|
2356 | } |
---|
2357 | |
---|
2358 | sprintf(buf, "%d", value); |
---|
2359 | buf1 = ostrcat(buf, "", 1, 0); |
---|
2360 | |
---|
2361 | debug(1000, "out"); |
---|
2362 | return buf1; |
---|
2363 | } |
---|
2364 | |
---|
2365 | char* oitoa64(off64_t value) |
---|
2366 | { |
---|
2367 | debug(1000, "in"); |
---|
2368 | char *buf = NULL, *buf1 = NULL; |
---|
2369 | |
---|
2370 | buf = malloc(MINMALLOC); |
---|
2371 | if(buf == NULL) |
---|
2372 | { |
---|
2373 | err("no memory"); |
---|
2374 | return NULL; |
---|
2375 | } |
---|
2376 | |
---|
2377 | sprintf(buf, "%lld", value); |
---|
2378 | buf1 = ostrcat(buf, "", 1, 0); |
---|
2379 | |
---|
2380 | debug(1000, "out"); |
---|
2381 | return buf1; |
---|
2382 | } |
---|
2383 | |
---|
2384 | char* oftoa64(double value, char* count) |
---|
2385 | { |
---|
2386 | debug(1000, "in"); |
---|
2387 | char *buf = NULL, *buf1 = NULL; |
---|
2388 | char* tmpstr = NULL; |
---|
2389 | |
---|
2390 | buf = malloc(MINMALLOC); |
---|
2391 | if(buf == NULL) |
---|
2392 | { |
---|
2393 | err("no memory"); |
---|
2394 | return NULL; |
---|
2395 | } |
---|
2396 | |
---|
2397 | tmpstr = ostrcat("%.", count, 0, 0); |
---|
2398 | tmpstr = ostrcat(tmpstr, "f", 1, 0); |
---|
2399 | |
---|
2400 | sprintf(buf, tmpstr, value); |
---|
2401 | buf1 = ostrcat(buf, "", 1, 0); |
---|
2402 | |
---|
2403 | free(tmpstr); |
---|
2404 | debug(1000, "out"); |
---|
2405 | return buf1; |
---|
2406 | } |
---|
2407 | |
---|
2408 | int ostrncmp(char* value1, char* value2, int count) |
---|
2409 | { |
---|
2410 | //debug(1000, "in"); |
---|
2411 | int ret = 1; |
---|
2412 | |
---|
2413 | if(value1 != NULL && value2 != NULL) |
---|
2414 | ret = strncmp(value1, value2, count); |
---|
2415 | |
---|
2416 | //debug(1000, "out"); |
---|
2417 | return ret; |
---|
2418 | } |
---|
2419 | |
---|
2420 | int ostrcmp(char* value1, char* value2) |
---|
2421 | { |
---|
2422 | // debug(1000, "in"); |
---|
2423 | int ret = 1; |
---|
2424 | |
---|
2425 | if(value1 != NULL && value2 != NULL) |
---|
2426 | ret = strcmp(value1, value2); |
---|
2427 | |
---|
2428 | // debug(1000, "out"); |
---|
2429 | return ret; |
---|
2430 | } |
---|
2431 | |
---|
2432 | int ostrcasecmp(char* value1, char* value2) |
---|
2433 | { |
---|
2434 | // debug(1000, "in"); |
---|
2435 | int ret = 1; |
---|
2436 | |
---|
2437 | if(value1 != NULL && value2 != NULL) |
---|
2438 | ret = strcasecmp(value1, value2); |
---|
2439 | |
---|
2440 | // debug(1000, "out"); |
---|
2441 | return ret; |
---|
2442 | } |
---|
2443 | |
---|
2444 | char* createpath(char* dir, char* file) |
---|
2445 | { |
---|
2446 | debug(1000, "in"); |
---|
2447 | char *absdir = NULL; |
---|
2448 | char *pos = NULL; |
---|
2449 | char* tmpdir = NULL; |
---|
2450 | |
---|
2451 | if(dir == NULL || file == NULL) |
---|
2452 | { |
---|
2453 | debug(1000, "out -> NULL detect"); |
---|
2454 | return NULL; |
---|
2455 | } |
---|
2456 | |
---|
2457 | tmpdir = ostrcat(dir, "", 0, 0); |
---|
2458 | if(tmpdir == NULL) |
---|
2459 | { |
---|
2460 | debug(1000, "out -> NULL detect"); |
---|
2461 | return NULL; |
---|
2462 | } |
---|
2463 | |
---|
2464 | while((tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] != '.') || tmpdir[strlen(tmpdir) - 1] == '/') |
---|
2465 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
2466 | |
---|
2467 | while(tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] == '.') |
---|
2468 | { |
---|
2469 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
2470 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
2471 | if(tmpdir[strlen(tmpdir) - 1] == '/') |
---|
2472 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
2473 | pos = strrchr(tmpdir, '/'); |
---|
2474 | if(pos != NULL) |
---|
2475 | pos[0] = '\0'; |
---|
2476 | } |
---|
2477 | |
---|
2478 | absdir = malloc(strlen(tmpdir) + strlen(file) + 2); |
---|
2479 | if(absdir == NULL) |
---|
2480 | { |
---|
2481 | free(tmpdir); |
---|
2482 | err("no memory"); |
---|
2483 | return NULL; |
---|
2484 | } |
---|
2485 | |
---|
2486 | if(strlen(file) > 0 || strlen(tmpdir) == 0) |
---|
2487 | sprintf(absdir, "%s/%s", tmpdir, file); |
---|
2488 | else |
---|
2489 | sprintf(absdir, "%s", tmpdir); |
---|
2490 | |
---|
2491 | debug(1000, "out"); |
---|
2492 | free(tmpdir); |
---|
2493 | return absdir; |
---|
2494 | } |
---|
2495 | |
---|
2496 | int settimezone(char* zone) |
---|
2497 | { |
---|
2498 | debug(1000, "in"); |
---|
2499 | int ret = 0; |
---|
2500 | char* tmpzone = NULL, *zonepath = NULL; |
---|
2501 | |
---|
2502 | zonepath = getconfig("zonepath", NULL); |
---|
2503 | if(zonepath == NULL) |
---|
2504 | { |
---|
2505 | err("config zonepath not defined"); |
---|
2506 | return 1; |
---|
2507 | } |
---|
2508 | |
---|
2509 | tmpzone = createpath(zonepath, zone); |
---|
2510 | if(tmpzone == NULL) |
---|
2511 | return 1; |
---|
2512 | |
---|
2513 | setenv("TZ", zone, 1); |
---|
2514 | |
---|
2515 | ret = unlink(getconfig("localtimefile", NULL)); |
---|
2516 | if(ret != 0) |
---|
2517 | perr("unlink"); |
---|
2518 | ret = symlink(tmpzone, getconfig("localtimefile", NULL)); |
---|
2519 | if(ret != 0) |
---|
2520 | perr("link"); |
---|
2521 | |
---|
2522 | free(tmpzone); |
---|
2523 | debug(1000, "out"); |
---|
2524 | return ret; |
---|
2525 | } |
---|
2526 | |
---|
2527 | int delchar(char** text, int pos) |
---|
2528 | { |
---|
2529 | debug(1000, "in"); |
---|
2530 | char *tmptext = NULL; |
---|
2531 | int i = 0, y = 0, len = 0; |
---|
2532 | |
---|
2533 | if(text == NULL || *text == NULL) |
---|
2534 | { |
---|
2535 | debug(1000, "out -> NULL detect"); |
---|
2536 | return pos; |
---|
2537 | } |
---|
2538 | |
---|
2539 | len = strlen(*text); |
---|
2540 | if(len == 0) return pos; |
---|
2541 | |
---|
2542 | tmptext = malloc(strlen(*text)); |
---|
2543 | if(tmptext == NULL) |
---|
2544 | { |
---|
2545 | err("no memory"); |
---|
2546 | return pos; |
---|
2547 | } |
---|
2548 | |
---|
2549 | for(i = 0; i < strlen(*text); i++) |
---|
2550 | { |
---|
2551 | if(i == pos - 1) |
---|
2552 | y++; |
---|
2553 | |
---|
2554 | tmptext[i] = (*text)[y]; |
---|
2555 | y++; |
---|
2556 | } |
---|
2557 | |
---|
2558 | if(i > 0) tmptext[i - 1] = '\0'; |
---|
2559 | if(pos >= strlen(tmptext)) pos = strlen(tmptext); |
---|
2560 | |
---|
2561 | free(*text); |
---|
2562 | *text = tmptext; |
---|
2563 | debug(1000, "out"); |
---|
2564 | return pos; |
---|
2565 | } |
---|
2566 | |
---|
2567 | |
---|
2568 | int insertchar(char** text, char zeichen, int pos) |
---|
2569 | { |
---|
2570 | debug(1000, "in"); |
---|
2571 | char *tmptext = NULL; |
---|
2572 | int i, y = 0; |
---|
2573 | |
---|
2574 | if(text == NULL || *text == NULL) |
---|
2575 | { |
---|
2576 | debug(1000, "out -> NULL detect"); |
---|
2577 | return pos; |
---|
2578 | } |
---|
2579 | |
---|
2580 | tmptext = malloc(strlen(*text) + 2); |
---|
2581 | if(tmptext == NULL) |
---|
2582 | { |
---|
2583 | err("no memory"); |
---|
2584 | return pos; |
---|
2585 | } |
---|
2586 | |
---|
2587 | if(strlen(*text) == 0) |
---|
2588 | { |
---|
2589 | tmptext[0] = zeichen; |
---|
2590 | i = 1; |
---|
2591 | pos = 0; |
---|
2592 | } |
---|
2593 | else |
---|
2594 | { |
---|
2595 | for(i = 0; i < strlen(*text) + 1; i++) |
---|
2596 | { |
---|
2597 | if(i == pos) |
---|
2598 | tmptext[i] = zeichen; |
---|
2599 | else |
---|
2600 | { |
---|
2601 | tmptext[i] = (*text)[y]; |
---|
2602 | y++; |
---|
2603 | } |
---|
2604 | } |
---|
2605 | } |
---|
2606 | tmptext[i] = '\0'; |
---|
2607 | |
---|
2608 | free(*text); |
---|
2609 | *text = tmptext; |
---|
2610 | debug(1000, "out"); |
---|
2611 | return pos + 1; |
---|
2612 | } |
---|
2613 | |
---|
2614 | void sighandler(int sig, struct sigcontext ctx) |
---|
2615 | { |
---|
2616 | debug(1000, "in"); |
---|
2617 | switch(sig) |
---|
2618 | { |
---|
2619 | case SIGUSR1: |
---|
2620 | { |
---|
2621 | //todo all configs |
---|
2622 | reloadconfig(status.configfile); |
---|
2623 | reloadconfig(getconfig("ownconfig", NULL)); |
---|
2624 | break; |
---|
2625 | } |
---|
2626 | case SIGSEGV: |
---|
2627 | case SIGBUS: |
---|
2628 | case SIGABRT: |
---|
2629 | { |
---|
2630 | #ifdef SIMULATE |
---|
2631 | //intel |
---|
2632 | debugstack((void *)ctx.eip, NULL); |
---|
2633 | err("got signal %d, fault address 0x%lx from 0x%lx", sig, ctx.cr2, ctx.eip); |
---|
2634 | #else |
---|
2635 | /* sh4 |
---|
2636 | unsigned long sc_regs[16]; |
---|
2637 | unsigned long sc_pc; //programm counter register |
---|
2638 | unsigned long sc_pr; //procedure register |
---|
2639 | unsigned long sc_sr; //status register |
---|
2640 | unsigned long sc_gbr; |
---|
2641 | unsigned long sc_mach; |
---|
2642 | unsigned long sc_macl; */ |
---|
2643 | |
---|
2644 | debugstack((void *)ctx.sc_pr, (void *)ctx.sc_pc); |
---|
2645 | err("got signal %d, programm counter reg: 0x%lx, procedure reg: 0x%lx", sig, ctx.sc_pc, ctx.sc_pr); |
---|
2646 | #endif |
---|
2647 | if(getconfigint("saverun", NULL) == 1 && status.longjumpbuf != NULL) |
---|
2648 | siglongjmp(status.longjumpbuf, 1); |
---|
2649 | else |
---|
2650 | exit(100); |
---|
2651 | break; |
---|
2652 | } |
---|
2653 | } |
---|
2654 | debug(1000, "out"); |
---|
2655 | } |
---|
2656 | |
---|
2657 | void calctext(char* buf, char* buf1, unsigned int* linecount, unsigned int* pagecount, unsigned int* poscount, int pagelen, int page) |
---|
2658 | { |
---|
2659 | debug(1000, "in"); |
---|
2660 | unsigned int tmpposcount = 0; |
---|
2661 | |
---|
2662 | *poscount = 0; |
---|
2663 | *linecount = 1; |
---|
2664 | *pagecount = 1; |
---|
2665 | |
---|
2666 | page--; |
---|
2667 | if(page < 0) page = 0; |
---|
2668 | |
---|
2669 | if(buf != NULL) |
---|
2670 | { |
---|
2671 | while(*buf != '\0') |
---|
2672 | { |
---|
2673 | if(*buf == '\n') |
---|
2674 | { |
---|
2675 | if(*(buf + 1) == '\0') break; |
---|
2676 | (*linecount)++; |
---|
2677 | |
---|
2678 | if(*linecount - 1 == pagelen * page) |
---|
2679 | *poscount = tmpposcount + 1; |
---|
2680 | } |
---|
2681 | buf++; |
---|
2682 | tmpposcount++; |
---|
2683 | } |
---|
2684 | } |
---|
2685 | |
---|
2686 | if(buf1 != NULL) |
---|
2687 | { |
---|
2688 | while(*buf1 != '\0') |
---|
2689 | { |
---|
2690 | if(*buf1 == '\n') |
---|
2691 | { |
---|
2692 | if(*(buf1 + 1) == '\0') break; |
---|
2693 | (*linecount)++; |
---|
2694 | |
---|
2695 | if(*linecount - 1 == pagelen * page) |
---|
2696 | *poscount = tmpposcount + 1; |
---|
2697 | } |
---|
2698 | buf1++; |
---|
2699 | tmpposcount++; |
---|
2700 | } |
---|
2701 | } |
---|
2702 | |
---|
2703 | if(pagelen > 0) |
---|
2704 | *pagecount = (int)ceil(((float)*linecount / pagelen)); |
---|
2705 | |
---|
2706 | debug(1000, "out"); |
---|
2707 | } |
---|
2708 | |
---|
2709 | int initlocale(char *localepath) |
---|
2710 | { |
---|
2711 | debug(1000, "in"); |
---|
2712 | setlocale(LC_ALL, ""); |
---|
2713 | if(bindtextdomain(PROGNAME, localepath) == NULL) |
---|
2714 | { |
---|
2715 | err("set bindtextdomain"); |
---|
2716 | return 1; |
---|
2717 | } |
---|
2718 | if(textdomain(PROGNAME) == NULL) |
---|
2719 | { |
---|
2720 | err("set textdomain"); |
---|
2721 | return 1; |
---|
2722 | } |
---|
2723 | debug(1000, "out"); |
---|
2724 | return 0; |
---|
2725 | } |
---|
2726 | |
---|
2727 | //for langage you must |
---|
2728 | //mkdir /usr/lib/locale |
---|
2729 | //ln -s %titanpath%/po /usr/lib/locale/po |
---|
2730 | //copy SYS_LC_MESSAGES from other language into LC_MESSAGE |
---|
2731 | int setlang(char *lang) |
---|
2732 | { |
---|
2733 | debug(1000, "in"); |
---|
2734 | char *ret; |
---|
2735 | |
---|
2736 | setenv("LANG", lang, 1); |
---|
2737 | setenv("LANGUAGE", lang, 1); |
---|
2738 | ret = setlocale(LC_MESSAGES, lang); |
---|
2739 | if(ret == NULL) |
---|
2740 | { |
---|
2741 | err("can't set LC_MESSAGES to %s", lang); |
---|
2742 | return 1; |
---|
2743 | } |
---|
2744 | debug(1000, "out"); |
---|
2745 | return 0; |
---|
2746 | } |
---|
2747 | |
---|
2748 | unsigned long readsysul(const char *filename, int line) |
---|
2749 | { |
---|
2750 | debug(1000, "in"); |
---|
2751 | int i = 0; |
---|
2752 | unsigned long ret = 0; |
---|
2753 | FILE *fd = NULL; |
---|
2754 | char *fileline = NULL; |
---|
2755 | char *buf1 = NULL; |
---|
2756 | |
---|
2757 | fileline = malloc(MINMALLOC); |
---|
2758 | if(fileline == NULL) |
---|
2759 | { |
---|
2760 | err("no memory"); |
---|
2761 | return 0; |
---|
2762 | } |
---|
2763 | |
---|
2764 | fd = fopen(filename, "r"); |
---|
2765 | if(fd == NULL) |
---|
2766 | { |
---|
2767 | perr("can't open %s", filename); |
---|
2768 | free(fileline); |
---|
2769 | return 0; |
---|
2770 | } |
---|
2771 | |
---|
2772 | for(i = 0; i < line; i++) |
---|
2773 | { |
---|
2774 | memset(fileline, 0, MINMALLOC); |
---|
2775 | fgets(fileline, MINMALLOC, fd); |
---|
2776 | } |
---|
2777 | |
---|
2778 | if(fileline[strlen(fileline) - 1] == '\n') |
---|
2779 | fileline[strlen(fileline) - 1] = '\0'; |
---|
2780 | buf1 = ostrcat(fileline, "", 1, 0); |
---|
2781 | |
---|
2782 | fclose(fd); |
---|
2783 | |
---|
2784 | if(buf1 != NULL) |
---|
2785 | { |
---|
2786 | ret = strtoul(buf1, NULL, 10); |
---|
2787 | free(buf1); buf1 = NULL; |
---|
2788 | } |
---|
2789 | |
---|
2790 | debug(1000, "out"); |
---|
2791 | return ret; |
---|
2792 | } |
---|
2793 | |
---|
2794 | |
---|
2795 | char* readsys(const char *filename, int line) |
---|
2796 | { |
---|
2797 | debug(1000, "in"); |
---|
2798 | int i = 0; |
---|
2799 | FILE *fd = NULL; |
---|
2800 | char *fileline = NULL; |
---|
2801 | char *buf1 = NULL; |
---|
2802 | |
---|
2803 | fileline = malloc(MINMALLOC); |
---|
2804 | if(fileline == NULL) |
---|
2805 | { |
---|
2806 | err("no memory"); |
---|
2807 | return NULL; |
---|
2808 | } |
---|
2809 | |
---|
2810 | fd = fopen(filename, "r"); |
---|
2811 | if(fd == NULL) |
---|
2812 | { |
---|
2813 | perr("can't open %s", filename); |
---|
2814 | free(fileline); |
---|
2815 | return NULL; |
---|
2816 | } |
---|
2817 | |
---|
2818 | for(i = 0; i < line; i++) |
---|
2819 | { |
---|
2820 | memset(fileline, 0, MINMALLOC); |
---|
2821 | fgets(fileline, MINMALLOC, fd); |
---|
2822 | } |
---|
2823 | |
---|
2824 | if(fileline[strlen(fileline) - 1] == '\n') |
---|
2825 | fileline[strlen(fileline) - 1] = '\0'; |
---|
2826 | buf1 = ostrcat(fileline, "", 1, 0); |
---|
2827 | |
---|
2828 | fclose(fd); |
---|
2829 | |
---|
2830 | debug(1000, "out"); |
---|
2831 | return buf1; |
---|
2832 | } |
---|
2833 | |
---|
2834 | //flag 0: without \n |
---|
2835 | //flag 1: with \n |
---|
2836 | int writesys(const char *filename, char *value, int flag) |
---|
2837 | { |
---|
2838 | debug(1000, "in"); |
---|
2839 | FILE *fd = NULL; |
---|
2840 | char* tmpstr = NULL; |
---|
2841 | int ret; |
---|
2842 | |
---|
2843 | if(value == NULL) |
---|
2844 | { |
---|
2845 | debug(1000, "out -> NULL detect"); |
---|
2846 | return 1; |
---|
2847 | } |
---|
2848 | |
---|
2849 | fd = fopen(filename, "w"); |
---|
2850 | if(fd == NULL) |
---|
2851 | { |
---|
2852 | perr("can't open %s", filename); |
---|
2853 | return 1; |
---|
2854 | } |
---|
2855 | |
---|
2856 | if(flag == 1) |
---|
2857 | tmpstr = ostrcat(value, "\n", 0, 0); |
---|
2858 | else |
---|
2859 | tmpstr = ostrcat(value, "", 0, 0); |
---|
2860 | |
---|
2861 | ret = fwrite(tmpstr, strlen(tmpstr), 1, fd); |
---|
2862 | if(ret != 1) |
---|
2863 | { |
---|
2864 | perr("writting to %s", filename); |
---|
2865 | free(tmpstr); |
---|
2866 | fclose(fd); |
---|
2867 | return 1; |
---|
2868 | } |
---|
2869 | |
---|
2870 | free(tmpstr); |
---|
2871 | fclose(fd); |
---|
2872 | debug(1000, "out"); |
---|
2873 | return 0; |
---|
2874 | } |
---|
2875 | |
---|
2876 | int writesysint(const char *filename, int value, int flag) |
---|
2877 | { |
---|
2878 | debug(1000, "in"); |
---|
2879 | char* tmpstr = NULL; |
---|
2880 | int ret = 0; |
---|
2881 | |
---|
2882 | tmpstr = oitoa(value); |
---|
2883 | ret = writesys(filename, tmpstr, flag); |
---|
2884 | |
---|
2885 | free(tmpstr); |
---|
2886 | debug(1000, "out"); |
---|
2887 | return ret; |
---|
2888 | } |
---|
2889 | |
---|
2890 | char* convertspacetolf(char* value) |
---|
2891 | { |
---|
2892 | debug(1000, "in"); |
---|
2893 | int i = 0; |
---|
2894 | |
---|
2895 | while(value[i] != '\0') |
---|
2896 | { |
---|
2897 | if(value[i] == ' ') |
---|
2898 | value[i] = '\n'; |
---|
2899 | i++; |
---|
2900 | } |
---|
2901 | |
---|
2902 | debug(1000, "out"); |
---|
2903 | return value; |
---|
2904 | } |
---|
2905 | |
---|
2906 | char* getcolorformatchoices() |
---|
2907 | { |
---|
2908 | debug(1000, "in"); |
---|
2909 | char *colorformatchoicesdev = NULL; |
---|
2910 | char *value = NULL; |
---|
2911 | |
---|
2912 | colorformatchoicesdev = getconfig("colorformatchoicesdev", NULL); |
---|
2913 | |
---|
2914 | if(colorformatchoicesdev == NULL) |
---|
2915 | { |
---|
2916 | debug(1000, "out -> NULL detect"); |
---|
2917 | return NULL; |
---|
2918 | } |
---|
2919 | |
---|
2920 | value = readsys(colorformatchoicesdev, 1); |
---|
2921 | if(value == NULL) |
---|
2922 | { |
---|
2923 | debug(1000, "out -> NULL detect"); |
---|
2924 | return NULL; |
---|
2925 | } |
---|
2926 | |
---|
2927 | value = convertspacetolf(value); |
---|
2928 | |
---|
2929 | debug(1000, "out"); |
---|
2930 | return value; |
---|
2931 | } |
---|
2932 | |
---|
2933 | char* getaudiosourcechoices() |
---|
2934 | { |
---|
2935 | debug(1000, "in"); |
---|
2936 | char *audiosourcechoicesdev = NULL; |
---|
2937 | char *value = NULL; |
---|
2938 | |
---|
2939 | audiosourcechoicesdev = getconfig("audiosourcechoicesdev", NULL); |
---|
2940 | |
---|
2941 | if(audiosourcechoicesdev == NULL) |
---|
2942 | { |
---|
2943 | debug(1000, "out -> NULL detect"); |
---|
2944 | return NULL; |
---|
2945 | } |
---|
2946 | |
---|
2947 | value = readsys(audiosourcechoicesdev, 1); |
---|
2948 | if(value == NULL) |
---|
2949 | { |
---|
2950 | debug(1000, "out -> NULL detect"); |
---|
2951 | return NULL; |
---|
2952 | } |
---|
2953 | |
---|
2954 | value = convertspacetolf(value); |
---|
2955 | |
---|
2956 | debug(1000, "out"); |
---|
2957 | return value; |
---|
2958 | } |
---|
2959 | |
---|
2960 | char* getac3choices() |
---|
2961 | { |
---|
2962 | debug(1000, "in"); |
---|
2963 | char *ac3choicesdev = NULL; |
---|
2964 | char *value = NULL; |
---|
2965 | |
---|
2966 | ac3choicesdev = getconfig("ac3choicesdev", NULL); |
---|
2967 | |
---|
2968 | if(ac3choicesdev == NULL) |
---|
2969 | { |
---|
2970 | debug(1000, "out -> NULL detect"); |
---|
2971 | return NULL; |
---|
2972 | } |
---|
2973 | |
---|
2974 | value = readsys(ac3choicesdev, 1); |
---|
2975 | if(value == NULL) |
---|
2976 | { |
---|
2977 | debug(1000, "out -> NULL detect"); |
---|
2978 | return NULL; |
---|
2979 | } |
---|
2980 | |
---|
2981 | value = convertspacetolf(value); |
---|
2982 | |
---|
2983 | debug(1000, "out"); |
---|
2984 | return value; |
---|
2985 | } |
---|
2986 | |
---|
2987 | int setciclock(int slotnr, char* value) |
---|
2988 | { |
---|
2989 | debug(1000, "in"); |
---|
2990 | char* ciclockdev = NULL, *tmpstr = NULL; |
---|
2991 | int ret = 0; |
---|
2992 | |
---|
2993 | ciclockdev = getconfig("ciclockdev", NULL); |
---|
2994 | |
---|
2995 | if(ciclockdev != NULL && value != NULL) |
---|
2996 | { |
---|
2997 | tmpstr = malloc(MINMALLOC); |
---|
2998 | if(tmpstr == NULL) |
---|
2999 | { |
---|
3000 | err("no mem"); |
---|
3001 | return 1; |
---|
3002 | } |
---|
3003 | |
---|
3004 | snprintf(tmpstr, MINMALLOC, ciclockdev, slotnr); |
---|
3005 | debug(100, "set %s to %s", tmpstr, value); |
---|
3006 | ret = writesys(tmpstr, value, 0); |
---|
3007 | |
---|
3008 | free(tmpstr); tmpstr = NULL; |
---|
3009 | return ret; |
---|
3010 | } |
---|
3011 | |
---|
3012 | debug(1000, "out"); |
---|
3013 | return 0; |
---|
3014 | } |
---|
3015 | |
---|
3016 | int setciinput(int slotnr, char* value) |
---|
3017 | { |
---|
3018 | debug(1000, "in"); |
---|
3019 | char* ciinputdev = NULL, *tmpstr = NULL; |
---|
3020 | int ret = 0; |
---|
3021 | |
---|
3022 | ciinputdev = getconfig("ciinputdev", NULL); |
---|
3023 | |
---|
3024 | if(ciinputdev != 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, ciinputdev, 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 setcisource(int tunernr, char* value) |
---|
3046 | { |
---|
3047 | debug(1000, "in"); |
---|
3048 | char* cisourcedev = NULL, *tmpstr = NULL; |
---|
3049 | int ret = 0; |
---|
3050 | |
---|
3051 | cisourcedev = getconfig("cisourcedev", NULL); |
---|
3052 | |
---|
3053 | if(cisourcedev != 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, cisourcedev, tunernr); |
---|
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 setinput(char* value) |
---|
3075 | { |
---|
3076 | debug(1000, "in"); |
---|
3077 | char* inputdev = NULL; |
---|
3078 | int ret = 0; |
---|
3079 | |
---|
3080 | inputdev = getconfig("inputdev", NULL); |
---|
3081 | |
---|
3082 | if(inputdev != NULL && value != NULL) |
---|
3083 | { |
---|
3084 | debug(100, "set %s to %s", inputdev, value); |
---|
3085 | ret = writesys(inputdev, value, 0); |
---|
3086 | return ret; |
---|
3087 | } |
---|
3088 | |
---|
3089 | debug(1000, "out"); |
---|
3090 | return 0; |
---|
3091 | } |
---|
3092 | |
---|
3093 | char* getinput() |
---|
3094 | { |
---|
3095 | debug(1000, "in"); |
---|
3096 | char *inputdev = NULL; |
---|
3097 | char *value = NULL; |
---|
3098 | |
---|
3099 | inputdev = getconfig("inputdev", NULL); |
---|
3100 | |
---|
3101 | if(inputdev == NULL) |
---|
3102 | { |
---|
3103 | debug(1000, "out -> NULL detect"); |
---|
3104 | return NULL; |
---|
3105 | } |
---|
3106 | |
---|
3107 | value = readsys(inputdev, 1); |
---|
3108 | if(value == NULL) |
---|
3109 | { |
---|
3110 | debug(1000, "out -> NULL detect"); |
---|
3111 | return NULL; |
---|
3112 | } |
---|
3113 | |
---|
3114 | debug(1000, "out"); |
---|
3115 | return value; |
---|
3116 | } |
---|
3117 | |
---|
3118 | int setac3(char* value) |
---|
3119 | { |
---|
3120 | debug(1000, "in"); |
---|
3121 | char* ac3dev = NULL; |
---|
3122 | int ret = 0; |
---|
3123 | |
---|
3124 | ac3dev = getconfig("ac3dev", NULL); |
---|
3125 | |
---|
3126 | if(ac3dev != NULL && value != NULL) |
---|
3127 | { |
---|
3128 | debug(100, "set %s to %s", ac3dev, value); |
---|
3129 | ret = writesys(ac3dev, value, 0); |
---|
3130 | if(ret == 0) addconfig("av_ac3mode", value); |
---|
3131 | return ret; |
---|
3132 | } |
---|
3133 | |
---|
3134 | debug(1000, "out"); |
---|
3135 | return 0; |
---|
3136 | } |
---|
3137 | |
---|
3138 | char* getac3() |
---|
3139 | { |
---|
3140 | debug(1000, "in"); |
---|
3141 | char *ac3dev = NULL; |
---|
3142 | char *value = NULL; |
---|
3143 | |
---|
3144 | ac3dev = getconfig("ac3dev", NULL); |
---|
3145 | |
---|
3146 | if(ac3dev == NULL) |
---|
3147 | { |
---|
3148 | debug(1000, "out -> NULL detect"); |
---|
3149 | return NULL; |
---|
3150 | } |
---|
3151 | |
---|
3152 | value = readsys(ac3dev, 1); |
---|
3153 | if(value == NULL) |
---|
3154 | { |
---|
3155 | debug(1000, "out -> NULL detect"); |
---|
3156 | return NULL; |
---|
3157 | } |
---|
3158 | |
---|
3159 | debug(1000, "out"); |
---|
3160 | return value; |
---|
3161 | } |
---|
3162 | |
---|
3163 | char* getpolicychoices() |
---|
3164 | { |
---|
3165 | debug(1000, "in"); |
---|
3166 | char *policychoicesdev = NULL; |
---|
3167 | char *value = NULL; |
---|
3168 | |
---|
3169 | policychoicesdev = getconfig("policychoicesdev", NULL); |
---|
3170 | |
---|
3171 | if(policychoicesdev == NULL) |
---|
3172 | { |
---|
3173 | debug(1000, "out -> NULL detect"); |
---|
3174 | return NULL; |
---|
3175 | } |
---|
3176 | |
---|
3177 | value = readsys(policychoicesdev, 1); |
---|
3178 | if(value == NULL) |
---|
3179 | { |
---|
3180 | debug(1000, "out -> NULL detect"); |
---|
3181 | return NULL; |
---|
3182 | } |
---|
3183 | |
---|
3184 | value = convertspacetolf(value); |
---|
3185 | |
---|
3186 | debug(1000, "out"); |
---|
3187 | return value; |
---|
3188 | } |
---|
3189 | |
---|
3190 | char* getpolicy() |
---|
3191 | { |
---|
3192 | debug(1000, "in"); |
---|
3193 | char *policydev = NULL; |
---|
3194 | char *value = NULL; |
---|
3195 | |
---|
3196 | policydev = getconfig("policydev", NULL); |
---|
3197 | |
---|
3198 | if(policydev == NULL) |
---|
3199 | { |
---|
3200 | debug(1000, "out -> NULL detect"); |
---|
3201 | return NULL; |
---|
3202 | } |
---|
3203 | |
---|
3204 | value = readsys(policydev, 1); |
---|
3205 | if(value == NULL) |
---|
3206 | { |
---|
3207 | debug(1000, "out -> NULL detect"); |
---|
3208 | return NULL; |
---|
3209 | } |
---|
3210 | |
---|
3211 | debug(1000, "out"); |
---|
3212 | return value; |
---|
3213 | } |
---|
3214 | |
---|
3215 | int setpolicy(char* value) |
---|
3216 | { |
---|
3217 | debug(1000, "in"); |
---|
3218 | char* policydev; |
---|
3219 | int ret = 0; |
---|
3220 | |
---|
3221 | policydev = getconfig("policydev", NULL); |
---|
3222 | |
---|
3223 | if(policydev != NULL && value != NULL) |
---|
3224 | { |
---|
3225 | debug(100, "set %s to %s", policydev, value); |
---|
3226 | ret = writesys(policydev, value, 0); |
---|
3227 | if(ret == 0) addconfig("av_policy", value); |
---|
3228 | return ret; |
---|
3229 | } |
---|
3230 | |
---|
3231 | debug(1000, "out"); |
---|
3232 | return 0; |
---|
3233 | } |
---|
3234 | |
---|
3235 | char* getaspectchoices() |
---|
3236 | { |
---|
3237 | debug(1000, "in"); |
---|
3238 | char *aspectchoicesdev = NULL; |
---|
3239 | char *value = NULL; |
---|
3240 | |
---|
3241 | aspectchoicesdev = getconfig("aspectchoicesdev", NULL); |
---|
3242 | |
---|
3243 | if(aspectchoicesdev == NULL) |
---|
3244 | { |
---|
3245 | debug(1000, "out -> NULL detect"); |
---|
3246 | return NULL; |
---|
3247 | } |
---|
3248 | |
---|
3249 | value = readsys(aspectchoicesdev, 1); |
---|
3250 | if(value == NULL) |
---|
3251 | { |
---|
3252 | debug(1000, "out -> NULL detect"); |
---|
3253 | return NULL; |
---|
3254 | } |
---|
3255 | |
---|
3256 | value = convertspacetolf(value); |
---|
3257 | |
---|
3258 | debug(1000, "out"); |
---|
3259 | return value; |
---|
3260 | } |
---|
3261 | |
---|
3262 | char* getaspect() |
---|
3263 | { |
---|
3264 | debug(1000, "in"); |
---|
3265 | char *aspectdev = NULL; |
---|
3266 | char *value = NULL; |
---|
3267 | |
---|
3268 | aspectdev = getconfig("aspectdev", NULL); |
---|
3269 | |
---|
3270 | if(aspectdev == NULL) |
---|
3271 | { |
---|
3272 | debug(1000, "out -> NULL detect"); |
---|
3273 | return NULL; |
---|
3274 | } |
---|
3275 | |
---|
3276 | value = readsys(aspectdev, 1); |
---|
3277 | if(value == NULL) |
---|
3278 | { |
---|
3279 | debug(1000, "out -> NULL detect"); |
---|
3280 | return NULL; |
---|
3281 | } |
---|
3282 | |
---|
3283 | debug(1000, "out"); |
---|
3284 | return value; |
---|
3285 | } |
---|
3286 | |
---|
3287 | int setaspect(char* value) |
---|
3288 | { |
---|
3289 | debug(1000, "in"); |
---|
3290 | char* aspectdev; |
---|
3291 | int ret = 0; |
---|
3292 | |
---|
3293 | aspectdev = getconfig("aspectdev", NULL); |
---|
3294 | |
---|
3295 | if(aspectdev != NULL && value != NULL) |
---|
3296 | { |
---|
3297 | debug(100, "set %s to %s", aspectdev, value); |
---|
3298 | ret = writesys(aspectdev, value, 0); |
---|
3299 | if(ret == 0) addconfig("av_aspect", value); |
---|
3300 | return ret; |
---|
3301 | } |
---|
3302 | |
---|
3303 | debug(1000, "out"); |
---|
3304 | return 0; |
---|
3305 | } |
---|
3306 | |
---|
3307 | char* getvideomodechoices() |
---|
3308 | { |
---|
3309 | debug(1000, "in"); |
---|
3310 | char *videomodechoicesdev = NULL; |
---|
3311 | char *value = NULL; |
---|
3312 | |
---|
3313 | videomodechoicesdev = getconfig("videomodechoicesdev", NULL); |
---|
3314 | |
---|
3315 | if(videomodechoicesdev == NULL) |
---|
3316 | { |
---|
3317 | debug(1000, "out -> NULL detect"); |
---|
3318 | return NULL; |
---|
3319 | } |
---|
3320 | |
---|
3321 | value = readsys(videomodechoicesdev, 1); |
---|
3322 | if(value == NULL) |
---|
3323 | { |
---|
3324 | debug(1000, "out -> NULL detect"); |
---|
3325 | return NULL; |
---|
3326 | } |
---|
3327 | |
---|
3328 | if(status.expertmodus < 10) |
---|
3329 | { |
---|
3330 | value = string_replace("1080p60", "", value, 1); |
---|
3331 | value = string_replace(" ", " ", value, 1); |
---|
3332 | value = string_replace("1080p59", "", value, 1); |
---|
3333 | value = string_replace(" ", " ", value, 1); |
---|
3334 | value = string_replace("1080p30", "", value, 1); |
---|
3335 | value = string_replace(" ", " ", value, 1); |
---|
3336 | value = string_replace("1080p25", "", value, 1); |
---|
3337 | value = string_replace(" ", " ", value, 1); |
---|
3338 | value = string_replace("1080p24", "", value, 1); |
---|
3339 | value = string_replace(" ", " ", value, 1); |
---|
3340 | value = string_replace("1080i60", "", value, 1); |
---|
3341 | value = string_replace(" ", " ", value, 1); |
---|
3342 | value = string_replace("720p60", "", value, 1); |
---|
3343 | value = string_replace(" ", " ", value, 1); |
---|
3344 | } |
---|
3345 | |
---|
3346 | value = convertspacetolf(value); |
---|
3347 | |
---|
3348 | debug(1000, "out"); |
---|
3349 | return value; |
---|
3350 | } |
---|
3351 | |
---|
3352 | char* getmode3dchoices() |
---|
3353 | { |
---|
3354 | debug(1000, "in"); |
---|
3355 | char *mode3dchoicesdev = NULL; |
---|
3356 | char *value = NULL; |
---|
3357 | |
---|
3358 | mode3dchoicesdev = getconfig("mode3dchoicesdev", NULL); |
---|
3359 | |
---|
3360 | if(mode3dchoicesdev == NULL) |
---|
3361 | { |
---|
3362 | return ostrcat("off\nsbs\ntab", "", 0, 0); |
---|
3363 | } |
---|
3364 | |
---|
3365 | value = readsys(mode3dchoicesdev, 1); |
---|
3366 | if(value == NULL) |
---|
3367 | { |
---|
3368 | debug(1000, "out -> NULL detect"); |
---|
3369 | return NULL; |
---|
3370 | } |
---|
3371 | |
---|
3372 | value = convertspacetolf(value); |
---|
3373 | |
---|
3374 | debug(1000, "out"); |
---|
3375 | return value; |
---|
3376 | } |
---|
3377 | |
---|
3378 | char* getmode3d() |
---|
3379 | { |
---|
3380 | debug(1000, "in"); |
---|
3381 | char *mode3ddev = NULL; |
---|
3382 | char *value = NULL; |
---|
3383 | |
---|
3384 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
3385 | |
---|
3386 | if(mode3ddev == NULL) |
---|
3387 | { |
---|
3388 | debug(1000, "out -> NULL detect"); |
---|
3389 | return NULL; |
---|
3390 | } |
---|
3391 | |
---|
3392 | value = readsys(mode3ddev, 1); |
---|
3393 | if(value == NULL) |
---|
3394 | { |
---|
3395 | debug(1000, "out -> NULL detect"); |
---|
3396 | return NULL; |
---|
3397 | } |
---|
3398 | |
---|
3399 | debug(1000, "out"); |
---|
3400 | return value; |
---|
3401 | } |
---|
3402 | |
---|
3403 | int setmode3d(char* value) |
---|
3404 | { |
---|
3405 | debug(1000, "in"); |
---|
3406 | char* mode3ddev; |
---|
3407 | int ret = 0; |
---|
3408 | |
---|
3409 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
3410 | |
---|
3411 | if(mode3ddev != NULL && value != NULL) |
---|
3412 | { |
---|
3413 | debug(100, "set %s to %s", mode3ddev, value); |
---|
3414 | ret = writesys(mode3ddev, value, 0); |
---|
3415 | if(ret == 0) addconfig("av_mode3d", value); |
---|
3416 | return ret; |
---|
3417 | } |
---|
3418 | |
---|
3419 | debug(1000, "out"); |
---|
3420 | return 0; |
---|
3421 | } |
---|
3422 | |
---|
3423 | char* getvideomode() |
---|
3424 | { |
---|
3425 | debug(1000, "in"); |
---|
3426 | char *videomodedev = NULL; |
---|
3427 | char *value = NULL; |
---|
3428 | |
---|
3429 | videomodedev = getconfig("videomodedev", NULL); |
---|
3430 | |
---|
3431 | if(videomodedev == NULL) |
---|
3432 | { |
---|
3433 | debug(1000, "out -> NULL detect"); |
---|
3434 | return NULL; |
---|
3435 | } |
---|
3436 | |
---|
3437 | value = readsys(videomodedev, 1); |
---|
3438 | if(value == NULL) |
---|
3439 | { |
---|
3440 | debug(1000, "out -> NULL detect"); |
---|
3441 | return NULL; |
---|
3442 | } |
---|
3443 | |
---|
3444 | debug(1000, "out"); |
---|
3445 | return value; |
---|
3446 | } |
---|
3447 | |
---|
3448 | void switchvideomode() |
---|
3449 | { |
---|
3450 | int rcret = 0; |
---|
3451 | char* tmpstr = NULL; |
---|
3452 | tmpstr = getvideomode(); |
---|
3453 | struct skin* playpolicy = getscreen("playpolicy"); |
---|
3454 | |
---|
3455 | if(tmpstr != NULL) |
---|
3456 | { |
---|
3457 | if(ostrcmp("pal", tmpstr) == 0 || ostrncmp("576", tmpstr, 3) == 0) |
---|
3458 | { |
---|
3459 | setvideomode("720p50", 0); |
---|
3460 | changefbresolution("720p50"); |
---|
3461 | changetext(playpolicy, "720p50"); |
---|
3462 | } |
---|
3463 | else if(ostrncmp("720", tmpstr, 3) == 0) |
---|
3464 | { |
---|
3465 | setvideomode("1080i50", 0); |
---|
3466 | changefbresolution("1080i50"); |
---|
3467 | changetext(playpolicy, "1080i50"); |
---|
3468 | } |
---|
3469 | else if(ostrncmp("1080", tmpstr, 4) == 0) |
---|
3470 | { |
---|
3471 | setvideomode("576i50", 0); |
---|
3472 | changefbresolution("576i50"); |
---|
3473 | changetext(playpolicy, "576i50"); |
---|
3474 | } |
---|
3475 | /* |
---|
3476 | int ret = textbox(_("Message"), _("Is this Videomode ok ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
3477 | if(ret == 0 || ret == 2) |
---|
3478 | { |
---|
3479 | setvideomode(tmpstr, 0); |
---|
3480 | changefbresolution(tmpstr); |
---|
3481 | } |
---|
3482 | */ |
---|
3483 | drawscreen(playpolicy, 0); |
---|
3484 | while(1) |
---|
3485 | { |
---|
3486 | rcret = waitrc(playpolicy, 5000, 0); |
---|
3487 | break; |
---|
3488 | } |
---|
3489 | clearscreen(playpolicy); |
---|
3490 | } |
---|
3491 | free(tmpstr); |
---|
3492 | } |
---|
3493 | |
---|
3494 | //flag 0: write videomode to config |
---|
3495 | //flag 1: don't write videomode to config |
---|
3496 | int setvideomode(char* value, int flag) |
---|
3497 | { |
---|
3498 | debug(1000, "in"); |
---|
3499 | char* videomodedev; |
---|
3500 | int ret = 0; |
---|
3501 | |
---|
3502 | videomodedev = getconfig("videomodedev", NULL); |
---|
3503 | |
---|
3504 | if(videomodedev != NULL && value != NULL) |
---|
3505 | { |
---|
3506 | debug(100, "set %s to %s", videomodedev, value); |
---|
3507 | ret = writesys(videomodedev, value, 0); |
---|
3508 | if(ret == 0 && flag == 0) addconfig("av_videomode", value); |
---|
3509 | return ret; |
---|
3510 | } |
---|
3511 | |
---|
3512 | debug(1000, "out"); |
---|
3513 | return 0; |
---|
3514 | } |
---|
3515 | |
---|
3516 | int setcolorformat(char* value) |
---|
3517 | { |
---|
3518 | debug(1000, "in"); |
---|
3519 | char* colorformatdev; |
---|
3520 | int ret = 0; |
---|
3521 | |
---|
3522 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
3523 | |
---|
3524 | if(colorformatdev != NULL && value != NULL) |
---|
3525 | { |
---|
3526 | debug(100, "set %s to %s", colorformatdev, value); |
---|
3527 | ret = writesys(colorformatdev, value, 0); |
---|
3528 | if(ret == 0) addconfig("av_colorformat", value); |
---|
3529 | return ret; |
---|
3530 | } |
---|
3531 | |
---|
3532 | debug(1000, "out"); |
---|
3533 | return 0; |
---|
3534 | } |
---|
3535 | |
---|
3536 | char* getcolorformat(int line) |
---|
3537 | { |
---|
3538 | debug(1000, "in"); |
---|
3539 | char *colorformatdev = NULL; |
---|
3540 | char *value = NULL; |
---|
3541 | |
---|
3542 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
3543 | |
---|
3544 | if(colorformatdev == NULL) |
---|
3545 | { |
---|
3546 | debug(1000, "out -> NULL detect"); |
---|
3547 | return NULL; |
---|
3548 | } |
---|
3549 | |
---|
3550 | value = readsys(colorformatdev, line); |
---|
3551 | if(value == NULL) |
---|
3552 | { |
---|
3553 | debug(1000, "out -> NULL detect"); |
---|
3554 | return NULL; |
---|
3555 | } |
---|
3556 | |
---|
3557 | debug(1000, "out"); |
---|
3558 | return value; |
---|
3559 | } |
---|
3560 | |
---|
3561 | int setaudiosource(char* value) |
---|
3562 | { |
---|
3563 | debug(1000, "in"); |
---|
3564 | char* audiosourcedev; |
---|
3565 | int ret = 1; |
---|
3566 | |
---|
3567 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
3568 | |
---|
3569 | if(audiosourcedev != NULL && value != NULL) |
---|
3570 | { |
---|
3571 | debug(100, "set %s to %s", audiosourcedev, value); |
---|
3572 | ret = writesys(audiosourcedev, value, 0); |
---|
3573 | if(ret == 0) addconfig("av_audiosource", value); |
---|
3574 | return ret; |
---|
3575 | } |
---|
3576 | |
---|
3577 | debug(1000, "out"); |
---|
3578 | return 0; |
---|
3579 | } |
---|
3580 | |
---|
3581 | char* getaudiosource() |
---|
3582 | { |
---|
3583 | debug(1000, "in"); |
---|
3584 | char *audiosourcedev = NULL; |
---|
3585 | char *value = NULL; |
---|
3586 | |
---|
3587 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
3588 | |
---|
3589 | if(audiosourcedev == NULL) |
---|
3590 | { |
---|
3591 | debug(1000, "out -> NULL detect"); |
---|
3592 | return NULL; |
---|
3593 | } |
---|
3594 | |
---|
3595 | value = readsys(audiosourcedev, 1); |
---|
3596 | if(value == NULL) |
---|
3597 | { |
---|
3598 | debug(1000, "out -> NULL detect"); |
---|
3599 | return NULL; |
---|
3600 | } |
---|
3601 | |
---|
3602 | debug(1000, "out"); |
---|
3603 | return value; |
---|
3604 | } |
---|
3605 | |
---|
3606 | int setprogress(value) |
---|
3607 | { |
---|
3608 | debug(1000, "in"); |
---|
3609 | char *progressdev; |
---|
3610 | |
---|
3611 | progressdev = getconfig("progressdev", NULL); |
---|
3612 | |
---|
3613 | if(progressdev != NULL) |
---|
3614 | { |
---|
3615 | debug(100, "set %s to %d",progressdev, value); |
---|
3616 | return writesysint(progressdev, value, 0); |
---|
3617 | } |
---|
3618 | |
---|
3619 | debug(1000, "out"); |
---|
3620 | return 0; |
---|
3621 | } |
---|
3622 | |
---|
3623 | int setmute(int value) |
---|
3624 | { |
---|
3625 | debug(1000, "in"); |
---|
3626 | char* mutedev; |
---|
3627 | int tmpvol; |
---|
3628 | |
---|
3629 | if(value == 2) |
---|
3630 | { |
---|
3631 | tmpvol = getvol(); |
---|
3632 | tmpvol = tmpvol * 50 / 100; |
---|
3633 | setvol(tmpvol); |
---|
3634 | } |
---|
3635 | else |
---|
3636 | { |
---|
3637 | mutedev = getconfig("mutedev", NULL); |
---|
3638 | |
---|
3639 | if(mutedev != NULL) |
---|
3640 | { |
---|
3641 | debug(100, "set %s to %d", mutedev, value); |
---|
3642 | return writesysint(mutedev, value, 0); |
---|
3643 | } |
---|
3644 | } |
---|
3645 | debug(1000, "out"); |
---|
3646 | return 0; |
---|
3647 | } |
---|
3648 | |
---|
3649 | int setvol(int value) |
---|
3650 | { |
---|
3651 | debug(1000, "in"); |
---|
3652 | char* voldev; |
---|
3653 | int ret = 0, tmpvol = value; |
---|
3654 | |
---|
3655 | voldev = getconfig("voldev", NULL); |
---|
3656 | |
---|
3657 | if(voldev != NULL) |
---|
3658 | { |
---|
3659 | if(value > 100) value = 100; |
---|
3660 | if(value < 0) value = 0; |
---|
3661 | value = 63 - value * 63 / 100; |
---|
3662 | debug(100, "set %s to %d", voldev, value); |
---|
3663 | ret = writesysint(voldev, value, 0); |
---|
3664 | if(ret == 0 && status.mute != 2) addconfigint("vol", tmpvol); |
---|
3665 | return ret; |
---|
3666 | } |
---|
3667 | |
---|
3668 | debug(1000, "out"); |
---|
3669 | return 0; |
---|
3670 | } |
---|
3671 | |
---|
3672 | int getvol() |
---|
3673 | { |
---|
3674 | debug(1000, "in"); |
---|
3675 | char *voldev = NULL; |
---|
3676 | char *value = NULL; |
---|
3677 | int tmpvol = 0; |
---|
3678 | |
---|
3679 | voldev = getconfig("voldev", NULL); |
---|
3680 | |
---|
3681 | if(voldev == NULL) |
---|
3682 | { |
---|
3683 | debug(1000, "out -> NULL detect"); |
---|
3684 | return 0; |
---|
3685 | } |
---|
3686 | |
---|
3687 | value = readsys(voldev, 1); |
---|
3688 | if(value == NULL) |
---|
3689 | { |
---|
3690 | debug(1000, "out -> NULL detect"); |
---|
3691 | return 0; |
---|
3692 | } |
---|
3693 | |
---|
3694 | tmpvol = atoi(value); |
---|
3695 | free(value); |
---|
3696 | tmpvol = 100 - tmpvol * 100 / 63; |
---|
3697 | |
---|
3698 | debug(1000, "out"); |
---|
3699 | return tmpvol; |
---|
3700 | } |
---|
3701 | |
---|
3702 | void setdebuglevel() |
---|
3703 | { |
---|
3704 | debug(1000, "in"); |
---|
3705 | |
---|
3706 | debug_level = getconfigint("debuglevel", NULL); |
---|
3707 | debug(0, "set debug level to %d", debug_level); |
---|
3708 | |
---|
3709 | debug(1000, "out"); |
---|
3710 | } |
---|
3711 | |
---|
3712 | char* getxmlentry(char *line, char *searchstr) |
---|
3713 | { |
---|
3714 | //debug(1000, "in"); |
---|
3715 | char *buf = NULL, *buf1 = NULL, *buf2 = NULL; |
---|
3716 | |
---|
3717 | buf = strstr(line, searchstr); |
---|
3718 | if(buf == NULL) |
---|
3719 | { |
---|
3720 | //debug(1000, "out -> searchstr=\"%s\" not found in line=\"%s\"", searchstr, line); |
---|
3721 | return NULL; |
---|
3722 | } |
---|
3723 | buf = buf + strlen(searchstr); |
---|
3724 | if(buf[0] == '"') |
---|
3725 | { |
---|
3726 | buf = buf + 1; |
---|
3727 | buf1 = ostrcat(buf, "", 0, 0); |
---|
3728 | if(buf1 == NULL) |
---|
3729 | { |
---|
3730 | err("ostrcat failed"); |
---|
3731 | return NULL; |
---|
3732 | } |
---|
3733 | buf2 = strchr(buf1, '"'); |
---|
3734 | if(buf2 == NULL) |
---|
3735 | { |
---|
3736 | err("strchr returns NULL"); |
---|
3737 | free(buf1); |
---|
3738 | return NULL; |
---|
3739 | } |
---|
3740 | buf2[0] = '\0'; |
---|
3741 | } |
---|
3742 | else |
---|
3743 | { |
---|
3744 | buf1 = ostrcat(buf, "", 0, 0); |
---|
3745 | if(buf1 == NULL) |
---|
3746 | { |
---|
3747 | err("ostrcat failed"); |
---|
3748 | return NULL; |
---|
3749 | } |
---|
3750 | buf2 = strchr(buf1, ' '); |
---|
3751 | if(buf2 == NULL) |
---|
3752 | { |
---|
3753 | buf2 = strstr(buf1, "/>"); |
---|
3754 | if(buf2 == NULL) |
---|
3755 | { |
---|
3756 | buf2 = strchr(buf1, '>'); |
---|
3757 | if(buf2 == NULL) |
---|
3758 | { |
---|
3759 | err("strchr returns NULL"); |
---|
3760 | free(buf1); |
---|
3761 | return NULL; |
---|
3762 | } |
---|
3763 | } |
---|
3764 | } |
---|
3765 | buf2[0] = '\0'; |
---|
3766 | } |
---|
3767 | //debug(1000, "out"); |
---|
3768 | return buf1; |
---|
3769 | } |
---|
3770 | |
---|
3771 | char* readfiletomem(const char* filename, int flag) |
---|
3772 | { |
---|
3773 | debug(1000, "in"); |
---|
3774 | FILE *fd = NULL; |
---|
3775 | char *fileline = NULL, *buf = NULL, *buf1 = NULL; |
---|
3776 | int buf1size = 0, buf1oldsize = 0; |
---|
3777 | |
---|
3778 | fileline = malloc(MINMALLOC); |
---|
3779 | if(fileline == NULL) |
---|
3780 | { |
---|
3781 | err("no memory"); |
---|
3782 | return NULL; |
---|
3783 | } |
---|
3784 | |
---|
3785 | fd = fopen(filename, "r"); |
---|
3786 | if(fd == NULL) |
---|
3787 | { |
---|
3788 | perr("can't open %s", filename); |
---|
3789 | free(fileline); |
---|
3790 | return NULL; |
---|
3791 | } |
---|
3792 | |
---|
3793 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
3794 | { |
---|
3795 | buf = fileline; |
---|
3796 | |
---|
3797 | if(flag == 1) |
---|
3798 | if(buf[0] == '#' || buf[0] == '\n') |
---|
3799 | continue; |
---|
3800 | |
---|
3801 | buf1oldsize = buf1size; |
---|
3802 | buf1size += strlen(buf); |
---|
3803 | buf1 = realloc(buf1, buf1size + 1); |
---|
3804 | if(buf1 == NULL) |
---|
3805 | { |
---|
3806 | err("no memory"); |
---|
3807 | free(fileline); |
---|
3808 | fclose(fd); |
---|
3809 | return NULL; |
---|
3810 | } |
---|
3811 | |
---|
3812 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
3813 | } |
---|
3814 | |
---|
3815 | free(fileline); |
---|
3816 | fclose(fd); |
---|
3817 | debug(1000, "out"); |
---|
3818 | return buf1; |
---|
3819 | } |
---|
3820 | |
---|
3821 | char* readeittomem(const char* filename) |
---|
3822 | { |
---|
3823 | unsigned char byte; |
---|
3824 | FILE *fil = NULL; |
---|
3825 | char *zeichen = NULL, *buf = NULL, *buf1 = NULL; |
---|
3826 | int buf1size = 0, buf1oldsize = 0; |
---|
3827 | int Beschreibung; |
---|
3828 | int len; |
---|
3829 | |
---|
3830 | zeichen = malloc(255); |
---|
3831 | if(zeichen == NULL) |
---|
3832 | { |
---|
3833 | err("no memory"); |
---|
3834 | return NULL; |
---|
3835 | } |
---|
3836 | buf = malloc(255); |
---|
3837 | if(buf == NULL) |
---|
3838 | { |
---|
3839 | free(zeichen); |
---|
3840 | err("no memory"); |
---|
3841 | return NULL; |
---|
3842 | } |
---|
3843 | |
---|
3844 | fil = fopen(filename, "r"); |
---|
3845 | if(fil == NULL) |
---|
3846 | { |
---|
3847 | err("can't open %s", filename); |
---|
3848 | free(zeichen); |
---|
3849 | free(buf); |
---|
3850 | return NULL; |
---|
3851 | } |
---|
3852 | Beschreibung = 0; |
---|
3853 | fseek(fil, 12, SEEK_SET); //ersten 12 Byte nicht relevant |
---|
3854 | while(!feof(fil)) { |
---|
3855 | byte=fgetc(fil); |
---|
3856 | |
---|
3857 | if (byte == 0x4D) { |
---|
3858 | fseek(fil, 4,SEEK_CUR); |
---|
3859 | byte=fgetc(fil); |
---|
3860 | len = byte + 0; |
---|
3861 | byte=fgetc(fil); |
---|
3862 | fgets(zeichen,len,fil); |
---|
3863 | if (byte != 0x05) |
---|
3864 | sprintf(buf,"%c%s\n", byte,zeichen); |
---|
3865 | else |
---|
3866 | sprintf(buf,"%s\n", zeichen); |
---|
3867 | |
---|
3868 | buf1oldsize = buf1size; |
---|
3869 | buf1size += strlen(buf); |
---|
3870 | buf1 = realloc(buf1, buf1size + 1); |
---|
3871 | if(buf1 == NULL) |
---|
3872 | { |
---|
3873 | err("no memory"); |
---|
3874 | free(zeichen); |
---|
3875 | free(buf); |
---|
3876 | fclose(fil); |
---|
3877 | return NULL; |
---|
3878 | } |
---|
3879 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
3880 | |
---|
3881 | //printf("T %s\n", zeichen); |
---|
3882 | byte=fgetc(fil); |
---|
3883 | len = byte + 0; |
---|
3884 | byte=fgetc(fil); |
---|
3885 | fgets(zeichen,len,fil); |
---|
3886 | if (byte != 0x05) |
---|
3887 | sprintf(buf,"%c%s\n\n", byte,zeichen); |
---|
3888 | else |
---|
3889 | sprintf(buf,"%s\n\n", zeichen); |
---|
3890 | |
---|
3891 | buf1oldsize = buf1size; |
---|
3892 | buf1size += strlen(buf); |
---|
3893 | buf1 = realloc(buf1, buf1size + 1); |
---|
3894 | if(buf1 == NULL) |
---|
3895 | { |
---|
3896 | err("no memory"); |
---|
3897 | free(zeichen); |
---|
3898 | free(buf); |
---|
3899 | fclose(fil); |
---|
3900 | return NULL; |
---|
3901 | } |
---|
3902 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
3903 | |
---|
3904 | } |
---|
3905 | else if (byte == 0x4E) { |
---|
3906 | fseek(fil, 6,SEEK_CUR); |
---|
3907 | byte=fgetc(fil); |
---|
3908 | len = byte; |
---|
3909 | byte=fgetc(fil); |
---|
3910 | fgets(zeichen,len,fil); |
---|
3911 | if (Beschreibung == 0) { |
---|
3912 | if (byte != 0x05) |
---|
3913 | sprintf(buf,"%c%s", byte,zeichen); |
---|
3914 | else |
---|
3915 | sprintf(buf,"%s", zeichen); |
---|
3916 | Beschreibung = 1; |
---|
3917 | } |
---|
3918 | else { |
---|
3919 | if (byte != 0x05) |
---|
3920 | sprintf(buf,"%c%s", byte,zeichen); |
---|
3921 | else |
---|
3922 | sprintf(buf,"%s", zeichen); |
---|
3923 | } |
---|
3924 | |
---|
3925 | buf1oldsize = buf1size; |
---|
3926 | buf1size += strlen(buf); |
---|
3927 | buf1 = realloc(buf1, buf1size + 1); |
---|
3928 | if(buf1 == NULL) |
---|
3929 | { |
---|
3930 | err("no memory"); |
---|
3931 | free(zeichen); |
---|
3932 | free(buf); |
---|
3933 | fclose(fil); |
---|
3934 | return NULL; |
---|
3935 | } |
---|
3936 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
3937 | |
---|
3938 | } |
---|
3939 | else { |
---|
3940 | byte=fgetc(fil); |
---|
3941 | len= byte; |
---|
3942 | fgets(zeichen,len+1,fil); |
---|
3943 | } |
---|
3944 | } |
---|
3945 | free(zeichen); |
---|
3946 | free(buf); |
---|
3947 | fclose(fil); |
---|
3948 | return buf1; |
---|
3949 | } |
---|
3950 | |
---|
3951 | char* command(char* input) |
---|
3952 | { |
---|
3953 | debug(1000, "in"); |
---|
3954 | char* tmpstr = NULL, *fileline = NULL; |
---|
3955 | FILE *iopipe = NULL; |
---|
3956 | |
---|
3957 | if(input == NULL) return NULL; |
---|
3958 | |
---|
3959 | fileline = malloc(MINMALLOC); |
---|
3960 | if(fileline == NULL) |
---|
3961 | { |
---|
3962 | err("no memory"); |
---|
3963 | return NULL; |
---|
3964 | } |
---|
3965 | |
---|
3966 | if((iopipe = popen(input, "r")) == NULL) |
---|
3967 | { |
---|
3968 | free(fileline); |
---|
3969 | return NULL; |
---|
3970 | } |
---|
3971 | |
---|
3972 | while(!feof(iopipe)) |
---|
3973 | { |
---|
3974 | if(fgets(fileline, MINMALLOC, iopipe) != NULL) |
---|
3975 | tmpstr = ostrcat(tmpstr, fileline, 1, 0); |
---|
3976 | } |
---|
3977 | |
---|
3978 | free(fileline); |
---|
3979 | pclose(iopipe); |
---|
3980 | debug(1000, "out"); |
---|
3981 | return tmpstr; |
---|
3982 | } |
---|
3983 | |
---|
3984 | char* string_tolower(char *str) |
---|
3985 | { |
---|
3986 | debug(1000, "in"); |
---|
3987 | int i; |
---|
3988 | |
---|
3989 | if(str == NULL) return NULL; |
---|
3990 | |
---|
3991 | for( i = 0; i < strlen(str); i++) |
---|
3992 | str[i] = tolower(str[i]); |
---|
3993 | |
---|
3994 | debug(1000, "out"); |
---|
3995 | return str; |
---|
3996 | } |
---|
3997 | |
---|
3998 | char* string_toupper(char *str) |
---|
3999 | { |
---|
4000 | debug(1000, "in"); |
---|
4001 | int i; |
---|
4002 | |
---|
4003 | if(str == NULL) return NULL; |
---|
4004 | |
---|
4005 | for( i = 0; i < strlen(str); i++) |
---|
4006 | str[i] = toupper(str[i]); |
---|
4007 | |
---|
4008 | debug(1000, "out"); |
---|
4009 | return str; |
---|
4010 | } |
---|
4011 | |
---|
4012 | char* stringreplacecharonce(char *str, char c1, char c2) |
---|
4013 | { |
---|
4014 | debug(1000, "in"); |
---|
4015 | int i; |
---|
4016 | |
---|
4017 | if(str == NULL) return NULL; |
---|
4018 | |
---|
4019 | for( i = 0; i < strlen(str); i++) |
---|
4020 | { |
---|
4021 | if(str[i] == c1) |
---|
4022 | { |
---|
4023 | str[i] = c2; |
---|
4024 | break; |
---|
4025 | } |
---|
4026 | } |
---|
4027 | |
---|
4028 | debug(1000, "out"); |
---|
4029 | return str; |
---|
4030 | } |
---|
4031 | |
---|
4032 | char* stringreplacechar(char *str, char c1, char c2) |
---|
4033 | { |
---|
4034 | debug(1000, "in"); |
---|
4035 | int i; |
---|
4036 | |
---|
4037 | if(str == NULL) return NULL; |
---|
4038 | |
---|
4039 | for( i = 0; i < strlen(str); i++) |
---|
4040 | if(str[i] == c1) str[i] = c2; |
---|
4041 | |
---|
4042 | debug(1000, "out"); |
---|
4043 | return str; |
---|
4044 | } |
---|
4045 | |
---|
4046 | char* string_removechar(char *str) |
---|
4047 | { |
---|
4048 | debug(1000, "in"); |
---|
4049 | int i; |
---|
4050 | |
---|
4051 | if(str == NULL) return NULL; |
---|
4052 | |
---|
4053 | for( i = 0; i < strlen(str); i++) |
---|
4054 | { |
---|
4055 | if(str[i] == '.') str[i] = ' '; |
---|
4056 | if(str[i] == '-') str[i] = ' '; |
---|
4057 | if(str[i] == '_') str[i] = ' '; |
---|
4058 | if(str[i] == '/') str[i] = ' '; |
---|
4059 | } |
---|
4060 | debug(1000, "out"); |
---|
4061 | return str; |
---|
4062 | } |
---|
4063 | |
---|
4064 | char* string_withchars2return(char *str) |
---|
4065 | { |
---|
4066 | debug(1000, "in"); |
---|
4067 | int i; |
---|
4068 | |
---|
4069 | for( i = 0; i < strlen(str); i++) |
---|
4070 | { |
---|
4071 | if(str[i] == ' ') str[i] = '\n'; |
---|
4072 | } |
---|
4073 | |
---|
4074 | debug(1000, "out"); |
---|
4075 | return str; |
---|
4076 | } |
---|
4077 | |
---|
4078 | char* string_remove_whitechars(char *text) |
---|
4079 | { |
---|
4080 | debug(1000, "in"); |
---|
4081 | char *p1 = text, *p2 = text; |
---|
4082 | |
---|
4083 | while(*p1 != '\0') |
---|
4084 | { |
---|
4085 | if(*p1 == ' ') |
---|
4086 | ++p1; |
---|
4087 | else |
---|
4088 | *p2++ = *p1++; |
---|
4089 | } |
---|
4090 | *p2 = '\0'; |
---|
4091 | |
---|
4092 | debug(1000, "out"); |
---|
4093 | return text; |
---|
4094 | } |
---|
4095 | |
---|
4096 | char* strstrip(char *text) |
---|
4097 | { |
---|
4098 | debug(1000, "in"); |
---|
4099 | char* tmpstr = text; |
---|
4100 | |
---|
4101 | if(text == NULL) return NULL; |
---|
4102 | int len = strlen(text); |
---|
4103 | |
---|
4104 | while(isspace(tmpstr[len - 1])) tmpstr[--len] = '\0'; |
---|
4105 | while(*tmpstr && isspace(*tmpstr)) ++tmpstr, --len; |
---|
4106 | |
---|
4107 | memmove(text, tmpstr, len + 1); |
---|
4108 | |
---|
4109 | debug(1000, "out"); |
---|
4110 | return text; |
---|
4111 | } |
---|
4112 | |
---|
4113 | char* string_strip_whitechars(char *text) |
---|
4114 | { |
---|
4115 | debug(1000, "in"); |
---|
4116 | int i; |
---|
4117 | |
---|
4118 | if(text == NULL) |
---|
4119 | { |
---|
4120 | debug(1000, "out -> NULL detect"); |
---|
4121 | return NULL; |
---|
4122 | } |
---|
4123 | |
---|
4124 | // text = string_removechar(text); |
---|
4125 | |
---|
4126 | for(i = 0; text[i] != '\0'; i++) |
---|
4127 | { |
---|
4128 | if(text[i] == ' ' && text[i + 1] == ' ') |
---|
4129 | { |
---|
4130 | int i2 = i + 1; |
---|
4131 | for(; text[i2] != '\0'; i2++) |
---|
4132 | { |
---|
4133 | text[i] = text[i2]; |
---|
4134 | i++; |
---|
4135 | } |
---|
4136 | text[i2 - 1] = '\0'; |
---|
4137 | i = -1; |
---|
4138 | } |
---|
4139 | } |
---|
4140 | |
---|
4141 | debug(1000, "out"); |
---|
4142 | return text; |
---|
4143 | } |
---|
4144 | |
---|
4145 | char* string_replace_remove_last_chars(char *search, char *replace, char *string, int free1) |
---|
4146 | { |
---|
4147 | debug(1000, "in"); |
---|
4148 | char* searchpos = NULL; |
---|
4149 | char* tmpstr = NULL; |
---|
4150 | |
---|
4151 | if(string == NULL || search == NULL) |
---|
4152 | { |
---|
4153 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
4154 | if(free1 == 1) free(string); |
---|
4155 | return tmpstr; |
---|
4156 | } |
---|
4157 | |
---|
4158 | searchpos = strstr(string, search); |
---|
4159 | |
---|
4160 | if(searchpos == NULL) |
---|
4161 | { |
---|
4162 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
4163 | if(free1 == 1) free(string); |
---|
4164 | return tmpstr; |
---|
4165 | } |
---|
4166 | |
---|
4167 | tmpstr = strndup(string, searchpos - string); |
---|
4168 | if(replace != NULL) |
---|
4169 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
4170 | |
---|
4171 | if(free1 == 1) free(string); |
---|
4172 | |
---|
4173 | debug(1000, "out"); |
---|
4174 | return tmpstr; |
---|
4175 | } |
---|
4176 | |
---|
4177 | char* string_replace(char *search, char *replace, char *string, int free1) |
---|
4178 | { |
---|
4179 | debug(1000, "in"); |
---|
4180 | char* searchpos = NULL; |
---|
4181 | char* tmpstr = NULL; |
---|
4182 | |
---|
4183 | if(string == NULL || search == NULL) |
---|
4184 | { |
---|
4185 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
4186 | if(free1 == 1) free(string); |
---|
4187 | return tmpstr; |
---|
4188 | } |
---|
4189 | |
---|
4190 | searchpos = strstr(string, search); |
---|
4191 | |
---|
4192 | if(searchpos == NULL) |
---|
4193 | { |
---|
4194 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
4195 | if(free1 == 1) free(string); |
---|
4196 | return tmpstr; |
---|
4197 | } |
---|
4198 | |
---|
4199 | tmpstr = strndup(string, searchpos - string); |
---|
4200 | if(replace == NULL) |
---|
4201 | tmpstr = ostrcat(tmpstr, "", 1, 0); |
---|
4202 | else |
---|
4203 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
4204 | tmpstr = ostrcat(tmpstr, string + (searchpos - string) + strlen(search), 1, 0); |
---|
4205 | |
---|
4206 | if(free1 == 1) free(string); |
---|
4207 | |
---|
4208 | debug(1000, "out"); |
---|
4209 | return tmpstr; |
---|
4210 | } |
---|
4211 | |
---|
4212 | int string_find(char* str, char* filename) |
---|
4213 | { |
---|
4214 | debug(1000, "in"); |
---|
4215 | int i, len_str, len_filename; |
---|
4216 | |
---|
4217 | if(str == NULL || filename == NULL) return 0; |
---|
4218 | |
---|
4219 | len_str = strlen(str); |
---|
4220 | len_filename = strlen(filename); |
---|
4221 | |
---|
4222 | for(i = 0; (i + len_str) < len_filename; i++) |
---|
4223 | if(strncmp(filename + i, str, len_str) == 0) |
---|
4224 | return 1; |
---|
4225 | |
---|
4226 | debug(1000, "out"); |
---|
4227 | return 0; |
---|
4228 | } |
---|
4229 | |
---|
4230 | int file_exist(char* filename) |
---|
4231 | { |
---|
4232 | debug(1000, "in"); |
---|
4233 | if (access(filename, F_OK) == 0) |
---|
4234 | return 1; |
---|
4235 | else |
---|
4236 | return 0; |
---|
4237 | } |
---|
4238 | |
---|
4239 | char* string_newline(char* str) |
---|
4240 | { |
---|
4241 | debug(1000, "in"); |
---|
4242 | if(str == NULL) return NULL; |
---|
4243 | |
---|
4244 | int size = strlen(str); |
---|
4245 | |
---|
4246 | if(str[size - 1] == '\n') |
---|
4247 | str[size - 1] = '\0'; |
---|
4248 | debug(1000, "out"); |
---|
4249 | return str; |
---|
4250 | } |
---|
4251 | |
---|
4252 | char* string_quote(char* str) |
---|
4253 | { |
---|
4254 | debug(1000, "in"); |
---|
4255 | char* tmpstr = NULL; |
---|
4256 | |
---|
4257 | tmpstr = ostrcat("\"", str, 0, 0); |
---|
4258 | tmpstr = ostrcat(tmpstr, "\"", 1, 0); |
---|
4259 | debug(1000, "out"); |
---|
4260 | return tmpstr; |
---|
4261 | } |
---|
4262 | |
---|
4263 | struct splitstr* strsplit(char *str, char *tok, int* count) |
---|
4264 | { |
---|
4265 | debug(1000, "in"); |
---|
4266 | char *tmpstr = NULL; |
---|
4267 | struct splitstr *tmparray = NULL; |
---|
4268 | *count = 0; |
---|
4269 | |
---|
4270 | if(tok == NULL) |
---|
4271 | return NULL; |
---|
4272 | |
---|
4273 | tmpstr = strtok(str, tok); |
---|
4274 | while(tmpstr != NULL) |
---|
4275 | { |
---|
4276 | *count = *count + 1; |
---|
4277 | tmparray = (struct splitstr*)realloc(tmparray, sizeof(struct splitstr*) * (*count)); |
---|
4278 | if(tmparray == NULL) |
---|
4279 | return NULL; |
---|
4280 | (&tmparray[(*count) - 1])->part = tmpstr; |
---|
4281 | tmpstr = strtok(NULL, tok); |
---|
4282 | } |
---|
4283 | debug(1000, "out"); |
---|
4284 | return tmparray; |
---|
4285 | } |
---|
4286 | |
---|
4287 | char* string_shortname(char *tmpfilename, int mode) |
---|
4288 | { |
---|
4289 | debug(50, "in %s",tmpfilename); |
---|
4290 | |
---|
4291 | // 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"; |
---|
4292 | char* str = NULL; |
---|
4293 | |
---|
4294 | if (mode==1){ |
---|
4295 | 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 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"; |
---|
4296 | str = ostrcat(str, replacelist, 0, 0); |
---|
4297 | } else { |
---|
4298 | 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"; |
---|
4299 | str = ostrcat(str, replacelist, 0, 0); |
---|
4300 | } |
---|
4301 | |
---|
4302 | char* replace = NULL; |
---|
4303 | struct splitstr* ret1 = NULL; |
---|
4304 | int count = 0; |
---|
4305 | int i = 0; |
---|
4306 | ret1 = strsplit(str, " ", &count); |
---|
4307 | int max = count - 1; |
---|
4308 | |
---|
4309 | for( i = 0; i < max; i++){ |
---|
4310 | struct splitstr* ret2 = NULL; |
---|
4311 | int count2 = 0; |
---|
4312 | int j = 0; |
---|
4313 | char *tmpstr = NULL; |
---|
4314 | tmpstr = ostrcat(tmpstr, tmpfilename, 1, 0); |
---|
4315 | ret2 = strsplit(tmpstr, " ,.-_", &count2); |
---|
4316 | |
---|
4317 | for( j = 0; j < count2; j++){ |
---|
4318 | if(j > 0){ |
---|
4319 | if(ostrcmp((&ret1[i])->part, (&ret2[j])->part) == 0){ |
---|
4320 | if (mode==1){ |
---|
4321 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
4322 | continue; |
---|
4323 | } else { |
---|
4324 | // tmpfilename = string_replace_remove_last_chars((&ret2[j])->part, replace, tmpfilename, 1); |
---|
4325 | // break; |
---|
4326 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
4327 | continue; |
---|
4328 | } |
---|
4329 | } |
---|
4330 | } |
---|
4331 | } |
---|
4332 | free(ret2); ret2 = NULL; |
---|
4333 | } |
---|
4334 | |
---|
4335 | free(ret1); ret1 = NULL; |
---|
4336 | free(replace); replace = NULL; |
---|
4337 | free(str); str = NULL; |
---|
4338 | |
---|
4339 | debug(50, "out %s", tmpfilename); |
---|
4340 | return tmpfilename; |
---|
4341 | } |
---|
4342 | |
---|
4343 | char* get_uuid(char* device) |
---|
4344 | { |
---|
4345 | debug(60, "in %s", device); |
---|
4346 | char* cmd = NULL, *tmpstr = NULL; |
---|
4347 | |
---|
4348 | if(device == NULL) return NULL; |
---|
4349 | |
---|
4350 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s UUID /dev/", 1, 0); |
---|
4351 | cmd = ostrcat(cmd, device, 1, 0); |
---|
4352 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
4353 | |
---|
4354 | tmpstr = string_newline(command(cmd)); |
---|
4355 | |
---|
4356 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
4357 | { |
---|
4358 | free(tmpstr); tmpstr = NULL; |
---|
4359 | } |
---|
4360 | |
---|
4361 | debug(60, "out %s", cmd); |
---|
4362 | free(cmd); cmd = NULL; |
---|
4363 | return tmpstr; |
---|
4364 | } |
---|
4365 | |
---|
4366 | char* get_label(char* device) |
---|
4367 | { |
---|
4368 | debug(60, "in %s", device); |
---|
4369 | char* cmd = NULL, *tmpstr = NULL; |
---|
4370 | |
---|
4371 | if(device == NULL) return NULL; |
---|
4372 | |
---|
4373 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s LABEL /dev/", 1, 0); |
---|
4374 | cmd = ostrcat(cmd, device, 1, 0); |
---|
4375 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
4376 | |
---|
4377 | tmpstr = string_newline(command(cmd)); |
---|
4378 | |
---|
4379 | if(tmpstr == NULL) |
---|
4380 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
4381 | |
---|
4382 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
4383 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
4384 | |
---|
4385 | debug(60, "out %s", cmd); |
---|
4386 | free(cmd); cmd = NULL; |
---|
4387 | return tmpstr; |
---|
4388 | } |
---|
4389 | |
---|
4390 | char* get_filesystem(char* device) |
---|
4391 | { |
---|
4392 | debug(60, "in %s", device); |
---|
4393 | char* cmd = NULL, *tmpstr = NULL; |
---|
4394 | |
---|
4395 | if(device == NULL) return NULL; |
---|
4396 | |
---|
4397 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s TYPE /dev/", 1, 0); |
---|
4398 | cmd = ostrcat(cmd, device, 1, 0); |
---|
4399 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
4400 | |
---|
4401 | tmpstr = string_newline(command(cmd)); |
---|
4402 | |
---|
4403 | if(tmpstr == NULL) |
---|
4404 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
4405 | |
---|
4406 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
4407 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
4408 | |
---|
4409 | debug(60, "out %s", cmd); |
---|
4410 | free(cmd); cmd = NULL; |
---|
4411 | return tmpstr; |
---|
4412 | } |
---|
4413 | |
---|
4414 | char* fixip(char* ipinput, int flag) |
---|
4415 | { |
---|
4416 | debug(60, "in %s", ipinput); |
---|
4417 | int ret = 0; |
---|
4418 | char* ipout = NULL; |
---|
4419 | unsigned char ip[4]; |
---|
4420 | |
---|
4421 | ip[0] = 0; |
---|
4422 | ip[1] = 0; |
---|
4423 | ip[2] = 0; |
---|
4424 | ip[3] = 0; |
---|
4425 | |
---|
4426 | if(ipinput == NULL) return NULL; |
---|
4427 | ret = sscanf(ipinput, "%hhu.%hhu.%hhu.%hhu", &ip[0], &ip[1], &ip[2], &ip[3]); |
---|
4428 | if(ret != 4) return NULL; |
---|
4429 | |
---|
4430 | ipout = malloc(16); |
---|
4431 | if(ipout == NULL) |
---|
4432 | { |
---|
4433 | err("no mem"); |
---|
4434 | return NULL; |
---|
4435 | } |
---|
4436 | |
---|
4437 | if(flag == 1) |
---|
4438 | snprintf(ipout, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
---|
4439 | else |
---|
4440 | snprintf(ipout, 16, "%03d.%03d.%03d.%03d", ip[0], ip[1], ip[2], ip[3]); |
---|
4441 | |
---|
4442 | return ipout; |
---|
4443 | } |
---|
4444 | |
---|
4445 | void setfanspeed(int speed, int aktion) |
---|
4446 | { |
---|
4447 | char* speedWert = NULL; |
---|
4448 | char* speedSet = NULL; |
---|
4449 | |
---|
4450 | if(speed < 0) |
---|
4451 | { |
---|
4452 | speedWert = getconfig("fanspeed", NULL); |
---|
4453 | if(speedWert == NULL) |
---|
4454 | speedSet = ostrcat(speedSet, "170", 1, 0); |
---|
4455 | else |
---|
4456 | speedSet = ostrcat(speedSet, speedWert, 1, 0); |
---|
4457 | } |
---|
4458 | else |
---|
4459 | { |
---|
4460 | if(speed == 0) |
---|
4461 | speedSet = ostrcat(speedSet, "115", 1, 0); |
---|
4462 | else if(speed == 25) |
---|
4463 | speedSet = ostrcat(speedSet, "130", 1, 0); |
---|
4464 | else if(speed == 50) |
---|
4465 | speedSet = ostrcat(speedSet, "145", 1, 0); |
---|
4466 | else if(speed == 75) |
---|
4467 | speedSet = ostrcat(speedSet, "155", 1, 0); |
---|
4468 | else |
---|
4469 | speedSet = ostrcat(speedSet, "170", 1, 0); |
---|
4470 | } |
---|
4471 | |
---|
4472 | writesys("/proc/stb/fan/fan_ctrl", speedSet, 1); |
---|
4473 | |
---|
4474 | if(aktion == 1) |
---|
4475 | addconfig("fanspeed", speedSet); |
---|
4476 | |
---|
4477 | free(speedSet); speedSet=NULL; |
---|
4478 | } |
---|
4479 | |
---|
4480 | void setaktres() |
---|
4481 | { |
---|
4482 | int m_width; |
---|
4483 | char* res = NULL; |
---|
4484 | char* res_akt = NULL; |
---|
4485 | char* res_sd = NULL; |
---|
4486 | int count=1; |
---|
4487 | int sec = 0; |
---|
4488 | |
---|
4489 | if(status.restimer == NULL) return; |
---|
4490 | sec = (int)status.restimer->param1; |
---|
4491 | |
---|
4492 | if(sec > 0) |
---|
4493 | { |
---|
4494 | while(status.restimer->aktion == START && count <= sec) |
---|
4495 | { |
---|
4496 | sleep(1); |
---|
4497 | if(status.restimer->aktion != START) |
---|
4498 | { |
---|
4499 | status.restimer = NULL; |
---|
4500 | return; |
---|
4501 | } |
---|
4502 | count++; |
---|
4503 | } |
---|
4504 | } |
---|
4505 | |
---|
4506 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
4507 | { |
---|
4508 | m_width = status.videosize.w; |
---|
4509 | if (m_width == 720) { |
---|
4510 | res_sd = getconfig("av_videomode_autores_sd", NULL); |
---|
4511 | if(res_sd == NULL) |
---|
4512 | res = ostrcat(res, "576i50", 1, 0); |
---|
4513 | else |
---|
4514 | res = ostrcat(res, res_sd, 1, 0); |
---|
4515 | } |
---|
4516 | else if (m_width == 1280) |
---|
4517 | res = ostrcat(res, "720p50", 1, 0); |
---|
4518 | else if (m_width == 1920) |
---|
4519 | res = ostrcat(res, "1080i50", 1, 0); |
---|
4520 | else |
---|
4521 | m_width = 0; |
---|
4522 | if ( m_width > 0) |
---|
4523 | { |
---|
4524 | res_akt = getvideomode(); |
---|
4525 | if (ostrcmp(res_akt, res) != 0) |
---|
4526 | { |
---|
4527 | setvideomode(res, 1); |
---|
4528 | changefbresolution(res); |
---|
4529 | sleep(1); |
---|
4530 | screenautores(res, 5, 0); |
---|
4531 | } |
---|
4532 | } |
---|
4533 | } |
---|
4534 | else |
---|
4535 | textbox(_("Message"), _("ERROR cant read res"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
4536 | |
---|
4537 | free(res); |
---|
4538 | res = NULL; |
---|
4539 | status.restimer = NULL; |
---|
4540 | return; |
---|
4541 | } |
---|
4542 | |
---|
4543 | char* gettimestamp() |
---|
4544 | { |
---|
4545 | char* timestamp = NULL; |
---|
4546 | struct timeval numtime; |
---|
4547 | |
---|
4548 | gettimeofday(&numtime, 0); |
---|
4549 | timestamp = ostrcat(timestamp, olutoa(numtime.tv_sec), 1, 1); |
---|
4550 | timestamp = ostrcat(timestamp, olutoa(numtime.tv_usec), 1, 1); |
---|
4551 | |
---|
4552 | return timestamp; |
---|
4553 | } |
---|
4554 | |
---|
4555 | char* string_decode(char* input, int flag) |
---|
4556 | { |
---|
4557 | if(input == NULL) |
---|
4558 | { |
---|
4559 | return input; |
---|
4560 | } |
---|
4561 | |
---|
4562 | while(string_find("\\u00",input)) |
---|
4563 | { |
---|
4564 | debug(210, "input: %s", input); |
---|
4565 | input = string_replace("\\u00", "%", input, 1); |
---|
4566 | debug(210, "input: %s", input); |
---|
4567 | } |
---|
4568 | |
---|
4569 | while(string_find("&",input)) |
---|
4570 | { |
---|
4571 | debug(210, "input: %s", input); |
---|
4572 | input = string_replace("&", "und", input, 1); |
---|
4573 | debug(210, "input: %s", input); |
---|
4574 | } |
---|
4575 | |
---|
4576 | while(string_find(">",input)) |
---|
4577 | { |
---|
4578 | debug(210, "input: %s", input); |
---|
4579 | input = string_replace(">", ">", input, 1); |
---|
4580 | debug(210, "input: %s", input); |
---|
4581 | } |
---|
4582 | |
---|
4583 | while(string_find("<",input)) |
---|
4584 | { |
---|
4585 | debug(210, "input: %s", input); |
---|
4586 | input = string_replace("<", "<", input, 1); |
---|
4587 | debug(210, "input: %s", input); |
---|
4588 | } |
---|
4589 | |
---|
4590 | while(string_find(""",input)) |
---|
4591 | { |
---|
4592 | debug(210, "input: %s", input); |
---|
4593 | input = string_replace(""", "\"", input, 1); |
---|
4594 | debug(210, "input: %s", input); |
---|
4595 | } |
---|
4596 | |
---|
4597 | while(string_find("&#x",input)) |
---|
4598 | { |
---|
4599 | debug(210, "out %s", input); |
---|
4600 | input = string_replace("&#x", "%", input, 1); |
---|
4601 | debug(210, "input: %s", input); |
---|
4602 | } |
---|
4603 | while(string_find("&#",input)) |
---|
4604 | { |
---|
4605 | debug(210, "input: %s", input); |
---|
4606 | input = string_replace("&#", "%", input, 1); |
---|
4607 | debug(210, "input: %s", input); |
---|
4608 | } |
---|
4609 | |
---|
4610 | if(flag == 1) |
---|
4611 | htmldecode2(input,input); |
---|
4612 | else |
---|
4613 | htmldecode(input,input); |
---|
4614 | |
---|
4615 | while(string_find(";",input)) |
---|
4616 | { |
---|
4617 | debug(210, "input: %s", input); |
---|
4618 | input = string_replace(";", "", input, 1); |
---|
4619 | debug(210, "input: %s", input); |
---|
4620 | } |
---|
4621 | |
---|
4622 | debug(1000, "out"); |
---|
4623 | return input; |
---|
4624 | } |
---|
4625 | |
---|
4626 | char* string_striptags(char* filename) |
---|
4627 | { |
---|
4628 | debug(1000, "in"); |
---|
4629 | int i, len_filename; |
---|
4630 | |
---|
4631 | if(filename == NULL) return 0; |
---|
4632 | |
---|
4633 | len_filename = strlen(filename); |
---|
4634 | |
---|
4635 | int skip =0; |
---|
4636 | for(i = 0; (i) < len_filename; i++) |
---|
4637 | { |
---|
4638 | if(filename[i] == '<') |
---|
4639 | { |
---|
4640 | debug(210, "found < in string"); |
---|
4641 | skip = 1; |
---|
4642 | } |
---|
4643 | else if(filename[i] == '>') |
---|
4644 | { |
---|
4645 | debug(210, "found > in string"); |
---|
4646 | skip = 0; |
---|
4647 | filename[i] = ' '; |
---|
4648 | } |
---|
4649 | if(skip == 1) |
---|
4650 | filename[i] = ' '; |
---|
4651 | } |
---|
4652 | |
---|
4653 | debug(1000, "out"); |
---|
4654 | return strstrip(filename); |
---|
4655 | } |
---|
4656 | |
---|
4657 | char* string_resub(char* str, char* str2, char* filename) |
---|
4658 | { |
---|
4659 | debug(1000, "in"); |
---|
4660 | int i, len_str, len_filename; |
---|
4661 | |
---|
4662 | if(str == NULL || str2 == NULL || filename == NULL) return 0; |
---|
4663 | |
---|
4664 | len_str = strlen(str); |
---|
4665 | len_filename = strlen(filename); |
---|
4666 | |
---|
4667 | int count = 0; |
---|
4668 | for(i = 0; (i + len_str) < len_filename; i++) |
---|
4669 | { |
---|
4670 | if(strncmp(filename + i, str, len_str) == 0 && count == 0) |
---|
4671 | { |
---|
4672 | count = i + len_str; |
---|
4673 | filename[i] = ' '; |
---|
4674 | } |
---|
4675 | else if(count == i && count != 0) |
---|
4676 | { |
---|
4677 | count = i - len_str; |
---|
4678 | break; |
---|
4679 | } |
---|
4680 | else |
---|
4681 | filename[i] = ' '; |
---|
4682 | } |
---|
4683 | len_str = strlen(str2); |
---|
4684 | |
---|
4685 | for(i = 0; (i + len_str) < len_filename; i++) |
---|
4686 | { |
---|
4687 | if(strncmp(filename + i, str2, len_str) == 0 && i >= count) |
---|
4688 | { |
---|
4689 | filename[i] = '\0'; |
---|
4690 | break; |
---|
4691 | } |
---|
4692 | } |
---|
4693 | |
---|
4694 | debug(1000, "out"); |
---|
4695 | return strstrip(filename); |
---|
4696 | } |
---|
4697 | |
---|
4698 | #endif |
---|