[lcd4linux @ 2004-05-25 19:47:11 by reinelt]

Status updated
obsolete files removed

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@433 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
reinelt
2004-05-25 19:47:12 +00:00
parent 9cc7535e56
commit 1c10cacd11
9 changed files with 13 additions and 1670 deletions
-381
View File
@@ -1,381 +0,0 @@
/* $Id: PalmPilot.c,v 1.17 2004/01/30 20:57:55 reinelt Exp $
*
* driver for 3Com Palm Pilot
*
* Copyright 2000 Michael Reinelt <reinelt@eunet.at>
*
* 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: PalmPilot.c,v $
* Revision 1.17 2004/01/30 20:57:55 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
*
* Revision 1.16 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
* Revision 1.15 2004/01/09 04:16:06 reinelt
* added 'section' argument to cfg_get(), but NULLed it on all calls by now.
*
* Revision 1.14 2003/10/05 17:58:50 reinelt
* libtool junk; copyright messages cleaned up
*
* Revision 1.13 2003/09/13 06:45:43 reinelt
* icons for all remaining drivers
*
* Revision 1.12 2003/09/09 06:54:43 reinelt
* new function 'cfg_number()'
*
* Revision 1.11 2003/08/24 05:17:58 reinelt
* liblcd4linux patch from Patrick Schemitz
*
* Revision 1.10 2003/08/17 12:11:58 reinelt
* framework for icons prepared
*
* Revision 1.9 2003/07/24 04:48:09 reinelt
* 'soft clear' needed for virtual rows
*
* Revision 1.8 2003/02/22 07:53:10 reinelt
* cfg_get(key,defval)
*
* Revision 1.7 2002/08/19 04:41:20 reinelt
* introduced bar.c, moved bar stuff from display.h to bar.h
*
* Revision 1.6 2001/04/27 05:04:57 reinelt
*
* replaced OPEN_MAX with sysconf()
* replaced mktemp() with mkstemp()
* unlock serial port if open() fails
*
* Revision 1.5 2001/03/16 16:40:17 ltoetsch
* implemented time bar
*
* Revision 1.4 2001/02/13 09:00:13 reinelt
*
* prepared framework for GPO's (general purpose outputs)
*
* Revision 1.3 2000/08/10 09:44:09 reinelt
*
* new debugging scheme: error(), info(), debug()
* uses syslog if in daemon mode
*
* Revision 1.2 2000/08/09 09:50:29 reinelt
*
* opened 0.98 development
* removed driver-specific signal-handlers
* added 'quit'-function to driver structure
* added global signal-handler
*
* Revision 1.1 2000/05/02 06:05:00 reinelt
*
* driver for 3Com Palm Pilot added
*
*/
/*
*
* exported fuctions:
*
* struct LCD PalmPilot[]
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "debug.h"
#include "cfg.h"
#include "lock.h"
#include "display.h"
#include "bar.h"
#include "icon.h"
#include "pixmap.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
static LCD Lcd;
static char *Port=NULL;
static speed_t Speed;
static int Device=-1;
static int pixel=-1;
static int pgap=0;
static int rgap=0;
static int cgap=0;
static int border=0;
static int icons;
static int Palm_open (void)
{
int fd;
pid_t pid;
struct termios portset;
if ((pid=lock_port(Port))!=0) {
if (pid==-1)
error ("PalmPilot: port %s could not be locked", Port);
else
error ("PalmPilot: port %s is locked by process %d", Port, pid);
return -1;
}
fd = open(Port, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd==-1) {
error ("PalmPilot: open(%s) failed: %s", Port, strerror(errno));
unlock_port(Port);
return -1;
}
if (tcgetattr(fd, &portset)==-1) {
error ("PalmPilot: tcgetattr(%s) failed: %s", Port, strerror(errno));
unlock_port(Port);
return -1;
}
cfmakeraw(&portset);
cfsetospeed(&portset, Speed);
if (tcsetattr(fd, TCSANOW, &portset)==-1) {
error ("PalmPilot: tcsetattr(%s) failed: %s", Port, strerror(errno));
unlock_port(Port);
return -1;
}
return fd;
}
static void Palm_write (char *string, int len)
{
if (Device==-1) return;
if (write (Device, string, len)==-1) {
if (errno==EAGAIN) {
usleep(1000);
if (write (Device, string, len)>=0) return;
}
error ("PalmPilot: write(%s) failed: %s", Port, strerror(errno));
}
}
int Palm_flush (void)
{
static unsigned char *bitbuf=NULL;
static unsigned char *rowbuf=NULL;
int xsize, ysize, row, col;
xsize=2*border+(Lcd.cols-1)*cgap+Lcd.cols*Lcd.xres*pixel+(Lcd.cols*Lcd.xres-1)*pgap;
ysize=2*border+(Lcd.rows-1)*rgap+Lcd.rows*Lcd.yres*pixel+(Lcd.rows*Lcd.yres-1)*pgap;
if (bitbuf==NULL) {
if ((bitbuf=malloc(xsize*ysize*sizeof(*bitbuf)))==NULL) {
error ("PalmPilot: malloc(%d) failed: %s", xsize*ysize*sizeof(*bitbuf), strerror(errno));
return -1;
}
}
if (rowbuf==NULL) {
if ((rowbuf=malloc(((xsize+7)/8)*sizeof(*rowbuf)))==NULL) {
error ("PalmPilot: malloc(%d) failed: %s", ((xsize+7)/8)*sizeof(*rowbuf), strerror(errno));
return -1;
}
}
memset (bitbuf, 0, xsize*ysize*sizeof(*bitbuf));
for (row=0; row<Lcd.rows*Lcd.yres; row++) {
int y=border+(row/Lcd.yres)*rgap+row*(pixel+pgap);
for (col=0; col<Lcd.cols*Lcd.xres; col++) {
int x=border+(col/Lcd.xres)*cgap+col*(pixel+pgap);
int a, b;
for (a=0; a<pixel; a++)
for (b=0; b<pixel; b++)
bitbuf[y*xsize+x+a*xsize+b]=LCDpixmap[row*Lcd.cols*Lcd.xres+col];
}
}
sprintf (rowbuf, "%c%c", xsize, ysize);
Palm_write (rowbuf, 2);
for (row=0; row<ysize; row++) {
memset (rowbuf, 0, (xsize+7)/8);
for (col=0; col<xsize; col++) {
rowbuf[col/8]<<=1;
rowbuf[col/8]|=bitbuf[row*xsize+col];
}
rowbuf[xsize/8]<<=(8-xsize%8)&7;
Palm_write (rowbuf, (xsize+7)/8);
}
return 0;
}
int Palm_clear (int full)
{
if (pix_clear()!=0)
return -1;
if (full)
return Palm_flush();
return 0;
}
int Palm_init (LCD *Self)
{
char *port, *s;
int speed;
int rows=-1, cols=-1;
int xres=1, yres=-1;
if (Port) {
free (Port);
Port=NULL;
}
port=cfg_get (NULL, "Port", NULL);
if (port==NULL || *port=='\0') {
error ("PalmPilot: no 'Port' entry in %s", cfg_source());
return -1;
}
Port=strdup(port);
if (cfg_number(NULL, "Speed", 19200, 1200,19200, &speed)<0) return -1;
switch (speed) {
case 1200:
Speed=B1200;
break;
case 2400:
Speed=B2400;
break;
case 4800:
Speed=B4800;
break;
case 9600:
Speed=B9600;
break;
case 19200:
Speed=B19200;
break;
default:
error ("PalmPilot: unsupported speed '%d' in %s", speed, cfg_source());
return -1;
}
debug ("using port %s at %d baud", Port, speed);
if (sscanf(s=cfg_get(NULL, "size", "20x4"), "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) {
error ("PalmPilot: bad size '%s'", s);
return -1;
}
if (sscanf(s=cfg_get(NULL, "font", "6x8"), "%dx%d", &xres, &yres)!=2 || xres<5 || yres<7) {
error ("PalmPilot: bad font '%s'", s);
return -1;
}
if (sscanf(s=cfg_get(NULL, "pixel", "1+0"), "%d+%d", &pixel, &pgap)!=2 || pixel<1 || pgap<0) {
error ("PalmPilot: bad pixel '%s'", s);
return -1;
}
if (sscanf(s=cfg_get(NULL, "gap", "0x0"), "%dx%d", &cgap, &rgap)!=2 || cgap<-1 || rgap<-1) {
error ("PalmPilot: bad gap '%s'", s);
return -1;
}
if (rgap<0) rgap=pixel+pgap;
if (cgap<0) cgap=pixel+pgap;
if (cfg_number(NULL, "border", 0, 0, 1000000, &border)<0) return -1;
if (pix_init (rows, cols, xres, yres)!=0) {
error ("PalmPilot: pix_init(%d, %d, %d, %d) failed", rows, cols, xres, yres);
return -1;
}
if (cfg_number(NULL, "Icons", 0, 0, 8, &icons) < 0) return -1;
if (icons>0) {
info ("allocating %d icons", icons);
icon_init(rows, cols, xres, yres, 8, icons, pix_icon);
}
Self->rows=rows;
Self->cols=cols;
Self->xres=xres;
Self->yres=yres;
Self->icons=icons;
Lcd=*Self;
// Device=open ("PalmOrb.dat", O_WRONLY | O_CREAT | O_TRUNC, 0644);
Device=Palm_open();
if (Device==-1) return -1;
pix_clear();
return 0;
}
int Palm_put (int row, int col, char *text)
{
return pix_put (row, col, text);
}
int Palm_bar (int type, int row, int col, int max, int len1, int len2)
{
return pix_bar (type, row, col, max, len1, len2);
}
int Palm_icon (int num, int seq, int row, int col)
{
return icon_draw (num, seq, row, col);
}
int Palm_quit (void)
{
debug ("closing port %s", Port);
close (Device);
unlock_port (Port);
return 0;
}
LCD PalmPilot[] = {
{ name: "PalmPilot",
rows: 0,
cols: 0,
xres: 0,
yres: 0,
bars: BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 | BAR_V2 | BAR_T,
icons: 0,
gpos: 0,
init: Palm_init,
clear: Palm_clear,
put: Palm_put,
bar: Palm_bar,
icon: Palm_icon,
gpo: NULL,
flush: Palm_flush,
quit: Palm_quit },
{ NULL }
};
+13 -9
View File
@@ -6,21 +6,24 @@ Lcd4Linux NextGeneration porting status
Cwlinux -> Ported (Text,Bar,Icon) + blacklight [gpo,gpi,inverted text,relay]
HD44780 -> Ported (Text,Bar,Icon) + soft brightness,'busy flag',gpo [soft contrast]
M50530 -> Ported (Text,Bar,Icon) + gpo
MatrixOrbital -> Ported (Text,Bar,Icon) + blacklight,contrast,gpo,pwm,rpm [?]
T6963* -> Ported (Text,Bar,Icon) [?]
USBLCD -> Ported (Text,Bar,Icon) [?]
MatrixOrbital -> Ported (Text,Bar,Icon) + blacklight,contrast,gpo,pwm,rpm
T6963* -> Ported (Text,Bar,Icon)
USBLCD -> Ported (Text,Bar,Icon)
XWindow* -> Ported (Text,Bar,Icon) [gnome applet ?]
Raster* -> Ported (Text,Bar,Icon)
BeckmannEgle ->
Curses ->
MilfordInstruments ->
PalmPilot ->
Raster* ->
SIN* ->
PalmPilot -> Obsolete
SIN -> Obsolete
* graphic displays
PLUGINS : format : status (functions) {old tokens} [todo]
------------------------------------------------------------
plugin_apm -> Finished (apm) {battery: bd bp bs}
@@ -39,12 +42,13 @@ Lcd4Linux NextGeneration porting status
plugin_uname -> Finished (uname) {o v}
plugin_wireless -> Finished (level, noise, quality, ...) {ws wl wn}
plugin_xmms -> Finished (xmms) NEW
plugin_isdn -> Finished (info, cps) {ic ii im io it}
plugin_uptime -> Finished (uptime) NEW
plugin_time -> Finished (time strftime) NEW
plugin_pop3 -> Finished (POP3check) {e* u*}
(special plugins : plugin_cfg, plugin_math, plugin_string)
tokens not ported :
mail {e* u*}
ISDN {ic ii im io it}
TODO : task {assigned to}
--------
-228
View File
@@ -1,228 +0,0 @@
/* $Id: mail.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $
*
* email specific functions
*
* Copyright 2001 Axel Ehnert <axel@ehnert.net>
*
* 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: mail.c,v $
* Revision 1.16 2004/03/03 03:47:04 reinelt
* big patch from Martin Hejl:
* - use qprintf() where appropriate
* - save CPU cycles on gettimeofday()
* - add quit() functions to free allocated memory
* - fixed lots of memory leaks
*
* Revision 1.15 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
* Revision 1.14 2004/01/09 04:16:06 reinelt
* added 'section' argument to cfg_get(), but NULLed it on all calls by now.
*
* Revision 1.13 2003/10/05 17:58:50 reinelt
* libtool junk; copyright messages cleaned up
*
* Revision 1.12 2003/02/22 07:53:10 reinelt
* cfg_get(key,defval)
*
* Revision 1.11 2001/09/12 05:58:16 reinelt
* fixed bug in mail2.c
*
* Revision 1.10 2001/09/12 05:37:22 reinelt
*
* fixed a bug in seti.c (file was never closed, lcd4linux run out of fd's
*
* improved socket debugging
*
* Revision 1.9 2001/08/05 17:13:29 reinelt
*
* cleaned up inlude of sys/time.h and time.h
*
* Revision 1.8 2001/03/15 15:49:23 ltoetsch
* fixed compile HD44780.c, cosmetics
*
* Revision 1.7 2001/03/15 14:25:05 ltoetsch
* added unread/total news
*
* Revision 1.6 2001/03/14 13:19:29 ltoetsch
* Added pop3/imap4 mail support
*
* Revision 1.5 2001/03/13 08:34:15 reinelt
*
* corrected a off-by-one bug with sensors
*
* Revision 1.4 2001/03/08 09:02:04 reinelt
*
* seti client cleanup
*
* Revision 1.3 2001/02/21 04:48:13 reinelt
*
* big mailbox patch from Axel Ehnert
* thanks to herp for his idea to check mtime of mailbox
*
* Revision 1.2 2001/02/19 00:15:46 reinelt
*
* integrated mail and seti client
* major rewrite of parser and tokenizer to support double-byte tokens
*
* Revision 1.1 2001/02/18 22:11:34 reinelt
* *** empty log message ***
*
*/
/*
* exported functions:
*
* Mail (int index, int *num)
* returns 0 if ok, -1 if error
* sets num to number of emails in mailbox #index
*
*/
#define FALSE 0
#define TRUE 1
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "cfg.h"
#include "debug.h"
#include "mail.h"
int Mail (int index, int *num, int *unseen)
{
FILE *fstr;
char buffer[32];
static int cfgmbx[MAILBOXES+1]={[0 ... MAILBOXES]=TRUE,}; // Mailbox #index configured?
static time_t mbxlt[MAILBOXES+1]={[0 ... MAILBOXES]=0,}; // mtime of Mailbox #index
static int mbxnum[MAILBOXES+1]={[0 ... MAILBOXES]=0,}; // Last calculated # of mails
static time_t now[MAILBOXES+1]={[0 ... MAILBOXES]=0,}; // Last call to procedure at
// for Mailbox #index
char *fnp1;
int v1=0;
int last_line_blank1; // Was the last line blank?
struct stat fst;
int rc;
char *s:
int i;
char *txt;
char txt1[100];
if (index<0 || index>MAILBOXES) return -1;
if (now[index] == 0) { /* first time, to give faster a chance */
now[index] = -1-index;
return 0;
}
if (now[index] < -1) { /* wait different time to avoid long startup */
now[index]++;
return 0;
}
if (now[index] > 0) { /* not first time, delay */
sprintf(txt1, "Delay_e%d", index);
s= cfg_get(NULL, txt1, "5");
i=now[index]+atoi(s);
free(s);
if (time(NULL)<=i)
return 0; // no more then 5/Delay_eX seconds after last check?
}
time(&now[index]); // for Mailbox #index
/*
Build the filename from the config
*/
qprintf(buffer, sizeof(buffer), "Mailbox%d", index);
fnp1=cfg_get(NULL, buffer, NULL);
if (fnp1==NULL || *fnp1=='\0') {
cfgmbx[index]=FALSE; // There is now entry for Mailbox #index
}
v1=mbxnum[index];
/*
Open the file
*/
if (cfgmbx[index]==TRUE) {
/*
Check the last touch of mailbox. Changed?
*/
rc=stat(fnp1, &fst);
if ( rc != 0 ) {
/*
is it pop3, imap4 or nntp?
*/
rc = Mail_pop_imap_news(fnp1, num, unseen);
if (rc == 0) {
free(fnp1);
return 0;
}
else
cfgmbx[index] = FALSE; /* don't try again */
error ("Error getting stat of Mailbox%d", index);
return (-1);
}
if ( mbxlt[index] != fst.st_mtime ) {
mbxlt[index]=fst.st_mtime;
fstr=fopen(fnp1,"r");
if (fstr != NULL) {
txt=&txt1[0];
last_line_blank1=TRUE;
v1=0;
while ( ( fgets ( txt1, 100, fstr ) ) != NULL ) {
txt1[strlen(txt1)-1]='\0'; // cut the newline
/*
Is there a "From ..." line. Count only, if a blank line was directly before this
*/
if ( strncmp (txt1, "From ", 5 ) == 0 ) {
if ( last_line_blank1 == TRUE ) {
v1++;
last_line_blank1 = FALSE;
}
}
if ( strlen (txt1) == 0 ) {
last_line_blank1 = TRUE;
}
else {
last_line_blank1 = FALSE;
}
}
fclose (fstr);
}
}
}
free(fnp1);
/* FIXME look at the Status of Mails */
*unseen = v1 - mbxnum[index];
if (*unseen < 0)
*unseen = 0;
mbxnum[index]=v1;
*num=v1;
return (0);
}
-50
View File
@@ -1,50 +0,0 @@
/* $Id: mail.h,v 1.5 2003/10/05 17:58:50 reinelt Exp $
*
* email specific functions
*
* Copyright 2001 Axel Ehnert <axel@ehnert.net>
*
* 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: mail.h,v $
* Revision 1.5 2003/10/05 17:58:50 reinelt
* libtool junk; copyright messages cleaned up
*
* Revision 1.4 2001/03/15 14:25:05 ltoetsch
* added unread/total news
*
* Revision 1.3 2001/03/14 13:19:29 ltoetsch
* Added pop3/imap4 mail support
*
* Revision 1.2 2001/03/08 09:02:04 reinelt
*
* seti client cleanup
*
* Revision 1.1 2001/02/18 22:11:34 reinelt
* *** empty log message ***
*
*/
#ifndef _MAIL_H
#define _MAIL_H_
#define MAILBOXES 9
int Mail (int index, int *num, int *unseen);
int Mail_pop_imap_news(char *mbx, int *num, int *unseen); /* mail2.c */
#endif
-537
View File
@@ -1,537 +0,0 @@
/* $Id: mail2.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
*
* mail: pop3, imap, news functions
*
* Copyright 2001 Leopold Tötsch <lt@toetsch.at>
*
* 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: mail2.c,v $
* Revision 1.13 2004/03/03 03:47:04 reinelt
* big patch from Martin Hejl:
* - use qprintf() where appropriate
* - save CPU cycles on gettimeofday()
* - add quit() functions to free allocated memory
* - fixed lots of memory leaks
*
* Revision 1.12 2004/01/30 20:57:56 reinelt
* HD44780 patch from Martin Hejl
* dmalloc integrated
*
* Revision 1.11 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
* Revision 1.10 2004/01/09 04:16:06 reinelt
* added 'section' argument to cfg_get(), but NULLed it on all calls by now.
*
* Revision 1.9 2003/10/05 17:58:50 reinelt
* libtool junk; copyright messages cleaned up
*
* Revision 1.8 2003/02/22 07:53:10 reinelt
* cfg_get(key,defval)
*
* Revision 1.7 2002/12/05 19:23:01 reinelt
* fixed undefined operations found by gcc3
*
* Revision 1.6 2001/09/12 06:17:22 reinelt
* *** empty log message ***
*
* Revision 1.5 2001/09/12 05:58:16 reinelt
* fixed bug in mail2.c
*
* Revision 1.4 2001/03/16 09:28:08 ltoetsch
* bugfixes
*
* Revision 1.3 2001/03/15 14:25:05 ltoetsch
* added unread/total news
*
* Revision 1.2 2001/03/15 11:10:53 ltoetsch
* added quit/logout to pop/imap
*
* Revision 1.1 2001/03/14 13:19:29 ltoetsch
* Added pop3/imap4 mail support
*
*
* Exported Functions:
*
* int Mail_pop_imap_news(char *mbox, int *total_mails, int *unseen);
* returns -1 on error, 0 on success
*
*/
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <malloc.h>
#include <errno.h>
#include "debug.h"
#include "cfg.h"
#include "socket.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
#define PROTO_UNKNOWN -1
#define PROTO_POP3 110
#define PROTO_NNTP 119
#define PROTO_IMAP4 143
/*
* parse_proto()
*
* parse a MailboxN entry in 's' as
*
* proto:[user[:pass]@]machine[:port][/dir]
*
* 's' get's destroyed
* returns 0 on success, -1 on error
*
*/
static int parse_proto(char *s, int *proto, char **user, char **pass,
char **machine, int *port, char **dir)
{
struct
{
char *prefix;
int proto;
}
protos[] =
{
{ "pop3:", PROTO_POP3 },
{ "nntp:", PROTO_NNTP },
{ "imap4:", PROTO_IMAP4 },
};
int i;
char *p, *q;
static char empty[] = "";
static char INBOX[] = "INBOX";
*proto = *port = PROTO_UNKNOWN;
for (i=0; i< sizeof(protos)/sizeof(protos[0]); i++)
{
if (memcmp(s, protos[i].prefix, strlen(protos[i].prefix)) == 0)
{
*proto = *port = protos[i].proto;
break;
}
}
if (*proto == PROTO_UNKNOWN)
return -1;
p = s + strlen(protos[i].prefix);
/*
* this might fail if user or pass contains a '/'
*
*/
if ((q = strchr(p, '/')) != NULL)
{
/* /dir */
*dir = q + 1;
*q = '\0';
}
else
*dir = empty;
if ((q = strchr(p, '@')) != NULL)
{
/* user, pass is present */
*machine = q + 1;
*q = '\0';
*user = p;
if ((q = strchr(p, ':')) != NULL)
{
/* user[:pass] */
*q = '\0';
*pass = q+1;
}
else
*pass = empty;
}
else
{
*machine = p;
*user = *pass = empty;
}
if ((q = strchr(*machine, ':')) != NULL)
{
/* machine[:pass] */
*q = '\0';
*port = atoi(q+1);
if (*port <= 0 || *port >= 0xffff)
return -1;
}
if (!**machine)
return -1;
if (*proto == PROTO_POP3 && **dir)
return -1;
if (*proto == PROTO_IMAP4 && !**dir)
*dir = INBOX;
return 0;
}
/* write buffer, compare with match */
#define BUFLEN 256
static int wr_rd(int fd, char *buf, char *match,
char *err, char *machine, int port)
{
int n;
n = write_socket(fd, buf);
if (n <= 0)
{
error("Couldn't write to %s:%d (%s)", machine, port, strerror(errno));
close(fd);
return -1;
}
n = read_socket_match(fd, buf, BUFLEN-1, match);
if (n <= 0)
{
error("%s %s:%d (%s)", err, machine, port, strerror(errno));
close(fd);
return -1;
}
return n;
}
static int check_nntp(char *user, char *pass, char *machine,
int port, char *dir, int *total, int *unseen)
{
int fd;
int n;
char buf[BUFLEN];
char line[BUFLEN];
FILE *fp;
int groups;
int err;
int totg, unsg;
int first;
char *s;
*total = 0;
*unseen = 0;
strcpy(buf, (s=cfg_get(NULL, "Newsrc", ".newsrc")));
if (*buf == 0 || ((fp = fopen(buf, "r")) == NULL)) {
error("Couldn't open .newsrc-file '%s'", buf);
free(s);
return -1;
}
free(s);
fd = open_socket(machine, port);
if (fd < 0)
{
error("Couldn't connect to %s:%d (%s)", machine, port, strerror(errno));
fclose(fp);
return -1;
}
n = read_socket_match(fd, buf, BUFLEN-1, "20"); /* server ready */
if (n <= 0) {
error("Server doesn't respond %s:%d (%s)", machine, port, strerror(errno));
close(fd);
return -1;
}
/* do auth if necessary, this is NOT TESTED */
if (*user) {
sprintf(buf, "AUTHINFO USER %s\r\n", user);
if (wr_rd(fd, buf, "381", "No AUTH required?", machine, port) <= 0)
return -1;
if (*pass)
{
sprintf(buf, "AUTHINFO PASS %s\r\n", pass);
if (wr_rd(fd, buf, "281", "Wrong PASS?", machine, port) <= 0)
return -1;
}
}
// Fixme: this is badbadbadbad
sleep(2); /* wait for newsserver to read groupinfo */
groups = 0;
err = 0;
totg = unsg = 0; /* total, unseen */
while (fgets(line, sizeof(line)-1, fp) && err < 5) {
char group[256];
char *p;
int smin, smax, lmin, lmax;
if (sscanf(line, "%255[^:]:", group) != 1) {
error("Couldn't read group in '%s'", line);
err++;
continue;
}
if ((p=strchr(group,':')) != NULL)
*p='\0';
/* check dir if it matches group */
if (*dir && strcmp(dir, group))
continue;
sprintf(buf, "GROUP %s\r\n", group);
if (wr_rd(fd, buf, "211", "Wrong Group", machine, port) <= 0) {
err++;
continue;
}
/* answer 211 total smin smax group: */
sscanf(buf, "211 %*d %d %d", &smin, &smax);
debug("nntp: %s: smin=%d smax=%d", group, smin, smax);
totg += smax-smin-1;
p = strchr(line, ':');
p++;
first = 1;
while (1) {
lmin = strtol(p, &p, 10);
if (*p == '-')
lmax = strtol(p+1, &p, 10);
else
lmax=lmin;
debug("nntp: %s: lmin=%d lmax=%d", group, lmin, lmax);
if (smax >= lmax) { /* server has more articles */
if (first)
unsg += smax - lmax;
else
unsg -= lmax-lmin+1;
first = 0;
}
else /* local has higher article ??? */
break;
if (*p == ',')
p++;
else
break;
}
} /* while fp */
fclose(fp);
strcpy(buf, "QUIT\r\n");
wr_rd(fd, buf, "2", "Quit", machine, port);
close(fd);
*unseen = unsg;
*total = totg;
return 0;
}
static int check_imap4(char *user, char *pass, char *machine,
int port, char *dir, int *total, int *unseen)
{
int fd = open_socket(machine, port);
int n;
char buf[BUFLEN];
char *p;
*total=0;
*unseen = 0;
if (fd < 0)
{
error("Couldn't connect to %s:%d (%s)", machine, port, strerror(errno));
return -1;
}
n = read_socket_match(fd, buf, BUFLEN-1, "* OK");
if (n <= 0) {
error("Server doesn't respond %s:%d (%s)", machine, port, strerror(errno));
close(fd);
return -1;
}
sprintf(buf, ". LOGIN %s %s\r\n", user, pass);
if (wr_rd(fd, buf, ". OK", "Wrong User/PASS?", machine, port) <= 0)
return -1;
sprintf(buf, ". STATUS %s (MESSAGES UNSEEN)\r\n", dir);
if (wr_rd(fd, buf, "*", "Wrong dir?", machine, port) <= 0)
return -1;
if ((p = strstr(buf, "MESSAGES")) != NULL)
sscanf(p, "%*s %d", total);
else {
error("Server doesn't provide MESSAGES (%s)", machine, port, strerror(errno));
close(fd);
return -1;
}
if ((p = strstr(buf, "UNSEEN")) != NULL)
sscanf(p, "%*s %d", unseen);
else {
error("Server doesn't provide UNSEEN (%s)", machine, port, strerror(errno));
close(fd);
return -1;
}
strcpy(buf,". LOGOUT\r\n");
wr_rd(fd, buf, "", "LOGOUT", machine, port);
close(fd);
return 0;
}
static int check_pop3(char *user, char *pass, char *machine,
int port, int *total, int *unseen)
{
int fd = open_socket(machine, port);
int n;
char buf[BUFLEN];
*total=0;
*unseen=0;
if (fd < 0)
{
error("Couldn't connect to %s:%d (%s)", machine, port, strerror(errno));
return -1;
}
n = read_socket_match(fd, buf, BUFLEN-1, "+OK");
if (n <= 0) {
error("Server doesn't respond %s:%d (%s)", machine, port, strerror(errno));
close(fd);
return -1;
}
if (*user)
{
sprintf(buf, "USER %s\r\n", user);
if (wr_rd(fd, buf, "+OK", "Wrong USER?", machine, port) <= 0)
return -1;
}
if (*pass)
{
sprintf(buf, "PASS %s\r\n", pass);
if (wr_rd(fd, buf, "+OK", "Wrong PASS?", machine, port) <= 0)
return -1;
}
sprintf(buf, "STAT\r\n");
if (wr_rd(fd, buf, "+OK", "Wrong STAT answer?", machine, port) <= 0)
return -1;
sscanf(buf, "+OK %d", total);
if (*total) {
sprintf(buf, "LAST\r\n");
if (wr_rd(fd, buf, "+OK", "Wrong LAST answer?", machine, port) <= 0)
return -1;
sscanf(buf, "+OK %d", unseen);
*unseen = *total - *unseen;
}
strcpy(buf, "QUIT\r\n");
wr_rd(fd, buf, "+OK", "Quit", machine, port);
close(fd);
return 0;
}
int Mail_pop_imap_news(char *s, int *total, int *unseen)
{
int proto, port, ret;
char *user, *pass, *machine, *dir, *ds;
ds = strdup(s);
if (ds == NULL)
{
error("Out of mem");
return -1;
}
ret = parse_proto(ds, &proto, &user, &pass,
&machine, &port, &dir) ;
if (ret < 0)
error("Not a pop3/imap4 mailbox");
else
ret = (proto == PROTO_POP3) ?
check_pop3(user, pass, machine, port, total, unseen) :
(proto == PROTO_NNTP) ?
check_nntp(user, pass, machine, port, dir, total, unseen) :
check_imap4(user, pass, machine, port, dir, total, unseen);
free(ds);
return ret;
}
#ifdef STANDALONE
/*
* test parse_proto with some garbage
*
*/
int foreground = 1;
int debugging = 3;
/*
* for STANDALONE tests, disable Text driver and
*
* cc -DSTANDALONE mail2.c socket.c debug.c -g -Wall -o mail2
*
*/
#ifdef CHECK_PARSER
static int test(char *s)
{
int ret;
int proto, port;
char *user, *pass, *machine, *dir, *ds;
ds = strdup(s);
ret = parse_proto(ds, &proto, &user, &pass,
&machine, &port, &dir) ;
printf("parse_proto(%s) ret=%d\n", s, ret);
if (!ret)
printf(
"\tproto='%d'\n"
"\tuser='%s'\n"
"\tpass='%s'\n"
"\tmachine='%s'\n"
"\tport='%d'\n"
"\tdir='%s'\n",
proto,user,pass,machine,port,dir);
free(ds);
return ret;
}
#endif
int main(int argc, char *argv[])
{
#ifdef CHECK_PARSER
int i, ret;
/* proto:[user[:pass]@]machine[:port][/dir] */
char *t[] =
{
"pop3:sepp:Geheim@Rechner:123",
"pop3:sepp@Rechner",
"pop3:Rechner:123",
"imap4:sepp:Geheim@Rechner/dir@/:pfad",
"imap4:sepp:Geheim@Rechner",
"imap4sepp:Geheim@Rechner/dir@/:pfad",
"imap4:sepp:Geheim/Rechner/dir@/:pfad",
"pop3:sepp@:",
0
};
ret = 0;
if (argc > 1)
ret |= test(argv[1]);
else
for (i = 0; t[i]; i++)
ret |= test(t[i]);
return ret;
# else
int total = -1, unseen = -1;
char *mbx = "imap4:user:pass@server/folder/file";
int ret = Mail_pop_imap(mbx, &total, &unseen);
printf("ret = %d, total = %d unseen = %d\n", ret, total, unseen);
return ret;
# endif
}
#endif
-228
View File
@@ -1,228 +0,0 @@
/* $Id: socket.c,v 1.7 2004/01/29 04:40:03 reinelt Exp $
*
* simple socket functions
*
* Copyright 2001 Leopold Tötsch <lt@toetsch.at>
*
* 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: socket.c,v $
* Revision 1.7 2004/01/29 04:40:03 reinelt
* every .c file includes "config.h" now
*
* Revision 1.6 2003/10/05 17:58:50 reinelt
* libtool junk; copyright messages cleaned up
*
* Revision 1.5 2002/12/05 19:09:57 reinelt
* patches for gcc-3.2
*
* Revision 1.4 2001/09/12 05:58:16 reinelt
* fixed bug in mail2.c
*
* Revision 1.3 2001/09/12 05:37:22 reinelt
*
* fixed a bug in seti.c (file was never closed, lcd4linux run out of fd's
*
* improved socket debugging
*
* Revision 1.2 2001/03/15 14:25:05 ltoetsch
* added unread/total news
*
* Revision 1.1 2001/03/14 13:19:29 ltoetsch
* Added pop3/imap4 mail support
*
*
*/
/*
* Exported Functions:
*
* int open_socket(char *machine, int port);
*
* open and connect to socket on machine:port
* returns fd on success or -1 on error
*
*
* int read_socket(int fd, char *buf, size_t size);
*
* read maximum size chars into buf
* returns n byte read, 0 on timeout, -1 on error
*
*
* int read_socket_match(int fd, char *buf, size_t size, char *match);
*
* read maximum size chars into buf and check if the start of line
* matches 'match'
* returns n on successful match, 0 on timeout/mismatch, -1 on error
*
*
* int write_socket(int fd, char *string);
*
* write string to socket fd
* returns n byte written, -1 on error
*
* with debuglevel 3, traffic on socket is logged
*
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "debug.h"
#define TIMEOUT 5 /* 5 seconds timeout */
static char *quotemeta (char *string)
{
static char buffer[256];
char *s, *p;
p=buffer;
for (s=string; *s; s++) {
if (isprint(*s)) {
*p++=*s;
} else {
switch (*s) {
case '\r':
*p++='\\';
*p++='r';
break;
case '\n':
*p++='\\';
*p++='n';
break;
default:
p+=sprintf(p, "<\\%03o>", (int)*s);
}
}
if ((p-buffer)>240) {
*p++='.';
*p++='.';
*p++='.';
break;
}
}
*p='\0';
return buffer;
}
static char *del_pass(char *s)
{
char *p;
/* del pop3 pass from log */
if (memcmp(s, "PASS ", 5) == 0)
for (p = s+5; *p && *p != '\r'; p++)
*p = '*';
/* del imap4 pass from log */
else if (memcmp(s, ". LOGIN", 7) == 0)
for (p = s + strlen(s)-3 ; p > s && *p != ' '; p--)
*p = '*';
return s;
}
static void sockdebug (char dir, int len, char *string) {
// delete passwords from log
if (dir=='>') {
del_pass (string);
}
message (3, "%c[%2d] %s", dir, len, quotemeta(string));
}
int open_socket(char *machine, int port)
{
struct hostent *addr;
struct sockaddr_in s;
int fd;
addr = gethostbyname (machine);
if (addr)
memcpy (&s.sin_addr, addr->h_addr, sizeof (struct in_addr));
else
return -1;
fd = socket (AF_INET, SOCK_STREAM, 0);
if (fd < 0)
return -1;
s.sin_family = AF_INET;
s.sin_port = htons (port);
if (connect (fd, (struct sockaddr *)&s, sizeof (s)) < 0)
return -1;
return fd;
}
int read_socket(int fd, char *buf, size_t size)
{
fd_set readfds;
struct timeval tv;
int n;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
tv.tv_sec = TIMEOUT;
tv.tv_usec = 0;
if (select(fd+1, &readfds, NULL, NULL, &tv) > 0)
n = read(fd, buf, size);
else
n = 0;
if (n >= 0)
buf[n] = '\0';
else
buf[0] = '\0';
sockdebug('<', n, buf);
return n;
}
int read_socket_match(int fd, char *buf, size_t size, char *match)
{
int n = read_socket(fd, buf, size);
int len;
if (n <= 0)
return n;
len = strlen(match);
if (n >= len && memcmp(buf, match, len) == 0)
return n;
return 0;
}
int write_socket(int fd, char *buf)
{
int n = write(fd, buf, strlen(buf));
sockdebug('>', n, del_pass(buf));
return n;
}
-45
View File
@@ -1,45 +0,0 @@
/* $Id: socket.h,v 1.2 2003/10/05 17:58:50 reinelt Exp $
*
* simple socket functions
*
* Copyright 2001 Leopold Tötsch <lt@toetsch.at>
*
* 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: socket.h,v $
* Revision 1.2 2003/10/05 17:58:50 reinelt
* libtool junk; copyright messages cleaned up
*
* Revision 1.1 2001/03/14 13:19:29 ltoetsch
* Added pop3/imap4 mail support
*
*
*/
#ifndef __SOCKET_H_
#define __SOCKET_H_
int open_socket(char *machine, int port);
int read_socket(int fd, char *buf, size_t size);
int read_socket_match(int fd, char *buf, size_t size, char *match);
int write_socket(int fd, char *buf);
#endif
-151
View File
@@ -1,151 +0,0 @@
/* $Id: wifi.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
*
* WIFI specific functions
*
* Copyright 2003 Xavier Vello <xavier66@free.fr>
*
* based on lcd4linux/isdn.c which is
* Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at>
*
* 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: wifi.c,v $
* Revision 1.7 2004/03/03 03:47:04 reinelt
* big patch from Martin Hejl:
* - use qprintf() where appropriate
* - save CPU cycles on gettimeofday()
* - add quit() functions to free allocated memory
* - fixed lots of memory leaks
*
* Revision 1.6 2004/01/29 04:40:03 reinelt
* every .c file includes "config.h" now
*
* Revision 1.5 2004/01/09 04:16:06 reinelt
* added 'section' argument to cfg_get(), but NULLed it on all calls by now.
*
* Revision 1.4 2004/01/06 22:33:14 reinelt
* Copyright statements cleaned up
*
* Revision 1.3 2003/12/01 07:08:51 reinelt
*
* Patches from Xavier:
* - WiFi: make interface configurable
* - "quiet" as an option from the config file
* - ignore missing "MemShared" on Linux 2.6
*
* Revision 1.2 2003/11/28 18:34:55 nicowallmeier
* Minor bugfixes
*
* Revision 1.1 2003/11/14 05:59:37 reinelt
* added wifi.c wifi.h which have been forgotten at the last checkin
*
*/
/*
* exported functions:
*
* Wifi (int *signal, int *link, int *noise)
* returns 0 if ok, -1 if error
* sets *signal to signal level (which determines the rate)
* sets *link to link quality
* sets *noise to noise level (reverse of link quality)
*
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include "debug.h"
#include "wifi.h"
#include "filter.h"
#include "cfg.h"
int Wifi (int *signal, int *link, int *noise)
{
int ws, wl, wn;
static int fd=-2;
char buffer[4096];
char *p;
char *interface=cfg_get(NULL, "Wifi.Interface", "wlan0");
*signal=0;
*link=0;
*noise=0;
if (fd==-1) return -1;
if (fd==-2) {
fd = open("/proc/net/wireless", O_RDONLY); // the real procfs file
//fd = open("/wireless", O_RDONLY); // a fake file for testing
if (fd==-1) {
error ("open(/proc/net/wireless) failed: %s", strerror(errno));
return -1;
}
debug ("open(/proc/net/wireless)=%d", fd);
}
if (lseek(fd, 0L, SEEK_SET)!=0) {
error ("lseek(/proc/net/wireless) failed: %s", strerror(errno));
fd=-1;
return -1;
}
if (read (fd, &buffer, sizeof(buffer)-1)==-1) {
error("read(/proc/net/wireless) failed: %s", strerror(errno));
fd=-1;
return -1;
}
p=strstr(buffer, interface);
if (p!=NULL) {
// TODO : size of interface ??
if (sscanf(p+13, "%d", &wl)!=1) {
error ("parse(/proc/net/wireless) failed: unknown format");
fd=-1;
return -1;
}
if (sscanf(p+19, "%d", &ws)!=1) {
error ("parse(/proc/net/wireless) failed: unknown format");
fd=-1;
return -1;
}
if (sscanf(p+25, "%d", &wn)!=1) {
error ("parse(/proc/net/wireless) failed: unknown format");
fd=-1;
return -1;
}
} else {
error("read(/proc/net/wireless) failed: %s", strerror(errno));
fd=-1;
return -1;
}
*signal=ws;
*link=wl;
*noise=wn;
free(interface);
return 0;
}
-41
View File
@@ -1,41 +0,0 @@
/* $Id: wifi.h,v 1.2 2004/01/06 22:33:14 reinelt Exp $
*
* WIFI specific functions
*
* Copyright 2003 Xavier Vello <xavier66@free.fr>
*
* based on lcd4linux/isdn.c which is
* Copyright 1999, 2000 Michael Reinelt <reinelt@eunet.at>
*
* 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: wifi.h,v $
* Revision 1.2 2004/01/06 22:33:14 reinelt
* Copyright statements cleaned up
*
* Revision 1.1 2003/11/14 05:59:37 reinelt
* added wifi.c wifi.h which have been forgotten at the last checkin
*
*/
#ifndef _WIFI_H_
#define _WIFI_H_
int Wifi (int *signal, int *link, int *noise);
#endif