Files
bongo/src/agents/imap/progress.c
T
pfelt 2e9fab5085 -- 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
2008-03-29 23:09:15 +00:00

66 lines
1.6 KiB
C

// 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>
/* traverse the global list and send oks to everyone */
void
DoUpdate(void)
{
BongoList *cur;
ImapSession *session;
ProgressUpdate *update;
XplWaitOnLocalSemaphore(Imap.sem_Busy);
cur = Imap.list_Busy;
while(cur) {
session = (ImapSession *)cur->data;
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, char *Message)
{
ProgressUpdate *p = MemMalloc(sizeof(ProgressUpdate));
if (p == NULL) {
return;
}
/* add ourselves to the list */
XplWaitOnLocalSemaphore(Imap.sem_Busy);
Imap.list_Busy = BongoListPrepend(Imap.list_Busy, session);
XplSignalLocalSemaphore(Imap.sem_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(ImapSession *session)
{
XplWaitOnLocalSemaphore(Imap.sem_Busy);
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;
}