From 2e9fab5085e86f391e2bda5c695431d2d602f573 Mon Sep 17 00:00:00 2001 From: pfelt Date: Sat, 29 Mar 2008 23:09:15 +0000 Subject: [PATCH] -- BongoSListDelete() and BongoListDelete() now conform better to the reset of the list api -- added back code from alex on the progress stuff due to oddness in the flushing and messaging. -- changed the progress stuff to use the new *ListDelete() calls --- include/bongoutil.h | 4 +-- src/agents/imap/copy.c | 5 ++-- src/agents/imap/imapd.c | 17 +++++------ src/agents/imap/imapd.h | 4 +-- src/agents/imap/progress.c | 60 +++++++++++++++++++++----------------- src/agents/imap/store.c | 14 ++++----- src/libs/bongoutil/lists.c | 38 +++++++++++++++++------- 7 files changed, 80 insertions(+), 62 deletions(-) diff --git a/include/bongoutil.h b/include/bongoutil.h index 2c7288a..7993d1d 100644 --- a/include/bongoutil.h +++ b/include/bongoutil.h @@ -332,7 +332,7 @@ BongoList *BongoListReverse(BongoList *list); void BongoListFree(BongoList *list); void BongoListFreeDeep(BongoList *list); int BongoListLength(BongoList *list); -BOOL BongoListDelete(BongoList *list, void *data); +BongoList *BongoListDelete(BongoList *list, void *data, BOOL deep); BongoSList *BongoSListCopy(BongoSList *slist); BongoSList *BongoSListAppend(BongoSList *slist, void *data); @@ -342,7 +342,7 @@ BongoSList *BongoSListReverse(BongoSList *slist); void BongoSListFree(BongoSList *slist); void BongoSListFreeDeep(BongoSList *slist); int BongoSListLength(BongoSList *slist); -BOOL BongoSListDelete(BongoSList *list, void *data); +BongoSList *BongoSListDelete(BongoSList *list, void *data, BOOL deep); /** end lists.c **/ diff --git a/src/agents/imap/copy.c b/src/agents/imap/copy.c index 0d60a6a..c0c207e 100644 --- a/src/agents/imap/copy.c +++ b/src/agents/imap/copy.c @@ -91,9 +91,8 @@ HandleCopy(ImapSession *session, BOOL ByUID) FolderPath targetPath; long ccode; char *ptr2; - void *BusyHandle; - BusyHandle = StartBusy(session); + StartBusy(session, "* OK - Copied UID range"); if ((ccode = CheckState(session, STATE_SELECTED)) == STATUS_CONTINUE) { if ((ccode = EventsSend(session, STORE_EVENT_ALL)) == STATUS_CONTINUE) { @@ -112,7 +111,7 @@ HandleCopy(ImapSession *session, BOOL ByUID) } } } - StopBusy(BusyHandle); + StopBusy(session); return(ccode); } diff --git a/src/agents/imap/imapd.c b/src/agents/imap/imapd.c index b902d01..8a13fc4 100644 --- a/src/agents/imap/imapd.c +++ b/src/agents/imap/imapd.c @@ -2365,7 +2365,6 @@ PurgeDeletedMessages(ImapSession *session, BOOL client_response, MessageInformat count = messageCount; while (count > 0) { - ProgressUpdate(session); if (!(message->flags & STORE_MSG_FLAG_DELETED) || (message->flags & STORE_MSG_FLAG_PURGED)) { message--; count--; @@ -2397,13 +2396,12 @@ ImapCommandClose(void *param) { ImapSession *session = (ImapSession *)param; long ccode; - void *BusyHandle; - BusyHandle = StartBusy(session); + StartBusy(session, "* OK - Purging deleted messages"); if ((ccode = CheckState(session, STATE_SELECTED)) == STATUS_CONTINUE) { if (session->folder.selected.readOnly) { FolderDeselect(session); - StopBusy(BusyHandle); + StopBusy(session); return(SendOk(session, "CLOSE")); } @@ -2411,11 +2409,11 @@ ImapCommandClose(void *param) FolderDeselect(session); if (ccode == STATUS_CONTINUE) { - StopBusy(BusyHandle); + StopBusy(session); return(SendOk(session, "CLOSE")); } } - StopBusy(BusyHandle); + StopBusy(session); return(SendError(session->client.conn, session->command.tag, "CLOSE", ccode)); } @@ -2425,9 +2423,8 @@ ImapCommandExpunge(void *param) ImapSession *session = (ImapSession *)param; OpenedFolder *selected = &session->folder.selected; long ccode; - void *BusyHandle; - BusyHandle = StartBusy(session); + StartBusy(session, NULL); if ((ccode = CheckState(session, STATE_SELECTED)) == STATUS_CONTINUE) { if ((ccode = EventsSend(session, STORE_EVENT_ALL)) == STATUS_CONTINUE) { @@ -2435,14 +2432,14 @@ ImapCommandExpunge(void *param) if (!(selected->readOnly)) { if ((ccode = PurgeDeletedMessages(session, TRUE, &(selected->message[selected->messageCount - 1]), selected->messageCount)) == STATUS_CONTINUE) { if ((ccode = MessageListLoad(session->store.conn, selected)) == STATUS_CONTINUE) { - StopBusy(BusyHandle); + StopBusy(session); return(SendOk(session, "EXPUNGE")); } } } } } - StopBusy(BusyHandle); + StopBusy(session); return(SendError(session->client.conn, session->command.tag, "EXPUNGE", ccode)); } diff --git a/src/agents/imap/imapd.h b/src/agents/imap/imapd.h index e5c03f3..d59beee 100755 --- a/src/agents/imap/imapd.h +++ b/src/agents/imap/imapd.h @@ -411,8 +411,8 @@ long MessageListLoad(Connection *conn, OpenedFolder *selected); /* progress.c */ void DoUpdate(void); -void *StartBusy(ImapSession *session); -void StopBusy(void *handle); +void StartBusy(ImapSession *session, char *Message); +void StopBusy(ImapSession *session); void CommandFetchCleanup(void); BOOL CommandFetchInit(void); diff --git a/src/agents/imap/progress.c b/src/agents/imap/progress.c index 66f3e78..15461ea 100644 --- a/src/agents/imap/progress.c +++ b/src/agents/imap/progress.c @@ -1,3 +1,5 @@ +// Parts Copyright (C) 2008 Patrick Felt. See COPYING for details. +// Parts Copyright (C) 2008 Alex Hudson. See COPYING for details. #include "imapd.h" #include @@ -5,55 +7,59 @@ void DoUpdate(void) { - BongoList *cur = Imap.list_Busy; + BongoList *cur; ImapSession *session; + ProgressUpdate *update; XplWaitOnLocalSemaphore(Imap.sem_Busy); + cur = Imap.list_Busy; while(cur) { session = (ImapSession *)cur->data; - ConnWriteStr(session->client.conn, "* OK - Still Busy\r\n"); + update = session->progress; + if (update->message) { + ConnWriteF(session->client.conn, "%s\r\n", update->message); + } ConnFlush(session->client.conn); cur = cur->next; } XplSignalLocalSemaphore(Imap.sem_Busy); } -void * -StartBusy(ImapSession *session) +void +StartBusy(ImapSession *session, char *Message) { - XplWaitOnLocalSemaphore(Imap.sem_Busy); + ProgressUpdate *p = MemMalloc(sizeof(ProgressUpdate)); + if (p == NULL) { + return; + } - /* add ourselves to the list and return the pointer */ + /* add ourselves to the list */ + XplWaitOnLocalSemaphore(Imap.sem_Busy); Imap.list_Busy = BongoListPrepend(Imap.list_Busy, session); XplSignalLocalSemaphore(Imap.sem_Busy); - return Imap.list_Busy; + p->last_update = time(0); + p->messages_processed = 0; + p->message = MemStrdup(Message); + session->progress = p; + + return; } /* this function takes the handle returned from StartProgressUpdate */ void -StopBusy(void *handle) +StopBusy(ImapSession *session) { - BongoList *me = (BongoList *)handle; - XplWaitOnLocalSemaphore(Imap.sem_Busy); - /* unlink me */ - if (me->prev || me->next) { - if (me->prev) { - me->prev->next = me->next; - } - - if (me->next) { - me->next->prev = me->prev; - } - } else { - /* i was the last item in the array. null it */ - Imap.list_Busy = NULL; - } - - /* free me */ - MemFree(me); - + BongoListDelete(Imap.list_Busy, session, FALSE); XplSignalLocalSemaphore(Imap.sem_Busy); + + if (session->progress) { + if (session->progress->message) { + MemFree(session->progress->message); + } + MemFree(session->progress); + session->progress = NULL; + } return; } diff --git a/src/agents/imap/store.c b/src/agents/imap/store.c index 9d491e6..e438d02 100644 --- a/src/agents/imap/store.c +++ b/src/agents/imap/store.c @@ -213,18 +213,17 @@ ImapCommandStore(void *param) long ccode; ImapSession *session = (ImapSession *)param; BOOL purgedMessage = FALSE; - void *BusyHandle; - BusyHandle = StartBusy(session); + StartBusy(session, "* OK - Store"); if ((ccode = HandleStore(session, FALSE, &purgedMessage)) == STATUS_CONTINUE) { if (!purgedMessage) { - StopBusy(BusyHandle); + StopBusy(session); return(SendOk(session, "STORE")); } ccode = STATUS_REQUESTED_MESSAGE_NO_LONGER_EXISTS; } - StopBusy(BusyHandle); + StopBusy(session); return(SendError(session->client.conn, session->command.tag, "STORE", ccode)); } @@ -234,18 +233,17 @@ ImapCommandUidStore(void *param) long ccode; ImapSession *session = (ImapSession *)param; BOOL purgedMessage = FALSE; - void *BusyHandle; - BusyHandle = StartBusy(session); + StartBusy(session, "* OK - UID Store"); memmove(session->command.buffer, session->command.buffer + strlen("UID "), strlen(session->command.buffer + strlen("UID ")) + 1); if ((ccode = HandleStore(session, TRUE, &purgedMessage)) == STATUS_CONTINUE) { if (!purgedMessage) { - StopBusy(BusyHandle); + StopBusy(session); return(SendOk(session, "UID STORE")); } ccode = STATUS_REQUESTED_MESSAGE_NO_LONGER_EXISTS; } - StopBusy(BusyHandle); + StopBusy(session); return(SendError(session->client.conn, session->command.tag, "UID STORE", ccode)); } diff --git a/src/libs/bongoutil/lists.c b/src/libs/bongoutil/lists.c index 4e1dee2..7a496ff 100644 --- a/src/libs/bongoutil/lists.c +++ b/src/libs/bongoutil/lists.c @@ -159,12 +159,12 @@ BongoSListLength(BongoSList *slist) return i; } -BOOL -BongoSListDelete(BongoSList *list, void *data) +BongoSList * +BongoSListDelete(BongoSList *list, void *data, BOOL deep) { + BongoSList *result=list; BongoSList *cur=list; BongoSList *prev=NULL; - BOOL result=FALSE; if (!list) { return result; @@ -172,12 +172,20 @@ BongoSListDelete(BongoSList *list, void *data) while (cur) { if (cur->data == data) { - result=TRUE; + if (cur == list) { + /* the item we are deleting is the first in the list. i need + * to reset the head of the list */ + result = list->next; + } + /* unlink this item */ if (prev) { prev->next = cur->next; } + if (deep) { + MemFree(cur->data); + } MemFree(cur); break; } @@ -328,10 +336,10 @@ BongoListLength(BongoList *list) return i; } -BOOL -BongoListDelete(BongoList *list, void *data) +BongoList * +BongoListDelete(BongoList *list, void *data, BOOL deep) { - BOOL result=FALSE; + BongoList *result=list; BongoList *cur=list; if (!list) { @@ -340,14 +348,24 @@ BongoListDelete(BongoList *list, void *data) while (cur) { if (cur->data == data) { - result=TRUE; + if (cur == list) { + /* the item we are deleting is the first in the list. i need + * to reset the head of the list */ + result = cur->next; + } + /* unlink this item */ + if (cur->next) { + cur->next->prev = cur->prev; + } + if (cur->prev) { cur->prev->next = cur->next; } - if (cur->next) { - cur->next->prev = cur->prev; + /* free the memory */ + if (deep) { + MemFree(cur->data); } MemFree(cur); break;