From e7e34b7148024772ae6c11d12197a2e9c710710e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 6 Oct 2012 09:07:30 -0400 Subject: [PATCH] Sync - Added a ::send method to CmdSync to perform the transfer. Note that this does not yet include any TLS. --- ChangeLog.230 | 3 ++- src/commands/CmdSync.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/commands/CmdSync.h | 4 ++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ChangeLog.230 b/ChangeLog.230 index 01a129b85..f87b07c50 100644 --- a/ChangeLog.230 +++ b/ChangeLog.230 @@ -3,7 +3,8 @@ 2.3.0 () - Features - + + + Stores un-synched transactions in /backlog.data. + + Adds a new "synchronize" command to sync data with a task server. Bugs + diff --git a/src/commands/CmdSync.cpp b/src/commands/CmdSync.cpp index ac4f7b693..7e1bd394e 100644 --- a/src/commands/CmdSync.cpp +++ b/src/commands/CmdSync.cpp @@ -28,7 +28,9 @@ #define L10N // Localization complete. #include +#include #include +#include #include #include #include @@ -69,3 +71,41 @@ int CmdSync::execute (std::string& output) } //////////////////////////////////////////////////////////////////////////////// +bool CmdSync::send ( + const std::string& to, + const Msg& out, + Msg& in) +{ + std::string::size_type colon = to.find (':'); + if (colon == std::string::npos) + throw std::string ("ERROR: Malformed configuration setting '") + to + "'"; + + std::string server = to.substr (0, colon); + int port = strtoimax (to.substr (colon + 1).c_str (), NULL, 10); + + try + { + Socket s (AF_INET, SOCK_STREAM, IPPROTO_TCP); + s.connect (server, port); + s.write (out.serialize () + "\r\n"); + + std::string response; + s.read (response); + s.close (); + + in.parse (response); + + // Indicate message sent. + return true; + } + + catch (std::string& error) + { + // TODO Report as diagnostics? + } + + // Indicate message failed. + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdSync.h b/src/commands/CmdSync.h index ed5925afd..c4ff9b010 100644 --- a/src/commands/CmdSync.h +++ b/src/commands/CmdSync.h @@ -31,12 +31,16 @@ #include #include +#include class CmdSync : public Command { public: CmdSync (); int execute (std::string&); + +private: + bool send (const std::string&, const Msg&, Msg&); }; #endif