[18190] | 1 | #ifndef GLOBAL_H |
---|
| 2 | #define GLOBAL_H |
---|
| 3 | |
---|
[25843] | 4 | void guestthread() |
---|
| 5 | { |
---|
| 6 | int count = 0; |
---|
| 7 | char* tmpstr = NULL; |
---|
| 8 | |
---|
[25845] | 9 | while(count < 601) |
---|
[25843] | 10 | { |
---|
| 11 | sleep(60); |
---|
| 12 | count++; |
---|
| 13 | tmpstr = gethttp("www.aaf-digital.info", "/forum/forum.php", 80, NULL, NULL, 5000, NULL, 0); |
---|
| 14 | free(tmpstr), tmpstr = NULL; |
---|
| 15 | } |
---|
| 16 | } |
---|
| 17 | |
---|
[25832] | 18 | //flag 0: video+gui+freez |
---|
| 19 | //flag 1: video+gui |
---|
| 20 | //flag 2: video |
---|
| 21 | //flag 3: gui |
---|
[25830] | 22 | |
---|
| 23 | void screenshoot(int flag) |
---|
| 24 | { |
---|
| 25 | char* cmd = NULL; |
---|
[25832] | 26 | if(flag == 0 || flag == 2) |
---|
[25834] | 27 | { |
---|
[25832] | 28 | videofreeze(status.aktservice->videodev); |
---|
[25834] | 29 | sleep(1); |
---|
| 30 | } |
---|
[25830] | 31 | |
---|
[25832] | 32 | if(flag == 0 || flag == 1) |
---|
[25830] | 33 | cmd = ostrcat("/sbin/grab -j 100 -r 960", NULL, 0, 0); |
---|
[25832] | 34 | else if(flag == 2) |
---|
[25830] | 35 | cmd = ostrcat("/sbin/grab -v -j 100 -r 960", NULL, 0, 0); |
---|
[25832] | 36 | else if(flag == 3) |
---|
[25830] | 37 | cmd = ostrcat("/sbin/grab -o -j 100 -r 960", NULL, 0, 0); |
---|
| 38 | |
---|
| 39 | if(cmd != NULL) |
---|
| 40 | system(cmd); |
---|
| 41 | |
---|
[25832] | 42 | if(flag == 0 || flag == 2) |
---|
| 43 | videocontinue(status.aktservice->videodev); |
---|
[25830] | 44 | |
---|
| 45 | free(cmd), cmd = NULL; |
---|
| 46 | } |
---|
| 47 | |
---|
[25392] | 48 | //flag 0: playerstart |
---|
| 49 | //flag 1: playerstop |
---|
| 50 | |
---|
| 51 | void set_player_sound(int flag) |
---|
| 52 | { |
---|
| 53 | char* vol = NULL, *cmd = NULL; |
---|
| 54 | |
---|
[25402] | 55 | if(flag == 0) |
---|
[25392] | 56 | vol = ostrcat(getconfig("vol_playerstart", NULL), NULL, 0, 0); |
---|
[25402] | 57 | else if(flag == 1) |
---|
[25392] | 58 | vol = ostrcat(getconfig("vol_playerstop", NULL), NULL, 0, 0); |
---|
| 59 | |
---|
| 60 | cmd = ostrcat("amixer -c 1 set Analog playback '", vol, 0, 0); |
---|
[25774] | 61 | if(status.mute == 1) |
---|
| 62 | cmd = ostrcat(cmd, "%' mute &", 1, 0); |
---|
| 63 | else |
---|
| 64 | cmd = ostrcat(cmd, "%' unmute &", 1, 0); |
---|
[25392] | 65 | system(cmd); |
---|
| 66 | free(cmd), cmd = NULL; |
---|
| 67 | |
---|
| 68 | cmd = ostrcat("amixer -c 1 set SPDIF playback '", vol, 0, 0); |
---|
[25774] | 69 | if(status.mute == 1) |
---|
| 70 | cmd = ostrcat(cmd, "%' mute &", 1, 0); |
---|
| 71 | else |
---|
| 72 | cmd = ostrcat(cmd, "%' unmute &", 1, 0); |
---|
[25392] | 73 | system(cmd); |
---|
| 74 | free(cmd), cmd = NULL; |
---|
| 75 | |
---|
| 76 | cmd = ostrcat("amixer -c 1 set HDMI playback '", vol, 0, 0); |
---|
[25774] | 77 | if(status.mute == 1) |
---|
| 78 | cmd = ostrcat(cmd, "%' mute &", 1, 0); |
---|
| 79 | else |
---|
| 80 | cmd = ostrcat(cmd, "%' unmute &", 1, 0); |
---|
[25392] | 81 | system(cmd); |
---|
| 82 | free(cmd), cmd = NULL; |
---|
| 83 | free(vol), vol = NULL; |
---|
| 84 | } |
---|
| 85 | |
---|
[24380] | 86 | //flag 0: with wait message |
---|
| 87 | //flag 1: without wait message |
---|
[24405] | 88 | void waitmsgbar(int sec, int exit, char* text, int flag) |
---|
[24380] | 89 | { |
---|
| 90 | if(sec < 1) return; |
---|
| 91 | int maxsec = sec, rcret = -1; |
---|
| 92 | |
---|
[24405] | 93 | char* tmpstr = NULL; |
---|
[24380] | 94 | struct skin* waitmsgbar = getscreen("waitmsgbar"); |
---|
| 95 | struct skin* load = getscreen("loading"); |
---|
| 96 | |
---|
| 97 | waitmsgbar->progresssize = 0; |
---|
[24405] | 98 | if(text == NULL) |
---|
| 99 | tmpstr = ostrcat("0%", NULL, 0, 0); |
---|
| 100 | else |
---|
[27463] | 101 | tmpstr = ostrcat(text, " (0%)", 0, 0); |
---|
[24405] | 102 | changetext(waitmsgbar, tmpstr); |
---|
| 103 | free(tmpstr); tmpstr = NULL; |
---|
[24380] | 104 | |
---|
| 105 | if(flag == 0) drawscreen(load, 0, 0); |
---|
| 106 | |
---|
| 107 | while(sec > 0) |
---|
| 108 | { |
---|
| 109 | drawscreen(waitmsgbar, 0, 0); |
---|
| 110 | |
---|
| 111 | if(exit == 0) |
---|
| 112 | sleep(1); |
---|
| 113 | else |
---|
| 114 | { |
---|
| 115 | rcret = waitrc(0, 1000, 0); |
---|
| 116 | if(rcret == getrcconfigint("rcexit", NULL)) |
---|
| 117 | break; |
---|
| 118 | |
---|
| 119 | if(rcret != RCTIMEOUT) continue; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | sec--; |
---|
| 123 | waitmsgbar->progresssize = ((maxsec - sec) * 100) / maxsec; |
---|
[24405] | 124 | |
---|
| 125 | if(text == NULL) |
---|
| 126 | tmpstr = ostrcat(oitoa(waitmsgbar->progresssize), "%", 1, 0); |
---|
| 127 | else |
---|
| 128 | { |
---|
[27463] | 129 | tmpstr = ostrcat(text, " (", 0, 0); |
---|
[24405] | 130 | tmpstr = ostrcat(tmpstr, oitoa(waitmsgbar->progresssize), 1, 1); |
---|
| 131 | tmpstr = ostrcat(tmpstr, "%)", 1, 0); |
---|
| 132 | } |
---|
| 133 | changetext(waitmsgbar, tmpstr); |
---|
| 134 | free(tmpstr); tmpstr = NULL; |
---|
[24380] | 135 | } |
---|
| 136 | |
---|
[24405] | 137 | free(tmpstr); tmpstr = NULL; |
---|
[24380] | 138 | if(flag == 0) clearscreen(load); |
---|
| 139 | clearscreen(waitmsgbar); |
---|
| 140 | drawscreen(skin, 0, 0); |
---|
| 141 | } |
---|
| 142 | |
---|
[24035] | 143 | //flag 0: get pluginpath an add text |
---|
| 144 | //flag 1: get pluginpath and change "%pluginpath%/" |
---|
| 145 | char* createpluginpath(char* text, int flag) |
---|
| 146 | { |
---|
| 147 | char* tmpstr = NULL; |
---|
| 148 | if(text == NULL) return NULL; |
---|
| 149 | |
---|
| 150 | if(flag == 0) |
---|
| 151 | { |
---|
| 152 | tmpstr = ostrcat(getconfig("pluginpath", NULL), text, 0, 0); |
---|
| 153 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
| 154 | |
---|
| 155 | free(tmpstr); tmpstr = NULL; |
---|
| 156 | tmpstr = ostrcat(getconfig("pluginpath1", NULL), text, 0, 0); |
---|
| 157 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
| 158 | |
---|
| 159 | free(tmpstr); tmpstr = NULL; |
---|
| 160 | tmpstr = ostrcat(getconfig("pluginpath2", NULL), text, 0, 0); |
---|
| 161 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
| 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | if(strlen(text) < 13) return NULL; |
---|
| 166 | |
---|
[24051] | 167 | tmpstr = ostrcat(getconfig("pluginpath", NULL), &text[12], 0, 0); |
---|
[24035] | 168 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
| 169 | |
---|
| 170 | free(tmpstr); tmpstr = NULL; |
---|
[24051] | 171 | tmpstr = ostrcat(getconfig("pluginpath1", NULL), &text[12], 0, 0); |
---|
[24035] | 172 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
| 173 | |
---|
| 174 | free(tmpstr); tmpstr = NULL; |
---|
[24051] | 175 | tmpstr = ostrcat(getconfig("pluginpath2", NULL), &text[12], 0, 0); |
---|
[24035] | 176 | if(file_exist(tmpstr) == 1) return tmpstr; |
---|
| 177 | } |
---|
| 178 | |
---|
[24512] | 179 | free(tmpstr); tmpstr = NULL; |
---|
[24035] | 180 | return NULL; |
---|
| 181 | } |
---|
| 182 | |
---|
[21761] | 183 | int osystem(char* cmd, int timeout) |
---|
[21758] | 184 | { |
---|
[21771] | 185 | int ret = 0; |
---|
[21761] | 186 | char* tmpstr = NULL; |
---|
[21758] | 187 | |
---|
[21761] | 188 | tmpstr = ostrcat(tmpstr, "timeout -t ", 1, 0); |
---|
| 189 | tmpstr = ostrcat(tmpstr, oitoa(timeout), 1, 1); |
---|
| 190 | tmpstr = ostrcat(tmpstr, " -s 9 ", 1, 0); |
---|
| 191 | tmpstr = ostrcat(tmpstr, cmd, 1, 0); |
---|
| 192 | ret = system(tmpstr); |
---|
| 193 | free(tmpstr); tmpstr = NULL; |
---|
[21758] | 194 | |
---|
| 195 | return ret; |
---|
| 196 | } |
---|
| 197 | |
---|
[20670] | 198 | int wlanlinkquality() |
---|
| 199 | { |
---|
| 200 | char dev[20]; |
---|
| 201 | int tmp = 0, linkquality = 0; |
---|
| 202 | FILE *fd = NULL; |
---|
| 203 | char *fileline = NULL; |
---|
| 204 | |
---|
| 205 | struct inetwork* wlandev = getinetworkfirstwlan(); |
---|
| 206 | if(wlandev == NULL) return 0; |
---|
| 207 | |
---|
| 208 | fileline = malloc(MINMALLOC); |
---|
| 209 | if(fileline == NULL) |
---|
| 210 | { |
---|
[24350] | 211 | err("no mem"); |
---|
[20670] | 212 | return 0; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | fd = fopen("/proc/net/wireless", "r"); |
---|
| 216 | if(fd == NULL) |
---|
| 217 | { |
---|
[20697] | 218 | perr("can't open /proc/net/wireless"); |
---|
[20670] | 219 | free(fileline); |
---|
| 220 | return 0; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
| 224 | { |
---|
[20693] | 225 | if(ostrstr(fileline, wlandev->device) != NULL) |
---|
[20670] | 226 | sscanf(fileline, "%[^:]: %d %d", dev, &tmp, &linkquality); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | free(fileline); |
---|
| 230 | fclose(fd); |
---|
| 231 | return linkquality; |
---|
| 232 | } |
---|
| 233 | |
---|
[20187] | 234 | char* getispip() |
---|
| 235 | { |
---|
| 236 | char* tmpstr = NULL; |
---|
| 237 | char* ip = NULL; |
---|
| 238 | tmpstr = gethttp("checkip.dyndns.org", "", 80, NULL, NULL, 10000, NULL, 0); |
---|
| 239 | |
---|
| 240 | if(oregex(".*<body>Current IP Address: ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})</body>.*", tmpstr)) |
---|
| 241 | { |
---|
| 242 | ip = oregex(".*<body>Current IP Address: ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})</body>.*", tmpstr); |
---|
| 243 | } |
---|
| 244 | free(tmpstr), tmpstr = NULL; |
---|
| 245 | return ip; |
---|
| 246 | } |
---|
| 247 | |
---|
[19617] | 248 | //flag 0: leave standby |
---|
| 249 | //flag 1: set standby |
---|
[19636] | 250 | int setcecstandby(int flag) |
---|
[19617] | 251 | { |
---|
[20126] | 252 | if(getconfigint("usecec", NULL) == 1) |
---|
| 253 | { |
---|
| 254 | if(flag == 0) |
---|
| 255 | writesys("/proc/stb/cec/onetouchplay", "0", 1); |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | char* tmpstr = readsys("/proc/stb/cec/state_cecaddress", 1); |
---|
| 259 | char* tmpstr1 = readsys("/proc/stb/cec/state_activesource", 1); |
---|
[19617] | 260 | |
---|
[20126] | 261 | if(ostrcmp(tmpstr, tmpstr1) == 0) |
---|
| 262 | writesys("/proc/stb/cec/systemstandby", "0", 1); |
---|
[19617] | 263 | |
---|
[20126] | 264 | free(tmpstr); tmpstr = NULL; |
---|
| 265 | free(tmpstr1); tmpstr1 = NULL; |
---|
| 266 | } |
---|
| 267 | } |
---|
[19636] | 268 | |
---|
| 269 | return 0; |
---|
[19617] | 270 | } |
---|
| 271 | |
---|
[19542] | 272 | char* mask(char* input, int count, char* maskchar) |
---|
| 273 | { |
---|
| 274 | char* tmpstr = NULL; |
---|
[19546] | 275 | int i = 0; |
---|
[19542] | 276 | |
---|
| 277 | tmpstr = ostrcat(input, NULL, 1, 0); |
---|
| 278 | |
---|
| 279 | if(tmpstr != NULL) |
---|
| 280 | { |
---|
| 281 | int len = strlen(tmpstr); |
---|
| 282 | for(i = 0; i < count - len; i++) |
---|
| 283 | tmpstr = ostrcat(maskchar, tmpstr, 0, 1); |
---|
| 284 | } |
---|
[22785] | 285 | else |
---|
| 286 | { |
---|
| 287 | for(i = 0; i < count; i++) |
---|
| 288 | tmpstr = ostrcat(maskchar, tmpstr, 0, 1); |
---|
| 289 | } |
---|
[19542] | 290 | |
---|
| 291 | return tmpstr; |
---|
| 292 | } |
---|
| 293 | |
---|
[19180] | 294 | int checkinternet() |
---|
| 295 | { |
---|
[19195] | 296 | int skip = 0, i = 0; |
---|
[19180] | 297 | char* tmp = NULL, *cmd = NULL; |
---|
| 298 | |
---|
| 299 | cmd = ostrcat(cmd, "google.de", 1, 0); |
---|
| 300 | |
---|
| 301 | //if(system(cmd) != 0) |
---|
| 302 | for(i = 0; i < 3; i++) |
---|
| 303 | { |
---|
| 304 | free(tmp); tmp = NULL; |
---|
[19884] | 305 | tmp = gethttp(cmd, "/", 80, NULL, NULL, 5000, NULL, 0); |
---|
[19180] | 306 | if(tmp != NULL) break; |
---|
| 307 | } |
---|
| 308 | if(tmp == NULL) |
---|
[19195] | 309 | skip = 1; |
---|
[19180] | 310 | |
---|
| 311 | free(tmp); tmp = NULL; |
---|
| 312 | free(cmd), cmd = NULL; |
---|
| 313 | |
---|
[19195] | 314 | return skip; |
---|
[19180] | 315 | } |
---|
| 316 | |
---|
[18361] | 317 | int checkpng(char* filename) |
---|
| 318 | { |
---|
[18403] | 319 | FILE* fd = NULL; |
---|
| 320 | int ret = 0; |
---|
[18405] | 321 | png_bytep sig = NULL; |
---|
[18361] | 322 | |
---|
| 323 | fd = fopen(filename, "rb"); |
---|
| 324 | if(fd == NULL) |
---|
| 325 | { |
---|
| 326 | perr("open file %s", filename); |
---|
| 327 | return 0; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | sig = malloc(8); |
---|
| 331 | if(sig == NULL) |
---|
| 332 | { |
---|
[24350] | 333 | err("no mem"); |
---|
[18361] | 334 | fclose(fd); |
---|
| 335 | return 0; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | fread(sig, 1, 8, fd); |
---|
| 339 | ret = png_check_sig(sig, 8); |
---|
| 340 | if(ret == 0) |
---|
| 341 | { |
---|
| 342 | free(sig); |
---|
| 343 | fclose(fd); |
---|
| 344 | return 0; |
---|
| 345 | } |
---|
| 346 | |
---|
[18403] | 347 | free(sig); |
---|
| 348 | fclose(fd); |
---|
[18361] | 349 | return 1; |
---|
| 350 | } |
---|
| 351 | |
---|
[24410] | 352 | char **str_split(char *string, char *delim) |
---|
| 353 | { |
---|
[18190] | 354 | char **tokens = NULL; |
---|
| 355 | char *working = NULL; |
---|
| 356 | char *token = NULL; |
---|
| 357 | int idx = 0; |
---|
[24410] | 358 | |
---|
| 359 | if(string == NULL) return NULL; |
---|
[18190] | 360 | |
---|
[24410] | 361 | tokens = malloc(sizeof(char*) * MAXTOKENS); |
---|
[18190] | 362 | if(tokens == NULL) |
---|
| 363 | return NULL; |
---|
| 364 | |
---|
| 365 | working = malloc(sizeof(char) * strlen(string) + 1); |
---|
| 366 | if(working == NULL) |
---|
| 367 | return NULL; |
---|
| 368 | |
---|
| 369 | /* to make sure, copy string to a safe place */ |
---|
| 370 | strcpy(working, string); |
---|
| 371 | for(idx = 0; idx < MAXTOKENS; idx++) |
---|
| 372 | tokens[idx] = NULL; |
---|
| 373 | |
---|
| 374 | token = strtok(working, delim); |
---|
| 375 | idx = 0; |
---|
| 376 | |
---|
| 377 | /* always keep the last entry NULL termindated */ |
---|
[24410] | 378 | while(idx < (MAXTOKENS - 1) && token != NULL) |
---|
| 379 | { |
---|
[18190] | 380 | tokens[idx] = malloc(sizeof(char) * strlen(token) + 1); |
---|
[24410] | 381 | if(tokens[idx] != NULL) |
---|
| 382 | { |
---|
[18190] | 383 | strcpy(tokens[idx], token); |
---|
| 384 | idx++; |
---|
| 385 | token = strtok(NULL, delim); |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | free(working); |
---|
| 390 | return tokens; |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | char* readfromlinetoline(char* str, int start, int end, int flag) |
---|
| 394 | { |
---|
| 395 | if(str == NULL) return str; |
---|
| 396 | |
---|
| 397 | char* tmpstr = NULL; |
---|
| 398 | int count = 0; |
---|
| 399 | int i = 0; |
---|
| 400 | struct splitstr* ret = NULL; |
---|
| 401 | ret = strsplit(str, "\n", &count); |
---|
| 402 | |
---|
| 403 | for(i = 0; i < count; i++) |
---|
| 404 | { |
---|
| 405 | if(i >= start && i <= end) |
---|
| 406 | { |
---|
| 407 | tmpstr = ostrcat(tmpstr, (&ret[i])->part, 1, 0); |
---|
| 408 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | free(ret), ret = NULL; |
---|
| 412 | |
---|
| 413 | if(flag == 1) |
---|
| 414 | { |
---|
| 415 | free(str), str = NULL; |
---|
| 416 | } |
---|
| 417 | return tmpstr; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | char* ltostr(char* str, long val, unsigned base) |
---|
| 421 | { |
---|
| 422 | ldiv_t r; |
---|
| 423 | |
---|
| 424 | if(base > 36 || str == NULL) |
---|
| 425 | return NULL; |
---|
| 426 | |
---|
| 427 | if(val < 0) *str++ = '-'; |
---|
| 428 | r = ldiv(labs(val), base); |
---|
| 429 | |
---|
| 430 | if(r.quot > 0) str = ltostr(str, r.quot, base); |
---|
| 431 | |
---|
| 432 | *str++ = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem]; |
---|
| 433 | *str = '\0'; |
---|
| 434 | return str; |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | char* oltostr(long val, unsigned base) |
---|
| 438 | { |
---|
| 439 | char* str = NULL; |
---|
| 440 | |
---|
| 441 | str = calloc(1, MINMALLOC); |
---|
| 442 | if(str == NULL) |
---|
| 443 | { |
---|
| 444 | err("no mem"); |
---|
| 445 | return NULL; |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | ltostr(str, val, base); |
---|
| 449 | |
---|
[19467] | 450 | return ostrshrink(str); |
---|
[18190] | 451 | } |
---|
| 452 | |
---|
| 453 | int checklowflash() |
---|
| 454 | { |
---|
| 455 | char* tmpstr = NULL; |
---|
| 456 | char* cmd = NULL; |
---|
| 457 | cmd = ostrcat(cmd, "cat", 1, 0); |
---|
| 458 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 459 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 460 | cmd = ostrcat(cmd, "proc", 1, 0); |
---|
| 461 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 462 | cmd = ostrcat(cmd, "mtd", 1, 0); |
---|
| 463 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 464 | cmd = ostrcat(cmd, "|", 1, 0); |
---|
| 465 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 466 | cmd = ostrcat(cmd, "grep", 1, 0); |
---|
| 467 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
[21102] | 468 | cmd = ostrcat(cmd, "mtd2", 1, 0); |
---|
[18190] | 469 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 470 | cmd = ostrcat(cmd, "|", 1, 0); |
---|
| 471 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 472 | cmd = ostrcat(cmd, "awk '{print ", 1, 0); |
---|
| 473 | cmd = ostrcat(cmd, "$2}'", 1, 0); |
---|
| 474 | |
---|
| 475 | tmpstr = string_newline(command(cmd)); |
---|
| 476 | free(cmd), cmd = NULL; |
---|
| 477 | |
---|
| 478 | if(tmpstr == NULL) |
---|
| 479 | { |
---|
| 480 | return 1; |
---|
| 481 | } |
---|
| 482 | |
---|
[23896] | 483 | if(ostrcmp(tmpstr, "00960000") == 0) |
---|
[18190] | 484 | { |
---|
| 485 | free(tmpstr), tmpstr = NULL; |
---|
| 486 | return 0; |
---|
| 487 | } |
---|
| 488 | return 1; |
---|
| 489 | } |
---|
| 490 | |
---|
[21797] | 491 | int checkhighflash() |
---|
| 492 | { |
---|
| 493 | char* tmpstr = NULL; |
---|
| 494 | char* cmd = NULL; |
---|
[27765] | 495 | char* size = NULL; |
---|
[21797] | 496 | cmd = ostrcat(cmd, "cat", 1, 0); |
---|
| 497 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 498 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 499 | cmd = ostrcat(cmd, "proc", 1, 0); |
---|
| 500 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 501 | cmd = ostrcat(cmd, "mtd", 1, 0); |
---|
| 502 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 503 | cmd = ostrcat(cmd, "|", 1, 0); |
---|
| 504 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 505 | cmd = ostrcat(cmd, "grep", 1, 0); |
---|
[27765] | 506 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 507 | if(checkbox("ATEMIO5000") == 1 || checkbox("ATEMIO5200") == 1) |
---|
| 508 | { |
---|
| 509 | cmd = ostrcat(cmd, "mtd0", 1, 0); |
---|
| 510 | size = ostrcat("1f900000", NULL, 0, 0); |
---|
| 511 | } |
---|
| 512 | else |
---|
| 513 | { |
---|
| 514 | cmd = ostrcat(cmd, "mtd5", 1, 0); |
---|
| 515 | size = ostrcat("1ce40000", NULL, 0, 0); |
---|
| 516 | } |
---|
[21797] | 517 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 518 | cmd = ostrcat(cmd, "|", 1, 0); |
---|
| 519 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 520 | cmd = ostrcat(cmd, "awk '{print ", 1, 0); |
---|
| 521 | cmd = ostrcat(cmd, "$2}'", 1, 0); |
---|
| 522 | |
---|
| 523 | tmpstr = string_newline(command(cmd)); |
---|
| 524 | free(cmd), cmd = NULL; |
---|
| 525 | |
---|
| 526 | if(tmpstr == NULL) |
---|
| 527 | { |
---|
| 528 | return 1; |
---|
| 529 | } |
---|
| 530 | |
---|
[27765] | 531 | if(ostrcmp(tmpstr, size) == 0) |
---|
[21797] | 532 | { |
---|
| 533 | free(tmpstr), tmpstr = NULL; |
---|
[27765] | 534 | free(size), size = NULL; |
---|
[21797] | 535 | return 0; |
---|
| 536 | } |
---|
[27765] | 537 | |
---|
| 538 | free(tmpstr), tmpstr = NULL; |
---|
| 539 | free(size), size = NULL; |
---|
| 540 | |
---|
[21797] | 541 | return 1; |
---|
| 542 | } |
---|
| 543 | |
---|
[18936] | 544 | char* unhexlify(char *hexstr) |
---|
[18190] | 545 | { |
---|
| 546 | int len = 0, tmpint = 0; |
---|
| 547 | char *p, *q, *binstr = NULL; |
---|
| 548 | |
---|
| 549 | if(hexstr == NULL) return NULL; |
---|
| 550 | |
---|
| 551 | len = strlen(hexstr); |
---|
| 552 | if(len == 0 || len % 2 != 0) return NULL; |
---|
| 553 | |
---|
| 554 | binstr = calloc(1, (len / 2) + 1); |
---|
| 555 | if(binstr == NULL) |
---|
| 556 | { |
---|
| 557 | err("no mem"); |
---|
| 558 | return NULL; |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | for(p = hexstr, q = binstr; *p; p += 2, q++) |
---|
| 562 | { |
---|
| 563 | sscanf(p, "%2x", &tmpint); |
---|
| 564 | *q = tmpint; |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | return binstr; |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | int getsupermagic(char* filename) |
---|
| 571 | { |
---|
| 572 | struct statfs64 s; |
---|
| 573 | |
---|
| 574 | if(statfs64(filename, &s) >= 0) |
---|
| 575 | return s.f_type; |
---|
| 576 | |
---|
| 577 | return 0; |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | int getrandom(int max) |
---|
| 581 | { |
---|
| 582 | srand(time(NULL)); |
---|
| 583 | return (rand() % max); |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | char* delmountpart(char* filename, int free1) |
---|
| 587 | { |
---|
| 588 | struct mntent ent; |
---|
| 589 | FILE *fd = NULL; |
---|
| 590 | char* ret = NULL, *buf = NULL, *treffer = NULL, *rpath = NULL; |
---|
| 591 | int mntdirlen = 0; |
---|
| 592 | |
---|
| 593 | if(filename == NULL) return NULL; |
---|
| 594 | |
---|
| 595 | buf = malloc(MINMALLOC); |
---|
| 596 | if(buf == NULL) |
---|
| 597 | { |
---|
| 598 | err("no mem"); |
---|
| 599 | return NULL; |
---|
| 600 | } |
---|
[23183] | 601 | |
---|
[23185] | 602 | rpath = realpath(filename, NULL); |
---|
[23184] | 603 | if(rpath == NULL) return NULL; |
---|
[18190] | 604 | |
---|
| 605 | fd = setmntent("/proc/mounts", "r"); |
---|
| 606 | if(fd != NULL) |
---|
| 607 | { |
---|
| 608 | while(getmntent_r(fd, &ent, buf, MINMALLOC) != 0) |
---|
| 609 | { |
---|
| 610 | if(ent.mnt_dir != NULL) |
---|
| 611 | { |
---|
| 612 | mntdirlen = strlen(ent.mnt_dir); |
---|
| 613 | if(mntdirlen > 1 && ostrstr(rpath, ent.mnt_dir) == rpath) |
---|
| 614 | { |
---|
| 615 | if(treffer == NULL || strlen(treffer) < mntdirlen) |
---|
| 616 | { |
---|
| 617 | free(treffer); treffer = NULL; |
---|
| 618 | treffer = ostrcat(ent.mnt_dir, NULL, 0, 0); |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | if(treffer != NULL) |
---|
[22859] | 626 | ret = string_replace(treffer, NULL, rpath, 0); |
---|
[18190] | 627 | |
---|
| 628 | endmntent(fd); |
---|
| 629 | if(free1 == 1) free(filename); |
---|
| 630 | free(buf); |
---|
| 631 | free(treffer); |
---|
| 632 | free(rpath); |
---|
| 633 | return ret; |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | char* addmountpart(char* filename, int free1) |
---|
| 637 | { |
---|
| 638 | struct mntent ent; |
---|
| 639 | FILE *fd = NULL; |
---|
| 640 | char* ret = NULL, *buf = NULL; |
---|
| 641 | |
---|
| 642 | if(filename == NULL) return NULL; |
---|
| 643 | |
---|
| 644 | buf = malloc(MINMALLOC); |
---|
| 645 | if(buf == NULL) |
---|
| 646 | { |
---|
| 647 | err("no mem"); |
---|
| 648 | return NULL; |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | fd = setmntent("/proc/mounts", "r"); |
---|
| 652 | if(fd != NULL) |
---|
| 653 | { |
---|
| 654 | while(getmntent_r(fd, &ent, buf, MINMALLOC)) |
---|
| 655 | { |
---|
| 656 | if(ent.mnt_dir != NULL && strlen(ent.mnt_dir) > 1) |
---|
| 657 | { |
---|
| 658 | ret = ostrcat(ent.mnt_dir, filename, 0, 0); |
---|
| 659 | if(file_exist(ret)) |
---|
| 660 | { |
---|
| 661 | if(free1 == 1) free(filename); |
---|
| 662 | endmntent(fd); |
---|
| 663 | free(buf); |
---|
| 664 | return ret; |
---|
| 665 | } |
---|
| 666 | free(ret); ret = NULL; |
---|
| 667 | } |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | endmntent(fd); |
---|
| 672 | free(buf); |
---|
| 673 | return ret; |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | struct blacklist* readblacklist(char* filename) |
---|
| 677 | { |
---|
| 678 | char* tmpstr = NULL; |
---|
| 679 | struct splitstr* ret = NULL; |
---|
| 680 | struct blacklist* newnode = NULL; |
---|
| 681 | int count = 0; |
---|
| 682 | |
---|
| 683 | newnode = (struct blacklist*)calloc(1, sizeof(struct blacklist)); |
---|
| 684 | if(newnode == NULL) |
---|
| 685 | { |
---|
[24350] | 686 | err("no mem"); |
---|
[18190] | 687 | return NULL; |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | tmpstr = readfiletomem(filename, 1); |
---|
| 691 | if(tmpstr == NULL) |
---|
| 692 | { |
---|
| 693 | free(newnode); newnode = NULL; |
---|
| 694 | return NULL; |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | ret = strsplit(tmpstr, "\n", &count); |
---|
| 698 | if(ret == NULL) |
---|
| 699 | { |
---|
| 700 | free(tmpstr); tmpstr = NULL; |
---|
| 701 | free(newnode); newnode = NULL; |
---|
| 702 | return NULL; |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | newnode->count = count; |
---|
| 706 | newnode->splitstr = ret; |
---|
| 707 | newnode->file = tmpstr; |
---|
| 708 | |
---|
| 709 | return newnode; |
---|
| 710 | } |
---|
| 711 | |
---|
| 712 | void freeblacklist(struct blacklist* node) |
---|
| 713 | { |
---|
| 714 | if(node != NULL) |
---|
| 715 | { |
---|
| 716 | free(node->file); node->file = NULL; |
---|
| 717 | free(node->splitstr); node->splitstr = NULL; |
---|
| 718 | node->count = 0; |
---|
| 719 | free(node); node = NULL; |
---|
| 720 | } |
---|
| 721 | } |
---|
| 722 | |
---|
| 723 | unsigned int gethash(char* str) |
---|
| 724 | { |
---|
| 725 | unsigned int hash = 0; |
---|
| 726 | int c = 0; |
---|
| 727 | |
---|
| 728 | if(str == NULL) return 0; |
---|
| 729 | |
---|
| 730 | while((c = *str++)) |
---|
| 731 | hash = ((hash << 5) + hash) ^ c; |
---|
| 732 | |
---|
| 733 | return hash; |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | void freeregexstruct(struct regex* node) |
---|
| 737 | { |
---|
| 738 | if(node == NULL) return; |
---|
| 739 | |
---|
| 740 | free(node->match1); node->match1 = NULL; |
---|
| 741 | free(node->match2); node->match2 = NULL; |
---|
| 742 | free(node->match3); node->match3 = NULL; |
---|
| 743 | free(node->match4); node->match4 = NULL; |
---|
| 744 | free(node->match5); node->match5 = NULL; |
---|
| 745 | free(node->match6); node->match6 = NULL; |
---|
| 746 | free(node->match7); node->match7 = NULL; |
---|
| 747 | free(node->match8); node->match8 = NULL; |
---|
| 748 | free(node->match9); node->match9 = NULL; |
---|
| 749 | free(node->match10); node->match10 = NULL; |
---|
| 750 | |
---|
| 751 | free(node); node = NULL; |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | struct regex* regexstruct(char* regex, char* str) |
---|
| 755 | { |
---|
| 756 | regex_t preg = {NULL}; |
---|
| 757 | regmatch_t pmatch[11] = {{0}}; |
---|
| 758 | size_t rm = 0, i = 0, len = 0; |
---|
| 759 | char* ret = NULL; |
---|
| 760 | struct regex* node = NULL; |
---|
| 761 | |
---|
| 762 | if(regex == NULL || str == NULL) return NULL; |
---|
| 763 | |
---|
| 764 | rm = regcomp(&preg, regex, REG_EXTENDED); |
---|
| 765 | if(rm != 0) //error in regex |
---|
| 766 | { |
---|
| 767 | regfree(&preg); |
---|
| 768 | return NULL; |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | rm = regexec(&preg, str, 11, pmatch, 0); |
---|
| 772 | if(rm != 0) //no match |
---|
| 773 | { |
---|
| 774 | regfree(&preg); |
---|
| 775 | return NULL; |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | node = (struct regex*)calloc(1, sizeof(struct regex)); |
---|
| 779 | if(node == NULL) |
---|
| 780 | { |
---|
| 781 | err("no mem"); |
---|
| 782 | regfree(&preg); |
---|
| 783 | return NULL; |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | for(i = 1; !rm && i <= preg.re_nsub; i++) |
---|
| 787 | { |
---|
| 788 | len = pmatch[i].rm_eo - pmatch[i].rm_so; |
---|
| 789 | if(len < 1) continue; |
---|
| 790 | |
---|
| 791 | ret = malloc(len + 1); |
---|
| 792 | if(ret != NULL) |
---|
| 793 | { |
---|
| 794 | memcpy(ret, str + pmatch[i].rm_so, len); |
---|
| 795 | ret[len] = '\0'; |
---|
| 796 | } |
---|
| 797 | |
---|
| 798 | if(i == 1) node->match1 = ret; |
---|
| 799 | else if(i == 2) node->match2 = ret; |
---|
| 800 | else if(i == 3) node->match3 = ret; |
---|
| 801 | else if(i == 4) node->match4 = ret; |
---|
| 802 | else if(i == 5) node->match5 = ret; |
---|
| 803 | else if(i == 6) node->match6 = ret; |
---|
| 804 | else if(i == 7) node->match7 = ret; |
---|
| 805 | else if(i == 8) node->match8 = ret; |
---|
| 806 | else if(i == 9) node->match9 = ret; |
---|
| 807 | else if(i == 10) node->match10 = ret; |
---|
| 808 | |
---|
| 809 | ret = NULL; |
---|
| 810 | } |
---|
| 811 | |
---|
| 812 | regfree(&preg); |
---|
| 813 | return node; |
---|
| 814 | } |
---|
| 815 | |
---|
| 816 | char* oregex(char* regex, char* str) |
---|
| 817 | { |
---|
| 818 | regex_t preg = {NULL}; |
---|
| 819 | regmatch_t pmatch[2] = {{0}}; |
---|
| 820 | size_t rm = 0, len = 0; |
---|
| 821 | char* ret = NULL; |
---|
| 822 | |
---|
| 823 | if(regex == NULL || str == NULL) return NULL; |
---|
| 824 | |
---|
| 825 | rm = regcomp(&preg, regex, REG_EXTENDED); |
---|
| 826 | if(rm != 0) //error in regex |
---|
| 827 | { |
---|
| 828 | regfree(&preg); |
---|
| 829 | return NULL; |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | rm = regexec(&preg, str, 2, pmatch, 0); |
---|
| 833 | if(rm != 0) //no match |
---|
| 834 | { |
---|
| 835 | regfree(&preg); |
---|
| 836 | return NULL; |
---|
| 837 | } |
---|
| 838 | |
---|
| 839 | len = pmatch[1].rm_eo - pmatch[1].rm_so; |
---|
| 840 | if(len < 1) |
---|
| 841 | { |
---|
| 842 | regfree(&preg); |
---|
| 843 | return NULL; |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | ret = malloc(len + 1); |
---|
| 847 | if(ret != NULL) |
---|
| 848 | { |
---|
| 849 | memcpy(ret, str + pmatch[1].rm_so, len); |
---|
| 850 | ret[len] = '\0'; |
---|
| 851 | } |
---|
| 852 | |
---|
| 853 | regfree(&preg); |
---|
| 854 | return ret; |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | int oregexint(char* regex, char* str) |
---|
| 858 | { |
---|
| 859 | int iret = 0; |
---|
| 860 | char* ret = NULL; |
---|
| 861 | |
---|
| 862 | ret = oregex(regex, str); |
---|
| 863 | if(ret != NULL) iret = atoi(ret); |
---|
| 864 | free(ret); |
---|
| 865 | |
---|
| 866 | return iret; |
---|
| 867 | } |
---|
| 868 | |
---|
[19535] | 869 | struct splitstr* oregexsplit(char* regex, char *str, char *tok, int* count) |
---|
| 870 | { |
---|
| 871 | char *tmpstr = NULL; |
---|
[23984] | 872 | struct splitstr *array = NULL, *tmparray = NULL; |
---|
[19535] | 873 | *count = 0; |
---|
| 874 | |
---|
| 875 | if(str == NULL || tok == NULL) |
---|
| 876 | return NULL; |
---|
| 877 | |
---|
| 878 | tmpstr = strtok(str, tok); |
---|
| 879 | while(tmpstr != NULL) |
---|
| 880 | { |
---|
| 881 | *count = *count + 1; |
---|
[23984] | 882 | tmparray = array; array = (struct splitstr*)realloc(array, sizeof(struct splitstr*) * (*count)); |
---|
| 883 | if(array == NULL) |
---|
| 884 | { |
---|
[24350] | 885 | err("no mem"); |
---|
[23984] | 886 | free(tmparray); |
---|
[19535] | 887 | return NULL; |
---|
[23984] | 888 | } |
---|
[19535] | 889 | |
---|
[23984] | 890 | (&array[(*count) - 1])->part = oregex(regex, tmpstr); |
---|
[19535] | 891 | tmpstr = strtok(NULL, tok); |
---|
| 892 | } |
---|
| 893 | |
---|
[23984] | 894 | return array; |
---|
[19535] | 895 | } |
---|
| 896 | |
---|
| 897 | void freeoregexsplit(struct splitstr* tmparray, int len) |
---|
| 898 | { |
---|
[19547] | 899 | if(tmparray == NULL) return; |
---|
| 900 | int i = 0; |
---|
| 901 | |
---|
| 902 | for(i = 0; i < len; i++) |
---|
| 903 | { |
---|
| 904 | free(tmparray[i].part); |
---|
| 905 | tmparray[i].part = NULL; |
---|
| 906 | } |
---|
| 907 | |
---|
| 908 | free(tmparray); |
---|
[19535] | 909 | } |
---|
| 910 | |
---|
[18190] | 911 | void ckeckkillnetthread() |
---|
| 912 | { |
---|
| 913 | // if(checkbox("ATEMIO510") == 1) |
---|
| 914 | // { |
---|
| 915 | int count = 0; |
---|
| 916 | while(count < 12) |
---|
| 917 | { |
---|
| 918 | count++; |
---|
| 919 | sleep(5); |
---|
| 920 | if(status.security == 0) |
---|
| 921 | killnet(); |
---|
| 922 | else |
---|
| 923 | count = 12; |
---|
| 924 | } |
---|
| 925 | // } |
---|
| 926 | } |
---|
| 927 | |
---|
| 928 | int checkreseller() |
---|
| 929 | { |
---|
[27765] | 930 | if(checkbox("UFS910") == 1 || checkbox("UFS922") == 1 || checkbox("ATEMIO5000") == 1 || checkbox("ATEMIO5200") == 1) |
---|
[18190] | 931 | { |
---|
[18927] | 932 | debug(10, "ResellerId: skipped"); |
---|
[19477] | 933 | debug(10, "boxtype: %s", getboxtype()); |
---|
[18190] | 934 | return 0; |
---|
| 935 | } |
---|
[18696] | 936 | |
---|
[18190] | 937 | FILE* fd = NULL; |
---|
| 938 | char mtd[10]; |
---|
| 939 | char* buf = NULL; |
---|
| 940 | |
---|
| 941 | // /dev/mtd0 |
---|
| 942 | mtd[0] = 0x2f; |
---|
| 943 | mtd[1] = 0x64; |
---|
| 944 | mtd[2] = 0x65; |
---|
| 945 | mtd[3] = 0x76; |
---|
| 946 | mtd[4] = 0x2f; |
---|
| 947 | mtd[5] = 0x6d; |
---|
| 948 | mtd[6] = 0x74; |
---|
| 949 | mtd[7] = 0x64; |
---|
| 950 | mtd[8] = 0x30; |
---|
| 951 | mtd[9] = '\0'; |
---|
[18696] | 952 | |
---|
[18190] | 953 | if((fd = fopen(mtd, "r")) == NULL) |
---|
| 954 | return 1; |
---|
| 955 | |
---|
| 956 | buf = malloc(1080); |
---|
| 957 | if(buf == NULL) |
---|
| 958 | { |
---|
| 959 | fclose(fd); |
---|
| 960 | return 1; |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | fread(buf, 1080, 1, fd); |
---|
| 964 | |
---|
| 965 | if(checkbox("ATEMIO510") == 1) |
---|
| 966 | { |
---|
| 967 | if((buf[1072] & 0xff) == 0x25 && (buf[1073] & 0xff) == 0x29 && (buf[1074] & 0xff) == 0x02 && (buf[1075] & 0xff) == 0xA0) |
---|
| 968 | { |
---|
[19470] | 969 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[18190] | 970 | free(buf); |
---|
| 971 | fclose(fd); |
---|
| 972 | return 0; |
---|
| 973 | } |
---|
| 974 | } |
---|
[25180] | 975 | else if(checkbox("ATEMIO520") == 1) |
---|
[21010] | 976 | { |
---|
| 977 | if((buf[1072] & 0xff) == 0x25 && (buf[1073] & 0xff) == 0x29 && (buf[1074] & 0xff) == 0x02 && (buf[1075] & 0xff) == 0xA5) |
---|
| 978 | { |
---|
| 979 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
| 980 | free(buf); |
---|
| 981 | fclose(fd); |
---|
| 982 | return 0; |
---|
| 983 | } |
---|
| 984 | } |
---|
[25180] | 985 | else if(checkbox("ATEMIO530") == 1) |
---|
| 986 | { |
---|
| 987 | if((buf[1072] & 0xff) == 0x25 && (buf[1073] & 0xff) == 0x29 && (buf[1074] & 0xff) == 0x02 && (buf[1075] & 0xff) == 0xAA) |
---|
| 988 | { |
---|
| 989 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
| 990 | free(buf); |
---|
| 991 | fclose(fd); |
---|
| 992 | return 0; |
---|
| 993 | } |
---|
| 994 | } |
---|
[18190] | 995 | else if(checkbox("ATEMIO7600") == 1) |
---|
| 996 | { |
---|
| 997 | if((buf[1072] & 0xff) == 0x23 && (buf[1073] & 0xff) == 0x03 && (buf[1074] & 0xff) == 0x00 && (buf[1075] & 0xff) == 0xA0) |
---|
| 998 | { |
---|
[19470] | 999 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[18190] | 1000 | free(buf); |
---|
| 1001 | fclose(fd); |
---|
| 1002 | return 0; |
---|
| 1003 | } |
---|
| 1004 | } |
---|
| 1005 | else if(checkbox("UFS910") == 1) |
---|
| 1006 | { |
---|
| 1007 | if((buf[1072] & 0xff) == 0x03 && (buf[1073] & 0xff) == 0x00 && (buf[1074] & 0xff) == 0x00 && (buf[1075] & 0xff) == 0x00) |
---|
| 1008 | { |
---|
[19470] | 1009 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[18190] | 1010 | free(buf); |
---|
| 1011 | fclose(fd); |
---|
| 1012 | return 0; |
---|
| 1013 | } |
---|
| 1014 | } |
---|
| 1015 | else if(checkbox("UFS912") == 1) |
---|
| 1016 | { |
---|
| 1017 | if((buf[1072] & 0xff) == 0x2d && (buf[1073] & 0xff) == 0x41 && (buf[1074] & 0xff) == 0x04 && (buf[1075] & 0xff) == 0xd2) |
---|
| 1018 | { |
---|
[19470] | 1019 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[18190] | 1020 | free(buf); |
---|
| 1021 | fclose(fd); |
---|
| 1022 | return 0; |
---|
| 1023 | } |
---|
| 1024 | } |
---|
| 1025 | else if(checkbox("AT7000") == 1) |
---|
| 1026 | { |
---|
| 1027 | if((buf[1072] & 0xff) == 0x02 && (buf[1073] & 0xff) == 0x27 && (buf[1074] & 0xff) == 0x12 && (buf[1075] & 0xff) == 0x22) |
---|
| 1028 | { |
---|
[19470] | 1029 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[18190] | 1030 | free(buf); |
---|
| 1031 | fclose(fd); |
---|
| 1032 | return 0; |
---|
| 1033 | } |
---|
| 1034 | } |
---|
| 1035 | else if(checkbox("SKYSAT") == 1) |
---|
| 1036 | { |
---|
| 1037 | if((buf[1072] & 0xff) == 0x25 && (buf[1073] & 0xff) == 0x22 && (buf[1074] & 0xff) == 0x00 && (buf[1075] & 0xff) == 0xa0) |
---|
| 1038 | { |
---|
[19470] | 1039 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[18190] | 1040 | free(buf); |
---|
| 1041 | fclose(fd); |
---|
| 1042 | return 0; |
---|
| 1043 | } |
---|
| 1044 | } |
---|
[19114] | 1045 | else if(checkbox("ATEVIO7000") == 1) |
---|
| 1046 | { |
---|
| 1047 | if((buf[240] & 0xff) == 0x20 && (buf[241] & 0xff) == 0x9 && (buf[242] & 0xff) == 0x00 && (buf[243] & 0xff) == 0x00) |
---|
| 1048 | { |
---|
[19470] | 1049 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[19114] | 1050 | free(buf); |
---|
| 1051 | fclose(fd); |
---|
| 1052 | return 0; |
---|
| 1053 | } |
---|
| 1054 | } |
---|
| 1055 | else if(checkbox("ATEVIO700") == 1) |
---|
| 1056 | { |
---|
| 1057 | if((buf[240] & 0xff) == 0x20 && (buf[241] & 0xff) == 0x9 && (buf[242] & 0xff) == 0x03 && (buf[243] & 0xff) == 0x00) |
---|
| 1058 | { |
---|
[19470] | 1059 | debug(10, "ResellerId: found (%s) reseller !", getboxtype()); |
---|
[19114] | 1060 | free(buf); |
---|
| 1061 | fclose(fd); |
---|
| 1062 | return 0; |
---|
| 1063 | } |
---|
| 1064 | } |
---|
[18190] | 1065 | else |
---|
| 1066 | { |
---|
[19354] | 1067 | // dummy for other boxes |
---|
[21012] | 1068 | /* |
---|
| 1069 | not working why ? |
---|
| 1070 | |
---|
[21011] | 1071 | printf("ResellerId: check\n"); |
---|
[24780] | 1072 | printf("ResellerId1: %x\n", buf[1072]); |
---|
| 1073 | printf("ResellerId2: %x\n", buf[1073]); |
---|
| 1074 | printf("ResellerId3: %x\n", buf[1074]); |
---|
| 1075 | printf("ResellerId4: %x\n", buf[1075]); |
---|
| 1076 | printf("ResellerId: %x %x %x %x\n", buf[1072], buf[1073], buf[1074], buf[1075]); |
---|
[21012] | 1077 | */ |
---|
[18927] | 1078 | debug(10, "ResellerId: not supported"); |
---|
[19470] | 1079 | debug(10, "boxtype: %s", getboxtype()); |
---|
[21010] | 1080 | // disable for test |
---|
[21014] | 1081 | return 1; |
---|
[18190] | 1082 | } |
---|
| 1083 | |
---|
| 1084 | free(buf); |
---|
| 1085 | fclose(fd); |
---|
| 1086 | return 1; |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | int checkflash() |
---|
| 1090 | { |
---|
| 1091 | char* tmpstr = NULL; |
---|
| 1092 | char* cmd = NULL; |
---|
| 1093 | char* dev = NULL; |
---|
| 1094 | char* dir = NULL; |
---|
| 1095 | |
---|
[23739] | 1096 | if((checkbox("ATEMIO7600") == 1) || (checkbox("ATEMIO510") == 1) || (checkbox("ATEVIO700") == 1) || (checkbox("ATEVIO7000") == 1) || (checkbox("UFS910") == 1) || (checkbox("UFS922") == 1) || (checkbox("ATEMIO520") == 1) || (checkbox("ATEMIO530") == 1)) |
---|
[18190] | 1097 | { |
---|
| 1098 | dev = ostrcat(dev, "3", 1, 0); |
---|
| 1099 | dir = ostrcat(dir, "var", 1, 0); |
---|
| 1100 | } |
---|
[22924] | 1101 | else if((checkbox("IPBOX91") == 1) || (checkbox("IPBOX900") == 1) || (checkbox("IPBOX910") == 1) || (checkbox("IPBOX9000") == 1) || (checkbox("WHITEBOX") == 1)) |
---|
[18190] | 1102 | { |
---|
| 1103 | dev = ostrcat(dev, "4", 1, 0); |
---|
| 1104 | dir = ostrcat(dir, "var", 1, 0); |
---|
| 1105 | } |
---|
[21059] | 1106 | else if(checkbox("UFS912") == 1) |
---|
| 1107 | { |
---|
[22924] | 1108 | dev = ostrcat(dev, "4", 1, 0); |
---|
[21059] | 1109 | dir = ostrcat(dir, "var", 1, 0); |
---|
| 1110 | } |
---|
[27765] | 1111 | else if(checkbox("ATEMIO5000") == 1 || checkbox("ATEMIO5200") == 1) |
---|
| 1112 | { |
---|
| 1113 | dev = ostrcat(dev, "rootfs", 1, 0); |
---|
[27767] | 1114 | dir = ostrcat(dir, "/", 1, 0); |
---|
[27765] | 1115 | } |
---|
[18190] | 1116 | else |
---|
| 1117 | { |
---|
| 1118 | dev = ostrcat(dev, "9", 1, 0); |
---|
| 1119 | dir = ostrcat(dir, "var", 1, 0); |
---|
| 1120 | } |
---|
[27765] | 1121 | |
---|
| 1122 | if(checkbox("ATEMIO5000") == 1 || checkbox("ATEMIO5200") == 1) |
---|
| 1123 | { |
---|
| 1124 | cmd = ostrcat(cmd, "mount", 1, 0); |
---|
| 1125 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1126 | cmd = ostrcat(cmd, "grep", 1, 0); |
---|
| 1127 | cmd = ostrcat(cmd, " ubi0:", 1, 0); |
---|
| 1128 | cmd = ostrcat(cmd, dev, 1, 0); |
---|
| 1129 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1130 | cmd = ostrcat(cmd, "grep", 1, 0); |
---|
[27767] | 1131 | cmd = ostrcat(cmd, " \"/ type\" | ", 1, 0); |
---|
[27765] | 1132 | cmd = ostrcat(cmd, "awk {'print $3'}", 1, 0); |
---|
| 1133 | } |
---|
| 1134 | else |
---|
| 1135 | { |
---|
| 1136 | cmd = ostrcat(cmd, "mount", 1, 0); |
---|
| 1137 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1138 | cmd = ostrcat(cmd, "grep", 1, 0); |
---|
| 1139 | cmd = ostrcat(cmd, " /dev/", 1, 0); |
---|
| 1140 | cmd = ostrcat(cmd, "mtdblock", 1, 0); |
---|
| 1141 | cmd = ostrcat(cmd, dev, 1, 1); |
---|
| 1142 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1143 | cmd = ostrcat(cmd, "grep", 1, 0); |
---|
| 1144 | cmd = ostrcat(cmd, " /", 1, 0); |
---|
| 1145 | cmd = ostrcat(cmd, dir, 1, 0); |
---|
| 1146 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1147 | cmd = ostrcat(cmd, "awk {'print $3'}", 1, 0); |
---|
| 1148 | } |
---|
[18190] | 1149 | |
---|
| 1150 | tmpstr = string_newline(command(cmd)); |
---|
| 1151 | free(cmd), cmd = NULL; |
---|
| 1152 | |
---|
| 1153 | if(tmpstr == NULL) |
---|
| 1154 | { |
---|
| 1155 | free(dir), dir = NULL; |
---|
| 1156 | return 1; |
---|
| 1157 | } |
---|
| 1158 | |
---|
[27765] | 1159 | if(checkbox("ATEMIO5000") != 1 && checkbox("ATEMIO5200") != 1) |
---|
| 1160 | dir = ostrcat("/", dir, 0, 1); |
---|
[18190] | 1161 | |
---|
| 1162 | if(ostrcmp(tmpstr, dir) == 0) |
---|
| 1163 | { |
---|
| 1164 | free(dir), dir = NULL; |
---|
| 1165 | free(tmpstr), tmpstr = NULL; |
---|
| 1166 | return 0; |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | free(dir), dir = NULL; |
---|
| 1170 | free(tmpstr), tmpstr = NULL; |
---|
| 1171 | return 1; |
---|
| 1172 | } |
---|
[22097] | 1173 | |
---|
| 1174 | char* getmacfromcmdline() |
---|
| 1175 | { |
---|
| 1176 | char* cmdline = NULL; |
---|
| 1177 | char* tmpstr = NULL; |
---|
| 1178 | char* mac = NULL; |
---|
[18190] | 1179 | |
---|
[22097] | 1180 | cmdline = readsys("/proc/cmdline", 1); |
---|
| 1181 | if(cmdline != NULL) |
---|
| 1182 | { |
---|
| 1183 | tmpstr = strstr(cmdline, "ethaddr:"); |
---|
| 1184 | if(tmpstr != NULL && strlen(tmpstr) >= 25) |
---|
| 1185 | { |
---|
| 1186 | tmpstr[25] = '\0'; |
---|
| 1187 | tmpstr += 8; |
---|
| 1188 | mac = ostrcat(tmpstr, NULL, 0, 0); |
---|
| 1189 | } |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | return mac; |
---|
| 1193 | } |
---|
| 1194 | |
---|
[18190] | 1195 | char* getcpuid() |
---|
| 1196 | { |
---|
| 1197 | char* serial = NULL; |
---|
| 1198 | char* buffer = NULL; |
---|
| 1199 | struct inetwork* net = getinetworkbydevice("eth0"); |
---|
| 1200 | |
---|
| 1201 | if(net != NULL) |
---|
| 1202 | { |
---|
| 1203 | int mac_int = 0; |
---|
| 1204 | int mac1_int = 0; |
---|
| 1205 | int mac2_int = 0; |
---|
| 1206 | |
---|
| 1207 | char* mac = NULL; |
---|
[22097] | 1208 | |
---|
[23739] | 1209 | if(checkbox("ATEMIO510") == 1 || checkbox("ATEMIO520") == 1 || checkbox("ATEMIO530") == 1 || checkbox("ATEMIO7600") == 1) |
---|
[22097] | 1210 | mac = getmacfromcmdline(); |
---|
| 1211 | else |
---|
| 1212 | mac = ostrcat(mac, net->mac, 1, 0); |
---|
[18190] | 1213 | |
---|
| 1214 | int count = 0; |
---|
| 1215 | char* mac1 = NULL; |
---|
| 1216 | char* mac2 = NULL; |
---|
| 1217 | char* tmpstr = NULL; |
---|
| 1218 | |
---|
| 1219 | tmpstr = ostrcat(mac, NULL, 0, 0); |
---|
| 1220 | |
---|
| 1221 | struct splitstr* ret = NULL; |
---|
| 1222 | ret = strsplit(tmpstr, ":", &count); |
---|
| 1223 | |
---|
| 1224 | if(ret != NULL && count == 6) |
---|
| 1225 | { |
---|
| 1226 | mac1 = ostrcat(mac1, (&ret[0])->part, 1, 0); |
---|
| 1227 | mac1 = ostrcat(mac1, (&ret[1])->part, 1, 0); |
---|
| 1228 | mac1 = ostrcat(mac1, (&ret[2])->part, 1, 0); |
---|
| 1229 | mac2 = ostrcat(mac2, (&ret[3])->part, 1, 0); |
---|
| 1230 | mac2 = ostrcat(mac2, (&ret[4])->part, 1, 0); |
---|
| 1231 | mac2 = ostrcat(mac2, (&ret[5])->part, 1, 0); |
---|
| 1232 | } |
---|
| 1233 | |
---|
| 1234 | free(ret); ret = NULL; |
---|
| 1235 | |
---|
| 1236 | if(mac1 != NULL) |
---|
| 1237 | { |
---|
| 1238 | sscanf(mac1, "%X", &mac1_int); |
---|
| 1239 | mac1_int = strtol(mac1 , NULL, 16); |
---|
| 1240 | free(mac1), mac1 = NULL; |
---|
| 1241 | } |
---|
| 1242 | |
---|
| 1243 | if(mac2 != NULL) |
---|
| 1244 | { |
---|
| 1245 | sscanf(mac2, "%X", &mac2_int); |
---|
| 1246 | mac2_int = strtol(mac2 , NULL, 16); |
---|
| 1247 | free(mac2), mac2 = NULL; |
---|
| 1248 | } |
---|
| 1249 | |
---|
| 1250 | free(tmpstr); tmpstr = NULL; |
---|
| 1251 | free(mac); mac = NULL; |
---|
| 1252 | |
---|
| 1253 | mac_int = mac1_int + mac2_int; |
---|
| 1254 | int cpuid = 7594; |
---|
| 1255 | mac_int += cpuid; |
---|
| 1256 | |
---|
| 1257 | buffer = malloc(50); |
---|
| 1258 | if(buffer == NULL) |
---|
| 1259 | return NULL; |
---|
| 1260 | sprintf(buffer, "%d", mac_int); |
---|
| 1261 | serial = ostrcat("AA040127", buffer, 0, 0); |
---|
| 1262 | free(buffer); |
---|
| 1263 | } |
---|
| 1264 | |
---|
| 1265 | return string_newline(serial); |
---|
| 1266 | } |
---|
| 1267 | |
---|
| 1268 | char* gettimeinfo() |
---|
| 1269 | { |
---|
| 1270 | char* cmd = NULL; |
---|
| 1271 | cmd = ostrcat(cmd, "cat", 1, 0); |
---|
| 1272 | cmd = ostrcat(cmd, " /", 1, 0); |
---|
| 1273 | cmd = ostrcat(cmd, "etc", 1, 0); |
---|
| 1274 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1275 | cmd = ostrcat(cmd, "image-version", 1, 0); |
---|
| 1276 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1277 | cmd = ostrcat(cmd, "cut", 1, 0); |
---|
| 1278 | cmd = ostrcat(cmd, " -d= ", 1, 0); |
---|
| 1279 | cmd = ostrcat(cmd, "-f2", 1, 0); |
---|
| 1280 | return command(cmd); |
---|
| 1281 | } |
---|
| 1282 | |
---|
| 1283 | char* gettimeinfovar() |
---|
| 1284 | { |
---|
| 1285 | char* cmd = NULL; |
---|
| 1286 | cmd = ostrcat(cmd, "cat", 1, 0); |
---|
| 1287 | cmd = ostrcat(cmd, " /", 1, 0); |
---|
| 1288 | cmd = ostrcat(cmd, "var", 1, 0); |
---|
| 1289 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1290 | cmd = ostrcat(cmd, "etc", 1, 0); |
---|
| 1291 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1292 | cmd = ostrcat(cmd, ".image-version", 1, 0); |
---|
| 1293 | cmd = ostrcat(cmd, " | ", 1, 0); |
---|
| 1294 | cmd = ostrcat(cmd, "cut", 1, 0); |
---|
| 1295 | cmd = ostrcat(cmd, " -d= ", 1, 0); |
---|
| 1296 | cmd = ostrcat(cmd, "-f2", 1, 0); |
---|
| 1297 | return command(cmd); |
---|
| 1298 | } |
---|
| 1299 | |
---|
| 1300 | char* getserialpw() |
---|
| 1301 | { |
---|
| 1302 | char* pw = NULL; |
---|
| 1303 | |
---|
| 1304 | pw = ostrcat(pw, "/", 1, 0); |
---|
| 1305 | pw = ostrcat(pw, "?", 1, 0); |
---|
| 1306 | pw = ostrcat(pw, "*", 1, 0); |
---|
| 1307 | pw = ostrcat(pw, "x", 1, 0); |
---|
| 1308 | pw = ostrcat(pw, "4", 1, 0); |
---|
| 1309 | pw = ostrcat(pw, "(", 1, 0); |
---|
| 1310 | pw = ostrcat(pw, "$", 1, 0); |
---|
| 1311 | pw = ostrcat(pw, "!", 1, 0); |
---|
| 1312 | pw = ostrcat(pw, "r", 1, 0); |
---|
| 1313 | pw = ostrcat(pw, "%", 1, 0); |
---|
| 1314 | pw = ostrcat(pw, "6", 1, 0); |
---|
| 1315 | pw = ostrcat(pw, "=", 1, 0); |
---|
| 1316 | pw = ostrcat(pw, "9", 1, 0); |
---|
| 1317 | pw = ostrcat(pw, "}", 1, 0); |
---|
| 1318 | |
---|
| 1319 | return pw; |
---|
| 1320 | } |
---|
| 1321 | |
---|
[23897] | 1322 | int writeserial(char* cpuid) |
---|
[18190] | 1323 | { |
---|
[23897] | 1324 | char* filename = "/var/etc/codepages/codepage.868", *pw = NULL; |
---|
[18190] | 1325 | unsigned char* buf = NULL; |
---|
| 1326 | FILE *fd = NULL; |
---|
| 1327 | int ret = 0; |
---|
| 1328 | |
---|
| 1329 | pw = getserialpw(); |
---|
| 1330 | buf = oencrypt(pw, cpuid, strlen(cpuid)); |
---|
| 1331 | free(pw); pw = NULL; |
---|
| 1332 | if(buf == NULL) return 1; |
---|
| 1333 | |
---|
| 1334 | fd = fopen(filename, "wbt"); |
---|
| 1335 | if(fd == NULL) |
---|
| 1336 | { |
---|
| 1337 | perr("can't open %s", filename); |
---|
| 1338 | free(buf); |
---|
| 1339 | return 1; |
---|
| 1340 | } |
---|
| 1341 | |
---|
| 1342 | ret += fwrite(buf, strlen(cpuid) * 2, 1, fd); |
---|
| 1343 | |
---|
| 1344 | free(buf); buf = NULL; |
---|
| 1345 | fclose(fd); |
---|
| 1346 | |
---|
| 1347 | if(ret != 1) return 1; |
---|
| 1348 | return 0; |
---|
| 1349 | } |
---|
| 1350 | |
---|
| 1351 | void checkserial(char* input) |
---|
| 1352 | { |
---|
| 1353 | char* filename = "/var/etc/codepages/codepage.868", *pw = NULL, *buf = NULL; |
---|
| 1354 | unsigned char* authbuf = NULL; |
---|
| 1355 | int count = 0, i = 0; |
---|
| 1356 | off64_t len = 0; |
---|
| 1357 | struct splitstr* ret = NULL; |
---|
| 1358 | |
---|
| 1359 | if(input == NULL) return; |
---|
| 1360 | |
---|
| 1361 | buf = readfiletomem(filename, 0); |
---|
| 1362 | len = getfilesize(filename); |
---|
| 1363 | |
---|
| 1364 | pw = getserialpw(); |
---|
| 1365 | |
---|
| 1366 | authbuf = odecrypt(pw, buf, len); |
---|
| 1367 | if(authbuf == NULL) |
---|
| 1368 | { |
---|
| 1369 | free(buf); |
---|
| 1370 | free(authbuf); |
---|
| 1371 | free(pw); |
---|
| 1372 | return; |
---|
| 1373 | } |
---|
| 1374 | free(buf); buf = NULL; |
---|
| 1375 | free(pw); pw = NULL; |
---|
| 1376 | |
---|
| 1377 | //Authfile check |
---|
| 1378 | ret = strsplit((char*)authbuf, "\n", &count); |
---|
[21073] | 1379 | if(ret != NULL) |
---|
[18190] | 1380 | { |
---|
[21073] | 1381 | for(i = 0; i < count; i++) |
---|
[18190] | 1382 | { |
---|
[21073] | 1383 | (&ret[i])->part = stringreplacecharonce((&ret[i])->part, ',', '\0'); |
---|
| 1384 | if(ret != NULL && ostrcmp(input, (&ret[i])->part) == 0) |
---|
| 1385 | { |
---|
| 1386 | status.security = 1; |
---|
[23897] | 1387 | if(count > 1) writeserial(input); |
---|
[21073] | 1388 | break; |
---|
| 1389 | } |
---|
[18190] | 1390 | } |
---|
| 1391 | } |
---|
| 1392 | free(ret); ret = NULL; |
---|
| 1393 | free(authbuf); |
---|
[23913] | 1394 | |
---|
| 1395 | // ufs910 work start |
---|
[23914] | 1396 | if(checkbox("UFS910")) |
---|
[23913] | 1397 | { |
---|
| 1398 | status.security = 1; |
---|
| 1399 | writeserial(input); |
---|
| 1400 | } |
---|
| 1401 | // ufs910 work end |
---|
[18190] | 1402 | |
---|
| 1403 | //Blacklist check |
---|
| 1404 | if(status.security == 1) |
---|
| 1405 | { |
---|
| 1406 | char* blackfile = NULL; |
---|
[19884] | 1407 | blackfile = gethttp("atemio.dyndns.tv", "/svn/auth/blacklist", 80, NULL, HTTPAUTH, 5000, NULL, 0); |
---|
[18190] | 1408 | |
---|
| 1409 | count = 0; |
---|
| 1410 | if(blackfile != NULL) |
---|
| 1411 | ret = strsplit(blackfile, "\n", &count); |
---|
| 1412 | |
---|
[21073] | 1413 | if(ret != NULL) |
---|
[18190] | 1414 | { |
---|
[21073] | 1415 | for(i = 0; i < count; i++) |
---|
[18190] | 1416 | { |
---|
[21074] | 1417 | if(ostrncmp("AA", ret[i].part, 2) == 0) |
---|
| 1418 | { |
---|
[21073] | 1419 | ret[i].part = stringreplacecharonce(ret[i].part, ',', '\0'); |
---|
| 1420 | if(ret != NULL && ostrcmp(input, ret[i].part) == 0) |
---|
| 1421 | { |
---|
| 1422 | status.security = 0; |
---|
| 1423 | break; |
---|
| 1424 | } |
---|
| 1425 | } |
---|
| 1426 | if(ostrncmp("BB", ret[i].part, 2) == 0) |
---|
[21074] | 1427 | { |
---|
[21092] | 1428 | char* tmp = ret[i].part + 2; |
---|
| 1429 | if(tmp != NULL && PLUGINVERSION == atoi(tmp)) |
---|
| 1430 | { |
---|
[21073] | 1431 | status.security = 0; |
---|
[23913] | 1432 | printf("error: 9\n"); |
---|
[21074] | 1433 | destroy(); |
---|
[21073] | 1434 | break; |
---|
| 1435 | } |
---|
| 1436 | } |
---|
[18190] | 1437 | } |
---|
| 1438 | } |
---|
| 1439 | free(ret); ret = NULL; |
---|
| 1440 | free(blackfile); |
---|
| 1441 | } |
---|
| 1442 | |
---|
| 1443 | if(status.security == 1) |
---|
| 1444 | { |
---|
[18215] | 1445 | startnet(); |
---|
[18190] | 1446 | setskinnodeslocked(0); |
---|
| 1447 | } |
---|
| 1448 | |
---|
| 1449 | if(status.security == 0) |
---|
| 1450 | unlink(filename); |
---|
| 1451 | |
---|
| 1452 | killnet(); |
---|
| 1453 | } |
---|
| 1454 | |
---|
| 1455 | int checkprozess(char* input) |
---|
| 1456 | { |
---|
| 1457 | char* tmpstr = NULL; |
---|
| 1458 | char* cmd = NULL; |
---|
| 1459 | int ret = 0; |
---|
| 1460 | |
---|
| 1461 | cmd = ostrcat(cmd, "pidof ", 1, 0); |
---|
| 1462 | cmd = ostrcat(cmd, input, 1, 0); |
---|
| 1463 | cmd = ostrcat(cmd, " | sed '/^ *$/d' | wc -l", 1, 0); |
---|
| 1464 | // printf("checkprozess: cmd=%s\n", cmd); |
---|
| 1465 | |
---|
| 1466 | tmpstr = string_newline(command(cmd)); |
---|
| 1467 | // printf("checkprozess: tmpstr=%s\n", tmpstr); |
---|
| 1468 | |
---|
| 1469 | free(cmd), cmd = NULL; |
---|
| 1470 | if(ostrcmp(tmpstr, "0") == 0) |
---|
| 1471 | ret = 0; |
---|
| 1472 | else |
---|
| 1473 | ret = 1; |
---|
| 1474 | |
---|
| 1475 | // printf("checkprozess: ret=%d\n", ret); |
---|
| 1476 | free(tmpstr), tmpstr = NULL; |
---|
| 1477 | return ret; |
---|
| 1478 | } |
---|
| 1479 | |
---|
[18215] | 1480 | void startnet() |
---|
| 1481 | { |
---|
| 1482 | char* cmd = NULL; |
---|
| 1483 | |
---|
| 1484 | if(status.security == 1) |
---|
| 1485 | { |
---|
| 1486 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1487 | cmd = ostrcat(cmd, "usr", 1, 0); |
---|
| 1488 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1489 | cmd = ostrcat(cmd, "sbin", 1, 0); |
---|
| 1490 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1491 | cmd = ostrcat(cmd, "inetd", 1, 0); |
---|
| 1492 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1493 | cmd = ostrcat(cmd, "&", 1, 0); |
---|
| 1494 | if(!checkprozess("inetd")) |
---|
| 1495 | system(cmd); |
---|
| 1496 | |
---|
| 1497 | free(cmd); cmd = NULL; |
---|
[22520] | 1498 | if(!file_exist(SERIALDEV) == 1) |
---|
| 1499 | mknod(SERIALDEV, S_IFCHR | 0666, makedev(204, 40)); |
---|
[18215] | 1500 | } |
---|
| 1501 | } |
---|
| 1502 | |
---|
[18190] | 1503 | void killnet() |
---|
| 1504 | { |
---|
| 1505 | if(status.security == 0) |
---|
| 1506 | { |
---|
| 1507 | status.expertmodus = 0; |
---|
| 1508 | char* cmd = NULL; |
---|
| 1509 | cmd = ostrcat(cmd, "killall", 1, 0); |
---|
| 1510 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1511 | cmd = ostrcat(cmd, "-9", 1, 0); |
---|
| 1512 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1513 | cmd = ostrcat(cmd, "inetd", 1, 0); |
---|
| 1514 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1515 | cmd = ostrcat(cmd, "telnetd", 1, 0); |
---|
| 1516 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1517 | cmd = ostrcat(cmd, "vsftpd", 1, 0); |
---|
| 1518 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1519 | cmd = ostrcat(cmd, "ftpd", 1, 0); |
---|
| 1520 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
| 1521 | cmd = ostrcat(cmd, "&", 1, 0); |
---|
| 1522 | system(cmd); |
---|
| 1523 | free(cmd); cmd = NULL; |
---|
| 1524 | |
---|
| 1525 | cmd = ostrcat(cmd, "emu.sh stop", 1, 0); |
---|
| 1526 | system(cmd); |
---|
| 1527 | free(cmd); cmd = NULL; |
---|
| 1528 | } |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | unsigned long getsysinfo() |
---|
| 1532 | { |
---|
[27776] | 1533 | if(checkbox("ATEMIO5000") == 1 || checkbox("ATEMIO5200") == 1) |
---|
| 1534 | { |
---|
| 1535 | debug(10, "syscode: skipped"); |
---|
| 1536 | debug(10, "boxtype: %s", getboxtype()); |
---|
| 1537 | return 0; |
---|
| 1538 | } |
---|
| 1539 | |
---|
[18190] | 1540 | char* tmpstr = NULL; |
---|
| 1541 | struct utsname info; |
---|
| 1542 | int i = 0, len = 0; |
---|
| 1543 | unsigned long ret = 0; |
---|
| 1544 | |
---|
| 1545 | if(uname(&info) < 0) |
---|
| 1546 | return 0; |
---|
| 1547 | else |
---|
| 1548 | { |
---|
| 1549 | tmpstr = ostrcat(tmpstr, info.release, 1, 0); |
---|
| 1550 | tmpstr = ostrcat(tmpstr, " ", 1, 0); |
---|
| 1551 | tmpstr = ostrcat(tmpstr, info.version, 1, 0); |
---|
| 1552 | |
---|
| 1553 | if(tmpstr != NULL) |
---|
| 1554 | { |
---|
| 1555 | len = strlen(tmpstr); |
---|
| 1556 | for(i = 0; i < len; i++) |
---|
| 1557 | { |
---|
| 1558 | if(isdigit(tmpstr[i]) && tmpstr[i] != '0' && tmpstr[i] != '1') |
---|
| 1559 | ret *= tmpstr[i]; |
---|
| 1560 | else |
---|
| 1561 | ret += tmpstr[i]; |
---|
| 1562 | } |
---|
| 1563 | } |
---|
| 1564 | free(tmpstr); tmpstr = NULL; |
---|
| 1565 | } |
---|
| 1566 | return ret; |
---|
| 1567 | } |
---|
| 1568 | |
---|
| 1569 | void destroy() |
---|
| 1570 | { |
---|
| 1571 | FILE* fd = NULL; |
---|
| 1572 | char mtd[10]; |
---|
| 1573 | char* buf = NULL; |
---|
| 1574 | |
---|
| 1575 | char* cmd = NULL; |
---|
| 1576 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1577 | cmd = ostrcat(cmd, "mnt", 1, 0); |
---|
| 1578 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1579 | cmd = ostrcat(cmd, "swapextensions", 1, 0); |
---|
| 1580 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1581 | cmd = ostrcat(cmd, "etc", 1, 0); |
---|
| 1582 | cmd = ostrcat(cmd, "/", 1, 0); |
---|
| 1583 | cmd = ostrcat(cmd, ".vnumber", 1, 0); |
---|
| 1584 | if(file_exist(cmd) == 0) |
---|
| 1585 | { |
---|
| 1586 | FILE* fd = NULL; |
---|
| 1587 | if((fd = fopen(cmd, "w")) != NULL) |
---|
| 1588 | fclose(fd); |
---|
| 1589 | } |
---|
| 1590 | free(cmd),cmd = NULL; |
---|
| 1591 | |
---|
| 1592 | // /dev/mtd2 |
---|
| 1593 | mtd[0] = 0x2f; |
---|
| 1594 | mtd[1] = 0x64; |
---|
| 1595 | mtd[2] = 0x65; |
---|
| 1596 | mtd[3] = 0x76; |
---|
| 1597 | mtd[4] = 0x2f; |
---|
| 1598 | mtd[5] = 0x6d; |
---|
| 1599 | mtd[6] = 0x74; |
---|
| 1600 | mtd[7] = 0x64; |
---|
| 1601 | mtd[8] = 0x32; |
---|
| 1602 | mtd[9] = '\0'; |
---|
| 1603 | |
---|
| 1604 | if((fd = fopen(mtd, "w")) == NULL) |
---|
| 1605 | return; |
---|
| 1606 | |
---|
[19467] | 1607 | buf = calloc(1, MINMALLOC); |
---|
[18190] | 1608 | if(buf == NULL) |
---|
| 1609 | { |
---|
| 1610 | fclose(fd); |
---|
| 1611 | return; |
---|
| 1612 | } |
---|
[19467] | 1613 | |
---|
[18190] | 1614 | fwrite(buf, MINMALLOC, 1, fd); |
---|
| 1615 | |
---|
| 1616 | free(buf); |
---|
| 1617 | fclose(fd); |
---|
| 1618 | } |
---|
| 1619 | |
---|
| 1620 | int getmaxsat(char* feshortname) |
---|
| 1621 | { |
---|
| 1622 | char *tmpstr = NULL; |
---|
| 1623 | int maxsat = 1; |
---|
| 1624 | |
---|
| 1625 | if(feshortname != NULL) |
---|
| 1626 | { |
---|
| 1627 | tmpstr = ostrcat(feshortname, "_maxsat", 0, 0); |
---|
| 1628 | maxsat = getconfigint(tmpstr, NULL); |
---|
| 1629 | free(tmpstr); tmpstr = NULL; |
---|
| 1630 | } |
---|
| 1631 | if(maxsat < 0) maxsat = 1; |
---|
| 1632 | |
---|
| 1633 | return maxsat; |
---|
| 1634 | } |
---|
| 1635 | |
---|
| 1636 | void autochangechannelname() |
---|
| 1637 | { |
---|
| 1638 | uint8_t lastsecnr = 0xff; |
---|
| 1639 | int secnr = 0; |
---|
| 1640 | unsigned char* buf = NULL; |
---|
| 1641 | |
---|
| 1642 | if(status.aktservice->fedev == NULL) return; |
---|
| 1643 | |
---|
| 1644 | while(secnr <= lastsecnr && secnr <= 256) |
---|
| 1645 | { |
---|
| 1646 | buf = dvbgetsdt(status.aktservice->fedev, secnr, 2000000); |
---|
| 1647 | if(buf != NULL) |
---|
[20636] | 1648 | findchannel(status.aktservice->fedev, NULL, buf, &lastsecnr, NULL, NULL, 1, 1); |
---|
[18190] | 1649 | else |
---|
| 1650 | break; |
---|
| 1651 | free(buf); buf = NULL; |
---|
| 1652 | secnr++; |
---|
| 1653 | } |
---|
| 1654 | } |
---|
| 1655 | |
---|
| 1656 | //check if emu ist installed, if not it hiddes the menu |
---|
| 1657 | int checkemu() |
---|
| 1658 | { |
---|
| 1659 | int ret = 0; |
---|
| 1660 | |
---|
| 1661 | ret = checkdirext("/var/etc", ".emu"); |
---|
| 1662 | if(ret == 0) |
---|
[21394] | 1663 | { |
---|
[18190] | 1664 | ret = checkdirext("/var/swap/etc", ".emu"); |
---|
[21394] | 1665 | if(ret == 0) |
---|
[22961] | 1666 | ret = checkdirext("/mnt/swapextensions/etc", ".emu"); |
---|
[21394] | 1667 | } |
---|
[18190] | 1668 | |
---|
| 1669 | return ret; |
---|
| 1670 | } |
---|
| 1671 | |
---|
| 1672 | int checkpluginskip(char* name) |
---|
| 1673 | { |
---|
| 1674 | if(ostrcmp(name, "3 Wins") == 0) return 1; |
---|
[18705] | 1675 | else if(ostrcmp(name, "Oscam Config") == 0) return 1; |
---|
[18190] | 1676 | else if(ostrcmp(name, "CallMonitor") == 0) return 1; |
---|
| 1677 | else if(ostrcmp(name, "Hello") == 0) return 1; |
---|
[18221] | 1678 | else if(ostrcmp(name, "Cat Catch") == 0) return 1; |
---|
[18190] | 1679 | else if(ostrcmp(name, "DLNA") == 0) return 1; |
---|
| 1680 | else if(ostrcmp(name, "DVD Player") == 0) return 1; |
---|
[18220] | 1681 | else if(ostrcmp(name, "File Manager") == 0) return 1; |
---|
[18221] | 1682 | else if(ostrcmp(name, "GmediaRender") == 0) return 1; |
---|
| 1683 | else if(ostrcmp(name, "Facebook") == 0) return 1; |
---|
[18190] | 1684 | else if(ostrcmp(name, "hbbtv Browser") == 0) return 1; |
---|
[18221] | 1685 | else if(ostrcmp(name, "IMDb") == 0) return 1; |
---|
| 1686 | else if(ostrcmp(name, "IMDb-API") == 0) return 1; |
---|
[18190] | 1687 | else if(ostrcmp(name, "IP-Kammera") == 0) return 1; |
---|
| 1688 | else if(ostrcmp(name, "Internet Browser") == 0) return 1; |
---|
| 1689 | else if(ostrcmp(name, "KeyLock") == 0) return 1; |
---|
| 1690 | else if(ostrcmp(name, "LCD Pearl") == 0) return 1; |
---|
[18221] | 1691 | else if(ostrcmp(name, "LCD Samsung SPF..") == 0) return 1; |
---|
[18190] | 1692 | else if(ostrcmp(name, "Mbox Info") == 0) return 1; |
---|
| 1693 | // else if(ostrcmp(name, "Media Center") == 0) return 1; |
---|
| 1694 | else if(ostrcmp(name, "Networkbrowser") == 0) return 1; |
---|
| 1695 | else if(ostrcmp(name, "News") == 0) return 1; |
---|
| 1696 | else if(ostrcmp(name, "Optimize") == 0) return 1; |
---|
| 1697 | else if(ostrcmp(name, "Panel") == 0) return 1; |
---|
| 1698 | else if(ostrcmp(name, "Permanent Time") == 0) return 1; |
---|
| 1699 | else if(ostrcmp(name, "RGUI") == 0) return 1; |
---|
| 1700 | else if(ostrcmp(name, "Script execute") == 0) return 1; |
---|
| 1701 | else if(ostrcmp(name, "Softcam Panel") == 0) return 1; |
---|
| 1702 | else if(ostrcmp(name, "Stock") == 0) return 1; |
---|
| 1703 | else if(ostrcmp(name, "Stop if not used") == 0) return 1; |
---|
| 1704 | else if(ostrcmp(name, "Streaminfo") == 0) return 1; |
---|
| 1705 | else if(ostrcmp(name, "TiTan Mediathek") == 0) return 1; |
---|
| 1706 | else if(ostrcmp(name, "Titan Media Center") == 0) return 1; |
---|
| 1707 | else if(ostrcmp(name, "TMDb") == 0) return 1; |
---|
| 1708 | else if(ostrcmp(name, "TopfieldVFD") == 0) return 1; |
---|
| 1709 | else if(ostrcmp(name, "Weather") == 0) return 1; |
---|
[18221] | 1710 | else if(ostrcmp(name, "zapback (Werbezapper)") == 0) return 1; |
---|
[25062] | 1711 | else if(ostrcmp(name, "Reader Config") == 0) return 1; |
---|
[18190] | 1712 | |
---|
| 1713 | return 0; |
---|
| 1714 | } |
---|
| 1715 | |
---|
| 1716 | //flag 0: unlock |
---|
| 1717 | //flag 1: lock |
---|
| 1718 | void setskinnodeslocked(int flag) |
---|
| 1719 | { |
---|
| 1720 | struct skin* node = skin; |
---|
| 1721 | struct skin* child = NULL; |
---|
| 1722 | int tmpflag; |
---|
| 1723 | |
---|
| 1724 | while(node != NULL) |
---|
| 1725 | { |
---|
| 1726 | child = node->child; |
---|
| 1727 | while(child != NULL) |
---|
| 1728 | { |
---|
| 1729 | if(ostrcmp("browser", child->name) == 0) child->locked = flag; |
---|
[18705] | 1730 | else if(ostrcmp("oscam", child->name) == 0) child->locked = flag; |
---|
[18221] | 1731 | else if(ostrcmp("catcatch", child->name) == 0) child->locked = flag; |
---|
[18190] | 1732 | else if(ostrcmp("callmon_main", child->name) == 0) child->locked = flag; |
---|
| 1733 | else if(ostrcmp("cinterface", child->name) == 0) child->locked = flag; |
---|
| 1734 | else if(ostrcmp("dlna", child->name) == 0) child->locked = flag; |
---|
| 1735 | else if(ostrcmp("dvdplayer", child->name) == 0) child->locked = flag; |
---|
| 1736 | else if(ostrcmp("extensionsmenu", child->name) == 0) child->locked = flag; |
---|
| 1737 | else if(ostrcmp("eraseswap", child->name) == 0) child->locked = flag; |
---|
[18223] | 1738 | else if(ostrcmp("facebook", child->name) == 0) child->locked = flag; |
---|
[18220] | 1739 | else if(ostrcmp("filemanager", child->name) == 0) child->locked = flag; |
---|
[18190] | 1740 | else if(ostrcmp("hbbtv", child->name) == 0) child->locked = flag; |
---|
| 1741 | else if(ostrcmp("imdb", child->name) == 0) child->locked = flag; |
---|
[18221] | 1742 | else if(ostrcmp("imdbapi", child->name) == 0) child->locked = flag; |
---|
[18190] | 1743 | else if(ostrcmp("instar", child->name) == 0) child->locked = flag; |
---|
| 1744 | else if(ostrcmp("keylock", child->name) == 0) child->locked = flag; |
---|
| 1745 | else if(ostrcmp("lcdpearl1", child->name) == 0) child->locked = flag; |
---|
| 1746 | else if(ostrcmp("lcdsamsung", child->name) == 0) child->locked = flag; |
---|
| 1747 | // else if(ostrcmp("mediacenter", child->name) == 0) child->locked = flag; |
---|
| 1748 | else if(ostrcmp("mboxinfo", child->name) == 0) child->locked = flag; |
---|
| 1749 | else if(ostrcmp("networkbrowser", child->name) == 0) child->locked = flag; |
---|
| 1750 | else if(ostrcmp("news", child->name) == 0) child->locked = flag; |
---|
| 1751 | else if(ostrcmp("optimize", child->name) == 0) child->locked = flag; |
---|
| 1752 | else if(ostrcmp("panel", child->name) == 0) child->locked = flag; |
---|
| 1753 | else if(ostrcmp("permtime", child->name) == 0) child->locked = flag; |
---|
| 1754 | else if(ostrcmp("plugins", child->name) == 0) child->locked = flag; |
---|
| 1755 | else if(ostrcmp("rgui", child->name) == 0) child->locked = flag; |
---|
| 1756 | else if(ostrcmp("scriptexec", child->name) == 0) child->locked = flag; |
---|
| 1757 | else if(ostrcmp("skinselect", child->name) == 0) child->locked = flag; |
---|
| 1758 | else if(ostrcmp("softcam", child->name) == 0) child->locked = flag; |
---|
| 1759 | else if(ostrcmp("stock", child->name) == 0) child->locked = flag; |
---|
| 1760 | else if(ostrcmp("stopifnotused", child->name) == 0) child->locked = flag; |
---|
| 1761 | else if(ostrcmp("streaminfo", child->name) == 0) child->locked = flag; |
---|
| 1762 | else if(ostrcmp("system_backup", child->name) == 0) child->locked = flag; |
---|
| 1763 | else if(ostrcmp("system_backup_restore", child->name) == 0) child->locked = flag; |
---|
| 1764 | else if(ostrcmp("systemupdatemenu", child->name) == 0) child->locked = flag; |
---|
| 1765 | else if(ostrcmp("tithek", child->name) == 0) child->locked = flag; |
---|
| 1766 | else if(ostrcmp("tmc", child->name) == 0) child->locked = flag; |
---|
| 1767 | else if(ostrcmp("tmdb", child->name) == 0) child->locked = flag; |
---|
| 1768 | else if(ostrcmp("TopfieldVFD", child->name) == 0) child->locked = flag; |
---|
| 1769 | else if(ostrcmp("weather", child->name) == 0) child->locked = flag; |
---|
| 1770 | else if(ostrcmp("wins3", child->name) == 0) child->locked = flag; |
---|
[18221] | 1771 | else if(ostrcmp("zapback_main", child->name) == 0) child->locked = flag; |
---|
[25062] | 1772 | else if(ostrcmp("Reader Config", child->name) == 0) child->locked = flag; |
---|
[25887] | 1773 | else if(ostrcmp("system_update_usb_tmp", child->name) == 0) child->locked = flag; |
---|
[18190] | 1774 | |
---|
[19711] | 1775 | if(status.expertmodus >= 11 && status.security == 1) |
---|
[18190] | 1776 | tmpflag = 0; |
---|
| 1777 | else |
---|
| 1778 | tmpflag = 1; |
---|
| 1779 | |
---|
[25061] | 1780 | // disable tmdb manual start |
---|
| 1781 | if(ostrcmp("TMDb", child->name) == 0) child->locked = 1; |
---|
| 1782 | |
---|
[25062] | 1783 | // disable Reader Config manual start |
---|
| 1784 | if(ostrcmp("Reader Config", child->name) == 0) child->locked = 1; |
---|
| 1785 | |
---|
[25939] | 1786 | // hide this menu on all boxes without ATEMIO530 |
---|
[27981] | 1787 | if(checkbox("ATEMIO520") == 1 && checkbox("ATEMIO530") != 1 && checkbox("ATEMIO5200") != 1 && checkbox("ATEMIO5000") != 1) |
---|
[25939] | 1788 | { |
---|
| 1789 | if(ostrcmp("settings_pluginbutton", child->name) == 0) child->locked = 1; |
---|
| 1790 | } |
---|
| 1791 | |
---|
[25887] | 1792 | // hide this menu on all boxes without ufs912 |
---|
[25558] | 1793 | if(checkbox("UFS912") != 1) |
---|
[25482] | 1794 | { |
---|
[25558] | 1795 | if(ostrcmp("overclocking", child->name) == 0) child->locked = 1; |
---|
[25482] | 1796 | } |
---|
| 1797 | |
---|
[18190] | 1798 | // dont show this menus |
---|
| 1799 | if(checkbox("ATEMIO510") == 1) |
---|
| 1800 | { |
---|
[19711] | 1801 | if(ostrcmp("vfdisplay", child->name) == 0) child->locked = 1; |
---|
[18190] | 1802 | } |
---|
[18834] | 1803 | |
---|
[18190] | 1804 | if(checkbox("UFS910") == 1) |
---|
| 1805 | { |
---|
| 1806 | if(ostrcmp("unlock", child->name) == 0) child->locked = 1; |
---|
| 1807 | } |
---|
[19711] | 1808 | |
---|
[25887] | 1809 | // workaround, after reboot black screen |
---|
| 1810 | if(checkbox("ATEVIO7000") == 1) |
---|
[21611] | 1811 | { |
---|
| 1812 | if(ostrcmp("restart", child->name) == 0) child->locked = 1; |
---|
| 1813 | } |
---|
| 1814 | |
---|
[27781] | 1815 | if(checkbox("ATEVIO5200") == 1) |
---|
| 1816 | { |
---|
| 1817 | if(ostrcmp("skinadjust", child->name) == 0) child->locked = 1; |
---|
[27847] | 1818 | if(ostrcmp("system_backup", child->name) == 0) child->locked = 1; |
---|
[27781] | 1819 | } |
---|
[27763] | 1820 | |
---|
[27847] | 1821 | if(checkbox("ATEVIO5000") == 1) |
---|
| 1822 | { |
---|
| 1823 | if(ostrcmp("system_backup", child->name) == 0) child->locked = 1; |
---|
| 1824 | } |
---|
| 1825 | |
---|
[18190] | 1826 | if(ostrcmp("savesettings", child->name) == 0) child->locked = tmpflag; |
---|
| 1827 | else if(ostrcmp("scartrecorder", child->name) == 0) child->locked = tmpflag; |
---|
| 1828 | else if(ostrcmp("system_update_usb_online", child->name) == 0) child->locked = tmpflag; |
---|
| 1829 | else if(ostrcmp("sambasettings", child->name) == 0) child->locked = tmpflag; |
---|
| 1830 | else if(ostrcmp("nfssettings", child->name) == 0) child->locked = tmpflag; |
---|
[20744] | 1831 | else if(ostrcmp("mediaplayer", child->name) == 0) |
---|
| 1832 | { |
---|
| 1833 | child->locked = tmpflag; |
---|
| 1834 | if(status.timeshifttype == 1) child->locked = 0; |
---|
[27126] | 1835 | if(checkbox("UFS910") == 1) child->locked = 0; |
---|
[27131] | 1836 | if(checkbox("UFS922") == 1) child->locked = 0; |
---|
[20744] | 1837 | } |
---|
[18190] | 1838 | |
---|
| 1839 | child = child->next; |
---|
| 1840 | } |
---|
| 1841 | node = node->next; |
---|
| 1842 | } |
---|
| 1843 | } |
---|
| 1844 | |
---|
| 1845 | int isbase64(char c) |
---|
| 1846 | { |
---|
| 1847 | if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=') |
---|
| 1848 | return 1; |
---|
| 1849 | return 0; |
---|
| 1850 | } |
---|
| 1851 | |
---|
| 1852 | char decodebase64(char c) |
---|
| 1853 | { |
---|
| 1854 | if(c >= 'A' && c <= 'Z') return(c - 'A'); |
---|
| 1855 | if(c >= 'a' && c <= 'z') return(c - 'a' + 26); |
---|
| 1856 | if(c >= '0' && c <= '9') return(c - '0' + 52); |
---|
| 1857 | if(c == '+') return(62); |
---|
| 1858 | return 63; |
---|
| 1859 | } |
---|
| 1860 | |
---|
| 1861 | int b64dec(char* dest, char* src) |
---|
| 1862 | { |
---|
| 1863 | if(src && *src) |
---|
| 1864 | { |
---|
| 1865 | char* p = dest; |
---|
| 1866 | int k, l = strlen(src) + 1; |
---|
| 1867 | char* buf = NULL; |
---|
| 1868 | |
---|
| 1869 | buf = malloc(l); |
---|
| 1870 | if(buf == NULL) return 0; |
---|
| 1871 | |
---|
| 1872 | for(k = 0, l = 0; src[k]; k++) |
---|
| 1873 | { |
---|
| 1874 | if(isbase64(src[k])) |
---|
| 1875 | buf[l++] = src[k]; |
---|
| 1876 | } |
---|
| 1877 | |
---|
| 1878 | for(k = 0; k < l; k += 4) |
---|
| 1879 | { |
---|
| 1880 | char c1 = 'A', c2 = 'A', c3 = 'A', c4 = 'A'; |
---|
| 1881 | char b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
---|
| 1882 | |
---|
| 1883 | c1 = buf[k]; |
---|
| 1884 | if(k + 1 < l) |
---|
| 1885 | c2 = buf[k + 1]; |
---|
| 1886 | if(k + 2 < l) |
---|
| 1887 | c3 = buf[k + 2]; |
---|
| 1888 | if(k + 3 < l) |
---|
| 1889 | c4 = buf[k + 3]; |
---|
| 1890 | |
---|
| 1891 | b1 = decodebase64(c1); |
---|
| 1892 | b2 = decodebase64(c2); |
---|
| 1893 | b3 = decodebase64(c3); |
---|
| 1894 | b4 = decodebase64(c4); |
---|
| 1895 | |
---|
| 1896 | *p++ = ((b1 << 2) | (b2 >> 4)); |
---|
| 1897 | |
---|
| 1898 | if(c3 != '=') |
---|
| 1899 | *p++ = (((b2 & 0xf) << 4) | (b3 >> 2)); |
---|
| 1900 | if(c4 != '=') |
---|
| 1901 | *p++ = (((b3 & 0x3) << 6) | b4); |
---|
| 1902 | |
---|
| 1903 | } |
---|
| 1904 | |
---|
| 1905 | free(buf); |
---|
| 1906 | return(p - dest); |
---|
| 1907 | } |
---|
| 1908 | return 0; |
---|
| 1909 | } |
---|
| 1910 | |
---|
| 1911 | void changechannellist(struct channel* chnode, char* channellist) |
---|
| 1912 | { |
---|
| 1913 | char* tmpstr = NULL; |
---|
| 1914 | |
---|
| 1915 | if(chnode == NULL || status.aktservice->channel == NULL) return; |
---|
| 1916 | |
---|
[19210] | 1917 | if(chnode->servicetype != 99) status.servicetype = chnode->servicetype; |
---|
[18190] | 1918 | if(status.servicetype == 0) |
---|
| 1919 | { |
---|
| 1920 | if(channellist != NULL) |
---|
| 1921 | { |
---|
| 1922 | tmpstr = ostrcat(channellist, NULL, 0, 0); |
---|
| 1923 | free(status.aktservice->channellist); |
---|
| 1924 | status.aktservice->channellist = tmpstr; |
---|
| 1925 | addconfig("channellist", tmpstr); |
---|
| 1926 | } |
---|
| 1927 | tmpstr = oitoa(status.aktservice->channel->serviceid); |
---|
| 1928 | addconfig("serviceid", tmpstr); |
---|
[18328] | 1929 | free(tmpstr); tmpstr = NULL; |
---|
[18454] | 1930 | tmpstr = ollutoa(status.aktservice->channel->transponderid); |
---|
[18190] | 1931 | addconfig("transponderid", tmpstr); |
---|
[18328] | 1932 | free(tmpstr); tmpstr = NULL; |
---|
[18190] | 1933 | } |
---|
| 1934 | else |
---|
| 1935 | { |
---|
| 1936 | if(channellist != NULL) |
---|
| 1937 | { |
---|
| 1938 | tmpstr = ostrcat(channellist, NULL, 0, 0); |
---|
| 1939 | free(status.aktservice->channellist); |
---|
| 1940 | status.aktservice->channellist = tmpstr; |
---|
| 1941 | addconfig("rchannellist", tmpstr); |
---|
| 1942 | } |
---|
| 1943 | tmpstr = oitoa(status.aktservice->channel->serviceid); |
---|
| 1944 | addconfig("rserviceid", tmpstr); |
---|
[18328] | 1945 | free(tmpstr); tmpstr = NULL; |
---|
[18454] | 1946 | tmpstr = ollutoa(status.aktservice->channel->transponderid); |
---|
[18190] | 1947 | addconfig("rtransponderid", tmpstr); |
---|
[18328] | 1948 | free(tmpstr); tmpstr = NULL; |
---|
[18190] | 1949 | } |
---|
| 1950 | } |
---|
| 1951 | |
---|
[24035] | 1952 | //flag 0: normal picons |
---|
| 1953 | //flag 1: alternate picons |
---|
[18190] | 1954 | char* createpiconpath(struct channel* chnode, int flag) |
---|
| 1955 | { |
---|
[23970] | 1956 | char* tmpstr = NULL, *picon = NULL; |
---|
[18190] | 1957 | |
---|
| 1958 | if(chnode != NULL) |
---|
| 1959 | { |
---|
[23970] | 1960 | picon = ostrcat("/", oitoa(chnode->serviceid), 0, 1); |
---|
| 1961 | picon = ostrcat(picon, "-", 1, 0); |
---|
| 1962 | picon = ostrcat(picon, ollutoa(chnode->transponderid), 1, 1); |
---|
| 1963 | picon = ostrcat(picon, ".png", 1, 0); |
---|
| 1964 | |
---|
| 1965 | if(flag == 1) |
---|
[23978] | 1966 | tmpstr = ostrcat("/mnt/swapextensions/usr/local/share/titan/picons/alternate", picon, 0, 0); |
---|
[18190] | 1967 | else |
---|
[23978] | 1968 | tmpstr = ostrcat("/mnt/swapextensions/usr/local/share/titan/picons", picon, 0, 0); |
---|
[23970] | 1969 | if(isfile(tmpstr)) |
---|
| 1970 | { |
---|
| 1971 | free(picon); |
---|
| 1972 | return tmpstr; |
---|
| 1973 | } |
---|
| 1974 | |
---|
[18190] | 1975 | free(tmpstr); tmpstr = NULL; |
---|
[23970] | 1976 | if(flag == 1) |
---|
[23978] | 1977 | tmpstr = ostrcat("/var/swap/usr/local/share/titan/picons/alternate", picon, 0, 0); |
---|
[23970] | 1978 | else |
---|
[23978] | 1979 | tmpstr = ostrcat("/var/swap/usr/local/share/titan/picons", picon, 0, 0); |
---|
[23970] | 1980 | if(isfile(tmpstr)) |
---|
| 1981 | { |
---|
| 1982 | free(picon); |
---|
| 1983 | return tmpstr; |
---|
| 1984 | } |
---|
| 1985 | |
---|
| 1986 | free(tmpstr); tmpstr = NULL; |
---|
| 1987 | if(flag == 1) |
---|
[23978] | 1988 | tmpstr = ostrcat("/var/usr/local/share/titan/picons/alternate", picon, 0, 0); |
---|
[23970] | 1989 | else |
---|
[23978] | 1990 | tmpstr = ostrcat("/var/usr/local/share/titan/picons", picon, 0, 0); |
---|
[23970] | 1991 | if(isfile(tmpstr)) |
---|
| 1992 | { |
---|
| 1993 | free(picon); |
---|
| 1994 | return tmpstr; |
---|
| 1995 | } |
---|
[18190] | 1996 | } |
---|
[23970] | 1997 | |
---|
| 1998 | free(tmpstr); tmpstr = NULL; |
---|
| 1999 | tmpstr = ostrcat(tmpstr, getconfig("defskinpath", NULL), 1, 0); |
---|
| 2000 | tmpstr = ostrcat(tmpstr, "/skin/", 1, 0); |
---|
| 2001 | tmpstr = ostrcat(tmpstr, "defpicon.png", 1, 0); |
---|
[18190] | 2002 | |
---|
[23970] | 2003 | free(picon); |
---|
[18190] | 2004 | return tmpstr; |
---|
| 2005 | } |
---|
| 2006 | |
---|
| 2007 | int checkskin() |
---|
| 2008 | { |
---|
| 2009 | int ret = 0; |
---|
| 2010 | char* defskinpath = NULL; |
---|
| 2011 | char* defskinconfig = NULL; |
---|
| 2012 | char* defskinfile = NULL; |
---|
| 2013 | |
---|
| 2014 | if(file_exist(getconfig("skinpath", NULL)) == 0) |
---|
| 2015 | ret = 1; |
---|
| 2016 | else if(file_exist(getconfig("skinconfig", NULL)) == 0) |
---|
| 2017 | ret = 2; |
---|
| 2018 | else if(file_exist(getconfig("skinfile", NULL)) == 0) |
---|
| 2019 | ret = 3; |
---|
| 2020 | |
---|
| 2021 | if(ret != 0) |
---|
| 2022 | { |
---|
| 2023 | err("skin not found code=%d, change to default", ret); |
---|
| 2024 | |
---|
| 2025 | defskinpath = getconfig("defskinpath", NULL); |
---|
| 2026 | if(defskinpath != NULL) addconfig("skinpath", defskinpath); |
---|
| 2027 | defskinconfig = getconfig("defskinconfig", NULL); |
---|
| 2028 | if(defskinconfig != NULL) addconfig("skinconfig", defskinconfig); |
---|
| 2029 | defskinfile = getconfig("defskinfile", NULL); |
---|
| 2030 | if(defskinfile != NULL) addconfig("skinfile", defskinfile); |
---|
| 2031 | |
---|
| 2032 | ret = 0; |
---|
| 2033 | if(file_exist(getconfig("skinpath", NULL)) == 0) |
---|
| 2034 | ret = 1; |
---|
| 2035 | else if(file_exist(getconfig("skinconfig", NULL)) == 0) |
---|
| 2036 | ret = 2; |
---|
| 2037 | else if(file_exist(getconfig("skinfile", NULL)) == 0) |
---|
| 2038 | ret = 3; |
---|
| 2039 | } |
---|
| 2040 | |
---|
| 2041 | if(ret != 0) |
---|
| 2042 | { |
---|
| 2043 | err("default skin not found code=%d", ret); |
---|
| 2044 | } |
---|
| 2045 | |
---|
| 2046 | return ret; |
---|
| 2047 | } |
---|
| 2048 | |
---|
| 2049 | int getaktvideosize() |
---|
| 2050 | { |
---|
| 2051 | //wait 3 sek after zap, befor videsize is valid |
---|
| 2052 | //driver takes a little time |
---|
| 2053 | if(status.videosizevalid == 1) |
---|
| 2054 | return 0; |
---|
| 2055 | else if(status.videosizevalid + 3 > time(NULL)) |
---|
| 2056 | return 1; |
---|
| 2057 | else |
---|
| 2058 | { |
---|
| 2059 | #ifndef SIMULATE |
---|
| 2060 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
| 2061 | #endif |
---|
[20752] | 2062 | { |
---|
[18190] | 2063 | status.videosizevalid = 1; |
---|
[20752] | 2064 | return 0; |
---|
| 2065 | } |
---|
[18190] | 2066 | } |
---|
| 2067 | |
---|
| 2068 | return 1; |
---|
| 2069 | } |
---|
| 2070 | |
---|
| 2071 | int ostrftime(char* buf, int count, char* format, struct tm* t) |
---|
| 2072 | { |
---|
| 2073 | int ret = -1; |
---|
| 2074 | |
---|
[20265] | 2075 | if(buf == NULL || t == NULL) return ret; |
---|
| 2076 | |
---|
[18190] | 2077 | if(format != NULL) |
---|
| 2078 | ret = strftime(buf, count, format, t); |
---|
| 2079 | else |
---|
| 2080 | ret = strftime(buf, count, "%d-%m-%Y %H:%M", t); |
---|
| 2081 | |
---|
| 2082 | return ret; |
---|
| 2083 | } |
---|
| 2084 | |
---|
| 2085 | //flag 0 = write all |
---|
| 2086 | //flag 1 = don't write epg |
---|
| 2087 | //flag 2 = only write epg |
---|
[19495] | 2088 | //flag 3 = only write config |
---|
[18190] | 2089 | int writeallconfig(int flag) |
---|
| 2090 | { |
---|
| 2091 | char* tmpstr = NULL; |
---|
| 2092 | int ret = 0; |
---|
| 2093 | |
---|
[19495] | 2094 | if(flag == 0 || flag == 1) |
---|
[18190] | 2095 | { |
---|
| 2096 | if(status.writerectimer == 1) |
---|
| 2097 | if(writerectimer(getconfig("rectimerfile", NULL), 0) != 0) |
---|
| 2098 | ret = 1; |
---|
| 2099 | if(status.writesat == 1) |
---|
| 2100 | if(writesat(getconfig("satfile", NULL)) != 0) |
---|
| 2101 | ret = 1; |
---|
| 2102 | if(status.writeplaylist == 1) |
---|
| 2103 | if(writeallplaylist() != 0) |
---|
| 2104 | ret = 1; |
---|
| 2105 | if(status.writemainplaylist == 1) |
---|
| 2106 | if(writemainplaylist(getconfig("playlistfile", NULL)) != 0) |
---|
| 2107 | ret = 1; |
---|
| 2108 | if(status.writebouquet == 1) |
---|
| 2109 | if(writeallbouquet() != 0) |
---|
| 2110 | ret = 1; |
---|
| 2111 | if(status.writemainbouquet == 1) |
---|
| 2112 | if(writemainbouquet(getconfig("bouquetfile", NULL)) != 0) |
---|
| 2113 | ret = 1; |
---|
| 2114 | if(status.writechannel == 1) |
---|
| 2115 | if(writechannel(getconfig("channelfile", NULL)) != 0) |
---|
| 2116 | ret = 1; |
---|
| 2117 | if(status.writetransponder == 1) |
---|
| 2118 | if(writetransponder(getconfig("transponderfile", NULL)) != 0) |
---|
| 2119 | ret = 1; |
---|
| 2120 | if(status.writeprovider == 1) |
---|
| 2121 | if(writeprovider(getconfig("providerfile", NULL)) != 0) |
---|
| 2122 | ret = 1; |
---|
| 2123 | if(status.writeownconfig == 1) |
---|
| 2124 | if(writeownconfig(getconfig("ownconfig", NULL)) != 0) |
---|
| 2125 | ret = 1; |
---|
| 2126 | if(status.writeepgscanlist == 1) |
---|
| 2127 | if(writeepgscanlist(getconfig("epgchannelfile", NULL)) != 0) |
---|
| 2128 | ret = 1; |
---|
| 2129 | if(status.writercconfig == 1) |
---|
| 2130 | if(writercconfig(getconfig("rcconfig", NULL)) != 0) |
---|
| 2131 | ret = 1; |
---|
| 2132 | if(status.writeskinconfig == 1) |
---|
| 2133 | if(writeskinconfig(getconfig("skinconfig", NULL)) != 0) |
---|
| 2134 | ret = 1; |
---|
[19495] | 2135 | if(status.writemostzap == 1) |
---|
| 2136 | if(writemostzap(getconfig("mostzapfile", NULL)) != 0) |
---|
| 2137 | ret = 1; |
---|
[20244] | 2138 | if(status.writelastsubtitle == 1) |
---|
| 2139 | if(writelastsubtitle(getconfig("lastsubtitle", NULL)) != 0) |
---|
| 2140 | ret = 1; |
---|
[22297] | 2141 | if(status.writechannelslot == 1) |
---|
| 2142 | if(writechannelslot(getconfig("channelslotfile", NULL)) != 0) |
---|
| 2143 | ret = 1; |
---|
[19495] | 2144 | } |
---|
| 2145 | if(flag == 0 || flag == 1 || flag == 3) |
---|
| 2146 | { |
---|
[18190] | 2147 | if(status.writeconfig == 1) |
---|
| 2148 | { |
---|
[19716] | 2149 | addconfigint("vol", getvol()); |
---|
[18190] | 2150 | if(writeconfig(status.configfile) != 0) |
---|
| 2151 | ret = 1; |
---|
| 2152 | } |
---|
| 2153 | } |
---|
| 2154 | if((flag == 0 || flag == 2) && time(NULL) > 1072224000) // 01.01.2004 |
---|
| 2155 | { |
---|
| 2156 | tmpstr = createpath(getconfig("epg_path", NULL), "epg.dat"); |
---|
| 2157 | if(writeepg(tmpstr) != 0) |
---|
| 2158 | ret = 1; |
---|
| 2159 | free(tmpstr); tmpstr = NULL; |
---|
| 2160 | } |
---|
| 2161 | |
---|
| 2162 | sync(); |
---|
| 2163 | |
---|
| 2164 | return ret; |
---|
| 2165 | } |
---|
| 2166 | |
---|
[20374] | 2167 | void* writeallconfigthread0() |
---|
| 2168 | { |
---|
| 2169 | writeallconfig(0); |
---|
| 2170 | pthread_exit(NULL); |
---|
| 2171 | } |
---|
| 2172 | |
---|
| 2173 | void* writeallconfigthread1() |
---|
| 2174 | { |
---|
| 2175 | writeallconfig(1); |
---|
| 2176 | pthread_exit(NULL); |
---|
| 2177 | } |
---|
| 2178 | |
---|
[18190] | 2179 | void initmutex(int flag) |
---|
| 2180 | { |
---|
| 2181 | if(flag == 1) |
---|
| 2182 | { |
---|
| 2183 | pthread_mutex_init(&status.drawingmutex, NULL); |
---|
| 2184 | pthread_mutex_init(&status.rectimermutex, NULL); |
---|
| 2185 | pthread_mutex_init(&status.servicemutex, NULL); |
---|
| 2186 | pthread_mutex_init(&status.epgmutex, NULL); |
---|
| 2187 | pthread_mutex_init(&status.vfdmutex, NULL); |
---|
| 2188 | pthread_mutex_init(&status.channelmutex, NULL); |
---|
| 2189 | pthread_mutex_init(&status.timerthreadmutex, NULL); |
---|
| 2190 | pthread_mutex_init(&status.audiotrackmutex, NULL); |
---|
| 2191 | pthread_mutex_init(&status.subtitlemutex, NULL); |
---|
| 2192 | pthread_mutex_init(&status.dmxdevmutex, NULL); |
---|
| 2193 | pthread_mutex_init(&status.rcmutex, NULL); |
---|
| 2194 | pthread_mutex_init(&status.queuemutex, NULL); |
---|
| 2195 | pthread_mutex_init(&status.clistmutex, NULL); |
---|
| 2196 | pthread_mutex_init(&status.hddmutex, NULL); |
---|
| 2197 | pthread_mutex_init(&status.linkedchannelmutex, NULL); |
---|
| 2198 | pthread_mutex_init(&status.tsseekmutex, NULL); |
---|
| 2199 | pthread_mutex_init(&status.accelfbmutex, NULL); |
---|
| 2200 | pthread_mutex_init(&status.mediadbmutex, NULL); |
---|
[18571] | 2201 | pthread_mutex_init(&status.oldentrymutex, NULL); |
---|
[18738] | 2202 | pthread_mutex_init(&status.newslettermutex, NULL); |
---|
[19839] | 2203 | pthread_mutex_init(&status.tithekmutex, NULL); |
---|
[20366] | 2204 | pthread_mutex_init(&status.inetworkmutex, NULL); |
---|
[20654] | 2205 | pthread_mutex_init(&status.textboxmutex, NULL); |
---|
[20708] | 2206 | pthread_mutex_init(&status.setaktresmutex, NULL); |
---|
[21386] | 2207 | pthread_mutex_init(&status.waitrcmutex, NULL); |
---|
[18190] | 2208 | } |
---|
| 2209 | else |
---|
| 2210 | { |
---|
| 2211 | pthread_mutex_destroy(&status.drawingmutex); |
---|
| 2212 | pthread_mutex_destroy(&status.rectimermutex); |
---|
| 2213 | pthread_mutex_destroy(&status.servicemutex); |
---|
| 2214 | pthread_mutex_destroy(&status.epgmutex); |
---|
| 2215 | pthread_mutex_destroy(&status.vfdmutex); |
---|
| 2216 | pthread_mutex_destroy(&status.channelmutex); |
---|
| 2217 | pthread_mutex_destroy(&status.timerthreadmutex); |
---|
| 2218 | pthread_mutex_destroy(&status.audiotrackmutex); |
---|
| 2219 | pthread_mutex_destroy(&status.subtitlemutex); |
---|
| 2220 | pthread_mutex_destroy(&status.dmxdevmutex); |
---|
| 2221 | pthread_mutex_destroy(&status.rcmutex); |
---|
| 2222 | pthread_mutex_destroy(&status.queuemutex); |
---|
| 2223 | pthread_mutex_destroy(&status.clistmutex); |
---|
| 2224 | pthread_mutex_destroy(&status.hddmutex); |
---|
| 2225 | pthread_mutex_destroy(&status.linkedchannelmutex); |
---|
| 2226 | pthread_mutex_destroy(&status.tsseekmutex); |
---|
| 2227 | pthread_mutex_destroy(&status.accelfbmutex); |
---|
| 2228 | pthread_mutex_destroy(&status.mediadbmutex); |
---|
[18571] | 2229 | pthread_mutex_destroy(&status.oldentrymutex); |
---|
[18738] | 2230 | pthread_mutex_destroy(&status.newslettermutex); |
---|
[19839] | 2231 | pthread_mutex_destroy(&status.tithekmutex); |
---|
[20366] | 2232 | pthread_mutex_destroy(&status.inetworkmutex); |
---|
[20654] | 2233 | pthread_mutex_destroy(&status.textboxmutex); |
---|
[20708] | 2234 | pthread_mutex_destroy(&status.setaktresmutex); |
---|
[21389] | 2235 | pthread_mutex_destroy(&status.waitrcmutex); |
---|
[18190] | 2236 | } |
---|
| 2237 | } |
---|
| 2238 | |
---|
| 2239 | int hexit(char c) |
---|
| 2240 | { |
---|
| 2241 | if(c >= '0' && c <= '9') |
---|
| 2242 | return c - '0'; |
---|
| 2243 | if(c >= 'a' && c <= 'f') |
---|
| 2244 | return c - 'a' + 10; |
---|
| 2245 | if(c >= 'A' && c <= 'F') |
---|
| 2246 | return c - 'A' + 10; |
---|
| 2247 | |
---|
| 2248 | return 0; |
---|
| 2249 | } |
---|
| 2250 | |
---|
| 2251 | char* htmlencode(char* from) |
---|
| 2252 | { |
---|
| 2253 | int buflen = 0; |
---|
| 2254 | char* buf = NULL, *to = NULL; |
---|
| 2255 | |
---|
[19467] | 2256 | buf = calloc(1, MINMALLOC); |
---|
[18190] | 2257 | if(buf == NULL) |
---|
| 2258 | { |
---|
| 2259 | err("no mem"); |
---|
| 2260 | return NULL; |
---|
| 2261 | } |
---|
| 2262 | to = buf; |
---|
| 2263 | |
---|
| 2264 | for(buflen = 0; *from != '\0' && buflen < MINMALLOC; ++from) |
---|
| 2265 | { |
---|
| 2266 | if(isalnum(*from) || strchr("/_.-~", *from) != NULL) |
---|
| 2267 | { |
---|
| 2268 | *to = *from; |
---|
| 2269 | ++to; |
---|
| 2270 | ++buflen; |
---|
| 2271 | } |
---|
| 2272 | else |
---|
| 2273 | { |
---|
| 2274 | sprintf(to, "%%%02x", (int)*from & 0xff); |
---|
| 2275 | to += 3; |
---|
| 2276 | buflen += 3; |
---|
| 2277 | } |
---|
| 2278 | } |
---|
| 2279 | *to = '\0'; |
---|
| 2280 | |
---|
[19467] | 2281 | buf = ostrshrink(buf); |
---|
[18190] | 2282 | return buf; |
---|
| 2283 | } |
---|
| 2284 | |
---|
| 2285 | void htmldecode(char* to, char* from) |
---|
| 2286 | { |
---|
| 2287 | if(to == NULL || from == NULL) return; |
---|
| 2288 | |
---|
| 2289 | for(; *from != '\0'; ++to, ++from) |
---|
| 2290 | { |
---|
| 2291 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
| 2292 | { |
---|
| 2293 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
| 2294 | from += 2; |
---|
| 2295 | } |
---|
| 2296 | else |
---|
| 2297 | *to = *from; |
---|
| 2298 | } |
---|
| 2299 | *to = '\0'; |
---|
| 2300 | } |
---|
| 2301 | |
---|
| 2302 | void htmldecode2(char* to, char* from) |
---|
| 2303 | { |
---|
| 2304 | if(to == NULL || from == NULL) return; |
---|
| 2305 | |
---|
| 2306 | for(; *from != '\0'; ++to, ++from) |
---|
| 2307 | { |
---|
| 2308 | if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4])) |
---|
| 2309 | { |
---|
| 2310 | *to = hexit(from[1]) * 16 + hexit(from[2]) * 16 + hexit(from[3]) * 16 + hexit(from[4]); |
---|
| 2311 | from += 4; |
---|
| 2312 | } |
---|
| 2313 | else if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2]) && isxdigit(from[3])) |
---|
| 2314 | { |
---|
| 2315 | *to = hexit(from[1]) * 16 + hexit(from[2]) * 16 + hexit(from[3]); |
---|
| 2316 | from += 3; |
---|
| 2317 | } |
---|
| 2318 | else if(from[0] == '%' && isxdigit(from[1]) && isxdigit(from[2])) |
---|
| 2319 | { |
---|
| 2320 | *to = hexit(from[1]) * 16 + hexit(from[2]); |
---|
| 2321 | from += 2; |
---|
| 2322 | } |
---|
| 2323 | else |
---|
| 2324 | *to = *from; |
---|
| 2325 | } |
---|
| 2326 | *to = '\0'; |
---|
| 2327 | } |
---|
| 2328 | |
---|
| 2329 | void htmldecode3(char* to, char* from) |
---|
| 2330 | { |
---|
| 2331 | if(to == NULL || from == NULL) return; |
---|
| 2332 | |
---|
| 2333 | for(; *from != '\0'; ++to, ++from) |
---|
| 2334 | { |
---|
| 2335 | if(from[0] == '\\' && from[1] == 'u' && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4]) && isxdigit(from[5]) && isxdigit(from[6]) && isxdigit(from[7])) |
---|
| 2336 | { |
---|
| 2337 | *to = hexit(from[2]) * 1048576 + hexit(from[3]) * 65536 + hexit(from[4]) * 4096 + hexit(from[5]) * 256 + hexit(from[6]) * 16 + hexit(from[7]); |
---|
| 2338 | from += 7; |
---|
| 2339 | } |
---|
| 2340 | if(from[0] == '\\' && from[1] == 'u' && isxdigit(from[2]) && isxdigit(from[3]) && isxdigit(from[4]) && isxdigit(from[5])) |
---|
| 2341 | { |
---|
| 2342 | *to = hexit(from[2]) * 4096 + hexit(from[3]) * 256 + hexit(from[4]) * 16 + hexit(from[5]); |
---|
| 2343 | from += 5; |
---|
| 2344 | } |
---|
| 2345 | else |
---|
| 2346 | *to = *from; |
---|
| 2347 | } |
---|
| 2348 | *to = '\0'; |
---|
| 2349 | } |
---|
| 2350 | |
---|
| 2351 | void setosdtransparent(int value) |
---|
| 2352 | { |
---|
| 2353 | int ret = 255; |
---|
| 2354 | if(value < 0) value = 0; |
---|
| 2355 | if(value > 100) value = 100; |
---|
| 2356 | |
---|
| 2357 | ret -= value * 2.55; |
---|
| 2358 | |
---|
| 2359 | setfbtransparent(ret); |
---|
| 2360 | } |
---|
| 2361 | |
---|
| 2362 | struct tm* olocaltime(time_t *value) |
---|
| 2363 | { |
---|
| 2364 | struct tm *loctime, *loctime1 = NULL; |
---|
| 2365 | |
---|
| 2366 | loctime1 = (struct tm*)malloc(sizeof(struct tm)); |
---|
| 2367 | if(loctime1 == NULL) |
---|
| 2368 | { |
---|
| 2369 | err("no mem"); |
---|
| 2370 | return NULL; |
---|
| 2371 | } |
---|
| 2372 | loctime = localtime_r(value, loctime1); |
---|
| 2373 | |
---|
| 2374 | return loctime; |
---|
| 2375 | } |
---|
| 2376 | |
---|
| 2377 | int setwakeuptimer(time_t waketime) |
---|
| 2378 | { |
---|
| 2379 | char* wakeuptimerprog = NULL; |
---|
| 2380 | struct tm *loctime = NULL; |
---|
| 2381 | char *buf = NULL; |
---|
| 2382 | int ret = -1; |
---|
| 2383 | |
---|
| 2384 | wakeuptimerprog = getconfig("wakeuptimerprog", NULL); |
---|
| 2385 | |
---|
| 2386 | if(wakeuptimerprog == NULL) |
---|
| 2387 | { |
---|
[23286] | 2388 | err("NULL detect"); |
---|
[18190] | 2389 | return ret; |
---|
| 2390 | } |
---|
| 2391 | |
---|
| 2392 | buf = malloc(MINMALLOC); |
---|
| 2393 | if(buf == NULL) |
---|
| 2394 | { |
---|
[24350] | 2395 | err("no mem"); |
---|
[18190] | 2396 | return ret; |
---|
| 2397 | } |
---|
| 2398 | |
---|
| 2399 | loctime = olocaltime(&waketime); |
---|
| 2400 | |
---|
| 2401 | if(loctime != NULL) |
---|
| 2402 | ostrftime(buf, MINMALLOC, wakeuptimerprog, loctime); |
---|
| 2403 | |
---|
| 2404 | if(buf != NULL) |
---|
| 2405 | { |
---|
| 2406 | debug(100, "set wake up timer (%s)", buf); |
---|
| 2407 | ret = system(buf); |
---|
| 2408 | } |
---|
| 2409 | |
---|
| 2410 | free(loctime); |
---|
| 2411 | free(buf); |
---|
| 2412 | return ret; |
---|
| 2413 | } |
---|
| 2414 | |
---|
| 2415 | int autoresolution() |
---|
| 2416 | { |
---|
| 2417 | char *hotpluginfo = NULL; |
---|
| 2418 | char *value = NULL; |
---|
| 2419 | |
---|
| 2420 | if(getconfig("av_videomode", NULL) != NULL || getconfig("av_colorformat", NULL)) |
---|
| 2421 | return 1; |
---|
| 2422 | |
---|
| 2423 | hotpluginfo = getconfig("hotpluginfo", NULL); |
---|
| 2424 | |
---|
| 2425 | if(hotpluginfo == NULL) |
---|
| 2426 | { |
---|
[23286] | 2427 | err("NULL detect"); |
---|
[18190] | 2428 | return 1; |
---|
| 2429 | } |
---|
| 2430 | |
---|
| 2431 | value = readsys(hotpluginfo, 1); |
---|
| 2432 | if(value == NULL) |
---|
| 2433 | { |
---|
[23286] | 2434 | err("NULL detect"); |
---|
[18190] | 2435 | return 1; |
---|
| 2436 | } |
---|
| 2437 | |
---|
| 2438 | if(value[0] == 'y') |
---|
| 2439 | { |
---|
| 2440 | setvideomode("720p50", 0); |
---|
[20751] | 2441 | changefbresolution("720p50", 0); |
---|
[23976] | 2442 | setcolorformat("hdmi_rgb", 0); |
---|
[18190] | 2443 | } |
---|
| 2444 | else |
---|
| 2445 | { |
---|
| 2446 | setvideomode("576i50", 0); |
---|
[20751] | 2447 | changefbresolution("576i50", 0); |
---|
[23976] | 2448 | setcolorformat("rgb", 1); |
---|
[18190] | 2449 | } |
---|
| 2450 | |
---|
| 2451 | free(value); |
---|
| 2452 | return 0; |
---|
| 2453 | } |
---|
| 2454 | |
---|
| 2455 | //TODO: can remove if new function work |
---|
| 2456 | /* |
---|
| 2457 | int writelengthfield(unsigned char *buf, unsigned int len) |
---|
| 2458 | { |
---|
| 2459 | if(len < 127) |
---|
| 2460 | { |
---|
| 2461 | *buf++ = len; |
---|
| 2462 | return 1; |
---|
| 2463 | } |
---|
| 2464 | else if(len < 256) |
---|
| 2465 | { |
---|
| 2466 | *buf++ = 0x81; |
---|
| 2467 | *buf++ = len; |
---|
| 2468 | return 2; |
---|
| 2469 | } |
---|
| 2470 | else if(len < 65535) |
---|
| 2471 | { |
---|
| 2472 | *buf++ = 0x82; |
---|
| 2473 | *buf++ = len >> 8; |
---|
| 2474 | *buf++ = len; |
---|
| 2475 | return 3; |
---|
| 2476 | } |
---|
| 2477 | |
---|
| 2478 | return 0; |
---|
| 2479 | } |
---|
| 2480 | */ |
---|
| 2481 | |
---|
| 2482 | size_t writelengthfield(unsigned char * buf, unsigned int len) |
---|
| 2483 | { |
---|
| 2484 | if(buf == NULL) return 0; |
---|
| 2485 | |
---|
| 2486 | if(len < 128) |
---|
| 2487 | { |
---|
| 2488 | buf[0] = len; |
---|
| 2489 | return 1; |
---|
| 2490 | } |
---|
| 2491 | else |
---|
| 2492 | { |
---|
| 2493 | unsigned int pos = 0; |
---|
| 2494 | unsigned int shiftby = 8; |
---|
| 2495 | unsigned char lenfieldsize = 1; |
---|
| 2496 | |
---|
| 2497 | while((len >> shiftby) != 0) |
---|
| 2498 | { |
---|
| 2499 | lenfieldsize++; |
---|
| 2500 | shiftby += 8; |
---|
| 2501 | } |
---|
| 2502 | |
---|
| 2503 | buf[pos++] = ((1 << 7) | lenfieldsize); |
---|
| 2504 | |
---|
| 2505 | while(shiftby != 0) |
---|
| 2506 | { |
---|
| 2507 | shiftby -= 8; |
---|
| 2508 | buf[pos++] = len >> shiftby; |
---|
| 2509 | } |
---|
| 2510 | return pos; |
---|
| 2511 | } |
---|
| 2512 | } |
---|
| 2513 | |
---|
| 2514 | //flag 0: del non alpha/num |
---|
| 2515 | //flag 1: change all / |
---|
[20150] | 2516 | //flag 2: change all non filename conform chars |
---|
[23052] | 2517 | //flag 3: replace non alpha/num with _ |
---|
[18190] | 2518 | void delspezchar(char* text, int flag) |
---|
| 2519 | { |
---|
| 2520 | char* tmpstr = text; |
---|
| 2521 | |
---|
| 2522 | if(text == NULL) return; |
---|
| 2523 | |
---|
| 2524 | while(*tmpstr != '\0') |
---|
| 2525 | { |
---|
[20150] | 2526 | if(flag == 1 || flag == 2) |
---|
[18190] | 2527 | { |
---|
[20150] | 2528 | if(tmpstr[0] == '/') tmpstr[0] = '-'; |
---|
| 2529 | if(flag == 2) |
---|
| 2530 | { |
---|
[24782] | 2531 | if(tmpstr[0] == '§') tmpstr[0] = '-'; |
---|
[20150] | 2532 | if(tmpstr[0] == '<') tmpstr[0] = '-'; |
---|
| 2533 | if(tmpstr[0] == '>') tmpstr[0] = '-'; |
---|
| 2534 | if(tmpstr[0] == ':') tmpstr[0] = '-'; |
---|
| 2535 | if(tmpstr[0] == '"') tmpstr[0] = '-'; |
---|
[20151] | 2536 | if(tmpstr[0] == '\\') tmpstr[0] = '-'; |
---|
[20150] | 2537 | if(tmpstr[0] == '|') tmpstr[0] = '-'; |
---|
| 2538 | if(tmpstr[0] == '*') tmpstr[0] = '-'; |
---|
| 2539 | if(tmpstr[0] == '?') tmpstr[0] = '-'; |
---|
| 2540 | if(tmpstr[0] == '[') tmpstr[0] = '-'; |
---|
| 2541 | if(tmpstr[0] == ']') tmpstr[0] = '-'; |
---|
| 2542 | if(tmpstr[0] == '=') tmpstr[0] = '-'; |
---|
| 2543 | if(tmpstr[0] == '%') tmpstr[0] = '-'; |
---|
| 2544 | if(tmpstr[0] == '$') tmpstr[0] = '-'; |
---|
| 2545 | if(tmpstr[0] == ',') tmpstr[0] = '-'; |
---|
| 2546 | if(tmpstr[0] == ';') tmpstr[0] = '-'; |
---|
| 2547 | if(tmpstr[0] == '~') tmpstr[0] = '-'; |
---|
| 2548 | } |
---|
[18190] | 2549 | } |
---|
[23052] | 2550 | else if(flag == 3) |
---|
| 2551 | { |
---|
| 2552 | if(!isalnum(tmpstr[0]) && tmpstr[0] != '-') |
---|
| 2553 | tmpstr[0] = '_'; |
---|
| 2554 | } |
---|
[18190] | 2555 | else |
---|
| 2556 | { |
---|
| 2557 | if(!isalnum(tmpstr[0]) && tmpstr[0] != '-' && tmpstr[0] != '.') |
---|
| 2558 | tmpstr[0] = ' '; |
---|
| 2559 | } |
---|
| 2560 | tmpstr++; |
---|
| 2561 | } |
---|
| 2562 | } |
---|
| 2563 | |
---|
| 2564 | void m_lock(pthread_mutex_t *mutex, int flag) |
---|
| 2565 | { |
---|
| 2566 | switch(flag) |
---|
| 2567 | { |
---|
| 2568 | case 0: debug(900, "drawingmutex lock"); break; |
---|
| 2569 | case 1: debug(900, "rectimermutex lock"); break; |
---|
| 2570 | case 2: debug(900, "servicemutex lock"); break; |
---|
| 2571 | case 3: debug(900, "vfdmutex lock"); break; |
---|
| 2572 | case 4: debug(900, "epgmutex lock"); break; |
---|
| 2573 | case 5: debug(900, "channelmutex lock"); break; |
---|
| 2574 | case 6: debug(900, "timerthreadmutex lock"); break; |
---|
| 2575 | case 7: debug(900, "audiotrackmutex lock"); break; |
---|
| 2576 | case 8: debug(900, "subtitlemutex lock"); break; |
---|
| 2577 | case 9: debug(900, "dmxdevmutex lock"); break; |
---|
| 2578 | case 10: debug(900, "rcmutex lock"); break; |
---|
| 2579 | case 11: debug(900, "queuemutex lock"); break; |
---|
| 2580 | case 12: debug(900, "clistmutex lock"); break; |
---|
| 2581 | case 13: debug(900, "hddmutex lock"); break; |
---|
| 2582 | case 14: debug(900, "linkedchannelmutex lock"); break; |
---|
| 2583 | case 15: debug(900, "tsseekmutex lock"); break; |
---|
| 2584 | case 16: debug(900, "accelfbmutex lock"); break; |
---|
| 2585 | case 17: debug(900, "mediadbmutex lock"); break; |
---|
[18571] | 2586 | case 18: debug(900, "oldentrymutex lock"); break; |
---|
[18738] | 2587 | case 19: debug(900, "newslettermutex lock"); break; |
---|
[19839] | 2588 | case 20: debug(900, "tithekmutex lock"); break; |
---|
[20366] | 2589 | case 21: debug(900, "inetworkmutex lock"); break; |
---|
[20654] | 2590 | case 22: debug(900, "textboxmutex lock"); break; |
---|
[20708] | 2591 | case 23: debug(900, "setaktresmutex lock"); break; |
---|
[21386] | 2592 | case 24: debug(900, "waitrcmutex lock"); break; |
---|
[18190] | 2593 | default: debug(900, "unknown mutex lock"); break; |
---|
| 2594 | } |
---|
| 2595 | pthread_mutex_lock(mutex); |
---|
| 2596 | } |
---|
| 2597 | |
---|
| 2598 | void m_unlock(pthread_mutex_t *mutex, int flag) |
---|
| 2599 | { |
---|
| 2600 | switch(flag) |
---|
| 2601 | { |
---|
| 2602 | case 0: debug(900, "drawingmutex unlock"); break; |
---|
| 2603 | case 1: debug(900, "rectimermutex unlock"); break; |
---|
| 2604 | case 2: debug(900, "servicemutex unlock"); break; |
---|
| 2605 | case 3: debug(900, "vfdmutex unlock"); break; |
---|
| 2606 | case 4: debug(900, "epgmutex unlock"); break; |
---|
| 2607 | case 5: debug(900, "channelmutex unlock"); break; |
---|
| 2608 | case 6: debug(900, "timerthreadmutex unlock"); break; |
---|
| 2609 | case 7: debug(900, "audiotrackmutex unlock"); break; |
---|
| 2610 | case 8: debug(900, "subtitlemutex unlock"); break; |
---|
| 2611 | case 9: debug(900, "dmxdevmutex unlock"); break; |
---|
| 2612 | case 10: debug(900, "rcmutex unlock"); break; |
---|
| 2613 | case 11: debug(900, "queuemutex unlock"); break; |
---|
| 2614 | case 12: debug(900, "clistmutex unlock"); break; |
---|
| 2615 | case 13: debug(900, "hddmutex unlock"); break; |
---|
| 2616 | case 14: debug(900, "linkedchannelmutex unlock"); break; |
---|
| 2617 | case 15: debug(900, "tsseekmutex unlock"); break; |
---|
| 2618 | case 16: debug(900, "accelfbmutex unlock"); break; |
---|
| 2619 | case 17: debug(900, "mediadbmutex unlock"); break; |
---|
[18571] | 2620 | case 18: debug(900, "oldentrymutex unlock"); break; |
---|
[18738] | 2621 | case 19: debug(900, "newslettermutex unlock"); break; |
---|
[19839] | 2622 | case 20: debug(900, "tithekmutex unlock"); break; |
---|
[20366] | 2623 | case 21: debug(900, "inetworkmutex unlock"); break; |
---|
[20654] | 2624 | case 22: debug(900, "textboxmutex unlock"); break; |
---|
[20708] | 2625 | case 23: debug(900, "setaktresmutex unlock"); break; |
---|
[21386] | 2626 | case 24: debug(900, "waitrcmutex unlock"); break; |
---|
[18190] | 2627 | default: debug(900, "unknown mutex unlock"); break; |
---|
| 2628 | } |
---|
| 2629 | pthread_mutex_unlock(mutex); |
---|
| 2630 | } |
---|
| 2631 | |
---|
[20730] | 2632 | void debugstack(int sig, void* address, void* address1) |
---|
[18190] | 2633 | { |
---|
[24091] | 2634 | Dl_info info, info1; |
---|
[21290] | 2635 | void* trace[20]; |
---|
[18190] | 2636 | size_t size; |
---|
[21290] | 2637 | size = backtrace(trace, 20); |
---|
[18190] | 2638 | |
---|
| 2639 | FILE* fd = NULL; |
---|
| 2640 | void* akttrace[2]; |
---|
[24091] | 2641 | int i = 0; |
---|
[18190] | 2642 | char **strings; |
---|
| 2643 | char **aktstring; |
---|
| 2644 | time_t rawtime; |
---|
[24091] | 2645 | #ifdef BETA |
---|
| 2646 | int y = 0; |
---|
| 2647 | Dl_info info2; |
---|
| 2648 | #endif |
---|
[18190] | 2649 | |
---|
| 2650 | char* imgversion = NULL; |
---|
| 2651 | struct stimerthread* tnode = NULL; |
---|
| 2652 | |
---|
| 2653 | if(isfile(getconfig("imagenamefile", NULL)) != 0) |
---|
| 2654 | imgversion = readsys(getconfig("imagenamefile", NULL), 1); |
---|
| 2655 | else |
---|
| 2656 | imgversion = ostrcat("unknown", NULL, 0, 0); |
---|
| 2657 | |
---|
| 2658 | tnode = gettimerbythread(pthread_self()); |
---|
| 2659 | if(tnode != NULL) |
---|
| 2660 | dladdr(tnode->func, &info); |
---|
| 2661 | |
---|
| 2662 | dladdr(address, &info1); |
---|
| 2663 | |
---|
| 2664 | strings = backtrace_symbols(trace, size); |
---|
| 2665 | akttrace[0] = (void*)address1; |
---|
| 2666 | akttrace[1] = (void*)address; |
---|
| 2667 | aktstring = backtrace_symbols(akttrace, 2); //get fault funktion name |
---|
| 2668 | |
---|
[22861] | 2669 | fprintf(stderr, "--------------------------------------\n"); |
---|
[22872] | 2670 | fprintf(stderr, "Box: %s\n", getboxtype()); |
---|
[22861] | 2671 | fprintf(stderr, "Image: %s\n", imgversion); |
---|
| 2672 | fprintf(stderr, "Signal: %d (%s)\n", sig, strsignal(sig)); |
---|
[18190] | 2673 | if(info1.dli_fname != NULL) |
---|
[22861] | 2674 | fprintf(stderr, "Error in File: %s\n", info1.dli_fname); |
---|
| 2675 | fprintf(stderr, "MainThread: %x\n", (unsigned int)status.mainthread); |
---|
[18190] | 2676 | if(tnode != NULL && info.dli_sname != NULL) |
---|
[22861] | 2677 | fprintf(stderr, "Error in Thread: %x (%s)\n", (unsigned int)pthread_self(), info.dli_sname); |
---|
[18190] | 2678 | else |
---|
[22861] | 2679 | fprintf(stderr, "Error in Thread: %x\n", (unsigned int)pthread_self()); |
---|
[23187] | 2680 | |
---|
| 2681 | fprintf(stderr, "\nObtaining %zd stack frames:\n\n", size); |
---|
[18190] | 2682 | for(i = 0; i < size; i++) |
---|
[22861] | 2683 | fprintf(stderr, "%s\n", strings[i]); |
---|
[18190] | 2684 | |
---|
[22861] | 2685 | fprintf(stderr, "\nLast functions:\n\n"); |
---|
| 2686 | fprintf(stderr, "%s\n", aktstring[0]); |
---|
| 2687 | fprintf(stderr, "%s\n", aktstring[1]); |
---|
[23224] | 2688 | |
---|
| 2689 | #ifdef BETA |
---|
[23187] | 2690 | for(i = 0; i < MAXSTACKTRACE; i++) |
---|
| 2691 | { |
---|
[23191] | 2692 | if(stacktrace[i].pos > 0) |
---|
[23187] | 2693 | { |
---|
| 2694 | fprintf(stderr, "\nObtaining %d Thread Stack frames [%p]:\n\n", stacktrace[i].pos, (void*)stacktrace[i].thread); |
---|
[23191] | 2695 | for(y = stacktrace[i].pos - 1; y >= 0; y--) |
---|
[23187] | 2696 | { |
---|
[23191] | 2697 | dladdr(stacktrace[i].func[y], &info2); |
---|
| 2698 | fprintf(stderr, "%s(%s) [%p]\n", info2.dli_fname, info2.dli_sname, stacktrace[i].func[y]); |
---|
[23187] | 2699 | } |
---|
| 2700 | } |
---|
| 2701 | } |
---|
[23224] | 2702 | #endif |
---|
[18190] | 2703 | |
---|
[22861] | 2704 | fprintf(stderr, "--------------------------------------\n"); |
---|
[18190] | 2705 | |
---|
[22500] | 2706 | char* logdir = ostrcat(getconfig("tracelog", NULL), NULL, 0, 0); |
---|
| 2707 | if(logdir != NULL) |
---|
| 2708 | { |
---|
| 2709 | char* tmplogdir = dirname(logdir); |
---|
| 2710 | if(tmplogdir != NULL) |
---|
| 2711 | { |
---|
| 2712 | if(!file_exist(tmplogdir)) |
---|
| 2713 | mkdir(tmplogdir, 0777); |
---|
| 2714 | } |
---|
| 2715 | free(logdir); logdir = NULL; |
---|
[22875] | 2716 | } |
---|
| 2717 | |
---|
| 2718 | //del file if greater 100KB |
---|
| 2719 | if(getfilesize(getconfig("tracelog", NULL)) > 102400) |
---|
| 2720 | unlink(getconfig("tracelog", NULL)); |
---|
[18466] | 2721 | |
---|
[22872] | 2722 | fd = fopen(getconfig("tracelog", NULL), "a"); |
---|
[18190] | 2723 | if(fd != NULL) |
---|
| 2724 | { |
---|
| 2725 | time(&rawtime); |
---|
| 2726 | fprintf(fd, "Date: %s", ctime(&rawtime)); |
---|
[22872] | 2727 | fprintf(fd, "Box: %s\n", getboxtype()); |
---|
[18190] | 2728 | fprintf(fd, "Image: %s\n", imgversion); |
---|
[20730] | 2729 | fprintf(fd, "Signal: %d (%s)\n", sig, strsignal(sig)); |
---|
[18190] | 2730 | if(info1.dli_fname != NULL) |
---|
[22861] | 2731 | fprintf(fd, "Error in File: %s\n", info1.dli_fname); |
---|
[18190] | 2732 | fprintf(fd, "MainThread: %x\n", (unsigned int)status.mainthread); |
---|
| 2733 | if(tnode != NULL && info.dli_sname != NULL) |
---|
| 2734 | fprintf(fd, "Error in Thread: %x (%s)\n", (unsigned int)pthread_self(), info.dli_sname); |
---|
| 2735 | else |
---|
| 2736 | fprintf(fd, "Error in Thread: %x\n", (unsigned int)pthread_self()); |
---|
[23187] | 2737 | |
---|
| 2738 | fprintf(fd, "\nObtaining %zd stack frames:\n\n", size); |
---|
| 2739 | for(i = 0; i < size; i++) |
---|
[18190] | 2740 | fprintf(fd, "%s\n", strings[i]); |
---|
[23187] | 2741 | |
---|
[18190] | 2742 | fprintf(fd, "\nLast functions:\n\n"); |
---|
| 2743 | fprintf(fd, "%s\n", aktstring[0]); |
---|
| 2744 | fprintf(fd, "%s\n", aktstring[1]); |
---|
[23224] | 2745 | |
---|
| 2746 | #ifdef BETA |
---|
[23187] | 2747 | for(i = 0; i < MAXSTACKTRACE; i++) |
---|
| 2748 | { |
---|
[23191] | 2749 | if(stacktrace[i].pos > 0) |
---|
[23187] | 2750 | { |
---|
| 2751 | fprintf(fd, "\nObtaining %d Thread Stack frames [%p]:\n\n", stacktrace[i].pos, (void*)stacktrace[i].thread); |
---|
[23191] | 2752 | for(y = stacktrace[i].pos - 1; y >= 0; y--) |
---|
[23187] | 2753 | { |
---|
[23191] | 2754 | dladdr(stacktrace[i].func[y], &info2); |
---|
| 2755 | fprintf(fd, "%s(%s) [%p]\n", info2.dli_fname, info2.dli_sname, stacktrace[i].func[y]); |
---|
[23187] | 2756 | } |
---|
| 2757 | } |
---|
| 2758 | } |
---|
[23224] | 2759 | #endif |
---|
[23187] | 2760 | |
---|
[18190] | 2761 | fprintf(fd, "--------------------------------------\n\n"); |
---|
| 2762 | fclose(fd); |
---|
| 2763 | sync(); |
---|
| 2764 | } |
---|
| 2765 | else |
---|
| 2766 | perr("open %s", getconfig("tracelog", NULL)); |
---|
| 2767 | |
---|
| 2768 | free(imgversion); |
---|
| 2769 | free(strings); |
---|
| 2770 | free(aktstring); |
---|
| 2771 | } |
---|
| 2772 | |
---|
| 2773 | int mountauto(const char *file, const char *dir, unsigned long int flag, const void *data) |
---|
| 2774 | { |
---|
| 2775 | int ret = -1; |
---|
| 2776 | char* saveptr = NULL, *filesystems = NULL, *tmpfilesystems = NULL, *token = NULL; |
---|
| 2777 | |
---|
| 2778 | filesystems = getconfig("filesystems", NULL); |
---|
| 2779 | tmpfilesystems = ostrcat(tmpfilesystems, filesystems, 0, 0); |
---|
| 2780 | |
---|
| 2781 | token = strtok_r(tmpfilesystems, ";", &saveptr); |
---|
| 2782 | while(token != NULL) |
---|
| 2783 | { |
---|
| 2784 | ret = mount(file, dir, token, flag, data); |
---|
| 2785 | if(ret == 0) break; |
---|
| 2786 | token = strtok_r(NULL, ";", &saveptr); |
---|
| 2787 | } |
---|
| 2788 | |
---|
| 2789 | free(tmpfilesystems); |
---|
| 2790 | return ret; |
---|
| 2791 | } |
---|
| 2792 | |
---|
| 2793 | int setwaswakuptimer(int value) |
---|
| 2794 | { |
---|
| 2795 | char *waswakeuptimerdev = NULL, *tmpstr = NULL; |
---|
| 2796 | int ret = 0; |
---|
| 2797 | |
---|
| 2798 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
| 2799 | |
---|
| 2800 | if(waswakeuptimerdev != NULL) |
---|
| 2801 | { |
---|
| 2802 | debug(100, "set %s to %d", waswakeuptimerdev, value); |
---|
| 2803 | tmpstr = oitoa(value); |
---|
| 2804 | ret = writesys(waswakeuptimerdev, tmpstr, 0); |
---|
| 2805 | free(tmpstr); tmpstr = NULL; |
---|
| 2806 | return ret; |
---|
| 2807 | } |
---|
| 2808 | |
---|
| 2809 | return 0; |
---|
| 2810 | } |
---|
| 2811 | |
---|
| 2812 | int getwaswakuptimer() |
---|
| 2813 | { |
---|
| 2814 | int ret = 0; |
---|
| 2815 | char *waswakeuptimerdev = NULL; |
---|
| 2816 | char *value = NULL; |
---|
| 2817 | |
---|
| 2818 | waswakeuptimerdev = getconfig("waswakeuptimerdev", NULL); |
---|
| 2819 | |
---|
| 2820 | if(waswakeuptimerdev == NULL) |
---|
| 2821 | { |
---|
[23286] | 2822 | err("NULL detect"); |
---|
[18190] | 2823 | return 0; |
---|
| 2824 | } |
---|
| 2825 | |
---|
| 2826 | value = readsys(waswakeuptimerdev, 1); |
---|
| 2827 | if(value == NULL) |
---|
| 2828 | { |
---|
[23286] | 2829 | err("NULL detect"); |
---|
[18190] | 2830 | return 0; |
---|
| 2831 | } |
---|
| 2832 | |
---|
| 2833 | // start from timer |
---|
| 2834 | if(atoi(value) == 1) ret = 1; |
---|
| 2835 | |
---|
| 2836 | free(value); |
---|
| 2837 | return ret; |
---|
| 2838 | } |
---|
| 2839 | |
---|
| 2840 | void checkboxstart() |
---|
| 2841 | { |
---|
| 2842 | struct rectimer* node = rectimer; |
---|
| 2843 | int timediff = getconfigint("rectimer_timediff", NULL); |
---|
| 2844 | |
---|
| 2845 | if(node == NULL) return; //no record |
---|
| 2846 | |
---|
| 2847 | while(node != NULL) |
---|
| 2848 | { |
---|
| 2849 | if(node->status < 2) |
---|
| 2850 | { |
---|
| 2851 | time_t akttime = time(NULL); |
---|
| 2852 | time_t begin = node->begin - getconfigint("wakeuptimerdevdiff", NULL); |
---|
[18927] | 2853 | |
---|
[20191] | 2854 | debug(400, "begin=%ld akttime1=%ld akttime2=%ld", begin, akttime - timediff, akttime + timediff); |
---|
[20137] | 2855 | |
---|
[18190] | 2856 | if(begin > akttime - timediff && begin < akttime + timediff) |
---|
| 2857 | { |
---|
| 2858 | debug(400, "found rectimer who has start the box"); |
---|
| 2859 | setwaswakuptimer(1); |
---|
[20129] | 2860 | setcecstandby(1); |
---|
[18190] | 2861 | } |
---|
| 2862 | } |
---|
| 2863 | node = node->next; |
---|
| 2864 | } |
---|
| 2865 | } |
---|
| 2866 | |
---|
| 2867 | int setwakeuptimerdev(time_t value) |
---|
| 2868 | { |
---|
| 2869 | char* wakeuptimerdev, *tmpstr = NULL; |
---|
| 2870 | int ret = 0; |
---|
| 2871 | int diff = getconfigint("wakeuptimerdevdiff", NULL); |
---|
| 2872 | |
---|
| 2873 | if(value != 0x7FFFFFFF && value - diff > time(NULL)) |
---|
| 2874 | value -= diff; |
---|
| 2875 | |
---|
| 2876 | wakeuptimerdev = getconfig("wakeuptimerdev", NULL); |
---|
| 2877 | |
---|
| 2878 | if(wakeuptimerdev != NULL && value >= time(NULL)) |
---|
| 2879 | { |
---|
| 2880 | debug(100, "set %s to %ld", wakeuptimerdev, value); |
---|
| 2881 | tmpstr = olutoa(value); |
---|
| 2882 | ret = writesys(wakeuptimerdev, tmpstr, 0); |
---|
| 2883 | free(tmpstr); tmpstr = NULL; |
---|
| 2884 | return ret; |
---|
| 2885 | } |
---|
| 2886 | |
---|
| 2887 | return 0; |
---|
| 2888 | } |
---|
| 2889 | |
---|
| 2890 | int changepolicy() |
---|
| 2891 | { |
---|
| 2892 | char *tmppolicy = NULL, *tmpstr = NULL; |
---|
| 2893 | |
---|
| 2894 | tmppolicy = getpolicy(); |
---|
| 2895 | |
---|
| 2896 | if(!ostrncmp("letterbox", tmppolicy, 8)) |
---|
| 2897 | tmpstr = ostrcat(tmpstr, "panscan", 1, 0); |
---|
| 2898 | else if(!ostrncmp("panscan", tmppolicy, 7)) |
---|
| 2899 | tmpstr = ostrcat(tmpstr, "non", 1, 0); |
---|
| 2900 | else if(!ostrncmp("non", tmppolicy, 3)) |
---|
| 2901 | tmpstr = ostrcat(tmpstr, "bestfit", 1, 0); |
---|
| 2902 | else if(!ostrncmp("bestfit", tmppolicy, 7)) |
---|
| 2903 | tmpstr = ostrcat(tmpstr, "letterbox", 1, 0); |
---|
| 2904 | |
---|
| 2905 | setpolicy(tmpstr); |
---|
| 2906 | |
---|
| 2907 | free(tmpstr); tmpstr = NULL; |
---|
| 2908 | free(tmppolicy); tmppolicy = NULL; |
---|
| 2909 | return 0; |
---|
| 2910 | } |
---|
| 2911 | |
---|
[20576] | 2912 | char* getmac(char* dev) |
---|
| 2913 | { |
---|
| 2914 | int sock = -1, i = 0; |
---|
| 2915 | struct ifreq buf; |
---|
| 2916 | char* tmpstr = NULL; |
---|
| 2917 | char tmpbuf[4] = {}; |
---|
| 2918 | |
---|
| 2919 | if(dev == NULL) return NULL; |
---|
| 2920 | |
---|
| 2921 | sock = socket(PF_INET, SOCK_DGRAM, 0); |
---|
| 2922 | if(sock >= 0) |
---|
| 2923 | { |
---|
| 2924 | memset(&buf, 0x00, sizeof(buf)); |
---|
| 2925 | strcpy(buf.ifr_name, dev); |
---|
| 2926 | ioctl(sock, SIOCGIFHWADDR, &buf); |
---|
| 2927 | close(sock); |
---|
| 2928 | |
---|
| 2929 | for(i = 0; i < 6; i++) |
---|
| 2930 | { |
---|
| 2931 | snprintf(tmpbuf, 4, "%.2X:", (unsigned char)buf.ifr_hwaddr.sa_data[i]); |
---|
| 2932 | tmpstr = ostrcat(tmpstr, tmpbuf, 1, 0); |
---|
| 2933 | } |
---|
| 2934 | if(tmpbuf != NULL) |
---|
| 2935 | tmpstr[strlen(tmpstr) - 1] = '\0'; |
---|
| 2936 | } |
---|
| 2937 | |
---|
| 2938 | return tmpstr; |
---|
| 2939 | } |
---|
| 2940 | |
---|
[18190] | 2941 | char* getdefaultgw() |
---|
| 2942 | { |
---|
| 2943 | char* name = NULL; |
---|
| 2944 | unsigned long def, gw, m; |
---|
| 2945 | int flags, ref, use, metric, mtu, win, ir; |
---|
| 2946 | struct in_addr ip; |
---|
| 2947 | |
---|
| 2948 | FILE *fd = fopen("/proc/net/route", "r"); |
---|
| 2949 | if(fd == NULL) |
---|
| 2950 | return NULL; |
---|
| 2951 | |
---|
| 2952 | if(fscanf(fd, "%*[^\n]\n") < 0) |
---|
| 2953 | { |
---|
| 2954 | fclose(fd); |
---|
| 2955 | return NULL; |
---|
| 2956 | } |
---|
| 2957 | |
---|
| 2958 | name = malloc(64); |
---|
| 2959 | if(name == NULL) |
---|
| 2960 | { |
---|
| 2961 | err("no mem"); |
---|
| 2962 | return NULL; |
---|
| 2963 | } |
---|
| 2964 | |
---|
| 2965 | while(1) |
---|
| 2966 | { |
---|
| 2967 | 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); |
---|
| 2968 | if(def == 0) break; |
---|
| 2969 | if(r != 11) |
---|
| 2970 | { |
---|
| 2971 | fclose(fd); |
---|
| 2972 | free(name); |
---|
| 2973 | return NULL; |
---|
| 2974 | } |
---|
| 2975 | if(!(flags & 0x0001)) continue; //is interface down |
---|
| 2976 | } |
---|
| 2977 | |
---|
| 2978 | fclose(fd); |
---|
| 2979 | free(name); |
---|
| 2980 | |
---|
| 2981 | ip.s_addr = gw; |
---|
| 2982 | if(def == 0) |
---|
| 2983 | return inet_ntoa(ip); |
---|
| 2984 | |
---|
| 2985 | return NULL; |
---|
| 2986 | } |
---|
| 2987 | |
---|
| 2988 | char* changefilenameext(char* filename, char* ext) |
---|
| 2989 | { |
---|
| 2990 | char* newfilename = NULL; |
---|
| 2991 | char* zeichen = NULL; |
---|
| 2992 | |
---|
| 2993 | if(filename == NULL) return NULL; |
---|
| 2994 | |
---|
| 2995 | newfilename = ostrcat(filename, NULL, 0, 0); |
---|
| 2996 | |
---|
| 2997 | zeichen = strrchr(newfilename, '.'); |
---|
| 2998 | if(zeichen != NULL) |
---|
| 2999 | { |
---|
| 3000 | zeichen[0] = '\0'; |
---|
| 3001 | newfilename = ostrcat(newfilename, ext, 1, 0); |
---|
| 3002 | } |
---|
| 3003 | |
---|
| 3004 | return newfilename; |
---|
| 3005 | } |
---|
| 3006 | |
---|
| 3007 | int cmpfilenameext(char* filename, char* ext) |
---|
| 3008 | { |
---|
| 3009 | char* zeichen = NULL; |
---|
| 3010 | |
---|
| 3011 | if(filename == NULL) return 1; |
---|
| 3012 | |
---|
| 3013 | zeichen = strrchr(filename, '.'); |
---|
| 3014 | if(zeichen != NULL) |
---|
| 3015 | { |
---|
| 3016 | if(ostrcasecmp(zeichen, ext) == 0) return 0; |
---|
| 3017 | } |
---|
| 3018 | |
---|
| 3019 | return 1; |
---|
| 3020 | } |
---|
| 3021 | |
---|
| 3022 | char* getfilenameext(char* filename) |
---|
| 3023 | { |
---|
| 3024 | char* zeichen = NULL; |
---|
| 3025 | |
---|
| 3026 | if(filename == NULL) return NULL; |
---|
| 3027 | |
---|
| 3028 | zeichen = strrchr(filename, '.'); |
---|
| 3029 | if(zeichen != NULL) |
---|
| 3030 | { |
---|
| 3031 | return ostrcat(zeichen + 1, NULL, 0, 0); |
---|
| 3032 | } |
---|
| 3033 | |
---|
| 3034 | return NULL; |
---|
| 3035 | } |
---|
| 3036 | |
---|
[22999] | 3037 | char* getfilenamepng(char* filename) |
---|
| 3038 | { |
---|
| 3039 | char* tmpstr = NULL; |
---|
| 3040 | |
---|
| 3041 | if(filename == NULL) return NULL; |
---|
| 3042 | |
---|
| 3043 | if(!filelistflt(".avi .dat .divx .flv .mkv .m4v .mp4 .mov .mpg .mpeg .mts .m2ts .trp .ts .vdr .vob .wmv .rm", filename)) |
---|
| 3044 | tmpstr = ostrcat("movie", NULL, 0, 0); |
---|
| 3045 | else if(!filelistflt(".mp3 .flac .ogg .wma .ra .wav", filename)) |
---|
| 3046 | tmpstr = ostrcat("musik", NULL, 0, 0); |
---|
| 3047 | else if(!filelistflt(".jpg .png", filename)) |
---|
| 3048 | tmpstr = ostrcat("picture", NULL, 0, 0); |
---|
| 3049 | else |
---|
[23006] | 3050 | tmpstr = ostrcat(getfilenameext(filename), NULL, 1, 0); |
---|
[22999] | 3051 | |
---|
| 3052 | if(tmpstr != NULL) |
---|
| 3053 | { |
---|
[23004] | 3054 | return tmpstr; |
---|
[22999] | 3055 | } |
---|
| 3056 | |
---|
| 3057 | return NULL; |
---|
| 3058 | } |
---|
| 3059 | |
---|
[18190] | 3060 | char* getcurrentdir(char* path) |
---|
| 3061 | { |
---|
| 3062 | char* zeichen = NULL; |
---|
| 3063 | |
---|
| 3064 | if(path == NULL) return NULL; |
---|
| 3065 | |
---|
| 3066 | zeichen = strrchr(path, '/'); |
---|
| 3067 | if(zeichen != NULL) |
---|
| 3068 | { |
---|
| 3069 | return ostrcat(zeichen + 1, NULL, 0, 0); |
---|
| 3070 | } |
---|
| 3071 | |
---|
| 3072 | return NULL; |
---|
| 3073 | } |
---|
| 3074 | |
---|
| 3075 | char* convert_timesec(int sec) |
---|
| 3076 | { |
---|
| 3077 | int hour = 0, min = 0, seconds = 0; |
---|
| 3078 | char* buf = NULL; |
---|
| 3079 | |
---|
| 3080 | buf = malloc(9); |
---|
| 3081 | if(buf == NULL) |
---|
| 3082 | { |
---|
| 3083 | err("no mem"); |
---|
| 3084 | return NULL; |
---|
| 3085 | } |
---|
| 3086 | |
---|
| 3087 | seconds = sec % 60; |
---|
| 3088 | min = (sec / 60) % 60; |
---|
| 3089 | hour = sec / 3600; |
---|
| 3090 | |
---|
| 3091 | if(seconds < 0) seconds = 0; |
---|
| 3092 | if(min < 0) min = 0; |
---|
| 3093 | if(hour < 0 || hour > 23) |
---|
| 3094 | { |
---|
| 3095 | hour = 0; |
---|
| 3096 | min = 0; |
---|
| 3097 | seconds = 0; |
---|
| 3098 | } |
---|
| 3099 | |
---|
| 3100 | snprintf(buf, 9, "%02d:%02d:%02d", hour, min, seconds); |
---|
| 3101 | |
---|
| 3102 | return buf; |
---|
| 3103 | } |
---|
| 3104 | |
---|
| 3105 | int checkdate() |
---|
| 3106 | { |
---|
| 3107 | time_t dvbtime = 0; |
---|
| 3108 | |
---|
| 3109 | if(time(NULL) < 1072224000 || status.timeupdatecount > 3600) // 01.01.2004 |
---|
| 3110 | { |
---|
| 3111 | if(dvbgetdate(&dvbtime, 10000000) == 0) //10 sek |
---|
| 3112 | { |
---|
| 3113 | setsystime(&dvbtime); |
---|
| 3114 | status.timeupdatecount = 0; |
---|
| 3115 | return 0; |
---|
| 3116 | } |
---|
| 3117 | return 1; |
---|
| 3118 | } |
---|
| 3119 | return 0; |
---|
| 3120 | } |
---|
| 3121 | |
---|
| 3122 | void closeonexec(int fd) |
---|
| 3123 | { |
---|
| 3124 | if(fd > -1) |
---|
| 3125 | fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); |
---|
| 3126 | } |
---|
| 3127 | |
---|
[19446] | 3128 | void startnewsletter(flag) |
---|
| 3129 | { |
---|
| 3130 | if(flag == 1) |
---|
| 3131 | { |
---|
| 3132 | if(getconfigint("newsletter", NULL) == 1 && status.newsletterthread == NULL) |
---|
| 3133 | status.newsletterthread = addtimer(&newsletterthreadfunc, START, 1000, 1, NULL, NULL, NULL); |
---|
| 3134 | } |
---|
| 3135 | else if(status.newsletterthread != NULL) |
---|
| 3136 | { |
---|
| 3137 | status.newsletterthread->aktion = STOP; |
---|
| 3138 | status.newsletterthread = NULL; |
---|
| 3139 | } |
---|
| 3140 | } |
---|
| 3141 | |
---|
[18190] | 3142 | void startthumb(flag) |
---|
| 3143 | { |
---|
| 3144 | if(flag == 1) |
---|
| 3145 | { |
---|
| 3146 | if(getconfigint("createthumb", NULL) == 1 && status.thumbthread == NULL) |
---|
| 3147 | status.thumbthread = addtimer(&thumbthread, START, 1000, 1, NULL, NULL, NULL); |
---|
| 3148 | } |
---|
| 3149 | else if(status.thumbthread != NULL) |
---|
| 3150 | { |
---|
| 3151 | status.thumbthread->aktion = STOP; |
---|
| 3152 | status.thumbthread = NULL; |
---|
| 3153 | } |
---|
| 3154 | } |
---|
| 3155 | |
---|
| 3156 | void starthttpd(flag) |
---|
| 3157 | { |
---|
| 3158 | if(flag == 1) |
---|
| 3159 | { |
---|
| 3160 | if(getconfigint("httpdstart", NULL) == 1 && status.httpthread == NULL) |
---|
| 3161 | { |
---|
| 3162 | status.httpthread = addtimer(&httpdthreadfunc, START, 10000, -1, NULL, NULL, NULL); |
---|
| 3163 | if(status.httpthread != NULL) |
---|
| 3164 | status.httpthread->flag = setbit(status.httpthread->flag, 0); |
---|
| 3165 | } |
---|
| 3166 | } |
---|
| 3167 | else if(status.httpthread != NULL) |
---|
| 3168 | { |
---|
| 3169 | status.httpthread->aktion = STOP; |
---|
| 3170 | status.httpthread = NULL; |
---|
| 3171 | } |
---|
| 3172 | } |
---|
| 3173 | |
---|
| 3174 | void startrguid(flag) |
---|
| 3175 | { |
---|
| 3176 | if(flag == 1) |
---|
| 3177 | { |
---|
| 3178 | if(getconfigint("rguidstart", NULL) == 1 && status.rguithread == NULL) |
---|
| 3179 | { |
---|
| 3180 | status.rguithread = addtimer(&rguidthreadfunc, START, 10000, -1, NULL, NULL, NULL); |
---|
| 3181 | if(status.rguithread != NULL) |
---|
| 3182 | status.rguithread->flag = setbit(status.rguithread->flag, 0); |
---|
| 3183 | } |
---|
| 3184 | } |
---|
| 3185 | else if(status.rguithread != NULL) |
---|
| 3186 | { |
---|
| 3187 | status.rguithread->aktion = STOP; |
---|
| 3188 | status.rguithread = NULL; |
---|
| 3189 | } |
---|
| 3190 | } |
---|
| 3191 | |
---|
[19470] | 3192 | char* getboxtype() |
---|
| 3193 | { |
---|
| 3194 | if(status.boxtype == NULL) |
---|
| 3195 | { |
---|
| 3196 | if(isfile("/etc/model") == 0) return NULL; |
---|
| 3197 | status.boxtype = string_toupper(readsys("/etc/model", 1)); |
---|
| 3198 | } |
---|
| 3199 | |
---|
| 3200 | return status.boxtype; |
---|
| 3201 | } |
---|
| 3202 | |
---|
[18190] | 3203 | int checkbox(char* box) |
---|
| 3204 | { |
---|
| 3205 | char* boxversion = NULL; |
---|
| 3206 | int ret = 0; |
---|
| 3207 | |
---|
| 3208 | if(status.boxtype == NULL) |
---|
| 3209 | { |
---|
| 3210 | if(isfile("/etc/model") == 0) return 0; |
---|
| 3211 | boxversion = string_toupper(readsys("/etc/model", 1)); |
---|
| 3212 | } |
---|
| 3213 | else |
---|
| 3214 | boxversion = status.boxtype; |
---|
| 3215 | |
---|
| 3216 | if(ostrcmp(boxversion, box) == 0) |
---|
| 3217 | { |
---|
| 3218 | status.boxtype = boxversion; |
---|
| 3219 | ret = 1; |
---|
| 3220 | } |
---|
| 3221 | |
---|
| 3222 | box = ostrcat(box, "\n", 0, 0); |
---|
| 3223 | if(ostrcmp(boxversion, box) == 0) |
---|
| 3224 | { |
---|
| 3225 | status.boxtype = boxversion; |
---|
| 3226 | ret = 1; |
---|
| 3227 | } |
---|
| 3228 | |
---|
| 3229 | if(status.boxtype == NULL) |
---|
| 3230 | free(boxversion); boxversion = NULL; |
---|
| 3231 | free(box); box = NULL; |
---|
| 3232 | |
---|
| 3233 | return ret; |
---|
| 3234 | } |
---|
| 3235 | |
---|
| 3236 | int setoverclockfreq(int mode) |
---|
| 3237 | { |
---|
| 3238 | // mode 0 = Set Standby Freq |
---|
| 3239 | // mode 1 = Set Freq |
---|
| 3240 | |
---|
| 3241 | if(ostrcmp(getownconfig("standby_overclock"), "0") == 0) |
---|
| 3242 | return 1; |
---|
| 3243 | |
---|
| 3244 | if(isfile("/proc/cpu_frequ/pll0_ndiv_mdiv") == 0) |
---|
| 3245 | return 1; |
---|
| 3246 | |
---|
| 3247 | char* tmpstr = NULL; |
---|
| 3248 | |
---|
| 3249 | if(mode == 0) |
---|
| 3250 | tmpstr = getownconfig("standby_freq"); |
---|
| 3251 | else |
---|
| 3252 | tmpstr = getownconfig("pll0_ndiv_mdiv"); |
---|
| 3253 | |
---|
| 3254 | return writesys("/proc/cpu_frequ/pll0_ndiv_mdiv", tmpstr, 1); |
---|
| 3255 | } |
---|
| 3256 | |
---|
[18373] | 3257 | /* |
---|
[18209] | 3258 | int checkdev(char* dev) |
---|
| 3259 | { |
---|
| 3260 | char* cmd = NULL; |
---|
| 3261 | cmd = ostrcat(cmd, "cat ", 1, 0); |
---|
| 3262 | cmd = ostrcat(cmd, dev, 1, 0); |
---|
| 3263 | |
---|
| 3264 | char* tmpstr = NULL; |
---|
| 3265 | tmpstr = string_newline(command(cmd)); |
---|
| 3266 | free(cmd), cmd = NULL; |
---|
| 3267 | |
---|
| 3268 | if(tmpstr == NULL) |
---|
| 3269 | { |
---|
| 3270 | return 0; |
---|
| 3271 | } |
---|
| 3272 | |
---|
| 3273 | if(ostrcmp(tmpstr, "Segmentation fault") == 0) |
---|
| 3274 | { |
---|
| 3275 | return 0; |
---|
| 3276 | } |
---|
| 3277 | |
---|
| 3278 | free(tmpstr), tmpstr = NULL; |
---|
| 3279 | return 1; |
---|
| 3280 | } |
---|
[18373] | 3281 | */ |
---|
[18209] | 3282 | |
---|
| 3283 | int setsaturation(int value) |
---|
| 3284 | { |
---|
| 3285 | char* saturationdev; |
---|
| 3286 | |
---|
| 3287 | saturationdev = getconfig("saturationdev", NULL); |
---|
| 3288 | |
---|
[18373] | 3289 | if(saturationdev != NULL /*&& checkdev(saturationdev)*/) |
---|
[18209] | 3290 | { |
---|
| 3291 | debug(100, "set %s to %d", saturationdev, value); |
---|
| 3292 | return writesysint(saturationdev, value, 1); |
---|
| 3293 | } |
---|
| 3294 | |
---|
| 3295 | return 0; |
---|
| 3296 | } |
---|
| 3297 | |
---|
| 3298 | int setbrightness(int value) |
---|
| 3299 | { |
---|
| 3300 | char* brightnessdev; |
---|
| 3301 | |
---|
| 3302 | brightnessdev = getconfig("brightnessdev", NULL); |
---|
| 3303 | |
---|
[18373] | 3304 | if(brightnessdev != NULL /*&& checkdev(brightnessdev)*/) |
---|
[18209] | 3305 | { |
---|
| 3306 | debug(100, "set %s to %d", brightnessdev, value); |
---|
| 3307 | return writesysint(brightnessdev, value, 1); |
---|
| 3308 | } |
---|
| 3309 | |
---|
| 3310 | return 0; |
---|
| 3311 | } |
---|
| 3312 | |
---|
[18190] | 3313 | int setcontrast(int value) |
---|
| 3314 | { |
---|
| 3315 | char* contrastdev; |
---|
| 3316 | |
---|
| 3317 | contrastdev = getconfig("contrastdev", NULL); |
---|
| 3318 | |
---|
[18373] | 3319 | if(contrastdev != NULL /*&& checkdev(contrastdev)*/) |
---|
[18190] | 3320 | { |
---|
| 3321 | debug(100, "set %s to %d", contrastdev, value); |
---|
| 3322 | return writesysint(contrastdev, value, 1); |
---|
| 3323 | } |
---|
| 3324 | |
---|
| 3325 | return 0; |
---|
| 3326 | } |
---|
| 3327 | |
---|
| 3328 | int settint(int value) |
---|
| 3329 | { |
---|
| 3330 | char* tintdev; |
---|
| 3331 | |
---|
| 3332 | tintdev = getconfig("tintdev", NULL); |
---|
| 3333 | |
---|
[18373] | 3334 | if(tintdev != NULL /*&& checkdev(tintdev)*/) |
---|
[18190] | 3335 | { |
---|
| 3336 | debug(100, "set %s to %d", tintdev, value); |
---|
| 3337 | return writesysint(tintdev, value, 1); |
---|
| 3338 | } |
---|
| 3339 | |
---|
| 3340 | return 0; |
---|
| 3341 | } |
---|
| 3342 | |
---|
| 3343 | int ozip(char* inbuf, int inlen, char** outbuf, int* outlen, int level) |
---|
| 3344 | { |
---|
| 3345 | int ret = 0; |
---|
| 3346 | z_stream stream; |
---|
[22763] | 3347 | |
---|
[24352] | 3348 | if(inbuf == NULL || outbuf == NULL || inlen == 0) return 1; |
---|
[18190] | 3349 | |
---|
| 3350 | stream.zalloc = Z_NULL; |
---|
| 3351 | stream.zfree = Z_NULL; |
---|
| 3352 | stream.opaque = Z_NULL; |
---|
[22763] | 3353 | stream.avail_in = 0; |
---|
| 3354 | stream.next_in = Z_NULL; |
---|
| 3355 | stream.avail_out = 0; |
---|
| 3356 | stream.next_out = Z_NULL; |
---|
[18190] | 3357 | |
---|
| 3358 | ret = deflateInit(&stream, level); |
---|
| 3359 | if(ret != Z_OK) |
---|
| 3360 | return 1; |
---|
| 3361 | |
---|
| 3362 | *outbuf = malloc(inlen); |
---|
| 3363 | if(*outbuf == NULL) |
---|
| 3364 | { |
---|
| 3365 | err("no mem"); |
---|
| 3366 | (void)deflateEnd(&stream); |
---|
| 3367 | return 1; |
---|
| 3368 | } |
---|
| 3369 | |
---|
| 3370 | stream.avail_in = inlen; |
---|
| 3371 | stream.next_in = (void*)inbuf; |
---|
[24324] | 3372 | |
---|
[18190] | 3373 | do |
---|
| 3374 | { |
---|
| 3375 | stream.avail_out = inlen; |
---|
| 3376 | stream.next_out = (void*)*outbuf; |
---|
| 3377 | |
---|
| 3378 | ret = deflate(&stream, Z_FINISH); |
---|
| 3379 | if(ret == Z_STREAM_ERROR) |
---|
| 3380 | { |
---|
| 3381 | free(*outbuf); *outbuf = NULL; |
---|
| 3382 | (void)deflateEnd(&stream); |
---|
| 3383 | return 1; |
---|
| 3384 | } |
---|
| 3385 | } |
---|
| 3386 | while(stream.avail_out == 0); |
---|
[24324] | 3387 | |
---|
| 3388 | char* tmpoutbuf = *outbuf; |
---|
[18190] | 3389 | *outlen = inlen - stream.avail_out; |
---|
| 3390 | *outbuf = realloc(*outbuf, *outlen); |
---|
[24350] | 3391 | if(*outbuf == NULL) |
---|
| 3392 | { |
---|
[24425] | 3393 | if(*outlen > 0) |
---|
| 3394 | { |
---|
| 3395 | err("no mem"); |
---|
| 3396 | free(tmpoutbuf); |
---|
| 3397 | } |
---|
[24351] | 3398 | *outlen = 0; |
---|
[24350] | 3399 | (void)deflateEnd(&stream); |
---|
| 3400 | return 1; |
---|
| 3401 | } |
---|
[18190] | 3402 | |
---|
| 3403 | (void)deflateEnd(&stream); |
---|
| 3404 | return 0; |
---|
| 3405 | } |
---|
| 3406 | |
---|
| 3407 | //flag 0: malloc mem |
---|
| 3408 | //flag 1: don't malloc mem |
---|
[24243] | 3409 | //flag 2: malloc mem (gzip) |
---|
| 3410 | //flag 3: don't malloc mem (gzip) |
---|
[18190] | 3411 | int ounzip(char* inbuf, int inlen, char** outbuf, int* outlen, int maxbuf, int flag) |
---|
| 3412 | { |
---|
| 3413 | int ret = 0; |
---|
| 3414 | z_stream stream; |
---|
[22763] | 3415 | |
---|
[24352] | 3416 | if(inbuf == NULL || outbuf == NULL || maxbuf == 0) return 1; |
---|
[22763] | 3417 | if(flag == 1 && *outbuf == NULL) return 1; |
---|
[18190] | 3418 | |
---|
| 3419 | stream.zalloc = Z_NULL; |
---|
| 3420 | stream.zfree = Z_NULL; |
---|
| 3421 | stream.opaque = Z_NULL; |
---|
| 3422 | stream.avail_in = 0; |
---|
| 3423 | stream.next_in = Z_NULL; |
---|
[22763] | 3424 | stream.avail_out = 0; |
---|
| 3425 | stream.next_out = Z_NULL; |
---|
[18190] | 3426 | |
---|
[24243] | 3427 | if(flag == 2 || flag == 3) |
---|
| 3428 | { |
---|
| 3429 | ret = inflateInit2(&stream, 16 + MAX_WBITS); |
---|
[24260] | 3430 | if(flag == 2) flag = 0; |
---|
| 3431 | else if(flag == 3) flag = 1; |
---|
[24243] | 3432 | } |
---|
| 3433 | else |
---|
| 3434 | ret = inflateInit(&stream); |
---|
[18190] | 3435 | if(ret != Z_OK) |
---|
| 3436 | return 1; |
---|
| 3437 | |
---|
| 3438 | if(flag == 0) |
---|
| 3439 | { |
---|
| 3440 | *outbuf = malloc(maxbuf); |
---|
| 3441 | if(*outbuf == NULL) |
---|
| 3442 | { |
---|
| 3443 | err("no mem"); |
---|
| 3444 | (void)inflateEnd(&stream); |
---|
| 3445 | return 1; |
---|
| 3446 | } |
---|
| 3447 | } |
---|
| 3448 | |
---|
| 3449 | stream.avail_in = inlen; |
---|
| 3450 | stream.next_in = (void*)inbuf; |
---|
| 3451 | |
---|
[24324] | 3452 | int round = 0; |
---|
[18190] | 3453 | do |
---|
| 3454 | { |
---|
| 3455 | stream.avail_out = maxbuf; |
---|
[24324] | 3456 | |
---|
| 3457 | if(flag == 0 && round > 0) |
---|
| 3458 | { |
---|
| 3459 | char* tmpoutbuf = *outbuf; |
---|
| 3460 | *outbuf = realloc(*outbuf, maxbuf * (round + 1)); |
---|
| 3461 | if(*outbuf == NULL) |
---|
| 3462 | { |
---|
[24350] | 3463 | err("no mem"); |
---|
[24324] | 3464 | free(tmpoutbuf); |
---|
| 3465 | (void)inflateEnd(&stream); |
---|
| 3466 | return 1; |
---|
| 3467 | } |
---|
| 3468 | stream.next_out = (void*)(*outbuf) + maxbuf * round; |
---|
| 3469 | } |
---|
| 3470 | else |
---|
| 3471 | stream.next_out = (void*)*outbuf; |
---|
[18190] | 3472 | |
---|
| 3473 | ret = inflate(&stream, Z_NO_FLUSH); |
---|
| 3474 | if(ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) |
---|
| 3475 | { |
---|
[24279] | 3476 | if(flag == 0) |
---|
| 3477 | { |
---|
| 3478 | free(*outbuf); |
---|
| 3479 | *outbuf = NULL; |
---|
| 3480 | } |
---|
[18190] | 3481 | (void)inflateEnd(&stream); |
---|
| 3482 | return 1; |
---|
| 3483 | } |
---|
| 3484 | |
---|
[24324] | 3485 | round++; |
---|
[18190] | 3486 | } |
---|
| 3487 | while(stream.avail_out == 0); |
---|
[24324] | 3488 | |
---|
| 3489 | if(flag == 0) |
---|
| 3490 | { |
---|
| 3491 | char* tmpoutbuf = *outbuf; |
---|
| 3492 | *outlen = (maxbuf * round) - stream.avail_out; |
---|
| 3493 | *outbuf = realloc(*outbuf, *outlen); |
---|
[24350] | 3494 | if(*outbuf == NULL) |
---|
| 3495 | { |
---|
| 3496 | err("no mem"); |
---|
[24353] | 3497 | if(*outlen > 0) free(tmpoutbuf); |
---|
[24351] | 3498 | *outlen = 0; |
---|
[24350] | 3499 | (void)inflateEnd(&stream); |
---|
| 3500 | return 1; |
---|
| 3501 | } |
---|
[24324] | 3502 | } |
---|
| 3503 | else |
---|
| 3504 | *outlen = maxbuf - stream.avail_out; |
---|
[18190] | 3505 | |
---|
| 3506 | (void)inflateEnd(&stream); |
---|
| 3507 | return 0; |
---|
| 3508 | } |
---|
| 3509 | |
---|
| 3510 | void endianswapshort(unsigned short* value) |
---|
| 3511 | { |
---|
| 3512 | *value = (*value >> 8) | (*value << 8); |
---|
| 3513 | } |
---|
| 3514 | |
---|
| 3515 | int rcnumber(int rcret) |
---|
| 3516 | { |
---|
| 3517 | if(rcret == getrcconfigint("rc0", NULL) || |
---|
| 3518 | rcret == getrcconfigint("rc1", NULL) || |
---|
| 3519 | rcret == getrcconfigint("rc2", NULL) || |
---|
| 3520 | rcret == getrcconfigint("rc3", NULL) || |
---|
| 3521 | rcret == getrcconfigint("rc4", NULL) || |
---|
| 3522 | rcret == getrcconfigint("rc5", NULL) || |
---|
| 3523 | rcret == getrcconfigint("rc6", NULL) || |
---|
| 3524 | rcret == getrcconfigint("rc7", NULL) || |
---|
| 3525 | rcret == getrcconfigint("rc8", NULL) || |
---|
| 3526 | rcret == getrcconfigint("rc9", NULL)) |
---|
| 3527 | return rcret; |
---|
| 3528 | else |
---|
| 3529 | return -9999; |
---|
| 3530 | } |
---|
| 3531 | |
---|
| 3532 | int checkdirext(char* dir, char* ext) |
---|
| 3533 | { |
---|
| 3534 | struct dirent *dirent = NULL; |
---|
| 3535 | DIR *pdir = NULL; |
---|
| 3536 | |
---|
| 3537 | pdir = opendir(dir); |
---|
| 3538 | if(pdir != NULL) |
---|
| 3539 | { |
---|
| 3540 | while((dirent = readdir(pdir)) != NULL) |
---|
| 3541 | { |
---|
| 3542 | if(ostrcmp(".", dirent->d_name) != 0 && ostrcmp("..", dirent->d_name) != 0) |
---|
| 3543 | { |
---|
| 3544 | if(ostrstr(dirent->d_name, ext) != NULL) |
---|
| 3545 | { |
---|
| 3546 | closedir(pdir); |
---|
| 3547 | return 1; |
---|
| 3548 | } |
---|
| 3549 | } |
---|
| 3550 | } |
---|
| 3551 | |
---|
| 3552 | closedir(pdir); |
---|
| 3553 | } |
---|
| 3554 | |
---|
| 3555 | return 0; |
---|
| 3556 | } |
---|
| 3557 | |
---|
| 3558 | int delallfiles(char* dir, char* ext) |
---|
| 3559 | { |
---|
| 3560 | struct dirent *dirent = NULL; |
---|
| 3561 | DIR *pdir = NULL; |
---|
| 3562 | char* tmpstr = NULL; |
---|
| 3563 | |
---|
| 3564 | pdir = opendir(dir); |
---|
| 3565 | if(pdir != NULL) |
---|
| 3566 | { |
---|
| 3567 | while((dirent = readdir(pdir)) != NULL) |
---|
| 3568 | { |
---|
| 3569 | if(ostrcmp(".", dirent->d_name) != 0 && ostrcmp("..", dirent->d_name) != 0) |
---|
| 3570 | { |
---|
| 3571 | if(ext == NULL || ostrstr(dirent->d_name, ext) != NULL) |
---|
| 3572 | { |
---|
| 3573 | tmpstr = ostrcat(dir, "/", 0, 0); |
---|
| 3574 | tmpstr = ostrcat(tmpstr, dirent->d_name, 1, 0); |
---|
| 3575 | unlink(tmpstr); |
---|
| 3576 | free(tmpstr); tmpstr = NULL; |
---|
| 3577 | } |
---|
| 3578 | } |
---|
| 3579 | } |
---|
| 3580 | |
---|
| 3581 | closedir(pdir); |
---|
| 3582 | } |
---|
| 3583 | |
---|
| 3584 | return 0; |
---|
| 3585 | } |
---|
| 3586 | |
---|
| 3587 | unsigned long getfilecount(char* dir) |
---|
| 3588 | { |
---|
| 3589 | unsigned long count = 0; |
---|
| 3590 | struct dirent *dirent = NULL; |
---|
| 3591 | DIR *pdir = NULL; |
---|
| 3592 | |
---|
| 3593 | pdir = opendir(dir); |
---|
| 3594 | if(pdir != NULL) |
---|
| 3595 | { |
---|
| 3596 | while((dirent = readdir(pdir)) != NULL) |
---|
| 3597 | count++; |
---|
| 3598 | |
---|
| 3599 | closedir(pdir); |
---|
| 3600 | } |
---|
| 3601 | |
---|
| 3602 | return count; |
---|
| 3603 | } |
---|
| 3604 | |
---|
| 3605 | int getfiletype(char* filename) |
---|
| 3606 | { |
---|
| 3607 | struct stat64 s; |
---|
| 3608 | |
---|
[22695] | 3609 | if(filename == NULL) return -1; |
---|
| 3610 | |
---|
[18190] | 3611 | if(stat64(filename, &s) >= 0) |
---|
| 3612 | { |
---|
[22695] | 3613 | if(S_ISREG(s.st_mode)) return DT_REG; |
---|
[18190] | 3614 | if(S_ISDIR(s.st_mode)) return DT_DIR; |
---|
[22695] | 3615 | if(S_ISCHR(s.st_mode)) return DT_CHR; |
---|
| 3616 | if(S_ISBLK(s.st_mode)) return DT_BLK; |
---|
| 3617 | if(S_ISFIFO(s.st_mode)) return DT_FIFO; |
---|
| 3618 | if(S_ISLNK(s.st_mode)) return DT_LNK; |
---|
[18190] | 3619 | } |
---|
| 3620 | |
---|
| 3621 | return DT_UNKNOWN; |
---|
| 3622 | } |
---|
| 3623 | |
---|
[21366] | 3624 | int getlfiletype(char* filename) |
---|
| 3625 | { |
---|
| 3626 | struct stat64 s; |
---|
| 3627 | |
---|
| 3628 | if(filename == NULL) return -1; |
---|
| 3629 | |
---|
| 3630 | if(lstat64(filename, &s) >= 0) |
---|
| 3631 | { |
---|
| 3632 | if(S_ISREG(s.st_mode)) return DT_REG; |
---|
| 3633 | if(S_ISDIR(s.st_mode)) return DT_DIR; |
---|
| 3634 | if(S_ISCHR(s.st_mode)) return DT_CHR; |
---|
| 3635 | if(S_ISBLK(s.st_mode)) return DT_BLK; |
---|
| 3636 | if(S_ISFIFO(s.st_mode)) return DT_FIFO; |
---|
| 3637 | if(S_ISLNK(s.st_mode)) return DT_LNK; |
---|
| 3638 | } |
---|
| 3639 | |
---|
| 3640 | return DT_UNKNOWN; |
---|
| 3641 | } |
---|
| 3642 | |
---|
[18190] | 3643 | unsigned long long getfullspace(char* dir) |
---|
| 3644 | { |
---|
| 3645 | struct statfs64 s; |
---|
| 3646 | unsigned long long fullsize = 0; |
---|
| 3647 | |
---|
| 3648 | if(statfs64(dir, &s) >= 0) |
---|
| 3649 | { |
---|
| 3650 | fullsize = s.f_blocks; |
---|
| 3651 | fullsize *= s.f_bsize; |
---|
| 3652 | } |
---|
| 3653 | |
---|
| 3654 | return fullsize; |
---|
| 3655 | } |
---|
| 3656 | |
---|
| 3657 | unsigned long long getfreespace(char* dir) |
---|
| 3658 | { |
---|
| 3659 | struct statfs64 s; |
---|
| 3660 | unsigned long long freesize = 0; |
---|
| 3661 | |
---|
| 3662 | if(statfs64(dir, &s) >= 0) |
---|
| 3663 | { |
---|
| 3664 | freesize = s.f_bfree; |
---|
| 3665 | freesize *= s.f_bsize; |
---|
| 3666 | } |
---|
| 3667 | |
---|
| 3668 | return freesize; |
---|
| 3669 | } |
---|
| 3670 | |
---|
| 3671 | int checkbit(int value, int bitpos) |
---|
| 3672 | { |
---|
| 3673 | int ret = 0; |
---|
| 3674 | |
---|
| 3675 | ret = value & (1 << bitpos) ? 1: 0; |
---|
| 3676 | return ret; |
---|
| 3677 | } |
---|
| 3678 | |
---|
| 3679 | int tooglebit(int value, int bitpos) |
---|
| 3680 | { |
---|
| 3681 | value ^= 1 << bitpos; |
---|
| 3682 | return value; |
---|
| 3683 | } |
---|
| 3684 | |
---|
| 3685 | int clearbit(int value, int bitpos) |
---|
| 3686 | { |
---|
| 3687 | value &= ~(1 << bitpos); |
---|
| 3688 | return value; |
---|
| 3689 | } |
---|
| 3690 | |
---|
| 3691 | int setbit(int value, int bitpos) |
---|
| 3692 | { |
---|
| 3693 | value |= 1 << bitpos; |
---|
| 3694 | return value; |
---|
| 3695 | } |
---|
| 3696 | |
---|
| 3697 | int setsystime(time_t* newtime) |
---|
| 3698 | { |
---|
| 3699 | if (stime(newtime)) |
---|
| 3700 | { |
---|
| 3701 | err("can't set system time"); |
---|
| 3702 | return 1; |
---|
| 3703 | } |
---|
| 3704 | return 0; |
---|
| 3705 | } |
---|
| 3706 | |
---|
| 3707 | off64_t getfilesize(char* name) |
---|
| 3708 | { |
---|
| 3709 | struct stat64 sbuf; |
---|
| 3710 | |
---|
| 3711 | if(lstat64(name, &sbuf) == -1) |
---|
| 3712 | return 0; |
---|
| 3713 | |
---|
| 3714 | return sbuf.st_size; |
---|
| 3715 | } |
---|
| 3716 | |
---|
| 3717 | time_t getfiletime(char* name, int type) |
---|
| 3718 | { |
---|
| 3719 | struct stat64 sbuf; |
---|
| 3720 | |
---|
| 3721 | if(lstat64(name, &sbuf) == -1) |
---|
| 3722 | return 0; |
---|
| 3723 | |
---|
| 3724 | switch(type) |
---|
| 3725 | { |
---|
| 3726 | case 1: return sbuf.st_mtime; |
---|
| 3727 | case 2: return sbuf.st_ctime; |
---|
| 3728 | default: return sbuf.st_atime; |
---|
| 3729 | } |
---|
| 3730 | } |
---|
| 3731 | |
---|
| 3732 | int isfile(char* name) |
---|
| 3733 | { |
---|
| 3734 | struct stat64 sbuf; |
---|
| 3735 | |
---|
| 3736 | if(lstat64(name, &sbuf) == -1) |
---|
| 3737 | return 0; |
---|
| 3738 | |
---|
| 3739 | if(S_ISREG(sbuf.st_mode)) |
---|
| 3740 | return 1; |
---|
| 3741 | |
---|
| 3742 | return 0; |
---|
| 3743 | } |
---|
| 3744 | |
---|
| 3745 | int isdir(char* name) |
---|
| 3746 | { |
---|
| 3747 | struct stat64 sbuf; |
---|
| 3748 | char *rpath = NULL; |
---|
| 3749 | |
---|
| 3750 | if(lstat64(name, &sbuf) == -1) |
---|
| 3751 | return 0; |
---|
| 3752 | |
---|
| 3753 | if(S_ISDIR(sbuf.st_mode)) |
---|
| 3754 | return 1; |
---|
| 3755 | |
---|
| 3756 | if(S_ISLNK(sbuf.st_mode)) |
---|
| 3757 | { |
---|
[23185] | 3758 | rpath = realpath(name, NULL); |
---|
[18190] | 3759 | if(lstat64(rpath, &sbuf) == -1) |
---|
| 3760 | { |
---|
| 3761 | free(rpath); |
---|
| 3762 | return 0; |
---|
| 3763 | } |
---|
| 3764 | free(rpath); |
---|
| 3765 | if(S_ISDIR(sbuf.st_mode)) |
---|
| 3766 | return 1; |
---|
[23183] | 3767 | } |
---|
[18190] | 3768 | |
---|
| 3769 | return 0; |
---|
| 3770 | } |
---|
| 3771 | |
---|
| 3772 | char* getmaxsatstring(int maxsat) |
---|
| 3773 | { |
---|
| 3774 | char* tmpstr = NULL, *tmpnr = NULL; |
---|
| 3775 | int i; |
---|
| 3776 | |
---|
| 3777 | tmpstr = ostrcat(tmpstr, "1", 1, 0); |
---|
| 3778 | for(i = 2; i <= maxsat; i++) |
---|
| 3779 | { |
---|
| 3780 | tmpnr = oitoa(i); |
---|
| 3781 | tmpstr = ostrcat(tmpstr, "\n", 1, 0); |
---|
| 3782 | tmpstr = ostrcat(tmpstr, tmpnr, 1, 1); |
---|
| 3783 | } |
---|
| 3784 | return tmpstr; |
---|
| 3785 | } |
---|
| 3786 | |
---|
| 3787 | void ostrcatbig(char** value1, char* value2, int* maxlen, int* pos) |
---|
| 3788 | { |
---|
| 3789 | int len = 0; |
---|
| 3790 | |
---|
| 3791 | if(value2 == NULL) |
---|
| 3792 | return; |
---|
[23286] | 3793 | |
---|
[24407] | 3794 | len = strlen(value2) + 1; |
---|
[18190] | 3795 | |
---|
| 3796 | if(*value1 != NULL && maxlen == 0) |
---|
| 3797 | *maxlen = strlen(*value1); |
---|
| 3798 | |
---|
[24407] | 3799 | if(*value1 == NULL || *pos + len > *maxlen) |
---|
[18190] | 3800 | { |
---|
[24407] | 3801 | *maxlen = *maxlen + len + (MINMALLOC * 10); |
---|
[18190] | 3802 | *value1 = realloc(*value1, *maxlen); |
---|
| 3803 | if(*value1 == NULL) |
---|
| 3804 | { |
---|
[24350] | 3805 | err("no mem"); |
---|
[18190] | 3806 | return; |
---|
| 3807 | } |
---|
| 3808 | } |
---|
| 3809 | |
---|
[24407] | 3810 | memcpy(*value1 + *pos, value2, len); |
---|
| 3811 | *pos = *pos + (len - 1); |
---|
[18190] | 3812 | } |
---|
| 3813 | |
---|
[19467] | 3814 | char* ostrshrink(char* value) |
---|
| 3815 | { |
---|
| 3816 | int len = 0; |
---|
| 3817 | char* buf = NULL; |
---|
| 3818 | |
---|
| 3819 | if(value == NULL) return NULL; |
---|
| 3820 | |
---|
| 3821 | len = strlen(value); |
---|
| 3822 | if(len == 0) return value; |
---|
| 3823 | |
---|
| 3824 | buf = malloc(len + 1); |
---|
| 3825 | if(buf == NULL) |
---|
| 3826 | return value; |
---|
| 3827 | |
---|
| 3828 | memcpy(buf, value, len); |
---|
| 3829 | free(value); |
---|
| 3830 | buf[len] = '\0'; |
---|
| 3831 | |
---|
| 3832 | return buf; |
---|
| 3833 | } |
---|
| 3834 | |
---|
[18190] | 3835 | char* ostrcat(char* value1, char* value2, int free1, int free2) |
---|
| 3836 | { |
---|
| 3837 | int len = 0, len1 = 0, len2 = 0; |
---|
| 3838 | char* buf = NULL; |
---|
| 3839 | |
---|
| 3840 | if(value1 == NULL && value2 == NULL) return NULL; |
---|
| 3841 | |
---|
| 3842 | if(value1 != NULL) len1 = strlen(value1); |
---|
| 3843 | if(value2 != NULL) len2 = strlen(value2); |
---|
| 3844 | |
---|
| 3845 | len = len1 + len2 + 1; |
---|
| 3846 | |
---|
[19348] | 3847 | if(free1 == 1) |
---|
| 3848 | buf = realloc(value1, len); |
---|
| 3849 | else |
---|
| 3850 | buf = malloc(len); |
---|
[18190] | 3851 | if(buf == NULL) |
---|
| 3852 | { |
---|
[19348] | 3853 | if(free1 == 1) free(value1); |
---|
| 3854 | if(free2 == 1) free(value2); |
---|
[18190] | 3855 | return NULL; |
---|
| 3856 | } |
---|
| 3857 | |
---|
[19348] | 3858 | if(free1 == 0 && len1 > 0) memcpy(buf, value1, len1); |
---|
[18190] | 3859 | if(len2 > 0) memcpy(buf + len1, value2, len2); |
---|
| 3860 | buf[len - 1] = '\0'; |
---|
| 3861 | |
---|
| 3862 | if(free2 == 1) free(value2); |
---|
| 3863 | |
---|
| 3864 | //helpfull for memleak detect |
---|
| 3865 | //if(buf != NULL && strlen(buf) == 0x0b - 0x01) |
---|
| 3866 | // printf("******** memleak string (%s) (%p) ********\n", buf, buf); |
---|
| 3867 | |
---|
| 3868 | return buf; |
---|
| 3869 | } |
---|
| 3870 | |
---|
[18431] | 3871 | char* ollutoa(uint64_t value) |
---|
| 3872 | { |
---|
[19467] | 3873 | char *buf = NULL; |
---|
[18431] | 3874 | |
---|
| 3875 | buf = malloc(MINMALLOC); |
---|
| 3876 | if(buf == NULL) |
---|
| 3877 | { |
---|
[24350] | 3878 | err("no mem"); |
---|
[18431] | 3879 | return NULL; |
---|
| 3880 | } |
---|
| 3881 | |
---|
| 3882 | sprintf(buf, "%llu", value); |
---|
[19467] | 3883 | buf = ostrshrink(buf); |
---|
[18431] | 3884 | |
---|
[19467] | 3885 | return buf; |
---|
[18431] | 3886 | } |
---|
| 3887 | |
---|
[18190] | 3888 | char* olutoa(unsigned long value) |
---|
| 3889 | { |
---|
[19467] | 3890 | char *buf = NULL; |
---|
[18190] | 3891 | |
---|
| 3892 | buf = malloc(MINMALLOC); |
---|
| 3893 | if(buf == NULL) |
---|
| 3894 | { |
---|
[24350] | 3895 | err("no mem"); |
---|
[18190] | 3896 | return NULL; |
---|
| 3897 | } |
---|
| 3898 | |
---|
| 3899 | sprintf(buf, "%lu", value); |
---|
[19467] | 3900 | buf = ostrshrink(buf); |
---|
[18190] | 3901 | |
---|
[19467] | 3902 | return buf; |
---|
[18190] | 3903 | } |
---|
| 3904 | |
---|
| 3905 | char* oitoax(int value) |
---|
| 3906 | { |
---|
[19467] | 3907 | char *buf = NULL; |
---|
[18190] | 3908 | |
---|
| 3909 | buf = malloc(MINMALLOC); |
---|
| 3910 | if(buf == NULL) |
---|
| 3911 | { |
---|
[24350] | 3912 | err("no mem"); |
---|
[18190] | 3913 | return NULL; |
---|
| 3914 | } |
---|
| 3915 | |
---|
| 3916 | sprintf(buf, "%x", value); |
---|
[19467] | 3917 | buf = ostrshrink(buf); |
---|
[18190] | 3918 | |
---|
[19467] | 3919 | return buf; |
---|
[18190] | 3920 | } |
---|
| 3921 | |
---|
| 3922 | char* oitoa(int value) |
---|
| 3923 | { |
---|
[19467] | 3924 | char *buf = NULL; |
---|
[18190] | 3925 | |
---|
| 3926 | buf = malloc(MINMALLOC); |
---|
| 3927 | if(buf == NULL) |
---|
| 3928 | { |
---|
[24350] | 3929 | err("no mem"); |
---|
[18190] | 3930 | return NULL; |
---|
| 3931 | } |
---|
| 3932 | |
---|
| 3933 | sprintf(buf, "%d", value); |
---|
[19467] | 3934 | buf = ostrshrink(buf); |
---|
[18190] | 3935 | |
---|
[19467] | 3936 | return buf; |
---|
[18190] | 3937 | } |
---|
| 3938 | |
---|
| 3939 | char* oitoa64(off64_t value) |
---|
| 3940 | { |
---|
[19467] | 3941 | char *buf = NULL; |
---|
[18190] | 3942 | |
---|
| 3943 | buf = malloc(MINMALLOC); |
---|
| 3944 | if(buf == NULL) |
---|
| 3945 | { |
---|
[24350] | 3946 | err("no mem"); |
---|
[18190] | 3947 | return NULL; |
---|
| 3948 | } |
---|
| 3949 | |
---|
| 3950 | sprintf(buf, "%lld", value); |
---|
[19469] | 3951 | buf = ostrshrink(buf); |
---|
[18190] | 3952 | |
---|
[19467] | 3953 | return buf; |
---|
[18190] | 3954 | } |
---|
| 3955 | |
---|
| 3956 | char* oftoa64(double value, char* count) |
---|
| 3957 | { |
---|
[19467] | 3958 | char *buf = NULL; |
---|
[18190] | 3959 | char* tmpstr = NULL; |
---|
| 3960 | |
---|
| 3961 | buf = malloc(MINMALLOC); |
---|
| 3962 | if(buf == NULL) |
---|
| 3963 | { |
---|
[24350] | 3964 | err("no mem"); |
---|
[18190] | 3965 | return NULL; |
---|
| 3966 | } |
---|
| 3967 | |
---|
| 3968 | tmpstr = ostrcat("%.", count, 0, 0); |
---|
| 3969 | tmpstr = ostrcat(tmpstr, "f", 1, 0); |
---|
| 3970 | |
---|
| 3971 | sprintf(buf, tmpstr, value); |
---|
[19469] | 3972 | buf = ostrshrink(buf); |
---|
[18190] | 3973 | |
---|
| 3974 | free(tmpstr); |
---|
[19467] | 3975 | return buf; |
---|
[18190] | 3976 | } |
---|
| 3977 | |
---|
| 3978 | int ostrncmp(char* value1, char* value2, int count) |
---|
| 3979 | { |
---|
| 3980 | int ret = 1; |
---|
| 3981 | |
---|
| 3982 | if(value1 != NULL && value2 != NULL) |
---|
| 3983 | ret = strncmp(value1, value2, count); |
---|
| 3984 | |
---|
| 3985 | return ret; |
---|
| 3986 | } |
---|
| 3987 | |
---|
| 3988 | int ostrcmp(char* value1, char* value2) |
---|
| 3989 | { |
---|
| 3990 | int ret = 1; |
---|
| 3991 | |
---|
| 3992 | if(value1 != NULL && value2 != NULL) |
---|
| 3993 | ret = strcmp(value1, value2); |
---|
| 3994 | |
---|
| 3995 | return ret; |
---|
| 3996 | } |
---|
| 3997 | |
---|
| 3998 | int ostrcasecmp(char* value1, char* value2) |
---|
| 3999 | { |
---|
| 4000 | int ret = 1; |
---|
| 4001 | |
---|
| 4002 | if(value1 != NULL && value2 != NULL) |
---|
| 4003 | ret = strcasecmp(value1, value2); |
---|
| 4004 | |
---|
| 4005 | return ret; |
---|
| 4006 | } |
---|
| 4007 | |
---|
| 4008 | char* createpath(char* dir, char* file) |
---|
| 4009 | { |
---|
| 4010 | char *absdir = NULL; |
---|
| 4011 | char *pos = NULL; |
---|
| 4012 | char* tmpdir = NULL; |
---|
| 4013 | |
---|
| 4014 | if(dir == NULL || file == NULL) |
---|
| 4015 | { |
---|
[23286] | 4016 | err("NULL detect"); |
---|
[18190] | 4017 | return NULL; |
---|
| 4018 | } |
---|
| 4019 | |
---|
| 4020 | tmpdir = ostrcat(dir, NULL, 0, 0); |
---|
| 4021 | if(tmpdir == NULL) |
---|
| 4022 | { |
---|
[23286] | 4023 | err("NULL detect"); |
---|
[18190] | 4024 | return NULL; |
---|
| 4025 | } |
---|
| 4026 | |
---|
| 4027 | while((tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] != '.') || tmpdir[strlen(tmpdir) - 1] == '/') |
---|
| 4028 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
| 4029 | |
---|
| 4030 | while(tmpdir[strlen(tmpdir) - 1] == '.' && tmpdir[strlen(tmpdir) - 2] == '.') |
---|
| 4031 | { |
---|
| 4032 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
| 4033 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
| 4034 | if(tmpdir[strlen(tmpdir) - 1] == '/') |
---|
| 4035 | tmpdir[strlen(tmpdir) - 1] = '\0'; |
---|
| 4036 | pos = strrchr(tmpdir, '/'); |
---|
| 4037 | if(pos != NULL) |
---|
| 4038 | pos[0] = '\0'; |
---|
| 4039 | } |
---|
| 4040 | |
---|
| 4041 | absdir = malloc(strlen(tmpdir) + strlen(file) + 2); |
---|
| 4042 | if(absdir == NULL) |
---|
| 4043 | { |
---|
| 4044 | free(tmpdir); |
---|
[24350] | 4045 | err("no mem"); |
---|
[18190] | 4046 | return NULL; |
---|
| 4047 | } |
---|
| 4048 | |
---|
| 4049 | if(strlen(file) > 0 || strlen(tmpdir) == 0) |
---|
| 4050 | sprintf(absdir, "%s/%s", tmpdir, file); |
---|
| 4051 | else |
---|
| 4052 | sprintf(absdir, "%s", tmpdir); |
---|
| 4053 | |
---|
| 4054 | free(tmpdir); |
---|
| 4055 | return absdir; |
---|
| 4056 | } |
---|
| 4057 | |
---|
| 4058 | int settimezone(char* zone) |
---|
| 4059 | { |
---|
| 4060 | int ret = 0; |
---|
| 4061 | char* tmpzone = NULL, *zonepath = NULL; |
---|
| 4062 | |
---|
| 4063 | zonepath = getconfig("zonepath", NULL); |
---|
| 4064 | if(zonepath == NULL) |
---|
| 4065 | { |
---|
| 4066 | err("config zonepath not defined"); |
---|
| 4067 | return 1; |
---|
| 4068 | } |
---|
| 4069 | |
---|
| 4070 | tmpzone = createpath(zonepath, zone); |
---|
| 4071 | if(tmpzone == NULL) |
---|
| 4072 | return 1; |
---|
| 4073 | |
---|
| 4074 | setenv("TZ", zone, 1); |
---|
| 4075 | |
---|
| 4076 | ret = unlink(getconfig("localtimefile", NULL)); |
---|
| 4077 | if(ret != 0) |
---|
| 4078 | perr("unlink"); |
---|
| 4079 | ret = symlink(tmpzone, getconfig("localtimefile", NULL)); |
---|
| 4080 | if(ret != 0) |
---|
| 4081 | perr("link"); |
---|
| 4082 | |
---|
| 4083 | free(tmpzone); |
---|
| 4084 | return ret; |
---|
| 4085 | } |
---|
| 4086 | |
---|
| 4087 | int delchar(char** text, int pos) |
---|
| 4088 | { |
---|
| 4089 | char *tmptext = NULL; |
---|
| 4090 | int i = 0, y = 0, len = 0; |
---|
| 4091 | |
---|
| 4092 | if(text == NULL || *text == NULL) |
---|
| 4093 | return pos; |
---|
| 4094 | |
---|
| 4095 | len = strlen(*text); |
---|
| 4096 | if(len == 0) return pos; |
---|
| 4097 | |
---|
| 4098 | tmptext = malloc(strlen(*text)); |
---|
| 4099 | if(tmptext == NULL) |
---|
| 4100 | { |
---|
[24350] | 4101 | err("no mem"); |
---|
[18190] | 4102 | return pos; |
---|
| 4103 | } |
---|
| 4104 | |
---|
| 4105 | for(i = 0; i < strlen(*text); i++) |
---|
| 4106 | { |
---|
| 4107 | if(i == pos - 1) |
---|
| 4108 | y++; |
---|
| 4109 | |
---|
| 4110 | tmptext[i] = (*text)[y]; |
---|
| 4111 | y++; |
---|
| 4112 | } |
---|
| 4113 | |
---|
| 4114 | if(i > 0) tmptext[i - 1] = '\0'; |
---|
| 4115 | if(pos >= strlen(tmptext)) pos = strlen(tmptext); |
---|
| 4116 | |
---|
| 4117 | free(*text); |
---|
| 4118 | *text = tmptext; |
---|
| 4119 | return pos; |
---|
| 4120 | } |
---|
| 4121 | |
---|
| 4122 | |
---|
| 4123 | int insertchar(char** text, char zeichen, int pos) |
---|
| 4124 | { |
---|
| 4125 | char *tmptext = NULL; |
---|
| 4126 | int i, y = 0; |
---|
| 4127 | |
---|
| 4128 | if(text == NULL || *text == NULL) |
---|
| 4129 | return pos; |
---|
| 4130 | |
---|
| 4131 | tmptext = malloc(strlen(*text) + 2); |
---|
| 4132 | if(tmptext == NULL) |
---|
| 4133 | { |
---|
[24350] | 4134 | err("no mem"); |
---|
[18190] | 4135 | return pos; |
---|
| 4136 | } |
---|
| 4137 | |
---|
| 4138 | if(strlen(*text) == 0) |
---|
| 4139 | { |
---|
| 4140 | tmptext[0] = zeichen; |
---|
| 4141 | i = 1; |
---|
| 4142 | pos = 0; |
---|
| 4143 | } |
---|
| 4144 | else |
---|
| 4145 | { |
---|
| 4146 | for(i = 0; i < strlen(*text) + 1; i++) |
---|
| 4147 | { |
---|
| 4148 | if(i == pos) |
---|
| 4149 | tmptext[i] = zeichen; |
---|
| 4150 | else |
---|
| 4151 | { |
---|
| 4152 | tmptext[i] = (*text)[y]; |
---|
| 4153 | y++; |
---|
| 4154 | } |
---|
| 4155 | } |
---|
| 4156 | } |
---|
| 4157 | tmptext[i] = '\0'; |
---|
| 4158 | |
---|
| 4159 | free(*text); |
---|
| 4160 | *text = tmptext; |
---|
| 4161 | return pos + 1; |
---|
| 4162 | } |
---|
| 4163 | |
---|
| 4164 | void calctext(char* buf, char* buf1, unsigned int* linecount, unsigned int* pagecount, unsigned int* poscount, int pagelen, int page) |
---|
| 4165 | { |
---|
| 4166 | unsigned int tmpposcount = 0; |
---|
[24771] | 4167 | unsigned int pagepagelen = 0; |
---|
[18190] | 4168 | |
---|
| 4169 | *poscount = 0; |
---|
| 4170 | *linecount = 1; |
---|
| 4171 | *pagecount = 1; |
---|
| 4172 | |
---|
| 4173 | page--; |
---|
| 4174 | if(page < 0) page = 0; |
---|
[24771] | 4175 | pagepagelen = pagelen * page; |
---|
[18190] | 4176 | |
---|
| 4177 | if(buf != NULL) |
---|
| 4178 | { |
---|
| 4179 | while(*buf != '\0') |
---|
| 4180 | { |
---|
| 4181 | if(*buf == '\n') |
---|
| 4182 | { |
---|
| 4183 | if(*(buf + 1) == '\0') break; |
---|
| 4184 | (*linecount)++; |
---|
| 4185 | |
---|
[24771] | 4186 | if(*linecount - 1 == pagepagelen) |
---|
[18190] | 4187 | *poscount = tmpposcount + 1; |
---|
| 4188 | } |
---|
| 4189 | buf++; |
---|
| 4190 | tmpposcount++; |
---|
| 4191 | } |
---|
| 4192 | } |
---|
| 4193 | |
---|
| 4194 | if(buf1 != NULL) |
---|
| 4195 | { |
---|
| 4196 | while(*buf1 != '\0') |
---|
| 4197 | { |
---|
| 4198 | if(*buf1 == '\n') |
---|
| 4199 | { |
---|
| 4200 | if(*(buf1 + 1) == '\0') break; |
---|
| 4201 | (*linecount)++; |
---|
| 4202 | |
---|
[24771] | 4203 | if(*linecount - 1 == pagepagelen) |
---|
[18190] | 4204 | *poscount = tmpposcount + 1; |
---|
| 4205 | } |
---|
| 4206 | buf1++; |
---|
| 4207 | tmpposcount++; |
---|
| 4208 | } |
---|
| 4209 | } |
---|
| 4210 | |
---|
| 4211 | if(pagelen > 0) |
---|
| 4212 | *pagecount = (int)ceil(((float)*linecount / pagelen)); |
---|
| 4213 | } |
---|
| 4214 | |
---|
| 4215 | int initlocale(char *localepath) |
---|
| 4216 | { |
---|
| 4217 | setlocale(LC_ALL, ""); |
---|
| 4218 | if(bindtextdomain(PROGNAME, localepath) == NULL) |
---|
| 4219 | { |
---|
| 4220 | err("set bindtextdomain"); |
---|
| 4221 | return 1; |
---|
| 4222 | } |
---|
| 4223 | if(textdomain(PROGNAME) == NULL) |
---|
| 4224 | { |
---|
| 4225 | err("set textdomain"); |
---|
| 4226 | return 1; |
---|
| 4227 | } |
---|
| 4228 | return 0; |
---|
| 4229 | } |
---|
| 4230 | |
---|
| 4231 | //for langage you must |
---|
| 4232 | //mkdir /usr/lib/locale |
---|
| 4233 | //ln -s %titanpath%/po /usr/lib/locale/po |
---|
| 4234 | //copy SYS_LC_MESSAGES from other language into LC_MESSAGE |
---|
| 4235 | int setlang(char *lang) |
---|
| 4236 | { |
---|
| 4237 | char *ret; |
---|
| 4238 | |
---|
| 4239 | setenv("LANG", lang, 1); |
---|
| 4240 | setenv("LANGUAGE", lang, 1); |
---|
| 4241 | ret = setlocale(LC_MESSAGES, lang); |
---|
| 4242 | if(ret == NULL) |
---|
| 4243 | { |
---|
| 4244 | err("can't set LC_MESSAGES to %s", lang); |
---|
| 4245 | return 1; |
---|
| 4246 | } |
---|
| 4247 | return 0; |
---|
| 4248 | } |
---|
| 4249 | |
---|
[24781] | 4250 | unsigned long readsysul(const char *filename, int line) |
---|
[18190] | 4251 | { |
---|
| 4252 | int i = 0, len = 0; |
---|
[24781] | 4253 | unsigned long ret = 0; |
---|
| 4254 | FILE *fd = NULL; |
---|
| 4255 | char *fileline = NULL; |
---|
| 4256 | char *buf1 = NULL; |
---|
| 4257 | |
---|
| 4258 | fileline = malloc(MINMALLOC); |
---|
| 4259 | if(fileline == NULL) |
---|
| 4260 | { |
---|
| 4261 | err("no mem"); |
---|
| 4262 | return 0; |
---|
| 4263 | } |
---|
| 4264 | |
---|
| 4265 | fd = fopen(filename, "r"); |
---|
| 4266 | if(fd == NULL) |
---|
| 4267 | { |
---|
| 4268 | perr("can't open %s", filename); |
---|
| 4269 | free(fileline); |
---|
| 4270 | return 0; |
---|
| 4271 | } |
---|
| 4272 | |
---|
| 4273 | for(i = 0; i < line; i++) |
---|
| 4274 | { |
---|
| 4275 | memset(fileline, 0, MINMALLOC); |
---|
| 4276 | fgets(fileline, MINMALLOC, fd); |
---|
| 4277 | } |
---|
| 4278 | |
---|
| 4279 | len = strlen(fileline) - 1; |
---|
| 4280 | if(len >= 0 && fileline[len] == '\n') |
---|
| 4281 | fileline[len] = '\0'; |
---|
| 4282 | buf1 = ostrshrink(fileline); |
---|
| 4283 | |
---|
| 4284 | fclose(fd); |
---|
| 4285 | |
---|
| 4286 | if(buf1 != NULL) |
---|
| 4287 | { |
---|
| 4288 | ret = strtoul(buf1, NULL, 10); |
---|
| 4289 | free(buf1); buf1 = NULL; |
---|
| 4290 | } |
---|
| 4291 | |
---|
| 4292 | return ret; |
---|
| 4293 | } |
---|
| 4294 | |
---|
| 4295 | unsigned long long readsysull(const char *filename, int line) |
---|
| 4296 | { |
---|
| 4297 | int i = 0, len = 0; |
---|
[24779] | 4298 | unsigned long long ret = 0; |
---|
[18190] | 4299 | FILE *fd = NULL; |
---|
| 4300 | char *fileline = NULL; |
---|
| 4301 | char *buf1 = NULL; |
---|
| 4302 | |
---|
| 4303 | fileline = malloc(MINMALLOC); |
---|
| 4304 | if(fileline == NULL) |
---|
| 4305 | { |
---|
[24350] | 4306 | err("no mem"); |
---|
[18190] | 4307 | return 0; |
---|
| 4308 | } |
---|
| 4309 | |
---|
| 4310 | fd = fopen(filename, "r"); |
---|
| 4311 | if(fd == NULL) |
---|
| 4312 | { |
---|
| 4313 | perr("can't open %s", filename); |
---|
| 4314 | free(fileline); |
---|
| 4315 | return 0; |
---|
| 4316 | } |
---|
| 4317 | |
---|
| 4318 | for(i = 0; i < line; i++) |
---|
| 4319 | { |
---|
| 4320 | memset(fileline, 0, MINMALLOC); |
---|
| 4321 | fgets(fileline, MINMALLOC, fd); |
---|
| 4322 | } |
---|
| 4323 | |
---|
| 4324 | len = strlen(fileline) - 1; |
---|
| 4325 | if(len >= 0 && fileline[len] == '\n') |
---|
| 4326 | fileline[len] = '\0'; |
---|
[19467] | 4327 | buf1 = ostrshrink(fileline); |
---|
[18190] | 4328 | |
---|
| 4329 | fclose(fd); |
---|
| 4330 | |
---|
| 4331 | if(buf1 != NULL) |
---|
| 4332 | { |
---|
[24779] | 4333 | ret = strtoull(buf1, NULL, 10); |
---|
[18190] | 4334 | free(buf1); buf1 = NULL; |
---|
| 4335 | } |
---|
| 4336 | |
---|
| 4337 | return ret; |
---|
| 4338 | } |
---|
| 4339 | |
---|
| 4340 | char* readsys(const char *filename, int line) |
---|
| 4341 | { |
---|
| 4342 | int i = 0, len = 0; |
---|
| 4343 | FILE *fd = NULL; |
---|
| 4344 | char *fileline = NULL; |
---|
| 4345 | char *buf1 = NULL; |
---|
| 4346 | |
---|
| 4347 | fileline = malloc(MINMALLOC); |
---|
| 4348 | if(fileline == NULL) |
---|
| 4349 | { |
---|
[24350] | 4350 | err("no mem"); |
---|
[18190] | 4351 | return NULL; |
---|
| 4352 | } |
---|
| 4353 | |
---|
| 4354 | fd = fopen(filename, "r"); |
---|
| 4355 | if(fd == NULL) |
---|
| 4356 | { |
---|
| 4357 | perr("can't open %s", filename); |
---|
| 4358 | free(fileline); |
---|
| 4359 | return NULL; |
---|
| 4360 | } |
---|
| 4361 | |
---|
| 4362 | for(i = 0; i < line; i++) |
---|
| 4363 | { |
---|
| 4364 | memset(fileline, 0, MINMALLOC); |
---|
| 4365 | fgets(fileline, MINMALLOC, fd); |
---|
| 4366 | } |
---|
| 4367 | |
---|
| 4368 | len = strlen(fileline) - 1; |
---|
| 4369 | if(len >= 0 && fileline[len] == '\n') |
---|
| 4370 | fileline[len] = '\0'; |
---|
[19467] | 4371 | buf1 = ostrshrink(fileline); |
---|
[18190] | 4372 | |
---|
| 4373 | fclose(fd); |
---|
| 4374 | return buf1; |
---|
| 4375 | } |
---|
| 4376 | |
---|
| 4377 | //flag 0: without \n |
---|
| 4378 | //flag 1: with \n |
---|
[18945] | 4379 | //flag 2: append without \n |
---|
| 4380 | //flag 3: append with \n |
---|
[18190] | 4381 | int writesys(const char *filename, char *value, int flag) |
---|
| 4382 | { |
---|
| 4383 | FILE *fd = NULL; |
---|
| 4384 | char* tmpstr = NULL; |
---|
| 4385 | int ret; |
---|
| 4386 | |
---|
| 4387 | if(value == NULL) |
---|
| 4388 | { |
---|
[23286] | 4389 | err("NULL detect"); |
---|
[18190] | 4390 | return 1; |
---|
| 4391 | } |
---|
| 4392 | |
---|
[18945] | 4393 | if(flag == 2 || flag == 3) |
---|
| 4394 | fd = fopen(filename, "a"); |
---|
| 4395 | else |
---|
| 4396 | fd = fopen(filename, "w"); |
---|
[18190] | 4397 | if(fd == NULL) |
---|
| 4398 | { |
---|
| 4399 | perr("can't open %s", filename); |
---|
| 4400 | return 1; |
---|
| 4401 | } |
---|
| 4402 | |
---|
[18945] | 4403 | if(flag == 1 || flag == 3) |
---|
[18190] | 4404 | tmpstr = ostrcat(value, "\n", 0, 0); |
---|
| 4405 | else |
---|
| 4406 | tmpstr = ostrcat(value, NULL, 0, 0); |
---|
| 4407 | |
---|
| 4408 | ret = fwrite(tmpstr, strlen(tmpstr), 1, fd); |
---|
| 4409 | if(ret != 1) |
---|
| 4410 | { |
---|
| 4411 | perr("writting to %s", filename); |
---|
| 4412 | free(tmpstr); |
---|
| 4413 | fclose(fd); |
---|
| 4414 | return 1; |
---|
| 4415 | } |
---|
| 4416 | |
---|
| 4417 | free(tmpstr); |
---|
| 4418 | fclose(fd); |
---|
| 4419 | return 0; |
---|
| 4420 | } |
---|
| 4421 | |
---|
[18990] | 4422 | //flag 0: without \n |
---|
| 4423 | //flag 1: with \n |
---|
| 4424 | //flag 2: append without \n |
---|
| 4425 | //flag 3: append with \n |
---|
[18190] | 4426 | int writesysint(const char *filename, int value, int flag) |
---|
| 4427 | { |
---|
| 4428 | char* tmpstr = NULL; |
---|
| 4429 | int ret = 0; |
---|
| 4430 | |
---|
| 4431 | tmpstr = oitoa(value); |
---|
| 4432 | ret = writesys(filename, tmpstr, flag); |
---|
| 4433 | |
---|
| 4434 | free(tmpstr); |
---|
| 4435 | return ret; |
---|
| 4436 | } |
---|
| 4437 | |
---|
| 4438 | char* getdevcontent(char* devconfig) |
---|
| 4439 | { |
---|
| 4440 | char *dev = NULL; |
---|
| 4441 | char *value = NULL; |
---|
| 4442 | |
---|
| 4443 | dev = getconfig(devconfig, NULL); |
---|
| 4444 | |
---|
| 4445 | if(dev == NULL) |
---|
| 4446 | { |
---|
[23286] | 4447 | err("NULL detect"); |
---|
[18190] | 4448 | return NULL; |
---|
| 4449 | } |
---|
| 4450 | |
---|
| 4451 | value = readsys(dev, 1); |
---|
| 4452 | if(value == NULL) |
---|
| 4453 | { |
---|
[23286] | 4454 | err("NULL detect"); |
---|
[18190] | 4455 | return NULL; |
---|
| 4456 | } |
---|
| 4457 | |
---|
| 4458 | return value; |
---|
| 4459 | } |
---|
| 4460 | |
---|
| 4461 | char* convertspacetolf(char* value) |
---|
| 4462 | { |
---|
| 4463 | int i = 0; |
---|
| 4464 | |
---|
| 4465 | while(value[i] != '\0') |
---|
| 4466 | { |
---|
| 4467 | if(value[i] == ' ') |
---|
| 4468 | value[i] = '\n'; |
---|
| 4469 | i++; |
---|
| 4470 | } |
---|
| 4471 | |
---|
| 4472 | return value; |
---|
| 4473 | } |
---|
| 4474 | |
---|
[23212] | 4475 | //flag 0: all |
---|
| 4476 | //flag 1: hdmi |
---|
| 4477 | //flag 2: not hdmi |
---|
| 4478 | char* getcolorformatchoices(int flag) |
---|
[18190] | 4479 | { |
---|
| 4480 | char *colorformatchoicesdev = NULL; |
---|
| 4481 | char *value = NULL; |
---|
| 4482 | |
---|
| 4483 | colorformatchoicesdev = getconfig("colorformatchoicesdev", NULL); |
---|
| 4484 | |
---|
| 4485 | if(colorformatchoicesdev == NULL) |
---|
| 4486 | { |
---|
[23286] | 4487 | err("NULL detect"); |
---|
[18190] | 4488 | return NULL; |
---|
| 4489 | } |
---|
| 4490 | |
---|
| 4491 | value = readsys(colorformatchoicesdev, 1); |
---|
| 4492 | if(value == NULL) |
---|
| 4493 | { |
---|
[23286] | 4494 | err("NULL detect"); |
---|
[18190] | 4495 | return NULL; |
---|
| 4496 | } |
---|
[23212] | 4497 | |
---|
| 4498 | if(flag == 1) |
---|
| 4499 | { |
---|
| 4500 | value = string_replace("rgb", NULL, value, 1); |
---|
| 4501 | value = string_replace(" ", " ", value, 1); |
---|
| 4502 | value = string_replace("cvbs", NULL, value, 1); |
---|
| 4503 | value = string_replace(" ", " ", value, 1); |
---|
| 4504 | value = string_replace("svideo", NULL, value, 1); |
---|
| 4505 | value = string_replace(" ", " ", value, 1); |
---|
| 4506 | value = string_replace("yuv", NULL, value, 1); |
---|
| 4507 | value = string_replace(" ", " ", value, 1); |
---|
| 4508 | } |
---|
| 4509 | else if(flag == 2) |
---|
| 4510 | { |
---|
| 4511 | value = string_replace("hdmi_rgb", NULL, value, 1); |
---|
| 4512 | value = string_replace(" ", " ", value, 1); |
---|
| 4513 | value = string_replace("hdmi_yuv", NULL, value, 1); |
---|
| 4514 | value = string_replace(" ", " ", value, 1); |
---|
| 4515 | value = string_replace("hdmi_422", NULL, value, 1); |
---|
| 4516 | value = string_replace(" ", " ", value, 1); |
---|
| 4517 | } |
---|
[18190] | 4518 | |
---|
[23212] | 4519 | value = strstrip(value); |
---|
[18190] | 4520 | value = convertspacetolf(value); |
---|
| 4521 | |
---|
| 4522 | return value; |
---|
| 4523 | } |
---|
| 4524 | |
---|
| 4525 | char* getaudiosourcechoices() |
---|
| 4526 | { |
---|
| 4527 | char *audiosourcechoicesdev = NULL; |
---|
| 4528 | char *value = NULL; |
---|
| 4529 | |
---|
| 4530 | audiosourcechoicesdev = getconfig("audiosourcechoicesdev", NULL); |
---|
| 4531 | |
---|
| 4532 | if(audiosourcechoicesdev == NULL) |
---|
| 4533 | { |
---|
[23286] | 4534 | err("NULL detect"); |
---|
[18190] | 4535 | return NULL; |
---|
| 4536 | } |
---|
| 4537 | |
---|
| 4538 | value = readsys(audiosourcechoicesdev, 1); |
---|
| 4539 | if(value == NULL) |
---|
| 4540 | { |
---|
[23286] | 4541 | err("NULL detect"); |
---|
[18190] | 4542 | return NULL; |
---|
| 4543 | } |
---|
| 4544 | |
---|
| 4545 | value = convertspacetolf(value); |
---|
| 4546 | |
---|
| 4547 | return value; |
---|
| 4548 | } |
---|
| 4549 | |
---|
| 4550 | char* getac3choices() |
---|
| 4551 | { |
---|
| 4552 | char *ac3choicesdev = NULL; |
---|
| 4553 | char *value = NULL; |
---|
| 4554 | |
---|
| 4555 | ac3choicesdev = getconfig("ac3choicesdev", NULL); |
---|
| 4556 | |
---|
| 4557 | if(ac3choicesdev == NULL) |
---|
| 4558 | { |
---|
[23286] | 4559 | err("NULL detect"); |
---|
[18190] | 4560 | return NULL; |
---|
| 4561 | } |
---|
| 4562 | |
---|
| 4563 | value = readsys(ac3choicesdev, 1); |
---|
| 4564 | if(value == NULL) |
---|
| 4565 | { |
---|
[23286] | 4566 | err("NULL detect"); |
---|
[18190] | 4567 | return NULL; |
---|
| 4568 | } |
---|
| 4569 | |
---|
| 4570 | value = convertspacetolf(value); |
---|
| 4571 | |
---|
| 4572 | return value; |
---|
| 4573 | } |
---|
| 4574 | |
---|
| 4575 | int setciclock(int slotnr, char* value) |
---|
| 4576 | { |
---|
| 4577 | char* ciclockdev = NULL, *tmpstr = NULL; |
---|
| 4578 | int ret = 0; |
---|
| 4579 | |
---|
| 4580 | ciclockdev = getconfig("ciclockdev", NULL); |
---|
| 4581 | |
---|
| 4582 | if(ciclockdev != NULL && value != NULL) |
---|
| 4583 | { |
---|
| 4584 | tmpstr = malloc(MINMALLOC); |
---|
| 4585 | if(tmpstr == NULL) |
---|
| 4586 | { |
---|
| 4587 | err("no mem"); |
---|
| 4588 | return 1; |
---|
| 4589 | } |
---|
| 4590 | |
---|
| 4591 | snprintf(tmpstr, MINMALLOC, ciclockdev, slotnr); |
---|
| 4592 | debug(100, "set %s to %s", tmpstr, value); |
---|
| 4593 | ret = writesys(tmpstr, value, 0); |
---|
| 4594 | |
---|
| 4595 | free(tmpstr); tmpstr = NULL; |
---|
| 4596 | return ret; |
---|
| 4597 | } |
---|
| 4598 | |
---|
| 4599 | return 0; |
---|
| 4600 | } |
---|
| 4601 | |
---|
| 4602 | //routes stream from tuner to ci or ci to ci |
---|
| 4603 | int setciinput(int slotnr, char* value) |
---|
| 4604 | { |
---|
| 4605 | char* ciinputdev = NULL, *tmpstr = NULL; |
---|
| 4606 | int ret = 0; |
---|
| 4607 | |
---|
| 4608 | ciinputdev = getconfig("ciinputdev", NULL); |
---|
| 4609 | |
---|
| 4610 | if(ciinputdev != NULL && value != NULL) |
---|
| 4611 | { |
---|
| 4612 | tmpstr = malloc(MINMALLOC); |
---|
| 4613 | if(tmpstr == NULL) |
---|
| 4614 | { |
---|
| 4615 | err("no mem"); |
---|
| 4616 | return 1; |
---|
| 4617 | } |
---|
| 4618 | |
---|
| 4619 | snprintf(tmpstr, MINMALLOC, ciinputdev, slotnr); |
---|
| 4620 | debug(100, "set %s to %s", tmpstr, value); |
---|
| 4621 | ret = writesys(tmpstr, value, 0); |
---|
| 4622 | |
---|
| 4623 | free(tmpstr); tmpstr = NULL; |
---|
| 4624 | return ret; |
---|
| 4625 | } |
---|
| 4626 | |
---|
| 4627 | return 0; |
---|
| 4628 | } |
---|
| 4629 | |
---|
| 4630 | //routes stream from tuner or ci to linux |
---|
| 4631 | int setcisource(int tunernr, char* value) |
---|
| 4632 | { |
---|
| 4633 | char* cisourcedev = NULL, *tmpstr = NULL; |
---|
| 4634 | int ret = 0; |
---|
| 4635 | |
---|
| 4636 | cisourcedev = getconfig("cisourcedev", NULL); |
---|
| 4637 | |
---|
| 4638 | if(cisourcedev != NULL && value != NULL) |
---|
| 4639 | { |
---|
| 4640 | tmpstr = malloc(MINMALLOC); |
---|
| 4641 | if(tmpstr == NULL) |
---|
| 4642 | { |
---|
| 4643 | err("no mem"); |
---|
| 4644 | return 1; |
---|
| 4645 | } |
---|
| 4646 | |
---|
| 4647 | snprintf(tmpstr, MINMALLOC, cisourcedev, tunernr); |
---|
| 4648 | debug(100, "set %s to %s", tmpstr, value); |
---|
| 4649 | ret = writesys(tmpstr, value, 0); |
---|
| 4650 | |
---|
| 4651 | free(tmpstr); tmpstr = NULL; |
---|
| 4652 | return ret; |
---|
| 4653 | } |
---|
| 4654 | |
---|
| 4655 | return 0; |
---|
| 4656 | } |
---|
| 4657 | |
---|
| 4658 | int setinput(char* value) |
---|
| 4659 | { |
---|
| 4660 | char* inputdev = NULL; |
---|
| 4661 | int ret = 0; |
---|
| 4662 | |
---|
| 4663 | inputdev = getconfig("inputdev", NULL); |
---|
| 4664 | |
---|
| 4665 | if(inputdev != NULL && value != NULL) |
---|
| 4666 | { |
---|
| 4667 | debug(100, "set %s to %s", inputdev, value); |
---|
| 4668 | ret = writesys(inputdev, value, 0); |
---|
| 4669 | return ret; |
---|
| 4670 | } |
---|
| 4671 | |
---|
| 4672 | return 0; |
---|
| 4673 | } |
---|
| 4674 | |
---|
| 4675 | char* getinput() |
---|
| 4676 | { |
---|
| 4677 | char *inputdev = NULL; |
---|
| 4678 | char *value = NULL; |
---|
| 4679 | |
---|
| 4680 | inputdev = getconfig("inputdev", NULL); |
---|
| 4681 | |
---|
| 4682 | if(inputdev == NULL) |
---|
| 4683 | { |
---|
[23286] | 4684 | err("NULL detect"); |
---|
[18190] | 4685 | return NULL; |
---|
| 4686 | } |
---|
| 4687 | |
---|
| 4688 | value = readsys(inputdev, 1); |
---|
| 4689 | if(value == NULL) |
---|
| 4690 | { |
---|
[23286] | 4691 | err("NULL detect"); |
---|
[18190] | 4692 | return NULL; |
---|
| 4693 | } |
---|
| 4694 | |
---|
| 4695 | return value; |
---|
| 4696 | } |
---|
| 4697 | |
---|
| 4698 | int setac3(char* value) |
---|
| 4699 | { |
---|
| 4700 | char* ac3dev = NULL; |
---|
| 4701 | int ret = 0; |
---|
| 4702 | |
---|
| 4703 | ac3dev = getconfig("ac3dev", NULL); |
---|
| 4704 | |
---|
| 4705 | if(ac3dev != NULL && value != NULL) |
---|
| 4706 | { |
---|
| 4707 | debug(100, "set %s to %s", ac3dev, value); |
---|
| 4708 | ret = writesys(ac3dev, value, 0); |
---|
| 4709 | if(ret == 0) addconfig("av_ac3mode", value); |
---|
| 4710 | return ret; |
---|
| 4711 | } |
---|
| 4712 | |
---|
| 4713 | return 0; |
---|
| 4714 | } |
---|
| 4715 | |
---|
| 4716 | char* getac3() |
---|
| 4717 | { |
---|
| 4718 | char *ac3dev = NULL; |
---|
| 4719 | char *value = NULL; |
---|
| 4720 | |
---|
| 4721 | ac3dev = getconfig("ac3dev", NULL); |
---|
| 4722 | |
---|
| 4723 | if(ac3dev == NULL) |
---|
| 4724 | { |
---|
[23286] | 4725 | err("NULL detect"); |
---|
[18190] | 4726 | return NULL; |
---|
| 4727 | } |
---|
| 4728 | |
---|
| 4729 | value = readsys(ac3dev, 1); |
---|
| 4730 | if(value == NULL) |
---|
| 4731 | { |
---|
[23286] | 4732 | err("NULL detect"); |
---|
[18190] | 4733 | return NULL; |
---|
| 4734 | } |
---|
| 4735 | |
---|
| 4736 | return value; |
---|
| 4737 | } |
---|
| 4738 | |
---|
[20621] | 4739 | int setaudiodelaybitstream(char* value) |
---|
| 4740 | { |
---|
| 4741 | char* audiodelaybitstreamdev = NULL; |
---|
| 4742 | int ret = 0; |
---|
| 4743 | |
---|
| 4744 | audiodelaybitstreamdev = getconfig("audiodelaybitstreamdev", NULL); |
---|
| 4745 | |
---|
| 4746 | if(audiodelaybitstreamdev != NULL && value != NULL) |
---|
| 4747 | { |
---|
| 4748 | debug(100, "set %s to %s", audiodelaybitstreamdev, value); |
---|
| 4749 | ret = writesys(audiodelaybitstreamdev, value, 0); |
---|
| 4750 | if(ret == 0) addconfig("audiodelaybitstream", value); |
---|
| 4751 | return ret; |
---|
| 4752 | } |
---|
| 4753 | |
---|
| 4754 | return 0; |
---|
| 4755 | } |
---|
| 4756 | |
---|
| 4757 | char* getaudiodelaybitstream() |
---|
| 4758 | { |
---|
| 4759 | char *audiodelaybitstreamdev = NULL; |
---|
| 4760 | char *value = NULL; |
---|
| 4761 | |
---|
| 4762 | audiodelaybitstreamdev = getconfig("audiodelaybitstreamdev", NULL); |
---|
| 4763 | |
---|
| 4764 | if(audiodelaybitstreamdev == NULL) |
---|
| 4765 | { |
---|
[23286] | 4766 | err("NULL detect"); |
---|
[20621] | 4767 | return NULL; |
---|
| 4768 | } |
---|
| 4769 | |
---|
| 4770 | value = readsys(audiodelaybitstreamdev, 1); |
---|
| 4771 | if(value == NULL) |
---|
| 4772 | { |
---|
[23286] | 4773 | err("NULL detect"); |
---|
[20621] | 4774 | return NULL; |
---|
| 4775 | } |
---|
| 4776 | |
---|
| 4777 | return value; |
---|
| 4778 | } |
---|
| 4779 | |
---|
[18190] | 4780 | char* getpolicychoices() |
---|
| 4781 | { |
---|
| 4782 | char *policychoicesdev = NULL; |
---|
| 4783 | char *value = NULL; |
---|
| 4784 | |
---|
| 4785 | policychoicesdev = getconfig("policychoicesdev", NULL); |
---|
| 4786 | |
---|
| 4787 | if(policychoicesdev == NULL) |
---|
| 4788 | { |
---|
[23286] | 4789 | err("NULL detect"); |
---|
[18190] | 4790 | return NULL; |
---|
| 4791 | } |
---|
| 4792 | |
---|
| 4793 | value = readsys(policychoicesdev, 1); |
---|
| 4794 | if(value == NULL) |
---|
| 4795 | { |
---|
[23286] | 4796 | err("NULL detect"); |
---|
[18190] | 4797 | return NULL; |
---|
| 4798 | } |
---|
| 4799 | |
---|
| 4800 | value = convertspacetolf(value); |
---|
| 4801 | |
---|
| 4802 | return value; |
---|
| 4803 | } |
---|
| 4804 | |
---|
| 4805 | char* getpolicy() |
---|
| 4806 | { |
---|
| 4807 | char *policydev = NULL; |
---|
| 4808 | char *value = NULL; |
---|
| 4809 | |
---|
| 4810 | policydev = getconfig("policydev", NULL); |
---|
| 4811 | |
---|
| 4812 | if(policydev == NULL) |
---|
| 4813 | { |
---|
[23286] | 4814 | err("NULL detect"); |
---|
[18190] | 4815 | return NULL; |
---|
| 4816 | } |
---|
| 4817 | |
---|
| 4818 | value = readsys(policydev, 1); |
---|
| 4819 | if(value == NULL) |
---|
| 4820 | { |
---|
[23286] | 4821 | err("NULL detect"); |
---|
[18190] | 4822 | return NULL; |
---|
| 4823 | } |
---|
| 4824 | |
---|
| 4825 | return value; |
---|
| 4826 | } |
---|
| 4827 | |
---|
| 4828 | int setpolicy(char* value) |
---|
| 4829 | { |
---|
| 4830 | char* policydev; |
---|
| 4831 | int ret = 0; |
---|
| 4832 | |
---|
| 4833 | policydev = getconfig("policydev", NULL); |
---|
| 4834 | |
---|
| 4835 | if(policydev != NULL && value != NULL) |
---|
| 4836 | { |
---|
| 4837 | debug(100, "set %s to %s", policydev, value); |
---|
| 4838 | ret = writesys(policydev, value, 0); |
---|
| 4839 | if(ret == 0) addconfig("av_policy", value); |
---|
| 4840 | return ret; |
---|
| 4841 | } |
---|
| 4842 | |
---|
| 4843 | return 0; |
---|
| 4844 | } |
---|
| 4845 | |
---|
| 4846 | char* getaspectchoices() |
---|
| 4847 | { |
---|
| 4848 | char *aspectchoicesdev = NULL; |
---|
| 4849 | char *value = NULL; |
---|
| 4850 | |
---|
| 4851 | aspectchoicesdev = getconfig("aspectchoicesdev", NULL); |
---|
| 4852 | |
---|
| 4853 | if(aspectchoicesdev == NULL) |
---|
| 4854 | { |
---|
[23286] | 4855 | err("NULL detect"); |
---|
[18190] | 4856 | return NULL; |
---|
| 4857 | } |
---|
| 4858 | |
---|
| 4859 | value = readsys(aspectchoicesdev, 1); |
---|
| 4860 | if(value == NULL) |
---|
| 4861 | { |
---|
[23286] | 4862 | err("NULL detect"); |
---|
[18190] | 4863 | return NULL; |
---|
| 4864 | } |
---|
| 4865 | |
---|
| 4866 | value = convertspacetolf(value); |
---|
| 4867 | |
---|
| 4868 | return value; |
---|
| 4869 | } |
---|
| 4870 | |
---|
| 4871 | char* getaspect() |
---|
| 4872 | { |
---|
| 4873 | char *aspectdev = NULL; |
---|
| 4874 | char *value = NULL; |
---|
| 4875 | |
---|
| 4876 | aspectdev = getconfig("aspectdev", NULL); |
---|
| 4877 | |
---|
| 4878 | if(aspectdev == NULL) |
---|
| 4879 | { |
---|
[23286] | 4880 | err("NULL detect"); |
---|
[18190] | 4881 | return NULL; |
---|
| 4882 | } |
---|
| 4883 | |
---|
| 4884 | value = readsys(aspectdev, 1); |
---|
| 4885 | if(value == NULL) |
---|
| 4886 | { |
---|
[23286] | 4887 | err("NULL detect"); |
---|
[18190] | 4888 | return NULL; |
---|
| 4889 | } |
---|
| 4890 | |
---|
| 4891 | return value; |
---|
| 4892 | } |
---|
| 4893 | |
---|
| 4894 | int setaspect(char* value) |
---|
| 4895 | { |
---|
| 4896 | char* aspectdev; |
---|
| 4897 | int ret = 0; |
---|
| 4898 | |
---|
| 4899 | aspectdev = getconfig("aspectdev", NULL); |
---|
| 4900 | |
---|
| 4901 | if(aspectdev != NULL && value != NULL) |
---|
| 4902 | { |
---|
| 4903 | debug(100, "set %s to %s", aspectdev, value); |
---|
| 4904 | ret = writesys(aspectdev, value, 0); |
---|
[21041] | 4905 | if(ret == 0) |
---|
| 4906 | { |
---|
| 4907 | addconfig("av_aspect", value); |
---|
| 4908 | |
---|
| 4909 | //set policy new after change aspect |
---|
[21047] | 4910 | char* tmpstr = getpolicy(); |
---|
[21041] | 4911 | setpolicy(tmpstr); |
---|
| 4912 | free(tmpstr); tmpstr = NULL; |
---|
| 4913 | } |
---|
[18190] | 4914 | return ret; |
---|
| 4915 | } |
---|
| 4916 | |
---|
| 4917 | return 0; |
---|
| 4918 | } |
---|
| 4919 | |
---|
| 4920 | char* getvideomodechoices() |
---|
| 4921 | { |
---|
| 4922 | char *videomodechoicesdev = NULL; |
---|
| 4923 | char *value = NULL; |
---|
| 4924 | |
---|
| 4925 | videomodechoicesdev = getconfig("videomodechoicesdev", NULL); |
---|
| 4926 | |
---|
| 4927 | if(videomodechoicesdev == NULL) |
---|
| 4928 | { |
---|
[23286] | 4929 | err("NULL detect"); |
---|
[18190] | 4930 | return NULL; |
---|
| 4931 | } |
---|
| 4932 | |
---|
| 4933 | value = readsys(videomodechoicesdev, 1); |
---|
| 4934 | if(value == NULL) |
---|
| 4935 | { |
---|
[23286] | 4936 | err("NULL detect"); |
---|
[18190] | 4937 | return NULL; |
---|
| 4938 | } |
---|
| 4939 | |
---|
[22859] | 4940 | value = string_replace("pal", NULL, value, 1); |
---|
[20751] | 4941 | value = string_replace(" ", " ", value, 1); |
---|
| 4942 | |
---|
[20115] | 4943 | if(status.mcaktiv == 0) |
---|
[18975] | 4944 | { |
---|
[22859] | 4945 | value = string_replace("1080p60", NULL, value, 1); |
---|
[18190] | 4946 | value = string_replace(" ", " ", value, 1); |
---|
[22859] | 4947 | value = string_replace("1080p59", NULL, value, 1); |
---|
[18190] | 4948 | value = string_replace(" ", " ", value, 1); |
---|
[22859] | 4949 | value = string_replace("1080p30", NULL, value, 1); |
---|
[18190] | 4950 | value = string_replace(" ", " ", value, 1); |
---|
[25360] | 4951 | value = string_replace("1080p29", NULL, value, 1); |
---|
| 4952 | value = string_replace(" ", " ", value, 1); |
---|
[22859] | 4953 | value = string_replace("1080p25", NULL, value, 1); |
---|
[18190] | 4954 | value = string_replace(" ", " ", value, 1); |
---|
[22859] | 4955 | value = string_replace("1080p24", NULL, value, 1); |
---|
[18190] | 4956 | value = string_replace(" ", " ", value, 1); |
---|
[25360] | 4957 | value = string_replace("1080p23", NULL, value, 1); |
---|
| 4958 | value = string_replace(" ", " ", value, 1); |
---|
[22859] | 4959 | value = string_replace("1080i60", NULL, value, 1); |
---|
[18190] | 4960 | value = string_replace(" ", " ", value, 1); |
---|
[25360] | 4961 | value = string_replace("1080i59", NULL, value, 1); |
---|
| 4962 | value = string_replace(" ", " ", value, 1); |
---|
| 4963 | value = string_replace("1080i60", NULL, value, 1); |
---|
| 4964 | value = string_replace(" ", " ", value, 1); |
---|
[22859] | 4965 | value = string_replace("720p60", NULL, value, 1); |
---|
[18190] | 4966 | value = string_replace(" ", " ", value, 1); |
---|
[25360] | 4967 | value = string_replace("576p50", NULL, value, 1); |
---|
| 4968 | value = string_replace(" ", " ", value, 1); |
---|
| 4969 | value = string_replace("1280x1024_75", NULL, value, 1); |
---|
| 4970 | value = string_replace(" ", " ", value, 1); |
---|
| 4971 | value = string_replace("1280x1024_70", NULL, value, 1); |
---|
| 4972 | value = string_replace(" ", " ", value, 1); |
---|
| 4973 | value = string_replace("1280x1024_60", NULL, value, 1); |
---|
| 4974 | value = string_replace(" ", " ", value, 1); |
---|
| 4975 | value = string_replace("1600x1200_60", NULL, value, 1); |
---|
| 4976 | value = string_replace(" ", " ", value, 1); |
---|
| 4977 | value = string_replace("1024x768_100", NULL, value, 1); |
---|
| 4978 | value = string_replace(" ", " ", value, 1); |
---|
| 4979 | value = string_replace("1024x768_90", NULL, value, 1); |
---|
| 4980 | value = string_replace(" ", " ", value, 1); |
---|
| 4981 | value = string_replace("1024x768_75", NULL, value, 1); |
---|
| 4982 | value = string_replace(" ", " ", value, 1); |
---|
| 4983 | value = string_replace("1024x768_70", NULL, value, 1); |
---|
| 4984 | value = string_replace(" ", " ", value, 1); |
---|
| 4985 | value = string_replace("1024x768_60", NULL, value, 1); |
---|
| 4986 | value = string_replace(" ", " ", value, 1); |
---|
[18975] | 4987 | } |
---|
[18190] | 4988 | |
---|
[22859] | 4989 | value = strstrip(value); |
---|
[18190] | 4990 | value = convertspacetolf(value); |
---|
| 4991 | |
---|
| 4992 | return value; |
---|
| 4993 | } |
---|
| 4994 | |
---|
| 4995 | char* getmode3dchoices() |
---|
| 4996 | { |
---|
| 4997 | char *mode3dchoicesdev = NULL; |
---|
| 4998 | char *value = NULL; |
---|
| 4999 | |
---|
| 5000 | mode3dchoicesdev = getconfig("mode3dchoicesdev", NULL); |
---|
| 5001 | |
---|
| 5002 | if(mode3dchoicesdev == NULL) |
---|
| 5003 | { |
---|
| 5004 | return ostrcat("off\nsbs\ntab", "", 0, 0); |
---|
| 5005 | } |
---|
| 5006 | |
---|
| 5007 | value = readsys(mode3dchoicesdev, 1); |
---|
| 5008 | if(value == NULL) |
---|
| 5009 | { |
---|
[23286] | 5010 | err("NULL detect"); |
---|
[18190] | 5011 | return NULL; |
---|
| 5012 | } |
---|
| 5013 | |
---|
| 5014 | value = convertspacetolf(value); |
---|
| 5015 | |
---|
| 5016 | return value; |
---|
| 5017 | } |
---|
| 5018 | |
---|
| 5019 | char* getmode3d() |
---|
| 5020 | { |
---|
| 5021 | char *mode3ddev = NULL; |
---|
| 5022 | char *value = NULL; |
---|
| 5023 | |
---|
| 5024 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
| 5025 | |
---|
| 5026 | if(mode3ddev == NULL) |
---|
| 5027 | { |
---|
[23286] | 5028 | err("NULL detect"); |
---|
[18190] | 5029 | return NULL; |
---|
| 5030 | } |
---|
| 5031 | |
---|
| 5032 | value = readsys(mode3ddev, 1); |
---|
| 5033 | if(value == NULL) |
---|
| 5034 | { |
---|
[23286] | 5035 | err("NULL detect"); |
---|
[18190] | 5036 | return NULL; |
---|
| 5037 | } |
---|
| 5038 | |
---|
| 5039 | return value; |
---|
| 5040 | } |
---|
| 5041 | |
---|
| 5042 | int setmode3d(char* value) |
---|
| 5043 | { |
---|
| 5044 | char* mode3ddev; |
---|
| 5045 | int ret = 0; |
---|
| 5046 | |
---|
| 5047 | mode3ddev = getconfig("mode3ddev", NULL); |
---|
| 5048 | |
---|
| 5049 | if(mode3ddev != NULL && value != NULL) |
---|
| 5050 | { |
---|
| 5051 | debug(100, "set %s to %s", mode3ddev, value); |
---|
| 5052 | ret = writesys(mode3ddev, value, 0); |
---|
| 5053 | if(ret == 0) addconfig("av_mode3d", value); |
---|
| 5054 | return ret; |
---|
| 5055 | } |
---|
| 5056 | |
---|
| 5057 | return 0; |
---|
| 5058 | } |
---|
| 5059 | |
---|
| 5060 | char* getvideomode() |
---|
| 5061 | { |
---|
| 5062 | char *videomodedev = NULL; |
---|
| 5063 | char *value = NULL; |
---|
| 5064 | |
---|
| 5065 | videomodedev = getconfig("videomodedev", NULL); |
---|
| 5066 | |
---|
| 5067 | if(videomodedev == NULL) |
---|
| 5068 | { |
---|
[23286] | 5069 | err("NULL detect"); |
---|
[18190] | 5070 | return NULL; |
---|
| 5071 | } |
---|
| 5072 | |
---|
| 5073 | value = readsys(videomodedev, 1); |
---|
| 5074 | if(value == NULL) |
---|
| 5075 | { |
---|
[23286] | 5076 | err("NULL detect"); |
---|
[18190] | 5077 | return NULL; |
---|
| 5078 | } |
---|
| 5079 | |
---|
| 5080 | return value; |
---|
| 5081 | } |
---|
| 5082 | |
---|
| 5083 | void switchvideomode() |
---|
| 5084 | { |
---|
| 5085 | int rcret = 0; |
---|
[25133] | 5086 | char* tmpstr = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL; |
---|
[18190] | 5087 | tmpstr = getvideomode(); |
---|
| 5088 | struct skin* playpolicy = getscreen("playpolicy"); |
---|
[25133] | 5089 | tmpstr2 = getcolorformat(2); |
---|
| 5090 | |
---|
[18190] | 5091 | if(tmpstr != NULL) |
---|
| 5092 | { |
---|
[25133] | 5093 | if((ostrcmp("pal", tmpstr) == 0 || ostrncmp("576", tmpstr, 3) == 0) && ostrncmp("yuv", tmpstr2, 3) == 0) |
---|
[18190] | 5094 | { |
---|
| 5095 | setvideomode("720p50", 0); |
---|
[20751] | 5096 | changefbresolution("720p50", 0); |
---|
[25133] | 5097 | changetext(playpolicy, "720p50 (rgb)"); |
---|
| 5098 | writevfdmenu("720p50 (rgb)"); |
---|
| 5099 | setcolorformat("rgb", 1); |
---|
[18520] | 5100 | unlink("/var/etc/.scart"); |
---|
[18190] | 5101 | } |
---|
[25133] | 5102 | else if((ostrcmp("pal", tmpstr) == 0 || ostrncmp("576", tmpstr, 3) == 0) && ostrncmp("rgb", tmpstr2, 3) == 0) |
---|
| 5103 | { |
---|
| 5104 | setvideomode("720p50", 0); |
---|
| 5105 | changefbresolution("720p50", 0); |
---|
| 5106 | changetext(playpolicy, "720p50 (yuv)"); |
---|
| 5107 | writevfdmenu("720p50 (yuv)"); |
---|
| 5108 | setcolorformat("yuv", 1); |
---|
| 5109 | unlink("/var/etc/.scart"); |
---|
| 5110 | } |
---|
[18190] | 5111 | else if(ostrncmp("720", tmpstr, 3) == 0) |
---|
| 5112 | { |
---|
| 5113 | setvideomode("1080i50", 0); |
---|
[20751] | 5114 | changefbresolution("1080i50", 0); |
---|
[25133] | 5115 | tmpstr3 = ostrcat("1080i50 (", tmpstr2, 0, 0); |
---|
| 5116 | tmpstr3 = ostrcat(tmpstr3, ")", 1, 0); |
---|
| 5117 | changetext(playpolicy, tmpstr3); |
---|
| 5118 | writevfdmenu(tmpstr3); |
---|
[18520] | 5119 | unlink("/var/etc/.scart"); |
---|
[18190] | 5120 | } |
---|
| 5121 | else if(ostrncmp("1080", tmpstr, 4) == 0) |
---|
| 5122 | { |
---|
| 5123 | setvideomode("576i50", 0); |
---|
[20751] | 5124 | changefbresolution("576i50", 0); |
---|
[25133] | 5125 | changetext(playpolicy, "576i50 (rgb)"); |
---|
| 5126 | writevfdmenu("576i50 (rgb)"); |
---|
| 5127 | setcolorformat("rgb", 1); |
---|
[18520] | 5128 | writesys("/var/etc/.scart", "0", 0); |
---|
[18190] | 5129 | } |
---|
| 5130 | /* |
---|
| 5131 | int ret = textbox(_("Message"), _("Is this Videomode ok ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
[20280] | 5132 | if(ret == 1 || ret == 2) |
---|
[18190] | 5133 | { |
---|
| 5134 | setvideomode(tmpstr, 0); |
---|
[20751] | 5135 | changefbresolution(tmpstr, 0); |
---|
[18190] | 5136 | } |
---|
| 5137 | */ |
---|
| 5138 | drawscreen(playpolicy, 0, 0); |
---|
| 5139 | while(1) |
---|
| 5140 | { |
---|
| 5141 | rcret = waitrc(playpolicy, 5000, 0); |
---|
| 5142 | break; |
---|
| 5143 | } |
---|
| 5144 | clearscreen(playpolicy); |
---|
| 5145 | } |
---|
| 5146 | free(tmpstr); |
---|
[25133] | 5147 | free(tmpstr2); |
---|
| 5148 | free(tmpstr3); |
---|
[18190] | 5149 | } |
---|
| 5150 | |
---|
| 5151 | //flag 0: write videomode to config |
---|
| 5152 | //flag 1: don't write videomode to config |
---|
| 5153 | int setvideomode(char* value, int flag) |
---|
| 5154 | { |
---|
| 5155 | char* videomodedev; |
---|
| 5156 | int ret = 0; |
---|
| 5157 | |
---|
| 5158 | videomodedev = getconfig("videomodedev", NULL); |
---|
| 5159 | |
---|
| 5160 | if(videomodedev != NULL && value != NULL) |
---|
| 5161 | { |
---|
| 5162 | debug(100, "set %s to %s", videomodedev, value); |
---|
| 5163 | ret = writesys(videomodedev, value, 0); |
---|
| 5164 | if(ret == 0 && flag == 0) addconfig("av_videomode", value); |
---|
| 5165 | return ret; |
---|
| 5166 | } |
---|
| 5167 | |
---|
| 5168 | return 0; |
---|
| 5169 | } |
---|
| 5170 | |
---|
[23976] | 5171 | //flag 0 = hdmi |
---|
| 5172 | //flag 1 = scart |
---|
| 5173 | int setcolorformat(char* value, int flag) |
---|
[18190] | 5174 | { |
---|
| 5175 | char* colorformatdev; |
---|
| 5176 | int ret = 0; |
---|
| 5177 | |
---|
| 5178 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
| 5179 | |
---|
| 5180 | if(colorformatdev != NULL && value != NULL) |
---|
| 5181 | { |
---|
| 5182 | debug(100, "set %s to %s", colorformatdev, value); |
---|
| 5183 | ret = writesys(colorformatdev, value, 0); |
---|
[23976] | 5184 | if(ret == 0) |
---|
| 5185 | { |
---|
| 5186 | if(flag == 0) |
---|
| 5187 | addconfig("av_colorformat", value); |
---|
| 5188 | else |
---|
| 5189 | addconfig("av_colorformatscart", value); |
---|
| 5190 | } |
---|
[18190] | 5191 | return ret; |
---|
| 5192 | } |
---|
| 5193 | |
---|
| 5194 | return 0; |
---|
| 5195 | } |
---|
| 5196 | |
---|
| 5197 | char* getcolorformat(int line) |
---|
| 5198 | { |
---|
| 5199 | char *colorformatdev = NULL; |
---|
| 5200 | char *value = NULL; |
---|
| 5201 | |
---|
| 5202 | colorformatdev = getconfig("colorformatdev", NULL); |
---|
| 5203 | |
---|
| 5204 | if(colorformatdev == NULL) |
---|
| 5205 | { |
---|
[23286] | 5206 | err("NULL detect"); |
---|
[18190] | 5207 | return NULL; |
---|
| 5208 | } |
---|
| 5209 | |
---|
| 5210 | value = readsys(colorformatdev, line); |
---|
| 5211 | if(value == NULL) |
---|
| 5212 | { |
---|
[23286] | 5213 | err("NULL detect"); |
---|
[18190] | 5214 | return NULL; |
---|
| 5215 | } |
---|
| 5216 | |
---|
| 5217 | return value; |
---|
| 5218 | } |
---|
| 5219 | |
---|
| 5220 | int setaudiosource(char* value) |
---|
| 5221 | { |
---|
| 5222 | char* audiosourcedev; |
---|
| 5223 | int ret = 1; |
---|
| 5224 | |
---|
| 5225 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
| 5226 | |
---|
| 5227 | if(audiosourcedev != NULL && value != NULL) |
---|
| 5228 | { |
---|
| 5229 | debug(100, "set %s to %s", audiosourcedev, value); |
---|
| 5230 | ret = writesys(audiosourcedev, value, 0); |
---|
| 5231 | if(ret == 0) addconfig("av_audiosource", value); |
---|
| 5232 | return ret; |
---|
| 5233 | } |
---|
| 5234 | |
---|
| 5235 | return 0; |
---|
| 5236 | } |
---|
| 5237 | |
---|
| 5238 | char* getaudiosource() |
---|
| 5239 | { |
---|
| 5240 | char *audiosourcedev = NULL; |
---|
| 5241 | char *value = NULL; |
---|
| 5242 | |
---|
| 5243 | audiosourcedev = getconfig("audiosourcedev", NULL); |
---|
| 5244 | |
---|
| 5245 | if(audiosourcedev == NULL) |
---|
| 5246 | { |
---|
[23286] | 5247 | err("NULL detect"); |
---|
[18190] | 5248 | return NULL; |
---|
| 5249 | } |
---|
| 5250 | |
---|
| 5251 | value = readsys(audiosourcedev, 1); |
---|
| 5252 | if(value == NULL) |
---|
| 5253 | { |
---|
[23286] | 5254 | err("NULL detect"); |
---|
[18190] | 5255 | return NULL; |
---|
| 5256 | } |
---|
| 5257 | |
---|
| 5258 | return value; |
---|
| 5259 | } |
---|
| 5260 | |
---|
[19965] | 5261 | char* getsataswitch() |
---|
| 5262 | { |
---|
| 5263 | char *sataswitchdev = NULL; |
---|
| 5264 | char *value = NULL; |
---|
| 5265 | |
---|
| 5266 | sataswitchdev = getconfig("sataswitchdev", NULL); |
---|
| 5267 | |
---|
| 5268 | if(sataswitchdev == NULL) |
---|
| 5269 | { |
---|
[23286] | 5270 | err("NULL detect"); |
---|
[19965] | 5271 | return NULL; |
---|
| 5272 | } |
---|
| 5273 | |
---|
| 5274 | value = readsys(sataswitchdev, 1); |
---|
| 5275 | if(value == NULL) |
---|
| 5276 | { |
---|
[23286] | 5277 | err("NULL detect"); |
---|
[19965] | 5278 | return NULL; |
---|
| 5279 | } |
---|
| 5280 | |
---|
| 5281 | return value; |
---|
| 5282 | } |
---|
| 5283 | |
---|
[19969] | 5284 | int setsataswitch(char* value) |
---|
| 5285 | { |
---|
| 5286 | char* sataswitchdev; |
---|
| 5287 | int ret = 1; |
---|
| 5288 | |
---|
| 5289 | sataswitchdev = getconfig("sataswitchdev", NULL); |
---|
| 5290 | |
---|
| 5291 | if(sataswitchdev != NULL && value != NULL) |
---|
| 5292 | { |
---|
| 5293 | debug(100, "set %s to %s", sataswitchdev, value); |
---|
| 5294 | ret = writesys(sataswitchdev, value, 0); |
---|
| 5295 | return ret; |
---|
| 5296 | } |
---|
| 5297 | |
---|
| 5298 | return 0; |
---|
| 5299 | } |
---|
| 5300 | |
---|
[18190] | 5301 | int setprogress(value) |
---|
| 5302 | { |
---|
| 5303 | char *progressdev; |
---|
| 5304 | |
---|
| 5305 | progressdev = getconfig("progressdev", NULL); |
---|
| 5306 | |
---|
| 5307 | if(progressdev != NULL) |
---|
| 5308 | { |
---|
| 5309 | debug(100, "set %s to %d",progressdev, value); |
---|
| 5310 | return writesysint(progressdev, value, 0); |
---|
| 5311 | } |
---|
| 5312 | |
---|
| 5313 | return 0; |
---|
| 5314 | } |
---|
| 5315 | |
---|
| 5316 | int setmute(int value) |
---|
| 5317 | { |
---|
| 5318 | char* mutedev; |
---|
[19391] | 5319 | int tmpvol, ret = 0; |
---|
[18190] | 5320 | |
---|
[19391] | 5321 | //don't set mute 2x |
---|
| 5322 | if(value == 1 && status.mute == 1) return 0; |
---|
| 5323 | |
---|
[25687] | 5324 | // printf("mute value: %d\n", value); |
---|
[25597] | 5325 | |
---|
[18190] | 5326 | if(value == 2) |
---|
[25597] | 5327 | { |
---|
[18190] | 5328 | tmpvol = getvol(); |
---|
| 5329 | tmpvol = tmpvol * 50 / 100; |
---|
[19491] | 5330 | status.mute = value; |
---|
[18190] | 5331 | setvol(tmpvol); |
---|
| 5332 | } |
---|
| 5333 | else |
---|
| 5334 | { |
---|
| 5335 | mutedev = getconfig("mutedev", NULL); |
---|
| 5336 | |
---|
| 5337 | if(mutedev != NULL) |
---|
| 5338 | { |
---|
| 5339 | debug(100, "set %s to %d", mutedev, value); |
---|
[19483] | 5340 | //if(status.volautochangevalue != 0 && value == 0) setvol(getvol()); |
---|
[19391] | 5341 | ret = writesysint(mutedev, value, 0); |
---|
| 5342 | if(ret == 0) status.mute = value; |
---|
[19483] | 5343 | if(status.volautochangevalue != 0 && value == 0) setvol(getvol()); |
---|
[25686] | 5344 | // if(value == 1) |
---|
| 5345 | // { |
---|
| 5346 | // printf("mute\n"); |
---|
| 5347 | // system("amixer -c 1 set HDMI mute &"); |
---|
| 5348 | // system("amixer -c 1 set Analog mute &"); |
---|
| 5349 | // system("amixer -c 1 set SPDIF mute &"); |
---|
| 5350 | // sleep(1); |
---|
| 5351 | // } |
---|
| 5352 | // else |
---|
| 5353 | // { |
---|
| 5354 | // printf("unmute\n"); |
---|
| 5355 | // system("amixer -c 1 set HDMI unmute &"); |
---|
| 5356 | // system("amixer -c 1 set Analog unmute &"); |
---|
| 5357 | // system("amixer -c 1 set SPDIF unmute &"); |
---|
| 5358 | // } |
---|
[25597] | 5359 | |
---|
[19391] | 5360 | return ret; |
---|
[18190] | 5361 | } |
---|
| 5362 | } |
---|
| 5363 | return 0; |
---|
| 5364 | } |
---|
| 5365 | |
---|
| 5366 | int setvol(int value) |
---|
| 5367 | { |
---|
| 5368 | char* voldev; |
---|
| 5369 | int ret = 0, tmpvol = value; |
---|
| 5370 | |
---|
| 5371 | voldev = getconfig("voldev", NULL); |
---|
[19481] | 5372 | |
---|
[18190] | 5373 | if(voldev != NULL) |
---|
| 5374 | { |
---|
| 5375 | if(value > 100) value = 100; |
---|
| 5376 | if(value < 0) value = 0; |
---|
[18906] | 5377 | if(status.volautochangevalue != 0 && value != 0) |
---|
| 5378 | { |
---|
[19481] | 5379 | if(status.volautochange == 0) |
---|
[18906] | 5380 | value = value - (status.volautochangevalue * value / 100); |
---|
| 5381 | } |
---|
[18190] | 5382 | value = 63 - value * 63 / 100; |
---|
| 5383 | debug(100, "set %s to %d", voldev, value); |
---|
[19481] | 5384 | ret = 0; |
---|
| 5385 | if(status.mute == 1) |
---|
| 5386 | status.volmute = value; |
---|
| 5387 | else |
---|
| 5388 | { |
---|
[19905] | 5389 | status.volmute = -1; |
---|
[19481] | 5390 | ret = writesysint(voldev, value, 0); |
---|
[27960] | 5391 | |
---|
| 5392 | #ifdef MIPSEL |
---|
| 5393 | struct dvbdev *audionode = NULL; |
---|
| 5394 | int openaudio = 0; |
---|
| 5395 | |
---|
[24768] | 5396 | if(ret == 0 && status.aktservice != NULL) |
---|
[27960] | 5397 | { |
---|
| 5398 | if(status.aktservice->audiodev == NULL) |
---|
| 5399 | { |
---|
| 5400 | audionode = audioopen(0); //we must open the audio device for change volume in external player |
---|
| 5401 | openaudio = 1; |
---|
| 5402 | } |
---|
| 5403 | else |
---|
| 5404 | audionode = status.aktservice->audiodev; |
---|
| 5405 | |
---|
| 5406 | if(ret == 0 && audionode != NULL) |
---|
| 5407 | ret = setmixer(audionode, value, value); |
---|
| 5408 | |
---|
| 5409 | if(openaudio == 1) |
---|
| 5410 | audioclose(audionode, -1); |
---|
| 5411 | } |
---|
| 5412 | #else |
---|
| 5413 | if(ret == 0 && status.aktservice != NULL) |
---|
[24767] | 5414 | ret = setmixer(status.aktservice->audiodev, value, value); |
---|
[27960] | 5415 | #endif |
---|
[19481] | 5416 | } |
---|
[18190] | 5417 | if(ret == 0 && status.mute != 2) addconfigint("vol", tmpvol); |
---|
| 5418 | return ret; |
---|
| 5419 | } |
---|
| 5420 | |
---|
| 5421 | return 0; |
---|
| 5422 | } |
---|
| 5423 | |
---|
| 5424 | int getvol() |
---|
| 5425 | { |
---|
| 5426 | char *voldev = NULL; |
---|
| 5427 | char *value = NULL; |
---|
[19905] | 5428 | int tmpvol = -1; |
---|
[18190] | 5429 | |
---|
| 5430 | voldev = getconfig("voldev", NULL); |
---|
| 5431 | |
---|
| 5432 | if(voldev == NULL) |
---|
| 5433 | { |
---|
[23286] | 5434 | err("NULL detect"); |
---|
[18190] | 5435 | return 0; |
---|
| 5436 | } |
---|
[19905] | 5437 | if(status.volmute == -1) |
---|
[19481] | 5438 | value = readsys(voldev, 1); |
---|
| 5439 | else |
---|
[19484] | 5440 | tmpvol = status.volmute; |
---|
[19905] | 5441 | if(value == NULL && tmpvol == -1) |
---|
[18190] | 5442 | { |
---|
[23286] | 5443 | err("NULL detect"); |
---|
[18190] | 5444 | return 0; |
---|
| 5445 | } |
---|
[19905] | 5446 | if(status.volmute == -1) |
---|
[19481] | 5447 | tmpvol = atoi(value); |
---|
[18190] | 5448 | free(value); |
---|
| 5449 | tmpvol = 100 - tmpvol * 100 / 63; |
---|
[18906] | 5450 | if(status.volautochangevalue != 0) |
---|
| 5451 | { |
---|
[19481] | 5452 | if(status.volautochange == 0 && status.volautochangevalue < 100) |
---|
[19473] | 5453 | tmpvol = tmpvol + ((tmpvol * status.volautochangevalue) / (100 - status.volautochangevalue)); |
---|
[18906] | 5454 | } |
---|
[18190] | 5455 | return tmpvol; |
---|
| 5456 | } |
---|
| 5457 | |
---|
| 5458 | void setdebuglevel() |
---|
| 5459 | { |
---|
| 5460 | debug_level = getconfigint("debuglevel", NULL); |
---|
| 5461 | debug(0, "set debug level to %d", debug_level); |
---|
| 5462 | } |
---|
| 5463 | |
---|
| 5464 | char* getxmlentry(char *line, char *searchstr) |
---|
| 5465 | { |
---|
| 5466 | char *buf = NULL, *buf1 = NULL, *buf2 = NULL; |
---|
| 5467 | |
---|
| 5468 | buf = ostrstr(line, searchstr); |
---|
| 5469 | if(buf == NULL) |
---|
| 5470 | return NULL; |
---|
[23286] | 5471 | |
---|
[18190] | 5472 | buf = buf + strlen(searchstr); |
---|
| 5473 | if(buf[0] == '"') |
---|
| 5474 | { |
---|
| 5475 | buf = buf + 1; |
---|
[23987] | 5476 | buf2 = strchr(buf, '"'); |
---|
[18190] | 5477 | if(buf2 == NULL) |
---|
| 5478 | { |
---|
| 5479 | err("strchr returns NULL"); |
---|
| 5480 | return NULL; |
---|
| 5481 | } |
---|
[23991] | 5482 | buf1 = strndup(buf, buf2 - buf); |
---|
[18190] | 5483 | if(buf1 == NULL) |
---|
| 5484 | { |
---|
[23991] | 5485 | err("strndup failed"); |
---|
[18190] | 5486 | return NULL; |
---|
| 5487 | } |
---|
[23987] | 5488 | } |
---|
| 5489 | else |
---|
| 5490 | { |
---|
| 5491 | buf2 = strchr(buf, ' '); |
---|
[18190] | 5492 | if(buf2 == NULL) |
---|
| 5493 | { |
---|
[23987] | 5494 | buf2 = ostrstr(buf, "/>"); |
---|
[18190] | 5495 | if(buf2 == NULL) |
---|
| 5496 | { |
---|
[23987] | 5497 | buf2 = strchr(buf, '>'); |
---|
[18190] | 5498 | if(buf2 == NULL) |
---|
| 5499 | { |
---|
| 5500 | err("strchr returns NULL"); |
---|
| 5501 | return NULL; |
---|
| 5502 | } |
---|
| 5503 | } |
---|
| 5504 | } |
---|
[23991] | 5505 | buf1 = strndup(buf, buf2 - buf); |
---|
[23987] | 5506 | if(buf1 == NULL) |
---|
| 5507 | { |
---|
[23991] | 5508 | err("strndup failed"); |
---|
[23987] | 5509 | return NULL; |
---|
| 5510 | } |
---|
[18190] | 5511 | } |
---|
[23286] | 5512 | |
---|
[18190] | 5513 | return buf1; |
---|
| 5514 | } |
---|
| 5515 | |
---|
[19831] | 5516 | char* readbintomem(const char* filename, size_t size) |
---|
| 5517 | { |
---|
| 5518 | FILE *fd = NULL; |
---|
| 5519 | char *fileline = NULL; |
---|
| 5520 | |
---|
| 5521 | fileline = calloc(1, size + 1); |
---|
| 5522 | if(fileline == NULL) |
---|
| 5523 | { |
---|
[24350] | 5524 | err("no mem"); |
---|
[19831] | 5525 | return NULL; |
---|
| 5526 | } |
---|
| 5527 | |
---|
| 5528 | fd = fopen(filename, "rb"); |
---|
| 5529 | if(fd == NULL) |
---|
| 5530 | { |
---|
| 5531 | perr("can't open %s", filename); |
---|
| 5532 | free(fileline); |
---|
| 5533 | return NULL; |
---|
| 5534 | } |
---|
| 5535 | |
---|
| 5536 | fread(fileline, size, 1, fd); |
---|
| 5537 | |
---|
| 5538 | fclose(fd); |
---|
| 5539 | return fileline; |
---|
| 5540 | } |
---|
| 5541 | |
---|
[18190] | 5542 | char* readfiletomem(const char* filename, int flag) |
---|
| 5543 | { |
---|
| 5544 | FILE *fd = NULL; |
---|
[23984] | 5545 | char *fileline = NULL, *buf = NULL, *tmpbuf = NULL; |
---|
| 5546 | int bufsize = 0, bufoldsize = 0; |
---|
[18190] | 5547 | |
---|
| 5548 | fileline = malloc(MINMALLOC); |
---|
| 5549 | if(fileline == NULL) |
---|
| 5550 | { |
---|
[24350] | 5551 | err("no mem"); |
---|
[18190] | 5552 | return NULL; |
---|
| 5553 | } |
---|
| 5554 | |
---|
| 5555 | fd = fopen(filename, "r"); |
---|
| 5556 | if(fd == NULL) |
---|
| 5557 | { |
---|
| 5558 | perr("can't open %s", filename); |
---|
| 5559 | free(fileline); |
---|
| 5560 | return NULL; |
---|
| 5561 | } |
---|
| 5562 | |
---|
| 5563 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
| 5564 | { |
---|
| 5565 | if(flag == 1) |
---|
[23984] | 5566 | if(fileline[0] == '#' || fileline[0] == '\n') |
---|
[18190] | 5567 | continue; |
---|
| 5568 | |
---|
[23984] | 5569 | bufoldsize = bufsize; |
---|
| 5570 | bufsize += strlen(fileline); |
---|
| 5571 | tmpbuf = buf; buf = realloc(buf, bufsize + 1); |
---|
| 5572 | if(buf == NULL) |
---|
[18190] | 5573 | { |
---|
[24350] | 5574 | err("no mem"); |
---|
[18190] | 5575 | free(fileline); |
---|
[23984] | 5576 | free(tmpbuf); |
---|
[18190] | 5577 | fclose(fd); |
---|
| 5578 | return NULL; |
---|
| 5579 | } |
---|
| 5580 | |
---|
[23984] | 5581 | sprintf(buf + bufoldsize, "%s", fileline); |
---|
[18190] | 5582 | } |
---|
| 5583 | |
---|
| 5584 | free(fileline); |
---|
| 5585 | fclose(fd); |
---|
[23984] | 5586 | return buf; |
---|
[18190] | 5587 | } |
---|
| 5588 | |
---|
| 5589 | char* readeittomem(const char* filename) |
---|
| 5590 | { |
---|
| 5591 | unsigned char byte; |
---|
| 5592 | FILE *fil = NULL; |
---|
[23984] | 5593 | char *zeichen = NULL, *buf = NULL, *buf1 = NULL, *tmpbuf1 = NULL; |
---|
[18190] | 5594 | int buf1size = 0, buf1oldsize = 0; |
---|
| 5595 | int Beschreibung; |
---|
[22329] | 5596 | int len; |
---|
[18190] | 5597 | |
---|
| 5598 | zeichen = malloc(255); |
---|
| 5599 | if(zeichen == NULL) |
---|
| 5600 | { |
---|
[24350] | 5601 | err("no mem"); |
---|
[18190] | 5602 | return NULL; |
---|
| 5603 | } |
---|
| 5604 | buf = malloc(255); |
---|
| 5605 | if(buf == NULL) |
---|
| 5606 | { |
---|
| 5607 | free(zeichen); |
---|
[24350] | 5608 | err("no mem"); |
---|
[18190] | 5609 | return NULL; |
---|
| 5610 | } |
---|
| 5611 | |
---|
| 5612 | fil = fopen(filename, "r"); |
---|
| 5613 | if(fil == NULL) |
---|
| 5614 | { |
---|
| 5615 | err("can't open %s", filename); |
---|
| 5616 | free(zeichen); |
---|
| 5617 | free(buf); |
---|
| 5618 | return NULL; |
---|
| 5619 | } |
---|
| 5620 | Beschreibung = 0; |
---|
| 5621 | fseek(fil, 12, SEEK_SET); //ersten 12 Byte nicht relevant |
---|
[23984] | 5622 | while(!feof(fil)) |
---|
| 5623 | { |
---|
| 5624 | byte = fgetc(fil); |
---|
[22329] | 5625 | |
---|
[23984] | 5626 | if(byte == 0x4D) |
---|
| 5627 | { |
---|
[18190] | 5628 | fseek(fil, 4,SEEK_CUR); |
---|
[23984] | 5629 | byte = fgetc(fil); |
---|
[18190] | 5630 | len = byte + 0; |
---|
[23984] | 5631 | byte = fgetc(fil); |
---|
| 5632 | fgets(zeichen, len, fil); |
---|
| 5633 | if(byte != 0x05) |
---|
| 5634 | sprintf(buf, "%c%s\n", byte, zeichen); |
---|
[18190] | 5635 | else |
---|
[23984] | 5636 | sprintf(buf, "%s\n", zeichen); |
---|
[18190] | 5637 | |
---|
| 5638 | buf1oldsize = buf1size; |
---|
| 5639 | buf1size += strlen(buf); |
---|
[23984] | 5640 | tmpbuf1 = buf1; buf1 = realloc(buf1, buf1size + 1); |
---|
[18190] | 5641 | if(buf1 == NULL) |
---|
| 5642 | { |
---|
[24350] | 5643 | err("no mem"); |
---|
[18190] | 5644 | free(zeichen); |
---|
| 5645 | free(buf); |
---|
[23984] | 5646 | free(tmpbuf1); |
---|
[18190] | 5647 | fclose(fil); |
---|
| 5648 | return NULL; |
---|
| 5649 | } |
---|
[22329] | 5650 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
| 5651 | |
---|
[18190] | 5652 | //printf("T %s\n", zeichen); |
---|
[23984] | 5653 | byte = fgetc(fil); |
---|
[18190] | 5654 | len = byte + 0; |
---|
[23984] | 5655 | byte = fgetc(fil); |
---|
| 5656 | fgets(zeichen, len, fil); |
---|
| 5657 | if(byte != 0x05) |
---|
| 5658 | sprintf(buf,"%c%s\n\n", byte, zeichen); |
---|
[18190] | 5659 | else |
---|
| 5660 | sprintf(buf,"%s\n\n", zeichen); |
---|
| 5661 | |
---|
| 5662 | buf1oldsize = buf1size; |
---|
| 5663 | buf1size += strlen(buf); |
---|
[23984] | 5664 | tmpbuf1 = buf1; buf1 = realloc(buf1, buf1size + 1); |
---|
[18190] | 5665 | if(buf1 == NULL) |
---|
| 5666 | { |
---|
[24350] | 5667 | err("no mem"); |
---|
[18190] | 5668 | free(zeichen); |
---|
| 5669 | free(buf); |
---|
[23984] | 5670 | free(tmpbuf1); |
---|
[18190] | 5671 | fclose(fil); |
---|
| 5672 | return NULL; |
---|
| 5673 | } |
---|
[22329] | 5674 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
[18190] | 5675 | |
---|
| 5676 | } |
---|
[23984] | 5677 | else if(byte == 0x4E) |
---|
| 5678 | { |
---|
| 5679 | fseek(fil, 6, SEEK_CUR); |
---|
| 5680 | byte = fgetc(fil); |
---|
[18190] | 5681 | len = byte; |
---|
[23984] | 5682 | byte = fgetc(fil); |
---|
| 5683 | fgets(zeichen, len, fil); |
---|
| 5684 | if(Beschreibung == 0) |
---|
| 5685 | { |
---|
| 5686 | if(byte != 0x05) |
---|
| 5687 | sprintf(buf, "%c%s", byte, zeichen); |
---|
[18190] | 5688 | else |
---|
[23984] | 5689 | sprintf(buf, "%s", zeichen); |
---|
[18190] | 5690 | Beschreibung = 1; |
---|
| 5691 | } |
---|
[22329] | 5692 | else |
---|
| 5693 | { |
---|
[23984] | 5694 | if(byte != 0x05) |
---|
| 5695 | sprintf(buf, "%c%s", byte, zeichen); |
---|
[18190] | 5696 | else |
---|
[23984] | 5697 | sprintf(buf, "%s", zeichen); |
---|
[18190] | 5698 | } |
---|
| 5699 | |
---|
| 5700 | buf1oldsize = buf1size; |
---|
| 5701 | buf1size += strlen(buf); |
---|
[23984] | 5702 | tmpbuf1 = buf1; buf1 = realloc(buf1, buf1size + 1); |
---|
[18190] | 5703 | if(buf1 == NULL) |
---|
| 5704 | { |
---|
[24350] | 5705 | err("no mem"); |
---|
[18190] | 5706 | free(zeichen); |
---|
| 5707 | free(buf); |
---|
[23984] | 5708 | free(tmpbuf1); |
---|
[18190] | 5709 | fclose(fil); |
---|
| 5710 | return NULL; |
---|
| 5711 | } |
---|
[22329] | 5712 | sprintf(buf1 + buf1oldsize, "%s", buf); |
---|
| 5713 | |
---|
| 5714 | } |
---|
[23984] | 5715 | else |
---|
| 5716 | { |
---|
| 5717 | byte = fgetc(fil); |
---|
[18190] | 5718 | len= byte; |
---|
[23984] | 5719 | fgets(zeichen, len + 1, fil); |
---|
[18190] | 5720 | } |
---|
| 5721 | } |
---|
| 5722 | free(zeichen); |
---|
| 5723 | free(buf); |
---|
| 5724 | fclose(fil); |
---|
| 5725 | return buf1; |
---|
| 5726 | } |
---|
| 5727 | |
---|
| 5728 | char* command(char* input) |
---|
| 5729 | { |
---|
[24407] | 5730 | int maxlen = 0, pos = 0; |
---|
[18190] | 5731 | char* tmpstr = NULL, *fileline = NULL; |
---|
| 5732 | FILE *iopipe = NULL; |
---|
| 5733 | |
---|
| 5734 | if(input == NULL) return NULL; |
---|
| 5735 | |
---|
| 5736 | fileline = malloc(MINMALLOC); |
---|
| 5737 | if(fileline == NULL) |
---|
| 5738 | { |
---|
[24350] | 5739 | err("no mem"); |
---|
[18190] | 5740 | return NULL; |
---|
| 5741 | } |
---|
| 5742 | |
---|
| 5743 | if((iopipe = popen(input, "r")) == NULL) |
---|
| 5744 | { |
---|
| 5745 | free(fileline); |
---|
| 5746 | return NULL; |
---|
| 5747 | } |
---|
| 5748 | |
---|
| 5749 | while(!feof(iopipe)) |
---|
| 5750 | { |
---|
| 5751 | if(fgets(fileline, MINMALLOC, iopipe) != NULL) |
---|
[24407] | 5752 | ostrcatbig(&tmpstr, fileline, &maxlen, &pos); |
---|
[18190] | 5753 | } |
---|
[24407] | 5754 | |
---|
| 5755 | if(pos > 0) |
---|
| 5756 | { |
---|
| 5757 | char* tmp = tmpstr; |
---|
| 5758 | tmpstr = realloc(tmpstr, pos + 1); |
---|
| 5759 | if(tmpstr == NULL) |
---|
| 5760 | tmpstr = tmp; |
---|
| 5761 | } |
---|
[18190] | 5762 | |
---|
| 5763 | free(fileline); |
---|
| 5764 | pclose(iopipe); |
---|
| 5765 | return tmpstr; |
---|
| 5766 | } |
---|
| 5767 | |
---|
| 5768 | char* string_tolower(char *str) |
---|
| 5769 | { |
---|
[22324] | 5770 | char *p1 = str; |
---|
[18190] | 5771 | |
---|
| 5772 | if(str == NULL) return NULL; |
---|
| 5773 | |
---|
[22324] | 5774 | while(*p1 != '\0') |
---|
| 5775 | *p1++ = tolower(*p1); |
---|
| 5776 | |
---|
[18190] | 5777 | return str; |
---|
| 5778 | } |
---|
| 5779 | |
---|
| 5780 | char* string_toupper(char *str) |
---|
| 5781 | { |
---|
[22324] | 5782 | char *p1 = str; |
---|
[18190] | 5783 | |
---|
| 5784 | if(str == NULL) return NULL; |
---|
| 5785 | |
---|
[22324] | 5786 | while(*p1 != '\0') |
---|
| 5787 | *p1++ = toupper(*p1); |
---|
| 5788 | |
---|
| 5789 | return str; |
---|
[18190] | 5790 | } |
---|
| 5791 | |
---|
| 5792 | char* stringreplacecharonce(char *str, char c1, char c2) |
---|
| 5793 | { |
---|
[22322] | 5794 | char *p1 = str; |
---|
[18190] | 5795 | |
---|
| 5796 | if(str == NULL) return NULL; |
---|
| 5797 | |
---|
[22322] | 5798 | while(*p1 != '\0') |
---|
[18190] | 5799 | { |
---|
[22322] | 5800 | if(*p1 == c1) |
---|
[18190] | 5801 | { |
---|
[22322] | 5802 | *p1 = c2; |
---|
| 5803 | break; |
---|
| 5804 | } |
---|
[22324] | 5805 | p1++; |
---|
[18190] | 5806 | } |
---|
| 5807 | |
---|
| 5808 | return str; |
---|
| 5809 | } |
---|
| 5810 | |
---|
| 5811 | char* stringreplacechar(char *str, char c1, char c2) |
---|
| 5812 | { |
---|
[22320] | 5813 | char *p1 = str; |
---|
[18190] | 5814 | |
---|
| 5815 | if(str == NULL) return NULL; |
---|
| 5816 | |
---|
[22320] | 5817 | while(*p1 != '\0') |
---|
| 5818 | { |
---|
| 5819 | if(*p1 == c1) *p1 = c2; |
---|
[22324] | 5820 | p1++; |
---|
[22320] | 5821 | } |
---|
[18190] | 5822 | |
---|
| 5823 | return str; |
---|
| 5824 | } |
---|
| 5825 | |
---|
[22320] | 5826 | |
---|
[18190] | 5827 | char* string_removechar(char *str) |
---|
| 5828 | { |
---|
[22322] | 5829 | char *p1 = str; |
---|
[18190] | 5830 | |
---|
| 5831 | if(str == NULL) return NULL; |
---|
| 5832 | |
---|
[22322] | 5833 | while(*p1 != '\0') |
---|
[18190] | 5834 | { |
---|
[22322] | 5835 | if(*p1 == '.') *p1 = ' '; |
---|
| 5836 | else if(*p1 == '-') *p1 = ' '; |
---|
| 5837 | else if(*p1 == '_') *p1 = ' '; |
---|
| 5838 | else if(*p1 == '/') *p1 = ' '; |
---|
[22324] | 5839 | p1++; |
---|
[18190] | 5840 | } |
---|
[22322] | 5841 | |
---|
[18190] | 5842 | return str; |
---|
| 5843 | } |
---|
| 5844 | |
---|
| 5845 | char* string_withchars2return(char *str) |
---|
| 5846 | { |
---|
[22322] | 5847 | char *p1 = str; |
---|
[18190] | 5848 | |
---|
[22322] | 5849 | if(str == NULL) return NULL; |
---|
| 5850 | |
---|
| 5851 | while(*p1 != '\0') |
---|
[18190] | 5852 | { |
---|
[22322] | 5853 | if(*p1 == ' ') *p1 = '\n'; |
---|
[22324] | 5854 | p1++; |
---|
[18190] | 5855 | } |
---|
| 5856 | |
---|
| 5857 | return str; |
---|
| 5858 | } |
---|
| 5859 | |
---|
| 5860 | char* string_remove_whitechars(char *text) |
---|
| 5861 | { |
---|
| 5862 | char *p1 = text, *p2 = text; |
---|
| 5863 | |
---|
[22324] | 5864 | if(text == NULL) return NULL; |
---|
| 5865 | |
---|
[18190] | 5866 | while(*p1 != '\0') |
---|
| 5867 | { |
---|
| 5868 | if(*p1 == ' ') |
---|
| 5869 | ++p1; |
---|
| 5870 | else |
---|
| 5871 | *p2++ = *p1++; |
---|
| 5872 | } |
---|
| 5873 | *p2 = '\0'; |
---|
| 5874 | |
---|
| 5875 | return text; |
---|
| 5876 | } |
---|
| 5877 | |
---|
| 5878 | char* strstrip(char *text) |
---|
| 5879 | { |
---|
| 5880 | char* tmpstr = text; |
---|
| 5881 | |
---|
| 5882 | if(text == NULL) return NULL; |
---|
| 5883 | int len = strlen(text); |
---|
| 5884 | |
---|
| 5885 | while(isspace(tmpstr[len - 1])) tmpstr[--len] = '\0'; |
---|
| 5886 | while(*tmpstr && isspace(*tmpstr)) ++tmpstr, --len; |
---|
| 5887 | |
---|
[24408] | 5888 | if(text != tmpstr) memmove(text, tmpstr, len + 1); |
---|
[18190] | 5889 | |
---|
| 5890 | return text; |
---|
| 5891 | } |
---|
| 5892 | |
---|
| 5893 | char* string_strip_whitechars(char *text) |
---|
| 5894 | { |
---|
[22323] | 5895 | char *p1 = text, *p2 = text; |
---|
[18190] | 5896 | |
---|
| 5897 | if(text == NULL) |
---|
| 5898 | return NULL; |
---|
| 5899 | |
---|
[22323] | 5900 | while(*p1 != '\0') |
---|
[18190] | 5901 | { |
---|
[22323] | 5902 | if(*p1 == ' ' && *(p1 + 1) == ' ') |
---|
| 5903 | ++p1; |
---|
| 5904 | else |
---|
| 5905 | *p2++ = *p1++; |
---|
[18190] | 5906 | } |
---|
[22323] | 5907 | *p2 = '\0'; |
---|
[18190] | 5908 | |
---|
| 5909 | return text; |
---|
| 5910 | } |
---|
| 5911 | |
---|
| 5912 | char* string_replace_all(char *search, char *replace, char *string, int free1) |
---|
| 5913 | { |
---|
| 5914 | char* tmpstr = NULL; |
---|
[22332] | 5915 | char* searchpos = NULL; |
---|
[18190] | 5916 | |
---|
| 5917 | if(string == NULL || search == NULL) |
---|
| 5918 | { |
---|
| 5919 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 5920 | if(free1 == 1) free(string); |
---|
| 5921 | return tmpstr; |
---|
| 5922 | } |
---|
| 5923 | |
---|
[22332] | 5924 | searchpos = strstr(string, search); |
---|
| 5925 | if(searchpos == NULL) |
---|
[18190] | 5926 | { |
---|
[22332] | 5927 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 5928 | if(free1 == 1) free(string); |
---|
| 5929 | return tmpstr; |
---|
[18190] | 5930 | } |
---|
| 5931 | |
---|
[22332] | 5932 | int count = 0; |
---|
| 5933 | int stringlen = strlen(string); |
---|
| 5934 | int searchlen = strlen(search); |
---|
| 5935 | int replacelen = strlen(replace); |
---|
| 5936 | |
---|
| 5937 | while(searchpos != NULL) |
---|
| 5938 | { |
---|
| 5939 | count++; |
---|
| 5940 | searchpos = strstr(searchpos + searchlen, search); |
---|
| 5941 | } |
---|
| 5942 | |
---|
| 5943 | int len = stringlen - (searchlen * count) + (replacelen * count); |
---|
| 5944 | tmpstr = calloc(1, len + 1); |
---|
| 5945 | if(tmpstr == NULL) |
---|
| 5946 | { |
---|
| 5947 | err("no mem"); |
---|
| 5948 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 5949 | if(free1 == 1) free(string); |
---|
| 5950 | return tmpstr; |
---|
| 5951 | } |
---|
| 5952 | |
---|
| 5953 | len = 0; |
---|
| 5954 | char* str = string; |
---|
| 5955 | char* tmp = tmpstr; |
---|
| 5956 | searchpos = strstr(str, search); |
---|
| 5957 | while(searchpos != NULL) |
---|
| 5958 | { |
---|
| 5959 | len = searchpos - str; |
---|
| 5960 | memcpy(tmp, str, len); |
---|
| 5961 | memcpy(tmp + len, replace, replacelen); |
---|
| 5962 | tmp += len + replacelen; |
---|
| 5963 | str += len + searchlen; |
---|
| 5964 | searchpos = strstr(str, search); |
---|
| 5965 | } |
---|
| 5966 | memcpy(tmp, str, strlen(str)); |
---|
| 5967 | |
---|
[18190] | 5968 | if(free1 == 1) free(string); |
---|
| 5969 | |
---|
| 5970 | return tmpstr; |
---|
| 5971 | } |
---|
| 5972 | |
---|
| 5973 | char* string_replace_remove_last_chars(char *search, char *replace, char *string, int free1) |
---|
| 5974 | { |
---|
| 5975 | char* searchpos = NULL; |
---|
| 5976 | char* tmpstr = NULL; |
---|
| 5977 | |
---|
| 5978 | if(string == NULL || search == NULL) |
---|
| 5979 | { |
---|
| 5980 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 5981 | if(free1 == 1) free(string); |
---|
| 5982 | return tmpstr; |
---|
| 5983 | } |
---|
| 5984 | |
---|
| 5985 | searchpos = ostrstr(string, search); |
---|
| 5986 | |
---|
| 5987 | if(searchpos == NULL) |
---|
| 5988 | { |
---|
| 5989 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 5990 | if(free1 == 1) free(string); |
---|
| 5991 | return tmpstr; |
---|
| 5992 | } |
---|
| 5993 | |
---|
| 5994 | tmpstr = strndup(string, searchpos - string); |
---|
| 5995 | if(replace != NULL) |
---|
| 5996 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
| 5997 | |
---|
| 5998 | if(free1 == 1) free(string); |
---|
| 5999 | |
---|
| 6000 | return tmpstr; |
---|
| 6001 | } |
---|
| 6002 | |
---|
| 6003 | char* string_replace(char *search, char *replace, char *string, int free1) |
---|
| 6004 | { |
---|
| 6005 | char* searchpos = NULL; |
---|
| 6006 | char* tmpstr = NULL; |
---|
| 6007 | |
---|
| 6008 | if(string == NULL || search == NULL) |
---|
| 6009 | { |
---|
| 6010 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 6011 | if(free1 == 1) free(string); |
---|
| 6012 | return tmpstr; |
---|
| 6013 | } |
---|
| 6014 | |
---|
| 6015 | searchpos = ostrstr(string, search); |
---|
| 6016 | |
---|
| 6017 | if(searchpos == NULL) |
---|
| 6018 | { |
---|
| 6019 | tmpstr = ostrcat(tmpstr, string, 1, 0); |
---|
| 6020 | if(free1 == 1) free(string); |
---|
| 6021 | return tmpstr; |
---|
| 6022 | } |
---|
| 6023 | |
---|
| 6024 | tmpstr = strndup(string, searchpos - string); |
---|
[22330] | 6025 | if(replace != NULL) |
---|
[18190] | 6026 | tmpstr = ostrcat(tmpstr, replace, 1, 0); |
---|
| 6027 | tmpstr = ostrcat(tmpstr, string + (searchpos - string) + strlen(search), 1, 0); |
---|
| 6028 | |
---|
| 6029 | if(free1 == 1) free(string); |
---|
| 6030 | |
---|
| 6031 | return tmpstr; |
---|
| 6032 | } |
---|
| 6033 | |
---|
| 6034 | //flag 0: search full str |
---|
| 6035 | //flag 1: search only end of string |
---|
| 6036 | char* ostrrstrcase(char* str, char* search, int len, int flag) |
---|
| 6037 | { |
---|
| 6038 | int slen = 0; |
---|
| 6039 | char* tmpstr = NULL; |
---|
| 6040 | |
---|
| 6041 | if(str == NULL || search == NULL) return NULL; |
---|
| 6042 | |
---|
| 6043 | if(len == -1) len = strlen(str); |
---|
| 6044 | slen = strlen(search); |
---|
| 6045 | if(slen > len) return NULL; |
---|
| 6046 | |
---|
| 6047 | for(tmpstr = str + len - slen; tmpstr >= str; tmpstr--) |
---|
| 6048 | { |
---|
| 6049 | if(strncasecmp(tmpstr, search, slen) == 0) |
---|
| 6050 | return tmpstr; |
---|
| 6051 | if(flag == 1) return NULL; |
---|
| 6052 | } |
---|
| 6053 | |
---|
| 6054 | return NULL; |
---|
| 6055 | } |
---|
| 6056 | |
---|
| 6057 | //flag 0: search full str |
---|
| 6058 | //flag 1: search only end of string |
---|
| 6059 | char* ostrrstr(char* str, char* search, int len, int flag) |
---|
| 6060 | { |
---|
| 6061 | int slen = 0; |
---|
| 6062 | char* tmpstr = NULL; |
---|
| 6063 | |
---|
| 6064 | if(str == NULL || search == NULL) return NULL; |
---|
| 6065 | |
---|
| 6066 | if(len == -1) len = strlen(str); |
---|
| 6067 | slen = strlen(search); |
---|
| 6068 | if(slen > len) return NULL; |
---|
| 6069 | |
---|
| 6070 | for(tmpstr = str + len - slen; tmpstr >= str; tmpstr--) |
---|
| 6071 | { |
---|
| 6072 | if(strncmp(tmpstr, search, slen) == 0) |
---|
| 6073 | return tmpstr; |
---|
| 6074 | if(flag == 1) return NULL; |
---|
| 6075 | } |
---|
| 6076 | |
---|
| 6077 | return NULL; |
---|
| 6078 | } |
---|
| 6079 | |
---|
| 6080 | char* ostrstr(char* str, char* search) |
---|
| 6081 | { |
---|
| 6082 | char* ret = NULL; |
---|
| 6083 | |
---|
| 6084 | if(str == NULL || search == NULL) return NULL; |
---|
| 6085 | ret = strstr(str, search); |
---|
| 6086 | |
---|
| 6087 | return ret; |
---|
| 6088 | } |
---|
| 6089 | |
---|
| 6090 | int file_exist(char* filename) |
---|
| 6091 | { |
---|
[19609] | 6092 | if(access(filename, F_OK) == 0) |
---|
[18190] | 6093 | return 1; |
---|
| 6094 | else |
---|
| 6095 | return 0; |
---|
| 6096 | } |
---|
| 6097 | |
---|
| 6098 | char* string_newline(char* str) |
---|
| 6099 | { |
---|
| 6100 | if(str == NULL) return NULL; |
---|
| 6101 | |
---|
| 6102 | int size = strlen(str); |
---|
| 6103 | |
---|
| 6104 | if(str[size - 1] == '\n') |
---|
| 6105 | str[size - 1] = '\0'; |
---|
[23286] | 6106 | |
---|
[18190] | 6107 | return str; |
---|
| 6108 | } |
---|
| 6109 | |
---|
| 6110 | char* string_quote(char* str) |
---|
| 6111 | { |
---|
| 6112 | char* tmpstr = NULL; |
---|
| 6113 | |
---|
| 6114 | tmpstr = ostrcat("\"", str, 0, 0); |
---|
| 6115 | tmpstr = ostrcat(tmpstr, "\"", 1, 0); |
---|
[23286] | 6116 | |
---|
[18190] | 6117 | return tmpstr; |
---|
| 6118 | } |
---|
| 6119 | |
---|
| 6120 | struct splitstr* strsplit(char *str, char *tok, int* count) |
---|
| 6121 | { |
---|
| 6122 | char *tmpstr = NULL; |
---|
[23984] | 6123 | struct splitstr *array = NULL, *tmparray = NULL; |
---|
[18190] | 6124 | *count = 0; |
---|
| 6125 | |
---|
| 6126 | if(str == NULL || tok == NULL) |
---|
| 6127 | return NULL; |
---|
| 6128 | |
---|
| 6129 | tmpstr = strtok(str, tok); |
---|
| 6130 | while(tmpstr != NULL) |
---|
| 6131 | { |
---|
| 6132 | *count = *count + 1; |
---|
[23984] | 6133 | tmparray = array; array = (struct splitstr*)realloc(array, sizeof(struct splitstr*) * (*count)); |
---|
| 6134 | if(array == NULL) |
---|
| 6135 | { |
---|
[24350] | 6136 | err("no mem"); |
---|
[23984] | 6137 | free(tmparray); |
---|
[18190] | 6138 | return NULL; |
---|
[23984] | 6139 | } |
---|
| 6140 | |
---|
| 6141 | (&array[(*count) - 1])->part = tmpstr; |
---|
[18190] | 6142 | tmpstr = strtok(NULL, tok); |
---|
| 6143 | } |
---|
| 6144 | |
---|
[23984] | 6145 | return array; |
---|
[18190] | 6146 | } |
---|
| 6147 | |
---|
| 6148 | char* string_shortname(char *tmpfilename, int mode) |
---|
| 6149 | { |
---|
[23984] | 6150 | debug(50, "in %s", tmpfilename); |
---|
[18190] | 6151 | |
---|
| 6152 | // 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"; |
---|
| 6153 | char* str = NULL; |
---|
| 6154 | |
---|
[23984] | 6155 | if(mode==1) |
---|
[18190] | 6156 | { |
---|
[18864] | 6157 | char* replacelist = "avi mkv x264 xvid se uncut ac3d ac3hd ac3 bdrip bluray cam camrip complete custom cut dc directors dl doku dts dvdr dvdrip dvdscr dvdscreener ecc extended french finnish german hd hddvd hddvdrip hdtv int internal int ld limited multi multisubs nordic ntsc pal pl r1 r5 recut remastered repack rip screener se see sse stv subbed swedish staffel tc telecine telesync ts unrated ws xxx italian"; |
---|
[18190] | 6158 | str = ostrcat(str, replacelist, 1, 0); |
---|
| 6159 | } |
---|
[23984] | 6160 | else if(mode==2) |
---|
[18190] | 6161 | { |
---|
[18864] | 6162 | char* replacelist = "1080i 1080p 720p ac3 ac3d ac3hd avi bdrip bluray cam camrip complete custom cut dat dc directors divx dl doku dts dvdr dvdrip dvdscr dvdscreener ecc ed extended finnish flv french german hd hddvd hddvdrip hdtv int internal ld limited linedubbed m2ts m4v md mkv mov mp4 mpeg mpg mts multi multisubs nordic ntsc pal pl proper r1 r3 r5 recut remastered repack rip rm screener se sse staffel stv subbed svcd swedish tc telecine telesync trp ts uc uncut unrated ur vcd vdr vob wmv ws x264 xvid xxx"; |
---|
[18190] | 6163 | str = ostrcat(str, replacelist, 1, 0); |
---|
| 6164 | } |
---|
| 6165 | else |
---|
| 6166 | { |
---|
| 6167 | 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"; |
---|
| 6168 | str = ostrcat(str, replacelist, 1, 0); |
---|
| 6169 | } |
---|
| 6170 | |
---|
| 6171 | char* replace = NULL; |
---|
| 6172 | struct splitstr* ret1 = NULL; |
---|
| 6173 | int count = 0; |
---|
| 6174 | int i = 0; |
---|
| 6175 | ret1 = strsplit(str, " ", &count); |
---|
| 6176 | int max = count - 1; |
---|
| 6177 | int first = 1; |
---|
| 6178 | |
---|
| 6179 | for(i = 0; i < max; i++) |
---|
| 6180 | { |
---|
| 6181 | struct splitstr* ret2 = NULL; |
---|
| 6182 | int count2 = 0; |
---|
| 6183 | int j = 0; |
---|
| 6184 | char *tmpstr = NULL; |
---|
| 6185 | tmpstr = ostrcat(tmpstr, tmpfilename, 1, 0); |
---|
| 6186 | ret2 = strsplit(tmpstr, " ,.-_", &count2); |
---|
| 6187 | |
---|
| 6188 | for(j = 0; j < count2; j++) |
---|
| 6189 | { |
---|
| 6190 | if(j > 0) |
---|
| 6191 | { |
---|
| 6192 | if(ostrcmp((&ret1[i])->part, (&ret2[j])->part) == 0) |
---|
| 6193 | { |
---|
[23984] | 6194 | if(mode==1) |
---|
[18190] | 6195 | { |
---|
| 6196 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
| 6197 | continue; |
---|
| 6198 | } |
---|
[23984] | 6199 | else if(mode==2) |
---|
[18190] | 6200 | { |
---|
| 6201 | tmpfilename = string_replace_remove_last_chars((&ret2[j])->part, replace, tmpfilename, 1); |
---|
[18845] | 6202 | //break; |
---|
| 6203 | continue; |
---|
[18190] | 6204 | } |
---|
| 6205 | else |
---|
| 6206 | { |
---|
| 6207 | tmpfilename = string_replace((&ret2[j])->part, replace, tmpfilename, 1); |
---|
| 6208 | continue; |
---|
| 6209 | } |
---|
| 6210 | } |
---|
[23984] | 6211 | else if(first == 1 && mode == 2) |
---|
[18190] | 6212 | { |
---|
| 6213 | // printf("zahl: %s\n", (&ret2[j])->part); |
---|
| 6214 | int theCharacter = atoi((&ret2[j])->part); |
---|
| 6215 | if(theCharacter != 0) |
---|
| 6216 | { |
---|
| 6217 | // printf("found zahl: %s\n", (&ret2[j])->part); |
---|
| 6218 | if(theCharacter > 1800 && theCharacter < 2100) |
---|
| 6219 | { |
---|
| 6220 | // printf("found year: %s\n", (&ret2[j])->part); |
---|
| 6221 | tmpfilename = string_replace_remove_last_chars((&ret2[j])->part, "", tmpfilename, 1); |
---|
| 6222 | break; |
---|
| 6223 | } |
---|
| 6224 | } |
---|
| 6225 | } |
---|
| 6226 | } |
---|
| 6227 | } |
---|
| 6228 | free(ret2); ret2 = NULL; |
---|
| 6229 | first = 0; |
---|
| 6230 | free(tmpstr), tmpstr = NULL; |
---|
| 6231 | } |
---|
| 6232 | |
---|
| 6233 | free(ret1); ret1 = NULL; |
---|
| 6234 | free(replace); replace = NULL; |
---|
| 6235 | free(str); str = NULL; |
---|
| 6236 | |
---|
| 6237 | debug(50, "out %s", tmpfilename); |
---|
| 6238 | return tmpfilename; |
---|
| 6239 | } |
---|
| 6240 | |
---|
| 6241 | char* get_uuid(char* device) |
---|
| 6242 | { |
---|
| 6243 | debug(60, "in %s", device); |
---|
| 6244 | char* cmd = NULL, *tmpstr = NULL; |
---|
| 6245 | |
---|
| 6246 | if(device == NULL) return NULL; |
---|
| 6247 | |
---|
| 6248 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s UUID /dev/", 1, 0); |
---|
| 6249 | cmd = ostrcat(cmd, device, 1, 0); |
---|
| 6250 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
| 6251 | |
---|
| 6252 | tmpstr = string_newline(command(cmd)); |
---|
| 6253 | |
---|
| 6254 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
| 6255 | { |
---|
| 6256 | free(tmpstr); tmpstr = NULL; |
---|
| 6257 | } |
---|
| 6258 | |
---|
| 6259 | debug(60, "out %s", cmd); |
---|
| 6260 | free(cmd); cmd = NULL; |
---|
| 6261 | return tmpstr; |
---|
| 6262 | } |
---|
| 6263 | |
---|
| 6264 | char* get_label(char* device) |
---|
| 6265 | { |
---|
| 6266 | debug(60, "in %s", device); |
---|
| 6267 | char* cmd = NULL, *tmpstr = NULL; |
---|
| 6268 | |
---|
| 6269 | if(device == NULL) return NULL; |
---|
| 6270 | |
---|
| 6271 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s LABEL /dev/", 1, 0); |
---|
| 6272 | cmd = ostrcat(cmd, device, 1, 0); |
---|
| 6273 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
| 6274 | |
---|
| 6275 | tmpstr = string_newline(command(cmd)); |
---|
| 6276 | |
---|
| 6277 | if(tmpstr == NULL) |
---|
| 6278 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
| 6279 | |
---|
| 6280 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
| 6281 | tmpstr = ostrcat(tmpstr, "NONLABEL", 1, 0); |
---|
| 6282 | |
---|
| 6283 | debug(60, "out %s", cmd); |
---|
| 6284 | free(cmd); cmd = NULL; |
---|
| 6285 | return tmpstr; |
---|
| 6286 | } |
---|
| 6287 | |
---|
| 6288 | char* get_filesystem(char* device) |
---|
| 6289 | { |
---|
| 6290 | debug(60, "in %s", device); |
---|
| 6291 | char* cmd = NULL, *tmpstr = NULL; |
---|
| 6292 | |
---|
| 6293 | if(device == NULL) return NULL; |
---|
| 6294 | |
---|
| 6295 | cmd = ostrcat(cmd, "/bin/blkid -w /dev/null -c /dev/null -s TYPE /dev/", 1, 0); |
---|
| 6296 | cmd = ostrcat(cmd, device, 1, 0); |
---|
| 6297 | cmd = ostrcat(cmd, " | cut -d'\"' -f2", 1, 0); |
---|
| 6298 | |
---|
| 6299 | tmpstr = string_newline(command(cmd)); |
---|
| 6300 | |
---|
| 6301 | if(tmpstr == NULL) |
---|
| 6302 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
| 6303 | |
---|
| 6304 | if(ostrcmp(string_newline(tmpstr), "") == 0) |
---|
| 6305 | tmpstr = ostrcat(tmpstr, "NONTYPE", 1, 0); |
---|
| 6306 | |
---|
| 6307 | debug(60, "out %s", cmd); |
---|
| 6308 | free(cmd); cmd = NULL; |
---|
| 6309 | return tmpstr; |
---|
| 6310 | } |
---|
| 6311 | |
---|
| 6312 | //flag 0: convert ip to 000.000.000.000 |
---|
| 6313 | //flag 1: convert ip to 0.0.0.0 |
---|
| 6314 | char* fixip(char* ipinput, int flag) |
---|
| 6315 | { |
---|
| 6316 | debug(60, "in %s", ipinput); |
---|
| 6317 | int ret = 0; |
---|
| 6318 | char* ipout = NULL; |
---|
| 6319 | unsigned char ip[4]; |
---|
| 6320 | |
---|
| 6321 | ip[0] = 0; |
---|
| 6322 | ip[1] = 0; |
---|
| 6323 | ip[2] = 0; |
---|
| 6324 | ip[3] = 0; |
---|
| 6325 | |
---|
| 6326 | if(ipinput == NULL) return NULL; |
---|
| 6327 | ret = sscanf(ipinput, "%hhu.%hhu.%hhu.%hhu", &ip[0], &ip[1], &ip[2], &ip[3]); |
---|
| 6328 | if(ret != 4) return NULL; |
---|
| 6329 | |
---|
| 6330 | ipout = malloc(16); |
---|
| 6331 | if(ipout == NULL) |
---|
| 6332 | { |
---|
| 6333 | err("no mem"); |
---|
| 6334 | return NULL; |
---|
| 6335 | } |
---|
| 6336 | |
---|
| 6337 | if(flag == 1) |
---|
| 6338 | snprintf(ipout, 16, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); |
---|
| 6339 | else |
---|
| 6340 | snprintf(ipout, 16, "%03d.%03d.%03d.%03d", ip[0], ip[1], ip[2], ip[3]); |
---|
| 6341 | |
---|
| 6342 | return ipout; |
---|
| 6343 | } |
---|
| 6344 | |
---|
| 6345 | void setfanspeed(int speed, int aktion) |
---|
| 6346 | { |
---|
| 6347 | char* speedWert = NULL; |
---|
| 6348 | char* speedSet = NULL; |
---|
| 6349 | |
---|
| 6350 | if(speed < 0) |
---|
| 6351 | { |
---|
[25515] | 6352 | if(speed == -1) |
---|
| 6353 | speedWert = getconfig("fanspeed", NULL); |
---|
| 6354 | else |
---|
| 6355 | speedWert = getconfig("fanspeedstandby", NULL); |
---|
[18190] | 6356 | if(speedWert == NULL) |
---|
| 6357 | speedSet = ostrcat(speedSet, "170", 1, 0); |
---|
| 6358 | else |
---|
| 6359 | speedSet = ostrcat(speedSet, speedWert, 1, 0); |
---|
| 6360 | } |
---|
| 6361 | else |
---|
| 6362 | { |
---|
| 6363 | if(speed == 0) |
---|
| 6364 | speedSet = ostrcat(speedSet, "115", 1, 0); |
---|
| 6365 | else if(speed == 25) |
---|
| 6366 | speedSet = ostrcat(speedSet, "130", 1, 0); |
---|
| 6367 | else if(speed == 50) |
---|
| 6368 | speedSet = ostrcat(speedSet, "145", 1, 0); |
---|
| 6369 | else if(speed == 75) |
---|
| 6370 | speedSet = ostrcat(speedSet, "155", 1, 0); |
---|
| 6371 | else |
---|
| 6372 | speedSet = ostrcat(speedSet, "170", 1, 0); |
---|
| 6373 | } |
---|
| 6374 | |
---|
| 6375 | writesys("/proc/stb/fan/fan_ctrl", speedSet, 1); |
---|
| 6376 | |
---|
| 6377 | if(aktion == 1) |
---|
| 6378 | addconfig("fanspeed", speedSet); |
---|
[25533] | 6379 | else if(aktion == 2) |
---|
[25515] | 6380 | addconfig("fanspeedstandby", speedSet); |
---|
[18190] | 6381 | |
---|
| 6382 | free(speedSet); speedSet=NULL; |
---|
| 6383 | } |
---|
| 6384 | |
---|
| 6385 | void setaktres() |
---|
| 6386 | { |
---|
[20708] | 6387 | int m_width = 0; |
---|
[18190] | 6388 | char* res = NULL; |
---|
| 6389 | char* res_akt = NULL; |
---|
| 6390 | char* res_sd = NULL; |
---|
[20708] | 6391 | int count = 1; |
---|
[18190] | 6392 | int sec = 0; |
---|
| 6393 | |
---|
[20708] | 6394 | m_lock(&status.setaktresmutex, 23); |
---|
| 6395 | |
---|
| 6396 | if(status.restimer == NULL) |
---|
| 6397 | goto end; |
---|
| 6398 | |
---|
[18190] | 6399 | sec = (int)status.restimer->param1; |
---|
| 6400 | |
---|
| 6401 | if(sec > 0) |
---|
| 6402 | { |
---|
[20708] | 6403 | while(status.restimer->aktion == START && count <= (sec * 10)) |
---|
[18190] | 6404 | { |
---|
[20708] | 6405 | usleep(100000); |
---|
[18190] | 6406 | if(status.restimer->aktion != START) |
---|
[20708] | 6407 | goto end; |
---|
[18190] | 6408 | count++; |
---|
| 6409 | } |
---|
| 6410 | } |
---|
[20708] | 6411 | if(status.restimer->aktion != START) goto end; |
---|
[18190] | 6412 | |
---|
| 6413 | if(videoreadqwidth(status.aktservice->videodev) == 0) |
---|
| 6414 | { |
---|
[20708] | 6415 | if(status.restimer->aktion != START) goto end; |
---|
[18190] | 6416 | m_width = status.videosize.w; |
---|
| 6417 | if(m_width == 720) |
---|
| 6418 | { |
---|
| 6419 | res_sd = getconfig("av_videomode_autores_sd", NULL); |
---|
| 6420 | if(res_sd == NULL) |
---|
| 6421 | res = ostrcat(res, "576i50", 1, 0); |
---|
| 6422 | else |
---|
| 6423 | res = ostrcat(res, res_sd, 1, 0); |
---|
| 6424 | } |
---|
| 6425 | else if (m_width == 1280) |
---|
| 6426 | res = ostrcat(res, "720p50", 1, 0); |
---|
| 6427 | else if (m_width == 1920) |
---|
| 6428 | res = ostrcat(res, "1080i50", 1, 0); |
---|
| 6429 | else |
---|
| 6430 | m_width = 0; |
---|
[18927] | 6431 | |
---|
[18190] | 6432 | if(m_width > 0) |
---|
| 6433 | { |
---|
[20708] | 6434 | if(status.restimer->aktion != START) goto end; |
---|
[18190] | 6435 | res_akt = getvideomode(); |
---|
[20708] | 6436 | if(status.restimer->aktion != START) goto end; |
---|
| 6437 | if(ostrcmp(res_akt, res) != 0) |
---|
[18190] | 6438 | { |
---|
[20708] | 6439 | if(status.restimer->aktion != START) goto end; |
---|
[18190] | 6440 | setvideomode(res, 1); |
---|
[20751] | 6441 | changefbresolution(res, 1); |
---|
| 6442 | /* |
---|
[20708] | 6443 | if(status.restimer->aktion != START) goto end; |
---|
| 6444 | |
---|
| 6445 | count = 0; |
---|
| 6446 | while(status.restimer->aktion == START && count < 10) |
---|
| 6447 | { |
---|
| 6448 | usleep(100000); |
---|
| 6449 | if(status.restimer->aktion != START) |
---|
| 6450 | goto end; |
---|
| 6451 | count++; |
---|
| 6452 | } |
---|
| 6453 | |
---|
| 6454 | if(status.restimer->aktion != START) goto end; |
---|
[20751] | 6455 | */ |
---|
[18190] | 6456 | screenautores(res, 5, 0); |
---|
| 6457 | } |
---|
| 6458 | } |
---|
| 6459 | } |
---|
| 6460 | else |
---|
[20708] | 6461 | { |
---|
| 6462 | if(status.restimer->aktion != START) goto end; |
---|
[18190] | 6463 | textbox(_("Message"), _("ERROR cant read res"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
[20708] | 6464 | } |
---|
[18190] | 6465 | |
---|
[20708] | 6466 | end: |
---|
| 6467 | free(res); res = NULL; |
---|
[18190] | 6468 | status.restimer = NULL; |
---|
[20708] | 6469 | m_unlock(&status.setaktresmutex, 23); |
---|
[18190] | 6470 | return; |
---|
| 6471 | } |
---|
| 6472 | |
---|
| 6473 | char* gettimestamp() |
---|
| 6474 | { |
---|
| 6475 | char* timestamp = NULL; |
---|
| 6476 | struct timeval numtime; |
---|
| 6477 | |
---|
| 6478 | gettimeofday(&numtime, 0); |
---|
| 6479 | timestamp = ostrcat(timestamp, olutoa(numtime.tv_sec), 1, 1); |
---|
| 6480 | timestamp = ostrcat(timestamp, olutoa(numtime.tv_usec), 1, 1); |
---|
| 6481 | |
---|
| 6482 | return timestamp; |
---|
| 6483 | } |
---|
| 6484 | |
---|
| 6485 | char* string_decode(char* input, int flag) |
---|
| 6486 | { |
---|
| 6487 | if(input == NULL) return input; |
---|
| 6488 | |
---|
| 6489 | while(ostrstr(input, "\\u00") != NULL) |
---|
| 6490 | { |
---|
| 6491 | debug(210, "input: %s", input); |
---|
| 6492 | input = string_replace("\\u00", "%", input, 1); |
---|
| 6493 | debug(210, "input: %s", input); |
---|
| 6494 | } |
---|
| 6495 | |
---|
| 6496 | while(ostrstr(input, "&") != NULL) |
---|
| 6497 | { |
---|
| 6498 | debug(210, "input: %s", input); |
---|
| 6499 | input = string_replace("&", "und", input, 1); |
---|
| 6500 | debug(210, "input: %s", input); |
---|
| 6501 | } |
---|
| 6502 | |
---|
| 6503 | while(ostrstr(input, ">") != NULL) |
---|
| 6504 | { |
---|
| 6505 | debug(210, "input: %s", input); |
---|
| 6506 | input = string_replace(">", ">", input, 1); |
---|
| 6507 | debug(210, "input: %s", input); |
---|
| 6508 | } |
---|
| 6509 | |
---|
| 6510 | while(ostrstr(input, "<") != NULL) |
---|
| 6511 | { |
---|
| 6512 | debug(210, "input: %s", input); |
---|
| 6513 | input = string_replace("<", "<", input, 1); |
---|
| 6514 | debug(210, "input: %s", input); |
---|
| 6515 | } |
---|
| 6516 | |
---|
| 6517 | while(ostrstr(input, """) != NULL) |
---|
| 6518 | { |
---|
| 6519 | debug(210, "input: %s", input); |
---|
| 6520 | input = string_replace(""", "\"", input, 1); |
---|
| 6521 | debug(210, "input: %s", input); |
---|
| 6522 | } |
---|
| 6523 | |
---|
| 6524 | while(ostrstr(input, "&#x") != NULL) |
---|
| 6525 | { |
---|
| 6526 | debug(210, "out %s", input); |
---|
| 6527 | input = string_replace("&#x", "%", input, 1); |
---|
| 6528 | debug(210, "input: %s", input); |
---|
| 6529 | } |
---|
[22375] | 6530 | |
---|
[18190] | 6531 | while(ostrstr(input, "&#") != NULL) |
---|
| 6532 | { |
---|
| 6533 | debug(210, "input: %s", input); |
---|
| 6534 | input = string_replace("&#", "%", input, 1); |
---|
| 6535 | debug(210, "input: %s", input); |
---|
| 6536 | } |
---|
| 6537 | |
---|
| 6538 | if(flag == 1) |
---|
| 6539 | htmldecode2(input, input); |
---|
| 6540 | else |
---|
| 6541 | htmldecode(input, input); |
---|
| 6542 | |
---|
| 6543 | while(ostrstr(input, ";") != NULL) |
---|
| 6544 | { |
---|
| 6545 | debug(210, "input: %s", input); |
---|
[22859] | 6546 | input = string_replace(";", NULL, input, 1); |
---|
[18190] | 6547 | debug(210, "input: %s", input); |
---|
| 6548 | } |
---|
| 6549 | |
---|
| 6550 | return input; |
---|
| 6551 | } |
---|
| 6552 | |
---|
| 6553 | char* string_deltags(char* str) |
---|
| 6554 | { |
---|
| 6555 | int i = 0, y = 0, len = 0; |
---|
| 6556 | |
---|
| 6557 | if(str == NULL) return 0; |
---|
| 6558 | |
---|
| 6559 | len = strlen(str); |
---|
| 6560 | |
---|
| 6561 | int skip = 0; |
---|
| 6562 | for(i = 0; i < len; i++) |
---|
| 6563 | { |
---|
| 6564 | if(str[i] == '<') |
---|
| 6565 | skip = 1; |
---|
| 6566 | else if(str[i] == '>') |
---|
| 6567 | skip = 0; |
---|
| 6568 | |
---|
| 6569 | if(skip == 0 && str[i] != '>') |
---|
| 6570 | { |
---|
| 6571 | str[y] = str[i]; |
---|
| 6572 | y++; |
---|
| 6573 | } |
---|
| 6574 | } |
---|
| 6575 | str[y] = '\0'; |
---|
| 6576 | |
---|
| 6577 | return str; |
---|
| 6578 | } |
---|
| 6579 | |
---|
| 6580 | char* string_striptags(char* str) |
---|
| 6581 | { |
---|
| 6582 | int i = 0, len = 0; |
---|
| 6583 | |
---|
| 6584 | if(str == NULL) return 0; |
---|
| 6585 | |
---|
| 6586 | len = strlen(str); |
---|
| 6587 | |
---|
[22375] | 6588 | int skip = 0; |
---|
[18190] | 6589 | for(i = 0; i < len; i++) |
---|
| 6590 | { |
---|
| 6591 | if(str[i] == '<') |
---|
| 6592 | skip = 1; |
---|
| 6593 | else if(str[i] == '>') |
---|
| 6594 | { |
---|
| 6595 | skip = 0; |
---|
| 6596 | str[i] = ' '; |
---|
| 6597 | } |
---|
| 6598 | if(skip == 1) |
---|
| 6599 | str[i] = ' '; |
---|
| 6600 | } |
---|
| 6601 | |
---|
| 6602 | return strstrip(str); |
---|
| 6603 | } |
---|
| 6604 | |
---|
| 6605 | char* string_resub(char* str, char* str2, char* input, int dir) |
---|
| 6606 | { |
---|
| 6607 | char* tmpstr = NULL, *pos = NULL, *pos2 = NULL; |
---|
| 6608 | |
---|
| 6609 | if(str == NULL || str2 == NULL || input == NULL) return NULL; |
---|
| 6610 | |
---|
| 6611 | if(dir == 0) |
---|
| 6612 | { |
---|
| 6613 | pos = ostrstr(input, str); |
---|
| 6614 | if(pos == NULL) return NULL; |
---|
[24405] | 6615 | pos += strlen(str); |
---|
[18190] | 6616 | |
---|
| 6617 | pos2 = ostrstr(pos, str2); |
---|
| 6618 | if(pos2 == NULL) return NULL; |
---|
| 6619 | } |
---|
| 6620 | else |
---|
| 6621 | { |
---|
| 6622 | pos2 = ostrstr(input, str2); |
---|
| 6623 | if(pos2 == NULL) return NULL; |
---|
| 6624 | |
---|
| 6625 | pos = ostrrstr(input, str, pos2 - input, 0); |
---|
| 6626 | if(pos == NULL) return NULL; |
---|
[24405] | 6627 | pos += strlen(str); |
---|
[18190] | 6628 | } |
---|
| 6629 | |
---|
| 6630 | tmpstr = strndup(pos, pos2 - pos); |
---|
| 6631 | |
---|
| 6632 | return strstrip(tmpstr); |
---|
| 6633 | } |
---|
| 6634 | |
---|
| 6635 | char* ostrstrcase(char* str, char* sub) |
---|
| 6636 | { |
---|
| 6637 | size_t len = 0; |
---|
| 6638 | |
---|
| 6639 | if(str == NULL || sub == NULL) return NULL; |
---|
| 6640 | |
---|
| 6641 | len = strlen(sub); |
---|
| 6642 | while(*str) |
---|
| 6643 | { |
---|
| 6644 | if(toupper(*str) == toupper(*sub) && strncasecmp(str, sub, len) == 0) |
---|
| 6645 | return str; |
---|
| 6646 | ++str; |
---|
| 6647 | } |
---|
| 6648 | return NULL; |
---|
| 6649 | } |
---|
| 6650 | |
---|
[19934] | 6651 | //flag 0: convert port to 00021 |
---|
| 6652 | //flag 1: convert port to 21 |
---|
| 6653 | char* fixport(char* input, int flag) |
---|
| 6654 | { |
---|
| 6655 | char* tmpstr = NULL; |
---|
| 6656 | |
---|
| 6657 | if(flag == 0) |
---|
| 6658 | { |
---|
| 6659 | int plen = strlen(input); |
---|
| 6660 | if(plen < 5) |
---|
| 6661 | { |
---|
| 6662 | int i; |
---|
| 6663 | for(i = 0; i < 5 - plen; i++) |
---|
| 6664 | tmpstr = ostrcat(tmpstr, "0", 1, 0); |
---|
| 6665 | } |
---|
| 6666 | tmpstr = ostrcat(tmpstr, input, 1, 0); |
---|
| 6667 | } |
---|
| 6668 | else |
---|
| 6669 | { |
---|
[22375] | 6670 | while (*input && *input == '0') |
---|
| 6671 | input++; |
---|
[19934] | 6672 | |
---|
| 6673 | tmpstr = ostrcat(tmpstr, input, 1, 0); |
---|
[22375] | 6674 | } |
---|
[19934] | 6675 | return tmpstr; |
---|
| 6676 | } |
---|
| 6677 | |
---|
[27944] | 6678 | //flag 0: Mon > Montag |
---|
| 6679 | //flag 1: Mon > Mon |
---|
| 6680 | char* translate_time(char* input, int flag) |
---|
| 6681 | { |
---|
| 6682 | char* tmpstr = NULL; |
---|
| 6683 | if(input == NULL) return tmpstr; |
---|
| 6684 | tmpstr = ostrcat(tmpstr, input, 1, 1); |
---|
| 6685 | |
---|
| 6686 | if(flag == 0) |
---|
| 6687 | { |
---|
| 6688 | tmpstr = string_replace_all("Mon", _("Monday"), tmpstr, 1); |
---|
| 6689 | tmpstr = string_replace_all("Tue", _("Tuesday"), tmpstr, 1); |
---|
[27952] | 6690 | tmpstr = string_replace_all("Wed", _("Wednesday"), tmpstr, 1); |
---|
[27944] | 6691 | tmpstr = string_replace_all("Thu", _("Thursday"), tmpstr, 1); |
---|
| 6692 | tmpstr = string_replace_all("Fri", _("Friday"), tmpstr, 1); |
---|
| 6693 | tmpstr = string_replace_all("Sat", _("Saturday"), tmpstr, 1); |
---|
| 6694 | tmpstr = string_replace_all("Sun", _("Sunday"), tmpstr, 1); |
---|
| 6695 | } |
---|
| 6696 | else |
---|
| 6697 | { |
---|
| 6698 | tmpstr = string_replace("Mon", _("Mon"), tmpstr, 1); |
---|
| 6699 | tmpstr = string_replace("Tue", _("Tue"), tmpstr, 1); |
---|
| 6700 | tmpstr = string_replace("Wed", _("Wed"), tmpstr, 1); |
---|
| 6701 | tmpstr = string_replace("Thu", _("Thu"), tmpstr, 1); |
---|
| 6702 | tmpstr = string_replace("Fri", _("Fri"), tmpstr, 1); |
---|
| 6703 | tmpstr = string_replace("Sat", _("Sat"), tmpstr, 1); |
---|
| 6704 | tmpstr = string_replace("Sun", _("Sun"), tmpstr, 1); |
---|
| 6705 | } |
---|
| 6706 | |
---|
| 6707 | return tmpstr; |
---|
| 6708 | } |
---|
| 6709 | |
---|
[18190] | 6710 | #endif |
---|