blob: 215ae9c2fccf1b05bbb0d699ab42cec2d54e19c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/client/client_util.h"
#include <string>
#include <vector>
#include "base/logging.h"
#include "base/string_util.h"
#include "remoting/client/client_config.h"
using std::string;
using std::vector;
namespace remoting {
// Get host JID from command line arguments, or stdin if not specified.
bool GetLoginInfoFromArgs(int argc, char** argv, ClientConfig* config) {
bool found_host_jid = false;
bool found_jid = false;
bool found_auth_token = false;
string host_jid;
string username;
string auth_token;
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) {
return false;
}
// Validate the chromoting host JID.
if (host_jid.find("/chromoting") == std::string::npos) {
return false;
}
if (!found_jid) {
return false;
}
if (!found_auth_token) {
return false;
}
config->host_jid = host_jid;
config->username = username;
config->auth_token = auth_token;
return true;
}
// Get host JID from command line arguments, or stdin if not specified.
bool GetLoginInfoFromUrlParams(const std::string& url, ClientConfig* config) {
// TODO(ajwong): We should use GURL or something. Don't parse this by hand!
// The Url should be of the form:
//
// chrome://remoting?user=<userid>&auth=<authtoken>&jid=<hostjid>
//
vector<string> parts;
SplitString(url, '&', &parts);
if (parts.size() != 3) {
return false;
}
size_t pos = parts[0].rfind('=');
if (pos == string::npos && (pos + 1) != string::npos) {
return false;
}
std::string username = parts[0].substr(pos + 1);
pos = parts[1].rfind('=');
if (pos == string::npos && (pos + 1) != string::npos) {
return false;
}
std::string auth_token = parts[1].substr(pos + 1);
pos = parts[2].rfind('=');
if (pos == string::npos && (pos + 1) != string::npos) {
return false;
}
std::string host_jid = parts[2].substr(pos + 1);
config->host_jid = host_jid;
config->username = username;
config->auth_token = auth_token;
return true;
}
} // namespace remoting
|