mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-29 07:57:20 +02:00
Sync
- Added a ::send method to CmdSync to perform the transfer. Note that this does not yet include any TLS.
This commit is contained in:
parent
5a9810a423
commit
e7e34b7148
3 changed files with 46 additions and 1 deletions
|
@ -3,7 +3,8 @@
|
||||||
2.3.0 () -
|
2.3.0 () -
|
||||||
|
|
||||||
Features
|
Features
|
||||||
+
|
+ Stores un-synched transactions in <data.location>/backlog.data.
|
||||||
|
+ Adds a new "synchronize" command to sync data with a task server.
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
+
|
+
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
#define L10N // Localization complete.
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
#include <Socket.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
#include <CmdSync.h>
|
#include <CmdSync.h>
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -31,12 +31,16 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <Command.h>
|
#include <Command.h>
|
||||||
|
#include <Msg.h>
|
||||||
|
|
||||||
class CmdSync : public Command
|
class CmdSync : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CmdSync ();
|
CmdSync ();
|
||||||
int execute (std::string&);
|
int execute (std::string&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool send (const std::string&, const Msg&, Msg&);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue