Author: saces Date: 2009-01-19 19:39:19 +0000 (Mon, 19 Jan 2009) New Revision: 25124
Added: trunk/apps/wxFCP/include/wx/fcp/connection.h trunk/apps/wxFCP/include/wx/fcp/ioconnection.h trunk/apps/wxFCP/include/wx/fcp/logger.h trunk/apps/wxFCP/include/wx/fcp/message.h trunk/apps/wxFCP/src/fcp/connection.cpp trunk/apps/wxFCP/src/fcp/ioconnection.cpp trunk/apps/wxFCP/src/fcp/logger.cpp trunk/apps/wxFCP/src/fcp/message.cpp Modified: trunk/apps/wxFCP/include/wx/fcp/fcp.h trunk/apps/wxFCP/samples/fcp/nodeinfo.cpp Log: initial files Added: trunk/apps/wxFCP/include/wx/fcp/connection.h =================================================================== --- trunk/apps/wxFCP/include/wx/fcp/connection.h (rev 0) +++ trunk/apps/wxFCP/include/wx/fcp/connection.h 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,57 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/fcp/connection.h +// Purpose: declaration for fcp connections +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _FCP_CONNECTION_H_ +#define _FCP_CONNECTION_H_ + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include <wx/socket.h> + +#include "wx/fcp/ioconnection.h" +#include "wx/fcp/message.h" + +class wxFCPConnection : protected wxFCPIOConnection +{ +public: + + wxFCPConnection(wxString *host, wxUint16 port, wxUint32 timeout, wxFCPLogger *logger=NULL); + + bool setFCPLogger(wxFCPLogger *logger); + bool Connect(); + bool ReConnect(); + bool Close(bool flush=false); + bool IsConnected(); + bool readLine(wxString& line); + +public: + bool readEndMessage(wxFCPNodeMessage& message); + bool sendCommand(wxFCPCommand *command); + bool sendCommand(wxFCPCommand& command); +private: +#if wxUSE_IPV6 + wxIPV6address m_sockaddress; +#else + wxIPV4address m_sockaddress; +#endif + wxUint32 m_timeout; + wxFCPNodeMessage* m_nodehellomessage; +}; + +// async stuff +class wxFCPConnectionRunner : protected wxFCPConnection +{ +}; + +#endif // ifndef _FCP_CONNECTION_H_ Modified: trunk/apps/wxFCP/include/wx/fcp/fcp.h =================================================================== --- trunk/apps/wxFCP/include/wx/fcp/fcp.h 2009-01-17 23:59:33 UTC (rev 25123) +++ trunk/apps/wxFCP/include/wx/fcp/fcp.h 2009-01-19 19:39:19 UTC (rev 25124) @@ -17,12 +17,49 @@ #include "wx/wx.h" #endif -#define DEFAULT_FCP_HOST "127.0.0.1" -#define DEFAULT_FCP_PORT 9481 -#define DEFAULT_FCP_TIMEOUT 300 +#ifndef DEFAULT_FCP_HOST + #define DEFAULT_FCP_HOST "127.0.0.1" +#endif -#define FCP_HOST_ENV_NAME "FCP_HOST" -#define FCP_PORT_ENV_NAME "FCP_PORT" -#define FCP_TIMEOUT_ENV_NAME "FCP_TIMEOUT" +#ifndef DEFAULT_FCP_PORT + #define DEFAULT_FCP_PORT 9481 +#endif +#ifndef DEFAULT_FCP_TIMEOUT + #define DEFAULT_FCP_TIMEOUT 300 +#endif + +#ifndef FCP_HOST_ENV_NAME + #define FCP_HOST_ENV_NAME "FCP_HOST" +#endif + +#ifndef FCP_PORT_ENV_NAME + #define FCP_PORT_ENV_NAME "FCP_PORT" +#endif + +#ifndef FCP_TIMEOUT_ENV_NAME + #define FCP_TIMEOUT_ENV_NAME "FCP_TIMEOUT" +#endif + +#ifndef REQUIRED_NODE_VERSION + #define REQUIRED_NODE_VERSION 1197 +#endif + +#ifndef REQUIRED_NODE_BUILD + #define REQUIRED_NODE_BUILD 25053 +#endif + +#ifndef REQUIRED_EXT_VERSION + #define REQUIRED_EXT_VERSION 26 +#endif + +#ifndef REQUIRED_EXT_BUILD + #define REQUIRED_EXT_BUILD 23771 +#endif + +#include "wx/fcp/connection.h" +#include "wx/fcp/message.h" +#include "wx/fcp/job.h" +#include "wx/fcp/session.h" + #endif // ifndef _FCP_FCP_H_ Added: trunk/apps/wxFCP/include/wx/fcp/ioconnection.h =================================================================== --- trunk/apps/wxFCP/include/wx/fcp/ioconnection.h (rev 0) +++ trunk/apps/wxFCP/include/wx/fcp/ioconnection.h 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,48 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/fcp/ioconnection.h +// Purpose: declaration for fcp io connections +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _FCP_IOCONNECTION_H_ +#define _FCP_IOCONNECTION_H_ + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/fcp/logger.h" +#include <wx/socket.h> + +class wxFCPIOConnection +{ +protected: + wxFCPIOConnection(); + ~wxFCPIOConnection(); + + bool setFCPLogger(wxFCPLogger *fcplogger); + void setTimeout(wxUint32 timeout); + bool Connect(wxSockAddress& sockaddress); + bool ReConnect(); + bool Close(bool flush=false); + bool isOK(); + bool IsConnected(); + + bool writeLine(const wxString& line); + bool readLine(wxString& line); + bool writeData(const void* buffer, wxUint32 nbytes); + bool readData(void* buffer, wxUint32 nbytes); + +private: + wxSocketClient *m_sock; + wxFCPLogger *m_fcplogger; + bool write(const void* buffer, wxUint32 nbytes); +}; + +#endif // ifndef _FCP_IOCONNECTION_H_ Added: trunk/apps/wxFCP/include/wx/fcp/logger.h =================================================================== --- trunk/apps/wxFCP/include/wx/fcp/logger.h (rev 0) +++ trunk/apps/wxFCP/include/wx/fcp/logger.h 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,50 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/fcp/logger.h +// Purpose: declaration for fcp logger +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _FCP_LOGGER_H_ +#define _FCP_LOGGER_H_ + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +class wxFCPLogger +{ +public: + wxFCPLogger() {}; + virtual ~wxFCPLogger() {}; + + virtual void incomingLine(const wxString& line)=0; + virtual void outgoingLine(const wxString& line)=0; + virtual void incomingData(const wxUint32 nbytes)=0; + virtual void outgoingData(const wxUint32 nbytes)=0; +}; + +class wxFCPNullLogger : public wxFCPLogger +{ +public: + virtual void incomingLine(const wxString& WXUNUSED(line)) { } + virtual void outgoingLine(const wxString& WXUNUSED(line)) { } + virtual void incomingData(const wxUint32 WXUNUSED(nbytes)) { } + virtual void outgoingData(const wxUint32 WXUNUSED(nbytes)) { } +}; + +class wxFCPSimpleLogger : public wxFCPLogger +{ +public: + virtual void incomingLine(const wxString& line); + virtual void outgoingLine(const wxString& line); + virtual void incomingData(const wxUint32 nbytes); + virtual void outgoingData(const wxUint32 nbytes); +}; + +#endif // ifndef _FCP_LOGGER_H_ Added: trunk/apps/wxFCP/include/wx/fcp/message.h =================================================================== --- trunk/apps/wxFCP/include/wx/fcp/message.h (rev 0) +++ trunk/apps/wxFCP/include/wx/fcp/message.h 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/fcp/message.h +// Purpose: declaration for fcp messages +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _FCP_MESSAGE_H_ +#define _FCP_MESSAGE_H_ + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +WX_DECLARE_STRING_HASH_MAP( wxString, MessageItems ); + +class wxFCPBaseMessage +{ +public: + wxFCPBaseMessage(); + virtual ~wxFCPBaseMessage(); + wxString toString(); + + virtual bool isDataCarrying()=0; + + void Clear(); + bool setName(wxString name); + const wxString getName(); + bool setEndMarker(wxString endmarker); + const wxString getEndMarker(); + bool setItem(const wxString key, const wxString value); + wxString getItem(const wxString key); + +public: + wxString m_name; + wxString m_endmarker; + MessageItems m_items; +}; + +// node to client +class wxFCPNodeMessage : public wxFCPBaseMessage +{ +public: + wxFCPNodeMessage(); + bool isMessageName(const wxString name); + virtual bool isDataCarrying(); +}; + +// client to node +class wxFCPCommand : public wxFCPBaseMessage +{ +public: + wxFCPCommand(); + virtual bool isDataCarrying(); +}; + +class wxFCPCommandFactory +{ +public: + static wxFCPCommand* VoidMessage(); + static wxFCPCommand* ClientHello(const wxString name); + static wxFCPCommand* GenerateSSK(); +}; + +#endif // ifndef _FCP_MESSAGE_H_ Modified: trunk/apps/wxFCP/samples/fcp/nodeinfo.cpp =================================================================== --- trunk/apps/wxFCP/samples/fcp/nodeinfo.cpp 2009-01-17 23:59:33 UTC (rev 25123) +++ trunk/apps/wxFCP/samples/fcp/nodeinfo.cpp 2009-01-19 19:39:19 UTC (rev 25124) @@ -13,9 +13,11 @@ // This application is used more for testing rather than as sample. // If you're looking at this file to learn how to use the wxFCP library, // you may better use the generated api documentation instead. - -#include "wx/cmdline.h" +// Overwrite defaults, less typing while testing +// or make it fit for your envirionment +//#define DEFAULT_FCP_PORT 9482 +//#define DEFAULT_FCP_TIMEOUT 20 #include "wx/fcp/fcp.h" #include "wx/wxprec.h" @@ -23,6 +25,8 @@ #include "wx/wx.h" #endif +#include <wx/cmdline.h> + int main(int argc, char **argv) { #if !wxUSE_UNICODE @@ -54,16 +58,26 @@ static const wxCmdLineEntryDesc cmdLineDesc[] = { { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show this help message"), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, - { wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose") }, + wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_SWITCH, _T("q"), _T("quiet"), _T("be quiet (don't log fcp)") }, + { wxCMD_LINE_OPTION, _T("o"), _T("fcphost"), _T("use given fcp host"), + wxCMD_LINE_VAL_STRING }, + { wxCMD_LINE_OPTION, _T("p"), _T("fcpport"), _T("use given fcp port"), + wxCMD_LINE_VAL_NUMBER }, + { wxCMD_LINE_OPTION, _T("t"), _T("fcptimeout"), _T("set connection timeout for fcp"), + wxCMD_LINE_VAL_NUMBER }, { wxCMD_LINE_NONE } }; + // init logging + wxLog *logger=new wxLogStream(&std::cout); + wxLog::SetActiveTarget(logger); + wxCmdLineParser parser(cmdLineDesc, argc, wxArgv); - switch ( parser.Parse() ) + switch ( parser.Parse(true) ) { case -1: - wxLogMessage(_T("Help was given, terminating.")); + return 0; // Help was shown, go away. break; case 0: @@ -71,11 +85,92 @@ break; default: - wxLogMessage(_T("Syntax error detected, aborting.")); + wxLogFatalError(_T("Syntax error detected, aborting.")); break; } - // do something useful here + wxString host; + if ( !parser.Found(_T("o"), &host) ) + { + if ( !wxGetEnv(_T(FCP_HOST_ENV_NAME), &host) ) + { + host = _T(DEFAULT_FCP_HOST); + } + } + long port; + if ( !parser.Found(_T("p"), &port) ) + { + wxString sport; + if ( wxGetEnv(_T(FCP_PORT_ENV_NAME), &sport) ) + { + if ( !sport.ToLong(&port) ) + { + wxLogFatalError(_T("not a valid number")); + } + } + else + { + port = DEFAULT_FCP_PORT; + } + } + + long timeout; + if ( !parser.Found(_T("t"), &timeout) ) + { + wxString stimeout; + if ( wxGetEnv(_T(FCP_TIMEOUT_ENV_NAME), &stimeout) ) + { + if ( !stimeout.ToLong(&timeout) ) + { + wxLogFatalError(_T("not a valid number")); + } + } + else + { + timeout = DEFAULT_FCP_TIMEOUT; + } + } + + // hack somewhat to get a first successfull hello + + wxFCPConnection conn = wxFCPConnection(&host, port, timeout); + + if ( !parser.Found(_T("q")) ) + { + wxFCPSimpleLogger *fcplogger = new wxFCPSimpleLogger(); + conn.setFCPLogger(fcplogger); + } + + conn.Connect(); + + if (conn.IsConnected()) + wxLogMessage(_T("Succeeded ! FCP Connection established (helo done)")); + else + { + wxLogMessage(_T("Can't connect/helo to the specified host")); + return 1; + } + + conn.sendCommand(wxFCPCommandFactory::GenerateSSK()); + + wxFCPNodeMessage message = wxFCPNodeMessage(); + conn.readEndMessage(message); + + if ( !message.isMessageName(_T("SSKKeypair")) ) + { + wxLogMessage(_T("Unexpected reply from node, generate ssk failed")); + return 1; + } + + wxString readkey = message.getItem(_T("RequestURI")); + wxString writekey = message.getItem(_T("InsertURI")); + + wxLogMessage(_T("Got a keypair from node:\n Insert URI: %s\n Request URI: %s"), writekey.c_str(), readkey.c_str()); + + conn.Close(true); + + wxLogMessage(_T("Socket closed. Bye")); + return 0; } Added: trunk/apps/wxFCP/src/fcp/connection.cpp =================================================================== --- trunk/apps/wxFCP/src/fcp/connection.cpp (rev 0) +++ trunk/apps/wxFCP/src/fcp/connection.cpp 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,132 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/fcp/connection.cpp +// Purpose: fcp connection classes +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include "wx/fcp/connection.h" + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +wxFCPConnection::wxFCPConnection(wxString *host, wxUint16 port, wxUint32 timeout, wxFCPLogger *logger) : wxFCPIOConnection() +{ +#if wxUSE_IPV6 + m_sockaddress = wxIPV6address(); +#else + m_sockaddress = wxIPV4address(); +#endif + m_sockaddress.Hostname(*host); + m_sockaddress.Service(port); + m_timeout = timeout; +} + +bool wxFCPConnection::Connect() +{ + wxFCPIOConnection::setTimeout(m_timeout); + wxFCPIOConnection::Connect(m_sockaddress); + + wxFCPCommand *helocommand = wxFCPCommandFactory::ClientHello(_T("FüüBör")); + + sendCommand(helocommand); + + wxFCPNodeMessage *message = new wxFCPNodeMessage(); + readEndMessage(*message); + + if ( !message->isMessageName(_T("NodeHello")) ) + { + wxLogMessage(_T("Unexpected reply from node, helo failed")); + m_nodehellomessage = NULL; + delete message; + return false; + } + + m_nodehellomessage = message; + return true; +} + +bool wxFCPConnection::Close(bool flush) +{ + return wxFCPIOConnection::Close(flush); +} + +bool wxFCPConnection::readLine(wxString& line) +{ + return wxFCPIOConnection::readLine(line); +} + +bool wxFCPConnection::readEndMessage(wxFCPNodeMessage& message) +{ + message.Clear(); + + wxString line = wxString(); + readLine(line); + message.setName(line); + + while ( true ) + { + readLine(line); + int pos = line.Find('='); + if (pos == wxNOT_FOUND) + { + message.setEndMarker(line); + break; + } + else + { + wxString k = line.Left(pos); + //wxLogMessage(_T("Key %s"), k.c_str()); + wxString v = line.Mid(pos+1); + //wxLogMessage(_T("Val %s"), v.c_str()); + message.setItem(k, v); + } + } + + return true; +} + +bool wxFCPConnection::IsConnected() +{ + if ( !wxFCPIOConnection::IsConnected() ) + return false; + return ( m_nodehellomessage ); +} + +bool wxFCPConnection::setFCPLogger(wxFCPLogger *logger) +{ + return wxFCPIOConnection::setFCPLogger(logger); +} + +bool wxFCPConnection::sendCommand(wxFCPCommand *command) +{ + bool result = sendCommand(*command); + if ( result ) + delete command; + return result; +} + +bool wxFCPConnection::sendCommand(wxFCPCommand& command) +{ + writeLine(command.getName()); + + // iterate over all the items + MessageItems::iterator it; + for( it = command.m_items.begin(); it != command.m_items.end(); ++it ) + { + wxString line = it->first; + line += '='; + line += it->second; + writeLine(line); + } + + writeLine(command.getEndMarker()); + + return true; +} Added: trunk/apps/wxFCP/src/fcp/ioconnection.cpp =================================================================== --- trunk/apps/wxFCP/src/fcp/ioconnection.cpp (rev 0) +++ trunk/apps/wxFCP/src/fcp/ioconnection.cpp 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,130 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/fcp/ioconnection.cpp +// Purpose: fcp connection io classes +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include "wx/fcp/ioconnection.h" + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +const char nl = '\n'; + +wxFCPIOConnection::wxFCPIOConnection() +{ + m_sock = new wxSocketClient(wxSOCKET_WAITALL); + m_sock->Notify(false); + m_fcplogger = NULL; +} + +wxFCPIOConnection::~wxFCPIOConnection() +{ + delete m_sock; +} + +bool wxFCPIOConnection::Connect(wxSockAddress& sockaddress) +{ + return m_sock->Connect(sockaddress, true); +} + +bool wxFCPIOConnection::IsConnected() +{ + if ( !m_sock ) + return false; + return m_sock->IsConnected(); +} + +bool wxFCPIOConnection::Close(bool flush) +{ + return false; +} + +bool wxFCPIOConnection::setFCPLogger(wxFCPLogger *logger) +{ +// if ( !m_fcplogger ) +// { + m_fcplogger = logger; + return true; +// } +// return false; +} + +void wxFCPIOConnection::setTimeout(wxUint32 timeout) +{ + m_sock->SetTimeout(timeout); +} + +bool wxFCPIOConnection::writeLine(const wxString& line) +{ + // TODO wxString::utf8_str() is since 2.8.4, + // invent our own convert for older versions + const wxCharBuffer cbuf = line.utf8_str(); + if ( m_fcplogger ) + m_fcplogger->outgoingLine(line); + write(cbuf, strlen(cbuf)); + return write(&nl, 1); +} + +bool wxFCPIOConnection::readLine(wxString& line) +{ + static const int MAX_LINE_LEN = 4096; + + line.Empty(); + + int n; + for ( n = 1; n < MAX_LINE_LEN; n++ ) + { + char c; + m_sock->Read( &c, 1 ); + int charsread = m_sock->LastCount(); + + if ( charsread == 1 ) + { + if ( c == '\n' ) + break; + line += c; + } + else if ( charsread == 0 ) + { + if ( n == 1 ) + return false; + else + break; + } + } + if ( m_fcplogger ) + m_fcplogger->incomingLine(line); + +// TODO static wxString FromUTF8(const char* s) + return true; +} + +bool wxFCPIOConnection::writeData(const void* buffer, wxUint32 nbytes) +{ + m_sock->Write(buffer, nbytes); + + if ( m_fcplogger ) + m_fcplogger->outgoingData(nbytes); + + return !m_sock->Error(); +} + +bool wxFCPIOConnection::write(const void* buffer, wxUint32 nbytes) +{ + m_sock->Write(buffer, nbytes); + return !m_sock->Error(); +} + +bool wxFCPIOConnection::readData(void* buffer, wxUint32 nbytes) +{ + m_sock->Read(buffer, nbytes); + return !m_sock->Error(); +} Added: trunk/apps/wxFCP/src/fcp/logger.cpp =================================================================== --- trunk/apps/wxFCP/src/fcp/logger.cpp (rev 0) +++ trunk/apps/wxFCP/src/fcp/logger.cpp 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,37 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/fcp/logger.cpp +// Purpose: fcp logger classes +// Author: saces +// Modified by: +// Created: 14.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/fcp/logger.h" + +void wxFCPSimpleLogger::incomingLine(const wxString& line) +{ + wxLogMessage(_T("FCP in: %s"), line.c_str()); +} + +void wxFCPSimpleLogger::outgoingLine(const wxString& line) +{ + wxLogMessage(_T("FCP out: %s"), line.c_str()); +} + +void wxFCPSimpleLogger::incomingData(const wxUint32 nbytes) +{ + wxLogMessage(_T("FCP in: <%d> bytes of data"), nbytes); +} + +void wxFCPSimpleLogger::outgoingData(const wxUint32 nbytes) +{ + wxLogMessage(_T("FCP out: <%d> bytes of data"), nbytes); +} Added: trunk/apps/wxFCP/src/fcp/message.cpp =================================================================== --- trunk/apps/wxFCP/src/fcp/message.cpp (rev 0) +++ trunk/apps/wxFCP/src/fcp/message.cpp 2009-01-19 19:39:19 UTC (rev 25124) @@ -0,0 +1,122 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/fcp/message.cpp +// Purpose: fcp message classes +// Author: saces +// Modified by: +// Created: 16.01.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2009 saces <[email protected]> +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include "wx/wxprec.h" +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/fcp/message.h" + +#define NORMAL_ENDMARKER "EndMessage" +#define DATA_ENDMARKER "Data" + +wxFCPBaseMessage::wxFCPBaseMessage() +{ + m_name = wxString(); + m_endmarker = wxString(); + m_items = MessageItems(); +} + +wxFCPBaseMessage::~wxFCPBaseMessage() { + Clear(); +} + +void wxFCPBaseMessage::Clear() +{ + m_name.Clear(); + m_endmarker.Clear(); + m_items.clear(); +} + +bool wxFCPBaseMessage::setName(wxString name) +{ + m_name = name; + return true; +} + +const wxString wxFCPBaseMessage::getName() +{ + return m_name; +} + +bool wxFCPBaseMessage::setEndMarker(wxString endmarker) +{ + m_endmarker = endmarker; + return true; +} + +const wxString wxFCPBaseMessage::getEndMarker() +{ + return _T(NORMAL_ENDMARKER); +} + +bool wxFCPBaseMessage::setItem(const wxString key, const wxString value) +{ + m_items[key] = value; + return true; +} + +wxString wxFCPBaseMessage::getItem(const wxString key) +{ + return m_items[key]; +} + +wxFCPNodeMessage::wxFCPNodeMessage() : +wxFCPBaseMessage() +{ + ; +} + +bool wxFCPNodeMessage::isDataCarrying() +{ + return false; +} + +bool wxFCPNodeMessage::isMessageName(const wxString name) +{ + return ( m_name == name ); +} + +//---- + +wxFCPCommand::wxFCPCommand() : +wxFCPBaseMessage() +{ + ; +} + +bool wxFCPCommand::isDataCarrying() +{ + return false; +} + +//---- + +wxFCPCommand* wxFCPCommandFactory::ClientHello(const wxString name) +{ + wxFCPCommand *ch = new wxFCPCommand(); + ch->setName(_T("ClientHello")); + ch->setItem(_T("Name"), name); + ch->setItem(_T("ExpectedVersion"), _T("2.0")); + return ch; +}; + +wxFCPCommand* wxFCPCommandFactory::GenerateSSK() +{ + wxFCPCommand *ch = new wxFCPCommand(); + ch->setName(_T("GenerateSSK")); + //ch->setItem(_T("Name"), name); + //ch->setItem(_T("ExpectedVersion"), _T("2.0")); + return ch; +}; + + _______________________________________________ cvs mailing list [email protected] http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
