[Pkg-wmaker-commits] [wmbiff] 06/16: general portability fixes, including HAVE___ATTRIBUTE__

Doug Torrance dtorrance-guest at moszumanska.debian.org
Thu Aug 20 03:02:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to tag wmbiff_0_4_13
in repository wmbiff.

commit 111f348a14485a50aea5156015528e89e8e1bb81
Author: bluehal <bluehal>
Date:   Sun Jan 19 13:13:04 2003 +0000

    general portability fixes,  including HAVE___ATTRIBUTE__
---
 wmbiff/Client.h      |  6 ++---
 wmbiff/Imap4Client.c | 66 ++++++++++++++++++++++++++--------------------------
 wmbiff/Makefile.am   |  5 ++--
 wmbiff/Pop3Client.c  | 30 +++++++++++-------------
 wmbiff/ShellClient.c |  3 ++-
 wmbiff/charutil.c    | 13 +++++++----
 wmbiff/charutil.h    |  4 +++-
 wmbiff/passwordMgr.c |  2 ++
 wmbiff/test_wmbiff.c | 24 ++++++++++++++-----
 wmbiff/tlsComm.c     | 16 +++++++++----
 wmbiff/wmbiff.c      | 14 ++++++++---
 11 files changed, 108 insertions(+), 75 deletions(-)

diff --git a/wmbiff/Client.h b/wmbiff/Client.h
index afbb6c5..c686c95 100644
--- a/wmbiff/Client.h
+++ b/wmbiff/Client.h
@@ -1,11 +1,11 @@
-/* $Id: Client.h,v 1.29 2002/10/13 21:27:45 bluehal Exp $ */
+/* $Id: Client.h,v 1.30 2003/01/19 13:13:04 bluehal Exp $ */
 /* Author : Scott Holden ( scotth at thezone.net )
    Modified : Yong-iL Joh ( tolkien at mizi.com )
    Modified : Jorge Garc�a ( Jorge.Garcia at uv.es )
  *
  * Email Checker Pop3/Imap4/Licq/Gicu/mbox/maildir/finger
  *
- * Last Updated : $Date: 2002/10/13 21:27:45 $
+ * Last Updated : $Date: 2003/01/19 13:13:04 $
  *
  */
 
@@ -111,7 +111,7 @@ int exists(const char *filename);	/* test -f */
 #define DM(mbox, msglevel, X...) \
 do { \
   if (mbox == NULL || (mbox)->debug >= msglevel) { \
-     printf("wmbiff/%s ", (mbox)->label); \
+     printf("wmbiff/%s ", (mbox != NULL) ? (mbox)->label : "NULL"); \
      printf(X); \
      (void)fflush(NULL); \
   } \
diff --git a/wmbiff/Imap4Client.c b/wmbiff/Imap4Client.c
index 362f2d3..e63d775 100644
--- a/wmbiff/Imap4Client.c
+++ b/wmbiff/Imap4Client.c
@@ -15,6 +15,7 @@
 #include "charutil.h"
 #include "tlsComm.h"
 #include "passwordMgr.h"
+#include "regulo.h"
 
 #include <sys/types.h>
 #include <stdio.h>
@@ -84,8 +85,10 @@ static struct connection_state *state_for_pcu(Pop3 pc)
 	char *connection_id;
 	struct connection_state *retval = NULL;
 	int i;
-	asprintf(&connection_id, "%s|%s|%d", PCU.userName,
-			 PCU.serverName, PCU.serverPort);
+	connection_id =
+		malloc(strlen(PCU.userName) + strlen(PCU.serverName) + 22);
+	sprintf(connection_id, "%s|%s|%d", PCU.userName, PCU.serverName,
+			PCU.serverPort);
 	for (i = 0; i < FDMAP_SIZE; i++)
 		if (fdmap[i].user_password_server_port != NULL &&
 			(strcmp(connection_id,
@@ -105,8 +108,10 @@ static void bind_state_to_pcu(Pop3 pc,
 	if (scs == NULL) {
 		abort();
 	}
-	asprintf(&connection_id, "%s|%s|%d", PCU.userName,
-			 PCU.serverName, PCU.serverPort);
+	connection_id =
+		malloc(strlen(PCU.userName) + strlen(PCU.serverName) + 22);
+	sprintf(connection_id, "%s|%s|%d", PCU.userName, PCU.serverName,
+			PCU.serverPort);
 	for (i = 0; i < FDMAP_SIZE && fdmap[i].cs != NULL; i++);
 	if (i == FDMAP_SIZE) {
 		/* should never happen */
@@ -159,7 +164,8 @@ FILE *imap_open(Pop3 pc)
 
 	/* got this far; we're going to create a connection_state 
 	   structure, although it might be a blacklist entry */
-	asprintf(&connection_name, "%s:%d", PCU.serverName, PCU.serverPort);
+	connection_name = malloc(strlen(PCU.serverName) + 20);
+	sprintf(connection_name, "%s:%d", PCU.serverName, PCU.serverPort);
 
 	assert(pc != NULL);
 
@@ -305,17 +311,27 @@ int imap_checkmail( /*@notnull@ */ Pop3 pc)
 	return 0;
 }
 
+
 /* parse the config line to setup the Pop3 structure */
 int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
 {
-	struct re_registers regs;
-	int i, matchedchars;
+	int i;
+	int matchedchars;
 	const char *regexes[] = {
 		".*imaps?:([^: ]{1,32}):([^@]{0,32})@([^/: ]+)(/(\"[^\"]+\")|([^: ]+))?(:[0-9]+)? *",
 		".*imaps?:([^: ]{1,32}) ([^ ]{1,32}) ([^/: ]+)(/(\"[^\"]+\")|([^: ]+))?( [0-9]+)? *",
 		NULL
 	};
 
+	struct regulo regulos[] = {
+		{1, PCU.userName, regulo_strcpy},
+		{2, PCU.password, regulo_strcpy},
+		{3, PCU.serverName, regulo_strcpy},
+		{4, pc->path, regulo_strcpy_skip1},
+		{7, &PCU.serverPort, regulo_atoi},
+		{0, NULL, NULL}
+	};
+
 	/* IMAP4 format: imap:user:password at server/mailbox[:port] */
 	/* If 'str' line is badly formatted, wmbiff won't display the mailbox. */
 	if (strncmp("sslimap:", str, 8) == 0 || strncmp("imaps:", str, 6) == 0) {
@@ -336,12 +352,17 @@ int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
 			   "passwords and privacy.\n");
 		exit(EXIT_FAILURE);
 #endif
-	} else
+	} else {
 		PCU.dossl = 0;
+	}
+
+	/* defaults */
+	PCU.serverPort = (PCU.dossl != 0) ? 993 : 143;
+	strcpy(pc->path, "INBOX");
 
 	for (matchedchars = 0, i = 0;
 		 regexes[i] != NULL && matchedchars <= 0; i++) {
-		matchedchars = compile_and_match_regex(regexes[i], str, &regs);
+		matchedchars = regulo_match(regexes[i], str, regulos);
 	}
 
 	/* failed to match either regex */
@@ -351,34 +372,12 @@ int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
 				matchedchars);
 		return -1;
 	}
-#ifdef why_wont_you_parse
-	for (i = 0; i < 8; i++) {
-		char buf[255];
-		copy_substring(buf, regs.start[i], regs.end[i], str);
-		IMAP_DM(pc, DEBUG_INFO, "%d: %s\n", i, buf);
-	}
-#endif
 
-	/* copy matches where they belong */
-	copy_substring(PCU.userName, regs.start[1], regs.end[1], str);
-	copy_substring(PCU.password, regs.start[2], regs.end[2], str);
 	if (PCU.password[0] == '\0')
 		PCU.interactive_password = 1;
-	copy_substring(PCU.serverName, regs.start[3], regs.end[3], str);
-	if (regs.start[4] != -1)
-		copy_substring(pc->path, regs.start[4] + 1, regs.end[4], str);
-	else
-		strcpy(pc->path, "INBOX");
 
-	if (regs.start[7] != -1)
-		PCU.serverPort = atoi(str + regs.start[7] + 1);
-	else
-		PCU.serverPort = (PCU.dossl != 0) ? 993 : 143;
+	grab_authList(str + matchedchars, PCU.authList);
 
-	grab_authList(str + regs.end[0], PCU.authList);
-
-	free(regs.end);				// added 3 jul 02, appeasing valgrind
-	free(regs.start);			// added 3 jul 02, appeasing valgrind
 
 	IMAP_DM(pc, DEBUG_INFO, "userName= '%s'\n", PCU.userName);
 	IMAP_DM(pc, DEBUG_INFO, "password is %d characters long\n",
@@ -442,7 +441,8 @@ static int authenticate_plaintext( /*@notnull@ */ Pop3 pc,
 
 #ifdef HAVE_GCRYPT_H
 static int authenticate_md5(Pop3 pc,
-				 struct connection_state *scs, const char *capabilities)
+							struct connection_state *scs,
+							const char *capabilities)
 {
 	char buf[BUF_SIZE];
 	char buf2[BUF_SIZE];
diff --git a/wmbiff/Makefile.am b/wmbiff/Makefile.am
index 04d431f..6f02da9 100644
--- a/wmbiff/Makefile.am
+++ b/wmbiff/Makefile.am
@@ -3,12 +3,13 @@ noinst_PROGRAMS = test_wmbiff
 bin_PROGRAMS = wmbiff
 wmbiff_SOURCES = wmbiff.c socket.c Pop3Client.c LicqClient.c mboxClient.c \
 	maildirClient.c Imap4Client.c tlsComm.c tlsComm.h ShellClient.c  \
-	passwordMgr.c passwordMgr.h charutil.c charutil.h Client.h 
+	passwordMgr.c passwordMgr.h charutil.c charutil.h Client.h  \
+	regulo.c regulo.h 
 EXTRA_wmbiff_SOURCES = gnutls-common.c gnutls-common.h	
 wmbiff_LDADD = -L../wmgeneral -lwmgeneral @LIBGCRYPT_LIBS@ @GNUTLS_COMMON_O@
 wmbiff_DEPENDENCIES = ../wmgeneral/libwmgeneral.a Makefile @GNUTLS_COMMON_O@
 test_wmbiff_SOURCES = ShellClient.c charutil.c charutil.h Client.h \
-	test_wmbiff.c passwordMgr.c Imap4Client.c 
+	test_wmbiff.c passwordMgr.c Imap4Client.c regulo.c
 man_MANS = wmbiff.1 wmbiffrc.5
 skindir = $(datadir)/wmbiff/skins
 skin_DATA = wmbiff-master-led.xpm wmbiff-master-contrast.xpm 
diff --git a/wmbiff/Pop3Client.c b/wmbiff/Pop3Client.c
index 79793ec..3439d6a 100644
--- a/wmbiff/Pop3Client.c
+++ b/wmbiff/Pop3Client.c
@@ -1,4 +1,4 @@
-/* $Id: Pop3Client.c,v 1.15 2002/07/04 01:07:28 bluehal Exp $ */
+/* $Id: Pop3Client.c,v 1.16 2003/01/19 13:13:04 bluehal Exp $ */
 /* Author : Scott Holden ( scotth at thezone.net )
    Modified : Yong-iL Joh ( tolkien at mizi.com )
    Modified : Jorge Garc�a ( Jorge.Garcia at uv.es )
@@ -16,6 +16,7 @@
 
 #include "Client.h"
 #include "charutil.h"
+#include "regulo.h"
 
 #ifdef USE_DMALLOC
 #include <dmalloc.h>
@@ -159,7 +160,6 @@ int pop3Create(Pop3 pc, const char *str)
 	/* If 'str' line is badly formatted, wmbiff won't display the mailbox. */
 	int i;
 	int matchedchars;
-	struct re_registers regs;
 	/* ([^: ]+) user
 	   ([^@]+) or ([^ ]+) password 
 	   ([^: ]+) server 
@@ -173,10 +173,20 @@ int pop3Create(Pop3 pc, const char *str)
 		"pop3:([^: ]{1,32}):([^@]{0,32})@([^: ]+)(:[0-9]+)? *",
 		NULL
 	};
+	struct regulo regulos[] = {
+		{1, PCU.userName, regulo_strcpy},
+		{2, PCU.password, regulo_strcpy},
+		{3, PCU.serverName, regulo_strcpy},
+		{4, &PCU.serverPort, regulo_atoi},
+		{0, NULL, NULL}
+	};
+
+	/* defaults */
+	PCU.serverPort = 110;
 
 	for (matchedchars = 0, i = 0;
 		 regexes[i] != NULL && matchedchars <= 0; i++) {
-		matchedchars = compile_and_match_regex(regexes[i], str, &regs);
+		matchedchars = regulo_match(regexes[i], str, regulos);
 	}
 
 	/* failed to match either regex */
@@ -187,19 +197,7 @@ int pop3Create(Pop3 pc, const char *str)
 		return -1;
 	}
 
-	/* copy matches where they belong */
-	copy_substring(PCU.userName, regs.start[1], regs.end[1], str);
-	copy_substring(PCU.password, regs.start[2], regs.end[2], str);
-	copy_substring(PCU.serverName, regs.start[3], regs.end[3], str);
-	if (regs.start[4] != -1)
-		PCU.serverPort = atoi(str + regs.start[4] + 1);
-	else
-		PCU.serverPort = 110;
-
-	grab_authList(str + regs.end[0], PCU.authList);
-
-	free(regs.end);				// added 3 jul 02, appeasing valgrind
-	free(regs.start);			// added 3 jul 02, appeasing valgrind
+	grab_authList(str + matchedchars, PCU.authList);
 
 	POP_DM(pc, DEBUG_INFO, "userName= '%s'\n", PCU.userName);
 	POP_DM(pc, DEBUG_INFO, "password is %d chars long\n",
diff --git a/wmbiff/ShellClient.c b/wmbiff/ShellClient.c
index e5e3cfc..19b646f 100644
--- a/wmbiff/ShellClient.c
+++ b/wmbiff/ShellClient.c
@@ -19,6 +19,7 @@
 #include <ctype.h>
 #include <signal.h>
 #include <assert.h>
+#include <strings.h>
 #include "charutil.h"
 #ifdef USE_DMALLOC
 #include <dmalloc.h>
@@ -32,7 +33,7 @@
 #ifdef __LCLINT__
 void (*old_signal_handler) (int);
 #else
-sig_t old_signal_handler;
+RETSIGTYPE(*old_signal_handler) (int);
 #endif
 
 /*@null@*/
diff --git a/wmbiff/charutil.c b/wmbiff/charutil.c
index 27d4789..f8b98e5 100644
--- a/wmbiff/charutil.c
+++ b/wmbiff/charutil.c
@@ -1,4 +1,4 @@
-/* $Id: charutil.c,v 1.14 2002/12/29 02:31:26 bluehal Exp $ */
+/* $Id: charutil.c,v 1.15 2003/01/19 13:13:04 bluehal Exp $ */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -7,6 +7,8 @@
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <regex.h>
 #ifdef USE_DMALLOC
 #include <dmalloc.h>
 #endif
@@ -36,8 +38,8 @@ static __inline__ void RightTrim(char *psValue)
 
 void FullTrim(char *psValue)
 {
-  RightTrim(psValue);
-  LeftTrim(psValue);
+	RightTrim(psValue);
+	LeftTrim(psValue);
 }
 
 void Bin2Hex(unsigned char *src, int length, char *dst)
@@ -175,7 +177,7 @@ void grab_authList(const char *source, char *destination)
 	}
 }
 
-
+#ifdef USE_GNU_REGEX
 int compile_and_match_regex(const char *regex, const char *str,	/*@out@ */
 							struct re_registers *regs)
 {
@@ -186,7 +188,6 @@ int compile_and_match_regex(const char *regex, const char *str,	/*@out@ */
 
 	/* compile the regex pattern */
 	memset(&rpbuf, 0, sizeof(struct re_pattern_buffer));
-
 	/* posix egrep interprets intervals (eg. {1,32}) nicely */
 	re_syntax_options = RE_SYNTAX_POSIX_EGREP;
 	errstr = re_compile_pattern(regex, strlen(regex), &rpbuf);
@@ -215,6 +216,7 @@ int compile_and_match_regex(const char *regex, const char *str,	/*@out@ */
 	regfree(&rpbuf);			// added 3 jul 02, appeasing valgrind
 	return matchedchars;
 }
+#endif
 
 /* like perl chomp(); useful for dealing with input from popen */
 void chomp(char *s)
@@ -233,6 +235,7 @@ char *strdup_ordie(const char *c)
 	}
 	return (ret);
 }
+
 /* vim:set ts=4: */
 /*
  * Local Variables:
diff --git a/wmbiff/charutil.h b/wmbiff/charutil.h
index a82d896..ac1da9f 100644
--- a/wmbiff/charutil.h
+++ b/wmbiff/charutil.h
@@ -1,4 +1,4 @@
-/* $Id: charutil.h,v 1.9 2002/12/29 02:31:26 bluehal Exp $ */
+/* $Id: charutil.h,v 1.10 2003/01/19 13:13:04 bluehal Exp $ */
 /* Author: Mark Hurley  (debian4tux at telocity.com)
  *
  * Character / string manipulation utilities. 
@@ -34,9 +34,11 @@ void copy_substring(char *destination,
 /* common to Pop3 and Imap4 authentication list grabber. */
 void grab_authList(const char *source, char *destination);
 
+#ifdef USE_GNU_REGEX
 /* handles main regex work */
 int compile_and_match_regex(const char *regex, const char *str,
 							/*@out@ */ struct re_registers *regs);
+#endif
 
 /* acts like perl's function of the same name */
 void chomp(char *s);
diff --git a/wmbiff/passwordMgr.c b/wmbiff/passwordMgr.c
index 5cc06a5..f2a8c33 100644
--- a/wmbiff/passwordMgr.c
+++ b/wmbiff/passwordMgr.c
@@ -33,6 +33,8 @@
 #include <sys/types.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
+#include <strings.h>			/* index */
 #include <sys/stat.h>
 #include "assert.h"
 
diff --git a/wmbiff/test_wmbiff.c b/wmbiff/test_wmbiff.c
index 7cb887b..eba6057 100644
--- a/wmbiff/test_wmbiff.c
+++ b/wmbiff/test_wmbiff.c
@@ -2,6 +2,12 @@
 #include <config.h>
 #endif
 
+#ifdef HAVE___ATTRIBUTE__
+#define UNUSED(x) /*@unused@*/  x __attribute__((unused))
+#else
+#define UNUSED(x) x
+#endif
+
 #include "Client.h"
 #include "passwordMgr.h"
 
@@ -187,22 +193,28 @@ int test_imap4creator(void) {
     CKSTRING(m.u.pop_imap.serverName, "bar");
     CKINT(m.u.pop_imap.serverPort, 12);
 
+    if(imap4Create(&m, "imap:foo:@bar/\"mybox\":12 auth")) {
+        return 1;
+    }
+    CKSTRING(m.path, "\"mybox\"");
+    CKSTRING(m.u.pop_imap.serverName, "bar");
+    CKINT(m.u.pop_imap.serverPort, 12);
+    CKSTRING(m.u.pop_imap.authList, "auth");
+
     
     return 0;
 }
 
 void initialize_blacklist(void) { } 
-void tlscomm_printf(int x __attribute__((unused)), const char *f __attribute__((unused)), ...) { }
+void tlscomm_printf(UNUSED(int x), UNUSED(const char *f), ...) { }
 void tlscomm_expect(void) {  } 
 void tlscomm_close() {  } 
-int tlscomm_is_blacklisted(const char *x __attribute__((unused))) {  return 1; } 
+int tlscomm_is_blacklisted(UNUSED(const char *x)) {  return 1; } 
 void initialize_gnutls(void) {  } 
-int sock_connect(const char *n __attribute__((unused)), 
-                 int p __attribute__((unused))) { return 1; } /* stdout */
+int sock_connect(UNUSED(const char *n), UNUSED(int p)) { return 1; } /* stdout */
 void initialize_unencrypted(void) {  } 
 
-int main(int argc __attribute__((unused)), 
-         char *argv[] __attribute__((unused))) {
+int main(UNUSED(int argc), UNUSED(char *argv[])) {
     if( test_backtickExpand() || 
         test_passwordMgr() ||
         test_imap4creator()) {
diff --git a/wmbiff/tlsComm.c b/wmbiff/tlsComm.c
index 9ef94a3..0a294f0 100644
--- a/wmbiff/tlsComm.c
+++ b/wmbiff/tlsComm.c
@@ -27,6 +27,12 @@
 #include <dmalloc.h>
 #endif
 
+#ifdef HAVE___ATTRIBUTE__
+#define UNUSED(x) /*@unused@*/  x __attribute__((unused))
+#else
+#define UNUSED(x) x
+#endif
+
 #include "tlsComm.h"
 
 #include "Client.h"				/* debugging messages */
@@ -466,11 +472,11 @@ void handle_gnutls_read_error(int readbytes, struct connection_state *scs)
 
 #else
 /* declare stubs when tls isn't compiled in */
-struct connection_state *
-initialize_gnutls( /*@unused@ */ int sd __attribute__ ((unused)),
-                   /*@unused@ */ char *name __attribute__ ((unused)),
-                   /*@unused@ */ Pop3 pc __attribute__ ((unused)),
-                   /*@unused@ */ const char *remote_hostname __attribute__ ((unused)))
+struct connection_state *initialize_gnutls(UNUSED(int sd),
+										   UNUSED(char *name),
+										   UNUSED(Pop3 pc),
+										   UNUSED(const char
+												  *remote_hostname))
 {
 	DM(pc, DEBUG_ERROR,
 	   "FATAL: tried to initialize ssl when ssl wasn't compiled in.\n");
diff --git a/wmbiff/wmbiff.c b/wmbiff/wmbiff.c
index 3d56dd6..de50a1b 100644
--- a/wmbiff/wmbiff.c
+++ b/wmbiff/wmbiff.c
@@ -1,4 +1,4 @@
-/* $Id: wmbiff.c,v 1.44 2003/01/04 03:39:35 bluehal Exp $ */
+/* $Id: wmbiff.c,v 1.45 2003/01/19 13:13:04 bluehal Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -321,7 +321,10 @@ static int Read_Config_File(char *filename, int *loopinterval)
 
 static void init_biff(char *config_file)
 {
-	int zok, loopinterval = DEFAULT_LOOP;
+#ifdef HAVE_GCRYPT_H
+	int zok;
+#endif
+	int loopinterval = DEFAULT_LOOP;
 	unsigned int i;
 
 	for (i = 0; i < num_mailboxes; i++) {
@@ -415,6 +418,7 @@ static char **LoadXPM(const char *pixmap_filename)
 			pixmap_filename);
 		break;
 	default:
+		break;
 	}
 	return (xpm);
 }
@@ -966,7 +970,11 @@ static void do_biff(int argc, char **argv)
 	}
 }
 
-static void sigchld_handler(int sig __attribute__ ((unused)))
+static void sigchld_handler(int sig
+#ifdef HAVE___ATTRIBUTE__
+							__attribute__ ((unused))
+#endif
+	)
 {
 	while (waitpid(0, NULL, WNOHANG) > 0);
 	signal(SIGCHLD, sigchld_handler);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbiff.git



More information about the Pkg-wmaker-commits mailing list