* More minor cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42973 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2011-10-29 17:38:58 +00:00
parent ee5f0dac80
commit a9bd4e48eb
4 changed files with 33 additions and 26 deletions
@@ -132,9 +132,9 @@ IMAPMailbox::StartWatchingMailbox(sem_id startedSem)
bigtime_t timeout = 1000 * 1000 * 60 * 29; // 29 min bigtime_t timeout = 1000 * 1000 * 60 * 29; // 29 min
status_t status; status_t status;
while (true) { while (true) {
int32 commandId = NextCommandId(); int32 commandID = NextCommandID();
TRACE("IDLE ...\n"); TRACE("IDLE ...\n");
status = SendCommand("IDLE", commandId); status = SendCommand("IDLE", commandID);
if (firstIDLE) { if (firstIDLE) {
release_sem(startedSem); release_sem(startedSem);
firstIDLE = false; firstIDLE = false;
@@ -142,7 +142,7 @@ IMAPMailbox::StartWatchingMailbox(sem_id startedSem)
if (status != B_OK) if (status != B_OK)
break; break;
status = HandleResponse(commandId, timeout, false); status = HandleResponse(commandID, timeout, false);
ProcessAfterQuacks(kIMAP4ClientTimeout); ProcessAfterQuacks(kIMAP4ClientTimeout);
if (atomic_get(&fWatching) == 0) if (atomic_get(&fWatching) == 0)
@@ -81,10 +81,10 @@ private:
MinMessageList fMessageList; MinMessageList fMessageList;
IMAPStorage& fStorage; IMAPStorage& fStorage;
IMAPMailboxListener* fIMAPMailboxListener; IMAPMailboxListener* fIMAPMailboxListener;
IMAPMailboxListener fNULLListener; IMAPMailboxListener fNULLListener;
MailboxSelectHandler fMailboxSelectHandler; MailboxSelectHandler fMailboxSelectHandler;
CapabilityHandler fCapabilityHandler; CapabilityHandler fCapabilityHandler;
ExistsHandler fExistsHandler; ExistsHandler fExistsHandler;
ExpungeHandler fExpungeHandler; ExpungeHandler fExpungeHandler;
@@ -1,3 +1,11 @@
/*
* Copyright 2010-2011, Haiku Inc. All Rights Reserved.
* Copyright 2010 Clemens Zeidler. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
#include "IMAPProtocol.h" #include "IMAPProtocol.h"
#include "IMAPHandler.h" #include "IMAPHandler.h"
@@ -5,12 +13,11 @@
#define DEBUG_IMAP_PROTOCOL #define DEBUG_IMAP_PROTOCOL
#ifdef DEBUG_IMAP_PROTOCOL #ifdef DEBUG_IMAP_PROTOCOL
#include <stdio.h> # include <stdio.h>
#define TRACE(x...) printf(x) # define TRACE(x...) printf(x)
#else #else
#define TRACE(x...) /* nothing */ # define TRACE(x...) ;
#endif #endif
@@ -18,7 +25,6 @@ ConnectionReader::ConnectionReader(ServerConnection* connection)
: :
fServerConnection(connection) fServerConnection(connection)
{ {
} }
@@ -137,7 +143,7 @@ IMAPProtocol::IMAPProtocol()
: :
fServerConnection(&fOwnServerConnection), fServerConnection(&fOwnServerConnection),
fConnectionReader(fServerConnection), fConnectionReader(fServerConnection),
fCommandId(0), fCommandID(0),
fStopNow(0), fStopNow(0),
fIsConnected(false) fIsConnected(false)
{ {
@@ -148,7 +154,7 @@ IMAPProtocol::IMAPProtocol(IMAPProtocol& connection)
: :
fServerConnection(connection.fServerConnection), fServerConnection(connection.fServerConnection),
fConnectionReader(fServerConnection), fConnectionReader(fServerConnection),
fCommandId(0), fCommandID(0),
fStopNow(0), fStopNow(0),
fIsConnected(false) fIsConnected(false)
{ {
@@ -285,13 +291,13 @@ IMAPProtocol::ProcessCommand(const char* command, bigtime_t timeout)
status_t status_t
IMAPProtocol::SendCommand(const char* command, int32 commandId) IMAPProtocol::SendCommand(const char* command, int32 commandID)
{ {
if (strlen(command) + 10 > 256) if (strlen(command) + 10 > 256)
return B_NO_MEMORY; return B_NO_MEMORY;
static char cmd[256]; static char cmd[256];
::sprintf(cmd, "A%.7ld %s"CRLF, commandId, command); ::sprintf(cmd, "A%.7ld %s"CRLF, commandID, command);
TRACE("_SendCommand: %s\n", cmd); TRACE("_SendCommand: %s\n", cmd);
int commandLength = strlen(cmd); int commandLength = strlen(cmd);
@@ -301,13 +307,14 @@ IMAPProtocol::SendCommand(const char* command, int32 commandId)
return B_ERROR; return B_ERROR;
} }
fOngoingCommands.push_back(commandId); fOngoingCommands.push_back(commandID);
return B_OK; return B_OK;
} }
status_t status_t
IMAPProtocol::HandleResponse(int32 commandId, bigtime_t timeout, bool disconnectOnTimeout) IMAPProtocol::HandleResponse(int32 commandID, bigtime_t timeout,
bool disconnectOnTimeout)
{ {
status_t commandStatus = B_ERROR; status_t commandStatus = B_ERROR;
@@ -342,7 +349,7 @@ IMAPProtocol::HandleResponse(int32 commandId, bigtime_t timeout, bool disconnect
static char idString[8]; static char idString[8];
::sprintf(idString, "A%.7ld", *it); ::sprintf(idString, "A%.7ld", *it);
if (line.FindFirst(idString) >= 0) { if (line.FindFirst(idString) >= 0) {
if (*it == commandId) { if (*it == commandID) {
BString result = IMAPParser::ExtractElementAfter(line, BString result = IMAPParser::ExtractElementAfter(line,
idString); idString);
if (result == "OK") if (result == "OK")
@@ -379,10 +386,10 @@ IMAPProtocol::ProcessAfterQuacks(bigtime_t timeout)
int32 int32
IMAPProtocol::NextCommandId() IMAPProtocol::NextCommandID()
{ {
fCommandId++; fCommandID++;
return fCommandId; return fCommandID;
} }
@@ -408,12 +415,12 @@ status_t
IMAPProtocol::_ProcessCommandWithoutAfterQuake(const char* command, IMAPProtocol::_ProcessCommandWithoutAfterQuake(const char* command,
bigtime_t timeout) bigtime_t timeout)
{ {
int32 commandId = NextCommandId(); int32 commandID = NextCommandID();
status_t status = SendCommand(command, commandId); status_t status = SendCommand(command, commandID);
if (status != B_OK) if (status != B_OK)
return status; return status;
return HandleResponse(commandId, timeout); return HandleResponse(commandID, timeout);
} }
@@ -97,7 +97,7 @@ protected:
bigtime_t timeout = kIMAP4ClientTimeout, bigtime_t timeout = kIMAP4ClientTimeout,
bool disconnectOnTimeout = true); bool disconnectOnTimeout = true);
void ProcessAfterQuacks(bigtime_t timeout); void ProcessAfterQuacks(bigtime_t timeout);
int32 NextCommandId(); int32 NextCommandID();
ServerConnection* fServerConnection; ServerConnection* fServerConnection;
ServerConnection fOwnServerConnection; ServerConnection fOwnServerConnection;
@@ -115,7 +115,7 @@ private:
bigtime_t timeout = kIMAP4ClientTimeout); bigtime_t timeout = kIMAP4ClientTimeout);
status_t _Disconnect(); status_t _Disconnect();
int32 fCommandId; int32 fCommandID;
std::vector<int32> fOngoingCommands; std::vector<int32> fOngoingCommands;
BString fCommandError; BString fCommandError;