diff options
Diffstat (limited to 'src/operator-idle.cc')
-rw-r--r-- | src/operator-idle.cc | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/src/operator-idle.cc b/src/operator-idle.cc index ccd70ea..369bcd9 100644 --- a/src/operator-idle.cc +++ b/src/operator-idle.cc @@ -2,32 +2,33 @@ * @file operator-idle.cc * @brief Operator for the IDLE command. Described in RFC2177 / June 1997. * @author Andreas Aardal Hanssen - * @date 2002-2005 + * @date 2002-2005 * ------------------------------------------------------------------ **/ -#include <unistd.h> - -#include <string> -#include <iostream> - -#include "iodevice.h" -#include "iofactory.h" #include "convert.h" #include "depot.h" #include "globals.h" +#include "iodevice.h" +#include "iofactory.h" #include "mailbox.h" #include "operators.h" #include "pendingupdates.h" #include "recursivedescent.h" #include "session.h" +#include <iostream> +#include <string> + +#include <unistd.h> + static bool directoryChangeNotification = false; -#ifdef HAVE_FNOTIFY // GNU dependencies removed -#include <sys/types.h> -#include <sys/select.h> -#include <stdio.h> +#ifdef HAVE_FNOTIFY // GNU dependencies removed #include <signal.h> +#include <stdio.h> + #include <fcntl.h> +#include <sys/select.h> +#include <sys/types.h> void fnotifyEventHandler(int sig) { @@ -47,14 +48,10 @@ static const int POLLTIMEOUT = 30; #endif //---------------------------------------------------------------------- -IdleOperator::IdleOperator(void) -{ -} +IdleOperator::IdleOperator(void) {} //---------------------------------------------------------------------- -IdleOperator::~IdleOperator(void) -{ -} +IdleOperator::~IdleOperator(void) {} //---------------------------------------------------------------------- const string IdleOperator::getName(void) const @@ -69,8 +66,7 @@ int IdleOperator::getState(void) const } //---------------------------------------------------------------------- -Operator::ProcessResult IdleOperator::process(Depot &depot, - Request &command) +Operator::ProcessResult IdleOperator::process(Depot &depot, Request &command) { Mailbox *mailbox = depot.getSelected(); string mailboxDir = depot.mailboxToFilename(mailbox->getName()); @@ -82,9 +78,9 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, int curfd = open((mailboxDir + "/cur").c_str(), O_RDONLY); // Watch for notifications for renames, deletes or creates. - if (newfd && curfd - && !fcntl(newfd, F_NOTIFY, DN_RENAME|DN_DELETE|DN_CREATE) - && !fcntl(curfd, F_NOTIFY, DN_RENAME|DN_DELETE|DN_CREATE)) { + if (newfd && curfd && !fcntl(newfd, F_NOTIFY, DN_RENAME | DN_DELETE | DN_CREATE) + && !fcntl(curfd, F_NOTIFY, DN_RENAME | DN_DELETE | DN_CREATE)) + { struct sigaction fnotifyAction; fnotifyAction.sa_handler = fnotifyEventHandler; sigemptyset(&fnotifyAction.sa_mask); @@ -99,12 +95,12 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, // when not using FNOTIFY, we need to check the session timeout. time_t startTime = time(0); #ifdef HAVE_FNOTIFY - (void)startTime; // removes a compile warning + (void)startTime; // removes a compile warning #endif bincClient << "+ idling" << endl; bincClient.flush(); - + // loop until the session times out or the client submits DONE. for (;;) { int maxfd = 0; @@ -123,17 +119,16 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, Session &session = Session::getInstance(); #ifdef HAVE_FNOTIFY if (waitForNotification) { - bincClient << "* BYE Timeout after " << session.timeout() - << " seconds of inactivity." << endl; + bincClient << "* BYE Timeout after " << session.timeout() << " seconds of inactivity." << endl; session.setState(Session::LOGOUT); close(newfd); close(curfd); return NOTHING; } else #endif - if (time(0) > startTime + IDLE_TIMEOUT) { - bincClient << "* BYE Timeout after " << IDLE_TIMEOUT - << " seconds of inactivity." << endl; + if (time(0) > startTime + IDLE_TIMEOUT) + { + bincClient << "* BYE Timeout after " << IDLE_TIMEOUT << " seconds of inactivity." << endl; session.setState(Session::LOGOUT); return NOTHING; } @@ -175,20 +170,21 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, } // scan for changes in the mailbox and report to the client. - if (pendingUpdates(mailbox, PendingUpdates::EXPUNGE - | PendingUpdates::EXISTS - | PendingUpdates::RECENT - | PendingUpdates::FLAGS, true) == false) { + if (pendingUpdates(mailbox, + PendingUpdates::EXPUNGE | PendingUpdates::EXISTS | PendingUpdates::RECENT + | PendingUpdates::FLAGS, + true) + == false) + { Session &session = Session::getInstance(); bincClient << "* NO " << session.getLastError() << endl; - bincWarning << "when scanning mailbox: " - << session.getLastError() << endl; + bincWarning << "when scanning mailbox: " << session.getLastError() << endl; #ifdef HAVE_FNOTIFY - close(newfd); - close(curfd); + close(newfd); + close(curfd); #endif - return NO; + return NO; } #ifdef HAVE_FNOTIFY @@ -197,15 +193,16 @@ Operator::ProcessResult IdleOperator::process(Depot &depot, directoryChangeNotification = false; // set up F_NOTIFY again. - if (!fcntl(newfd, F_NOTIFY, DN_MODIFY|DN_RENAME|DN_DELETE|DN_CREATE) - && !fcntl(curfd, F_NOTIFY, DN_MODIFY|DN_RENAME|DN_DELETE|DN_CREATE)) { + if (!fcntl(newfd, F_NOTIFY, DN_MODIFY | DN_RENAME | DN_DELETE | DN_CREATE) + && !fcntl(curfd, F_NOTIFY, DN_MODIFY | DN_RENAME | DN_DELETE | DN_CREATE)) + { struct sigaction fnotifyAction; fnotifyAction.sa_handler = fnotifyEventHandler; sigemptyset(&fnotifyAction.sa_mask); fnotifyAction.sa_flags = SA_RESTART; sigaction(SIGUSR1, &fnotifyAction, 0); } else { - waitForNotification = false; + waitForNotification = false; } } #endif @@ -225,8 +222,7 @@ Operator::ParseResult IdleOperator::parse(Request &c_in) const { Session &session = Session::getInstance(); - if (c_in.getUidMode()) - return REJECT; + if (c_in.getUidMode()) return REJECT; Operator::ParseResult res; if ((res = expectCRLF()) != ACCEPT) { |