mirror of
https://github.com/netfun2000/lcd4linux.git
synced 2026-02-27 09:44:34 +08:00
[lcd4linux @ 2004-02-22 17:35:41 by reinelt]
some fixes for generic graphic driver and T6963 removed ^M from plugin_imon (Nico, are you editing under Windows?) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@373 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
16
Makefile.in
16
Makefile.in
@@ -106,7 +106,7 @@ lcd4linux_LDADD = @DRIVERS@ @DRVLIBS@
|
||||
#remove next line for liblcd4linux
|
||||
lcd4linux_DEPENDENCIES = @DRIVERS@
|
||||
|
||||
lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h lock.c lock.h pid.c pid.h timer.c timer.h udelay.c udelay.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_ppp.c plugin_dvb.c plugin_i2c_sensors.c plugin_xmms.c
|
||||
lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h lock.c lock.h pid.c pid.h timer.c timer.h udelay.c udelay.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_ppp.c plugin_dvb.c plugin_i2c_sensors.c plugin_imon.c plugin_xmms.c
|
||||
|
||||
|
||||
#liblcd4linux_la_DEPENDENCIES = @DRIVERS@
|
||||
@@ -145,7 +145,8 @@ plugin_string.$(OBJEXT) plugin_cfg.$(OBJEXT) plugin_uname.$(OBJEXT) \
|
||||
plugin_loadavg.$(OBJEXT) plugin_proc_stat.$(OBJEXT) \
|
||||
plugin_cpuinfo.$(OBJEXT) plugin_meminfo.$(OBJEXT) \
|
||||
plugin_netdev.$(OBJEXT) plugin_ppp.$(OBJEXT) plugin_dvb.$(OBJEXT) \
|
||||
plugin_i2c_sensors.$(OBJEXT) plugin_xmms.$(OBJEXT)
|
||||
plugin_i2c_sensors.$(OBJEXT) plugin_imon.$(OBJEXT) \
|
||||
plugin_xmms.$(OBJEXT)
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@@ -171,11 +172,12 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/MilfordInstruments.P \
|
||||
.deps/drv_generic_text.P .deps/evaluator.P .deps/hash.P .deps/layout.P \
|
||||
.deps/lcd4linux.P .deps/lock.P .deps/pid.P .deps/plugin.P \
|
||||
.deps/plugin_cfg.P .deps/plugin_cpuinfo.P .deps/plugin_dvb.P \
|
||||
.deps/plugin_i2c_sensors.P .deps/plugin_loadavg.P .deps/plugin_math.P \
|
||||
.deps/plugin_meminfo.P .deps/plugin_netdev.P .deps/plugin_ppp.P \
|
||||
.deps/plugin_proc_stat.P .deps/plugin_string.P .deps/plugin_uname.P \
|
||||
.deps/plugin_xmms.P .deps/timer.P .deps/udelay.P .deps/widget.P \
|
||||
.deps/widget_bar.P .deps/widget_icon.P .deps/widget_text.P
|
||||
.deps/plugin_i2c_sensors.P .deps/plugin_imon.P .deps/plugin_loadavg.P \
|
||||
.deps/plugin_math.P .deps/plugin_meminfo.P .deps/plugin_netdev.P \
|
||||
.deps/plugin_ppp.P .deps/plugin_proc_stat.P .deps/plugin_string.P \
|
||||
.deps/plugin_uname.P .deps/plugin_xmms.P .deps/timer.P .deps/udelay.P \
|
||||
.deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \
|
||||
.deps/widget_text.P
|
||||
SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES)
|
||||
OBJECTS = $(lcd4linux_OBJECTS)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Id: drv_T6963.c,v 1.2 2004/02/18 06:39:20 reinelt Exp $
|
||||
/* $Id: drv_T6963.c,v 1.3 2004/02/22 17:35:41 reinelt Exp $
|
||||
*
|
||||
* new style driver for T6963-based displays
|
||||
*
|
||||
@@ -23,6 +23,10 @@
|
||||
*
|
||||
*
|
||||
* $Log: drv_T6963.c,v $
|
||||
* Revision 1.3 2004/02/22 17:35:41 reinelt
|
||||
* some fixes for generic graphic driver and T6963
|
||||
* removed ^M from plugin_imon (Nico, are you editing under Windows?)
|
||||
*
|
||||
* Revision 1.2 2004/02/18 06:39:20 reinelt
|
||||
* T6963 driver for graphic displays finished
|
||||
*
|
||||
@@ -310,7 +314,6 @@ static void drv_T6_blit(int row, int col, int height, int width)
|
||||
for (r=row; r<row+height; r++) {
|
||||
for (c=col; c<col+width; c++) {
|
||||
unsigned char mask = 1<<(XRES-1-c%XRES);
|
||||
//if (c<8) debug ("c=%d c%%XRES=%d mask=%d", c, c%XRES, mask);
|
||||
if (drv_generic_graphic_FB[r*LCOLS+c]) {
|
||||
// set bit
|
||||
Buffer1[(r*DCOLS+c)/XRES] |= mask;
|
||||
@@ -335,7 +338,6 @@ static void drv_T6_blit(int row, int col, int height, int width)
|
||||
}
|
||||
memcpy (Buffer2+j, Buffer1+j, i-j-e+1);
|
||||
drv_T6_copy (j, Buffer1+j, i-j-e+1);
|
||||
// sleep (1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,6 +412,7 @@ static int drv_T6_start (char *section)
|
||||
// set direction: write
|
||||
drv_generic_parport_direction (0);
|
||||
|
||||
|
||||
// initialize display
|
||||
|
||||
drv_T6_send_word (0x40, 0x0000); // Set Text Home Address
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
*
|
||||
*
|
||||
* $Log: drv_generic_graphic.c,v $
|
||||
* Revision 1.3 2004/02/22 17:35:41 reinelt
|
||||
* some fixes for generic graphic driver and T6963
|
||||
* removed ^M from plugin_imon (Nico, are you editing under Windows?)
|
||||
*
|
||||
* Revision 1.2 2004/02/18 06:39:20 reinelt
|
||||
* T6963 driver for graphic displays finished
|
||||
*
|
||||
@@ -229,9 +233,9 @@ int drv_generic_graphic_bar_draw (WIDGET *W)
|
||||
|
||||
case DIR_EAST:
|
||||
for (y=0; y<YRES; y++) {
|
||||
len=y<YRES/2 ? val1 : val2;
|
||||
int val=y<YRES/2 ? val1 : val2;
|
||||
for (x=0; x<max; x++) {
|
||||
drv_generic_graphic_FB[(row+y)*LCOLS+col+x] = x<len ? !rev : rev;
|
||||
drv_generic_graphic_FB[(row+y)*LCOLS+col+x] = x<val ? !rev : rev;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -244,8 +248,8 @@ int drv_generic_graphic_bar_draw (WIDGET *W)
|
||||
case DIR_NORTH:
|
||||
for (y=0; y<max; y++) {
|
||||
for (x=0; x<XRES; x++) {
|
||||
len=x<XRES/2 ? val1 : val2;
|
||||
drv_generic_graphic_FB[(row+y)*LCOLS+col+x] = y<len ? !rev : rev;
|
||||
int val=x<XRES/2 ? val1 : val2;
|
||||
drv_generic_graphic_FB[(row+y)*LCOLS+col+x] = y<val ? !rev : rev;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -74,7 +74,7 @@ Display USBLCD {
|
||||
Display T6963-240x64 {
|
||||
Driver 'T6963'
|
||||
Port '/dev/parports/0'
|
||||
Size '240x64'
|
||||
Size '240x128'
|
||||
Wire.CE 'STROBE'
|
||||
Wire.CD 'SELECT'
|
||||
Wire.RD 'AUTOFD'
|
||||
@@ -152,6 +152,48 @@ Widget LoadBar {
|
||||
}
|
||||
|
||||
|
||||
Widget Disk {
|
||||
class 'Text'
|
||||
# disk.[rw]blk return blocks, we assume a blocksize of 512
|
||||
# to get the number in kB/s we would do blk*512/1024, which is blk/2
|
||||
expression (disk('.*', 'rblk', 500)+disk('.*', 'wblk', 500))/2
|
||||
prefix 'disk'
|
||||
postfix ' '
|
||||
width 10
|
||||
precision 0
|
||||
align 'R'
|
||||
update tick
|
||||
}
|
||||
|
||||
Widget DiskBar {
|
||||
class 'Bar'
|
||||
expression disk('.*', 'rblk', 500)
|
||||
expression2 disk('.*', 'wblk', 500)
|
||||
length 14
|
||||
direction 'E'
|
||||
update tack
|
||||
}
|
||||
|
||||
Widget Eth0 {
|
||||
class 'Text'
|
||||
expression (netdev('eth0.Rx.bytes', 500)+netdev('eth0.Tx.bytes', 500))/1024
|
||||
prefix 'eth0'
|
||||
postfix ' '
|
||||
width 10
|
||||
precision 0
|
||||
align 'R'
|
||||
update tick
|
||||
}
|
||||
|
||||
Widget Eth0Bar {
|
||||
class 'Bar'
|
||||
expression netdev('eth0.Rx.bytes', 500)
|
||||
expression2 netdev('eth0.Tx.bytes', 500)
|
||||
length 14
|
||||
direction 'E'
|
||||
update tack
|
||||
}
|
||||
|
||||
Widget Heartbeat {
|
||||
class 'Icon'
|
||||
speed 800
|
||||
@@ -276,6 +318,14 @@ Layout Default {
|
||||
Col1 'Load'
|
||||
Col11 'LoadBar'
|
||||
}
|
||||
Row5 {
|
||||
Col1 'Disk'
|
||||
Col11 'DiskBar'
|
||||
}
|
||||
Row6 {
|
||||
Col1 'Eth0'
|
||||
Col11 'Eth0Bar'
|
||||
}
|
||||
}
|
||||
|
||||
Layout L24x8 {
|
||||
@@ -312,14 +362,14 @@ Layout Test {
|
||||
Row06.Col1 'Test'
|
||||
Row07.Col1 'Test'
|
||||
Row08.Col1 'Test'
|
||||
Row09.Col1 'Test'
|
||||
Row10.Col1 'Test'
|
||||
Row11.Col1 'Test'
|
||||
Row12.Col1 'Test'
|
||||
Row13.Col1 'Test'
|
||||
Row14.Col1 'Test'
|
||||
Row15.Col1 'Test'
|
||||
Row16.Col1 'Test'
|
||||
# Row09.Col1 'Test'
|
||||
# Row10.Col1 'Test'
|
||||
# Row11.Col1 'Test'
|
||||
# Row12.Col1 'Test'
|
||||
# Row13.Col1 'Test'
|
||||
# Row14.Col1 'Test'
|
||||
# Row15.Col1 'Test'
|
||||
# Row16.Col1 'Test'
|
||||
}
|
||||
|
||||
#Display 'LK204'
|
||||
@@ -331,9 +381,9 @@ Layout Test {
|
||||
#Display 'USBLCD'
|
||||
Display 'T6963-240x64'
|
||||
|
||||
#Layout 'Default'
|
||||
Layout 'Default'
|
||||
#Layout 'L16x2'
|
||||
Layout 'Test'
|
||||
#Layout 'Test'
|
||||
|
||||
|
||||
Variables {
|
||||
|
||||
854
plugin_imon.c
854
plugin_imon.c
@@ -1,428 +1,432 @@
|
||||
/* $Id: plugin_imon.c,v 1.1 2004/02/18 14:45:43 nicowallmeier Exp $
|
||||
*
|
||||
* imond/telmond data processing
|
||||
*
|
||||
* Copyright 2003 Nico Wallmeier <nico.wallmeier@post.rwth-aachen.de>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
/* $Id: plugin_imon.c,v 1.2 2004/02/22 17:35:41 reinelt Exp $
|
||||
*
|
||||
* imond/telmond data processing
|
||||
*
|
||||
* Copyright 2003 Nico Wallmeier <nico.wallmeier@post.rwth-aachen.de>
|
||||
*
|
||||
* 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: plugin_imon.c,v $
|
||||
* Revision 1.2 2004/02/22 17:35:41 reinelt
|
||||
* some fixes for generic graphic driver and T6963
|
||||
* removed ^M from plugin_imon (Nico, are you editing under Windows?)
|
||||
*
|
||||
* Revision 1.1 2004/02/18 14:45:43 nicowallmeier
|
||||
* Imon/Telmon plugin ported
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "plugin.h"
|
||||
#include "cfg.h"
|
||||
#include "hash.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <linux/errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h> /* decl of inet_addr() */
|
||||
#include <sys/socket.h>
|
||||
|
||||
static HASH TELMON = { 0, };
|
||||
static HASH IMON = { 0, };
|
||||
|
||||
static char thost[256];
|
||||
static int tport;
|
||||
static char phoneb[256];
|
||||
|
||||
static char ihost[256];
|
||||
static char ipass[256];
|
||||
static int iport;
|
||||
|
||||
static int fd=0;
|
||||
static int err=0;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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,
|
||||
(char *) &opt, sizeof (opt));
|
||||
|
||||
if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) != 0)
|
||||
{
|
||||
(void) close (fd);
|
||||
perror (host_name);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (fd);
|
||||
} /* service_connect (char * host_name, int port) */
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* send_command (int fd, char * str) - send command to imond
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
send_command (int fd, char * str)
|
||||
{
|
||||
char buf[256];
|
||||
int len = strlen (str);
|
||||
|
||||
sprintf (buf, "%s\r\n", str);
|
||||
write (fd, buf, len + 2);
|
||||
|
||||
return;
|
||||
} /* send_command (int fd, char * str) */
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* get_answer (int fd) - get answer from imond
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
static char *
|
||||
get_answer (int fd)
|
||||
{
|
||||
static char buf[8192];
|
||||
int len;
|
||||
|
||||
len = read (fd, buf, 8192);
|
||||
|
||||
if (len <= 0)
|
||||
{
|
||||
return ((char *) NULL);
|
||||
}
|
||||
|
||||
while (len > 1 && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
|
||||
{
|
||||
buf[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
if (! strncmp (buf, "OK ", 3)) /* OK xxxx */
|
||||
{
|
||||
return (buf + 3);
|
||||
}
|
||||
else if (len > 2 && ! strcmp (buf + len - 2, "OK"))
|
||||
{
|
||||
*(buf + len - 2) = '\0';
|
||||
return (buf);
|
||||
}
|
||||
else if (len == 2 && ! strcmp (buf + len - 2, "OK"))
|
||||
{
|
||||
return (buf);
|
||||
}
|
||||
|
||||
return ((char *) NULL); /* ERR xxxx */
|
||||
} /* get_answer (int fd) */
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* get_value (char * cmd) - send command, get value
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
static char *
|
||||
get_value (char * cmd)
|
||||
{
|
||||
char * answer;
|
||||
|
||||
send_command (fd, cmd);
|
||||
|
||||
answer = get_answer (fd);
|
||||
|
||||
if (answer)
|
||||
{
|
||||
return (answer);
|
||||
}
|
||||
|
||||
return ("");
|
||||
} /* get_value (char * cmd, int arg) */
|
||||
|
||||
static void phonebook(char *number){
|
||||
FILE * fp;
|
||||
char line[256];
|
||||
|
||||
fp = fopen (phoneb, "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);
|
||||
}
|
||||
|
||||
|
||||
static int parse_telmon(){
|
||||
static int telmond_fd=-2;
|
||||
static char oldanswer[128];
|
||||
int age;
|
||||
|
||||
// reread every 1 sec only
|
||||
age=hash_age(&TELMON, NULL, NULL);
|
||||
if (age>0 && age<=1000) return 0;
|
||||
|
||||
if (telmond_fd != -1){
|
||||
char telbuf[128];
|
||||
|
||||
telmond_fd = service_connect (thost, tport);
|
||||
if (telmond_fd >= 0){
|
||||
int l = read (telmond_fd, telbuf, 127);
|
||||
if ((l > 0) && (strcmp(telbuf,oldanswer))){
|
||||
char date[11];
|
||||
char time[11];
|
||||
char number[256];
|
||||
char msn[256];
|
||||
sscanf(telbuf,"%s %s %s %s",date,time,number,msn);
|
||||
hash_set (&TELMON, "time", time);
|
||||
date[4]='\0';
|
||||
date[7]='\0';
|
||||
snprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
|
||||
hash_set (&TELMON, "number", number);
|
||||
hash_set (&TELMON, "msn", msn);
|
||||
hash_set (&TELMON, "date", time);
|
||||
phonebook(number);
|
||||
phonebook(msn);
|
||||
hash_set (&TELMON, "name", number);
|
||||
hash_set (&TELMON, "msnname", msn);
|
||||
}
|
||||
close (telmond_fd);
|
||||
strcpy(oldanswer,telbuf);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void my_telmon (RESULT *result, RESULT *arg1){
|
||||
char *val=NULL;
|
||||
if (parse_telmon()<0) {
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
|
||||
val=hash_get(&TELMON, R2S(arg1));
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
void init(){
|
||||
if (fd!=0) return;
|
||||
|
||||
fd=service_connect(ihost,iport);
|
||||
|
||||
if (fd<0){
|
||||
err++;
|
||||
} else if ((ipass!=NULL) && (*ipass!='\0')) { // Passwort senden
|
||||
char buf[40];
|
||||
snprintf(buf,sizeof(buf),"pass %s",ipass);
|
||||
send_command(fd,buf);
|
||||
get_answer(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static int parse_imon(char *cmd){
|
||||
// reread every half sec only
|
||||
int age=hash_age(&IMON, cmd, NULL);
|
||||
if (age>0 && age<=500) return 0;
|
||||
|
||||
init(); // establish connection
|
||||
|
||||
if (err) return -1;
|
||||
|
||||
hash_set (&IMON, cmd , get_value(cmd));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void my_imon_version (RESULT *result){
|
||||
char *val;
|
||||
// read only ones
|
||||
int age=hash_age(&IMON, "version", NULL);
|
||||
if (age<0){
|
||||
char *s;
|
||||
init();
|
||||
if (err){
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
s=get_value("version");
|
||||
for (;;){ // interne Versionsnummer killen
|
||||
if (s[0]==' '){
|
||||
s=s+1;
|
||||
break;
|
||||
}
|
||||
s=s+1;
|
||||
}
|
||||
hash_set (&IMON, "version", s);
|
||||
}
|
||||
|
||||
val=hash_get(&IMON, "version");
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
static int parse_imon_rates(char *channel){
|
||||
char buf[128],in[25],out[25];
|
||||
char *s;
|
||||
int age;
|
||||
|
||||
snprintf(buf,sizeof(buf),"rate %s in",channel);
|
||||
|
||||
// reread every half sec only
|
||||
age=hash_age(&IMON, buf, NULL);
|
||||
if (age>0 && age<=500) return 0;
|
||||
|
||||
init(); // establish connection
|
||||
|
||||
if (err) return -1;
|
||||
|
||||
snprintf(buf, sizeof(buf), "rate %s", channel);
|
||||
s=get_value(buf);
|
||||
|
||||
if (sscanf(s,"%s %s",in, out)!=2) return -1;
|
||||
|
||||
snprintf(buf, sizeof(buf), "rate %s in", channel);
|
||||
hash_set (&IMON, buf , in);
|
||||
snprintf(buf, sizeof(buf), "rate %s out", channel);
|
||||
hash_set (&IMON, buf , out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void my_imon_rates (RESULT *result, RESULT *arg1, RESULT *arg2){
|
||||
char *val;
|
||||
char buf[128];
|
||||
|
||||
if (parse_imon_rates(R2S(arg1))<0) {
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
|
||||
|
||||
val=hash_get(&IMON, buf);
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
static void my_imon (RESULT *result, RESULT *arg1){
|
||||
char *val=NULL,*cmd=R2S(arg1);
|
||||
|
||||
if (parse_imon(cmd)<0) {
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
|
||||
val=hash_get(&IMON, cmd);
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
int plugin_init_imon (void){
|
||||
char telmon='\1',imon='\1';
|
||||
|
||||
char *s=cfg_get ("Telmon", "Host","127.0.0.1");
|
||||
if (*s=='\0') {
|
||||
error ("[Telmon] no 'Host' entry in %s", cfg_source());
|
||||
telmon='\0';
|
||||
}
|
||||
strcpy(thost,s);
|
||||
|
||||
if ((telmon=='\01') && (cfg_number("Telmon", "Port",5001,1,65536,&tport)<0)){
|
||||
error ("[Telmon] no valid port definition");
|
||||
telmon='\0';
|
||||
}
|
||||
|
||||
s=cfg_get ("Telmon", "Phonebook","/etc/phonebook");
|
||||
strcpy(phoneb,s);
|
||||
|
||||
s=cfg_get ("Imon", "Host", "127.0.0.1");
|
||||
if (*s=='\0') {
|
||||
error ("[Imon] no 'Host' entry in %s", cfg_source());
|
||||
imon='\0';
|
||||
}
|
||||
strcpy(ihost,s);
|
||||
|
||||
if ((imon=='\01') && (cfg_number("Imon", "Port",5000,1,65536,&iport)<0)){
|
||||
error ("[Imon] no valid port definition");
|
||||
imon='\0';
|
||||
}
|
||||
|
||||
s=cfg_get ("Imon", "Pass", "");
|
||||
strcpy(ipass,s);
|
||||
|
||||
if (telmon=='\1') AddFunction ("telmon", 1, my_telmon);
|
||||
if (imon=='\1'){
|
||||
AddFunction ("imon", 1, my_imon);
|
||||
AddFunction ("version", 0, my_imon_version);
|
||||
AddFunction ("rates", 2, my_imon_rates);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "plugin.h"
|
||||
#include "cfg.h"
|
||||
#include "hash.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <linux/errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h> /* decl of inet_addr() */
|
||||
#include <sys/socket.h>
|
||||
|
||||
static HASH TELMON = { 0, };
|
||||
static HASH IMON = { 0, };
|
||||
|
||||
static char thost[256];
|
||||
static int tport;
|
||||
static char phoneb[256];
|
||||
|
||||
static char ihost[256];
|
||||
static char ipass[256];
|
||||
static int iport;
|
||||
|
||||
static int fd=0;
|
||||
static int err=0;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* 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,
|
||||
(char *) &opt, sizeof (opt));
|
||||
|
||||
if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) != 0)
|
||||
{
|
||||
(void) close (fd);
|
||||
perror (host_name);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (fd);
|
||||
} /* service_connect (char * host_name, int port) */
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* send_command (int fd, char * str) - send command to imond
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
static void
|
||||
send_command (int fd, char * str)
|
||||
{
|
||||
char buf[256];
|
||||
int len = strlen (str);
|
||||
|
||||
sprintf (buf, "%s\r\n", str);
|
||||
write (fd, buf, len + 2);
|
||||
|
||||
return;
|
||||
} /* send_command (int fd, char * str) */
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* get_answer (int fd) - get answer from imond
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
static char *
|
||||
get_answer (int fd)
|
||||
{
|
||||
static char buf[8192];
|
||||
int len;
|
||||
|
||||
len = read (fd, buf, 8192);
|
||||
|
||||
if (len <= 0)
|
||||
{
|
||||
return ((char *) NULL);
|
||||
}
|
||||
|
||||
while (len > 1 && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
|
||||
{
|
||||
buf[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
if (! strncmp (buf, "OK ", 3)) /* OK xxxx */
|
||||
{
|
||||
return (buf + 3);
|
||||
}
|
||||
else if (len > 2 && ! strcmp (buf + len - 2, "OK"))
|
||||
{
|
||||
*(buf + len - 2) = '\0';
|
||||
return (buf);
|
||||
}
|
||||
else if (len == 2 && ! strcmp (buf + len - 2, "OK"))
|
||||
{
|
||||
return (buf);
|
||||
}
|
||||
|
||||
return ((char *) NULL); /* ERR xxxx */
|
||||
} /* get_answer (int fd) */
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* get_value (char * cmd) - send command, get value
|
||||
*----------------------------------------------------------------------------
|
||||
*/
|
||||
static char *
|
||||
get_value (char * cmd)
|
||||
{
|
||||
char * answer;
|
||||
|
||||
send_command (fd, cmd);
|
||||
|
||||
answer = get_answer (fd);
|
||||
|
||||
if (answer)
|
||||
{
|
||||
return (answer);
|
||||
}
|
||||
|
||||
return ("");
|
||||
} /* get_value (char * cmd, int arg) */
|
||||
|
||||
static void phonebook(char *number){
|
||||
FILE * fp;
|
||||
char line[256];
|
||||
|
||||
fp = fopen (phoneb, "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);
|
||||
}
|
||||
|
||||
|
||||
static int parse_telmon(){
|
||||
static int telmond_fd=-2;
|
||||
static char oldanswer[128];
|
||||
int age;
|
||||
|
||||
// reread every 1 sec only
|
||||
age=hash_age(&TELMON, NULL, NULL);
|
||||
if (age>0 && age<=1000) return 0;
|
||||
|
||||
if (telmond_fd != -1){
|
||||
char telbuf[128];
|
||||
|
||||
telmond_fd = service_connect (thost, tport);
|
||||
if (telmond_fd >= 0){
|
||||
int l = read (telmond_fd, telbuf, 127);
|
||||
if ((l > 0) && (strcmp(telbuf,oldanswer))){
|
||||
char date[11];
|
||||
char time[11];
|
||||
char number[256];
|
||||
char msn[256];
|
||||
sscanf(telbuf,"%s %s %s %s",date,time,number,msn);
|
||||
hash_set (&TELMON, "time", time);
|
||||
date[4]='\0';
|
||||
date[7]='\0';
|
||||
snprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
|
||||
hash_set (&TELMON, "number", number);
|
||||
hash_set (&TELMON, "msn", msn);
|
||||
hash_set (&TELMON, "date", time);
|
||||
phonebook(number);
|
||||
phonebook(msn);
|
||||
hash_set (&TELMON, "name", number);
|
||||
hash_set (&TELMON, "msnname", msn);
|
||||
}
|
||||
close (telmond_fd);
|
||||
strcpy(oldanswer,telbuf);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void my_telmon (RESULT *result, RESULT *arg1){
|
||||
char *val=NULL;
|
||||
if (parse_telmon()<0) {
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
|
||||
val=hash_get(&TELMON, R2S(arg1));
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
void init(){
|
||||
if (fd!=0) return;
|
||||
|
||||
fd=service_connect(ihost,iport);
|
||||
|
||||
if (fd<0){
|
||||
err++;
|
||||
} else if ((ipass!=NULL) && (*ipass!='\0')) { // Passwort senden
|
||||
char buf[40];
|
||||
snprintf(buf,sizeof(buf),"pass %s",ipass);
|
||||
send_command(fd,buf);
|
||||
get_answer(fd);
|
||||
}
|
||||
}
|
||||
|
||||
static int parse_imon(char *cmd){
|
||||
// reread every half sec only
|
||||
int age=hash_age(&IMON, cmd, NULL);
|
||||
if (age>0 && age<=500) return 0;
|
||||
|
||||
init(); // establish connection
|
||||
|
||||
if (err) return -1;
|
||||
|
||||
hash_set (&IMON, cmd , get_value(cmd));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void my_imon_version (RESULT *result){
|
||||
char *val;
|
||||
// read only ones
|
||||
int age=hash_age(&IMON, "version", NULL);
|
||||
if (age<0){
|
||||
char *s;
|
||||
init();
|
||||
if (err){
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
s=get_value("version");
|
||||
for (;;){ // interne Versionsnummer killen
|
||||
if (s[0]==' '){
|
||||
s=s+1;
|
||||
break;
|
||||
}
|
||||
s=s+1;
|
||||
}
|
||||
hash_set (&IMON, "version", s);
|
||||
}
|
||||
|
||||
val=hash_get(&IMON, "version");
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
static int parse_imon_rates(char *channel){
|
||||
char buf[128],in[25],out[25];
|
||||
char *s;
|
||||
int age;
|
||||
|
||||
snprintf(buf,sizeof(buf),"rate %s in",channel);
|
||||
|
||||
// reread every half sec only
|
||||
age=hash_age(&IMON, buf, NULL);
|
||||
if (age>0 && age<=500) return 0;
|
||||
|
||||
init(); // establish connection
|
||||
|
||||
if (err) return -1;
|
||||
|
||||
snprintf(buf, sizeof(buf), "rate %s", channel);
|
||||
s=get_value(buf);
|
||||
|
||||
if (sscanf(s,"%s %s",in, out)!=2) return -1;
|
||||
|
||||
snprintf(buf, sizeof(buf), "rate %s in", channel);
|
||||
hash_set (&IMON, buf , in);
|
||||
snprintf(buf, sizeof(buf), "rate %s out", channel);
|
||||
hash_set (&IMON, buf , out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void my_imon_rates (RESULT *result, RESULT *arg1, RESULT *arg2){
|
||||
char *val;
|
||||
char buf[128];
|
||||
|
||||
if (parse_imon_rates(R2S(arg1))<0) {
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
|
||||
|
||||
val=hash_get(&IMON, buf);
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
static void my_imon (RESULT *result, RESULT *arg1){
|
||||
char *val=NULL,*cmd=R2S(arg1);
|
||||
|
||||
if (parse_imon(cmd)<0) {
|
||||
SetResult(&result, R_STRING, "");
|
||||
return;
|
||||
}
|
||||
|
||||
val=hash_get(&IMON, cmd);
|
||||
if (val==NULL) val="";
|
||||
SetResult(&result, R_STRING, val);
|
||||
}
|
||||
|
||||
int plugin_init_imon (void){
|
||||
char telmon='\1',imon='\1';
|
||||
|
||||
char *s=cfg_get ("Telmon", "Host","127.0.0.1");
|
||||
if (*s=='\0') {
|
||||
error ("[Telmon] no 'Host' entry in %s", cfg_source());
|
||||
telmon='\0';
|
||||
}
|
||||
strcpy(thost,s);
|
||||
|
||||
if ((telmon=='\01') && (cfg_number("Telmon", "Port",5001,1,65536,&tport)<0)){
|
||||
error ("[Telmon] no valid port definition");
|
||||
telmon='\0';
|
||||
}
|
||||
|
||||
s=cfg_get ("Telmon", "Phonebook","/etc/phonebook");
|
||||
strcpy(phoneb,s);
|
||||
|
||||
s=cfg_get ("Imon", "Host", "127.0.0.1");
|
||||
if (*s=='\0') {
|
||||
error ("[Imon] no 'Host' entry in %s", cfg_source());
|
||||
imon='\0';
|
||||
}
|
||||
strcpy(ihost,s);
|
||||
|
||||
if ((imon=='\01') && (cfg_number("Imon", "Port",5000,1,65536,&iport)<0)){
|
||||
error ("[Imon] no valid port definition");
|
||||
imon='\0';
|
||||
}
|
||||
|
||||
s=cfg_get ("Imon", "Pass", "");
|
||||
strcpy(ipass,s);
|
||||
|
||||
if (telmon=='\1') AddFunction ("telmon", 1, my_telmon);
|
||||
if (imon=='\1'){
|
||||
AddFunction ("imon", 1, my_imon);
|
||||
AddFunction ("version", 0, my_imon_version);
|
||||
AddFunction ("rates", 2, my_imon_rates);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user