15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/host/server_log_entry.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/stringize_macros.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/sys_info.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/base/constants.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "remoting/protocol/session.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::SysInfo; 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using buzz::QName; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using buzz::XmlElement; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using remoting::protocol::Session; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace remoting { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kLogCommand[] = "log"; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kLogEntry[] = "entry"; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyEventName[] = "event-name"; 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueEventNameSessionState[] = "session-state"; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueEventNameHeartbeat[] = "heartbeat"; 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochconst char kValueEventNameHostStatus[] = "host-status"; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyRole[] = "role"; 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueRoleHost[] = "host"; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyMode[] = "mode"; 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueModeIt2Me[] = "it2me"; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueModeMe2Me[] = "me2me"; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeySessionState[] = "session-state"; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueSessionStateConnected[] = "connected"; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValueSessionStateClosed[] = "closed"; 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochconst char kStatusName[] = "status"; 437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochconst char kExitCodeName[] = "exit-code"; 447dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyOsName[] = "os-name"; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyOsVersion[] = "os-version"; 494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyHostVersion[] = "host-version"; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyCpu[] = "cpu"; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kKeyConnectionType[] = "connection-type"; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ServerLogEntry::ServerLogEntry() { 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ServerLogEntry::~ServerLogEntry() { 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_ptr<buzz::XmlElement> ServerLogEntry::MakeStanza() { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return scoped_ptr<buzz::XmlElement>( 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new XmlElement(QName(kChromotingXmlNamespace, kLogCommand))); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForSessionStateChange( 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool connected) { 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->Set(kKeyRole, kValueRoleHost); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->Set(kKeyEventName, kValueEventNameSessionState); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->Set(kKeySessionState, GetValueSessionState(connected)); 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return entry.Pass(); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_ptr<ServerLogEntry> ServerLogEntry::MakeForHeartbeat() { 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->Set(kKeyRole, kValueRoleHost); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) entry->Set(kKeyEventName, kValueEventNameHeartbeat); 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return entry.Pass(); 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// static 907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochscoped_ptr<ServerLogEntry> ServerLogEntry::MakeForHostStatus( 917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch HostStatusSender::HostStatus host_status, HostExitCodes exit_code) { 927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch scoped_ptr<ServerLogEntry> entry(new ServerLogEntry()); 937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch entry->Set(kKeyRole, kValueRoleHost); 947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch entry->Set(kKeyEventName, kValueEventNameHostStatus); 957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch entry->Set(kStatusName, HostStatusSender::HostStatusToString(host_status)); 967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (host_status == HostStatusSender::OFFLINE) 977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch entry->Set(kExitCodeName, ExitCodeToString(exit_code)); 987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch return entry.Pass(); 997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 1007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ServerLogEntry::AddHostFields() { 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 10368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Set(kKeyOsName, "Windows"); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(OS_MACOSX) 10568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Set(kKeyOsName, "Mac"); 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(OS_CHROMEOS) 10768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Set(kKeyOsName, "ChromeOS"); 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(OS_LINUX) 10968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Set(kKeyOsName, "Linux"); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SysInfo::OperatingSystemVersionNumbers is only defined for the following 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // OSes: see base/sys_info_unittest.cc. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::stringstream os_version; 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 os_major_version = 0; 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 os_minor_version = 0; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int32 os_bugfix_version = 0; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SysInfo::OperatingSystemVersionNumbers(&os_major_version, &os_minor_version, 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) &os_bugfix_version); 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) os_version << os_major_version << "." << os_minor_version << "." 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) << os_bugfix_version; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Set(kKeyOsVersion, os_version.str()); 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Set(kKeyHostVersion, STRINGIZE(VERSION)); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Set(kKeyCpu, SysInfo::OperatingSystemArchitecture()); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ServerLogEntry::AddModeField(ServerLogEntry::Mode mode) { 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Set(kKeyMode, GetValueMode(mode)); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ServerLogEntry::AddConnectionTypeField( 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protocol::TransportRoute::RouteType type) { 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Set(kKeyConnectionType, protocol::TransportRoute::GetTypeString(type)); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* ServerLogEntry::GetValueMode(ServerLogEntry::Mode mode) { 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (mode) { 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case IT2ME: 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return kValueModeIt2Me; 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ME2ME: 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return kValueModeMe2Me; 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NOTREACHED(); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)scoped_ptr<XmlElement> ServerLogEntry::ToStanza() const { 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<XmlElement> stanza(new XmlElement(QName( 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) kChromotingXmlNamespace, kLogEntry))); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ValuesMap::const_iterator iter; 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (iter = values_map_.begin(); iter != values_map_.end(); ++iter) { 157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) stanza->AddAttr(QName(std::string(), iter->first), iter->second); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return stanza.Pass(); 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// static 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char* ServerLogEntry::GetValueSessionState(bool connected) { 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return connected ? kValueSessionStateConnected : kValueSessionStateClosed; 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ServerLogEntry::Set(const std::string& key, const std::string& value) { 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) values_map_[key] = value; 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace remoting 172