Commit 41b7a7ff authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Reland "bluetooth: Remove UriBeacon code"

Reason for reland: There is no more dependency in iOS

> Revert of bluetooth: Remove UriBeacon code (patchset #2 id:20001 of https://codereview.chromium.org/2015703002/ )
>
> Reason for revert:
> This code is still used on iOS. The code will be upstreamed soon, but at the moment some dependencies prevent it.
>
> Original issue's description:
> > bluetooth: Remove UriBeacon code
> >
> > This code was introduced by the Physical Web team when they were exploring
> > integration with Chrome. They ended up going a different route so this
> > code is useless now.
> >
> > Committed: https://crrev.com/3d392de68c541604a01a0c077c44d0ba4c7a02c7
> > Cr-Commit-Position: refs/heads/master@{#396112}
>
> TBR=scheib@chromium.org,ortuno@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://crrev.com/2faae4040325203cc26381aa24126c7fc6320f8a
> Cr-Commit-Position: refs/heads/master@{#396142}

Change-Id: If7718c2bf48124e933758f5ee1d105638deccce3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2278308
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: default avatarMatt Reynolds <mattreynolds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785604}
parent 8aa19533
......@@ -70,7 +70,6 @@ test("device_unittests") {
"bluetooth/test/test_bluetooth_local_gatt_service_delegate.h",
"bluetooth/test/test_pairing_delegate.cc",
"bluetooth/test/test_pairing_delegate.h",
"bluetooth/uribeacon/uri_encoder_unittest.cc",
"gamepad/abstract_haptic_gamepad_unittest.cc",
"gamepad/dualshock4_controller_unittest.cc",
"gamepad/gamepad_blocklist_unittest.cc",
......@@ -102,7 +101,6 @@ test("device_unittests") {
"//device/bluetooth",
"//device/bluetooth:deprecated_experimental_mojo",
"//device/bluetooth:mocks",
"//device/bluetooth/uribeacon",
"//device/fido",
"//device/fido:test_support",
"//device/gamepad",
......
......@@ -221,7 +221,6 @@ component("bluetooth") {
"//crypto",
"//device/base",
"//device/bluetooth/strings",
"//device/bluetooth/uribeacon",
"//ipc",
"//net",
"//third_party/re2",
......
# Copyright 2015 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.
source_set("uribeacon") {
sources = [
"uri_encoder.cc",
"uri_encoder.h",
]
deps = [ "//base" ]
}
// Copyright 2015 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 <string.h>
#include "uri_encoder.h"
#include "base/stl_util.h"
using base::StringPiece;
namespace {
struct expansion {
uint8_t code;
const char* value;
};
// The two following data structures are the expansions code tables for URI
// encoding described in the following specification:
// https://github.com/google/uribeacon/blob/master/specification/AdvertisingMode.md
// For the prefix of the URI.
struct expansion prefix_expansions_list[] = {
{0, "http://www."},
{1, "https://www."},
{2, "http://"},
{3, "https://"},
{4, "urn:uuid:"},
};
// For the remaining part of the URI.
struct expansion expansions_list[] = {
{0, ".com/"},
{1, ".org/"},
{2, ".edu/"},
{3, ".net/"},
{4, ".info/"},
{5, ".biz/"},
{6, ".gov/"},
{7, ".com"},
{8, ".org"},
{9, ".edu"},
{10, ".net"},
{11, ".info"},
{12, ".biz"},
{13, ".gov"},
};
struct expansion* CommonLookupExpansionByValue(struct expansion* table,
int table_length,
const std::string& input,
int input_index) {
int found = -1;
int found_length = -1;
for (int k = 0; k < table_length; k++) {
const char* value = table[k].value;
int len = static_cast<int>(strlen(table[k].value));
if (input_index + len <= static_cast<int>(input.size())) {
if (len > found_length && strncmp(&input[input_index], value, len) == 0) {
found = k;
found_length = len;
}
}
}
if (found == -1)
return NULL;
return &table[found];
}
struct expansion* LookupExpansionByValue(const std::string& input,
int input_index) {
return CommonLookupExpansionByValue(
expansions_list, base::size(expansions_list), input, input_index);
}
struct expansion* LookupPrefixExpansionByValue(const std::string& input,
int input_index) {
return CommonLookupExpansionByValue(prefix_expansions_list,
base::size(prefix_expansions_list), input,
input_index);
}
struct expansion* LookupExpansionByCode(const std::vector<uint8_t>& input,
int input_index) {
if (input[input_index] >= base::size(expansions_list))
return NULL;
return &expansions_list[input[input_index]];
}
struct expansion* LookupPrefixExpansionByCode(const std::vector<uint8_t>& input,
int input_index) {
if (input[input_index] >= base::size(prefix_expansions_list))
return NULL;
return &prefix_expansions_list[input[input_index]];
}
} // namespace
void device::EncodeUriBeaconUri(const std::string& input,
std::vector<uint8_t>& output) {
int i = 0;
while (i < static_cast<int>(input.size())) {
struct expansion* exp;
if (i == 0)
exp = LookupPrefixExpansionByValue(input, i);
else
exp = LookupExpansionByValue(input, i);
if (exp == NULL) {
output.push_back(static_cast<uint8_t>(input[i]));
i++;
} else {
output.push_back(exp->code);
i += static_cast<int>(strlen(exp->value));
}
}
}
void device::DecodeUriBeaconUri(const std::vector<uint8_t>& input,
std::string& output) {
int length = static_cast<int>(input.size());
for (int i = 0; i < length; i++) {
struct expansion* exp;
if (i == 0)
exp = LookupPrefixExpansionByCode(input, i);
else
exp = LookupExpansionByCode(input, i);
if (exp == NULL)
output.push_back(static_cast<char>(input[i]));
else
output.append(exp->value);
}
}
// Copyright 2015 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.
#ifndef DEVICE_BLUETOOTH_URIBEACON_URI_ENCODER_H_
#define DEVICE_BLUETOOTH_URIBEACON_URI_ENCODER_H_
#include <stdint.h>
#include <string>
#include <vector>
#include "base/strings/string_piece.h"
namespace device {
// The following functions EncodeUriBeaconUri() and DecodeUriBeaconUri() helps
// encoding/decoding URI with the UriBeacon encoding.
//
// Example usage:
//
// std::vector<uint8_t> encoded;
// EncodeUriBeaconUri("http://web.mit.edu/", encoded)
// // encoded -> {2, 'w', 'e', 'b', '.', 'm', 'i', 't', 2}
//
// const char encodedUri[] = {0, 'u', 'r', 'i', 'b', 'e', 'a', 'c', 'o', 'n',
// 8};
// const std::vector<uint8_t> kEncodedUri(encodedUri, encodedUri +
// sizeof(encodedUri));
// std::string decoded;
// DecodeUriBeaconUri(kEncodedUri, decoded)
// // decoded -> "http://uribeacon.org"
// Encodes the input string using URI encoding described in UriBeacon
// specifications. |input| must be ASCII characters.
void EncodeUriBeaconUri(const std::string& input, std::vector<uint8_t>& output);
// Decodes the input string using URI encoding described in UriBeacon
// specifications.
void DecodeUriBeaconUri(const std::vector<uint8_t>& input, std::string& output);
} // namespace device
#endif
// Copyright 2015 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 <stdint.h>
#include "device/bluetooth/uribeacon/uri_encoder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace device {
TEST(UriEncoderTest, Url1) {
const std::string kUri = "http://123.com";
const char encoded_uri[] = {2, '1', '2', '3', 7};
const std::vector<uint8_t> kEncodedUri(encoded_uri,
encoded_uri + sizeof(encoded_uri));
std::vector<uint8_t> encoded;
std::string decoded;
EncodeUriBeaconUri(kUri, encoded);
EXPECT_EQ(kEncodedUri, encoded);
DecodeUriBeaconUri(encoded, decoded);
EXPECT_EQ(kUri, decoded);
}
TEST(UriEncoderTest, Url2) {
const std::string kUri = "http://www.abcdefghijklmnop.org";
const char encoded_uri[] = {
0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 8};
const std::vector<uint8_t> kEncodedUri(encoded_uri,
encoded_uri + sizeof(encoded_uri));
std::vector<uint8_t> encoded;
std::string decoded;
EncodeUriBeaconUri(kUri, encoded);
EXPECT_EQ(kEncodedUri, encoded);
DecodeUriBeaconUri(encoded, decoded);
EXPECT_EQ(kUri, decoded);
}
TEST(UriEncoderTest, Url3) {
const std::string kUri = "https://123.com/123";
const char encoded_uri[] = {3, '1', '2', '3', 0, '1', '2', '3'};
const std::vector<uint8_t> kEncodedUri(encoded_uri,
encoded_uri + sizeof(encoded_uri));
std::vector<uint8_t> encoded;
std::string decoded;
EncodeUriBeaconUri(kUri, encoded);
EXPECT_EQ(kEncodedUri, encoded);
DecodeUriBeaconUri(encoded, decoded);
EXPECT_EQ(kUri, decoded);
}
TEST(UriEncoderTest, Url4) {
const std::string kUri = "http://www.uribeacon.org";
const char encoded_uri[] = {
0, 'u', 'r', 'i', 'b', 'e', 'a', 'c', 'o', 'n', 8};
const std::vector<uint8_t> kEncodedUri(encoded_uri,
encoded_uri + sizeof(encoded_uri));
std::vector<uint8_t> encoded;
std::string decoded;
EncodeUriBeaconUri(kUri, encoded);
EXPECT_EQ(kEncodedUri, encoded);
DecodeUriBeaconUri(encoded, decoded);
EXPECT_EQ(kUri, decoded);
}
TEST(UriEncoderTest, Url5) {
const std::string kUri = "http://web.mit.edu/";
const char encoded_uri[] = {2, 'w', 'e', 'b', '.', 'm', 'i', 't', 2};
const std::vector<uint8_t> kEncodedUri(encoded_uri,
encoded_uri + sizeof(encoded_uri));
std::vector<uint8_t> encoded;
std::string decoded;
EncodeUriBeaconUri(kUri, encoded);
EXPECT_EQ(kEncodedUri, encoded);
DecodeUriBeaconUri(encoded, decoded);
EXPECT_EQ(kUri, decoded);
}
} // namespace device
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment