mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 14:35:37 +02:00
The tools allow efficient and fast synchronization of large directory trees from a Windows workstation to a Linux target machine. cdc_rsync* support efficient copy of files by using content-defined chunking (CDC) to identify chunks within files that can be reused. asset_stream_manager + cdc_fuse_fs support efficient streaming of a local directory to a remote virtual file system based on FUSE. It also employs CDC to identify and reuse unchanged data chunks.
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
// Copyright 2022 Google LLC
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "common/url.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <regex>
|
|
|
|
#include "absl/strings/str_format.h"
|
|
|
|
namespace cdc_ft {
|
|
|
|
absl::StatusOr<Url> Url::Parse(const std::string& url_string) {
|
|
std::string url_copy = url_string;
|
|
std::for_each(url_copy.begin(), url_copy.end(),
|
|
[](char& c) { c = tolower(c); });
|
|
std::regex re("(https?)://([^:^?/]+)(?::([0-9]+))?.*");
|
|
std::smatch match;
|
|
if (!std::regex_match(url_copy, match, re))
|
|
return absl::Status(
|
|
absl::StatusCode::kInvalidArgument,
|
|
absl::StrFormat("'%s' is not a valid url.", url_string.c_str()));
|
|
Url url;
|
|
url.protocol = match[1].str();
|
|
url.host = match[2].str();
|
|
if (match.size() == 4 && match[3].length() > 0)
|
|
url.port = match[3].str();
|
|
else if (url.protocol.back() == 's')
|
|
url.port = "443";
|
|
else
|
|
url.port = "80";
|
|
return url;
|
|
}
|
|
|
|
Url::Url() = default;
|
|
|
|
Url::Url(std::string protocol, std::string host, std::string port)
|
|
: protocol(protocol), host(host), port(port) {}
|
|
|
|
Url::~Url() = default;
|
|
|
|
bool operator==(const Url& lhs, const Url& rhs) {
|
|
return lhs.host == rhs.host && lhs.port == rhs.port &&
|
|
lhs.protocol == rhs.protocol;
|
|
}
|
|
|
|
} // namespace cdc_ft
|