mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-04 12:28:35 +02:00
Url support #462
- Added TransportCurl for http, https and ftp - Added url support for import command
This commit is contained in:
parent
adc7992608
commit
bf316974d9
10 changed files with 352 additions and 98 deletions
|
@ -32,6 +32,7 @@
|
|||
#include "Transport.h"
|
||||
#include "TransportSSH.h"
|
||||
#include "TransportRSYNC.h"
|
||||
#include "TransportCurl.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Transport::Transport (const std::string& host, const std::string& path, const std::string& user="", const std::string& port="")
|
||||
|
@ -111,67 +112,75 @@ void Transport::parseUri(std::string uri)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
Transport* Transport::getTransport(const std::string& uri)
|
||||
{
|
||||
if (uri.find("ssh://") == 0) {
|
||||
return new TransportSSH(uri);
|
||||
}
|
||||
else if (uri.find("rsync://") == 0) {
|
||||
return new TransportRSYNC(uri);
|
||||
}
|
||||
else if ( (uri.find(":") != std::string::npos)
|
||||
&& (uri.find("://") == std::string::npos) )
|
||||
{
|
||||
return new TransportSSH(uri);
|
||||
}
|
||||
if (uri.find("ssh://") == 0)
|
||||
{
|
||||
return new TransportSSH(uri);
|
||||
}
|
||||
else if (uri.find("rsync://") == 0)
|
||||
{
|
||||
return new TransportRSYNC(uri);
|
||||
}
|
||||
else if ( (uri.find("http://") == 0)
|
||||
|| (uri.find("https://") == 0)
|
||||
|| (uri.find("ftp://") == 0) )
|
||||
{
|
||||
return new TransportCurl(uri);
|
||||
}
|
||||
else if ( (uri.find(":") != std::string::npos)
|
||||
&& (uri.find("://") == std::string::npos) )
|
||||
{
|
||||
return new TransportSSH(uri);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Transport::execute()
|
||||
{
|
||||
if (executable == "")
|
||||
return -1;
|
||||
if (executable == "")
|
||||
return -1;
|
||||
|
||||
pid_t child_pid = fork();
|
||||
pid_t child_pid = fork();
|
||||
|
||||
if (child_pid == 0)
|
||||
{
|
||||
// this is done by the child process
|
||||
char shell[] = "sh";
|
||||
char opt[] = "-c";
|
||||
if (child_pid == 0)
|
||||
{
|
||||
// this is done by the child process
|
||||
char shell[] = "sh";
|
||||
char opt[] = "-c";
|
||||
|
||||
std::string cmdline = executable;
|
||||
std::string cmdline = executable;
|
||||
|
||||
std::vector <std::string>::iterator it;
|
||||
for (it = arguments.begin(); it != arguments.end(); ++it)
|
||||
{
|
||||
std::string tmp = *it;
|
||||
cmdline += " " + tmp;
|
||||
}
|
||||
std::vector <std::string>::iterator it;
|
||||
for (it = arguments.begin(); it != arguments.end(); ++it)
|
||||
{
|
||||
std::string tmp = *it;
|
||||
cmdline += " " + tmp;
|
||||
}
|
||||
|
||||
char** argv = new char*[4];
|
||||
argv[0] = shell; // sh
|
||||
argv[1] = opt; // -c
|
||||
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
|
||||
argv[3] = NULL; // required by execv
|
||||
char** argv = new char*[4];
|
||||
argv[0] = shell; // sh
|
||||
argv[1] = opt; // -c
|
||||
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
|
||||
argv[3] = NULL; // required by execv
|
||||
|
||||
int ret = execvp("sh", argv);
|
||||
delete[] argv;
|
||||
int ret = execvp("sh", argv);
|
||||
delete[] argv;
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is done by the parent process
|
||||
int child_status;
|
||||
exit(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is done by the parent process
|
||||
int child_status;
|
||||
|
||||
pid_t pid = waitpid(child_pid, &child_status, 0);
|
||||
pid_t pid = waitpid(child_pid, &child_status, 0);
|
||||
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
else
|
||||
return child_status;
|
||||
}
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
else
|
||||
return child_status;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue