1 | #ifndef GLOBAL_H |
---|
2 | #define GLOBAL_H |
---|
3 | |
---|
4 | //check if emu ist installed, if not it hiddes the menu |
---|
5 | int checkemu() |
---|
6 | { |
---|
7 | char* tmpstr = NULL; |
---|
8 | |
---|
9 | tmpstr = command("emu.sh list"); |
---|
10 | if(tmpstr != NULL) |
---|
11 | return 1; |
---|
12 | |
---|
13 | return 0; |
---|
14 | } |
---|
15 | |
---|
16 | //can use to disable a menu for a box (node type must be MENU) |
---|
17 | int checkmenuforbox(char *name) |
---|
18 | { |
---|
19 | if(status.expertmodus == 1) return 1; |
---|
20 | if(checkbox("ATEMIO500") == 1) |
---|
21 | { |
---|
22 | if(ostrcmp("vfdisplay", name) == 0) return 0; |
---|
23 | if(ostrcmp("savesettings", name) == 0) return 0; |
---|
24 | if(ostrcmp("recordpath", name) == 0) return 0; |
---|
25 | if(ostrcmp("videosettings", name) == 0) return 0; |
---|
26 | if(ostrcmp("scartrecorder", name) == 0) return 0; |
---|
27 | if(ostrcmp("information", name) == 0) return 0; |
---|
28 | if(ostrcmp("plugins", name) == 0) return 0; |
---|
29 | if(ostrcmp("vfdisplay", name) == 0) return 0; |
---|
30 | if(ostrcmp("rotorsettings", name) == 0) return 0; |
---|
31 | if(ostrcmp("satconfig", name) == 0) return 0; |
---|
32 | if(ostrcmp("satfinder", name) == 0) return 0; |
---|
33 | if(ostrcmp("mediacenter", name) == 0) return 0; |
---|
34 | if(ostrcmp("configurehdd", name) == 0) return 0; |
---|
35 | if(ostrcmp("aafpanel_system_aafwizard", name) == 0) return 0; |
---|
36 | if(ostrcmp("aafpanel_settings_overclocking", name) == 0) return 0; |
---|
37 | if(ostrcmp("aafpanel_settings_fancontrol", name) == 0) return 0; |
---|
38 | if(ostrcmp("aafpanel_settings_automount", name) == 0) return 0; |
---|
39 | if(ostrcmp("aafpanel_settings_autostart", name) == 0) return 0; |
---|
40 | if(ostrcmp("aafpanel_settings_videotune", name) == 0) return 0; |
---|
41 | if(ostrcmp("aafpanel_system_update_usb_online", name) == 0) return 0; |
---|
42 | if(ostrcmp("aafpanel_system_update_usb_tmp", name) == 0) return 0; |
---|
43 | if(ostrcmp("aafpanel_extensions_menu", name) == 0) return 0; |
---|
44 | if(ostrcmp("aafpanel_system_backup", name) == 0) return 0; |
---|
45 | } |
---|
46 | return 1; |
---|
47 | } |
---|
48 | |
---|
49 | int isbase64(char c) |
---|
50 | { |
---|
51 | if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=') |
---|
52 | return 1; |
---|
53 | return 0; |
---|
54 | } |
---|
55 | |
---|
56 | char decodebase64(char c) |
---|
57 | { |
---|
58 | if(c >= 'A' && c <= 'Z') return(c - 'A'); |
---|
59 | if(c >= 'a' && c <= 'z') return(c - 'a' + 26); |
---|
60 | if(c >= '0' && c <= '9') return(c - '0' + 52); |
---|
61 | if(c == '+') return(62); |
---|
62 | return 63; |
---|
63 | } |
---|
64 | |
---|
65 | int b64dec(char* dest, char* src) |
---|
66 | { |
---|
67 | if(src && *src) |
---|
68 | { |
---|
69 | char* p = dest; |
---|
70 | int k, l = strlen(src) + 1; |
---|
71 | char* buf = NULL; |
---|
72 | |
---|
73 | buf = malloc(l); |
---|
74 | if(buf == NULL) return 0; |
---|
75 | |
---|
76 | for(k = 0, l = 0; src[k]; k++) |
---|
77 | { |
---|
78 | if(isbase64(src[k])) |
---|
79 | buf[l++] = src[k]; |
---|
80 | } |
---|
81 | |
---|
82 | for(k = 0; k < l; k += 4) |
---|
83 | { |
---|
84 | char c1 = 'A', c2 = 'A', c3 = 'A', c4 = 'A'; |
---|
85 | char b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
---|
86 | |
---|
87 | c1 = buf[k]; |
---|
88 | if(k + 1 < l) |
---|
89 | c2 = buf[k + 1]; |
---|
90 | if(k + 2 < l) |
---|
91 | c3 = buf[k + 2]; |
---|
92 | if(k + 3 < l) |
---|
93 | c4 = buf[k + 3]; |
---|
94 | |
---|
95 | b1 = decodebase64(c1); |
---|
96 | b2 = decodebase64(c2); |
---|
97 | b3 = decodebase64(c3); |
---|
98 | b4 = decodebase64(c4); |
---|
99 | |
---|
100 | *p++ = ((b1 << 2) | (b2 >> 4)); |
---|
101 | |
---|
102 | if(c3 != '=') |
---|
103 | *p++ = (((b2 & 0xf) << 4) | (b3 >> 2)); |
---|
104 | if(c4 != '=') |
---|
105 | *p++ = (((b3 & 0x3) << 6) | b4); |
---|
106 | |
---|
107 | } |
---|
108 | |
---|
109 | free(buf); |
---|
110 | return(p - dest); |
---|
111 | } |
---|
112 | return 0; |
---|
113 | } |
---|
114 | |
---|
115 | void changechannellist(struct channel* chnode, char* channellist) |
---|
116 | { |
---|
117 | char* tmpstr = NULL; |
---|
118 | |
---|
119 | if(chnode == NULL || status.aktservice->channel == NULL) return; |
---|
120 | |
---|
121 | status.servicetype = chnode->servicetype; |
---|
122 | if(status.servicetype == 0) |
---|
123 | { |
---|
124 | if(channellist != NULL) |
---|
125 | { |
---|
126 | tmpstr = ostrcat(channellist, NULL, 0, 0); |
---|
127 | free(status.aktservice->channellist); |
---|
128 | status.aktservice->channellist = tmpstr; |
---|
129 | addconfig("channellist", tmpstr); |
---|
130 | } |
---|
131 | tmpstr = oitoa(status.aktservice->channel->serviceid); |
---|
132 | addconfig("serviceid", tmpstr); |
---|
133 | free(tmpstr); tmpstr = NULL; |
---|
134 | tmpstr = olutoa(status.aktservice->channel->transponderid); |
---|
135 | addconfig("transponderid", tmpstr); |
---|
136 | free(tmpstr); tmpstr = NULL; |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | if(channellist != NULL) |
---|
141 | { |
---|
142 | tmpstr = ostrcat(channellist, NULL, 0, 0); |
---|
143 | free(status.aktservice->channellist); |
---|
144 | status.aktservice->channellist = tmpstr; |
---|
145 | addconfig("rchannellist", tmpstr); |
---|
146 | } |
---|
147 | tmpstr = oitoa(status.aktservice->channel->serviceid); |
---|
148 | addconfig("rserviceid", tmpstr); |
---|
149 | free(tmpstr); tmpstr = NULL; |
---|
150 | tmpstr = olutoa(status.aktservice->channel->transponderid); |
---|
151 | addconfig("rtransponderid", tmpstr); |
---|
152 | free(tmpstr); tmpstr = NULL; |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | char* createpiconpath(struct channel* chnode) |
---|
157 | { |
---|
158 | char* tmpstr = NULL, *tmpnr = NULL; |
---|
159 | |
---|
160 | if(chnode != NULL) |
---|
161 | { |
---|
162 | tmpstr = ostrcat(tmpstr, getconfig("piconpath", NULL), 1, 0); |
---|
163 | tmpstr = ostrcat(tmpstr, "/", 1, 0); |
---|
164 | |
---|
165 | tmpnr = oitoa(chnode->serviceid); |
---|
166 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
167 | tmpnr = NULL; |
---|
168 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
169 | tmpnr = olutoa(chnode->transponderid); |
---|
170 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
171 | tmpnr = NULL; |
---|
172 | tmpstr = ostrcat(tmpstr, ".png", 1, 0); |
---|
173 | } |
---|
174 | if(!isfile(tmpstr)) |
---|
175 | { |
---|
176 | free(tmpstr); tmpstr = NULL; |
---|
177 | tmpstr = ostrcat(tmpstr, getconfig("piconpath", NULL), 1, 0); |
---|
178 | tmpstr = ostrcat(tmpstr, "/", 1, 0); |
---|
179 | tmpstr = ostrcat(tmpstr, "default.png", 1, 0); |
---|
180 | } |
---|
181 | |
---|
182 | return tmpstr; |
---|
183 | } |
---|
184 | |
---|
185 | int checkskin() |
---|
186 | { |
---|
187 | int ret = 0; |
---|
188 | char* defskinpath = NULL; |
---|
189 | char* defskinconfig = NULL; |
---|
190 | char* defskinfile = NULL; |
---|
191 | |
---|
192 | if(file_exist(getconfig("skinpath", NULL)) == 0) |
---|
193 | ret = 1; |
---|
194 | else if(file_exist(getconfig("skinconfig", NULL)) == 0) |
---|
195 | ret = 2; |
---|
196 | else if(file_exist(getconfig("skinfile", NULL)) == 0) |
---|
197 | ret = 3; |
---|
198 | |
---|
199 | if(ret != 0) |
---|
200 | { |
---|
201 | err("skin not found code=%d, change to default", ret); |
---|
202 | |
---|
203 | defskinpath = getconfig("defskinpath", NULL); |
---|
204 | if(defskinpath != NULL) addconfig("skinpath", defskinpath); |
---|
205 | defskinconfig = getconfig("defskinconfig", NULL); |
---|
206 | if(defskinconfig != NULL) addconfig("skinconfig", defskinconfig); |
---|
207 | defskinfile = getconfig("defskinfile", NULL); |
---|
208 | if(defskinfile != NULL) addconfig("skinfile", defskinfile); |
---|
209 | |
---|
210 | ret = 0; |
---|
211 | if(file_exist(getconfig("skinpath", NULL)) == 0) |
---|
212 | ret = 1; |
---|
213 | else if(file_exist(getconfig("skinconfig", NULL)) == 0) |
---|
214 | ret = 2; |
---|
215 | else if(file_exist(getconfig("skinfile", NULL)) == 0) |
---|
216 | ret = 3; |
---|
217 | } |
---|
218 | |
---|
219 | if(ret != 0) |
---|
220 | { |
---|
221 | err("default skin not found code=%d", ret); |
---|
222 | } |
---|
223 | |
---|
224 | return ret; |
---|
225 | } |
---|
226 | |
---|
227 | int getaktvideosize() |
---|
228 | { |
---|
229 | //wait 3 sek after zap, befor videsize is valid |
---|
230 | //driver takes a little time |
---|
231 | if(status.videosizevalid == 1) |
---|
232 | return 0; |
---|
233 | else if(status.videosizevalid + 3 > time(NULL)) |
---|
234 | return 1; |
---|
235 | else |
---|
236 | { |
---|
237 | #ifndef SIMULATE |
---|
238 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
239 | #endif |
---|
240 | status.videosizevalid = 1; |
---|
241 | } |
---|
242 | |
---|
243 | return 1; |
---|
244 | } |
---|
245 | |
---|
246 | int ostrftime(char* buf, int count, char* format, struct tm* t) |
---|
247 | { |
---|
248 | int ret = -1; |
---|
249 | |
---|
250 | if(format != NULL) |
---|
251 | ret = strftime(buf, count, format, t); |
---|
252 | else |
---|
253 | ret = strftime(buf, count, "%d-%m-%Y %H:%M", t); |
---|
254 | |
---|
255 | return ret; |
---|
256 | } |
---|
257 | |
---|
258 | //flag 0 = write all |
---|
259 | //flag 1 = don't write epg |
---|
260 | int writeallconfig(int flag) |
---|
261 | { |
---|
262 | debug(1000, "in"); |
---|
263 | char* tmpstr = NULL; |
---|
264 | int ret = 0; |
---|
265 | |
---|
266 | if(status.writerectimer == 1) |
---|
267 | if(writerectimer(getconfig("rectimerfile", NULL), 0) != 0) |
---|
268 | ret = 1; |
---|
269 | if(status.writesat == 1) |
---|
270 | if(writesat(getconfig("satfile", NULL)) != 0) |
---|
271 | ret = 1; |
---|
272 | if(status.writeplaylist == 1) |
---|
273 | if(writeallplaylist() != 0) |
---|
274 | ret = 1; |
---|
275 | if(status.writemainplaylist == 1) |
---|
276 | if(writemainplaylist(getconfig("playlistfile", NULL)) != 0) |
---|
277 | ret = 1; |
---|
278 | if(status.writebouquet == 1) |
---|
279 | if(writeallbouquet() != 0) |
---|
280 | ret = 1; |
---|
281 | if(status.writemainbouquet == 1) |
---|
282 | if(writemainbouquet(getconfig("bouquetfile", NULL)) != 0) |
---|
283 | ret = 1; |
---|
284 | if(status.writechannel == 1) |
---|
285 | if(writechannel(getconfig("channelfile", NULL)) != 0) |
---|
286 | ret = 1; |
---|
287 | if(status.writetransponder == 1) |
---|
288 | if(writetransponder(getconfig("transponderfile", NULL)) != 0) |
---|
289 | ret = 1; |
---|
290 | if(status.writeprovider == 1) |
---|
291 | if(writeprovider(getconfig("providerfile", NULL)) != 0) |
---|
292 | ret = 1; |
---|
293 | if(status.writeownconfig == 1) |
---|
294 | if(writeownconfig(getconfig("ownconfig", NULL)) != 0) |
---|
295 | ret = 1; |
---|
296 | if(status.writeepgscanlist == 1) |
---|
297 | if(writeepgscanlist(getconfig("epgchannelfile", NULL)) != 0) |
---|
298 | ret = 1; |
---|
299 | if(status.writercconfig == 1) |
---|
300 | if(writercconfig(getconfig("rcconfig", NULL)) != 0) |
---|
301 | ret = 1; |
---|
302 | if(status.writeskinconfig == 1) |
---|
303 | if(writeskinconfig(getconfig("skinconfig", NULL)) != 0) |
---|
304 | ret = 1; |
---|
305 | if(status.writeconfig == 1) |
---|
306 | if(writeconfig(status.configfile) != 0) |
---|
307 | ret = 1; |
---|
308 | if(flag == 0 && time(NULL) > 1072224000) // 01.01.2004 |
---|
309 | { |
---|
310 | tmpstr = createpath(getconfig("epg_path", NULL), "epg.dat"); |
---|
311 | if(writeepg(tmpstr) != 0) |
---|
312 | ret = 1; |
---|
313 | free(tmpstr); tmpstr = NULL; |
---|
314 | } |
---|
315 | |
---|
316 | sync(); |
---|
317 | |
---|
318 | debug(1000, "out"); |
---|
319 | return ret; |
---|
320 | } |
---|
321 | |
---|
322 | void initmutex(int flag) |
---|
323 | { |
---|
324 | if(flag == 1) |
---|
325 | { |
---|
326 | pthread_mutex_init(&status.drawingmutex, NULL); |
---|
327 | pthread_mutex_init(&status.rectimermutex, NULL); |
---|
328 | pthread_mutex_init(&status.servicemutex, NULL); |
---|
329 | pthread_mutex_init(&status.epgmutex, NULL); |
---|
330 | pthread_mutex_init(&status.vfdmutex, NULL); |
---|
331 | pthread_mutex_init(&status.channelmutex, NULL); |
---|
332 | pthread_mutex_init(&status.timerthreadmutex, NULL); |
---|
333 | pthread_mutex_init(&status.audiotrackmutex, NULL); |
---|
334 | pthread_mutex_init(&status.subtitlemutex, NULL); |
---|
335 | pthread_mutex_init(&status.dmxdevmutex, NULL); |
---|
336 | pthread_mutex_init(&status.rcmutex, NULL); |
---|
337 | pthread_mutex_init(&status.queuemutex, NULL); |
---|
338 | pthread_mutex_init(&status.clistmutex, NULL); |
---|
339 | pthread_mutex_init(&status.hddmutex, NULL); |
---|
340 | } |
---|
341 | else |
---|
342 | { |
---|
343 | pthread_mutex_destroy(&status.drawingmutex); |
---|
344 | pthread_mutex_destroy(&status.rectimermutex); |
---|
345 | pthread_mutex_destroy(&status.servicemutex); |
---|
346 | pthread_mutex_destroy(&status.epgmutex); |
---|
347 | pthread_mutex_destroy(&status.vfdmutex); |
---|
348 | pthread_mutex_destroy(&status.channelmutex); |
---|
349 | pthread_mutex_destroy(&status.timerthreadmutex); |
---|
350 | pthread_mutex_destroy(&status.audiotrackmutex); |
---|
351 | pthread_mutex_destroy(&status.subtitlemutex); |
---|
352 | pthread_mutex_destroy(&status.dmxdevmutex); |
---|
353 | pthread_mutex_destroy(&status.rcmutex); |
---|
354 | pthread_mutex_destroy(&status.queuemutex); |
---|
355 | pthread_mutex_destroy(&status.clistmutex); |
---|
356 | pthread_mutex_destroy(&status.hddmutex); |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | int hexit(char c) |
---|
361 | { |
---|
362 | if(c >= '0' && c <= '9') |
---|
363 | return c - '0'; |
---|
364 | if(c >= 'a' && c <= 'f') |
---|
365 | return c - 'a' + 10; |
---|
366 | if(c >= 'A' && c <= 'F') |
---|
367 | return c - 'A' + 10; |
---|
368 | |
---|
369 | return 0; |
---|
370 | } |
---|
371 | |
---|
372 | char* htmlencode(char* from) |
---|
373 | { |
---|
374 | int buflen = 0; |
---|
375 | char* buf = NULL, *to = NULL; |
---|
376 | |
---|
377 | buf = malloc(MINMALLOC); |
---|
378 | if(buf == NULL) |
---|
379 | { |
---|
380 | err("no mem"); |
---|
381 | return NULL; |
---|
382 | } |
---|
383 | memset(buf, 0, MINMALLOC); |
---|
384 | to = buf; |
---|
385 | |
---|
386 | for(buflen = 0; *from != '\0' && buflen < MINMALLOC; ++from) |
---|
387 | { |
---|
388 | if(isalnum(*from) || strchr("/_.-~", *from) != NULL) |
---|
389 | { |
---|
390 | *to = *from; |
---|
391 | ++to; |
---|
392 | ++buflen; |
---|
393 | } |
---|
394 | else |
---|
395 | { |
---|
396 | sprintf(to, "%%%02x", (int)*from & 0xff); |
---|
397 | to += 3; |
---|
398 | buflen += 3; |
---|
399 | } |
---|
400 | } |
---|
401 | *to = '\0'; |
---|
402 | |
---|
403 | buf = ostrcat(buf, NULL, 1, 0); |
---|
404 | return buf; |
---|
405 | } |
---|
406 | |
---|
407 | void htmldecode(char* to, char* from) |
---|
408 | { |
---|
409 | for(; *from != '\0'; ++to, ++from) |
---|
410 | { |
---|
411 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
412 | { |
---|
413 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
414 | from += 2; |
---|
415 | } |
---|
416 | else |
---|
417 | *to = *from; |
---|
418 | } |
---|
419 | *to = '\0'; |
---|
420 | } |
---|
421 | |
---|
422 | void setosdtransparent(int value) |
---|
423 | { |
---|
424 | int ret = 255; |
---|
425 | if(value < 0) value = 0; |
---|
426 | if(value > 100) value = 100; |
---|
427 | |
---|
428 | ret -= value * 2.55; |
---|
429 | |
---|
430 | setfbtransparent(ret); |
---|
431 | } |
---|
432 | |
---|
433 | struct tm* olocaltime(time_t *value) |
---|
434 | { |
---|
435 | struct tm *loctime, *loctime1 = NULL; |
---|
436 | |
---|
437 | loctime1 = (struct tm*)malloc(sizeof(struct tm)); |
---|
438 | if(loctime1 == NULL) |
---|
439 | { |
---|
440 | err("no mem"); |
---|
441 | return NULL; |
---|
442 | } |
---|
443 | loctime = localtime_r(value, loctime1); |
---|
444 | |
---|
445 | return loctime; |
---|
446 | } |
---|
447 | |
---|
448 | int setwakeuptimer(time_t waketime) |
---|
449 | { |
---|
450 | debug(1000, "in"); |
---|
451 | char* wakeuptimerprog = NULL; |
---|
452 | struct tm *loctime = NULL; |
---|
453 | char *buf = NULL; |
---|
454 | int ret = -1; |
---|
455 | |
---|
456 | wakeuptimerprog = getconfig("wakeuptimerprog", NULL); |
---|
457 | |
---|
458 | if(wakeuptimerprog == NULL) |
---|
459 | { |
---|
460 | debug(1000, "out -> NULL detect"); |
---|
461 | return ret; |
---|
462 | } |
---|
463 | |
---|
464 | buf = malloc(MINMALLOC); |
---|
465 | if(buf == NULL) |
---|
466 | { |
---|
467 | err("no memory"); |
---|
468 | return ret; |
---|
469 | } |
---|
470 | |
---|
471 | loctime = olocaltime(&waketime); |
---|
472 | |
---|
473 | if(loctime != NULL) |
---|
474 | ostrftime(buf, MINMALLOC, wakeuptimerprog, loctime); |
---|
475 | |
---|
476 | if(buf != NULL) |
---|
477 | { |
---|
478 | debug(100, "set wake up timer (%s)", buf); |
---|
479 | ret = system(buf); |
---|
480 | } |
---|
481 | |
---|
482 | free(loctime); |
---|
483 | free(buf); |
---|
484 | debug(1000, "out"); |
---|
485 | return ret; |
---|
486 | } |
---|
487 | |
---|
488 | int autoresolution() |
---|
489 | { |
---|
490 | debug(1000, "in"); |
---|
491 | char *hotpluginfo = NULL; |
---|
492 | char *value = NULL; |
---|
493 | |
---|
494 | if(getconfig("av_videomode", NULL) != NULL || getconfig("av_colorformat", NULL)) |
---|
495 | return 1; |
---|
496 | |
---|
497 | hotpluginfo = getconfig("hotpluginfo", NULL); |
---|
498 | |
---|
499 | if(hotpluginfo == NULL) |
---|
500 | { |
---|
501 | debug(1000, "out -> NULL detect"); |
---|
502 | return 1; |
---|
503 | } |
---|
504 | |
---|
505 | value = readsys(hotpluginfo, 1); |
---|
506 | if(value == NULL) |
---|
507 | { |
---|
508 | debug(1000, "out -> NULL detect"); |
---|
509 | return 1; |
---|
510 | } |
---|
511 | |
---|
512 | if(value[0] == 'y') |
---|
513 | { |
---|
514 | setvideomode("720p50"); |
---|
515 | changefbresolution("720p50"); |
---|
516 | setcolorformat("hdmi_rgb"); |
---|
517 | } |
---|
518 | else |
---|
519 | { |
---|
520 | setvideomode("576i50"); |
---|
521 | changefbresolution("576i50"); |
---|
522 | setcolorformat("rgb"); |
---|
523 | } |
---|
524 | |
---|
525 | free(value); |
---|
526 | debug(1000, "out"); |
---|
527 | return 0; |
---|
528 | } |
---|
529 | |
---|
530 | //TODO: can remove if new function work |
---|
531 | /* |
---|
532 | int writelengthfield(unsigned char *buf, unsigned int len) |
---|
533 | { |
---|
534 | if(len < 127) |
---|
535 | { |
---|
536 | *buf++ = len; |
---|
537 | return 1; |
---|
538 | } |
---|
539 | else if(len < 256) |
---|
540 | { |
---|
541 | *buf++ = 0x81; |
---|
542 | *buf++ = len; |
---|
543 | return 2; |
---|
544 | } |
---|
545 | else if(len < 65535) |
---|
546 | { |
---|
547 | *buf++ = 0x82; |
---|
548 | *buf++ = len >> 8; |
---|
549 | *buf++ = len; |
---|
550 | return 3; |
---|
551 | } |
---|
552 | |
---|
553 | return 0; |
---|
554 | } |
---|
555 | */ |
---|
556 | |
---|
557 | size_t writelengthfield(unsigned char * buf, unsigned int len) |
---|
558 | { |
---|
559 | if(buf == NULL) return 0; |
---|
560 | |
---|
561 | if(len < 128) |
---|
562 | { |
---|
563 | buf[0] = len; |
---|
564 | return 1; |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | unsigned int pos = 0; |
---|
569 | unsigned int shiftby = 8; |
---|
570 | unsigned char lenfieldsize = 1; |
---|
571 | |
---|
572 | while((len >> shiftby) != 0) |
---|
573 | { |
---|
574 | lenfieldsize++; |
---|
575 | shiftby += 8; |
---|
576 | } |
---|
577 | |
---|
578 | buf[pos++] = ((1 << 7) | lenfieldsize); |
---|
579 | |
---|
580 | while(shiftby != 0) |
---|
581 | { |
---|
582 | shiftby -= 8; |
---|
583 | buf[pos++] = len >> shiftby; |
---|
584 | } |
---|
585 | return pos; |
---|
586 | } |
---|
587 | } |
---|
588 | |
---|
589 | |
---|
590 | //flag 0: del non alpha/num |
---|
591 | //flag 1: change all / |
---|
592 | void delspezchar(char* text, int flag) |
---|
593 | { |
---|
594 | char* tmpstr = text; |
---|
595 | |
---|
596 | while(*tmpstr != '\0') |
---|
597 | { |
---|
598 | if(flag == 1) |
---|
599 | { |
---|
600 | if(tmpstr[0] == '/') |
---|
601 | tmpstr[0] = '-'; |
---|
602 | } |
---|
603 | else |
---|
604 | { |
---|
605 | if(!isalnum(tmpstr[0]) && tmpstr[0] != '-' && tmpstr[0] != '.') |
---|
606 | tmpstr[0] = ' '; |
---|
607 | } |
---|
608 | tmpstr++; |
---|
609 | } |
---|
610 | } |
---|
611 | |
---|
612 | void m_lock(pthread_mutex_t *mutex, int flag) |
---|
613 | { |
---|
614 | switch(flag) |
---|
615 | { |
---|
616 | case 0: debug(900, "drawingmutex lock"); break; |
---|
617 | case 1: debug(900, "rectimermutex lock"); break; |
---|
618 | case 2: debug(900, "servicemutex lock"); break; |
---|
619 | case 3: debug(900, "vfdmutex lock"); break; |
---|
620 | case 4: debug(900, "epgmutex lock"); break; |
---|
621 | case 5: debug(900, "channelmutex lock"); break; |
---|
622 | case 6: debug(900, "timerthreadmutex lock"); break; |
---|
623 | case 7: debug(900, "audiotrackmutex lock"); break; |
---|
624 | case 8: debug(900, "subtitlemutex lock"); break; |
---|
625 | case 9: debug(900, "dmxdevmutex lock"); break; |
---|
626 | case 10: debug(900, "rcmutex lock"); break; |
---|
627 | case 11: debug(900, "queuemutex lock"); break; |
---|
628 | case 12: debug(900, "clistmutex lock"); break; |
---|
629 | case 13: debug(900, "hddmutex lock"); break; |
---|
630 | default: debug(900, " unknown mutex lock"); break; |
---|
631 | } |
---|
632 | pthread_mutex_lock(mutex); |
---|
633 | } |
---|
634 | |
---|
635 | void m_unlock(pthread_mutex_t *mutex, int flag) |
---|
636 | { |
---|
637 | switch(flag) |
---|
638 | { |
---|
639 | case 0: debug(900, "drawingmutex unlock"); break; |
---|
640 | case 1: debug(900, "rectimermutex unlock"); break; |
---|
641 | case 2: debug(900, "servicemutex unlock"); break; |
---|
642 | case 3: debug(900, "vfdmutex unlock"); break; |
---|
643 | case 4: debug(900, "epgmutex unlock"); break; |
---|
644 | case 5: debug(900, "channelmutex unlock"); break; |
---|
645 | case 6: debug(900, "timerthreadmutex unlock"); break; |
---|
646 | case 7: debug(900, "audiotrackmutex unlock"); break; |
---|
647 | case 8: debug(900, "subtitlemutex unlock"); break; |
---|
648 | case 9: debug(900, "dmxdevmutex unlock"); break; |
---|
649 | case 10: debug(900, "rcmutex unlock"); break; |
---|
650 | case 11: debug(900, "queuemutex unlock"); break; |
---|
651 | case 12: debug(900, "clistmutex unlock"); break; |
---|
652 | case 13: debug(900, "hddmutex unlock"); break; |
---|
653 | default: debug(900, " unknown mutex unlock"); break; |
---|
654 | } |
---|
655 | pthread_mutex_unlock(mutex); |
---|
656 | } |
---|
657 | |
---|
658 | void debugstack(void* address, void* address1) |
---|
659 | { |
---|
660 | void* trace[10]; |
---|
661 | size_t size; |
---|
662 | size = backtrace(trace, 10); |
---|
663 | |
---|
664 | FILE* fd = NULL; |
---|
665 | void* akttrace[2]; |
---|
666 | int i; |
---|
667 | char **strings; |
---|
668 | char **aktstring; |
---|
669 | time_t rawtime; |
---|
670 | |
---|
671 | strings = backtrace_symbols(trace, size); |
---|
672 | akttrace[0] = (void*)address1; |
---|
673 | akttrace[1] = (void*)address; |
---|
674 | aktstring = backtrace_symbols(akttrace, 2); //get fault funktion name |
---|
675 | |
---|
676 | printf("--------------------------------------\n"); |
---|
677 | printf("Obtaining %zd stack frames:\n\n", size); |
---|
678 | |
---|
679 | for(i = 0; i < size; i++) |
---|
680 | printf("%s\n", strings[i]); |
---|
681 | |
---|
682 | printf("\nLast functions:\n\n"); |
---|
683 | printf("%s\n", aktstring[0]); |
---|
684 | printf("%s\n", aktstring[1]); |
---|
685 | |
---|
686 | printf("--------------------------------------\n"); |
---|
687 | |
---|
688 | fd = fopen(getconfig("tracelog", NULL), "a"); |
---|
689 | if(fd != NULL) |
---|
690 | { |
---|
691 | time(&rawtime); |
---|
692 | fprintf(fd, "Date: %s", ctime(&rawtime)); |
---|
693 | fprintf(fd, "Obtaining %zd stack frames:\n\n", size); |
---|
694 | for(i = 1; i < size; i++) |
---|
695 | fprintf(fd, "%s\n", strings[i]); |
---|
696 | fprintf(fd, "\nLast functions:\n\n"); |
---|
697 | fprintf(fd, "%s\n", aktstring[0]); |
---|
698 | fprintf(fd, "%s\n", aktstring[1]); |
---|
699 | fprintf(fd, "--------------------------------------\n\n"); |
---|
700 | fclose(fd); |
---|
701 | sync(); |
---|
702 | } |
---|
703 | else |
---|
704 | perr("open %s", getconfig("tracelog", NULL)); |
---|
705 | |
---|
706 | free(strings); |
---|
707 | free(aktstring); |
---|
708 | } |
---|
709 | |
---|
710 | int mountauto(const char *file, const char *dir, unsigned long int flag, const void *data) |
---|
711 | { |
---|
712 | int ret = -1; |
---|
713 | char* saveptr = NULL, *filesystems = NULL, *tmpfilesystems = NULL, *token = NULL; |
---|
714 | |
---|
715 | filesystems = getconfig("filesystems", NULL); |
---|
716 | tmpfilesystems = ostrcat(tmpfilesystems, filesystems, 0, 0); |
---|
717 | |
---|
718 | token = strtok_r(tmpfilesystems, ";" , &saveptr); |
---|
719 | while(token != NULL) |
---|
720 | { |
---|
721 | ret = mount(file, dir, token, flag, data); |
---|
722 | if(ret == 0) break; |
---|
723 | token = strtok_r(NULL, ";" , &saveptr); |
---|
724 | } |
---|
725 | |
---|
726 | free(tmpfilesystems); |
---|
727 | return ret; |
---|
728 | } |
---|
729 | |
---|
730 | int getwaswakuptimer() |
---|
731 | { |
---|
732 | debug(1000, "in"); |
---|
733 | int ret = 0; |
---|
734 | char *waswakeuptimerdev = NULL; |
---|
735 | char *value = NULL; |
---|
736 | |
---|
737 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
738 | |
---|
739 | if(waswakeuptimerdev == NULL) |
---|
740 | { |
---|
741 | debug(1000, "out -> NULL detect"); |
---|
742 | return 0; |
---|
743 | } |
---|
744 | |
---|
745 | value = readsys(waswakeuptimerdev, 1); |
---|
746 | if(value == NULL) |
---|
747 | { |
---|
748 | debug(1000, "out -> NULL detect"); |
---|
749 | return 0; |
---|
750 | } |
---|
751 | |
---|
752 | // start from timer |
---|
753 | if(atoi(value) == 1) ret = 1; |
---|
754 | |
---|
755 | free(value); |
---|
756 | debug(1000, "out"); |
---|
757 | return ret; |
---|
758 | } |
---|
759 | |
---|
760 | int setwakeuptimerdev(time_t value) |
---|
761 | { |
---|
762 | debug(1000, "in"); |
---|
763 | char* wakeuptimerdev, *tmpstr = NULL; |
---|
764 | int ret = 0; |
---|
765 | |
---|
766 | wakeuptimerdev = getconfig("wakeuptimerdev", NULL); |
---|
767 | |
---|
768 | if(wakeuptimerdev != NULL && value >= time(NULL)) |
---|
769 | { |
---|
770 | debug(100, "set %s to %ld", wakeuptimerdev, value); |
---|
771 | tmpstr = olutoa(value); |
---|
772 | ret = writesys(wakeuptimerdev, tmpstr, 0); |
---|
773 | free(tmpstr); tmpstr = NULL; |
---|
774 | return ret; |
---|
775 | } |
---|
776 | |
---|
777 | debug(1000, "out"); |
---|
778 | return 0; |
---|
779 | } |
---|
780 | |
---|
781 | int changepolicy() |
---|
782 | { |
---|
783 | debug(1000, "in"); |
---|
784 | char *tmppolicy = NULL, *tmpstr = NULL; |
---|
785 | |
---|
786 | tmppolicy = getpolicy(); |
---|
787 | |
---|
788 | if(!ostrncmp("letterbox", tmppolicy, 8)) |
---|
789 | tmpstr = ostrcat(tmpstr, "panscan", 1, 0); |
---|
790 | else if(!ostrncmp("panscan", tmppolicy, 7)) |
---|
791 | tmpstr = ostrcat(tmpstr, "non", 1, 0); |
---|
792 | else if(!ostrncmp("non", tmppolicy, 3)) |
---|
793 | tmpstr = ostrcat(tmpstr, "bestfit", 1, 0); |
---|
794 | else if(!ostrncmp("bestfit", tmppolicy, 7)) |
---|
795 | tmpstr = ostrcat(tmpstr, "letterbox", 1, 0); |
---|
796 | |
---|
797 | setpolicy(tmpstr); |
---|
798 | |
---|
799 | free(tmpstr); tmpstr = NULL; |
---|
800 | free(tmppolicy); tmppolicy = NULL; |
---|
801 | debug(1000, "out"); |
---|
802 | return 0; |
---|
803 | } |
---|
804 | |
---|
805 | char* getdefaultgw() |
---|
806 | { |
---|
807 | char* name = NULL; |
---|
808 | unsigned long def, gw, m; |
---|
809 | int flags, ref, use, metric, mtu, win, ir; |
---|
810 | struct in_addr ip; |
---|
811 | |
---|
812 | FILE *fd = fopen("/proc/net/route", "r"); |
---|
813 | if(fd == NULL) |
---|
814 | return NULL; |
---|
815 | |
---|
816 | if(fscanf(fd, "%*[^\n]\n") < 0) |
---|
817 | { |
---|
818 | fclose(fd); |
---|
819 | return NULL; |
---|
820 | } |
---|
821 | |
---|
822 | name = malloc(64); |
---|
823 | if(name == NULL) |
---|
824 | { |
---|
825 | err("no mem"); |
---|
826 | return NULL; |
---|
827 | } |
---|
828 | |
---|
829 | while(1) |
---|
830 | { |
---|
831 | 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); |
---|
832 | if(def == 0) break; |
---|
833 | if(r != 11) |
---|
834 | { |
---|
835 | fclose(fd); |
---|
836 | free(name); |
---|
837 | return NULL; |
---|
838 | } |
---|
839 | if(!(flags & 0x0001)) continue; //is interface down |
---|
840 | } |
---|
841 | |
---|
842 | fclose(fd); |
---|
843 | free(name); |
---|
844 | |
---|
845 | ip.s_addr = gw; |
---|
846 | if(def == 0) |
---|
847 | return inet_ntoa(ip); |
---|
848 | |
---|
849 | return NULL; |
---|
850 | } |
---|
851 | |
---|
852 | char* changefilenameext(char* filename, char* ext) |
---|
853 | { |
---|
854 | char* newfilename = NULL; |
---|
855 | char* zeichen = NULL; |
---|
856 | |
---|
857 | if(filename == NULL) return NULL; |
---|
858 | |
---|
859 | newfilename = ostrcat(filename, "", 0, 0); |
---|
860 | |
---|
861 | zeichen = strrchr(newfilename, '.'); |
---|
862 | if(zeichen != NULL) |
---|
863 | { |
---|
864 | zeichen[0] = '\0'; |
---|
865 | newfilename = ostrcat(newfilename, ".epg", 1, 0); |
---|
866 | } |
---|
867 | |
---|
868 | return newfilename; |
---|
869 | } |
---|
870 | |
---|
871 | char* convert_timesec(int sec) |
---|
872 | { |
---|
873 | int hour = 0, min = 0, seconds = 0; |
---|
874 | char* buf = NULL; |
---|
875 | |
---|
876 | buf = malloc(9); |
---|
877 | if(buf == NULL) |
---|
878 | { |
---|
879 | err("no mem"); |
---|
880 | return NULL; |
---|
881 | } |
---|
882 | |
---|
883 | seconds = sec % 60; |
---|
884 | min = (sec / 60) % 60; |
---|
885 | hour = sec / 3600; |
---|
886 | |
---|
887 | if(seconds < 0) seconds = 0; |
---|
888 | if(min < 0) min = 0; |
---|
889 | if(hour < 0) hour = 0; |
---|
890 | |
---|
891 | snprintf(buf, 9, "%02d:%02d:%02d", hour, min, seconds); |
---|
892 | |
---|
893 | return buf; |
---|
894 | } |
---|
895 | |
---|
896 | int checkdate() |
---|
897 | { |
---|
898 | time_t dvbtime = 0; |
---|
899 | |
---|
900 | if(time(NULL) < 1072224000 || status.timeupdatecount > 3600) // 01.01.2004 |
---|
901 | { |
---|
902 | if(dvbgetdate(&dvbtime, 10000000) == 0) //10 sek |
---|
903 | { |
---|
904 | setsystime(&dvbtime); |
---|
905 | status.timeupdatecount = 0; |
---|
906 | return 0; |
---|
907 | } |
---|
908 | return 1; |
---|
909 | } |
---|
910 | return 0; |
---|
911 | } |
---|
912 | |
---|
913 | void closeonexec(fd) |
---|
914 | { |
---|
915 | if(fd > -1) |
---|
916 | fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
---|
917 | } |
---|
918 | |
---|
919 | void starthttpd(flag) |
---|
920 | { |
---|
921 | if(flag == 1) |
---|
922 | { |
---|
923 | if(getconfigint("httpdstart", NULL) == 1 && status.httpthread == NULL) |
---|
924 | { |
---|
925 | status.httpthread = addtimer(&httpdthreadfunc, START, 10000, -1, NULL, NULL, NULL); |
---|
926 | } |
---|
927 | } |
---|
928 | else if(status.httpthread != NULL) |
---|
929 | { |
---|
930 | status.httpthread->aktion = STOP; |
---|
931 | status.httpthread = NULL; |
---|
932 | } |
---|
933 | } |
---|
934 | |
---|
935 | int checkbox(char* box) |
---|
936 | { |
---|
937 | char* boxversion = NULL; |
---|
938 | int ret = 0; |
---|
939 | |
---|
940 | if(status.boxtype == NULL) |
---|
941 | { |
---|
942 | if(isfile("/etc/model") == 0) return 0; |
---|
943 | boxversion = string_toupper(readsys("/etc/model", 1)); |
---|
944 | } |
---|
945 | else |
---|
946 | boxversion = status.boxtype; |
---|
947 | |
---|
948 | if(ostrcmp(boxversion, box) == 0) |
---|
949 | { |
---|
950 | status.boxtype = boxversion; |
---|
951 | ret = 1; |
---|
952 | } |
---|
953 | |
---|
954 | box = ostrcat(box, "\n", 0, 0); |
---|
955 | if(ostrcmp(boxversion, box) == 0) |
---|
956 | { |
---|
957 | status.boxtype = boxversion; |
---|
958 | ret = 1; |
---|
959 | } |
---|
960 | |
---|
961 | if(status.boxtype == NULL) |
---|
962 | free(boxversion); boxversion = NULL; |
---|
963 | free(box); box = NULL; |
---|
964 | |
---|
965 | return ret; |
---|
966 | } |
---|
967 | |
---|
968 | int setoverclockfreq(int mode) |
---|
969 | { |
---|
970 | // mode 0 = Set Standby Freq |
---|
971 | // mode 1 = Set Freq |
---|
972 | |
---|
973 | if(ostrcmp(getownconfig("standby_overclock"), "0") == 0) |
---|
974 | return 1; |
---|
975 | |
---|
976 | if(isfile("/proc/cpu_frequ/pll0_ndiv_mdiv") == 0) |
---|
977 | return 1; |
---|
978 | |
---|
979 | char* tmpstr = NULL; |
---|
980 | |
---|
981 | if(mode == 0) |
---|
982 | tmpstr = getownconfig("standby_freq"); |
---|
983 | else |
---|
984 | tmpstr = getownconfig("pll0_ndiv_mdiv"); |
---|
985 | |
---|
986 | return writesys("/proc/cpu_frequ/pll0_ndiv_mdiv", tmpstr, 1); |
---|
987 | } |
---|
988 | |
---|
989 | int setsaturation(int value) |
---|
990 | { |
---|
991 | debug(1000, "in"); |
---|
992 | char* saturationdev; |
---|
993 | |
---|
994 | saturationdev = getconfig("saturationdev", NULL); |
---|
995 | |
---|
996 | if(saturationdev != NULL) |
---|
997 | { |
---|
998 | debug(100, "set %s to %d", saturationdev, value); |
---|
999 | return writesysint(saturationdev, value, 1); |
---|
1000 | } |
---|
1001 | |
---|
1002 | debug(1000, "out"); |
---|
1003 | return 0; |
---|
1004 | } |
---|
1005 | |
---|
1006 | int setbrightness(int value) |
---|
1007 | { |
---|
1008 | debug(1000, "in"); |
---|
1009 | char* brightnessdev; |
---|
1010 | |
---|
1011 | brightnessdev = getconfig("brightnessdev", NULL); |
---|
1012 | |
---|
1013 | if(brightnessdev != NULL) |
---|
1014 | { |
---|
1015 | debug(100, "set %s to %d", brightnessdev, value); |
---|
1016 | return writesysint(brightnessdev, value, 1); |
---|
1017 | } |
---|
1018 | |
---|
1019 | debug(1000, "out"); |
---|
1020 | return 0; |
---|
1021 | } |
---|
1022 | |
---|
1023 | int setcontrast(int value) |
---|
1024 | { |
---|
1025 | debug(1000, "in"); |
---|
1026 | char* contrastdev; |
---|
1027 | |
---|
1028 | contrastdev = getconfig("contrastdev", NULL); |
---|
1029 | |
---|
1030 | if(contrastdev != NULL) |
---|
1031 | { |
---|
1032 | debug(100, "set %s to %d", contrastdev, value); |
---|
1033 | return writesysint(contrastdev, value, 1); |
---|
1034 | } |
---|
1035 | |
---|
1036 | debug(1000, "out"); |
---|
1037 | return 0; |
---|
1038 | } |
---|
1039 | |
---|
1040 | int settint(int value) |
---|
1041 | { |
---|
1042 | debug(1000, "in"); |
---|
1043 | char* tintdev; |
---|
1044 | |
---|
1045 | tintdev = getconfig("tintdev", NULL); |
---|
1046 | |
---|
1047 | if(tintdev != NULL) |
---|
1048 | { |
---|
1049 | debug(100, "set %s to %d", tintdev, value); |
---|
1050 | return writesysint(tintdev, value, 1); |
---|
1051 | } |
---|
1052 | |
---|
1053 | debug(1000, "out"); |
---|
1054 | return 0; |
---|
1055 | } |
---|
1056 | |
---|
1057 | int zip(char* inbuf, int inlen, char** outbuf, int* outlen, int level) |
---|
1058 | { |
---|
1059 | int ret = 0; |
---|
1060 | z_stream stream; |
---|
1061 | |
---|
1062 | if(inlen > MINMALLOC) |
---|
1063 | return 1; |
---|
1064 | |
---|
1065 | stream.zalloc = Z_NULL; |
---|
1066 | stream.zfree = Z_NULL; |
---|
1067 | stream.opaque = Z_NULL; |
---|
1068 | |
---|
1069 | ret = deflateInit(&stream, level); |
---|
1070 | if(ret != Z_OK) |
---|
1071 | return 1; |
---|
1072 | |
---|
1073 | *outbuf = malloc(inlen); |
---|
1074 | if(*outbuf == NULL) |
---|
1075 | { |
---|
1076 | err("no mem"); |
---|
1077 | (void)deflateEnd(&stream); |
---|
1078 | return 1; |
---|
1079 | } |
---|
1080 | |
---|
1081 | stream.avail_in = inlen; |
---|
1082 | stream.next_in = (void*)inbuf; |
---|
1083 | |
---|
1084 | do |
---|
1085 | { |
---|
1086 | stream.avail_out = inlen; |
---|
1087 | stream.next_out = (void*)*outbuf; |
---|
1088 | |
---|
1089 | ret = deflate(&stream, Z_FINISH); |
---|
1090 | if(ret == Z_STREAM_ERROR) |
---|
1091 | { |
---|
1092 | free(*outbuf); *outbuf = NULL; |
---|
1093 | (void)deflateEnd(&stream); |
---|
1094 | return 1; |
---|
1095 | } |
---|
1096 | |
---|
1097 | } |
---|
1098 | while(stream.avail_out == 0); |
---|
1099 | *outlen = inlen - stream.avail_out; |
---|
1100 | *outbuf = realloc(*outbuf, *outlen); |
---|
1101 | |
---|
1102 | (void)deflateEnd(&stream); |
---|
1103 | return 0; |
---|
1104 | } |
---|
1105 | |
---|
1106 | int unzip(char* inbuf, int inlen, char** outbuf, int* outlen) |
---|
1107 | { |
---|
1108 | int ret = 0; |
---|
1109 | z_stream stream; |
---|
1110 | |
---|
1111 | stream.zalloc = Z_NULL; |
---|
1112 | stream.zfree = Z_NULL; |
---|
1113 | stream.opaque = Z_NULL; |
---|
1114 | stream.avail_in = 0; |
---|
1115 | stream.next_in = Z_NULL; |
---|
1116 | |
---|
1117 | ret = inflateInit(&stream); |
---|
1118 | if(ret != Z_OK) |
---|
1119 | return 1; |
---|
1120 | |
---|
1121 | *outbuf = malloc(MINMALLOC); |
---|
1122 | if(*outbuf == NULL) |
---|
1123 | { |
---|
1124 | err("no mem"); |
---|
1125 | (void)inflateEnd(&stream); |
---|
1126 | return 1; |
---|
1127 | } |
---|
1128 | |
---|
1129 | stream.avail_in = inlen; |
---|
1130 | stream.next_in = (void*)inbuf; |
---|
1131 | |
---|
1132 | do |
---|
1133 | { |
---|
1134 | stream.avail_out = MINMALLOC; |
---|
1135 | stream.next_out = (void*)*outbuf; |
---|
1136 | |
---|
1137 | ret = inflate(&stream, Z_NO_FLUSH); |
---|
1138 | if(ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) |
---|
1139 | { |
---|
1140 | free(*outbuf); *outbuf = NULL; |
---|
1141 | (void)inflateEnd(&stream); |
---|
1142 | return 1; |
---|
1143 | } |
---|
1144 | |
---|
1145 | } |
---|
1146 | while(stream.avail_out == 0); |
---|
1147 | *outlen = MINMALLOC - stream.avail_out; |
---|
1148 | *outbuf = realloc(*outbuf, *outlen); |
---|
1149 | |
---|
1150 | (void)inflateEnd(&stream); |
---|
1151 | return 0; |
---|
1152 | } |
---|
1153 | |
---|
1154 | void endianswapshort(unsigned short* value) |
---|
1155 | { |
---|
1156 | *value = (*value >> 8) | (*value << 8); |
---|
1157 | } |
---|
1158 | |
---|
1159 | int rcnumber(int rcret) |
---|
1160 | { |
---|
1161 | if(rcret == getrcconfigint("rc0", NULL) || |
---|
1162 | rcret == getrcconfigint("rc1", NULL) || |
---|
1163 | rcret == getrcconfigint("rc2", NULL) || |
---|
1164 | rcret == getrcconfigint("rc3", NULL) || |
---|
1165 | rcret == getrcconfigint("rc4", NULL) || |
---|
1166 | rcret == getrcconfigint("rc5", NULL) || |
---|
1167 | rcret == getrcconfigint("rc6", NULL) || |
---|
1168 | rcret == getrcconfigint("rc7", NULL) || |
---|
1169 | rcret == getrcconfigint("rc8", NULL) || |
---|
1170 | rcret == getrcconfigint("rc9", NULL)) |
---|
1171 | return rcret; |
---|
1172 | else |
---|
1173 | return -9999; |
---|
1174 | } |
---|
1175 | |
---|
1176 | long long getfreespace(char* dir) |
---|
1177 | { |
---|
1178 | struct statfs64 s; |
---|
1179 | long long freesize = 0; |
---|
1180 | |
---|
1181 | if(statfs64(dir, &s) >= 0) |
---|
1182 | { |
---|
1183 | freesize = s.f_bfree; |
---|
1184 | freesize *= s.f_bsize; |
---|
1185 | } |
---|
1186 | |
---|
1187 | return freesize; |
---|
1188 | } |
---|
1189 | |
---|
1190 | int checkbit(int value, int bitpos) |
---|
1191 | { |
---|
1192 | int ret = 0; |
---|
1193 | |
---|
1194 | ret = value & (1 << bitpos) ? 1: 0; |
---|
1195 | return ret; |
---|
1196 | } |
---|
1197 | |
---|
1198 | int tooglebit(int value, int bitpos) |
---|
1199 | { |
---|
1200 | value ^= 1 << bitpos; |
---|
1201 | return value; |
---|
1202 | } |
---|
1203 | |
---|
1204 | int clearbit(int value, int bitpos) |
---|
1205 | { |
---|
1206 | value &= ~(1 << bitpos); |
---|
1207 | return value; |
---|
1208 | } |
---|
1209 | |
---|
1210 | int setbit(int value, int bitpos) |
---|
1211 | { |
---|
1212 | value |= 1 << bitpos; |
---|
1213 | return value; |
---|
1214 | } |
---|
1215 | |
---|
1216 | int setsystime(time_t* newtime) |
---|
1217 | { |
---|
1218 | if (stime(newtime)) |
---|
1219 | { |
---|
1220 | err("can't set system time"); |
---|
1221 | return 1; |
---|
1222 | } |
---|
1223 | return 0; |
---|
1224 | } |
---|
1225 | |
---|
1226 | off64_t getfilesize(char* name) |
---|
1227 | { |
---|
1228 | struct stat64 sbuf; |
---|
1229 | |
---|
1230 | if(lstat64(name, &sbuf) == -1) |
---|
1231 | return 0; |
---|
1232 | |
---|
1233 | return sbuf.st_size; |
---|
1234 | } |
---|
1235 | |
---|
1236 | time_t getfiletime(char* name, int type) |
---|
1237 | { |
---|
1238 | struct stat64 sbuf; |
---|
1239 | |
---|
1240 | if(lstat64(name, &sbuf) == -1) |
---|
1241 | return 0; |
---|
1242 | |
---|
1243 | switch(type) |
---|
1244 | { |
---|
1245 | case 1: return sbuf.st_mtime; |
---|
1246 | case 2: return sbuf.st_ctime; |
---|
1247 | default: return sbuf.st_atime; |
---|
1248 | } |
---|
1249 | } |
---|
1250 | |
---|
1251 | int isfile(char* name) |
---|
1252 | { |
---|
1253 | struct stat64 sbuf; |
---|
1254 | |
---|
1255 | if(lstat64(name, &sbuf) == -1) |
---|
1256 | return 0; |
---|
1257 | |
---|
1258 | if(S_ISREG(sbuf.st_mode)) |
---|
1259 | return 1; |
---|
1260 | |
---|
1261 | return 0; |
---|
1262 | } |
---|
1263 | |
---|
1264 | int isdir(char* name) |
---|
1265 | { |
---|
1266 | struct stat64 sbuf; |
---|
1267 | char *rpath = NULL; |
---|
1268 | |
---|
1269 | if(lstat64(name, &sbuf) == -1) |
---|
1270 | return 0; |
---|
1271 | |
---|
1272 | if(S_ISDIR(sbuf.st_mode)) |
---|
1273 | return 1; |
---|
1274 | |
---|
1275 | if(S_ISLNK(sbuf.st_mode)) |
---|
1276 | { |
---|
1277 | rpath = realpath(name, NULL); |
---|
1278 | if(lstat64(rpath, &sbuf) == -1) |
---|
1279 | { |
---|
1280 | free(rpath); |
---|
1281 | return 0; |
---|
1282 | } |
---|
1283 | free(rpath); |
---|
1284 | if(S_ISDIR(sbuf.st_mode)) |
---|
1285 | return 1; |
---|
1286 | } |
---|
1287 | |
---|
1288 | return 0; |
---|
1289 | } |
---|
1290 | |
---|
1291 | char* getmaxsatstring() |
---|
1292 | { |
---|
1293 | char* tmpstr = NULL, *tmpnr = NULL; |
---|
1294 | int i; |
---|
1295 | |
---|
1296 | tmpstr = ostrcat(tmpstr, "1", 1, 0); |
---|
1297 | for(i = 2; i <= status.maxsat; i++) |
---|
1298 | { |
---|
1299 | tmpnr = oitoa(i); |
---|
1300 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
1301 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
1302 | } |
---|
1303 | return tmpstr; |
---|
1304 | } |
---|
1305 | |
---|
1306 | void ostrcatbig(char** value1, char* value2, int* maxlen, int* pos) |
---|
1307 | { |
---|
1308 | // debug(1000, "in"); |
---|
1309 | int len = 0; |
---|
1310 | |
---|
1311 | if(value2 == NULL) |
---|
1312 | { |
---|
1313 | debug(1000, "out -> NULL detect"); |
---|
1314 | return; |
---|
1315 | } |
---|
1316 | len = strlen(value2); |
---|
1317 | |
---|
1318 | if(len > MINMALLOC) |
---|
1319 | { |
---|
1320 | err("string to long"); |
---|
1321 | return; |
---|
1322 | } |
---|
1323 | |
---|
1324 | if(*value1 != NULL && maxlen == 0) |
---|
1325 | *maxlen = strlen(*value1); |
---|
1326 | |
---|
1327 | if(*value1 == NULL || *pos + len + 1 > *maxlen) |
---|
1328 | { |
---|
1329 | *maxlen = *maxlen + (MINMALLOC * 10); |
---|
1330 | *value1 = realloc(*value1, *maxlen); |
---|
1331 | if(*value1 == NULL) |
---|
1332 | { |
---|
1333 | err("no memory"); |
---|
1334 | return; |
---|
1335 | } |
---|
1336 | } |
---|
1337 | |
---|
1338 | memcpy(*value1 + *pos, value2, len + 1); |
---|
1339 | *pos = *pos + len; |
---|
1340 | |
---|
1341 | //debug(1000, "out"); |
---|
1342 | } |
---|
1343 | |
---|
1344 | char* ostrcat(char* value1, char* value2, int free1, int free2) |
---|
1345 | { |
---|
1346 | // debug(1000, "in"); |
---|
1347 | char* buf = NULL; |
---|
1348 | |
---|
1349 | if(value1 == NULL && value2 == NULL) return NULL; |
---|
1350 | |
---|
1351 | if(value2 == NULL) |
---|
1352 | { |
---|
1353 | value2 = malloc(1); |
---|
1354 | if(value2 == NULL) |
---|
1355 | { |
---|
1356 | err("no memory"); |
---|
1357 | return NULL; |
---|
1358 | } |
---|
1359 | free2 = 1; |
---|
1360 | value2[0] = '\0'; |
---|
1361 | } |
---|
1362 | |
---|
1363 | if(value1 == NULL) |
---|
1364 | { |
---|
1365 | value1 = malloc(1); |
---|
1366 | if(value1 == NULL) |
---|
1367 | { |
---|
1368 | err("no memory"); |
---|
1369 | return NULL; |
---|
1370 | } |
---|
1371 | free1 = 1; |
---|
1372 | value1[0] = '\0'; |
---|
1373 | } |
---|
1374 | |
---|
1375 | buf = malloc(strlen(value1) + strlen(value2) + 1); |
---|
1376 | if(buf == NULL) |
---|
1377 | { |
---|
1378 | err("no memory"); |
---|
1379 | return NULL; |
---|
1380 | } |
---|
1381 | |
---|
1382 | sprintf(buf, "%s%s", value1, value2); |
---|
1383 | |
---|
1384 | if(free1 == 1) {free(value1); value1 = NULL;} |
---|
1385 | if(free2 == 1) {free(value2); value2 = NULL;} |
---|
1386 | |
---|
1387 | //helpfull for memleak detect |
---|
1388 | //if(buf != NULL && strlen(buf) == 0x0b - 0x01) |
---|
1389 | // printf("******** memleak string (%s) (%p) ********\n", buf, buf); |
---|
1390 | |
---|
1391 | //debug(1000, "out"); |
---|
1392 | return buf; |
---|
1393 | } |
---|
1394 | |
---|
1395 | char* olutoa(unsigned long value) |
---|
1396 | { |
---|
1397 | debug(1000, "in"); |
---|
1398 | char *buf = NULL, *buf1 = NULL; |
---|
1399 | |
---|
1400 | buf = malloc(MINMALLOC); |
---|
1401 | if(buf == NULL) |
---|
1402 | { |
---|
1403 | err("no memory"); |
---|
1404 | return NULL; |
---|
1405 | } |
---|
1406 | |
---|
1407 | sprintf(buf, "%lu", value); |
---|
1408 | buf1 = ostrcat(buf, "", 1, 0); |
---|
1409 | |
---|
1410 | debug(1000, "out"); |
---|
1411 | return buf1; |
---|
1412 | } |
---|
1413 | |
---|
1414 | char* oitoa(int value) |
---|
1415 | { |
---|
1416 | debug(1000, "in"); |
---|
1417 | char *buf = NULL, *buf1 = NULL; |
---|
1418 | |
---|
1419 | buf = malloc(MINMALLOC); |
---|
1420 | if(buf == NULL) |
---|
1421 | { |
---|
1422 | err("no memory"); |
---|
1423 | return NULL; |
---|
1424 | } |
---|
1425 | |
---|
1426 | sprintf(buf, "%d", value); |
---|
1427 | buf1 = ostrcat(buf, "", 1, 0); |
---|
1428 | |
---|
1429 | debug(1000, "out"); |
---|
1430 | return buf1; |
---|
1431 | } |
---|
1432 | |
---|
1433 | char* oitoa64(off64_t value) |
---|
1434 | { |
---|
1435 | debug(1000, "in"); |
---|
1436 | char *buf = NULL, *buf1 = NULL; |
---|
1437 | |
---|
1438 | buf = malloc(MINMALLOC); |
---|
1439 | if(buf == NULL) |
---|
1440 | { |
---|
1441 | err("no memory"); |
---|
1442 | return NULL; |
---|
1443 | } |
---|
1444 | |
---|
1445 | sprintf(buf, "%lld", value); |
---|
1446 | buf1 = ostrcat(buf, "", 1, 0); |
---|
1447 | |
---|
1448 | debug(1000, "out"); |
---|
1449 | return buf1; |
---|
1450 | } |
---|
1451 | |
---|
1452 | char* oftoa64(double value, char* count) |
---|
1453 | { |
---|
1454 | debug(1000, "in"); |
---|
1455 | char *buf = NULL, *buf1 = NULL; |
---|
1456 | char* tmpstr = NULL; |
---|
1457 | |
---|
1458 | buf = malloc(MINMALLOC); |
---|
1459 | if(buf == NULL) |
---|
1460 | { |
---|
1461 | err("no memory"); |
---|
1462 | return NULL; |
---|
1463 | } |
---|
1464 | |
---|
1465 | tmpstr = ostrcat("%.", count, 0, 0); |
---|
1466 | tmpstr = ostrcat(tmpstr, "f", 1, 0); |
---|
1467 | |
---|
1468 | sprintf(buf, tmpstr, value); |
---|
1469 | buf1 = ostrcat(buf, "", 1, 0); |
---|
1470 | |
---|
1471 | free(tmpstr); |
---|
1472 | debug(1000, "out"); |
---|
1473 | return buf1; |
---|
1474 | } |
---|
1475 | |
---|
1476 | int ostrncmp(char* value1, char* value2, int count) |
---|
1477 | { |
---|
1478 | //debug(1000, "in"); |
---|
1479 | int ret = 1; |
---|
1480 | |
---|
1481 | if(value1 != NULL && value2 != NULL) |
---|
1482 | ret = strncmp(value1, value2, count); |
---|
1483 | |
---|
1484 | //debug(1000, "out"); |
---|
1485 | return ret; |
---|
1486 | } |
---|
1487 | |
---|
1488 | int ostrcmp(char* value1, char* value2) |
---|
1489 | { |
---|
1490 | // debug(1000, "in"); |
---|
1491 | int ret = 1; |
---|
1492 | |
---|
1493 | if(value1 != NULL && value2 != NULL) |
---|
1494 | ret = strcmp(value1, value2); |
---|
1495 | |
---|
1496 | // debug(1000, "out"); |
---|
1497 | return ret; |
---|
1498 | } |
---|
1499 | |
---|
1500 | char* createpath(char* dir, char* file) |
---|
1501 | { |
---|
1502 | debug(1000, "in"); |
---|
1503 | char *absdir = NULL; |
---|
1504 | char *pos = NULL; |
---|
1505 | char* tmpdir = NULL; |
---|
1506 | |
---|
1507 | if(dir == NULL || file == NULL) |
---|
1508 | { |
---|
1509 | debug(1000, "out -> NULL detect"); |
---|
1510 | return NULL; |
---|
1511 | } |
---|
1512 | |
---|
1513 | tmpdir = ostrcat(dir, "", 0, 0); |
---|
1514 | if(tmpdir == NULL) |
---|
1515 | { |
---|
1516 | debug(1000, "out -> NULL detect"); |
---|
1517 | return NULL; |
---|
1518 | } |
---|
1519 | |
---|
1520 | while((tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] != '.') || tmpdir[strlen(tmpdir) - 1] == '/') |
---|
1521 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
1522 | |
---|
1523 | while(tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] == '.') |
---|
1524 | { |
---|
1525 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
1526 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
1527 | if(tmpdir[strlen(tmpdir) - 1] == '/') |
---|
1528 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
1529 | pos = strrchr(tmpdir, '/'); |
---|
1530 | if(pos != NULL) |
---|
1531 | pos[0] = '\0'; |
---|
1532 | } |
---|
1533 | |
---|
1534 | absdir = malloc(strlen(tmpdir) + strlen(file) + 2); |
---|
1535 | if(absdir == NULL) |
---|
1536 | { |
---|
1537 | free(tmpdir); |
---|
1538 | err("no memory"); |
---|
1539 | return NULL; |
---|
1540 | } |
---|
1541 | |
---|
1542 | if(strlen(file) > 0 || strlen(tmpdir) == 0) |
---|
1543 | sprintf(absdir, "%s/%s", tmpdir, file); |
---|
1544 | else |
---|
1545 | sprintf(absdir, "%s", tmpdir); |
---|
1546 | |
---|
1547 | debug(1000, "out"); |
---|
1548 | free(tmpdir); |
---|
1549 | return absdir; |
---|
1550 | } |
---|
1551 | |
---|
1552 | int settimezone(char* zone) |
---|
1553 | { |
---|
1554 | debug(1000, "in"); |
---|
1555 | int ret = 0; |
---|
1556 | char* tmpzone = NULL, *zonepath = NULL; |
---|
1557 | |
---|
1558 | zonepath = getconfig("zonepath", NULL); |
---|
1559 | if(zonepath == NULL) |
---|
1560 | { |
---|
1561 | err("config zonepath not defined"); |
---|
1562 | return 1; |
---|
1563 | } |
---|
1564 | |
---|
1565 | tmpzone = createpath(zonepath, zone); |
---|
1566 | if(tmpzone == NULL) |
---|
1567 | return 1; |
---|
1568 | |
---|
1569 | setenv("TZ", zone, 1); |
---|
1570 | |
---|
1571 | ret = unlink(getconfig("localtimefile", NULL)); |
---|
1572 | if(ret != 0) |
---|
1573 | perr("unlink"); |
---|
1574 | ret = symlink(tmpzone, getconfig("localtimefile", NULL)); |
---|
1575 | if(ret != 0) |
---|
1576 | perr("link"); |
---|
1577 | |
---|
1578 | free(tmpzone); |
---|
1579 | debug(1000, "out"); |
---|
1580 | return ret; |
---|
1581 | } |
---|
1582 | |
---|
1583 | int delchar(char** text, int pos) |
---|
1584 | { |
---|
1585 | debug(1000, "in"); |
---|
1586 | char *tmptext = NULL; |
---|
1587 | int i, y = 0; |
---|
1588 | |
---|
1589 | if(*text == NULL) |
---|
1590 | { |
---|
1591 | debug(1000, "out -> NULL detect"); |
---|
1592 | return pos; |
---|
1593 | } |
---|
1594 | |
---|
1595 | tmptext = malloc(strlen(*text)); |
---|
1596 | if(tmptext == NULL) |
---|
1597 | { |
---|
1598 | err("no memory"); |
---|
1599 | return pos; |
---|
1600 | } |
---|
1601 | |
---|
1602 | for(i = 0; i < strlen(*text); i++) |
---|
1603 | { |
---|
1604 | if(i == pos - 1) |
---|
1605 | y++; |
---|
1606 | |
---|
1607 | tmptext[i] = (*text)[y]; |
---|
1608 | y++; |
---|
1609 | } |
---|
1610 | |
---|
1611 | tmptext[i] = '\0'; |
---|
1612 | if(pos >= strlen(tmptext)) pos = strlen(tmptext); |
---|
1613 | |
---|
1614 | free(*text); |
---|
1615 | *text = tmptext; |
---|
1616 | debug(1000, "out"); |
---|
1617 | return pos; |
---|
1618 | } |
---|
1619 | |
---|
1620 | |
---|
1621 | int insertchar(char** text, char zeichen, int pos) |
---|
1622 | { |
---|
1623 | debug(1000, "in"); |
---|
1624 | char *tmptext = NULL; |
---|
1625 | int i, y = 0; |
---|
1626 | |
---|
1627 | if(*text == NULL) |
---|
1628 | { |
---|
1629 | debug(1000, "out -> NULL detect"); |
---|
1630 | return pos; |
---|
1631 | } |
---|
1632 | |
---|
1633 | tmptext = malloc(strlen(*text) + 2); |
---|
1634 | if(tmptext == NULL) |
---|
1635 | { |
---|
1636 | err("no memory"); |
---|
1637 | return pos; |
---|
1638 | } |
---|
1639 | |
---|
1640 | if(strlen(*text) == 0) |
---|
1641 | { |
---|
1642 | tmptext[0] = zeichen; |
---|
1643 | i = 1; |
---|
1644 | pos = 0; |
---|
1645 | } |
---|
1646 | else |
---|
1647 | { |
---|
1648 | for(i = 0; i < strlen(*text) + 1; i++) |
---|
1649 | { |
---|
1650 | if(i == pos) |
---|
1651 | tmptext[i] = zeichen; |
---|
1652 | else |
---|
1653 | { |
---|
1654 | tmptext[i] = (*text)[y]; |
---|
1655 | y++; |
---|
1656 | } |
---|
1657 | } |
---|
1658 | } |
---|
1659 | tmptext[i] = '\0'; |
---|
1660 | |
---|
1661 | free(*text); |
---|
1662 | *text = tmptext; |
---|
1663 | debug(1000, "out"); |
---|
1664 | return pos + 1; |
---|
1665 | } |
---|
1666 | |
---|
1667 | void sighandler(int sig, struct sigcontext ctx) |
---|
1668 | { |
---|
1669 | debug(1000, "in"); |
---|
1670 | switch(sig) |
---|
1671 | { |
---|
1672 | case SIGUSR1: |
---|
1673 | { |
---|
1674 | //todo all configs |
---|
1675 | reloadconfig(status.configfile); |
---|
1676 | reloadconfig(getconfig("ownconfig", NULL)); |
---|
1677 | break; |
---|
1678 | } |
---|
1679 | case SIGSEGV: |
---|
1680 | case SIGBUS: |
---|
1681 | case SIGABRT: |
---|
1682 | { |
---|
1683 | #ifdef SIMULATE |
---|
1684 | //intel |
---|
1685 | debugstack((void *)ctx.eip, NULL); |
---|
1686 | err("got signal %d, fault address 0x%lx from 0x%lx", sig, ctx.cr2, ctx.eip); |
---|
1687 | #else |
---|
1688 | /* sh4 |
---|
1689 | unsigned long sc_regs[16]; |
---|
1690 | unsigned long sc_pc; //programm counter register |
---|
1691 | unsigned long sc_pr; //procedure register |
---|
1692 | unsigned long sc_sr; //status register |
---|
1693 | unsigned long sc_gbr; |
---|
1694 | unsigned long sc_mach; |
---|
1695 | unsigned long sc_macl; */ |
---|
1696 | |
---|
1697 | debugstack((void *)ctx.sc_pr, (void *)ctx.sc_pc); |
---|
1698 | err("got signal %d, programm counter reg: 0x%lx, procedure reg: 0x%lx", sig, ctx.sc_pc, ctx.sc_pr); |
---|
1699 | #endif |
---|
1700 | if(getconfigint("saverun", NULL) == 1 && status.longjumpbuf != NULL) |
---|
1701 | siglongjmp(status.longjumpbuf, 1); |
---|
1702 | else |
---|
1703 | exit(100); |
---|
1704 | break; |
---|
1705 | } |
---|
1706 | } |
---|
1707 | debug(1000, "out"); |
---|
1708 | } |
---|
1709 | |
---|
1710 | void calctext(char* buf, char* buf1, unsigned int* linecount, unsigned int* pagecount, unsigned int* poscount, int pagelen, int page) |
---|
1711 | { |
---|
1712 | debug(1000, "in"); |
---|
1713 | unsigned int tmpposcount = 0; |
---|
1714 | |
---|
1715 | *poscount = 0; |
---|
1716 | *linecount = 1; |
---|
1717 | *pagecount = 1; |
---|
1718 | |
---|
1719 | page--; |
---|
1720 | if(page < 0) page = 0; |
---|
1721 | |
---|
1722 | if(buf != NULL) |
---|
1723 | { |
---|
1724 | while(*buf != '\0') |
---|
1725 | { |
---|
1726 | if(*buf == '\n') |
---|
1727 | { |
---|
1728 | if(*(buf + 1) == '\0') break; |
---|
1729 | (*linecount)++; |
---|
1730 | |
---|
1731 | if(*linecount - 1 == pagelen * page) |
---|
1732 | *poscount = tmpposcount + 1; |
---|
1733 | } |
---|
1734 | buf++; |
---|
1735 | tmpposcount++; |
---|
1736 | } |
---|
1737 | } |
---|
1738 | |
---|
1739 | if(buf1 != NULL) |
---|
1740 | { |
---|
1741 | while(*buf1 != '\0') |
---|
1742 | { |
---|
1743 | if(*buf1 == '\n') |
---|
1744 | { |
---|
1745 | if(*(buf1 + 1) == '\0') break; |
---|
1746 | (*linecount)++; |
---|
1747 | |
---|
1748 | if(*linecount - 1 == pagelen * page) |
---|
1749 | *poscount = tmpposcount + 1; |
---|
1750 | } |
---|
1751 | buf1++; |
---|
1752 | tmpposcount++; |
---|
1753 | } |
---|
1754 | } |
---|
1755 | |
---|
1756 | if(pagelen > 0) |
---|
1757 | *pagecount = (int)ceil(((float)*linecount / pagelen)); |
---|
1758 | |
---|
1759 | debug(1000, "out"); |
---|
1760 | } |
---|
1761 | |
---|
1762 | int initlocale(char *localepath) |
---|
1763 | { |
---|
1764 | debug(1000, "in"); |
---|
1765 | setlocale(LC_ALL, ""); |
---|
1766 | if(bindtextdomain(PROGNAME, localepath) == NULL) |
---|
1767 | { |
---|
1768 | err("set bindtextdomain"); |
---|
1769 | return 1; |
---|
1770 | } |
---|
1771 | if(textdomain(PROGNAME) == NULL) |
---|
1772 | { |
---|
1773 | err("set textdomain"); |
---|
1774 | return 1; |
---|
1775 | } |
---|
1776 | debug(1000, "out"); |
---|
1777 | return 0; |
---|
1778 | } |
---|
1779 | |
---|
1780 | //for langage you must |
---|
1781 | //mkdir /usr/lib/locale |
---|
1782 | //ln -s %titanpath%/po /usr/lib/locale/po |
---|
1783 | //copy SYS_LC_MESSAGES from other language into LC_MESSAGE |
---|
1784 | int setlang(char *lang) |
---|
1785 | { |
---|
1786 | debug(1000, "in"); |
---|
1787 | char *ret; |
---|
1788 | |
---|
1789 | setenv("LANG", lang, 1); |
---|
1790 | setenv("LANGUAGE", lang, 1); |
---|
1791 | ret = setlocale(LC_MESSAGES, lang); |
---|
1792 | if(ret == NULL) |
---|
1793 | { |
---|
1794 | err("can't set LC_MESSAGES to %s", lang); |
---|
1795 | return 1; |
---|
1796 | } |
---|
1797 | debug(1000, "out"); |
---|
1798 | return 0; |
---|
1799 | } |
---|
1800 | |
---|
1801 | unsigned long readsysul(const char *filename, int line) |
---|
1802 | { |
---|
1803 | debug(1000, "in"); |
---|
1804 | int i = 0; |
---|
1805 | unsigned long ret = 0; |
---|
1806 | FILE *fd = NULL; |
---|
1807 | char *fileline = NULL; |
---|
1808 | char *buf1 = NULL; |
---|
1809 | |
---|
1810 | fileline = malloc(MINMALLOC); |
---|
1811 | if(fileline == NULL) |
---|
1812 | { |
---|
1813 | err("no memory"); |
---|
1814 | return 0; |
---|
1815 | } |
---|
1816 | |
---|
1817 | fd = fopen(filename, "r"); |
---|
1818 | if(fd == NULL) |
---|
1819 | { |
---|
1820 | perr("can't open %s", filename); |
---|
1821 | free(fileline); |
---|
1822 | return 0; |
---|
1823 | } |
---|
1824 | |
---|
1825 | for(i = 0; i < line; i++) |
---|
1826 | { |
---|
1827 | memset(fileline, 0, MINMALLOC); |
---|
1828 | fgets(fileline, MINMALLOC, fd); |
---|
1829 | } |
---|
1830 | |
---|
1831 | if(fileline[strlen(fileline) - 1] == '\n') |
---|
1832 | fileline[strlen(fileline) - 1] = '\0'; |
---|
1833 | buf1 = ostrcat(fileline, "", 1, 0); |
---|
1834 | |
---|
1835 | fclose(fd); |
---|
1836 | |
---|
1837 | if(buf1 != NULL) |
---|
1838 | { |
---|
1839 | ret = strtoul(buf1, NULL, 10); |
---|
1840 | free(buf1); buf1 = NULL; |
---|
1841 | } |
---|
1842 | |
---|
1843 | debug(1000, "out"); |
---|
1844 | return ret; |
---|
1845 | } |
---|
1846 | |
---|
1847 | |
---|
1848 | char* readsys(const char *filename, int line) |
---|
1849 | { |
---|
1850 | debug(1000, "in"); |
---|
1851 | int i = 0; |
---|
1852 | FILE *fd = NULL; |
---|
1853 | char *fileline = NULL; |
---|
1854 | char *buf1 = NULL; |
---|
1855 | |
---|
1856 | fileline = malloc(MINMALLOC); |
---|
1857 | if(fileline == NULL) |
---|
1858 | { |
---|
1859 | err("no memory"); |
---|
1860 | return NULL; |
---|
1861 | } |
---|
1862 | |
---|
1863 | fd = fopen(filename, "r"); |
---|
1864 | if(fd == NULL) |
---|
1865 | { |
---|
1866 | perr("can't open %s", filename); |
---|
1867 | free(fileline); |
---|
1868 | return NULL; |
---|
1869 | } |
---|
1870 | |
---|
1871 | for(i = 0; i < line; i++) |
---|
1872 | { |
---|
1873 | memset(fileline, 0, MINMALLOC); |
---|
1874 | fgets(fileline, MINMALLOC, fd); |
---|
1875 | } |
---|
1876 | |
---|
1877 | if(fileline[strlen(fileline) - 1] == '\n') |
---|
1878 | fileline[strlen(fileline) - 1] = '\0'; |
---|
1879 | buf1 = ostrcat(fileline, "", 1, 0); |
---|
1880 | |
---|
1881 | fclose(fd); |
---|
1882 | |
---|
1883 | debug(1000, "out"); |
---|
1884 | return buf1; |
---|
1885 | } |
---|
1886 | |
---|
1887 | int writesys(const char *filename, char *value, int flag) |
---|
1888 | { |
---|
1889 | debug(1000, "in"); |
---|
1890 | FILE *fd = NULL; |
---|
1891 | char* tmpstr = NULL; |
---|
1892 | int ret; |
---|
1893 | |
---|
1894 | if(value == NULL) |
---|
1895 | { |
---|
1896 | debug(1000, "out -> NULL detect"); |
---|
1897 | return 1; |
---|
1898 | } |
---|
1899 | |
---|
1900 | fd = fopen(filename, "w"); |
---|
1901 | if(fd == NULL) |
---|
1902 | { |
---|
1903 | perr("can't open %s", filename); |
---|
1904 | return 1; |
---|
1905 | } |
---|
1906 | |
---|
1907 | if(flag == 1) |
---|
1908 | tmpstr = ostrcat(value, "\n", 0, 0); |
---|
1909 | else |
---|
1910 | tmpstr = ostrcat(value, "", 0, 0); |
---|
1911 | |
---|
1912 | ret = fwrite(tmpstr, strlen(tmpstr), 1, fd); |
---|
1913 | if(ret != 1) |
---|
1914 | { |
---|
1915 | perr("writting to %s", filename); |
---|
1916 | free(tmpstr); |
---|
1917 | fclose(fd); |
---|
1918 | return 1; |
---|
1919 | } |
---|
1920 | |
---|
1921 | free(tmpstr); |
---|
1922 | fclose(fd); |
---|
1923 | debug(1000, "out"); |
---|
1924 | return 0; |
---|
1925 | } |
---|
1926 | |
---|
1927 | int writesysint(const char *filename, int value, int flag) |
---|
1928 | { |
---|
1929 | debug(1000, "in"); |
---|
1930 | char* tmpstr = NULL; |
---|
1931 | int ret = 0; |
---|
1932 | |
---|
1933 | tmpstr = oitoa(value); |
---|
1934 | ret = writesys(filename, tmpstr, flag); |
---|
1935 | |
---|
1936 | free(tmpstr); |
---|
1937 | debug(1000, "out"); |
---|
1938 | return ret; |
---|
1939 | } |
---|
1940 | |
---|
1941 | char* convertspacetolf(char* value) |
---|
1942 | { |
---|
1943 | debug(1000, "in"); |
---|
1944 | int i = 0; |
---|
1945 | |
---|
1946 | while(value[i] != '\0') |
---|
1947 | { |
---|
1948 | if(value[i] == ' ') |
---|
1949 | value[i] = '\n'; |
---|
1950 | i++; |
---|
1951 | } |
---|
1952 | |
---|
1953 | debug(1000, "out"); |
---|
1954 | return value; |
---|
1955 | } |
---|
1956 | |
---|
1957 | char* getcolorformatchoices() |
---|
1958 | { |
---|
1959 | debug(1000, "in"); |
---|
1960 | char *colorformatchoicesdev = NULL; |
---|
1961 | char *value = NULL; |
---|
1962 | |
---|
1963 | colorformatchoicesdev = getconfig("colorformatchoicesdev", NULL); |
---|
1964 | |
---|
1965 | if(colorformatchoicesdev == NULL) |
---|
1966 | { |
---|
1967 | debug(1000, "out -> NULL detect"); |
---|
1968 | return NULL; |
---|
1969 | } |
---|
1970 | |
---|
1971 | value = readsys(colorformatchoicesdev, 1); |
---|
1972 | if(value == NULL) |
---|
1973 | { |
---|
1974 | debug(1000, "out -> NULL detect"); |
---|
1975 | return NULL; |
---|
1976 | } |
---|
1977 | |
---|
1978 | value = convertspacetolf(value); |
---|
1979 | |
---|
1980 | debug(1000, "out"); |
---|
1981 | return value; |
---|
1982 | } |
---|
1983 | |
---|
1984 | char* getaudiosourcechoices() |
---|
1985 | { |
---|
1986 | debug(1000, "in"); |
---|
1987 | char *audiosourcechoicesdev = NULL; |
---|
1988 | char *value = NULL; |
---|
1989 | |
---|
1990 | audiosourcechoicesdev = getconfig("audiosourcechoicesdev", NULL); |
---|
1991 | |
---|
1992 | if(audiosourcechoicesdev == NULL) |
---|
1993 | { |
---|
1994 | debug(1000, "out -> NULL detect"); |
---|
1995 | return NULL; |
---|
1996 | } |
---|
1997 | |
---|
1998 | value = readsys(audiosourcechoicesdev, 1); |
---|
1999 | if(value == NULL) |
---|
2000 | { |
---|
2001 | debug(1000, "out -> NULL detect"); |
---|
2002 | return NULL; |
---|
2003 | } |
---|
2004 | |
---|
2005 | value = convertspacetolf(value); |
---|
2006 | |
---|
2007 | debug(1000, "out"); |
---|
2008 | return value; |
---|
2009 | } |
---|
2010 | |
---|
2011 | char* getac3choices() |
---|
2012 | { |
---|
2013 | debug(1000, "in"); |
---|
2014 | char *ac3choicesdev = NULL; |
---|
2015 | char *value = NULL; |
---|
2016 | |
---|
2017 | ac3choicesdev = getconfig("ac3choicesdev", NULL); |
---|
2018 | |
---|
2019 | if(ac3choicesdev == NULL) |
---|
2020 | { |
---|
2021 | debug(1000, "out -> NULL detect"); |
---|
2022 | return NULL; |
---|
2023 | } |
---|
2024 | |
---|
2025 | value = readsys(ac3choicesdev, 1); |
---|
2026 | if(value == NULL) |
---|
2027 | { |
---|
2028 | debug(1000, "out -> NULL detect"); |
---|
2029 | return NULL; |
---|
2030 | } |
---|
2031 | |
---|
2032 | value = convertspacetolf(value); |
---|
2033 | |
---|
2034 | debug(1000, "out"); |
---|
2035 | return value; |
---|
2036 | } |
---|
2037 | |
---|
2038 | int setciclock(int slotnr, char* value) |
---|
2039 | { |
---|
2040 | debug(1000, "in"); |
---|
2041 | char* ciclockdev = NULL, *tmpstr = NULL; |
---|
2042 | int ret = 0; |
---|
2043 | |
---|
2044 | ciclockdev = getconfig("ciclockdev", NULL); |
---|
2045 | |
---|
2046 | if(ciclockdev != NULL && value != NULL) |
---|
2047 | { |
---|
2048 | tmpstr = malloc(MINMALLOC); |
---|
2049 | if(tmpstr == NULL) |
---|
2050 | { |
---|
2051 | err("no mem"); |
---|
2052 | return 1; |
---|
2053 | } |
---|
2054 | |
---|
2055 | snprintf(tmpstr, MINMALLOC, ciclockdev, slotnr); |
---|
2056 | debug(100, "set %s to %s", tmpstr, value); |
---|
2057 | ret = writesys(tmpstr, value, 0); |
---|
2058 | |
---|
2059 | free(tmpstr); tmpstr = NULL; |
---|
2060 | return ret; |
---|
2061 | } |
---|
2062 | |
---|
2063 | debug(1000, "out"); |
---|
2064 | return 0; |
---|
2065 | } |
---|
2066 | |
---|
2067 | int setciinput(int slotnr, char* value) |
---|
2068 | { |
---|
2069 | debug(1000, "in"); |
---|
2070 | char* ciinputdev = NULL, *tmpstr = NULL; |
---|
2071 | int ret = 0; |
---|
2072 | |
---|
2073 | ciinputdev = getconfig("ciinputdev", NULL); |
---|
2074 | |
---|
2075 | if(ciinputdev != NULL && value != NULL) |
---|
2076 | { |
---|
2077 | tmpstr = malloc(MINMALLOC); |
---|
2078 | if(tmpstr == NULL) |
---|
2079 | { |
---|
2080 | err("no mem"); |
---|
2081 | return 1; |
---|
2082 | } |
---|
2083 | |
---|
2084 | snprintf(tmpstr, MINMALLOC, ciinputdev, slotnr); |
---|
2085 | debug(100, "set %s to %s", tmpstr, value); |
---|
2086 | ret = writesys(tmpstr, value, 0); |
---|
2087 | |
---|
2088 | free(tmpstr); tmpstr = NULL; |
---|
2089 | return ret; |
---|
2090 | } |
---|
2091 | |
---|
2092 | debug(1000, "out"); |
---|
2093 | return 0; |
---|
2094 | } |
---|
2095 | |
---|
2096 | int setcisource(int tunernr, char* value) |
---|
2097 | { |
---|
2098 | debug(1000, "in"); |
---|
2099 | char* cisourcedev = NULL, *tmpstr = NULL; |
---|
2100 | int ret = 0; |
---|
2101 | |
---|
2102 | cisourcedev = getconfig("cisourcedev", NULL); |
---|
2103 | |
---|
2104 | if(cisourcedev != NULL && value != NULL) |
---|
2105 | { |
---|
2106 | tmpstr = malloc(MINMALLOC); |
---|
2107 | if(tmpstr == NULL) |
---|
2108 | { |
---|
2109 | err("no mem"); |
---|
2110 | return 1; |
---|
2111 | } |
---|
2112 | |
---|
2113 | snprintf(tmpstr, MINMALLOC, cisourcedev, tunernr); |
---|
2114 | debug(100, "set %s to %s", tmpstr, value); |
---|
2115 | ret = writesys(tmpstr, value, 0); |
---|
2116 | |
---|
2117 | free(tmpstr); tmpstr = NULL; |
---|
2118 | return ret; |
---|
2119 | } |
---|
2120 | |
---|
2121 | debug(1000, "out"); |
---|
2122 | return 0; |
---|
2123 | } |
---|
2124 | |
---|
2125 | int setinput(char* value) |
---|
2126 | { |
---|
2127 | debug(1000, "in"); |
---|
2128 | char* inputdev = NULL; |
---|
2129 | int ret = 0; |
---|
2130 | |
---|
2131 | inputdev = getconfig("inputdev", NULL); |
---|
2132 | |
---|
2133 | if(inputdev != NULL && value != NULL) |
---|
2134 | { |
---|
2135 | debug(100, "set %s to %s", inputdev, value); |
---|
2136 | ret = writesys(inputdev, value, 0); |
---|
2137 | return ret; |
---|
2138 | } |
---|
2139 | |
---|
2140 | debug(1000, "out"); |
---|
2141 | return 0; |
---|
2142 | } |
---|
2143 | |
---|
2144 | char* getinput() |
---|
2145 | { |
---|
2146 | debug(1000, "in"); |
---|
2147 | char *inputdev = NULL; |
---|
2148 | char *value = NULL; |
---|
2149 | |
---|
2150 | inputdev = getconfig("inputdev", NULL); |
---|
2151 | |
---|
2152 | if(inputdev == NULL) |
---|
2153 | { |
---|
2154 | debug(1000, "out -> NULL detect"); |
---|
2155 | return NULL; |
---|
2156 | } |
---|
2157 | |
---|
2158 | value = readsys(inputdev, 1); |
---|
2159 | if(value == NULL) |
---|
2160 | { |
---|
2161 | debug(1000, "out -> NULL detect"); |
---|
2162 | return NULL; |
---|
2163 | } |
---|
2164 | |
---|
2165 | debug(1000, "out"); |
---|
2166 | return value; |
---|
2167 | } |
---|
2168 | |
---|
2169 | int setac3(char* value) |
---|
2170 | { |
---|
2171 | debug(1000, "in"); |
---|
2172 | char* ac3dev = NULL; |
---|
2173 | int ret = 0; |
---|
2174 | |
---|
2175 | ac3dev = getconfig("ac3dev", NULL); |
---|
2176 | |
---|
2177 | if(ac3dev != NULL && value != NULL) |
---|
2178 | { |
---|
2179 | debug(100, "set %s to %s", ac3dev, value); |
---|
2180 | ret = writesys(ac3dev, value, 0); |
---|
2181 | if(ret == 0) addconfig("av_ac3mode", value); |
---|
2182 | return ret; |
---|
2183 | } |
---|
2184 | |
---|
2185 | debug(1000, "out"); |
---|
2186 | return 0; |
---|
2187 | } |
---|
2188 | |
---|
2189 | char* getac3() |
---|
2190 | { |
---|
2191 | debug(1000, "in"); |
---|
2192 | char *ac3dev = NULL; |
---|
2193 | char *value = NULL; |
---|
2194 | |
---|
2195 | ac3dev = getconfig("ac3dev", NULL); |
---|
2196 | |
---|
2197 | if(ac3dev == NULL) |
---|
2198 | { |
---|
2199 | debug(1000, "out -> NULL detect"); |
---|
2200 | return NULL; |
---|
2201 | } |
---|
2202 | |
---|
2203 | value = readsys(ac3dev, 1); |
---|
2204 | if(value == NULL) |
---|
2205 | { |
---|
2206 | debug(1000, "out -> NULL detect"); |
---|
2207 | return NULL; |
---|
2208 | } |
---|
2209 | |
---|
2210 | debug(1000, "out"); |
---|
2211 | return value; |
---|
2212 | } |
---|
2213 | |
---|
2214 | char* getpolicychoices() |
---|
2215 | { |
---|
2216 | debug(1000, "in"); |
---|
2217 | char *policychoicesdev = NULL; |
---|
2218 | char *value = NULL; |
---|
2219 | |
---|
2220 | policychoicesdev = getconfig("policychoicesdev", NULL); |
---|
2221 | |
---|
2222 | if(policychoicesdev == NULL) |
---|
2223 | { |
---|
2224 | debug(1000, "out -> NULL detect"); |
---|
2225 | return NULL; |
---|
2226 | } |
---|
2227 | |
---|
2228 | value = readsys(policychoicesdev, 1); |
---|
2229 | if(value == NULL) |
---|
2230 | { |
---|
2231 | debug(1000, "out -> NULL detect"); |
---|
2232 | return NULL; |
---|
2233 | } |
---|
2234 | |
---|
2235 | value = convertspacetolf(value); |
---|
2236 | |
---|
2237 | debug(1000, "out"); |
---|
2238 | return value; |
---|
2239 | } |
---|
2240 | |
---|
2241 | char* getpolicy() |
---|
2242 | { |
---|
2243 | debug(1000, "in"); |
---|
2244 | char *policydev = NULL; |
---|
2245 | char *value = NULL; |
---|
2246 | |
---|
2247 | policydev = getconfig("policydev", NULL); |
---|
2248 | |
---|
2249 | if(policydev == NULL) |
---|
2250 | { |
---|
2251 | debug(1000, "out -> NULL detect"); |
---|
2252 | return NULL; |
---|
2253 | } |
---|
2254 | |
---|
2255 | value = readsys(policydev, 1); |
---|
2256 | if(value == NULL) |
---|
2257 | { |
---|
2258 | debug(1000, "out -> NULL detect"); |
---|
2259 | return NULL; |
---|
2260 | } |
---|
2261 | |
---|
2262 | debug(1000, "out"); |
---|
2263 | return value; |
---|
2264 | } |
---|
2265 | |
---|
2266 | int setpolicy(char* value) |
---|
2267 | { |
---|
2268 | debug(1000, "in"); |
---|
2269 | char* policydev; |
---|
2270 | int ret = 0; |
---|
2271 | |
---|
2272 | policydev = getconfig("policydev", NULL); |
---|
2273 | |
---|
2274 | if(policydev != NULL && value != NULL) |
---|
2275 | { |
---|
2276 | debug(100, "set %s to %s", policydev, value); |
---|
2277 | ret = writesys(policydev, value, 0); |
---|
2278 | if(ret == 0) addconfig("av_policy", value); |
---|
2279 | return ret; |
---|
2280 | } |
---|
2281 | |
---|
2282 | debug(1000, "out"); |
---|
2283 | return 0; |
---|
2284 | } |
---|
2285 | |
---|
2286 | char* getaspectchoices() |
---|
2287 | { |
---|
2288 | debug(1000, "in"); |
---|
2289 | char *aspectchoicesdev = NULL; |
---|
2290 | char *value = NULL; |
---|
2291 | |
---|
2292 | aspectchoicesdev = getconfig("aspectchoicesdev", NULL); |
---|
2293 | |
---|
2294 | if(aspectchoicesdev == NULL) |
---|
2295 | { |
---|
2296 | debug(1000, "out -> NULL detect"); |
---|
2297 | return NULL; |
---|
2298 | } |
---|
2299 | |
---|
2300 | value = readsys(aspectchoicesdev, 1); |
---|
2301 | if(value == NULL) |
---|
2302 | { |
---|
2303 | debug(1000, "out -> NULL detect"); |
---|
2304 | return NULL; |
---|
2305 | } |
---|
2306 | |
---|
2307 | value = convertspacetolf(value); |
---|
2308 | |
---|
2309 | debug(1000, "out"); |
---|
2310 | return value; |
---|
2311 | } |
---|
2312 | |
---|
2313 | char* getaspect() |
---|
2314 | { |
---|
2315 | debug(1000, "in"); |
---|
2316 | char *aspectdev = NULL; |
---|
2317 | char *value = NULL; |
---|
2318 | |
---|
2319 | aspectdev = getconfig("aspectdev", NULL); |
---|
2320 | |
---|
2321 | if(aspectdev == NULL) |
---|
2322 | { |
---|
2323 | debug(1000, "out -> NULL detect"); |
---|
2324 | return NULL; |
---|
2325 | } |
---|
2326 | |
---|
2327 | value = readsys(aspectdev, 1); |
---|
2328 | if(value == NULL) |
---|
2329 | { |
---|
2330 | debug(1000, "out -> NULL detect"); |
---|
2331 | return NULL; |
---|
2332 | } |
---|
2333 | |
---|
2334 | debug(1000, "out"); |
---|
2335 | return value; |
---|
2336 | } |
---|
2337 | |
---|
2338 | int setaspect(char* value) |
---|
2339 | { |
---|
2340 | debug(1000, "in"); |
---|
2341 | char* aspectdev; |
---|
2342 | int ret = 0; |
---|
2343 | |
---|
2344 | aspectdev = getconfig("aspectdev", NULL); |
---|
2345 | |
---|
2346 | if(aspectdev != NULL && value != NULL) |
---|
2347 | { |
---|
2348 | debug(100, "set %s to %s", aspectdev, value); |
---|
2349 | ret = writesys(aspectdev, value, 0); |
---|
2350 | if(ret == 0) addconfig("av_aspect", value); |
---|
2351 | return ret; |
---|
2352 | } |
---|
2353 | |
---|
2354 | debug(1000, "out"); |
---|
2355 | return 0; |
---|
2356 | } |
---|
2357 | |
---|
2358 | char* getvideomodechoices() |
---|
2359 | { |
---|
2360 | debug(1000, "in"); |
---|
2361 | char *videomodechoicesdev = NULL; |
---|
2362 | char *value = NULL; |
---|
2363 | |
---|
2364 | videomodechoicesdev = getconfig("videomodechoicesdev", NULL); |
---|
2365 | |
---|
2366 | if(videomodechoicesdev == NULL) |
---|
2367 | { |
---|
2368 | debug(1000, "out -> NULL detect"); |
---|
2369 | return NULL; |
---|
2370 | } |
---|
2371 | |
---|
2372 | value = readsys(videomodechoicesdev, 1); |
---|
2373 | if(value == NULL) |
---|
2374 | { |
---|
2375 | debug(1000, "out -> NULL detect"); |
---|
2376 | return NULL; |
---|
2377 | } |
---|
2378 | |
---|
2379 | if(status.expertmodus == 0) |
---|
2380 | { |
---|
2381 | value = string_replace("1080p60", "", value, 1); |
---|
2382 | value = string_replace(" ", " ", value, 1); |
---|
2383 | value = string_replace("1080p59", "", value, 1); |
---|
2384 | value = string_replace(" ", " ", value, 1); |
---|
2385 | value = string_replace("1080p50", "", value, 1); |
---|
2386 | value = string_replace(" ", " ", value, 1); |
---|
2387 | value = string_replace("1080p30", "", value, 1); |
---|
2388 | value = string_replace(" ", " ", value, 1); |
---|
2389 | value = string_replace("1080p25", "", value, 1); |
---|
2390 | value = string_replace(" ", " ", value, 1); |
---|
2391 | value = string_replace("1080p24", "", value, 1); |
---|
2392 | value = string_replace(" ", " ", value, 1); |
---|
2393 | value = string_replace("1080i60", "", value, 1); |
---|
2394 | value = string_replace(" ", " ", value, 1); |
---|
2395 | value = string_replace("720p60", "", value, 1); |
---|
2396 | value = string_replace(" ", " ", value, 1); |
---|
2397 | } |
---|
2398 | |
---|
2399 | value = convertspacetolf(value); |
---|
2400 | |
---|
2401 | debug(1000, "out"); |
---|
2402 | return value; |
---|
2403 | } |
---|
2404 | |
---|
2405 | char* getmode3dchoices() |
---|
2406 | { |
---|
2407 | debug(1000, "in"); |
---|
2408 | char *mode3dchoicesdev = NULL; |
---|
2409 | char *value = NULL; |
---|
2410 | |
---|
2411 | mode3dchoicesdev = getconfig("mode3dchoicesdev", NULL); |
---|
2412 | |
---|
2413 | if(mode3dchoicesdev == NULL) |
---|
2414 | { |
---|
2415 | return ostrcat("off\nsbs\ntab", "", 0, 0); |
---|
2416 | } |
---|
2417 | |
---|
2418 | value = readsys(mode3dchoicesdev, 1); |
---|
2419 | if(value == NULL) |
---|
2420 | { |
---|
2421 | debug(1000, "out -> NULL detect"); |
---|
2422 | return NULL; |
---|
2423 | } |
---|
2424 | |
---|
2425 | value = convertspacetolf(value); |
---|
2426 | |
---|
2427 | debug(1000, "out"); |
---|
2428 | return value; |
---|
2429 | } |
---|
2430 | |
---|
2431 | char* getmode3d() |
---|
2432 | { |
---|
2433 | debug(1000, "in"); |
---|
2434 | char *mode3ddev = NULL; |
---|
2435 | char *value = NULL; |
---|
2436 | |
---|
2437 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
2438 | |
---|
2439 | if(mode3ddev == NULL) |
---|
2440 | { |
---|
2441 | debug(1000, "out -> NULL detect"); |
---|
2442 | return NULL; |
---|
2443 | } |
---|
2444 | |
---|
2445 | value = readsys(mode3ddev, 1); |
---|
2446 | if(value == NULL) |
---|
2447 | { |
---|
2448 | debug(1000, "out -> NULL detect"); |
---|
2449 | return NULL; |
---|
2450 | } |
---|
2451 | |
---|
2452 | debug(1000, "out"); |
---|
2453 | return value; |
---|
2454 | } |
---|
2455 | |
---|
2456 | int setmode3d(char* value) |
---|
2457 | { |
---|
2458 | debug(1000, "in"); |
---|
2459 | char* mode3ddev; |
---|
2460 | int ret = 0; |
---|
2461 | |
---|
2462 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
2463 | |
---|
2464 | if(mode3ddev != NULL && value != NULL) |
---|
2465 | { |
---|
2466 | debug(100, "set %s to %s", mode3ddev, value); |
---|
2467 | ret = writesys(mode3ddev, value, 0); |
---|
2468 | if(ret == 0) addconfig("av_mode3d", value); |
---|
2469 | return ret; |
---|
2470 | } |
---|
2471 | |
---|
2472 | debug(1000, "out"); |
---|
2473 | return 0; |
---|
2474 | } |
---|
2475 | |
---|
2476 | char* getvideomode() |
---|
2477 | { |
---|
2478 | debug(1000, "in"); |
---|
2479 | char *videomodedev = NULL; |
---|
2480 | char *value = NULL; |
---|
2481 | |
---|
2482 | videomodedev = getconfig("videomodedev", NULL); |
---|
2483 | |
---|
2484 | if(videomodedev == NULL) |
---|
2485 | { |
---|
2486 | debug(1000, "out -> NULL detect"); |
---|
2487 | return NULL; |
---|
2488 | } |
---|
2489 | |
---|
2490 | value = readsys(videomodedev, 1); |
---|
2491 | if(value == NULL) |
---|
2492 | { |
---|
2493 | debug(1000, "out -> NULL detect"); |
---|
2494 | return NULL; |
---|
2495 | } |
---|
2496 | |
---|
2497 | debug(1000, "out"); |
---|
2498 | return value; |
---|
2499 | } |
---|
2500 | |
---|
2501 | int setvideomode(char* value) |
---|
2502 | { |
---|
2503 | debug(1000, "in"); |
---|
2504 | char* videomodedev; |
---|
2505 | int ret = 0; |
---|
2506 | |
---|
2507 | videomodedev = getconfig("videomodedev", NULL); |
---|
2508 | |
---|
2509 | if(videomodedev != NULL && value != NULL) |
---|
2510 | { |
---|
2511 | debug(100, "set %s to %s", videomodedev, value); |
---|
2512 | ret = writesys(videomodedev, value, 0); |
---|
2513 | if(ret == 0) addconfig("av_videomode", value); |
---|
2514 | return ret; |
---|
2515 | } |
---|
2516 | |
---|
2517 | debug(1000, "out"); |
---|
2518 | return 0; |
---|
2519 | } |
---|
2520 | |
---|
2521 | int setcolorformat(char* value) |
---|
2522 | { |
---|
2523 | debug(1000, "in"); |
---|
2524 | char* colorformatdev; |
---|
2525 | int ret = 0; |
---|
2526 | |
---|
2527 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
2528 | |
---|
2529 | if(colorformatdev != NULL && value != NULL) |
---|
2530 | { |
---|
2531 | debug(100, "set %s to %s", colorformatdev, value); |
---|
2532 | ret = writesys(colorformatdev, value, 0); |
---|
2533 | if(ret == 0) addconfig("av_colorformat", value); |
---|
2534 | return ret; |
---|
2535 | } |
---|
2536 | |
---|
2537 | debug(1000, "out"); |
---|
2538 | return 0; |
---|
2539 | } |
---|
2540 | |
---|
2541 | char* getcolorformat(int line) |
---|
2542 | { |
---|
2543 | debug(1000, "in"); |
---|
2544 | char *colorformatdev = NULL; |
---|
2545 | char *value = NULL; |
---|
2546 | |
---|
2547 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
2548 | |
---|
2549 | if(colorformatdev == NULL) |
---|
2550 | { |
---|
2551 | debug(1000, "out -> NULL detect"); |
---|
2552 | return NULL; |
---|
2553 | } |
---|
2554 | |
---|
2555 | value = readsys(colorformatdev, line); |
---|
2556 | if(value == NULL) |
---|
2557 | { |
---|
2558 | debug(1000, "out -> NULL detect"); |
---|
2559 | return NULL; |
---|
2560 | } |
---|
2561 | |
---|
2562 | debug(1000, "out"); |
---|
2563 | return value; |
---|
2564 | } |
---|
2565 | |
---|
2566 | int setaudiosource(char* value) |
---|
2567 | { |
---|
2568 | debug(1000, "in"); |
---|
2569 | char* audiosourcedev; |
---|
2570 | int ret = 1; |
---|
2571 | |
---|
2572 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
2573 | |
---|
2574 | if(audiosourcedev != NULL && value != NULL) |
---|
2575 | { |
---|
2576 | debug(100, "set %s to %s", audiosourcedev, value); |
---|
2577 | ret = writesys(audiosourcedev, value, 0); |
---|
2578 | if(ret == 0) addconfig("av_audiosource", value); |
---|
2579 | return ret; |
---|
2580 | } |
---|
2581 | |
---|
2582 | debug(1000, "out"); |
---|
2583 | return 0; |
---|
2584 | } |
---|
2585 | |
---|
2586 | char* getaudiosource() |
---|
2587 | { |
---|
2588 | debug(1000, "in"); |
---|
2589 | char *audiosourcedev = NULL; |
---|
2590 | char *value = NULL; |
---|
2591 | |
---|
2592 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
2593 | |
---|
2594 | if(audiosourcedev == NULL) |
---|
2595 | { |
---|
2596 | debug(1000, "out -> NULL detect"); |
---|
2597 | return NULL; |
---|
2598 | } |
---|
2599 | |
---|
2600 | value = readsys(audiosourcedev, 1); |
---|
2601 | if(value == NULL) |
---|
2602 | { |
---|
2603 | debug(1000, "out -> NULL detect"); |
---|
2604 | return NULL; |
---|
2605 | } |
---|
2606 | |
---|
2607 | debug(1000, "out"); |
---|
2608 | return value; |
---|
2609 | } |
---|
2610 | |
---|
2611 | int setprogress(value) |
---|
2612 | { |
---|
2613 | debug(1000, "in"); |
---|
2614 | char *progressdev; |
---|
2615 | |
---|
2616 | progressdev = getconfig("progressdev", NULL); |
---|
2617 | |
---|
2618 | if(progressdev != NULL) |
---|
2619 | { |
---|
2620 | debug(100, "set %s to %d",progressdev, value); |
---|
2621 | return writesysint(progressdev, value, 0); |
---|
2622 | } |
---|
2623 | |
---|
2624 | debug(1000, "out"); |
---|
2625 | return 0; |
---|
2626 | } |
---|
2627 | |
---|
2628 | int setmute(int value) |
---|
2629 | { |
---|
2630 | debug(1000, "in"); |
---|
2631 | char* mutedev; |
---|
2632 | |
---|
2633 | mutedev = getconfig("mutedev", NULL); |
---|
2634 | |
---|
2635 | if(mutedev != NULL) |
---|
2636 | { |
---|
2637 | debug(100, "set %s to %d", mutedev, value); |
---|
2638 | return writesysint(mutedev, value, 0); |
---|
2639 | } |
---|
2640 | |
---|
2641 | debug(1000, "out"); |
---|
2642 | return 0; |
---|
2643 | } |
---|
2644 | |
---|
2645 | int setvol(int value) |
---|
2646 | { |
---|
2647 | debug(1000, "in"); |
---|
2648 | char* voldev; |
---|
2649 | int ret = 0, tmpvol = value; |
---|
2650 | |
---|
2651 | voldev = getconfig("voldev", NULL); |
---|
2652 | |
---|
2653 | if(voldev != NULL) |
---|
2654 | { |
---|
2655 | value = 63 - value * 63 / 100; |
---|
2656 | debug(100, "set %s to %d", voldev, value); |
---|
2657 | ret = writesysint(voldev, value, 0); |
---|
2658 | if(ret == 0) addconfigint("vol", tmpvol); |
---|
2659 | return ret; |
---|
2660 | } |
---|
2661 | |
---|
2662 | debug(1000, "out"); |
---|
2663 | return 0; |
---|
2664 | } |
---|
2665 | |
---|
2666 | int getvol() |
---|
2667 | { |
---|
2668 | debug(1000, "in"); |
---|
2669 | char *voldev = NULL; |
---|
2670 | char *value = NULL; |
---|
2671 | int tmpvol = 0; |
---|
2672 | |
---|
2673 | voldev = getconfig("voldev", NULL); |
---|
2674 | |
---|
2675 | if(voldev == NULL) |
---|
2676 | { |
---|
2677 | debug(1000, "out -> NULL detect"); |
---|
2678 | return 0; |
---|
2679 | } |
---|
2680 | |
---|
2681 | value = readsys(voldev, 1); |
---|
2682 | if(value == NULL) |
---|
2683 | { |
---|
2684 | debug(1000, "out -> NULL detect"); |
---|
2685 | return 0; |
---|
2686 | } |
---|
2687 | |
---|
2688 | tmpvol = atoi(value); |
---|
2689 | free(value); |
---|
2690 | tmpvol = 100 - tmpvol * 100 / 63; |
---|
2691 | |
---|
2692 | debug(1000, "out"); |
---|
2693 | return tmpvol; |
---|
2694 | } |
---|
2695 | |
---|
2696 | void setdebuglevel() |
---|
2697 | { |
---|
2698 | debug(1000, "in"); |
---|
2699 | |
---|
2700 | debug_level = getconfigint("debuglevel", NULL); |
---|
2701 | debug(0, "set debug level to %d", debug_level); |
---|
2702 | |
---|
2703 | debug(1000, "out"); |
---|
2704 | } |
---|
2705 | |
---|
2706 | char* getxmlentry(char *line, char *searchstr) |
---|
2707 | { |
---|
2708 | //debug(1000, "in"); |
---|
2709 | char *buf = NULL, *buf1 = NULL, *buf2 = NULL; |
---|
2710 | |
---|
2711 | buf = strstr(line, searchstr); |
---|
2712 | if(buf == NULL) |
---|
2713 | { |
---|
2714 | //debug(1000, "out -> searchstr=\"%s\" not found in line=\"%s\"", searchstr, line); |
---|
2715 | return NULL; |
---|
2716 | } |
---|
2717 | buf = buf + strlen(searchstr); |
---|
2718 | if(buf[0] == '"') |
---|
2719 | { |
---|
2720 | buf = buf + 1; |
---|
2721 | buf1 = ostrcat(buf, "", 0, 0); |
---|
2722 | if(buf1 == NULL) |
---|
2723 | { |
---|
2724 | err("ostrcat failed"); |
---|
2725 | return NULL; |
---|
2726 | } |
---|
2727 | buf2 = strchr(buf1, '"'); |
---|
2728 | if(buf2 == NULL) |
---|
2729 | { |
---|
2730 | err("strchr returns NULL"); |
---|
2731 | free(buf1); |
---|
2732 | return NULL; |
---|
2733 | } |
---|
2734 | buf2[0] = '\0'; |
---|
2735 | } |
---|
2736 | else |
---|
2737 | { |
---|
2738 | buf1 = ostrcat(buf, "", 0, 0); |
---|
2739 | if(buf1 == NULL) |
---|
2740 | { |
---|
2741 | err("ostrcat failed"); |
---|
2742 | return NULL; |
---|
2743 | } |
---|
2744 | buf2 = strchr(buf1, ' '); |
---|
2745 | if(buf2 == NULL) |
---|
2746 | { |
---|
2747 | buf2 = strstr(buf1, "/>"); |
---|
2748 | if(buf2 == NULL) |
---|
2749 | { |
---|
2750 | buf2 = strchr(buf1, '>'); |
---|
2751 | if(buf2 == NULL) |
---|
2752 | { |
---|
2753 | err("strchr returns NULL"); |
---|
2754 | free(buf1); |
---|
2755 | return NULL; |
---|
2756 | } |
---|
2757 | } |
---|
2758 | } |
---|
2759 | buf2[0] = '\0'; |
---|
2760 | } |
---|
2761 | //debug(1000, "out"); |
---|
2762 | return buf1; |
---|
2763 | } |
---|
2764 | |
---|
2765 | char* readfiletomem(const char* filename, int flag) |
---|
2766 | { |
---|
2767 | debug(1000, "in"); |
---|
2768 | FILE *fd = NULL; |
---|
2769 | char *fileline = NULL, *buf = NULL, *buf1 = NULL; |
---|
2770 | int buf1size = 0, buf1oldsize = 0; |
---|
2771 | |
---|
2772 | fileline = malloc(MINMALLOC); |
---|
2773 | if(fileline == NULL) |
---|
2774 | { |
---|
2775 | err("no memory"); |
---|
2776 | return NULL; |
---|
2777 | } |
---|
2778 | |
---|
2779 | fd = fopen(filename, "r"); |
---|
2780 | if(fd == NULL) |
---|
2781 | { |
---|
2782 | perr("can't open %s", filename); |
---|
2783 | free(fileline); |
---|
2784 | return NULL; |
---|
2785 | } |
---|
2786 | |
---|
2787 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
2788 | { |
---|
2789 | buf = fileline; |
---|
2790 | |
---|
2791 | if(flag == 1) |
---|
2792 | if(buf[0] == '#' || buf[0] == '\n') |
---|
2793 | continue; |
---|
2794 | |
---|
2795 | buf1oldsize = buf1size; |
---|
2796 | buf1size += strlen(buf); |
---|
2797 | buf1 = realloc(buf1, buf1size + 1); |
---|
2798 | if(buf1 == NULL) |
---|
2799 | { |
---|
2800 | err("no memory"); |
---|
2801 | free(fileline); |
---|
2802 | fclose(fd); |
---|
2803 | return NULL; |
---|
2804 | } |
---|
2805 | |
---|
2806 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
2807 | } |
---|
2808 | |
---|
2809 | free(fileline); |
---|
2810 | fclose(fd); |
---|
2811 | debug(1000, "out"); |
---|
2812 | return buf1; |
---|
2813 | } |
---|
2814 | |
---|
2815 | char* command(char* input) |
---|
2816 | { |
---|
2817 | debug(1000, "in"); |
---|
2818 | char* tmpstr = NULL, *fileline = NULL; |
---|
2819 | FILE *iopipe; |
---|
2820 | |
---|
2821 | fileline = malloc(MINMALLOC); |
---|
2822 | if(fileline == NULL) |
---|
2823 | { |
---|
2824 | err("no memory"); |
---|
2825 | return NULL; |
---|
2826 | } |
---|
2827 | |
---|
2828 | if((iopipe = popen(input, "r")) == NULL) |
---|
2829 | { |
---|
2830 | free(fileline); |
---|
2831 | return NULL; |
---|
2832 | } |
---|
2833 | |
---|
2834 | while(!feof(iopipe)) |
---|
2835 | { |
---|
2836 | if(fgets(fileline, MINMALLOC, iopipe) != NULL) |
---|
2837 | tmpstr = ostrcat(tmpstr, fileline, 1, 0); |
---|
2838 | } |
---|
2839 | |
---|
2840 | free(fileline); |
---|
2841 | pclose(iopipe); |
---|
2842 | debug(1000, "out"); |
---|
2843 | return tmpstr; |
---|
2844 | } |
---|
2845 | |
---|
2846 | char* string_tolower(char *str) |
---|
2847 | { |
---|
2848 | debug(1000, "in"); |
---|
2849 | int i; |
---|
2850 | |
---|
2851 | if(str == NULL) return NULL; |
---|
2852 | |
---|
2853 | for( i = 0; i < strlen(str); i++) |
---|
2854 | str[i] = tolower(str[i]); |
---|
2855 | |
---|
2856 | debug(1000, "out"); |
---|
2857 | return str; |
---|
2858 | } |
---|
2859 | |
---|
2860 | char* string_toupper(char *str) |
---|
2861 | { |
---|
2862 | debug(1000, "in"); |
---|
2863 | int i; |
---|
2864 | |
---|
2865 | if(str == NULL) return NULL; |
---|
2866 | |
---|
2867 | for( i = 0; i < strlen(str); i++) |
---|
2868 | str[i] = toupper(str[i]); |
---|
2869 | |
---|
2870 | debug(1000, "out"); |
---|
2871 | return str; |
---|
2872 | } |
---|
2873 | |
---|
2874 | char* stringreplacecharonce(char *str, char c1, char c2) |
---|
2875 | { |
---|
2876 | debug(1000, "in"); |
---|
2877 | int i; |
---|
2878 | |
---|
2879 | if(str == NULL) return NULL; |
---|
2880 | |
---|
2881 | for( i = 0; i < strlen(str); i++) |
---|
2882 | { |
---|
2883 | if(str[i] == c1) |
---|
2884 | { |
---|
2885 | str[i] = c2; |
---|
2886 | break; |
---|
2887 | } |
---|
2888 | } |
---|
2889 | |
---|
2890 | debug(1000, "out"); |
---|
2891 | return str; |
---|
2892 | } |
---|
2893 | |
---|
2894 | char* stringreplacechar(char *str, char c1, char c2) |
---|
2895 | { |
---|
2896 | debug(1000, "in"); |
---|
2897 | int i; |
---|
2898 | |
---|
2899 | if(str == NULL) return NULL; |
---|
2900 | |
---|
2901 | for( i = 0; i < strlen(str); i++) |
---|
2902 | if(str[i] == c1) str[i] = c2; |
---|
2903 | |
---|
2904 | debug(1000, "out"); |
---|
2905 | return str; |
---|
2906 | } |
---|
2907 | |
---|
2908 | char* string_removechar(char *str) |
---|
2909 | { |
---|
2910 | debug(1000, "in"); |
---|
2911 | int i; |
---|
2912 | |
---|
2913 | if(str == NULL) return NULL; |
---|
2914 | |
---|
2915 | for( i = 0; i < strlen(str); i++) |
---|
2916 | { |
---|
2917 | if(str[i] == '.') str[i] = ' '; |
---|
2918 | if(str[i] == '-') str[i] = ' '; |
---|
2919 | if(str[i] == '_') str[i] = ' '; |
---|
2920 | if(str[i] == '/') str[i] = ' '; |
---|
2921 | } |
---|
2922 | debug(1000, "out"); |
---|
2923 | return str; |
---|
2924 | } |
---|
2925 | |
---|
2926 | char* string_withchars2return(char *str) |
---|
2927 | { |
---|
2928 | debug(1000, "in"); |
---|
2929 | int i; |
---|
2930 | |
---|
2931 | for( i = 0; i < strlen(str); i++) |
---|
2932 | { |
---|
2933 | if(str[i] == ' ') str[i] = '\n'; |
---|
2934 | } |
---|
2935 | |
---|
2936 | debug(1000, "out"); |
---|
2937 | return str; |
---|
2938 | } |
---|
2939 | |
---|
2940 | char* string_remove_whitechars(char *text) |
---|
2941 | { |
---|
2942 | debug(1000, "in"); |
---|
2943 | char *p1 = text, *p2 = text; |
---|
2944 | |
---|
2945 | while(*p1 != '\0') |
---|
2946 | { |
---|
2947 | if(*p1 == ' ') |
---|
2948 | ++p1; |
---|
2949 | else |
---|
2950 | *p2++ = *p1++; |
---|
2951 | } |
---|
2952 | *p2 = '\0'; |
---|
2953 | |
---|
2954 | debug(1000, "out"); |
---|
2955 | return text; |
---|
2956 | } |
---|
2957 | |
---|
2958 | char* strstrip(char *text) |
---|
2959 | { |
---|
2960 | debug(1000, "in"); |
---|
2961 | char* tmpstr = text; |
---|
2962 | |
---|
2963 | if(text == NULL) return NULL; |
---|
2964 | int len = strlen(text); |
---|
2965 | |
---|
2966 | while(isspace(tmpstr[len - 1])) tmpstr[--len] = '\0'; |
---|
2967 | while(*tmpstr && isspace(*tmpstr)) ++tmpstr, --len; |
---|
2968 | |
---|
2969 | memmove(text, tmpstr, len + 1); |
---|
2970 | |
---|
2971 | debug(1000, "out"); |
---|
2972 | return text; |
---|
2973 | } |
---|
2974 | |
---|
2975 | char* string_strip_whitechars(char *text) |
---|
2976 | { |
---|
2977 | debug(1000, "in"); |
---|
2978 | int i; |
---|
2979 | |
---|
2980 | if(text == NULL) |
---|
2981 | { |
---|
2982 | debug(1000, "out -> NULL detect"); |
---|
2983 | return NULL; |
---|
2984 | } |
---|
2985 | |
---|
2986 | text = string_removechar(text); |
---|
2987 | |
---|
2988 | for(i = 0; text[i] != '\0'; i++) |
---|
2989 | { |
---|
2990 | if(text[i] == ' ' && text[i + 1] == ' ') |
---|
2991 | { |
---|
2992 | int i2 = i + 1; |
---|
2993 | for(; text[i2] != '\0'; i2++) |
---|
2994 | { |
---|
2995 | text[i] = text[i2]; |
---|
2996 | i++; |
---|
2997 | } |
---|
2998 | text[i2 - 1] = '\0'; |
---|
2999 | i = -1; |
---|
3000 | } |
---|
3001 | } |
---|
3002 | |
---|
3003 | debug(1000, "out"); |
---|
3004 | return text; |
---|
3005 | } |
---|
3006 | |
---|
3007 | char* string_replace_remove_last_chars(char *search, char *replace, char *string, int free1) |
---|
3008 | { |
---|
3009 | debug(1000, "in"); |
---|
3010 | char* searchpos = NULL; |
---|
3011 | char* tmpstr = NULL; |
---|
3012 | |
---|
3013 | if(string == NULL || search == NULL) |
---|
3014 | return string; |
---|
3015 | |
---|
3016 | searchpos = strstr(string, search); |
---|
3017 | |
---|
3018 | if(searchpos == NULL) |
---|
3019 | return string; |
---|
3020 | |
---|
3021 | tmpstr = strndup(string, searchpos - string); |
---|
3022 | if(replace != NULL) |
---|
3023 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
3024 | |
---|
3025 | if(free1 == 1) free(string); |
---|
3026 | |
---|
3027 | debug(1000, "out"); |
---|
3028 | return tmpstr; |
---|
3029 | } |
---|
3030 | |
---|
3031 | char* string_replace(char *search, char *replace, char *string, int free1) |
---|
3032 | { |
---|
3033 | debug(1000, "in"); |
---|
3034 | char* searchpos = NULL; |
---|
3035 | char* tmpstr = NULL; |
---|
3036 | |
---|
3037 | if(string == NULL || search == NULL) |
---|
3038 | return string; |
---|
3039 | |
---|
3040 | searchpos = strstr(string, search); |
---|
3041 | |
---|
3042 | if(searchpos == NULL) |
---|
3043 | return string; |
---|
3044 | |
---|
3045 | tmpstr = strndup(string, searchpos - string); |
---|
3046 | if(replace == NULL) |
---|
3047 | tmpstr = ostrcat(tmpstr, "", 1, 0); |
---|
3048 | else |
---|
3049 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
3050 | tmpstr = ostrcat(tmpstr, string + (searchpos - string) + strlen(search), 1, 0); |
---|
3051 | |
---|
3052 | if(free1 == 1) free(string); |
---|
3053 | |
---|
3054 | debug(1000, "out"); |
---|
3055 | return tmpstr; |
---|
3056 | } |
---|
3057 | |
---|
3058 | int string_find(char* str, char* filename) |
---|
3059 | { |
---|
3060 | debug(1000, "in"); |
---|
3061 | int i, len_str, len_filename; |
---|
3062 | |
---|
3063 | if(str == NULL || filename == NULL) return 0; |
---|
3064 | |
---|
3065 | len_str = strlen(str); |
---|
3066 | len_filename = strlen(filename); |
---|
3067 | |
---|
3068 | for(i = 0; (i + len_str) < len_filename; i++) |
---|
3069 | if(strncmp(filename + i, str, len_str) == 0) |
---|
3070 | return 1; |
---|
3071 | |
---|
3072 | debug(1000, "out"); |
---|
3073 | return 0; |
---|
3074 | } |
---|
3075 | |
---|
3076 | int file_exist(char* filename) |
---|
3077 | { |
---|
3078 | debug(1000, "in"); |
---|
3079 | if (access(filename, F_OK) == 0) |
---|
3080 | return 1; |
---|
3081 | else |
---|
3082 | return 0; |
---|
3083 | } |
---|
3084 | |
---|
3085 | char* string_newline(char* str) |
---|
3086 | { |
---|
3087 | debug(1000, "in"); |
---|
3088 | if(str == NULL) return NULL; |
---|
3089 | |
---|
3090 | int size = strlen(str); |
---|
3091 | |
---|
3092 | if(str[size - 1] == '\n') |
---|
3093 | str[size - 1] = '\0'; |
---|
3094 | debug(1000, "out"); |
---|
3095 | return str; |
---|
3096 | } |
---|
3097 | |
---|
3098 | char* string_quote(char* str) |
---|
3099 | { |
---|
3100 | debug(1000, "in"); |
---|
3101 | char* tmpstr = NULL; |
---|
3102 | |
---|
3103 | tmpstr = ostrcat("\"", str, 0, 0); |
---|
3104 | tmpstr = ostrcat(tmpstr, "\"", 1, 0); |
---|
3105 | debug(1000, "out"); |
---|
3106 | return tmpstr; |
---|
3107 | } |
---|
3108 | |
---|
3109 | struct splitstr* strsplit(char *str, char *tok, int* count) |
---|
3110 | { |
---|
3111 | debug(1000, "in"); |
---|
3112 | char *tmpstr = NULL; |
---|
3113 | struct splitstr *tmparray = NULL; |
---|
3114 | *count = 0; |
---|
3115 | |
---|
3116 | if(tok == NULL) |
---|
3117 | return NULL; |
---|
3118 | |
---|
3119 | tmpstr = strtok(str, tok); |
---|
3120 | while(tmpstr != NULL) |
---|
3121 | { |
---|
3122 | *count = *count + 1; |
---|
3123 | tmparray = (struct splitstr*)realloc(tmparray, sizeof(struct splitstr*) * (*count)); |
---|
3124 | if(tmparray == NULL) |
---|
3125 | return NULL; |
---|
3126 | (&tmparray[(*count) - 1])->part = tmpstr; |
---|
3127 | tmpstr = strtok(NULL, tok); |
---|
3128 | } |
---|
3129 | debug(1000, "out"); |
---|
3130 | return tmparray; |
---|
3131 | } |
---|
3132 | |
---|
3133 | char* string_shortname(char *tmpfilename, int mode) |
---|
3134 | { |
---|
3135 | debug(50, "in %s",tmpfilename); |
---|
3136 | |
---|
3137 | // 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"; |
---|
3138 | char* str = NULL; |
---|
3139 | |
---|
3140 | if (mode==1){ |
---|
3141 | 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"; |
---|
3142 | str = ostrcat(str, replacelist, 0, 0); |
---|
3143 | } else { |
---|
3144 | 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"; |
---|
3145 | str = ostrcat(str, replacelist, 0, 0); |
---|
3146 | } |
---|
3147 | |
---|
3148 | char* replace = NULL; |
---|
3149 | struct splitstr* ret1 = NULL; |
---|
3150 | int count = 0; |
---|
3151 | int i = 0; |
---|
3152 | ret1 = strsplit(str, " ", &count); |
---|
3153 | int max = count - 1; |
---|
3154 | |
---|
3155 | for( i = 0; i < max; i++){ |
---|
3156 | struct splitstr* ret2 = NULL; |
---|
3157 | int count2 = 0; |
---|
3158 | int j = 0; |
---|
3159 | char *tmpstr = NULL; |
---|
3160 | tmpstr = ostrcat(tmpstr, tmpfilename, 1, 0); |
---|
3161 | ret2 = strsplit(tmpstr, " ,.-_", &count2); |
---|
3162 | |
---|
3163 | for( j = 0; j < count2; j++){ |
---|
3164 | if(j > 0){ |
---|
3165 | if(ostrcmp((&ret1[i])->part, (&ret2[j])->part) == 0){ |
---|
3166 | if (mode==1){ |
---|
3167 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
3168 | continue; |
---|
3169 | } else { |
---|
3170 | // tmpfilename = string_replace_remove_last_chars((&ret2[j])->part, replace, tmpfilename, 1); |
---|
3171 | // break; |
---|
3172 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
3173 | continue; |
---|
3174 | } |
---|
3175 | } |
---|
3176 | } |
---|
3177 | } |
---|
3178 | free(ret2); ret2 = NULL; |
---|
3179 | } |
---|
3180 | |
---|
3181 | free(ret1); ret1 = NULL; |
---|
3182 | free(replace); replace = NULL; |
---|
3183 | free(str); str = NULL; |
---|
3184 | |
---|
3185 | debug(50, "out %s", tmpfilename); |
---|
3186 | return tmpfilename; |
---|
3187 | } |
---|
3188 | |
---|
3189 | char* get_ipk_section() |
---|
3190 | { |
---|
3191 | debug(60, "in"); |
---|
3192 | return command("ipkg list | awk '{ print $1 }' | cut -d '-' -f3 | sed 's/Successfully//' | sort -u"); |
---|
3193 | } |
---|
3194 | |
---|
3195 | char* get_ipk_list(char* section) |
---|
3196 | { |
---|
3197 | debug(60, "in %s",section); |
---|
3198 | char* cmd = NULL, *tmpstr = NULL; |
---|
3199 | |
---|
3200 | if(section == NULL) return NULL; |
---|
3201 | |
---|
3202 | cmd = ostrcat(cmd, "ipkg list *-", 1, 0); |
---|
3203 | cmd = ostrcat(cmd, section, 1, 0); |
---|
3204 | cmd = ostrcat(cmd, "-* | sed 's/Successfully terminated.//'", 1, 0); |
---|
3205 | |
---|
3206 | tmpstr = command(cmd); |
---|
3207 | |
---|
3208 | debug(60, "out %s",cmd); |
---|
3209 | free(cmd); cmd = NULL; |
---|
3210 | return tmpstr; |
---|
3211 | } |
---|
3212 | |
---|
3213 | /* disable cant handling 2 feeds.... |
---|
3214 | char* get_ipk_install(char* ipk) |
---|
3215 | { |
---|
3216 | debug(60, "in %s",ipk); |
---|
3217 | char* tmpstr1 = NULL; |
---|
3218 | char* tmpstr2 = NULL; |
---|
3219 | char* tmpstr3 = NULL; |
---|
3220 | |
---|
3221 | if(ipk == NULL) return NULL; |
---|
3222 | |
---|
3223 | struct splitstr* ret1 = NULL; |
---|
3224 | int count1 = 0; |
---|
3225 | tmpstr1 = ostrcat("", ipk, 0, 0); |
---|
3226 | ret1 = strsplit(tmpstr1, " ", &count1); |
---|
3227 | tmpstr2 = ostrcat("", "", 0, 0); |
---|
3228 | tmpstr3 = ostrcat(tmpstr3 , (&ret1[1])->part, 1, 0); |
---|
3229 | debug(60, "tmpstr3: %s", tmpstr3); |
---|
3230 | |
---|
3231 | strcpy(tmpstr2, tmpstr3 + 2); |
---|
3232 | debug(60, "tmpstr2: %s", tmpstr2); |
---|
3233 | |
---|
3234 | char* ipkname = NULL, *tmpstr = NULL; |
---|
3235 | ipkname = ostrcat(ipkname, "/titan-plugin-", 1, 0); |
---|
3236 | ipkname = ostrcat(ipkname, (&ret1[0])->part, 1, 0); |
---|
3237 | ipkname = ostrcat(ipkname, "_", 1, 0); |
---|
3238 | ipkname = ostrcat(ipkname, tmpstr2, 1, 0); |
---|
3239 | ipkname = ostrcat(ipkname, "_sh4.ipk", 1, 0); |
---|
3240 | |
---|
3241 | char* ip = NULL; |
---|
3242 | char* cmd = NULL; |
---|
3243 | char* path = NULL; |
---|
3244 | |
---|
3245 | cmd = ostrcat(cmd, "cat /var/etc/ipkg/official-feed.conf | cut -d '/' -f4", 1, 0); |
---|
3246 | debug(60, "cmd: %s", cmd); |
---|
3247 | cmd = strstrip(string_newline(command(cmd))); |
---|
3248 | debug(60, "cmd: %s", cmd); |
---|
3249 | |
---|
3250 | ip = ostrcat("", cmd, 0, 0); |
---|
3251 | debug(60, "ip: %s", ip); |
---|
3252 | |
---|
3253 | cmd = ostrcat("", "cat /var/etc/ipkg/official-feed.conf | cut -d ' ' -f3 | sed 's!http://", 0, 0); |
---|
3254 | cmd = ostrcat(cmd, ip, 1, 0); |
---|
3255 | cmd = ostrcat(cmd, "/!!'", 1, 0); |
---|
3256 | debug(60, "cmd: %s", cmd); |
---|
3257 | cmd = strstrip(string_newline(command(cmd))); |
---|
3258 | debug(60, "cmd: %s", cmd); |
---|
3259 | |
---|
3260 | path = ostrcat(path, cmd, 1, 0); |
---|
3261 | path = ostrcat(path, ipkname, 1, 0); |
---|
3262 | debug(60, "path: %s", path); |
---|
3263 | |
---|
3264 | screendownload("Download", ip, path, 80, "/tmp/tmp.ipk", 0); |
---|
3265 | |
---|
3266 | tmpstr = command("ipkg install /tmp/tmp.ipk"); |
---|
3267 | |
---|
3268 | debug(60, "out %s",cmd); |
---|
3269 | free(ipkname); ipkname = NULL; |
---|
3270 | free(tmpstr1); tmpstr1 = NULL; |
---|
3271 | free(tmpstr2); tmpstr2 = NULL; |
---|
3272 | free(tmpstr3); tmpstr3 = NULL; |
---|
3273 | return tmpstr; |
---|
3274 | } |
---|
3275 | */ |
---|
3276 | char* get_ipk_install(char* ipk) |
---|
3277 | { |
---|
3278 | debug(60, "in %s",ipk); |
---|
3279 | |
---|
3280 | char* cmd = NULL, *tmpstr = NULL; |
---|
3281 | cmd = ostrcat(cmd, "ipkg install titan-plugin-", 1, 0); |
---|
3282 | cmd = ostrcat(cmd, ipk, 1, 0); |
---|
3283 | |
---|
3284 | tmpstr = command(cmd); |
---|
3285 | |
---|
3286 | debug(60, "out %s",cmd); |
---|
3287 | free(cmd); cmd = NULL; |
---|
3288 | return tmpstr; |
---|
3289 | } |
---|
3290 | |
---|
3291 | char* get_ipk_tmpinstall() |
---|
3292 | { |
---|
3293 | debug(60, "in"); |
---|
3294 | |
---|
3295 | char* cmd = NULL, *tmpstr = NULL; |
---|
3296 | cmd = ostrcat(cmd, "ipkg install /tmp/*.ipk", 1, 0); |
---|
3297 | |
---|
3298 | tmpstr = command(cmd); |
---|
3299 | |
---|
3300 | debug(60, "out %s",cmd); |
---|
3301 | free(cmd); cmd = NULL; |
---|
3302 | return tmpstr; |
---|
3303 | } |
---|
3304 | |
---|
3305 | char* get_ipk_listinstall() |
---|
3306 | { |
---|
3307 | debug(60, "in"); |
---|
3308 | char* cmd = NULL, *tmpstr = NULL; |
---|
3309 | |
---|
3310 | cmd = ostrcat(cmd, "ipkg list_installed | awk '{ print $1 }' | sed 's/Successfully//' | sed 's/titan-plugin-//'", 1, 0); |
---|
3311 | |
---|
3312 | tmpstr = command(cmd); |
---|
3313 | |
---|
3314 | debug(60, "out %s",cmd); |
---|
3315 | free(cmd); cmd = NULL; |
---|
3316 | return tmpstr; |
---|
3317 | } |
---|
3318 | |
---|
3319 | char* get_ipk_remove(char* ipk) |
---|
3320 | { |
---|
3321 | debug(60, "in %s",ipk); |
---|
3322 | char* cmd = NULL, *tmpstr = NULL; |
---|
3323 | |
---|
3324 | if(ipk == NULL) return NULL; |
---|
3325 | |
---|
3326 | cmd = ostrcat(cmd, "ipkg remove titan-plugin-", 1, 0); |
---|
3327 | cmd = ostrcat(cmd, ipk, 1, 0); |
---|
3328 | |
---|
3329 | tmpstr = command(cmd); |
---|
3330 | |
---|
3331 | debug(60, "out"); |
---|
3332 | free(cmd); cmd = NULL; |
---|
3333 | return tmpstr; |
---|
3334 | } |
---|
3335 | |
---|
3336 | char* get_ipk_update() |
---|
3337 | { |
---|
3338 | debug(60, "in"); |
---|
3339 | char* tmpstr1 = NULL; |
---|
3340 | |
---|
3341 | if(!file_exist("/tmp/Packages.preview.tar.gz")) |
---|
3342 | { |
---|
3343 | char* ip = NULL; |
---|
3344 | char* cmd = NULL; |
---|
3345 | char* path = NULL; |
---|
3346 | |
---|
3347 | cmd = ostrcat(cmd, "cat /var/etc/ipkg/official-feed.conf | cut -d '/' -f4", 1, 0); |
---|
3348 | debug(60, "cmd: %s", cmd); |
---|
3349 | cmd = strstrip(string_newline(command(cmd))); |
---|
3350 | debug(60, "cmd: %s", cmd); |
---|
3351 | |
---|
3352 | struct splitstr* ret1 = NULL; |
---|
3353 | int count1 = 0; |
---|
3354 | tmpstr1 = ostrcat("", cmd, 0, 0); |
---|
3355 | ret1 = strsplit(tmpstr1, "\n", &count1); |
---|
3356 | int max = count1; |
---|
3357 | int i = 0; |
---|
3358 | for( i = 0; i < max; i++){ |
---|
3359 | system("rm -rf /tmp/Packages.preview.tar.gz"); |
---|
3360 | ip = ostrcat("", (&ret1[i])->part, 0, 0); |
---|
3361 | debug(60, "ip: %s", ip); |
---|
3362 | cmd = ostrcat("", "cat /var/etc/ipkg/official-feed.conf | grep ", 0, 0); |
---|
3363 | cmd = ostrcat(cmd, ip, 1, 0); |
---|
3364 | cmd = ostrcat(cmd, " | cut -d ' ' -f3 | sed 's!http://", 1, 0); |
---|
3365 | cmd = ostrcat(cmd, ip, 1, 0); |
---|
3366 | cmd = ostrcat(cmd, "/!!'", 1, 0); |
---|
3367 | debug(60, "cmd: %s", cmd); |
---|
3368 | cmd = strstrip(string_newline(command(cmd))); |
---|
3369 | debug(60, "cmd: %s", cmd); |
---|
3370 | |
---|
3371 | path = ostrcat("", cmd, 0, 0); |
---|
3372 | path = ostrcat(path, "/Packages.preview.tar.gz", 1, 0); |
---|
3373 | debug(60, "path: %s", path); |
---|
3374 | |
---|
3375 | screendownload("Download", ip, path, 80, "/tmp/Packages.preview.tar.gz", 0); |
---|
3376 | |
---|
3377 | system("tar -zxvf /tmp/Packages.preview.tar.gz -C /tmp"); |
---|
3378 | |
---|
3379 | } |
---|
3380 | |
---|
3381 | free(cmd), cmd = NULL; |
---|
3382 | free(ip), ip = NULL; |
---|
3383 | free(path), path = NULL; |
---|
3384 | } |
---|
3385 | debug(60, "out"); |
---|
3386 | return command("ipkg update"); |
---|
3387 | } |
---|
3388 | |
---|
3389 | char* get_ipk_info(char* section) |
---|
3390 | { |
---|
3391 | debug(60, "in %s",section); |
---|
3392 | char* cmd = NULL, *tmpstr = NULL; |
---|
3393 | |
---|
3394 | if(section == NULL) return NULL; |
---|
3395 | |
---|
3396 | cmd = ostrcat(cmd, "ipkg list *-", 1, 0); |
---|
3397 | cmd = ostrcat(cmd, section, 1, 0); |
---|
3398 | cmd = ostrcat(cmd, " | cut -d'-' -f6 | sed 's/Successfully terminated.//'", 1, 0); |
---|
3399 | |
---|
3400 | tmpstr = command(cmd); |
---|
3401 | |
---|
3402 | debug(60, "out %s",cmd); |
---|
3403 | free(cmd); cmd = NULL; |
---|
3404 | return tmpstr; |
---|
3405 | } |
---|
3406 | |
---|
3407 | char* get_uuid(char* device) |
---|
3408 | { |
---|
3409 | debug(60, "in %s", device); |
---|
3410 | |
---|
3411 | char* cmd = NULL, *tmpstr = NULL; |
---|
3412 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s UUID /dev/", 1, 0); |
---|
3413 | cmd = ostrcat(cmd, device, 1, 0); |
---|
3414 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
3415 | |
---|
3416 | tmpstr = string_newline(command(cmd)); |
---|
3417 | |
---|
3418 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
3419 | { |
---|
3420 | free(tmpstr); tmpstr = NULL; |
---|
3421 | } |
---|
3422 | |
---|
3423 | debug(60, "out %s", cmd); |
---|
3424 | free(cmd); cmd = NULL; |
---|
3425 | return tmpstr; |
---|
3426 | } |
---|
3427 | |
---|
3428 | char* get_label(char* device) |
---|
3429 | { |
---|
3430 | debug(60, "in %s", device); |
---|
3431 | char* cmd = NULL, *tmpstr = NULL; |
---|
3432 | |
---|
3433 | if(device == NULL) return NULL; |
---|
3434 | |
---|
3435 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s LABEL /dev/", 1, 0); |
---|
3436 | cmd = ostrcat(cmd, device, 1, 0); |
---|
3437 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
3438 | |
---|
3439 | tmpstr = string_newline(command(cmd)); |
---|
3440 | |
---|
3441 | if(tmpstr == NULL) |
---|
3442 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
3443 | |
---|
3444 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
3445 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
3446 | |
---|
3447 | debug(60, "out %s", cmd); |
---|
3448 | free(cmd); cmd = NULL; |
---|
3449 | return tmpstr; |
---|
3450 | } |
---|
3451 | |
---|
3452 | char* get_filesystem(char* device) |
---|
3453 | { |
---|
3454 | debug(60, "in %s", device); |
---|
3455 | char* cmd = NULL, *tmpstr = NULL; |
---|
3456 | |
---|
3457 | if(device == NULL) return NULL; |
---|
3458 | |
---|
3459 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s TYPE /dev/", 1, 0); |
---|
3460 | cmd = ostrcat(cmd, device, 1, 0); |
---|
3461 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
3462 | |
---|
3463 | tmpstr = string_newline(command(cmd)); |
---|
3464 | |
---|
3465 | if(tmpstr == NULL) |
---|
3466 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
3467 | |
---|
3468 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
3469 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
3470 | |
---|
3471 | debug(60, "out %s", cmd); |
---|
3472 | free(cmd); cmd = NULL; |
---|
3473 | return tmpstr; |
---|
3474 | } |
---|
3475 | |
---|
3476 | char* fixip(char* ipinput, int flag) |
---|
3477 | { |
---|
3478 | debug(60, "in %s", ipinput); |
---|
3479 | char* ipout = NULL; |
---|
3480 | unsigned char ip[4]; |
---|
3481 | |
---|
3482 | if(ipinput == NULL) return NULL; |
---|
3483 | sscanf(ipinput, "%hhu.%hhu.%hhu.%hhu", &ip[0], &ip[1], &ip[2], &ip[3]); |
---|
3484 | |
---|
3485 | ipout = malloc(16); |
---|
3486 | if(ipout == NULL) |
---|
3487 | { |
---|
3488 | err("no mem"); |
---|
3489 | return NULL; |
---|
3490 | } |
---|
3491 | |
---|
3492 | if(flag == 1) |
---|
3493 | snprintf(ipout, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
---|
3494 | else |
---|
3495 | snprintf(ipout, 16, "%03d.%03d.%03d.%03d", ip[0], ip[1], ip[2], ip[3]); |
---|
3496 | |
---|
3497 | return ipout; |
---|
3498 | } |
---|
3499 | |
---|
3500 | void setfanspeed(int speed, int aktion) |
---|
3501 | { |
---|
3502 | char* speedWert = NULL; |
---|
3503 | char* speedSet = NULL; |
---|
3504 | |
---|
3505 | if(speed < 0) |
---|
3506 | { |
---|
3507 | speedWert = getconfig("fanspeed", NULL); |
---|
3508 | if(speedWert == NULL) |
---|
3509 | speedSet = ostrcat(speedSet, "170", 1, 0); |
---|
3510 | else |
---|
3511 | speedSet = ostrcat(speedSet, speedWert, 1, 0); |
---|
3512 | } |
---|
3513 | else |
---|
3514 | { |
---|
3515 | if(speed == 0) |
---|
3516 | speedSet = ostrcat(speedSet, "115", 1, 0); |
---|
3517 | else if(speed == 25) |
---|
3518 | speedSet = ostrcat(speedSet, "130", 1, 0); |
---|
3519 | else if(speed == 50) |
---|
3520 | speedSet = ostrcat(speedSet, "145", 1, 0); |
---|
3521 | else if(speed == 75) |
---|
3522 | speedSet = ostrcat(speedSet, "155", 1, 0); |
---|
3523 | else |
---|
3524 | speedSet = ostrcat(speedSet, "170", 1, 0); |
---|
3525 | } |
---|
3526 | |
---|
3527 | writesys("/proc/stb/fan/fan_ctrl", speedSet, 1); |
---|
3528 | |
---|
3529 | if(aktion == 1) |
---|
3530 | addconfig("fanspeed", speedSet); |
---|
3531 | |
---|
3532 | free(speedSet); speedSet=NULL; |
---|
3533 | } |
---|
3534 | |
---|
3535 | void setaktres() |
---|
3536 | { |
---|
3537 | int m_width; |
---|
3538 | char* res = NULL; |
---|
3539 | char* res_akt = NULL; |
---|
3540 | char* res_sd = NULL; |
---|
3541 | int count=1; |
---|
3542 | int sec = 0; |
---|
3543 | |
---|
3544 | if(status.restimer == NULL) return; |
---|
3545 | sec = (int)status.restimer->param1; |
---|
3546 | |
---|
3547 | if(sec > 0) |
---|
3548 | { |
---|
3549 | while(status.restimer->aktion == START && count <= sec) |
---|
3550 | { |
---|
3551 | sleep(1); |
---|
3552 | if(status.restimer->aktion != START) |
---|
3553 | { |
---|
3554 | status.restimer = NULL; |
---|
3555 | return; |
---|
3556 | } |
---|
3557 | count++; |
---|
3558 | } |
---|
3559 | } |
---|
3560 | |
---|
3561 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
3562 | { |
---|
3563 | m_width = status.videosize.w; |
---|
3564 | if (m_width == 720) { |
---|
3565 | res_sd = getconfig("av_videomode_autores_sd", NULL); |
---|
3566 | if(res_sd == NULL) |
---|
3567 | res = ostrcat(res, "576i50", 1, 0); |
---|
3568 | else |
---|
3569 | res = ostrcat(res, res_sd, 1, 0); |
---|
3570 | } |
---|
3571 | else if (m_width == 1280) |
---|
3572 | res = ostrcat(res, "720p50", 1, 0); |
---|
3573 | else if (m_width == 1920) |
---|
3574 | res = ostrcat(res, "1080i50", 1, 0); |
---|
3575 | else |
---|
3576 | m_width = 0; |
---|
3577 | if ( m_width > 0) |
---|
3578 | { |
---|
3579 | res_akt = getvideomode(); |
---|
3580 | if (ostrcmp(res_akt, res) != 0) |
---|
3581 | { |
---|
3582 | setvideomode(res); |
---|
3583 | changefbresolution(res); |
---|
3584 | sleep(1); |
---|
3585 | screenautores(res, 5, 0); |
---|
3586 | } |
---|
3587 | } |
---|
3588 | } |
---|
3589 | else |
---|
3590 | textbox(_("Message"), _("ERROR cant read res"), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
3591 | |
---|
3592 | free(res); |
---|
3593 | res = NULL; |
---|
3594 | status.restimer = NULL; |
---|
3595 | return; |
---|
3596 | } |
---|
3597 | |
---|
3598 | #endif |
---|