Commit d3ef8ffb authored by Laurent Montel's avatar Laurent Montel 😁

Coding style

parent 2338035a
......@@ -47,7 +47,8 @@ using std::endl;
static const char *token2string(Lexer::Token t)
{
switch (t) {
#define CASE(x) case Lexer::x: return #x
#define CASE(x) case Lexer::x: \
return #x
CASE(None);
CASE(HashComment);
CASE(BracketComment);
......@@ -269,8 +270,7 @@ static const TestCase testcases[] = {
{ { Lexer::Special, "{" }, { Lexer::Special, "}" },
{ Lexer::Special, "[" }, { Lexer::Special, "]" },
{ Lexer::Special, "(" }, { Lexer::Special, ")" },
{ Lexer::Special, ";" }, { Lexer::Special, "," }, { Lexer::None, nullptr }
},
{ Lexer::Special, ";" }, { Lexer::Special, "," }, { Lexer::None, nullptr }},
Error::None, 0, 0
},
//
......@@ -438,24 +438,20 @@ static const TestCase testcases[] = {
{ Lexer::LineFeeds, "1" },
{ Lexer::Identifier, "bar" },
{ Lexer::LineFeeds, "1" },
{ Lexer::None, nullptr }
},
{ Lexer::None, nullptr }},
Error::None, 0, 0
},
//
// Whitespace / token separation: invalid
//
};
static const int numTestCases = sizeof testcases / sizeof * testcases;
static const int numTestCases = sizeof testcases / sizeof *testcases;
int main(int argc, char *argv[])
{
if (argc == 2) { // manual test
const char *scursor = argv[1];
const char *const send = argv[1] + qstrlen(argv[1]);
......@@ -471,13 +467,13 @@ int main(int argc, char *argv[])
<< lexer.error().line() << "," << lexer.error().column()
<< ")" << endl;
break;
} else
} else {
cout << "Got " << token2string(token) << ": \""
<< result.toUtf8().data() << "\" at ("
<< lexer.line() << "," << lexer.column() << ")" << endl;
}
}
cout << "End" << endl;
} else if (argc == 1) { // automated test
bool success = true;
for (int i = 0; i < numTestCases; ++i) {
......@@ -521,8 +517,8 @@ int main(int argc, char *argv[])
if (error) {
goto ErrorOut;
}
if (t.expected[j].token == Lexer::None &&
t.expected[j].result == nullptr) {
if (t.expected[j].token == Lexer::None
&& t.expected[j].result == nullptr) {
break;
}
}
......@@ -530,7 +526,7 @@ int main(int argc, char *argv[])
ok = false;
cerr << " premature end of expected token list";
}
ErrorOut:
ErrorOut:
if (ok) {
cerr << " ok";
}
......
This diff is collapsed.
......@@ -33,8 +33,8 @@ inline bool initSASL()
#ifdef Q_OS_WIN32 //krazy:exclude=cpp
QByteArray libInstallPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("lib") + QLatin1String("sasl2"))));
QByteArray configPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("config") + QLatin1String("sasl2"))));
if (sasl_set_path(SASL_PATH_TYPE_PLUGIN, libInstallPath.data()) != SASL_OK ||
sasl_set_path(SASL_PATH_TYPE_CONFIG, configPath.data()) != SASL_OK) {
if (sasl_set_path(SASL_PATH_TYPE_PLUGIN, libInstallPath.data()) != SASL_OK
|| sasl_set_path(SASL_PATH_TYPE_CONFIG, configPath.data()) != SASL_OK) {
fprintf(stderr, "SASL path initialization failed!\n");
return false;
}
......
This diff is collapsed.
......@@ -52,8 +52,8 @@ public:
void clear();
protected:
uint rType;
uint quantity;
uint rType;
uint quantity;
QByteArray key;
QByteArray val;
QByteArray extra;
......@@ -61,7 +61,6 @@ protected:
class kio_sieveProtocol : public KIO::TCPSlaveBase
{
public:
enum connectionModes {
NORMAL,
......@@ -116,23 +115,23 @@ protected:
bool saslInteract(void *in, KIO::AuthInfo &ai);
// IOSlave global data
uint m_connMode;
uint m_connMode;
// Host-specific data
QStringList m_sasl_caps;
bool m_supportsTLS;
QStringList m_sasl_caps;
bool m_supportsTLS;
// Global server respose class
kio_sieveResponse r;
// connection details
QString m_sServer;
QString m_sUser;
QString m_sPass;
QString m_sAuth;
bool m_shouldBeConnected;
bool m_allowUnencrypted;
quint16 m_port;
QString m_sServer;
QString m_sUser;
QString m_sPass;
QString m_sAuth;
bool m_shouldBeConnected;
bool m_allowUnencrypted;
quint16 m_port;
private:
bool requestCapabilitiesAfterStartTLS() const;
......
......@@ -40,9 +40,7 @@
#include <QStack>
namespace KSieve
{
namespace KSieve {
class Lexer::Impl
{
public:
......@@ -128,7 +126,13 @@ private:
struct State {
State(const char *s = nullptr)
: cursor(s), line(0), beginOfLine(s), error() {}
: cursor(s)
, line(0)
, beginOfLine(s)
, error()
{
}
const char *cursor;
int line;
const char *beginOfLine;
......@@ -137,10 +141,10 @@ private:
const char *const mEnd;
const bool mIgnoreComments : 1;
const bool mIgnoreLF : 1;
QStack<State> mStateStack;
const bool mIgnoreLF : 1;
QStack<State> mStateStack;
const char *beginOfLine() const
const char *beginOfLine() const
{
return mState.beginOfLine;
}
......@@ -159,19 +163,23 @@ private:
{
return mEnd - mState.cursor < 0 ? 0 : mEnd - mState.cursor;
}
void makeError(Error::Type e)
{
makeError(e, line(), column());
}
void makeError(Error::Type e, int errorLine, int errorCol)
{
mState.error = Error(e, errorLine, errorCol);
}
void makeIllegalCharError(char ch);
void makeIllegalCharError()
{
makeIllegalCharError(*mState.cursor);
}
/** Defines the current char to end a line.
Warning: increases @p mCursor!
**/
......@@ -180,6 +188,7 @@ private:
++mState.line;
mState.beginOfLine = ++mState.cursor;
}
bool skipTo(char c, bool acceptEnd = false)
{
while (!atEnd()) {
......@@ -195,23 +204,26 @@ private:
}
return acceptEnd;
}
bool skipToCRLF(bool acceptEnd = true)
{
for (; !atEnd(); ++mState.cursor)
for (; !atEnd(); ++mState.cursor) {
if (*mState.cursor == '\n' || *mState.cursor == '\r') {
return eatCRLF();
}
}
return acceptEnd;
}
void skipTo8BitEnd()
{
while (!atEnd() && (signed char)*mState.cursor < 0) {
++mState.cursor;
}
}
void skipToDelim();
};
}
#endif
......@@ -43,9 +43,7 @@
#include <ksieve/scriptbuilder.h>
namespace KSieve
{
namespace KSieve {
class Parser::Impl
{
friend class Parser;
......@@ -56,6 +54,7 @@ private:
{
mBuilder = builder;
}
ScriptBuilder *scriptBuilder() const
{
return mBuilder;
......@@ -90,6 +89,7 @@ private:
{
return mToken;
}
QString tokenValue() const
{
return mTokenValue;
......@@ -99,12 +99,14 @@ private:
{
return !mToken && lexer.atEnd();
}
bool obtainToken();
void consumeToken()
{
mToken = Lexer::None;
mTokenValue.clear();
}
void makeError(Error::Type e, int line, int col)
{
mError = Error(e, line, col);
......@@ -112,14 +114,17 @@ private:
scriptBuilder()->error(mError);
}
}
void makeError(Error::Type e)
{
makeError(e, lexer.line(), lexer.column());
}
void makeUnexpectedTokenError(Error::Type e)
{
makeError(e); // ### save wrong token...
}
bool isArgumentToken() const;
bool isStringToken() const;
......@@ -129,7 +134,6 @@ private:
Lexer::Impl lexer;
ScriptBuilder *mBuilder;
};
}
#endif
......@@ -33,11 +33,8 @@
#ifndef KSIEVE_IMPL_UTF8VALIDATOR_H
#define KSIEVE_IMPL_UTF8VALIDATOR_H
namespace KSieve
{
namespace KSieve {
extern bool isValidUtf8(const char *s, unsigned int len);
} // namespace KSieve
#endif
......@@ -77,7 +77,8 @@ bool KManageSieve::Response::parseResponse(const QByteArray &line)
clear();
switch (line.at(0)) {
case '{': {
case '{':
{
m_type = Quantity;
bool ok = false;
m_quantity = parseQuantity(line, 0, &ok);
......@@ -87,7 +88,8 @@ bool KManageSieve::Response::parseResponse(const QByteArray &line)
// expecting "key" "value" pairs
m_type = KeyValuePair;
break;
default: {
default:
{
// expecting single string
m_type = Action;
m_key = line;
......@@ -115,9 +117,8 @@ bool KManageSieve::Response::parseResponse(const QByteArray &line)
start = line.indexOf('"', end + 1);
if (start == -1) {
if (line.length() > end)
if (line.length() > end) {
// skip " and space
{
m_extra = line.right(line.length() - end - 2);
}
return true;
......@@ -142,7 +143,7 @@ KManageSieve::Response::Result KManageSieve::Response::operationResult() const
return Ok;
} else if (response == "NO") {
return No;
} else if (response == "BY"/*E*/) {
} else if (response == "BY" /*E*/) {
return Bye;
}
}
......
......@@ -23,9 +23,7 @@
#include <QByteArray>
namespace KManageSieve
{
namespace KManageSieve {
/** A response from a managesieve server.
* @internal
*/
......@@ -40,10 +38,11 @@ public:
};
Response()
: m_type(None),
m_quantity(0)
: m_type(None)
, m_quantity(0)
{
}
Type type() const;
QByteArray action() const;
uint quantity() const;
......@@ -71,7 +70,6 @@ private:
QByteArray m_value;
QByteArray m_extra;
};
}
#endif
......@@ -40,7 +40,7 @@ inline bool initSASL()
QByteArray libInstallPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("lib") + QLatin1String("sasl2"))));
QByteArray configPath(QFile::encodeName(QDir::toNativeSeparators(KGlobal::dirs()->installPath("config") + QLatin1String("sasl2"))));
if (sasl_set_path(SASL_PATH_TYPE_PLUGIN, libInstallPath.data()) != SASL_OK
|| sasl_set_path(SASL_PATH_TYPE_CONFIG, configPath.data()) != SASL_OK) {
|| sasl_set_path(SASL_PATH_TYPE_CONFIG, configPath.data()) != SASL_OK) {
fprintf(stderr, "SASL path initialization failed!\n");
return false;
}
......
......@@ -41,14 +41,14 @@ Q_DECLARE_METATYPE(KManageSieve::AuthDetails)
Q_DECLARE_METATYPE(KManageSieve::Response)
Q_DECLARE_METATYPE(KSslErrorUiData)
Session::Session(QObject *parent) :
QObject(parent),
m_thread(new SessionThread(this)),
m_currentJob(nullptr),
m_state(None),
m_supportsStartTls(false),
m_connected(false),
m_disconnected(true)
Session::Session(QObject *parent)
: QObject(parent)
, m_thread(new SessionThread(this))
, m_currentJob(nullptr)
, m_state(None)
, m_supportsStartTls(false)
, m_connected(false)
, m_disconnected(true)
{
qRegisterMetaType<KManageSieve::AuthDetails>();
qRegisterMetaType<KManageSieve::Response>();
......@@ -68,7 +68,7 @@ Session::Session(QObject *parent) :
connect(m_thread, &SessionThread::sslDone,
this, &Session::sslDone);
connect(m_thread, &SessionThread::socketDisconnected,
[ = ]() {
[=]() {
m_connected = false;
m_disconnected = true;
});
......@@ -117,12 +117,12 @@ void Session::processResponse(const KManageSieve::Response &response, const QByt
disconnectFromHost();
return;
}
if (!allowUnencrypted() && QSslSocket::supportsSsl() && !m_supportsStartTls &&
KMessageBox::warningContinueCancel(nullptr,
i18n("TLS encryption was requested, but your Sieve server does not advertise TLS in its capabilities.\n"
"You can choose to try to initiate TLS negotiations nonetheless, or cancel the operation."),
i18n("Server Does Not Advertise TLS"), KGuiItem(i18n("&Start TLS nonetheless")), KStandardGuiItem::cancel(),
QStringLiteral("ask_starttls_%1").arg(m_url.host())) != KMessageBox::Continue) {
if (!allowUnencrypted() && QSslSocket::supportsSsl() && !m_supportsStartTls
&& KMessageBox::warningContinueCancel(nullptr,
i18n("TLS encryption was requested, but your Sieve server does not advertise TLS in its capabilities.\n"
"You can choose to try to initiate TLS negotiations nonetheless, or cancel the operation."),
i18n("Server Does Not Advertise TLS"), KGuiItem(i18n("&Start TLS nonetheless")), KStandardGuiItem::cancel(),
QStringLiteral("ask_starttls_%1").arg(m_url.host())) != KMessageBox::Continue) {
setErrorMessage(KIO::buildErrorString(KIO::ERR_USER_CANCELED, i18n("TLS encryption requested, but not supported by server.")));
disconnectFromHost();
return;
......@@ -277,11 +277,11 @@ KManageSieve::AuthDetails Session::requestAuthDetails(const QUrl &url)
ai.comment = i18n("Please enter your authentication details for your sieve account "
"(usually the same as your email password):");
QPointer<KPasswordDialog> dlg =
new KPasswordDialog(
QPointer<KPasswordDialog> dlg
= new KPasswordDialog(
nullptr,
KPasswordDialog::ShowUsernameLine | KPasswordDialog::ShowKeepPassword
);
);
dlg->setUsername(ai.username);
dlg->setPassword(ai.password);
dlg->setKeepPassword(ai.keepPassword);
......
......@@ -31,9 +31,7 @@
class KSslErrorUiData;
namespace KManageSieve
{
namespace KManageSieve {
class SieveJob;
class SessionThread;
......@@ -106,7 +104,6 @@ private:
friend class SessionThread;
};
}
#endif
......@@ -275,8 +275,7 @@ void SessionThread::doStartAuthentication()
}
// Called in main thread
void SessionThread::continueAuthentication(const Response