diff options
author | Klaas Freitag <freitag@owncloud.com> | 2013-12-19 19:48:10 +0400 |
---|---|---|
committer | Klaas Freitag <freitag@owncloud.com> | 2013-12-19 19:48:10 +0400 |
commit | 72b479c1e0f2f0ae02338011fcf88aaa7b91e521 (patch) | |
tree | dbe2ba5f53100da3380900fe4a0686ab38087dbd /src/owncloudcmd | |
parent | d17be6f1ff14f214623848ae0c0f2580b393d8cd (diff) |
Added proxy support to owncloudcmd.
Diffstat (limited to 'src/owncloudcmd')
-rw-r--r-- | src/owncloudcmd/owncloudcmd.cpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/owncloudcmd/owncloudcmd.cpp b/src/owncloudcmd/owncloudcmd.cpp index c36f05acb..487642f22 100644 --- a/src/owncloudcmd/owncloudcmd.cpp +++ b/src/owncloudcmd/owncloudcmd.cpp @@ -38,26 +38,11 @@ int getauth(const char* prompt, char* buf, size_t len, int echo, int verify, voi return 0; } -struct ProxyInfo { - const char *proxyType; - const char *proxyHost; - int proxyPort; - const char *proxyUser; - const char *proxyPwd; - - ProxyInfo() { - proxyType = 0; - proxyHost = 0; - proxyPort = 0; - proxyUser = 0; - proxyPwd = 0; - } -}; - struct CmdOptions { QString source_dir; QString target_url; QString config_directory; + QString proxy; }; void help() @@ -68,6 +53,8 @@ void help() std::cout << "" << std::endl; std::cout << "Options:" << std::endl; std::cout << " --confdir = configdir: Read config from there." << std::endl; + std::cout << " --httpproxy = proxy: Specify a http proxy to use." << std::endl; + std::cout << " Proxy is http://server:port" << std::endl; std::cout << "" << std::endl; exit(1); @@ -97,6 +84,8 @@ void parseOptions( const QStringList& app_args, CmdOptions *options ) if( option == "--confdir" && !it.peekNext().startsWith("-") ) { options->config_directory = it.next(); + } else if( option == "--httpproxy" && !it.peekNext().startsWith("-")) { + options->proxy = it.next(); } else { help(); } @@ -110,7 +99,6 @@ void parseOptions( const QStringList& app_args, CmdOptions *options ) int main(int argc, char **argv) { QCoreApplication app(argc, argv); - ProxyInfo proxyInfo; CmdOptions options; parseOptions( app.arguments(), &options ); @@ -139,6 +127,29 @@ int main(int argc, char **argv) { } csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); + if( !options.proxy.isNull() ) { + QString host; + int port = 0; + bool ok; + + QStringList pList = options.proxy.split(':'); + if(pList.count() == 3) { + // http: //192.168.178.23 : 8080 + // 0 1 2 + host = pList.at(1); + if( host.startsWith("//") ) host.remove(0, 2); + + port = pList.at(2).toInt(&ok); + + if( !host.isNull() ) { + csync_set_module_property(_csync_ctx, "proxy_type", (void*) "HttpProxy"); + csync_set_module_property(_csync_ctx, "proxy_host", host.toUtf8().data()); + if( ok && port ) { + csync_set_module_property(_csync_ctx, "proxy_port", (void*) &port); + } + } + } + } SyncJournalDb db(options.source_dir); CSyncThread csyncthread(_csync_ctx, options.source_dir, QUrl(options.target_url).path(), &db); |