Merge branch '2.0.0' of tasktools.org:task into 2.0.0

This commit is contained in:
Paul Beckingham 2011-12-01 00:04:04 -05:00
commit c25bb6404f
7 changed files with 96 additions and 29 deletions

View file

@ -72,6 +72,22 @@ Transport* Transport::getTransport(const Uri& uri)
////////////////////////////////////////////////////////////////////////////////
int Transport::execute()
{
// quote arguments
std::vector<std::string>::iterator it = _arguments.begin ();
for (; it != _arguments.end (); it++)
{
// quote until the first appearance of '{'
size_t pos = it->find('{');
if (pos != 0)
{
// '{' is not the first character
it->insert(0, "\"");
if (pos != std::string::npos)
it->insert(pos+1, "\"");
else
it->append("\"");
}
}
return ::execute(_executable, _arguments);
}

View file

@ -63,12 +63,12 @@ void TransportCurl::send(const std::string& source)
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
_arguments.push_back ("-T");
_arguments.push_back ("\"" + source + "\"");
_arguments.push_back ("\"" + escape (source, ' ') + "\"");
}
else
{
_arguments.push_back ("-T");
_arguments.push_back (source);
_arguments.push_back (escape (source, ' '));
}
// cmd line is: curl -T source protocol://host:port/path
@ -103,6 +103,7 @@ void TransportCurl::recv(std::string target)
_arguments.push_back(_uri._user);
}
std::vector<std::string> targetargs;
if (is_filelist(_uri._path))
{
@ -124,15 +125,16 @@ void TransportCurl::recv(std::string target)
suffix = toSplit.substr (pos+1);
split (splitted, toSplit.substr(0, pos), ',');
target = "";
std::vector <std::string>::iterator file;
for (file = splitted.begin (); file != splitted.end (); ++file)
target += " -o " + prefix + *file + suffix;
for (file = splitted.begin (); file != splitted.end (); ++file) {
targetargs.push_back ("-o");
targetargs.push_back (prefix + *file + suffix);
}
}
else
{
target = "-o " + target;
targetargs.push_back ("-o");
targetargs.push_back (target);
}
// cmd line is: curl protocol://host:port/path/to/source/file -o path/to/target/file
@ -145,7 +147,7 @@ void TransportCurl::recv(std::string target)
_arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path);
}
_arguments.push_back (target);
_arguments.insert (_arguments.end (), targetargs.begin (), targetargs.end ());
int result = execute();
if (result)

View file

@ -31,6 +31,7 @@
#include <text.h>
#include <i18n.h>
#include <TransportSSH.h>
#include <util.h>
////////////////////////////////////////////////////////////////////////////////
TransportSSH::TransportSSH(const Uri& uri) : Transport(uri)
@ -60,11 +61,11 @@ void TransportSSH::send(const std::string& source)
if (_uri._user != "")
{
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + escape (_uri._path, ' '));
}
else
{
_arguments.push_back (_uri._host + ":" + _uri._path);
_arguments.push_back (_uri._host + ":" + escape (_uri._path, ' '));
}
if (execute())
@ -91,11 +92,11 @@ void TransportSSH::recv(std::string target)
if (_uri._user != "")
{
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + escape (_uri._path, ' '));
}
else
{
_arguments.push_back (_uri._host + ":" + _uri._path);
_arguments.push_back (_uri._host + ":" + escape (_uri._path, ' '));
}
_arguments.push_back (target);

View file

@ -199,12 +199,18 @@ std::string Uri::ToString ()
return _data;
std::string result;
// strip password from _user
std::string::size_type pos = _user.find (":");
result = _protocol + "://";
if (_user.length () > 0)
result += _user.substr (0, pos) + "@";
if (_user.length () > 0) {
// obscure password in _user
std::string::size_type pos = _user.find (":");
if (pos != std::string::npos) {
std::string::size_type len = _user.length () - pos - 1;
result += _user.replace (pos+1, len, len, '*') + "@";
}
else
result += _user + "@";
}
result += _host;
@ -288,7 +294,7 @@ void Uri::parse ()
}
// path is absolute for ssh:// syntax
if ( (_protocol == "ssh") && (pathDelimiter == "/") )
if ( (_protocol == "ssh") && (pathDelimiter == "/") && (_path[0] != '~') )
{
_path = "/" + _path;
}

View file

@ -38,6 +38,7 @@
#include <Directory.h>
#include <ViewText.h>
#include <CmdShow.h>
#include <Uri.h>
extern Context context;
@ -226,6 +227,9 @@ int CmdShow::execute (std::string& output)
i->substr (0, 7) != "report." &&
i->substr (0, 6) != "alias." &&
i->substr (0, 5) != "hook." &&
i->substr (0, 5) != "push." &&
i->substr (0, 5) != "pull." &&
i->substr (0, 6) != "merge." &&
i->substr (0, 21) != "urgency.user.project." &&
i->substr (0, 17) != "urgency.user.tag.")
{
@ -273,9 +277,20 @@ int CmdShow::execute (std::string& output)
else if (std::find (default_values.begin (), default_values.end (), *i) != default_values.end ())
color = warning;
std::string value = context.config.get (*i);
// hide sensible information
if ( (i->substr (0, 5) == "push." ||
i->substr (0, 5) == "pull." ||
i->substr (0, 6) == "merge.") && (i->find (".uri") != std::string::npos) ) {
Uri uri (value);
uri.parse ();
value = uri.ToString ();
}
int row = view.addRow ();
view.set (row, 0, *i, color);
view.set (row, 1, context.config.get (*i), color);
view.set (row, 1, value, color);
}
}

View file

@ -405,11 +405,8 @@ int execute(const std::string& executable, std::vector<std::string> arguments)
if (executable == "")
return -1;
pid_t child_pid = fork();
if (child_pid == 0)
{
// this is done by the child process
// create command line before forking because the parent process also needs this for
// calling context.debug()
char shell[] = "bash";
char opt[] = "-c";
@ -421,6 +418,13 @@ int execute(const std::string& executable, std::vector<std::string> arguments)
cmdline += " " + (std::string)*it;
}
context.debug ("Executing: " + std::string(shell) + " " + std::string(opt) + " " + cmdline);
pid_t child_pid = fork();
if (child_pid == 0)
{
// this is done by the child process
char** argv = new char*[4];
argv[0] = shell; // bash
argv[1] = opt; // -c
@ -534,6 +538,27 @@ const std::string decode (const std::string& value)
return modified;
}
////////////////////////////////////////////////////////////////////////////////
// Escapes any unescaped character of type c within the given string
// e.g. ' ' -> '\ '
const std::string escape (const std::string& value, char c)
{
std::string modified = value;
char tmp[2] = {c, '\0'};
std::string search = tmp;
std::string replace = "\\" + search;
std::string::size_type pos = modified.find (search);
while (pos != std::string::npos) {
if ( modified[pos-1] != '\\' )
modified.replace (pos, 1, replace);
pos = modified.find (search, pos+1);
}
return modified;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -80,5 +80,7 @@ unsigned burndown_size (unsigned ntasks);
const std::string encode (const std::string&);
const std::string decode (const std::string&);
const std::string escape (const std::string&, char);
#endif
////////////////////////////////////////////////////////////////////////////////