aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2001-09-12 05:37:22 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2001-09-12 05:37:22 +0000
commit4340dc126ba0920dc93c0e74d48cfee769547399 (patch)
treedfa02a8502b1be3dd801d0a2a1e872dfea99baac
parent9e49a79d95a7c61099ab86b6106d98a77b66a79e (diff)
downloadlcd4linux-4340dc126ba0920dc93c0e74d48cfee769547399.tar.gz
[lcd4linux @ 2001-09-12 05:37:22 by reinelt]
fixed a bug in seti.c (file was never closed, lcd4linux run out of fd's improved socket debugging git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@147 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to '')
-rw-r--r--debug.h9
-rw-r--r--mail.c9
-rw-r--r--seti.c11
-rw-r--r--socket.c93
4 files changed, 99 insertions, 23 deletions
diff --git a/debug.h b/debug.h
index 6db001b..9bc452f 100644
--- a/debug.h
+++ b/debug.h
@@ -1,4 +1,4 @@
-/* $Id: debug.h,v 1.3 2001/03/14 13:19:29 ltoetsch Exp $
+/* $Id: debug.h,v 1.4 2001/09/12 05:37:22 reinelt Exp $
*
* debug messages
*
@@ -20,6 +20,12 @@
*
*
* $Log: debug.h,v $
+ * Revision 1.4 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.3 2001/03/14 13:19:29 ltoetsch
* Added pop3/imap4 mail support
*
@@ -42,7 +48,6 @@
void message (int level, const char *format, ...);
-#define sockdebug(args...) message (3, args)
#define debug(args...) message (2, __FILE__ ": " args)
#define info(args...) message (1, args)
#define error(args...) message (0, args)
diff --git a/mail.c b/mail.c
index 4077c00..3e90e3c 100644
--- a/mail.c
+++ b/mail.c
@@ -1,4 +1,4 @@
-/* $Id: mail.c,v 1.9 2001/08/05 17:13:29 reinelt Exp $
+/* $Id: mail.c,v 1.10 2001/09/12 05:37:22 reinelt Exp $
*
* email specific functions
*
@@ -20,6 +20,12 @@
*
*
* $Log: mail.c,v $
+ * 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
@@ -163,7 +169,6 @@ int Mail (int index, int *num, int *unseen)
if ( strncmp (txt1, "From ", 5 ) == 0 ) {
if ( last_line_blank1 == TRUE ) {
v1++;
- debug ("mailbox%d found mail %d",index, v1);
last_line_blank1 = FALSE;
}
}
diff --git a/seti.c b/seti.c
index 8832bfc..03d0943 100644
--- a/seti.c
+++ b/seti.c
@@ -1,4 +1,4 @@
-/* $Id: seti.c,v 1.5 2001/08/05 17:13:29 reinelt Exp $
+/* $Id: seti.c,v 1.6 2001/09/12 05:37:22 reinelt Exp $
*
* seti@home specific functions
*
@@ -20,6 +20,12 @@
*
*
* $Log: seti.c,v $
+ * Revision 1.6 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.5 2001/08/05 17:13:29 reinelt
*
* cleaned up inlude of sys/time.h and time.h
@@ -112,9 +118,12 @@ int Seti (double *perc, double *cput)
if (read (fd, &buffer, sizeof(buffer)-1)==-1) {
error ("read(%s) failed: %s", fn, strerror(errno));
+ close (fd);
fd=-1;
return -1;
}
+
+ close (fd);
p=strstr(buffer, "prog=");
if (p==NULL) {
diff --git a/socket.c b/socket.c
index cb00033..ca57f95 100644
--- a/socket.c
+++ b/socket.c
@@ -1,4 +1,4 @@
-/* $Id: socket.c,v 1.2 2001/03/15 14:25:05 ltoetsch Exp $
+/* $Id: socket.c,v 1.3 2001/09/12 05:37:22 reinelt Exp $
*
* simple socket functions
*
@@ -20,6 +20,12 @@
*
*
* $Log: socket.c,v $
+ * 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
*
@@ -63,6 +69,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
+#include <ctype.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
@@ -74,6 +81,67 @@
#define TIMEOUT 5 /* 5 seconds timeout */
+
+static char *quotemeta (char *string)
+{
+ 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;
@@ -102,7 +170,7 @@ int read_socket(int fd, char *buf, size_t size)
{
fd_set readfds;
struct timeval tv;
- int n = 0;
+ int n;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
@@ -111,11 +179,14 @@ int read_socket(int fd, char *buf, size_t size)
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("<(%d),%s", n, buf);
+ sockdebug('<', n, buf);
return n;
}
@@ -131,24 +202,10 @@ int read_socket_match(int fd, char *buf, size_t size, char *match)
return 0;
}
-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;
-}
-
int write_socket(int fd, char *buf)
{
int n = write(fd, buf, strlen(buf));
- sockdebug(">(%d),%s", n, del_pass(buf));
+ sockdebug('>', n, del_pass(buf));
return n;
}