Index: chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc |
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc b/chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc |
index 34c69483f6af03961720b09e9d64905f0d87e668..bad124633845b66684ed2039dbeebb5088ce0821 100644 |
--- a/chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc |
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_service_record.cc |
@@ -6,14 +6,21 @@ |
#include <string> |
+#include "base/logging.h" |
+#include "base/string_number_conversions.h" |
#include "chrome/common/libxml_utils.h" |
namespace { |
static const char* kAttributeNode = "attribute"; |
static const char* kIdAttribute = "id"; |
+static const char* kProtocolDescriptorListId = "0x0004"; |
+static const char* kRfcommUuid = "0x0003"; |
static const char* kSdpNameId = "0x0100"; |
+static const char* kSequenceNode = "sequence"; |
static const char* kTextNode = "text"; |
+static const char* kUint8Node = "uint8"; |
+static const char* kUuidNode = "uuid"; |
static const char* kValueAttribute = "value"; |
bool advanceToTag(XmlReader* reader, const char* node_type) { |
@@ -30,6 +37,7 @@ namespace chromeos { |
bool BluetoothServiceRecord::Init(const std::string& xml_data) { |
name_.clear(); |
+ supports_rfcomm_ = false; |
keybuk
2012/04/19 01:05:40
Isn't this in the constructor now
bryeung
2012/04/19 19:42:43
Yep :-)
|
XmlReader reader; |
if (!reader.Load(xml_data)) |
@@ -39,10 +47,14 @@ bool BluetoothServiceRecord::Init(const std::string& xml_data) { |
std::string id; |
if (reader.NodeAttribute(kIdAttribute, &id)) { |
if (id == kSdpNameId) { |
- if (advanceToTag(&reader, kTextNode)) { |
- std::string value; |
- if (reader.NodeAttribute(kValueAttribute, &value)) |
- name_ = value; |
+ if (advanceToTag(&reader, kTextNode)) |
+ reader.NodeAttribute(kValueAttribute, &name_); |
+ } else if (id == kProtocolDescriptorListId) { |
+ if (advanceToTag(&reader, kSequenceNode)) { |
+ std::string sequence_content; |
+ if (reader.ReadElementContent(&sequence_content)) { |
+ ExtractChannels(sequence_content); |
+ } |
keybuk
2012/04/19 01:05:40
may as well add L2CAP + L2CAP PSM while you're in
bryeung
2012/04/19 19:42:43
future CL?
|
} |
} |
} |
@@ -53,4 +65,33 @@ bool BluetoothServiceRecord::Init(const std::string& xml_data) { |
return true; |
} |
+void BluetoothServiceRecord::ExtractChannels(const std::string& xml_data) { |
+ XmlReader reader; |
+ if (!reader.Load(xml_data)) |
+ return; |
+ |
+ do { |
+ if (reader.NodeName() == kSequenceNode) { |
+ if (advanceToTag(&reader, kUuidNode)) { |
+ std::string type; |
+ if (reader.NodeAttribute(kValueAttribute, &type) && |
+ type == kRfcommUuid) { |
+ if (advanceToTag(&reader, kUint8Node)) { |
+ std::string channel_string; |
+ if (reader.NodeAttribute(kValueAttribute, &channel_string)) { |
+ unsigned channel; |
+ if (base::StringToUint(channel_string, &channel)) { |
+ if ((channel & 0xFF) == channel) { |
+ rfcomm_channel_ = static_cast<uint8_t>(channel); |
+ supports_rfcomm_ = true; |
+ } |
+ } |
+ } |
+ } |
+ } |
+ } |
+ } |
+ } while (advanceToTag(&reader, kSequenceNode)); |
+} |
+ |
} // namespace chromeos |