This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
166 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "CommandFactory.h" | ||
#include "Visit.h" | ||
#include "Find.h" | ||
#include "Command.h" | ||
#include "Reset.h" | ||
#include "Node.h" | ||
#include "Url.h" | ||
#include "Source.h" | ||
#include "Evaluate.h" | ||
#include "Execute.h" | ||
#include "FrameFocus.h" | ||
#include "Header.h" | ||
#include "Render.h" | ||
#include "Body.h" | ||
#include "Status.h" | ||
#include "Headers.h" | ||
#include "SetCookie.h" | ||
#include "ClearCookies.h" | ||
#include "GetCookies.h" | ||
|
||
CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) { | ||
m_page = page; | ||
} | ||
|
||
Command *CommandFactory::createCommand(const char *name) { | ||
#include "find_command.h" | ||
return NULL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <QObject> | ||
|
||
class Command; | ||
class WebPage; | ||
|
||
class CommandFactory : public QObject { | ||
Q_OBJECT | ||
|
||
public: | ||
CommandFactory(WebPage *page, QObject *parent = 0); | ||
Command *createCommand(const char *name); | ||
|
||
private: | ||
WebPage *m_page; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "CommandParser.h" | ||
|
||
#include <QIODevice> | ||
|
||
CommandParser::CommandParser(QIODevice *device, QObject *parent) : | ||
QObject(parent) { | ||
m_device = device; | ||
m_expectingDataSize = -1; | ||
connect(m_device, SIGNAL(readyRead()), this, SLOT(checkNext())); | ||
} | ||
|
||
void CommandParser::checkNext() { | ||
if (m_expectingDataSize == -1) { | ||
if (m_device->canReadLine()) { | ||
readLine(); | ||
checkNext(); | ||
} | ||
} else { | ||
if (m_device->bytesAvailable() >= m_expectingDataSize) { | ||
readDataBlock(); | ||
checkNext(); | ||
} | ||
} | ||
} | ||
|
||
void CommandParser::readLine() { | ||
char buffer[128]; | ||
qint64 lineLength = m_device->readLine(buffer, 128); | ||
if (lineLength != -1) { | ||
buffer[lineLength - 1] = 0; | ||
processNext(buffer); | ||
} | ||
} | ||
|
||
void CommandParser::readDataBlock() { | ||
char *buffer = new char[m_expectingDataSize + 1]; | ||
m_device->read(buffer, m_expectingDataSize); | ||
buffer[m_expectingDataSize] = 0; | ||
processNext(buffer); | ||
m_expectingDataSize = -1; | ||
delete[] buffer; | ||
} | ||
|
||
void CommandParser::processNext(const char *data) { | ||
if (m_commandName.isNull()) { | ||
m_commandName = data; | ||
m_argumentsExpected = -1; | ||
} else { | ||
processArgument(data); | ||
} | ||
} | ||
|
||
void CommandParser::processArgument(const char *data) { | ||
if (m_argumentsExpected == -1) { | ||
m_argumentsExpected = QString(data).toInt(); | ||
} else if (m_expectingDataSize == -1) { | ||
m_expectingDataSize = QString(data).toInt(); | ||
} else { | ||
m_arguments.append(QString::fromUtf8(data)); | ||
} | ||
|
||
if (m_arguments.length() == m_argumentsExpected) { | ||
emit commandReady(m_commandName, m_arguments); | ||
m_commandName = QString(); | ||
m_arguments.clear(); | ||
m_argumentsExpected = -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <QObject> | ||
#include <QStringList> | ||
|
||
class QIODevice; | ||
|
||
class CommandParser : public QObject { | ||
Q_OBJECT | ||
|
||
public: | ||
CommandParser(QIODevice *device, QObject *parent = 0); | ||
|
||
public slots: | ||
void checkNext(); | ||
|
||
signals: | ||
void commandReady(QString commandName, QStringList arguments); | ||
|
||
private: | ||
void readLine(); | ||
void readDataBlock(); | ||
void processNext(const char *line); | ||
void processArgument(const char *data); | ||
QIODevice *m_device; | ||
QString m_commandName; | ||
QStringList m_arguments; | ||
int m_argumentsExpected; | ||
int m_expectingDataSize; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters