source: titan/titan/titan.c @ 23913

Last change on this file since 23913 was 23913, checked in by obi, 11 years ago

fix sec

File size: 27.6 KB
Line 
1#include "struct.h"
2#include "header.h"
3#include "debug.h"
4#include "crc32.h"
5#include "sock.h"
6
7#define SYSCODE 0UL
8#define HTTPAUTH "aXBrLUdaRmg6RkhaVkJHaG56ZnZFaEZERlRHenVpZjU2NzZ6aGpHVFVHQk5Iam0="
9
10struct clist *config[LISTHASHSIZE] = {NULL};
11struct clist *ownconfig[LISTHASHSIZE] = {NULL};
12struct clist *rcconfig[LISTHASHSIZE] = {NULL};
13struct clist *skinconfig[LISTHASHSIZE] = {NULL};
14struct skin *skin = NULL;
15struct fb *fb = NULL;
16struct fb* skinfb = NULL;
17struct fb* accelfb = NULL;
18struct fb* fb1 = NULL;
19struct fb* lcdskinfb = NULL;
20struct font *font = NULL;
21struct rc *rc = NULL;
22struct dvbdev *dvbdev = NULL;
23struct dvbdev *dvbdevsim = NULL;
24struct channel *channel = NULL;
25struct transponder *transponder = NULL;
26struct provider *provider = NULL;
27struct sat *sat = NULL;
28struct service *service = NULL;
29struct mainbouquet *mainbouquet = NULL;
30struct mainplaylist *mainplaylist = NULL;
31struct pic *pic = NULL;
32struct rcmap *rcmap = NULL;
33struct inetwork *inetwork = NULL;
34struct stimerthread *stimerthread = NULL;
35struct rectimer *rectimer = NULL;
36struct subpage* subpage = NULL, *oldsubpage = NULL;
37struct epgscanlist* epgscanlist = NULL;
38struct screensaver* screensaver = NULL;
39struct channelcache* channelcache[CHANNELCACHEMAX] = {NULL};
40struct transpondercache* transpondercache[TRANSPONDERCACHEMAX] = {NULL};
41struct hdd* hdd = NULL;
42struct queue* queue = NULL;
43struct caservice caservice[MAXCASERVICE];
44struct channelhistory channelhistory[MAXCHANNELHISTORY];
45struct mostzap* mostzap = NULL;
46struct mediadbfilter* mediadbfilter = NULL;
47struct mediadbcategory* mediadbcategory = NULL;
48struct mediadb* mediadb = NULL;
49struct mediadbcache* mediadbcache[MEDIADBCACHEMAX] = {NULL};
50struct unicable* unicable = NULL;
51struct oldentry* oldentry = NULL;
52struct newsletter* newsletter = NULL;
53struct extepgcache* extepgcache = NULL;
54struct extepgchannel* extepgchannel = NULL;
55struct extepgconfig* extepgconfig = NULL;
56struct lastsubtitle* lastsubtitle = NULL;
57struct style* style = NULL;
58struct download* bgdownload[MAXBGDOWNLOAD] = {NULL};
59struct channelslot *channelslot = NULL;
60
61#ifdef SH4
62#include "sh4port.h"
63#endif
64
65#ifdef MIPSEL
66#include "mipselport.h"
67#endif
68
69#ifdef I386
70#include "i386port.h"
71#endif
72
73#include "oldentry.h"
74#include "tpk.h"
75#include "jsmn.h"
76#include "queue.h"
77#include "channelcache.h"
78#include "transpondercache.h"
79#include "strconvert.h"
80#include "numinput.h"
81#include "textinput.h"
82#include "radiotext.h"
83#include "list.h"
84#include "config.h"
85#include "defaults.h"
86#include "ownconfig.h"
87#include "rcconfig.h"
88#include "skinconfig.h"
89#include "thumb.h"
90#include "global.h"
91#include "stream.h"
92#include "dvbdev.h"
93#include "rotorcalc.h"
94#include "frontenddev.h"
95#include "dmxdev.h"
96#include "videodev.h"
97#include "audiodev.h"
98#include "cidev.h"
99#include "cadev.h"
100#include "scdev.h"
101#include "ca.h"
102#include "dvrdev.h"
103#include "cam.h"
104#include "dvb.h"
105#include "fb.h"
106#include "font.h"
107#include "rcmap.h"
108#include "rc.h"
109#include "sat.h"
110#include "transponder.h"
111#include "provider.h"
112#include "channel.h"
113#include "bouquets.h"
114#include "mainbouquets.h"
115#include "playlist.h"
116#include "mainplaylist.h"
117#include "pic.h"
118#include "filelist.h"
119#include "skinfunc.h"
120#include "style.h"
121#include "skin.h"
122#include "inputhelp.h"
123#include "rcfunc.h"
124#include "listbox.h"
125#include "choicebox.h"
126#include "vfd.h"
127#include "timerthread.h"
128#include "service.h"
129#include "pip.h"
130#include "player.h"
131#include "dvdplayer.h"
132#include "timeshift.h"
133#include "record.h"
134#include "zap.h"
135#include "showiframe.h"
136#include "epgrecord.h"
137#include "multiepg.h"
138#include "gmultiepg.h"
139#include "epg.h"
140#include "eit.h"
141#include "extepg.h"
142#include "epgscan.h"
143#include "menulist.h"
144#include "videomode.h"
145#include "inetwork.h"
146#include "keyactions.h"
147#include "scart.h"
148#include "standby.h"
149#include "dir.h"
150#include "spinner.h"
151#include "lnbconfig.h"
152#include "diseqcconfig.h"
153#include "tunerconfig.h"
154#include "epgsettings.h"
155#include "listedit.h"
156#include "channellist.h"
157#include "vfdisplay.h"
158#include "videosettings.h"
159#include "textbox.h"
160#include "autores.h"
161#include "language.h"
162#include "about.h"
163#include "serviceinfo.h"
164#include "avsettings.h"
165#include "mute.h"
166#include "volume.h"
167#include "timezone.h"
168#include "adjust.h"
169#include "skinadjust.h"
170#include "blindscanadjust.h"
171#include "moduleconfig.h"
172#include "scconfig.h"
173#include "possetup.h"
174#include "rectimer.h"
175#include "pin.h"
176#include "plugin.h"
177#include "recordpath.h"
178#include "subtitle.h"
179#include "audiotrack.h"
180#include "linkedchannel.h"
181#include "powerofftimer.h"
182#include "skinselector.h"
183#include "play.h"
184#include "satfinder.h"
185#include "menu.h"
186#include "channelbynr.h"
187#include "infobar.h"
188#include "network.h"
189#include "harddisk.h"
190#include "httpdfunc.h"
191#include "httpd.h"
192#include "download.h"
193#include "copyfile.h"
194#include "screensaver.h"
195#include "screensaveradjust.h"
196#include "scan.h"
197#include "restoredefault.h"
198#include "help.h"
199#include "httpdsettings.h"
200#include "epgsearch.h"
201#include "inadyn.h"
202#include "rguid.h"
203#include "channelhistroy.h"
204#include "mostzap.h"
205#include "settings_redbutton.h"
206#include "settings_bluebutton.h"
207#include "extensions.h"
208#include "system_update.h"
209#include "system_backup.h"
210#include "system_backup_restore.h"
211#include "info.h"
212#include "softcam.h"
213#include "id3.h"
214#include "mediadbcache.h"
215#include "mediadb.h"
216#include "mediadbsettings.h"
217#include "colorpicker.h"
218#include "ocrypt.h"
219#include "unlock.h"
220#include "md5.h"
221#include "rc4.h"
222#include "textinputhist.h"
223#include "system_infos.h"
224#include "system_infos_sysinfo.h"
225#include "unicable.h"
226#include "newsletter.h"
227#include "dirsort.h"
228#include "shortepg.h"
229#include "mediadbedit.h"
230#include "tpchoice.h"
231#include "marker.h"
232#include "timeshiftsettings.h"
233#include "log.h"
234#include "bgdownload.h"
235#include "fancontrol.h"
236#include "channelslot.h"
237#include "hwtest.h"
238
239#define TIMECODE ""
240
241void demomodethread(struct stimerthread* self)
242{
243        textbox(_("Message"), _("!!! This is a DEMO Version !!!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 600, 0, 1);
244}
245
246int createstartscreen()
247{
248        addscreen("<screen name=framebuffer/>", 0, 0);
249        if(skin == NULL)
250        {
251                err("can't set framebuffer skin");
252                return 1;
253        }
254        addscreen("<screen name=skinerror/>", 0, 0);
255        status.skinerr = getscreen("skinerror");
256        skin->width = skinfb->width;
257        skin->height = skinfb->height;
258        skin->iwidth = skinfb->width;
259        skin->iheight = skinfb->height;
260        skin->rwidth = skinfb->width;
261        skin->rheight = skinfb->height;
262        skin->bgcol = 0;
263        skin->transparent = 255;
264        skin->flag = 1;
265
266        return 0;
267}
268
269//exitcode: 1 power off
270//exitcode: 2 restart
271//exitcode: 3 Gui restart
272//flag: 0 do not check record
273//flag: 1 check record
274//flag: 2 check record / don't write config
275//flag: 3 check record with timeout
276//flag: 4 check record with increase fixpowerofftime
277//flag: 5 check record with increase powerofftime
278void oshutdown(int exitcode, int flag)
279{
280        struct dvbdev* dvbnode = dvbdev;
281        struct service* servicenode = service;
282        void* threadstatus;
283        int i = 0, faststop = 0, ret = 0;
284        char* tmpstr = NULL;
285        struct skin* logo = getscreen("logo");
286        pthread_attr_t writethreadattr = {};
287        pthread_t writethread = '\0';
288
289        //stop permanent timeshift
290        if(status.timeshift == 1)
291                timeshiftstop(3);
292
293        //check if record running
294        if((flag == 1 || flag == 2 || flag == 3 || flag == 4 || flag == 5) && (status.recording > 0 || getrectimerbytimediff(300) != NULL))
295        {
296                if(flag == 4 && status.fixpowerofftime > 1)
297                {
298                                status.fixpowerofftime = time(NULL) + 900; //check powerofftimer again in 15min
299                                return;
300                }
301                if(flag == 5 && status.sd_timer != NULL && status.sd_timer->active)
302                {
303                                status.sd_timer->shutdown_time = time(NULL) + 900; //check powerofftimer again in 15min
304                                return;
305                }
306
307                if(textbox(_("Message"), _("Found running record\nor record is starting in next time.\nReally shutdown ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) != 1)
308                        return;
309        }
310
311        //check if download is running
312        for(i = 0; i < MAXBGDOWNLOAD; i++)
313        {
314                if(bgdownload[i] != NULL && bgdownload[i]->ret == -1)
315                {
316                        if(textbox(_("Message"), _("Found running download\nReally shutdown ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) != 1)
317                                return;
318                        break;
319                }
320        }
321
322        ret = servicestop(status.aktservice, 1, 1);
323        if(ret == 1) return;
324       
325        if(exitcode == 1)
326                tmpstr = getconfig("powerofflogo", NULL);
327        else if(exitcode == 2)
328                tmpstr = getconfig("restartlogo", NULL);
329        else if(exitcode == 3)
330                tmpstr = getconfig("guirestartlogo", NULL);
331               
332        if(tmpstr != NULL)
333        {
334                changepic(logo, tmpstr);
335                tmpstr = NULL;
336                drawscreen(logo, 0, 0);
337        }
338        else
339                clearfball();
340
341        //stop all records
342        while(servicenode != NULL)
343        {
344                servicenode->recendtime = 1;
345                servicenode = servicenode->next;
346        }
347
348        faststop = getconfigint("faststop", NULL);
349
350        // Free memory, semaphores, etc. and say goodbye
351        if(faststop == 0) cleanupvfd();
352
353        if(status.servicetype != 99) //don't save tmp servicetype
354        {
355                tmpstr = oitoa(status.servicetype);
356                addconfig("servicetype", tmpstr);
357                free(tmpstr); tmpstr = NULL;
358        }
359
360        status.sec = 0;
361
362        if(flag != 2)
363        {
364                //start write thread
365                pthread_attr_init(&writethreadattr);
366                pthread_attr_setstacksize(&writethreadattr, 50000);
367                pthread_attr_setdetachstate(&writethreadattr, PTHREAD_CREATE_JOINABLE);
368
369                int epgsave = getconfigint("epgsave", NULL);
370                if((epgsave == 1 && exitcode == 3) || epgsave == 2)
371                        ret = pthread_create(&writethread, &writethreadattr, writeallconfigthread1, NULL); //do not save epg
372                else
373                        ret = pthread_create(&writethread, &writethreadattr, writeallconfigthread0, NULL); //save epg
374                if(ret)
375                {
376                        err("create write thread");
377                }
378        }
379
380        //reset ci devices
381        while(dvbnode != NULL)
382        {
383                if(dvbnode->type == CIDEV && dvbnode->fd > -1)
384                {
385                        if(dvbnode->caslot != NULL) dvbnode->caslot->status = 101;
386                        usleep(10000);
387                        careset(dvbnode, dvbnode->devnr);
388                }
389                dvbnode = dvbnode->next;
390        }
391
392        if(faststop == 0)
393        {
394                //wait for write thread
395                if(writethread != '\0')
396                        pthread_join(writethread, &threadstatus);
397                pthread_attr_destroy(&writethreadattr);
398
399                //stop timer thread
400                i = 0;
401                status.timerthreadaktion = STOP;
402                while(status.timerthreadstatus != DEACTIVE)
403                {
404                        usleep(100000);
405                        i++; if(i > 20) break;
406                }
407
408                if(i > 20)
409                {
410                        err("detect hanging timer thread");
411                }
412                else if(status.timerthread != '\0')
413                        pthread_join(status.timerthread, &threadstatus);
414                pthread_attr_destroy(&status.timerthreadattr);
415
416                // free timerthread struct and stop all timer sub threads
417                freetimer(0);
418
419                status.skinerr = NULL;
420                free(status.gateway);
421                free(status.dnsserver1);
422                free(status.dnsserver2);
423                free(status.boxtype);
424                free(status.httpauth);
425                free(status.bgpic);
426
427                freeservice();
428                freecaservice();
429
430                freescreen();
431                freepic();
432                freefont();
433                deinitfont();
434
435                freerectimer();
436                freemostzap(0);
437                freechannelhistory();
438                freesat();
439                freeallplaylist();
440                freemainplaylist();
441                freeallbouquet();
442                freemainbouquet();
443                freechannel(0);
444                freetransponder();
445                freeprovider();
446                freeownconfig();
447                freeepgscanlist();
448                freercconfig();
449                freeskinconfig();
450                freequeue();
451                freehdd(0);
452
453                free(status.configfile);
454                freeconfig();
455
456                freedvbdev(0);
457
458                closefb(fb);
459                freefb();
460
461                closerc();
462                freerc();
463                freercmap();
464                free_shutdowntimervar();
465                freeinetwork();
466                freeoldentry();
467                freeextepgconfig();
468                freelastsubtitle();
469                freebgdownload();
470                freechannelslot();
471        }
472        else
473                freetimer(1);
474
475        if(exitcode == 1)
476                setcecstandby(1);
477
478        starthttpd(0);
479        startrguid(0);
480        initmutex(0);
481
482        if(faststop != 0)
483        {
484                //wait for write thread
485                if(writethread != '\0')
486                        pthread_join(writethread, &threadstatus);
487                pthread_attr_destroy(&writethreadattr);
488        }
489
490        exit(exitcode);
491}
492
493int main(int argc, char *argv[])
494{
495        int ret = 0, serviceret = 0, skincheck = 0;
496        char* tmpstr = NULL;
497        unsigned char *mmapfb = NULL;
498        struct sigaction sa;
499        struct stimerthread *tmpthread = NULL;
500        //struct sched_param schedparam;
501
502#ifdef SIMULATE
503        // for mem leak debug
504        setenv("MALLOC_TRACE", "/home/nit/titan/m.txt", 1);
505        mtrace();
506        status.security = 1;
507#endif
508
509        printf("[%s] copyright by %s - version %s\n", PROGNAME, COPYRIGHT, OVERSION);
510        printf("[%s] crontribut: %s\n", PROGNAME, CRONTRIBUT);
511
512        sa.sa_handler = (void *)sighandler;
513        sigemptyset(&sa.sa_mask);
514        sa.sa_flags = SA_RESTART;
515       
516        initsignal(&sa);
517
518        status.rguidfd = -1;
519        status.sec = time(NULL);
520        status.mainthread = pthread_self();
521
522        if(argc > 1)
523                status.configfile = ostrcat(argv[1], NULL, 0, 0);
524        else
525                status.configfile = ostrcat(CONFIGFILE, NULL, 0, 0);
526
527        printf("[%s] using config: %s\n", PROGNAME, status.configfile);
528        ret = readconfig(status.configfile, config);
529        if(ret != 0)
530                return 100;
531
532        //start timer thread
533        status.timerthreadaktion = START;
534        pthread_attr_init(&status.timerthreadattr);
535        pthread_attr_setstacksize(&status.timerthreadattr, 50000);
536        pthread_attr_setdetachstate(&status.timerthreadattr, PTHREAD_CREATE_JOINABLE);
537        ret = pthread_create(&status.timerthread, &status.timerthreadattr, timerthreadfunc, NULL);
538        if(ret)
539        {
540                err("create timer thread");
541                return 100;
542        }
543
544        //change working dir to /tmp
545        //chdir("/tmp");
546
547        //set main scheduler priority
548        //schedparam.sched_priority = 10;
549        //pthread_setschedparam(pthread_self(), SCHED_RR, &schedparam);
550
551        readconfig(getconfig("ownconfig", NULL), ownconfig);
552        readconfig(getconfig("rcconfig", NULL), rcconfig);
553
554        skincheck = checkskin();
555        readconfig(getconfig("skinconfig", NULL), skinconfig);
556
557        setprogress(100);
558        setdefaults();
559        setdebuglevel();
560        initmutex(1);
561        m_lock(&status.waitrcmutex, 24);
562        initvfd();
563
564        if(checkbox("UFS922") == 1)
565                setfanspeed(-1, 0);
566
567        system(getconfig("skriptbeforetv", NULL));
568        ret = setcecstandby(0);
569        ret = setvideomode(getconfig("av_videomode", NULL), 0);
570        ret = setpolicy(getconfig("av_policy", NULL));
571        ret = setaspect(getconfig("av_aspect", NULL));
572        ret = setcolorformat(getconfig("av_colorformat", NULL));
573        ret = setaudiosource(getconfig("av_audiosource", NULL));
574        ret = setac3(getconfig("av_ac3mode", NULL));
575        ret = setmode3d(getconfig("av_mode3d", NULL));
576        ret = setvfdbrightness(getconfigint("vfdbrightness", NULL));
577        ret = setaudiodelaybitstream(getconfig("audiodelaybitstream", NULL));
578        ret = addinetworkall(NULL);
579       
580#ifndef SIMULATE
581        if(getconfigint("sos", NULL) == 0)
582        {
583                if(ostrcmp(string_newline(gettimeinfo()), TIMECODE) == 1)
584                {
585                        printf("error: 1\n");
586                        destroy();
587                        exit(100);
588                }
589                if(ostrcmp(string_newline(gettimeinfovar()), TIMECODE) == 1)
590                {
591                        printf("error: 2\n");           
592                        destroy();
593                        exit(100);
594                }
595                if(checkreseller() != 0)
596                {
597                        printf("error: 3\n");           
598                        destroy();
599                        exit(100);
600                }
601                if(getsysinfo() != SYSCODE)
602                {
603                        printf("error: 4\n");           
604                        destroy();
605                        exit(100);
606                }
607                if(file_exist("/mnt/swapextensions/etc/.vnumber") == 1)
608                {
609                        printf("error: 5\n");           
610                        destroy();
611                        exit(100);
612                }
613                if(checkflash() != 0)
614                {
615                        printf("error: 6\n");           
616                        destroy();
617                        exit(100);
618                }
619                if(checkbox("ATEMIO520__") == 1 && checkhighflash() != 0)
620                {
621                        printf("error: 7\n");           
622                        destroy();
623                        exit(100);
624                }
625                if(checkbox("UFS910") == 1 && checklowflash() != 0)
626                {
627                        printf("error: 8\n");           
628                        destroy();
629                        exit(100);
630                }
631       
632                char* cpuid = getcpuid();
633                checkserial(cpuid);
634                free(cpuid); cpuid = NULL;
635        }
636        else
637        {
638                status.security = 1;
639                startnet();
640                setskinnodeslocked(0);
641        }
642#endif
643
644        ret = initfont();
645        if(ret != 0)
646                return 100;
647        ret = openfont(getconfig("fontfile1", NULL));
648        if(ret != 0)
649        {
650                err("open fontfile1 font");
651                return 100;
652        }
653        openfont(getconfig("fontfile2", NULL));
654        openfont(getconfig("fontfile3", NULL));
655        openfont(getconfig("fontfile4", NULL));
656        openfont(getconfig("fontfile5", NULL));
657
658        //skin defined fonts
659        openfont(getskinconfig("fontfile1", NULL));
660        openfont(getskinconfig("fontfile2", NULL));
661        openfont(getskinconfig("fontfile3", NULL));
662        openfont(getskinconfig("fontfile4", NULL));
663        openfont(getskinconfig("fontfile5", NULL));
664
665        setvol(getconfigint("vol", NULL));
666
667        setlang(getconfig("lang", NULL));
668        initlocale(getconfig("localepath", NULL));
669
670        fb = openfb(getconfig("fbdev", NULL), 0);
671        if(fb == NULL)
672                return 100;
673        clearfball();
674        enablemanualblit();
675
676        tmpstr = getconfig("fb1dev", NULL);
677        if(tmpstr != NULL)
678                fb1 = openfb(tmpstr, 1);
679        tmpstr = NULL;
680
681        if(status.usedirectfb != 1)
682        {
683                skinfb = addfb(SKINFB, 0, getconfigint("skinfbwidth", NULL), getconfigint("skinfbheight", NULL), 4, fb->fd, fb->fb + fb->varfbsize, fb->fixfbsize);
684                if(skinfb != NULL)
685                {
686                        ret = getfbsize(0);
687                        if(ret > 0)
688                                accelfb = addfb(ACCELFB, 0, ret / 4, 1, 4, fb->fd, skinfb->fb + skinfb->varfbsize, fb->fixfbsize);
689                }
690                else
691                {
692                        debug(100, "use directfb");
693                        status.usedirectfb = 1;
694                }
695        }
696
697        if(status.usedirectfb == 1)
698        {
699                skinfb = fb;
700                ret = getfbsize(0);
701                if(ret > 0)
702                        accelfb = addfb(ACCELFB, 0, ret / 4, 1, 4, fb->fd, skinfb->fb + skinfb->varfbsize, fb->fixfbsize);
703        }
704
705        //if(lcdskinfb == NULL) {
706                //mmapfb = malloc(4 * 320 * 240);
707                //mmapfb = malloc(4 * 1024 * 768);
708                //mmapfb = NULL;
709                /* dev=999 ist LCD Buffer */
710                //lcdskinfb = addfb("lcdskinfb", 999, 320, 240, 4, -1, mmapfb, 4 * 320 * 240);
711                //lcdskinfb = addfb("lcdskinfb", 999, 1024, 768, 4, -1, mmapfb, 4 * 1024 * 768);
712                // mmapfb = NULL;
713        //}
714
715        ret = createstartscreen();
716        if(ret != 0) return 100;
717
718        //from here we can use starterror screen
719        ret = openrc();
720        if(ret != 0)
721        {
722                tmpstr = ostrcat(tmpstr, _("Error: open rc device !!"), 1, 0);
723                goto starterror;
724        }
725
726        if(fegetdev() < 1)
727        {
728                tmpstr = ostrcat(tmpstr, _("Error: no frontend device found !!"), 1, 0);
729                err("no frontend device found");
730                goto starterror;
731        }
732        if(dmxgetdev() < 1)
733        {
734                tmpstr = ostrcat(tmpstr, _("Error: no demux device found !!"), 1, 0);
735                err("no demux device found");
736                goto starterror;
737        }
738        if(videogetdev() < 1)
739        {
740                tmpstr = ostrcat(tmpstr, _("Error: no video device found !!"), 1, 0);
741                err("no video device found");
742                goto starterror;
743        }
744        if(audiogetdev() < 1)
745        {
746                tmpstr = ostrcat(tmpstr, _("Error: no audio device found !!"), 1, 0);
747                err("no audio device found");
748                goto starterror;
749        }
750        ret = fecreatedummy();
751        ret = cagetdev();
752        ret = cigetdev();
753        ret = dvrgetdev();
754        ret = scgetdev();
755        settunerstatus();
756
757        //start ca slot watching threads
758        castart();
759
760        //check skin
761        if(skincheck > 0)
762        {
763
764                tmpstr = ostrcat(tmpstr, _("Error: skin not found !!"), 1, 0);
765                err("skin not found");
766                goto starterror;
767        }
768
769        ret = readsat(getconfig("satfile", NULL));
770        ret = readtransponder(getconfig("transponderfile", NULL));
771        ret = readprovider(getconfig("providerfile", NULL));
772        ret = readchannel(getconfig("channelfile", NULL));
773        ret = readtransponderencoding(getconfig("transponderencodingfile", NULL));
774        ret = readmostzap(getconfig("mostzapfile", NULL));
775        ret = readlastsubtitle(getconfig("lastsubtitle", NULL));
776        ret = readchannelslot(getconfig("channelslotfile", NULL));
777
778        status.aktservice = addservice(NULL);
779        status.lastservice = addservice(NULL);
780        status.pipservice = addservice(NULL);
781
782        //check if startchannel defined
783        char* startchannellist = getconfig("startchannellist", NULL);
784        int startserviceid = getconfigint("startserviceid", NULL);
785        uint64_t starttransponderid = getconfigllu("starttransponderid", NULL);
786        int startservicetype = getconfigint("startservicetype", NULL);
787        if(startchannellist != NULL && startserviceid != 0)
788        {
789                if(startservicetype == 0)
790                {
791                        addconfig("channellist", startchannellist);
792                        addconfigint("serviceid", startserviceid);
793                        addconfigllu("transponderid", starttransponderid);
794                }
795                else
796                {
797                        addconfig("rchannellist", startchannellist);
798                        addconfigint("rserviceid", startserviceid);
799                        addconfigllu("rtransponderid", starttransponderid);
800                }
801                addconfigint("servicetype", startservicetype);
802        }
803
804        //tune to channel
805        if(status.servicetype == 0)
806                serviceret = servicestart(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)), getconfig("channellist", NULL), NULL, 0);
807        else
808                serviceret = servicestart(getchannel(getconfigint("rserviceid", NULL), getconfigllu("rtransponderid", NULL)), getconfig("rchannellist", NULL),  NULL, 0);
809
810        ret = readscreen(getconfig("skinfile", NULL), 0, 0);
811        ret = readmainbouquet(getconfig("bouquetfile", NULL));
812        ret = readallbouquet();
813        ret = readmainplaylist(getconfig("playlistfile", NULL));
814        ret = readallplaylist();
815        ret = readrcmap(getconfig("rcmapfile", NULL));
816        ret = readepgscanlist(getconfig("epgchannelfile", NULL));
817        ret = settimezone(getconfig("timezone", NULL));
818        ret = readextepgconfig(getconfig("extepgfile", NULL));
819
820        //check to remove preinstalled tpk packages
821        ret = tpkupdatepre();
822
823        addtimer(&checkdate, START, 2000, -1, NULL, NULL, NULL);
824        if(checkbox("ATEMIO510") == 0)
825                addtimer(&updatevfd, START, 1000, -1, NULL, NULL, NULL);
826
827        if(getconfigint("firststart", NULL) == 1)
828        {
829                if(file_exist("/var/etc/.scart"))
830                {
831                        setvideomode("pal", 0);
832                        changefbresolution("pal", 0);
833                        autoresolution();
834                }
835                addconfig("firststart", "0");
836        }
837               
838        //first wizzard
839        if(getconfigint("nofirstwizzard", NULL) < 2)
840        {
841                if(file_exist("/var/etc/.scart"))
842                {
843                        setvideomode("pal", 0);
844                        changefbresolution("pal", 0);
845                }
846
847                autoresolution();
848
849                if(getconfigint("nofirstwizzard", NULL) == 0)
850                {
851firstwizzardstep1:
852
853                        status.updatevfd = PAUSE;
854                        screenavsettings(1);
855                        resettvpic();
856                        //this screen can reload the skin (on language change)
857                        //all skin changes before here than are deleted
858                        if(screenlanguage(2) == 2) return 100;
859                        resettvpic();
860                        screentunerconfig();
861                        resettvpic();
862                        screenscanconfig(1);
863                        resettvpic();
864                        screennetwork_adapter();
865                        resettvpic();
866                        writevfd("Setting OK ?");
867                        if(textbox(_("First Wizzard"), _("Settings OK ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 2)
868                        {
869                                goto firstwizzardstep1;
870                        }
871                        resettvpic();
872                }
873
874                char* msg = NULL;
875                msg = readfiletomem("/etc/imageinfo", 0);
876                textbox(_("Info"), _(msg), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1100, 680, 30, 0);
877                free(msg); msg = NULL;
878               
879                writevfd("");
880                status.updatevfd = START;
881                drawscreen(skin, 0, 0);
882                addconfig("nofirstwizzard", "2");
883        }
884        else
885        {
886                // workaround, remove bootlogo on startup
887                drawscreen(skin, 0, 0);
888
889                //check servicestart
890                if(serviceret != 21) // no message if startchannel empty
891                        servicecheckret(serviceret, 0);
892        }
893
894        //start spinner thread
895        addtimer(&checkspinner, START, 2000, -1, NULL, NULL, NULL);
896        //start auto shutdown thread
897        addtimer(&checkshutdowntimer, START, 10000, -1, NULL, NULL, NULL);
898        //start demo mode
899        if(checkbox("WHITEBOX") == 1)
900                addtimer(&demomodethread, START, 600000, -1, NULL, NULL, NULL);
901
902        status.lastrcaction = time(NULL);
903        ret = loadplugin();
904        setosdtransparent(getskinconfigint("osdtransparent", NULL));
905        ret = setsaturation(getconfigint("vs_saturation", NULL));
906        ret = setbrightness(getconfigint("vs_brightness", NULL));
907        ret = setcontrast(getconfigint("vs_contrast", NULL));
908        ret = settint(getconfigint("vs_tint", NULL));
909       
910#ifndef SIMULATE
911        //set skinentrys locked
912        if(status.security == 0)
913                setskinnodeslocked(1);
914        else
915                setskinnodeslocked(0);
916#endif
917
918        //start epg thread
919        status.epgthread = addtimer(&epgthreadfunc, START, 1000, -1, NULL, NULL, NULL);
920        //start record timer thread (on delay change you must change rectimer.h also)
921        status.rectimerthread = addtimer(&checkrectimer, START, 1000, -1, NULL, NULL, NULL);
922        //check if cam socket connected
923        addtimer(&checkcam, START, 3000, -1, NULL, NULL, NULL);
924        //start stream server
925        tmpthread = addtimer(&streamthreadfunc, START, 10000, -1, NULL, NULL, NULL);
926        if(tmpthread != NULL)
927        {
928                tmpthread->flag = setbit(tmpthread->flag, 0);
929                tmpthread = NULL;
930        }
931        //start epg scanlist
932        status.epgscanlistthread = addtimer(&epgscanlistthread, START, 1000, 1, NULL, NULL, NULL);
933        //get pmt
934        if(getconfigint("checkpmtalways", NULL) == 1)
935                addtimer(&dvbgetpmtthread, START, 2000, -1, NULL, NULL, NULL);
936        //check hdd
937        status.addhddall = addtimer(&addhddall, START, 6000, -1, NULL, NULL, NULL);
938        //check net
939        addtimer(&addinetworkall, START, 15000, -1, NULL, NULL, NULL);
940        //check kill net (security)
941        addtimer(&ckeckkillnetthread, START, 1000, 1, NULL, NULL, NULL);
942        //check old entrys and remove from mem
943        addtimer(&oldentrythreadfunc, START, 60000 * 60, -1, NULL, NULL, NULL);
944
945        //start newsletter
946        startnewsletter(1);
947
948        //thumb create thread
949        startthumb(1);
950
951        //start webserver
952        starthttpd(1);
953       
954        //start rguid
955        startrguid(1);
956
957        //init the player
958        playerinit(argc, argv);
959
960        system(getconfig("skriptaftertv", NULL));
961
962        //for atemio to unlock box with stick
963        if(file_exist("/media/hdd/movie/titankey"))
964        {
965                char* cpuid = getcpuid();
966                char* cmd = ostrcat("/media/hdd/movie/titankey ", cpuid, 0, 0);
967                system(cmd);
968                checkserial(cpuid);
969                free(cmd); cmd = NULL;
970
971                if(status.security == 1)
972                {
973                        char* mac = getmacfromcmdline();
974                        if(mac != NULL)
975                        {
976                                cmd = ostrcat(cmd, cpuid, 1, 0);
977                                cmd = ostrcat(cmd, ",", 1, 0);
978                                cmd = ostrcat(cmd, mac, 1, 0);
979                               
980                                free(mac); mac = NULL;
981                        }
982                        else
983                                cmd = ostrcat(cmd, cpuid, 1, 0);
984
985                        writesys("/media/hdd/movie/codelist.txt", cmd, 3);
986                        textbox(_("Message"), _("Receiver successful unlocked"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
987                }
988
989                free(cpuid); cpuid = NULL;
990                free(cmd); cmd = NULL;
991        }
992
993        //must called direct befor screeninfobar
994        if(getconfigint("saverun", NULL) == 1)
995        {
996                ret = sigsetjmp(status.longjumpbuf, 1);
997                if(ret != 0 && ret != 999)
998                {
999                        err("set sigsegjump");
1000                }
1001        }
1002       
1003        //check free space in /var
1004        if(getfreespace("/var") / 1024 < 250) //200kb
1005                textbox(_("Message"), _("Free space in /var to little!\nThis can make problems!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 7, 0);
1006        else
1007        {
1008                //check writeable in /var
1009                if(mkdir("/var/writetest", 0777) != 0 && errno != EEXIST)
1010                {
1011                        if(textbox(_("Message"), _("/var not writeable!\nRepair it?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) == 1)
1012                        {
1013                                system("repairjffs2.sh var &"); //this script kills titan an reboot
1014                                sleep(10);
1015                        }
1016                }
1017                rmdir("/var/writetest");
1018        }
1019
1020        //check free space in /mnt
1021        if(getfreespace("/mnt") / 1024 < 200) //200kb
1022                textbox(_("Message"), _("Free space in /mnt to little!\nThis can make problems!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 7, 0);
1023        else
1024        {
1025                //check writeable in /mnt
1026                if(mkdir("/mnt/writetest", 0777) != 0 && errno != EEXIST)
1027                {
1028                        if(textbox(_("Message"), _("/mnt not writeable!\nRepair it?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) == 1)
1029                        {
1030                                system("repairjffs2.sh mnt &"); //this script kills titan an reboot
1031                                sleep(10);
1032                        }
1033                }
1034                rmdir("/mnt/writetest");
1035        }
1036
1037        screeninfobar();
1038
1039        //for testign screens
1040        //screenmanualscan();
1041        //screeninputhelp();
1042        //screendownload("test", "www.orf.at", NULL, 80, "test.html", 0);
1043        //screenrectimer();
1044        //screenepgsettings();
1045        //screenlnb("1");
1046        //screendiseqc("1");
1047        //screenlanguage();
1048        //screenvideosettings();
1049        //screenskinselect();
1050        //screenrectimer();
1051        //screennetwork_adapter(2);
1052        //screenpin();
1053        //screenchannellist();
1054        //recordstart(channel, RECDIRECT);
1055        //mc_main();
1056        //screenmc_videoplayer();
1057        //screenserviceinfo();
1058        //screentunerconfig();
1059        //screenvfdisplay();
1060        //screenavsettings(1);
1061        //screenadjust();
1062        //subtitlestart();
1063
1064        if(mmapfb != NULL) {
1065                free(mmapfb); mmapfb=NULL;
1066        }
1067        oshutdown(1, 1);
1068        return 0;
1069
1070starterror:
1071        addscreen("<screen hspace=5 vspace=5 type=textbox name=starterror posx=center posy=center bordersize=2 bordercol=#ffffff fontsize=30 fontcol=#ffffff width=600 height=150/>", 0, 0);
1072        struct skin *starterror = getscreen("starterror");
1073        if(tmpstr == NULL)
1074                tmpstr = ostrcat(tmpstr, _("Unknown Error."), 1, 0);
1075        tmpstr = ostrcat(tmpstr, "\n", 1, 0);
1076        tmpstr = ostrcat(tmpstr, _("Automatic stop in 10 seconds."), 1, 0);
1077        changetext(starterror, _(tmpstr));
1078        drawscreen(starterror, 0, 0);
1079        sleep(10);
1080        free(tmpstr);
1081        return 100;
1082}
Note: See TracBrowser for help on using the repository browser.