-- 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
This commit is contained in:
pfelt
2008-03-29 23:09:15 +00:00
parent 362bdba3f1
commit 2e9fab5085
7 changed files with 80 additions and 62 deletions
+2 -2
View File
@@ -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 **/
+2 -3
View File
@@ -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);
}
+7 -10
View File
@@ -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));
}
+2 -2
View File
@@ -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);
+33 -27
View File
@@ -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 <time.h>
@@ -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;
}
+6 -8
View File
@@ -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));
}
+28 -10
View File
@@ -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;