Skip to content

Commit

Permalink
Merge branch 'no-afnetworking'
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed May 17, 2020
2 parents 6ffba64 + 1a5d49a commit ca1286c
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 493 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
[submodule "deps/casablanca"]
path = deps/casablanca
url = https://github.com/Microsoft/cpprestsdk.git
[submodule "deps/AFNetworking"]
path = deps/AFNetworking
url = https://github.com/vslavik/AFNetworking.git
[submodule "deps/mctrl"]
path = deps/mctrl
url = https://github.com/mity/mctrl.git
Expand Down
6 changes: 0 additions & 6 deletions Poedit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
B22A5C86184E4B870034BEFD /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = B22A5C7F184E4B870034BEFD /* [email protected] */; };
B22A5C87184E4B870034BEFD /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = B22A5C80184E4B870034BEFD /* [email protected] */; };
B22C5F0A17DDC67400ECAFD1 /* language.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B22C5F0817DDC67400ECAFD1 /* language.cpp */; };
B22E690F1A936294002C06C7 /* libAFNetworking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B22E690E1A936294002C06C7 /* libAFNetworking.a */; };
B22E69111A93699E002C06C7 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B22E69101A93699E002C06C7 /* SystemConfiguration.framework */; };
B230E2281A73F81400FB1E57 /* hidpi.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B230E2261A73F81400FB1E57 /* hidpi.cpp */; };
B2377A202159179B0085E9C4 /* catalog_xliff.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2377A1E2159179B0085E9C4 /* catalog_xliff.cpp */; };
Expand Down Expand Up @@ -337,7 +336,6 @@
B22C5F0817DDC67400ECAFD1 /* language.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = language.cpp; sourceTree = "<group>"; };
B22C5F0917DDC67400ECAFD1 /* language.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = language.h; sourceTree = "<group>"; };
B22CC9CE1E7719E700709DEA /* cloud_sync.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cloud_sync.h; sourceTree = "<group>"; };
B22E690E1A936294002C06C7 /* libAFNetworking.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libAFNetworking.a; sourceTree = BUILT_PRODUCTS_DIR; };
B22E69101A93699E002C06C7 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
B230E2261A73F81400FB1E57 /* hidpi.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = hidpi.cpp; sourceTree = "<group>"; };
B230E2271A73F81400FB1E57 /* hidpi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hidpi.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -628,7 +626,6 @@
B2D76A50181D028B0083C9D9 /* libboost_system.a in Frameworks */,
B2D76A51181D028B0083C9D9 /* libboost_thread.a in Frameworks */,
B2083D131A87D17D00150BBF /* libcld2.a in Frameworks */,
B22E690F1A936294002C06C7 /* libAFNetworking.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -862,7 +859,6 @@
isa = PBXGroup;
children = (
B22E69101A93699E002C06C7 /* SystemConfiguration.framework */,
B22E690E1A936294002C06C7 /* libAFNetworking.a */,
B2083D121A87D17D00150BBF /* libcld2.a */,
B2284A54183BE68200E097C7 /* Security.framework */,
B2D76A46181D028B0083C9D9 /* libboost_date_time.a */,
Expand Down Expand Up @@ -1756,7 +1752,6 @@
deps/lucene,
deps/lucene/LucenePlusPlus/include,
deps/cld2,
deps/AFNetworking/AFNetworking,
"$(DEPS_BUILD_DIR)/icu/include",
);
LIBRARY_SEARCH_PATHS = "$(DEPS_BUILD_DIR)/icu/lib";
Expand Down Expand Up @@ -1828,7 +1823,6 @@
deps/lucene,
deps/lucene/LucenePlusPlus/include,
deps/cld2,
deps/AFNetworking/AFNetworking,
"$(DEPS_BUILD_DIR)/icu/include",
);
LIBRARY_SEARCH_PATHS = "$(DEPS_BUILD_DIR)/icu/lib";
Expand Down
3 changes: 0 additions & 3 deletions Poedit2.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion deps/AFNetworking
Submodule AFNetworking deleted from 3be799
329 changes: 0 additions & 329 deletions deps/custom_build/AFNetworking.xcodeproj/project.pbxproj

This file was deleted.

23 changes: 0 additions & 23 deletions docs/Acknowledgments.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,29 +291,6 @@ <h2>C++ REST SDK<a href="https://casablanca.codeplex.com"></a></h2>
SOFTWARE.


<h2>AFNetworking<a href="http://afnetworking.com"></a></h2>
<p>
Copyright (c) 2013-2014 AFNetworking (http://afnetworking.com/)
<p>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
<p>
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
<p>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


<h2>mCtrl<a href="http://mctrl.org"></a></h2>
<p>
mCtrl is covered with the <a href="https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html">GNU Lesser General Public License 2.1</a> or (at your option) any later version.
Expand Down
19 changes: 16 additions & 3 deletions src/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ class http_client
static void set_ui_language(const std::string& lang);
#endif

/// Return true if the server is reachable, i.e. client is online
bool is_reachable() const;

/// Sets Authorization header to be used in all requests
void set_authorization(const std::string& auth);

Expand Down Expand Up @@ -185,6 +182,22 @@ class http_client
std::unique_ptr<impl> m_impl;
};

/// Monitor if networking is available
class http_reachability
{
public:
/// Creates an instance of the monitor object.
http_reachability(const std::string& url);
~http_reachability();

/// Return true if the host is reachable, i.e. client is online
bool is_reachable() const;

private:
class impl;
std::unique_ptr<impl> m_impl;
};

#endif // HAVE_HTTP_CLIENT

#endif // Poedit_http_client_h
100 changes: 62 additions & 38 deletions src/http_client_casablanca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,41 +139,10 @@ class http_client::impl

std::shared_ptr<http::http_pipeline_stage> gzip_stage = std::make_shared<gzip_compression_support>();
m_native.add_handler(gzip_stage);

#ifdef _WIN32
m_networkListManager = nullptr;
CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL, IID_INetworkListManager, (LPVOID *)&m_networkListManager);
#endif
}

~impl()
{
#ifdef _WIN32
if (m_networkListManager)
m_networkListManager->Release();
#endif
}

static string_t ui_language;

bool is_reachable() const
{
#ifdef _WIN32
if (m_networkListManager)
{
NLM_CONNECTIVITY result;
HRESULT hr = m_networkListManager->GetConnectivity(&result);
if (SUCCEEDED(hr))
return result & (NLM_CONNECTIVITY_IPV4_INTERNET|NLM_CONNECTIVITY_IPV6_INTERNET);
}
// manager fallback (IPv6 ignorant):
DWORD flags;
return ::InternetGetConnectedState(&flags, 0);
#else
return true; // TODO
#endif
}

void set_authorization(const std::string& auth)
{
m_auth = std::wstring(auth.begin(), auth.end());
Expand Down Expand Up @@ -305,8 +274,6 @@ class http_client::impl

return std::to_wstring(info.dwMajorVersion) + L"." + std::to_wstring(info.dwMinorVersion);
}

INetworkListManager *m_networkListManager;
#endif

http_client& m_owner;
Expand All @@ -333,11 +300,6 @@ void http_client::set_ui_language(const std::string& lang)
impl::ui_language = to_string_t(lang);
}

bool http_client::is_reachable() const
{
return m_impl->is_reachable();
}

void http_client::set_authorization(const std::string& auth)
{
m_impl->set_authorization(auth);
Expand All @@ -357,3 +319,65 @@ dispatch::future<::json> http_client::post(const std::string& url, const http_bo
{
return m_impl->post(url, data);
}


#ifdef _WIN32

class http_reachability::impl
{
public:
impl()
{
m_networkListManager = nullptr;
CoCreateInstance(CLSID_NetworkListManager, NULL, CLSCTX_ALL, IID_INetworkListManager, (LPVOID *)&m_networkListManager);
}

~impl()
{
if (m_networkListManager)
m_networkListManager->Release();
}

bool is_reachable() const
{
if (m_networkListManager)
{
NLM_CONNECTIVITY result;
HRESULT hr = m_networkListManager->GetConnectivity(&result);
if (SUCCEEDED(hr))
return result & (NLM_CONNECTIVITY_IPV4_INTERNET|NLM_CONNECTIVITY_IPV6_INTERNET);
}
// manager fallback (IPv6 ignorant):
DWORD flags;
return ::InternetGetConnectedState(&flags, 0);
}

private:
INetworkListManager *m_networkListManager;
};

#else // !WIN32

class http_reachability::impl
{
public:
impl() {}
bool is_reachable() const { return true; } // TODO
};

#endif


http_reachability::http_reachability(const std::string& /*url*/)
: m_impl(new impl)
{
}

http_reachability::~http_reachability()
{
}

bool http_reachability::is_reachable() const
{
return m_impl->is_reachable();
}
Loading

0 comments on commit ca1286c

Please sign in to comment.