2009-11-23 02:08:22 -06:00
|
|
|
#ifndef _USER_SCRIPT_H
|
|
|
|
#define _USER_SCRIPT_H
|
|
|
|
|
|
|
|
#include "abstractprotocol.h"
|
|
|
|
#include "userscript.pb.h"
|
|
|
|
#include "ui_userscript.h"
|
|
|
|
|
|
|
|
#include <QScriptEngine>
|
|
|
|
#include <QScriptValue>
|
|
|
|
|
|
|
|
class UserScriptProtocol;
|
|
|
|
|
|
|
|
class UserProtocol : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
Q_ENUMS(ProtocolIdType);
|
2009-11-28 02:35:05 -06:00
|
|
|
Q_ENUMS(CksumType);
|
2009-11-23 02:08:22 -06:00
|
|
|
|
|
|
|
Q_PROPERTY(QString name READ name WRITE setName);
|
|
|
|
Q_PROPERTY(bool protocolFrameValueVariable
|
|
|
|
READ isProtocolFrameValueVariable
|
|
|
|
WRITE setProtocolFrameValueVariable);
|
|
|
|
Q_PROPERTY(bool protocolFrameSizeVariable
|
|
|
|
READ isProtocolFrameSizeVariable
|
|
|
|
WRITE setProtocolFrameSizeVariable);
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum ProtocolIdType
|
|
|
|
{
|
|
|
|
ProtocolIdLlc = AbstractProtocol::ProtocolIdLlc,
|
|
|
|
ProtocolIdEth = AbstractProtocol::ProtocolIdEth,
|
|
|
|
ProtocolIdIp = AbstractProtocol::ProtocolIdIp
|
|
|
|
};
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
enum CksumType
|
|
|
|
{
|
|
|
|
CksumIp = AbstractProtocol::CksumIp,
|
|
|
|
CksumIpPseudo = AbstractProtocol::CksumIpPseudo,
|
|
|
|
CksumTcpUdp = AbstractProtocol::CksumTcpUdp
|
|
|
|
};
|
2009-11-23 02:08:22 -06:00
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
UserProtocol(AbstractProtocol *parent);
|
2009-11-23 02:08:22 -06:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
QString name() const;
|
|
|
|
void setName(QString &name);
|
|
|
|
|
|
|
|
bool isProtocolFrameValueVariable() const;
|
|
|
|
void setProtocolFrameValueVariable(bool variable);
|
|
|
|
bool isProtocolFrameSizeVariable() const;
|
|
|
|
void setProtocolFrameSizeVariable(bool variable);
|
|
|
|
|
|
|
|
quint32 payloadProtocolId(UserProtocol::ProtocolIdType type) const;
|
|
|
|
int protocolFrameOffset(int streamIndex = 0) const;
|
|
|
|
int protocolFramePayloadSize(int streamIndex = 0) const;
|
|
|
|
|
|
|
|
bool isProtocolFramePayloadValueVariable() const;
|
|
|
|
bool isProtocolFramePayloadSizeVariable() const;
|
|
|
|
|
|
|
|
quint32 protocolFrameHeaderCksum(int streamIndex = 0,
|
|
|
|
AbstractProtocol::CksumType cksumType = AbstractProtocol::CksumIp) const;
|
|
|
|
quint32 protocolFramePayloadCksum(int streamIndex = 0,
|
|
|
|
AbstractProtocol::CksumType cksumType = AbstractProtocol::CksumIp) const;
|
|
|
|
|
|
|
|
private:
|
2009-11-28 02:35:05 -06:00
|
|
|
AbstractProtocol *parent_;
|
2009-11-23 02:08:22 -06:00
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
QString name_;
|
|
|
|
bool protocolFrameValueVariable_;
|
|
|
|
bool protocolFrameSizeVariable_;
|
2009-11-23 02:08:22 -06:00
|
|
|
};
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
|
|
|
|
|
2009-11-23 02:08:22 -06:00
|
|
|
class UserScriptConfigForm : public QWidget, public Ui::UserScript
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
UserScriptConfigForm(UserScriptProtocol *protocol, QWidget *parent = 0);
|
|
|
|
|
|
|
|
private:
|
2009-11-28 02:35:05 -06:00
|
|
|
void updateStatus();
|
|
|
|
UserScriptProtocol *protocol_;
|
2009-11-23 02:08:22 -06:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void on_programEdit_textChanged();
|
|
|
|
void on_compileButton_clicked(bool checked = false);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
|
2009-11-23 02:08:22 -06:00
|
|
|
class UserScriptProtocol : public AbstractProtocol
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
UserScriptProtocol(StreamBase *stream, AbstractProtocol *parent = 0);
|
|
|
|
virtual ~UserScriptProtocol();
|
|
|
|
|
|
|
|
static AbstractProtocol* createInstance(StreamBase *stream,
|
|
|
|
AbstractProtocol *parent = 0);
|
|
|
|
virtual quint32 protocolNumber() const;
|
|
|
|
|
|
|
|
virtual void protoDataCopyInto(OstProto::Protocol &protocol) const;
|
|
|
|
virtual void protoDataCopyFrom(const OstProto::Protocol &protocol);
|
|
|
|
|
|
|
|
virtual quint32 protocolId(ProtocolIdType type) const;
|
|
|
|
|
|
|
|
virtual QString name() const;
|
|
|
|
virtual QString shortName() const;
|
|
|
|
|
|
|
|
virtual int fieldCount() const;
|
|
|
|
|
|
|
|
virtual QVariant fieldData(int index, FieldAttrib attrib,
|
|
|
|
int streamIndex = 0) const;
|
|
|
|
virtual bool setFieldData(int index, const QVariant &value,
|
|
|
|
FieldAttrib attrib = FieldValue);
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
virtual int protocolFrameSize(int streamIndex = 0) const;
|
|
|
|
|
2009-11-23 02:08:22 -06:00
|
|
|
virtual bool isProtocolFrameValueVariable() const;
|
|
|
|
virtual bool isProtocolFrameSizeVariable() const;
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
virtual quint32 protocolFrameCksum(int streamIndex = 0,
|
|
|
|
CksumType cksumType = CksumIp) const;
|
|
|
|
|
2009-11-23 02:08:22 -06:00
|
|
|
virtual QWidget* configWidget();
|
|
|
|
virtual void loadConfigWidget();
|
|
|
|
virtual void storeConfigWidget();
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
void evaluateUserScript() const;
|
|
|
|
bool isScriptValid() const;
|
2009-11-23 02:08:22 -06:00
|
|
|
int userScriptErrorLineNumber() const;
|
|
|
|
QString userScriptErrorText() const;
|
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
private:
|
2009-11-23 02:08:22 -06:00
|
|
|
int userScriptLineCount() const;
|
|
|
|
|
|
|
|
enum userScriptfield
|
|
|
|
{
|
|
|
|
// Frame Fields
|
|
|
|
userScript_program = 0,
|
|
|
|
|
|
|
|
userScript_fieldCount
|
|
|
|
};
|
2009-11-28 02:35:05 -06:00
|
|
|
OstProto::UserScript data;
|
|
|
|
UserScriptConfigForm *configForm;
|
2009-11-23 02:08:22 -06:00
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
mutable QScriptEngine engine_;
|
|
|
|
mutable UserProtocol userProtocol_;
|
|
|
|
mutable QScriptValue userProtocolScriptValue_;
|
2009-11-23 02:08:22 -06:00
|
|
|
|
2009-11-28 02:35:05 -06:00
|
|
|
mutable bool isScriptValid_;
|
|
|
|
mutable int errorLineNumber_;
|
|
|
|
mutable QString errorText_;
|
2009-11-23 02:08:22 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim: set shiftwidth=4 tabstop=8 softtabstop=4 expandtab: */
|