OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
8 extern "C" { | 8 extern "C" { |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 } | 10 } |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "net/socket/socket.h" | 23 #include "net/socket/socket.h" |
24 #include "remoting/base/constants.h" | 24 #include "remoting/base/constants.h" |
25 #include "remoting/jingle_glue/jingle_client.h" | 25 #include "remoting/jingle_glue/jingle_client.h" |
26 #include "remoting/jingle_glue/jingle_thread.h" | 26 #include "remoting/jingle_glue/jingle_thread.h" |
27 #include "remoting/protocol/jingle_session_manager.h" | 27 #include "remoting/protocol/jingle_session_manager.h" |
28 | 28 |
29 using remoting::kChromotingTokenServiceName; | 29 using remoting::kChromotingTokenServiceName; |
30 | 30 |
31 namespace remoting { | 31 namespace remoting { |
32 | |
33 namespace protocol { | 32 namespace protocol { |
34 | 33 |
35 namespace { | 34 namespace { |
36 const int kBufferSize = 4096; | 35 const int kBufferSize = 4096; |
37 } // namespace | 36 } // namespace |
38 | 37 |
39 class ProtocolTestClient; | 38 class ProtocolTestClient; |
40 | 39 |
41 class ProtocolTestConnection | 40 class ProtocolTestConnection |
42 : public base::RefCountedThreadSafe<ProtocolTestConnection> { | 41 : public base::RefCountedThreadSafe<ProtocolTestConnection> { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 278 |
280 session_manager_->Init( | 279 session_manager_->Init( |
281 client_->GetFullJid(), client_->session_manager(), | 280 client_->GetFullJid(), client_->session_manager(), |
282 NewCallback(this, &ProtocolTestClient::OnNewSession)); | 281 NewCallback(this, &ProtocolTestClient::OnNewSession)); |
283 session_manager_->set_allow_local_ips(true); | 282 session_manager_->set_allow_local_ips(true); |
284 | 283 |
285 if (host_jid_ != "") { | 284 if (host_jid_ != "") { |
286 ProtocolTestConnection* connection = | 285 ProtocolTestConnection* connection = |
287 new ProtocolTestConnection(this, client_->message_loop()); | 286 new ProtocolTestConnection(this, client_->message_loop()); |
288 connection->Init(session_manager_->Connect( | 287 connection->Init(session_manager_->Connect( |
289 host_jid_, CandidateChromotocolConfig::CreateDefault(), | 288 host_jid_, CandidateSessionConfig::CreateDefault(), |
290 NewCallback(connection, | 289 NewCallback(connection, |
291 &ProtocolTestConnection::OnStateChange))); | 290 &ProtocolTestConnection::OnStateChange))); |
292 connections_.push_back(make_scoped_refptr(connection)); | 291 connections_.push_back(make_scoped_refptr(connection)); |
293 } | 292 } |
294 } else if (state == JingleClient::CLOSED) { | 293 } else if (state == JingleClient::CLOSED) { |
295 std::cerr << "Connection closed" << std::endl; | 294 std::cerr << "Connection closed" << std::endl; |
296 } | 295 } |
297 } | 296 } |
298 | 297 |
299 void ProtocolTestClient::OnNewSession( | 298 void ProtocolTestClient::OnNewSession( |
300 Session* session, | 299 Session* session, |
301 SessionManager::IncomingSessionResponse* response) { | 300 SessionManager::IncomingSessionResponse* response) { |
302 std::cerr << "Accepting connection from " << session->jid() << std::endl; | 301 std::cerr << "Accepting connection from " << session->jid() << std::endl; |
303 | 302 |
304 session->set_config(ChromotocolConfig::CreateDefault()); | 303 session->set_config(SessionConfig::CreateDefault()); |
305 *response = SessionManager::ACCEPT; | 304 *response = SessionManager::ACCEPT; |
306 | 305 |
307 ProtocolTestConnection* test_connection = | 306 ProtocolTestConnection* test_connection = |
308 new ProtocolTestConnection(this, client_->message_loop()); | 307 new ProtocolTestConnection(this, client_->message_loop()); |
309 session->SetStateChangeCallback( | 308 session->SetStateChangeCallback( |
310 NewCallback(test_connection, &ProtocolTestConnection::OnStateChange)); | 309 NewCallback(test_connection, &ProtocolTestConnection::OnStateChange)); |
311 test_connection->Init(session); | 310 test_connection->Init(session); |
312 AutoLock auto_lock(connections_lock_); | 311 AutoLock auto_lock(connections_lock_); |
313 connections_.push_back(make_scoped_refptr(test_connection)); | 312 connections_.push_back(make_scoped_refptr(test_connection)); |
314 } | 313 } |
315 | 314 |
316 void ProtocolTestClient::OnFinishedClosing() { | 315 void ProtocolTestClient::OnFinishedClosing() { |
317 closed_event_.Signal(); | 316 closed_event_.Signal(); |
318 } | 317 } |
319 | 318 |
320 void ProtocolTestClient::DestroyConnection( | 319 void ProtocolTestClient::DestroyConnection( |
321 scoped_refptr<ProtocolTestConnection> connection) { | 320 scoped_refptr<ProtocolTestConnection> connection) { |
322 connection->Close(); | 321 connection->Close(); |
323 AutoLock auto_lock(connections_lock_); | 322 AutoLock auto_lock(connections_lock_); |
324 for (ConnectionsList::iterator it = connections_.begin(); | 323 for (ConnectionsList::iterator it = connections_.begin(); |
325 it != connections_.end(); ++it) { | 324 it != connections_.end(); ++it) { |
326 if ((*it) == connection) { | 325 if ((*it) == connection) { |
327 connections_.erase(it); | 326 connections_.erase(it); |
328 return; | 327 return; |
329 } | 328 } |
330 } | 329 } |
331 } | 330 } |
332 | 331 |
333 } // namespace protocol | 332 } // namespace protocol |
334 | |
335 } // namespace remoting | 333 } // namespace remoting |
336 | 334 |
337 using remoting::protocol::ProtocolTestClient; | 335 using remoting::protocol::ProtocolTestClient; |
338 | 336 |
339 void usage(char* command) { | 337 void usage(char* command) { |
340 std::cerr << "Usage: " << command << "--username=<username>" << std::endl | 338 std::cerr << "Usage: " << command << "--username=<username>" << std::endl |
341 << "\t--auth_token=<auth_token>" << std::endl | 339 << "\t--auth_token=<auth_token>" << std::endl |
342 << "\t[--host_jid=<host_jid>]" << std::endl; | 340 << "\t[--host_jid=<host_jid>]" << std::endl; |
343 exit(1); | 341 exit(1); |
344 } | 342 } |
(...skipping 19 matching lines...) Expand all Loading... |
364 if (!cmd_line->HasSwitch("auth_token")) | 362 if (!cmd_line->HasSwitch("auth_token")) |
365 usage(argv[0]); | 363 usage(argv[0]); |
366 std::string auth_token(cmd_line->GetSwitchValueASCII("auth_token")); | 364 std::string auth_token(cmd_line->GetSwitchValueASCII("auth_token")); |
367 | 365 |
368 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); | 366 scoped_refptr<ProtocolTestClient> client(new ProtocolTestClient()); |
369 | 367 |
370 client->Run(username, auth_token, host_jid); | 368 client->Run(username, auth_token, host_jid); |
371 | 369 |
372 return 0; | 370 return 0; |
373 } | 371 } |
OLD | NEW |