KiCad PCB EDA Suite
Loading...
Searching...
No Matches
remote_provider_utils.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef REMOTE_PROVIDER_UTILS_H
21#define REMOTE_PROVIDER_UTILS_H
22
23#include <vector>
24
26#include <kicommon.h>
27#include <wx/string.h>
28
29
34KICOMMON_API wxString UrlEncode( const wxString& aValue );
35
40KICOMMON_API wxString RemoteProviderJsonString( const nlohmann::json& aObject, const char* aKey );
41
46KICOMMON_API bool IsLoopbackHost( const wxString& aHost );
47
53KICOMMON_API bool ValidateRemoteUrlSecurity( const wxString& aUrl, bool aAllowInsecureLocalhost,
54 wxString& aError, const wxString& aLabel );
55
60KICOMMON_API wxString NormalizedUrlOrigin( const wxString& aUrl );
61
62
67class KICOMMON_API COLLECTING_JSON_ERROR_HANDLER : public nlohmann::json_schema::error_handler
68{
69public:
70 void error( const nlohmann::json::json_pointer& aPointer, const nlohmann::json& aInstance,
71 const std::string& aMessage ) override;
72
73 bool HasErrors() const { return !m_errors.empty(); }
74 wxString FirstError() const;
75
76private:
77 std::vector<wxString> m_errors;
78};
79
80#endif // REMOTE_PROVIDER_UTILS_H
Collects JSON-schema validation errors so the caller can inspect them after a validation pass.
void error(const nlohmann::json::json_pointer &aPointer, const nlohmann::json &aInstance, const std::string &aMessage) override
#define KICOMMON_API
Definition kicommon.h:28
KICOMMON_API wxString NormalizedUrlOrigin(const wxString &aUrl)
Return a normalized scheme://host:port origin string for aUrl.
KICOMMON_API bool IsLoopbackHost(const wxString &aHost)
Return true when aHost resolves to a loopback address (localhost, 127.0.0.1, or ::1).
KICOMMON_API bool ValidateRemoteUrlSecurity(const wxString &aUrl, bool aAllowInsecureLocalhost, wxString &aError, const wxString &aLabel)
Validate that aUrl uses HTTPS, or HTTP on a loopback address when aAllowInsecureLocalhost is true.
KICOMMON_API wxString RemoteProviderJsonString(const nlohmann::json &aObject, const char *aKey)
Extract an optional string value from a JSON object, returning an empty wxString when the key is abse...
KICOMMON_API wxString UrlEncode(const wxString &aValue)
Percent-encode a string for use in URL query parameters (RFC 3986 unreserved characters are passed th...