mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +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
|
@ -28,7 +28,9 @@
|
|||
#define L10N // Localization complete.
|
||||
|
||||
#include <iostream>
|
||||
#include <inttypes.h>
|
||||
#include <Context.h>
|
||||
#include <Socket.h>
|
||||
#include <text.h>
|
||||
#include <i18n.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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue