OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/client/client_util.h" | 5 #include "remoting/client/client_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "remoting/base/constants.h" |
12 #include "remoting/client/client_config.h" | 13 #include "remoting/client/client_config.h" |
13 | 14 |
14 using std::string; | 15 using std::string; |
15 using std::vector; | 16 using std::vector; |
16 | 17 |
17 namespace remoting { | 18 namespace remoting { |
18 | 19 |
19 // Get host JID from command line arguments, or stdin if not specified. | 20 // Get host JID from command line arguments, or stdin if not specified. |
20 bool GetLoginInfoFromArgs(int argc, char** argv, ClientConfig* config) { | 21 bool GetLoginInfoFromArgs(int argc, char** argv, ClientConfig* config) { |
21 bool found_host_jid = false; | 22 bool found_host_jid = false; |
22 bool found_jid = false; | 23 bool found_jid = false; |
23 bool found_auth_token = false; | 24 bool found_auth_token = false; |
24 string host_jid; | 25 string host_jid; |
25 string username; | 26 string username; |
26 string auth_token; | 27 string auth_token; |
| 28 string auth_service(kChromotingTokenDefaultServiceName); |
27 | 29 |
28 for (int i = 1; i < argc; i++) { | 30 for (int i = 1; i < argc; i++) { |
29 std::string arg = argv[i]; | 31 std::string arg = argv[i]; |
30 if (arg == "--host_jid") { | 32 if (arg == "--host_jid") { |
31 if (++i >= argc) { | 33 if (++i >= argc) { |
32 LOG(WARNING) << "Expected Host JID to follow --host_jid option"; | 34 LOG(WARNING) << "Expected Host JID to follow --host_jid option"; |
33 } else { | 35 } else { |
34 found_host_jid = true; | 36 found_host_jid = true; |
35 host_jid = argv[i]; | 37 host_jid = argv[i]; |
36 } | 38 } |
37 } else if (arg == "--jid") { | 39 } else if (arg == "--jid") { |
38 if (++i >= argc) { | 40 if (++i >= argc) { |
39 LOG(WARNING) << "Expected JID to follow --jid option"; | 41 LOG(WARNING) << "Expected JID to follow --jid option"; |
40 } else { | 42 } else { |
41 found_jid = true; | 43 found_jid = true; |
42 username = argv[i]; | 44 username = argv[i]; |
43 } | 45 } |
44 } else if (arg == "--token") { | 46 } else if (arg == "--token") { |
45 if (++i >= argc) { | 47 if (++i >= argc) { |
46 LOG(WARNING) << "Expected Auth token to follow --token option"; | 48 LOG(WARNING) << "Expected Auth token to follow --token option"; |
47 } else { | 49 } else { |
48 found_auth_token = true; | 50 found_auth_token = true; |
49 auth_token = argv[i]; | 51 auth_token = argv[i]; |
50 } | 52 } |
| 53 } else if (arg == "--service") { |
| 54 if (++i >= argc) { |
| 55 LOG(WARNING) << "Expected service name to follow --service option"; |
| 56 } else { |
| 57 auth_service = argv[i]; |
| 58 } |
51 } else { | 59 } else { |
52 LOG(WARNING) << "Unrecognized option: " << arg; | 60 LOG(WARNING) << "Unrecognized option: " << arg; |
53 } | 61 } |
54 } | 62 } |
55 | 63 |
56 if (!found_host_jid) | 64 if (!found_host_jid) |
57 return false; | 65 return false; |
58 | 66 |
59 // Validate the chromoting host JID. | 67 // Validate the chromoting host JID. |
60 if ((host_jid.find("/chromoting") == std::string::npos) || !found_jid || | 68 if ((host_jid.find("/chromoting") == std::string::npos) || !found_jid || |
61 !found_auth_token) | 69 !found_auth_token) |
62 return false; | 70 return false; |
63 | 71 |
64 NOTIMPLEMENTED() << "Nonce ignored."; | 72 NOTIMPLEMENTED() << "Nonce ignored."; |
65 | 73 |
66 config->host_jid = host_jid; | 74 config->host_jid = host_jid; |
67 config->username = username; | 75 config->username = username; |
68 config->auth_token = auth_token; | 76 config->auth_token = auth_token; |
| 77 config->auth_service = auth_service; |
69 return true; | 78 return true; |
70 } | 79 } |
71 | 80 |
72 } // namespace remoting | 81 } // namespace remoting |
OLD | NEW |