diff options
author | garykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 03:19:26 +0000 |
---|---|---|
committer | garykac@google.com <garykac@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-11 03:19:26 +0000 |
commit | 062595456e871f314985ef6e3375bc8ebaf3e514 (patch) | |
tree | fff6f638e9f9db1979dc681649483aaec409a11f /remoting/client/client_util.cc | |
parent | 2028539fd25578e5725e528d8a2de8f53923576d (diff) | |
download | chromium_src-062595456e871f314985ef6e3375bc8ebaf3e514.zip chromium_src-062595456e871f314985ef6e3375bc8ebaf3e514.tar.gz chromium_src-062595456e871f314985ef6e3375bc8ebaf3e514.tar.bz2 |
Add cmdline options to set the hostjid, jid and auth token for the chromoting
client.
Add a simple python script to extract jid/token info and launch the client
with the appropriate args.
Fix x11_client to work with Albert's client restructuring.
BUG=none
TEST=manual
Review URL: http://codereview.chromium.org/2734004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49497 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client/client_util.cc')
-rw-r--r-- | remoting/client/client_util.cc | 89 |
1 files changed, 67 insertions, 22 deletions
diff --git a/remoting/client/client_util.cc b/remoting/client/client_util.cc index 2bc50c0..ddaee42 100644 --- a/remoting/client/client_util.cc +++ b/remoting/client/client_util.cc @@ -6,43 +6,88 @@ #include <iostream> +#include "base/logging.h" + namespace remoting { // Get host JID from command line arguments, or stdin if not specified. -bool GetLoginInfo(std::string* host_jid, +bool GetLoginInfo(int argc, char** argv, + std::string* host_jid, std::string* username, std::string* auth_token) { - std::cout << "Host JID: "; - std::cin >> *host_jid; - std::cin.ignore(); // Consume the leftover '\n' + bool found_host_jid = false; + bool found_jid = false; + bool found_auth_token = false; + + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + if (arg == "--host_jid") { + if (++i >= argc) { + LOG(WARNING) << "Expected Host JID to follow --host_jid option" + << std::endl; + } else { + found_host_jid = true; + *host_jid = argv[i]; + } + } else if (arg == "--jid") { + if (++i >= argc) { + LOG(WARNING) << "Expected JID to follow --jid option" << std::endl; + } else { + found_jid = true; + *username = argv[i]; + } + } else if (arg == "--token") { + if (++i >= argc) { + LOG(WARNING) << "Expected Auth token to follow --token option" + << std::endl; + } else { + found_auth_token = true; + *auth_token = argv[i]; + } + } else { + LOG(WARNING) << "Unrecognized option: " << arg << std::endl; + } + } + if (!found_host_jid) { + std::cout << "Host JID: "; + std::cin >> *host_jid; + std::cin.ignore(); // Consume the leftover '\n' + } + + // Validate the chromoting host JID. if (host_jid->find("/chromoting") == std::string::npos) { std::cerr << "Error: Expected Host JID in format: <jid>/chromoting<id>" << std::endl; return false; } - // Get username (JID). - // Extract default JID from host_jid. - std::string default_username; - size_t jid_end = host_jid->find('/'); - if (jid_end != std::string::npos) { - default_username = host_jid->substr(0, jid_end); - } - std::cout << "JID [" << default_username << "]: "; - getline(std::cin, *username); - if (username->length() == 0) { - username->swap(default_username); + if (!found_jid) { + // Get username (JID). + // Extract default JID from host_jid. + std::string default_username; + size_t jid_end = host_jid->find('/'); + if (jid_end != std::string::npos) { + default_username = host_jid->substr(0, jid_end); + } + std::cout << "JID [" << default_username << "]: "; + getline(std::cin, *username); + if (username->length() == 0) { + username->swap(default_username); + } + if (username->length() == 0) { + std::cerr << "Error: Expected valid JID username" << std::endl; + return false; + } } - if (username->length() == 0) { - std::cerr << "Error: Expected valid JID username" << std::endl; - return 1; + + if (!found_auth_token) { + // Get authentication token. + std::cout << "Auth token: "; + getline(std::cin, *auth_token); + std::cout << std::endl; } - // Get authenication token (with console echo turned off). - std::cout << "Auth token: "; - getline(std::cin, *auth_token); - std::cout << std::endl; return true; } |