/* $Id: imon.c,v 1.3 2004/01/09 04:16:06 reinelt Exp $ * * imond/telmond data processing * * Copyright 2003 Nico Wallmeier * * This file is part of LCD4Linux. * * LCD4Linux is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * LCD4Linux is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * * $Log: imon.c,v $ * Revision 1.3 2004/01/09 04:16:06 reinelt * added 'section' argument to cfg_get(), but NULLed it on all calls by now. * * Revision 1.2 2004/01/06 22:33:14 reinelt * Copyright statements cleaned up * * Revision 1.1 2003/10/12 06:08:28 nicowallmeier * imond/telmond support * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* decl of inet_addr() */ #include #include "cfg.h" #include "debug.h" #include "parser.h" #include "imon.h" #define TRUE 1 #define FALSE 0 static int fd; /*---------------------------------------------------------------------------- * service_connect (host_name, port) - connect to tcp-service *---------------------------------------------------------------------------- */ static int service_connect (char * host_name, int port) { struct sockaddr_in addr; struct hostent * host_p; int fd; int opt = 1; (void) memset ((char *) &addr, 0, sizeof (addr)); if ((addr.sin_addr.s_addr = inet_addr ((char *) host_name)) == INADDR_NONE) { host_p = gethostbyname (host_name); if (! host_p) { error ("%s: host not found\n", host_name); return (-1); } (void) memcpy ((char *) (&addr.sin_addr), host_p->h_addr, host_p->h_length); } addr.sin_family = AF_INET; addr.sin_port = htons ((unsigned short) port); if ((fd = socket (AF_INET, SOCK_STREAM, 0)) < 0) { /* open socket */ perror ("socket"); return (-1); } (void) setsockopt (fd, IPPROTO_TCP, TCP_NODELAY,
# Sweden - HÃ¥llan
[CHANNEL]
	DELIVERY_SYSTEM = DVBT
	FREQUENCY = 570000000
	BANDWIDTH_HZ = 8000000
if (cpu) (*i).cpu = get_numerical_value("cpu"); if (datetime){ s = get_value ("date"); sscanf (s, "%s %s %s", day, d, (*i).time); strncpy ((*i).date, d, 6); strcpy ((*i).date + 6, d + 8); (*i).date[2]='.'; (*i).date[5]='.'; if (hb) (*i).time[5] =' '; hb=!hb; } return 0; } char* ImonVer(){ static char buffer[32]=""; if (*buffer=='\0') { char *s; if ((fd==0) && ((fd=init())<0)) return ""; s=get_value("version"); for (;;){ // interne Versionsnummer killen if (s[0]==' '){ s=s+1; break; } s=s+1; } strcpy(buffer,s); } return buffer; } void phonebook(char *number){ FILE * fp; char line[256]; fp = fopen (cfg_get (NULL, "Telmon_Phonebook","/etc/phonebook"), "r"); if (! fp) return; while (fgets (line, 128, fp)){ if (*line == '#') continue; if (!strncmp(line,number,strlen(number))){ char *komma=strchr(line,','); char *beginn=strchr(line,'='); if (!beginn) return; while (strrchr(line,'\r')) strrchr(line,'\r')[0]='\0'; while (strrchr(line,'\n')) strrchr(line,'\n')[0]='\0'; if (komma) komma[0]='\0'; strcpy(number,beginn+1); break; } } fclose(fp); } int Telmon(struct telmon *t){ static int tick; static int telmond_fd=-2; static char oldanswer[128]; static char host[256]; static int port; if (tick++ % 50 != 0) return 0; if (telmond_fd == -2){ //not initializied char *s=cfg_get (NULL, "Telmon_Host","127.0.0.1"); if (*s=='\0') { error ("Telmon: no 'Telmon_Host' entry in %s", cfg_source()); telmond_fd=-1; return -1; } strcpy(host,s); if (cfg_number(NULL, "Telmon_Port",5000,1,65536,&port)<0){ telmond_fd=-1; return -1; } } if (telmond_fd != -1){ char telbuf[128]; telmond_fd = service_connect (host, port); if (telmond_fd >= 0){ int l = read (telmond_fd, telbuf, 127); if ((l > 0) && (strcmp(telbuf,oldanswer))){ char date[11]; sscanf(telbuf,"%s %s %s %s",date,(*t).time,(*t).number,(*t).msn); date[4]='\0'; date[7]='\0'; sprintf((*t).date,"%s.%s.%s",date+8,date+5,date); phonebook((*t).number); phonebook((*t).msn); } close (telmond_fd); strcpy(oldanswer,telbuf); } } return 0; }