Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
174
tools/EVerest-main/lib/everest/ocpp/3rd_party/websocketpp_utils/base64.hpp
vendored
Normal file
174
tools/EVerest-main/lib/everest/ocpp/3rd_party/websocketpp_utils/base64.hpp
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
******
|
||||
base64.hpp is a repackaging of the base64.cpp and base64.h files into a
|
||||
single header suitable for use as a header only library. This conversion was
|
||||
done by Peter Thorson (webmaster@zaphoyd.com) in 2012. All modifications to
|
||||
the code are redistributed under the same license as the original, which is
|
||||
listed below.
|
||||
******
|
||||
|
||||
base64.cpp and base64.h
|
||||
|
||||
Copyright (C) 2004-2008 René Nyffenegger
|
||||
|
||||
This source code is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented; you must not
|
||||
claim that you wrote the original source code. If you use this source code
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original source code.
|
||||
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BASE64_EVEREST_HPP_
|
||||
#define BASE64_EVEREST_HPP_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ocpp {
|
||||
|
||||
static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/";
|
||||
|
||||
/// Test whether a character is a valid base64 character
|
||||
/**
|
||||
* @param c The character to test
|
||||
* @return true if c is a valid base64 character
|
||||
*/
|
||||
static inline bool is_base64(unsigned char c) {
|
||||
return (c == 43 || // +
|
||||
(c >= 47 && c <= 57) || // /-9
|
||||
(c >= 65 && c <= 90) || // A-Z
|
||||
(c >= 97 && c <= 122)); // a-z
|
||||
}
|
||||
|
||||
/// Encode a char buffer into a base64 string
|
||||
/**
|
||||
* @param input The input data
|
||||
* @param len The length of input in bytes
|
||||
* @return A base64 encoded string representing input
|
||||
*/
|
||||
inline std::string base64_encode(const unsigned char* input, size_t len) {
|
||||
std::string ret;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
unsigned char char_array_3[3];
|
||||
unsigned char char_array_4[4];
|
||||
|
||||
while ((len--) != 0) {
|
||||
char_array_3[i++] = *(input++);
|
||||
if (i == 3) {
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for (i = 0; (i < 4); i++) {
|
||||
ret += base64_chars[char_array_4[i]];
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
for (j = i; j < 3; j++) {
|
||||
char_array_3[j] = '\0';
|
||||
}
|
||||
|
||||
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
|
||||
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
|
||||
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
|
||||
char_array_4[3] = char_array_3[2] & 0x3f;
|
||||
|
||||
for (j = 0; (j < i + 1); j++) {
|
||||
ret += base64_chars[char_array_4[j]];
|
||||
}
|
||||
|
||||
while ((i++ < 3)) {
|
||||
ret += '=';
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Encode a string into a base64 string
|
||||
/**
|
||||
* @param input The input data
|
||||
* @return A base64 encoded string representing input
|
||||
*/
|
||||
inline std::string base64_encode(const std::string& input) {
|
||||
return base64_encode(reinterpret_cast<const unsigned char*>(input.data()), input.size());
|
||||
}
|
||||
|
||||
/// Decode a base64 encoded string into a string of raw bytes
|
||||
/**
|
||||
* @param input The base64 encoded input data
|
||||
* @return A string representing the decoded raw bytes
|
||||
*/
|
||||
inline std::string base64_decode(const std::string& input) {
|
||||
size_t in_len = input.size();
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int in_ = 0;
|
||||
unsigned char char_array_4[4];
|
||||
unsigned char char_array_3[3];
|
||||
std::string ret;
|
||||
|
||||
while (((in_len--) != 0) && (input[in_] != '=') && is_base64(input[in_])) {
|
||||
char_array_4[i++] = input[in_];
|
||||
in_++;
|
||||
if (i == 4) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
char_array_4[i] = static_cast<unsigned char>(base64_chars.find(char_array_4[i]));
|
||||
}
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (i = 0; (i < 3); i++) {
|
||||
ret += char_array_3[i];
|
||||
}
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
for (j = i; j < 4; j++) {
|
||||
char_array_4[j] = 0;
|
||||
}
|
||||
|
||||
for (j = 0; j < 4; j++) {
|
||||
char_array_4[j] = static_cast<unsigned char>(base64_chars.find(char_array_4[j]));
|
||||
}
|
||||
|
||||
char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
|
||||
char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
|
||||
char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
|
||||
|
||||
for (j = 0; (j < i - 1); j++) {
|
||||
ret += static_cast<std::string::value_type>(char_array_3[j]);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace ocpp
|
||||
|
||||
#endif // BASE64_EVEREST_HPP_
|
||||
313
tools/EVerest-main/lib/everest/ocpp/3rd_party/websocketpp_utils/uri.hpp
vendored
Normal file
313
tools/EVerest-main/lib/everest/ocpp/3rd_party/websocketpp_utils/uri.hpp
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WEBSOCKETPP_URI_EVEREST_HPP
|
||||
#define WEBSOCKETPP_URI_EVEREST_HPP
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
namespace ocpp {
|
||||
|
||||
// TODO: figure out why this fixes horrible linking errors.
|
||||
|
||||
/// Default port for ws://
|
||||
static const uint16_t uri_default_port = 80;
|
||||
/// Default port for wss://
|
||||
static const uint16_t uri_default_secure_port = 443;
|
||||
|
||||
class uri {
|
||||
public:
|
||||
explicit uri(const std::string& uri_string) : m_valid(false) {
|
||||
std::string::const_iterator it;
|
||||
std::string::const_iterator temp;
|
||||
|
||||
int state = 0;
|
||||
|
||||
it = uri_string.begin();
|
||||
const size_t uri_len = uri_string.length();
|
||||
|
||||
if (uri_len >= 7 && std::equal(it, it + 6, "wss://")) {
|
||||
m_secure = true;
|
||||
m_scheme = "wss";
|
||||
it += 6;
|
||||
} else if (uri_len >= 6 && std::equal(it, it + 5, "ws://")) {
|
||||
m_secure = false;
|
||||
m_scheme = "ws";
|
||||
it += 5;
|
||||
} else if (uri_len >= 8 && std::equal(it, it + 7, "http://")) {
|
||||
m_secure = false;
|
||||
m_scheme = "http";
|
||||
it += 7;
|
||||
} else if (uri_len >= 9 && std::equal(it, it + 8, "https://")) {
|
||||
m_secure = true;
|
||||
m_scheme = "https";
|
||||
it += 8;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// extract host.
|
||||
// either a host string
|
||||
// an IPv4 address
|
||||
// or an IPv6 address
|
||||
if (*it == '[') {
|
||||
++it;
|
||||
// IPv6 literal
|
||||
// extract IPv6 digits until ]
|
||||
|
||||
// TODO: this doesn't work on g++... not sure why
|
||||
// temp = std::find(it,it2,']');
|
||||
|
||||
temp = it;
|
||||
while (temp != uri_string.end()) {
|
||||
if (*temp == ']') {
|
||||
break;
|
||||
}
|
||||
++temp;
|
||||
}
|
||||
|
||||
if (temp == uri_string.end()) {
|
||||
return;
|
||||
}
|
||||
// validate IPv6 literal parts
|
||||
// can contain numbers, a-f and A-F
|
||||
m_host.append(it, temp);
|
||||
|
||||
it = temp + 1;
|
||||
if (it == uri_string.end()) {
|
||||
state = 2;
|
||||
} else if (*it == '/') {
|
||||
state = 2;
|
||||
++it;
|
||||
} else if (*it == ':') {
|
||||
state = 1;
|
||||
++it;
|
||||
} else {
|
||||
// problem
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// IPv4 or hostname
|
||||
// extract until : or /
|
||||
while (state == 0) {
|
||||
if (it == uri_string.end()) {
|
||||
state = 2;
|
||||
break;
|
||||
}
|
||||
if (*it == '/') {
|
||||
state = 2;
|
||||
} else if (*it == ':') {
|
||||
// end hostname start port
|
||||
state = 1;
|
||||
} else {
|
||||
m_host += *it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// parse port
|
||||
std::string port;
|
||||
while (state == 1) {
|
||||
if (it == uri_string.end()) {
|
||||
// state is not used after this point presently.
|
||||
// this should be re-enabled if it ever is needed in a future
|
||||
// refactoring
|
||||
// state = 3;
|
||||
break;
|
||||
}
|
||||
if (*it == '/') {
|
||||
state = 3;
|
||||
} else {
|
||||
port += *it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
m_port = get_port_from_string(port, m_valid);
|
||||
|
||||
m_resource = "/";
|
||||
m_resource.append(it, uri_string.end());
|
||||
}
|
||||
|
||||
uri(bool secure, const std::string& host, uint16_t port, const std::string& resource) :
|
||||
m_scheme(secure ? "wss" : "ws"),
|
||||
m_host(host),
|
||||
m_resource(resource.empty() ? "/" : resource),
|
||||
m_port(port),
|
||||
m_secure(secure),
|
||||
m_valid(true) {
|
||||
}
|
||||
|
||||
uri(bool secure, const std::string& host, const std::string& resource) :
|
||||
m_scheme(secure ? "wss" : "ws"),
|
||||
m_host(host),
|
||||
m_resource(resource.empty() ? "/" : resource),
|
||||
m_port(secure ? uri_default_secure_port : uri_default_port),
|
||||
m_secure(secure),
|
||||
m_valid(true) {
|
||||
}
|
||||
|
||||
uri(bool secure, const std::string& host, const std::string& port, const std::string& resource) :
|
||||
m_scheme(secure ? "wss" : "ws"), m_host(host), m_resource(resource.empty() ? "/" : resource), m_secure(secure) {
|
||||
m_port = get_port_from_string(port, m_valid);
|
||||
}
|
||||
|
||||
uri(const std::string& scheme, const std::string& host, uint16_t port, const std::string& resource) :
|
||||
m_scheme(scheme),
|
||||
m_host(host),
|
||||
m_resource(resource.empty() ? "/" : resource),
|
||||
m_port(port),
|
||||
m_secure(scheme == "wss" || scheme == "https"),
|
||||
m_valid(true) {
|
||||
}
|
||||
|
||||
uri(std::string scheme, const std::string& host, const std::string& resource) :
|
||||
m_scheme(scheme),
|
||||
m_host(host),
|
||||
m_resource(resource.empty() ? "/" : resource),
|
||||
m_port((scheme == "wss" || scheme == "https") ? uri_default_secure_port : uri_default_port),
|
||||
m_secure(scheme == "wss" || scheme == "https"),
|
||||
m_valid(true) {
|
||||
}
|
||||
|
||||
uri(const std::string& scheme, const std::string& host, const std::string& port, const std::string& resource) :
|
||||
m_scheme(scheme),
|
||||
m_host(host),
|
||||
m_resource(resource.empty() ? "/" : resource),
|
||||
m_secure(scheme == "wss" || scheme == "https") {
|
||||
m_port = get_port_from_string(port, m_valid);
|
||||
}
|
||||
|
||||
bool get_valid() const {
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
bool get_secure() const {
|
||||
return m_secure;
|
||||
}
|
||||
|
||||
const std::string& get_scheme() const {
|
||||
return m_scheme;
|
||||
}
|
||||
|
||||
const std::string& get_host() const {
|
||||
return m_host;
|
||||
}
|
||||
|
||||
std::string get_host_port() const {
|
||||
if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
|
||||
return m_host;
|
||||
}
|
||||
std::stringstream p;
|
||||
p << m_host << ":" << m_port;
|
||||
return p.str();
|
||||
}
|
||||
|
||||
std::string get_authority() const {
|
||||
std::stringstream p;
|
||||
p << m_host << ":" << m_port;
|
||||
return p.str();
|
||||
}
|
||||
|
||||
uint16_t get_port() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
std::string get_port_str() const {
|
||||
std::stringstream p;
|
||||
p << m_port;
|
||||
return p.str();
|
||||
}
|
||||
|
||||
const std::string& get_resource() const {
|
||||
return m_resource;
|
||||
}
|
||||
|
||||
std::string str() const {
|
||||
std::stringstream s;
|
||||
|
||||
s << m_scheme << "://" << m_host;
|
||||
|
||||
if (m_port != (m_secure ? uri_default_secure_port : uri_default_port)) {
|
||||
s << ":" << m_port;
|
||||
}
|
||||
|
||||
s << m_resource;
|
||||
return s.str();
|
||||
}
|
||||
|
||||
/// Return the query portion
|
||||
/**
|
||||
* Returns the query portion (after the ?) of the URI or an empty string if
|
||||
* there is none.
|
||||
*
|
||||
* @return query portion of the URI.
|
||||
*/
|
||||
std::string get_query() const {
|
||||
const std::size_t found = m_resource.find('?');
|
||||
if (found != std::string::npos) {
|
||||
return m_resource.substr(found + 1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t get_port_from_string(const std::string& port, bool& out_valid) const {
|
||||
out_valid = true;
|
||||
if (port.empty()) {
|
||||
return (m_secure ? uri_default_secure_port : uri_default_port);
|
||||
}
|
||||
|
||||
const auto t_port = std::stoul(port);
|
||||
|
||||
if (t_port > 65535) {
|
||||
out_valid = false;
|
||||
}
|
||||
|
||||
if (t_port == 0) {
|
||||
out_valid = false;
|
||||
}
|
||||
|
||||
return static_cast<uint16_t>(t_port);
|
||||
}
|
||||
|
||||
std::string m_scheme;
|
||||
std::string m_host;
|
||||
std::string m_resource;
|
||||
uint16_t m_port = 0;
|
||||
bool m_secure = false;
|
||||
bool m_valid = false;
|
||||
};
|
||||
|
||||
} // namespace ocpp
|
||||
|
||||
#endif // WEBSOCKETPP_URI_HPP
|
||||
Reference in New Issue
Block a user