[Pkg-wmaker-commits] [wmbiff] 24/38: general rewrite of the msglst headers, so that the list is pre-cached for responsiveness.

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


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

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

commit cba25772c4d6b8351e7ab72eae9d661aaf0b466c
Author: bluehal <bluehal>
Date:   Sun Jun 8 07:01:08 2003 +0000

    general rewrite of the msglst headers, so that the list is pre-cached for responsiveness.
---
 wmbiff/Client.h      | 10 +++++++--
 wmbiff/Imap4Client.c | 59 ++++++++++++++++++++++++++++++++++++++++++----------
 wmbiff/MessageList.c | 12 ++++++-----
 wmbiff/MessageList.h |  1 +
 wmbiff/ShellClient.c |  9 ++++++++
 5 files changed, 73 insertions(+), 18 deletions(-)

diff --git a/wmbiff/Client.h b/wmbiff/Client.h
index 87f6ddc..216cffb 100644
--- a/wmbiff/Client.h
+++ b/wmbiff/Client.h
@@ -1,11 +1,11 @@
-/* $Id: Client.h,v 1.33 2003/04/17 01:56:00 bluehal Exp $ */
+/* $Id: Client.h,v 1.34 2003/06/08 07:01:08 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: 2003/04/17 01:56:00 $
+ * Last Updated : $Date: 2003/06/08 07:01:08 $
  *
  */
 
@@ -47,6 +47,8 @@ typedef struct _mbox_t {
 	int blink_stat;				/* blink digits flag-counter */
 	int debug;					/* debugging status */
 
+	struct msglst *headerCache;
+
 	union {
 		struct {
 			time_t mtime;
@@ -76,7 +78,11 @@ typedef struct _mbox_t {
 	} u;
 
 	int (*checkMail) ( /*@notnull@ */ Pop3);
+
+	/* collect the headers to show in a pop up */
 	struct msglst *(*getHeaders) ( /*@notnull@ */ Pop3);
+	/* allow the client to free the headers, or keep them cached */
+	void (*releaseHeaders) ( /*@notnull@ */ Pop3, struct msglst * ml);
 
 	time_t prevtime;
 	time_t prevfetch_time;
diff --git a/wmbiff/Imap4Client.c b/wmbiff/Imap4Client.c
index 8632a4d..9e00a89 100644
--- a/wmbiff/Imap4Client.c
+++ b/wmbiff/Imap4Client.c
@@ -278,6 +278,8 @@ FILE *imap_open(Pop3 pc)
 
 }
 
+void imap_cacheHeaders( /*@notnull@ */ Pop3 pc);
+
 int imap_checkmail( /*@notnull@ */ Pop3 pc)
 {
 	/* recover connection state from the cache */
@@ -313,6 +315,12 @@ int imap_checkmail( /*@notnull@ */ Pop3 pc)
 		if (msg != NULL)
 			(void) sscanf(msg, "(MESSAGES %d UNSEEN %d)",
 						  &(pc->TotalMsgs), &(pc->UnreadMsgs));
+		/* update the cached headers if evidence that change
+		   has occurred; not necessarily complete. */
+		if (pc->UnreadMsgs != pc->OldUnreadMsgs ||
+			pc->TotalMsgs != pc->OldMsgs) {
+			imap_cacheHeaders(pc);
+		}
 	} else {
 		/* something went wrong. bail. */
 		tlscomm_close(unbind(scs));
@@ -321,22 +329,35 @@ int imap_checkmail( /*@notnull@ */ Pop3 pc)
 	return 0;
 }
 
-struct msglst *imap_getHeaders( /*@notnull@ */ Pop3 pc)
+void imap_cacheHeaders( /*@notnull@ */ Pop3 pc)
 {
 	struct connection_state *scs = state_for_pcu(pc);
-	struct msglst *message_list;
 	char *msgid;
 	char buf[BUF_SIZE];
+	struct msglst *h;
 
 	if (scs == NULL) {
 		(void) imap_open(pc);
 		scs = state_for_pcu(pc);
 	}
 	if (scs == NULL) {
-		return NULL;
+		return;
 	}
 	if (tlscomm_is_blacklisted(scs) != 0) {
-		return NULL;
+		return;
+	}
+
+	if (pc->headerCache != NULL) {
+		/* make sure the current copy is "unlocked" */
+		if (pc->headerCache->in_use == 1) {
+			return;
+		}
+		/* free the old one */
+		for (h = pc->headerCache; h != NULL;) {
+			struct msglst *n = h->next;
+			free(h);
+			h = n;
+		}
 	}
 
 	IMAP_DM(pc, DEBUG_INFO, "working headers\n");
@@ -344,7 +365,7 @@ struct msglst *imap_getHeaders( /*@notnull@ */ Pop3 pc)
 	tlscomm_printf(scs, "a004 EXAMINE %s\r\n", pc->path);
 	if (tlscomm_expect(scs, "a004 OK", buf, 127) == 0) {
 		tlscomm_close(unbind(scs));
-		return NULL;
+		return;
 	}
 	IMAP_DM(pc, DEBUG_INFO, "examine ok\n");
 
@@ -352,13 +373,13 @@ struct msglst *imap_getHeaders( /*@notnull@ */ Pop3 pc)
 	tlscomm_printf(scs, "a005 SEARCH UNSEEN\r\n");
 	if (tlscomm_expect(scs, "* SEARCH", buf, 127) == 0) {
 		tlscomm_close(unbind(scs));
-		return NULL;
+		return;
 	}
 	IMAP_DM(pc, DEBUG_INFO, "search: %s", buf);
 	if (strlen(buf) < 9)
-		return NULL;			/* search turned up nothing */
+		return;					/* search turned up nothing */
 	msgid = strtok(buf + 9, " \r\n");
-	message_list = NULL;
+	pc->headerCache = NULL;
 	/* the isdigit cruft is to deal with EOL */
 	if (msgid != NULL && isdigit(msgid[0]))
 		do {
@@ -387,8 +408,8 @@ struct msglst *imap_getHeaders( /*@notnull@ */ Pop3 pc)
 				}
 				IMAP_DM(pc, DEBUG_INFO, "From: '%s' Subj: '%s'\n", m->from,
 						m->subj);
-				m->next = message_list;
-				message_list = m;
+				m->next = pc->headerCache;
+				pc->headerCache = m;
 			} else {
 				IMAP_DM(pc, DEBUG_ERROR, "error fetching: %s", hdrbuf);
 			}
@@ -398,9 +419,24 @@ struct msglst *imap_getHeaders( /*@notnull@ */ Pop3 pc)
 	tlscomm_printf(scs, "a06 CLOSE\r\n");	/* return to polling state */
 	/*  may be unneeded tlscomm_expect(scs, "a06 OK CLOSE\r\n" );  see if it worked? */
 	IMAP_DM(pc, DEBUG_INFO, "worked headers\n");
-	return message_list;
 }
 
+struct msglst *imap_getHeaders( /*@notnull@ */ Pop3 pc)
+{
+	if (pc->headerCache == NULL)
+		imap_cacheHeaders(pc);
+	if (pc->headerCache != NULL)
+		pc->headerCache->in_use = 1;
+	return pc->headerCache;
+}
+
+void imap_releaseHeaders(Pop3 pc
+						 __attribute__ ((unused)), struct msglst *h)
+{
+	assert(h != NULL);
+	/* allow the list to be released next time around */
+	h->in_use = 0;
+}
 
 /* parse the config line to setup the Pop3 structure */
 int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
@@ -504,6 +540,7 @@ int imap4Create( /*@notnull@ */ Pop3 pc, const char *const str)
 
 	pc->checkMail = imap_checkmail;
 	pc->getHeaders = imap_getHeaders;
+	pc->releaseHeaders = imap_releaseHeaders;
 	pc->TotalMsgs = 0;
 	pc->UnreadMsgs = 0;
 	pc->OldMsgs = -1;
diff --git a/wmbiff/MessageList.c b/wmbiff/MessageList.c
index 52c77c6..76d47b0 100644
--- a/wmbiff/MessageList.c
+++ b/wmbiff/MessageList.c
@@ -33,6 +33,9 @@ static XFontStruct *fn;
 static int fontHeight;
 extern const char *foreground;
 extern const char *background;
+
+Pop3 Active_pc;
+
 static int loadFont(const char *fontname)
 {
 	if (display != NULL) {
@@ -70,6 +73,8 @@ void msglst_show(Pop3 pc, int x, int y)
 	XGCValues gcv;
 	unsigned long gcm;
 
+	Active_pc = pc;				/* hold so we can release later. */
+
 	/* local gc */
 	gcm = GCForeground | GCBackground | GCGraphicsExposures;
 	gcv.foreground = GetColor(foreground);
@@ -161,15 +166,12 @@ void msglst_show(Pop3 pc, int x, int y)
 void msglst_hide(void)
 {
 	if (newwin) {
-		struct msglst *n, *h;
 		flush_expose(newwin);	/* swallow the messages */
 		XDestroyWindow(display, newwin);
 		//   } else {
 		// no window fprintf(stderr, "unexpected error destroying msglist window\n");
-		for (h = Headers; h != NULL;) {
-			n = h->next;
-			free(h);
-			h = n;
+		if (Active_pc->releaseHeaders != NULL && Headers != NULL) {
+			Active_pc->releaseHeaders(Active_pc, Headers);
 		}
 		newwin = 0;
 	}
diff --git a/wmbiff/MessageList.h b/wmbiff/MessageList.h
index 548504e..1889615 100644
--- a/wmbiff/MessageList.h
+++ b/wmbiff/MessageList.h
@@ -5,6 +5,7 @@ struct msglst {
 	struct msglst *next;
 	char subj[SUBJ_LEN];
 	char from[FROM_LEN];
+	unsigned int in_use:1;
 };
 
 void msglst_show(Pop3 pc, int x, int y);
diff --git a/wmbiff/ShellClient.c b/wmbiff/ShellClient.c
index ebb31dd..c1328da 100644
--- a/wmbiff/ShellClient.c
+++ b/wmbiff/ShellClient.c
@@ -243,6 +243,15 @@ struct msglst *shell_getHeaders( /*@notnull@ */ Pop3 pc)
 	}
 	return message_list;
 }
+void shell_releaseHeaders(Pop3 pc
+						  __attribute__ ((unused)), struct msglst *h)
+{
+	for (; h != NULL;) {
+		struct msglst *n = h->next;
+		free(h);
+		h = n;
+	}
+}
 
 int shellCreate( /*@notnull@ */ Pop3 pc, const char *str)
 {

-- 
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