int parser(char *citycode, const char *trans, int metric, int inet, int ctmo) { int rec=0, flag=0; int cc=0, bc=1, exit_ind=-1; char gettemp; FILE *wxfile=NULL; char url[512]; char debug[505]; #ifdef WWEATHER extern char key[]; int d_flag=0; //data flag ">DATA<" int D_flag=0; //data flag "[DATA]" int l_flag=0; //do not change to upper case (URL) #else int day_data=PRE_DAY; int previews=9; extern char par[], key[]; #endif memset(data,0,MAXITEM*MAXMEM /* 1000*50 */); memset(conveng,0,500*40); memset(convger,0,500*40); prev_count=0; memset(null,0,2); tc=0; t_actday=0; t_actmonth=0; #ifdef WWEATHER /* sprintf (url,"wget -q -O /tmp/tuxwettr.tmp \"http://free.worldweatheronline.com/feed/weather.ashx?q=%s&format=xml&num_of_days=5&includeLocation=yes&key=%s\"",citycode,key); exit_ind=system(url); sleep(1); */ sprintf (url,"http://api.worldweatheronline.com/free/v1/weather.ashx?q=%s&format=xml&num_of_days=5&includeLocation=yes&key=%s",citycode,key); exit_ind=HTTP_downloadFile(url, "/tmp/tuxwettr.tmp", 0, inet, ctmo, 3); if(exit_ind != 0) { printf("Tuxwetter <Download data from server failed. Errorcode: %d>\n",exit_ind); exit_ind=-1; return exit_ind; } exit_ind=-1; if ((wxfile = fopen("/tmp/tuxwettr.tmp","r"))==NULL) { printf("Tuxwetter <Missing tuxwettr.tmp File>\n"); return exit_ind; } else { fgets(debug,50,wxfile); //printf("%s\n",debug); if((debug[45] != 'r')||(debug[46] != 'e')||(debug[47] != 'q')) { fclose(wxfile); return exit_ind; } else { // starting position forcast bc = NA; strcpy(data[bc],"N/A"); bc++; fseek(wxfile, 0L, SEEK_SET); while (!feof(wxfile)) { gettemp=fgetc(wxfile); if (gettemp == '<' || gettemp == ']') rec = 0; if (gettemp == ':') l_flag = 1; if (rec == 1) { if(!l_flag) data[bc][cc] = toupper(gettemp); else data[bc][cc] = gettemp; //printf("#2 data[%d][%d] = %c(%d)\n",bc,cc,gettemp,gettemp); cc++; d_flag=1; if(cc == MAXMEM-1) rec = 0; } if (gettemp == '>' || gettemp == '[') rec = 1; if (gettemp == '[' && !D_flag) { rec = 0; D_flag = 1; } if ((gettemp == '<' || gettemp == ']') && d_flag) { data[bc][cc] = '\0'; //printf("data[%d] = %s\n",bc,data[bc]); bc++; cc = 0; rec = 0; d_flag = 0; D_flag = 0; l_flag = 0; } } } } fclose(wxfile); cc=0; exit_ind=1; #else /* sprintf (url,"http://xoap.weather.com/weather/local/%s?cc=*&dayf=%d&prod=xoap&unit=%c&par=1005530704&key=a9c95f7636ad307b",citycode,previews,(metric)?'m':'u'); exit_ind=HTTP_downloadFile(url, "/tmp/tuxwettr.tmp", 0, inet, ctmo, 3); */ sprintf (url,"wget -q -O /tmp/tuxwettr.tmp http://xoap.weather.com/weather/local/%s?unit=%c\\&dayf=%d\\&cc=*\\&prod=xoap\\&link=xoap\\&par=%s\\&key=%s",citycode,(metric)?'m':'u',previews,par,key); exit_ind=system(url); sleep(1); if(exit_ind != 0) { printf("Tuxwetter <Download data from server failed. Errorcode: %d>\n",exit_ind); exit_ind=-1; return exit_ind; } exit_ind=-1; system("sed -i /'prmo'/,/'\\/lnks'/d /tmp/tuxwettr.tmp"); if ((wxfile = fopen("/tmp/tuxwettr.tmp","r"))==NULL) { printf("Tuxwetter <Missing tuxwettr.tmp File>\n"); return exit_ind; } else { bc=1; fgets(debug,500,wxfile); // printf("%s",debug); fgets(debug,5,wxfile); // printf("%s",debug); if((debug[0] != 60)||(debug[1] != 33)||(debug[2] != 45)||(debug[3] != 45)) { fclose(wxfile); return exit_ind; } else { fclose(wxfile); wxfile = fopen("/tmp/tuxwettr.tmp","r"); while (!feof(wxfile)) { gettemp=fgetc(wxfile); if ((gettemp >=97) && (gettemp <=122)) gettemp = gettemp -32; if (gettemp == 13) gettemp=0; if (bc == day_data) { if (gettemp == 62) { rec = 0; } if (rec == 1) { data[bc][cc] = gettemp; cc++; } if (gettemp == 60) rec = 1; if (gettemp == 13) data[bc][cc+1] =0; if (gettemp == 10) { bc++; cc = 0; rec = 0; flag=1; prev_count++; } } else { if (gettemp == 60) rec = 0; if (rec == 1) { data[bc][cc] = gettemp; cc++; } if (gettemp == 62) rec = 1; if (gettemp == 13) data[bc][cc] =0; if (gettemp == 10) { bc++; cc = 0; rec = 0; } } if ((flag==1) && (gettemp == 0)) { day_data=day_data+PRE_STEP; flag=0; } } } fclose(wxfile); } if (prev_count > 0) prev_count=prev_count-1; if (prev_count > 0) prev_count=prev_count-1; cc=0; exit_ind=1; #endif //*** Übersetzungs File *** if ((wxfile = fopen(trans,"r"))==NULL) { printf("Tuxwetter <File %s not found.>\n",trans); return exit_ind; } else { while (!feof(wxfile)) { gettemp=fgetc(wxfile); if (gettemp == 10) { cc=0; tc++; flag=0; } else { if (gettemp == 124) { cc=0; flag=2; } if (gettemp == 13) gettemp = 0; if (flag==0) { if ((gettemp >=97) && (gettemp <=122)) gettemp = gettemp -32; conveng[tc][cc]=gettemp; } if (flag==1) convger[tc][cc]=gettemp; cc++; if (flag == 2) { flag--; cc=0; } } } fclose(wxfile); } prs_get_dtime (0, ACT_UPTIME, debug, metric); return 0; }
/****************************************************************************** * Blockads Main ******************************************************************************/ int main (void) { int loop=0,found,werbung=0,tnet, tv, cnum=-1; char tstr[512],line_buffer[512],zapchan[40],srcchan[40],*cpt1=NULL; FILE *fh1,*fh2; printf("Blockads Version %s\n",P_VERSION); if((fh1=fopen(FLG_FILE,"r"))==NULL) { // system("ping -c 5 google.com &"); fb = open(FB_DEVICE, O_RDWR); rc = open(RC_DEVICE, O_RDONLY); fcntl(rc, F_SETFL, (fcntl(rc, F_GETFL) | O_EXCL) & ~O_NONBLOCK); if((sx=Read_Neutrino_Cfg("screen_StartX"))<0) sx=80; if((ex=Read_Neutrino_Cfg("screen_EndX"))<0) ex=620; if((sy=Read_Neutrino_Cfg("screen_StartY"))<0) sy=80; if((ey=Read_Neutrino_Cfg("screen_EndY"))<0) ey=505; if(Read_Neutrino_Cfg("rounded_corners")>0) radius=9; else radius=0; //init framebuffer if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { printf("Blockads <FBIOGET_FSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { printf("Blockads <FBIOGET_VSCREENINFO failed>\n"); return -1; } if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { printf("Blockads <mapping of Framebuffer failed>\n"); return -1; } //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("Tuxwetter <FT_Init_FreeType failed with Errorcode 0x%.2X>", error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("Tuxwetter <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("Tuxwetter <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_Lookup_Face(manager, FONT, &face))) { printf("Tuxwetter <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } use_kerning = FT_HAS_KERNING(face); #ifdef FT_NEW_CACHE_API desc.face_id = FONT; desc.flags = FT_LOAD_MONOCHROME; #else desc.font.face_id = FONT; desc.image_type = ftc_image_mono; #endif //init backbuffer if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres))) { printf("Blockads <allocating of Backbuffer failed>\n"); munmap(lfb, fix_screeninfo.smem_len); return -1; } memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres); if (!ReadConf()) { printf("Blockads <Configuration failed>\n"); return -1; } found=0; loop=0; if(!HTTP_downloadFile("localhost",80,"/control/channellist", LST_FILE, 0, 1)) { if(!HTTP_downloadFile("localhost",80,"/control/zapto", ZAP_FILE, 0, 1)) { if((fh1=fopen(ZAP_FILE,"r"))!=NULL) { while((fgets(line_buffer, sizeof(line_buffer), fh1)>0) && (strlen(line_buffer)<4)); if(strlen(line_buffer)>1) { Trim_String(line_buffer); strcpy(zapchan,line_buffer); if((fh2=fopen(LST_FILE,"r"))!=NULL) { while(!found && (fgets(line_buffer, sizeof(line_buffer), fh2))) { if(strstr(line_buffer,zapchan)==line_buffer) { if((cpt1=strchr(line_buffer,' '))!=NULL) { cpt1++; Trim_String(cpt1); strcpy(msgchan,cpt1); loop=1; if(!Translate_Channel(cpt1, tstr)) { cnum=Get_ChannelNumber(tstr); strcpy(srcchan,tstr); found=1; } } } } if(!found) { inet=-1; } fclose(fh2); } } fclose(fh1); } } } if(!loop) { sprintf(tstr,"Fehler beim Auslesen der Kanalliste.\nPlugin konnte nicht gestartet werden."); Msg_Popup(tstr); return -1; } if(volume) { volume=0; if(!HTTP_downloadFile("localhost",80,"/control/volume?status", ZAP_FILE, 0, 1)) { if((fh1=fopen(ZAP_FILE,"r"))!=NULL) { while((fgets(line_buffer, sizeof(line_buffer), fh1)>0) && !strlen(line_buffer)); if(strlen(line_buffer)>=1) { Trim_String(line_buffer); sscanf(line_buffer,"%d",&mute); } fclose(fh1); } } if(!HTTP_downloadFile("localhost",80,"/control/volume", ZAP_FILE, 0, 1)) { if((fh1=fopen(ZAP_FILE,"r"))!=NULL) { while((fgets(line_buffer, sizeof(line_buffer), fh1)>0) && !strlen(line_buffer)); if(strlen(line_buffer)>=1) { Trim_String(line_buffer); sscanf(line_buffer,"%d",&volume); } fclose(fh1); } } } if(inet>=0) { tnet=-1; if(Open_Socket()!=-1) { tv=Check_Socket(cnum,&werbung); if(tv>0) { tnet=inet; if(!werbung) { if(!zapalways) { int adf=0; sprintf(tstr,"Für Kanal %s wird\nmomentan keine Werbung gemeldet.\nWerbung läuft im Augenblick auf:\n",msgchan); for(tv=0; tv<NUM_CHANNELS; tv++) { Check_Channel(tv,&found); if(found) { sprintf(tstr+strlen(tstr),"\n%s",Get_ChannelName(tv)); adf=1; } } if(!adf) { sprintf(tstr+strlen(tstr),"\nkeinem anderen Sender"); } Msg_Popup(tstr); loop=0; } else { tnet=-1; } } else { if((fh2=fopen(FLG_FILE,"w"))!=NULL) { int adf=0; fprintf(fh2,"%s\n%d\n%d\n%s\n%d\n%d\n%d\n",zapchan,cnum,rezap*60,msgchan,volume,mute,debounce); fclose(fh2); system("/bin/blockad &"); sprintf(tstr,"Werbezapper fr Kanal %s aktiviert.\nSie können jetzt umschalten.\n\nWerbung läuft im Augenblick auch auf:\n",msgchan); for(tv=0; tv<NUM_CHANNELS; tv++) { Check_Channel(tv,&found); if(found && (tv != cnum)) { sprintf(tstr+strlen(tstr),"\n%s",Get_ChannelName(tv)); adf=1; } } if(!adf) { sprintf(tstr+strlen(tstr),"\nkeinem anderen Sender"); } Msg_Popup(tstr); } } } Close_Socket(); } inet=tnet; } if(inet==-1 && loop) { Start_NoInet(zapchan); } } else { Msg_Popup("Werbezapper deaktiviert"); remove(FLG_FILE); sleep(2); } // clear Display memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres); memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres); munmap(lfb, fix_screeninfo.smem_len); close(fb); free(lbb); FTC_Manager_Done(manager); FT_Done_FreeType(library); fcntl(rc, F_SETFL, O_NONBLOCK); close(rc); return 0; }