Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
) Some platforms were passing in an explicit port, even for default 80/443, while others were just leaving it blank. This led to discrepencies between the platform checkpoints, as a remote URL is used for calculating a replication checkpoint. If a preloaded database is used on a platform that differs in this manner, then the previous checkpoint will fail to be detected. This commit solves this by checking for both variations during the previous checkpoint search.
- Loading branch information
Showing
7 changed files
with
233 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// URLTransformer.cc | ||
// | ||
// Copyright (c) 2021 Couchbase. All rights reserved. | ||
// | ||
// 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 "URLTransformer.hh" | ||
#include "c4Replicator.h" | ||
|
||
namespace litecore::repl { | ||
URLTransformStrategy& operator++(URLTransformStrategy& s) { | ||
s = static_cast<URLTransformStrategy>(static_cast<unsigned>(s) + 1); | ||
return s; | ||
} | ||
|
||
static alloc_slice AsIs(slice inputURL) { | ||
return static_cast<alloc_slice>(inputURL); | ||
} | ||
|
||
static alloc_slice AddPort(slice inputURL) { | ||
C4Address addr; | ||
if(!c4address_fromURL(inputURL, &addr, nullptr) || (addr.port != 80 && addr.port != 443)) { | ||
return nullslice; | ||
} | ||
|
||
if(c4SliceEqual(kC4Replicator2Scheme, addr.scheme)) { | ||
addr.port = 80; | ||
} else if(c4SliceEqual(kC4Replicator2TLSScheme, addr.scheme)) { | ||
addr.port = 443; | ||
} | ||
|
||
return c4address_toURL(addr); | ||
} | ||
|
||
static alloc_slice RemovePort(slice inputURL) { | ||
C4Address addr; | ||
if(!c4address_fromURL(inputURL, &addr, nullptr) || (addr.port != 80 && addr.port != 443)) { | ||
return nullslice; | ||
} | ||
|
||
addr.port = 0; | ||
return c4address_toURL(addr); | ||
} | ||
|
||
alloc_slice transform_url(slice inputURL, URLTransformStrategy strategy) { | ||
switch(strategy) { | ||
case URLTransformStrategy::AsIs: | ||
return AsIs(inputURL); | ||
case URLTransformStrategy::AddPort: | ||
return AddPort(inputURL); | ||
case URLTransformStrategy::RemovePort: | ||
return RemovePort(inputURL); | ||
} | ||
|
||
return nullslice; | ||
} | ||
|
||
alloc_slice transform_url(const alloc_slice &inputURL, URLTransformStrategy strategy) { | ||
switch(strategy) { | ||
case URLTransformStrategy::AsIs: | ||
return inputURL; | ||
case URLTransformStrategy::AddPort: | ||
return AddPort(inputURL); | ||
case URLTransformStrategy::RemovePort: | ||
return RemovePort(inputURL); | ||
} | ||
|
||
return nullslice; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// URLTransformer.hh | ||
// | ||
// Copyright (c) 2021 Couchbase. All rights reserved. | ||
// | ||
// 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. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "fleece/slice.hh" | ||
#include <optional> | ||
|
||
namespace litecore::repl { | ||
using namespace fleece; | ||
using namespace std; | ||
|
||
/** | ||
* Strategies for handling the situation in CBL-1515 | ||
* (briefly, platforms are inconsistent about including port number | ||
* in their URLs) | ||
*/ | ||
enum class URLTransformStrategy : unsigned { | ||
AsIs, ///< Pass through the URL unaltered | ||
AddPort, ///< Force the port in the URL | ||
RemovePort ///< Force no port in the URL | ||
}; | ||
|
||
// An operator to allow simple forward iteration on the enum values | ||
URLTransformStrategy& operator++(URLTransformStrategy& s); | ||
|
||
/** | ||
* Transforms the URL passed in input using the provided strategy (note only URLs using | ||
* standard ports 80 / 443 will be considered for transformation) | ||
* | ||
* @param inputURL The URL to transform | ||
* @param strategy The strategy to use | ||
* @returns The transformed URL. If the URL is not a candidate for AddPort or RemovePort | ||
* (e.g. not a valid URL, or not using a standard port) then nullslice is returned) | ||
*/ | ||
alloc_slice transform_url(slice inputURL, URLTransformStrategy strategy); | ||
|
||
/** | ||
* Transforms the URL passed in input using the provided strategy (note only URLs using | ||
* standard ports 80 / 443 will be considered for transformation). This overload | ||
* is simply to allow the optimization to not make copies in the AsIs strategy. | ||
* | ||
* @param inputURL The URL to transform | ||
* @param strategy The strategy to use | ||
* @returns The transformed URL. If the URL is not a candidate for AddPort or RemovePort | ||
* (e.g. not a valid URL, or not using a standard port) then nullslice is returned) | ||
*/ | ||
alloc_slice transform_url(const alloc_slice &inputURL, URLTransformStrategy strategy); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters