Merge pull request 'formated code' (#13) from formated-code into main
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled

Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/openrouter/pulls/13
This commit was merged in pull request #13.
This commit is contained in:
wt committed 2025-02-13 12:27:14 +03:00
commit c86d4d77ba
11 files changed
+1720 -822

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
tab_width = 8
trim_trailing_whitespace = true
insert_final_newline = true
[DEVELOPERS]
indent_style = tab
indent_size = tab
[Config*.in*]
indent_style = tab
indent_size = tab
[linux/Config.ext.in]
indent_style = tab
indent_size = tab
[Makefile*]
indent_style = tab
indent_size = tab
[*.mk]
indent_style = tab
indent_size = tab
[*.patch]
trim_trailing_whitespace = false
[S{0..9}{0..9}*]
indent_style = tab
indent_size = tab
[*.adoc]
trim_trailing_whitespace = false
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
cpp_indent_case_contents_when_block = true
cpp_new_line_before_open_brace_namespace = new_line
cpp_new_line_before_open_brace_function = new_line
+28 -4
View File
@@ -1,13 +1,37 @@
CXX=g++ CXX=g++
STRIP=strip STRIP=strip
CXXFLAGS=-Wall -I src/libs -I src -std=c++20 CXXFLAGS=-Wall -I src/libs -I src -std=c++20
SOURCES=src/openrouter.cpp src/security/cors.cpp src/settings/telnet/enabled.cpp src/settings/telnet/port.cpp src/settings/ssh/status.cpp src/settings/ssh/keys.cpp src/settings/ssh/port.cpp src/settings/ssh/server.cpp src/settings/dns/enabled.cpp src/settings/dns/servers.cpp src/settings/dns/local_domains.cpp src/settings/wifi/status.cpp src/settings/wifi/name.cpp src/settings/wifi/password.cpp src/settings/wifi/qr.cpp src/settings/wifi/channel.cpp src/settings/ftp/ftp.cpp src/system/reboot/reboot.cpp src/system/syslog/syslog.cpp src/system/uptime/uptime.cpp src/OpenRouter/OpenRouter.cpp src/auth/auth.cpp src/libs/QR-Code-generator/qrcodegen.cpp src/libs/QR-Code-generator/qrtosvg.cpp SOURCES=src/openrouter.cpp \
TARGET=bin/openrouter src/security/cors.cpp \
src/settings/telnet/enabled.cpp \
src/settings/telnet/port.cpp \
src/settings/ssh/status.cpp \
src/settings/ssh/keys.cpp \
src/settings/ssh/port.cpp \
src/settings/ssh/server.cpp \
src/settings/dns/enabled.cpp \
src/settings/dns/servers.cpp \
src/settings/dns/local_domains.cpp \
src/settings/wifi/status.cpp \
src/settings/wifi/name.cpp \
src/settings/wifi/password.cpp \
src/settings/wifi/qr.cpp \
src/settings/wifi/channel.cpp \
src/settings/ftp/ftp.cpp \
src/system/reboot/reboot.cpp \
src/system/syslog/syslog.cpp \
src/system/uptime/uptime.cpp \
src/OpenRouter/OpenRouter.cpp \
src/auth/auth.cpp \
src/libs/QR-Code-generator/qrcodegen.cpp \
src/libs/QR-Code-generator/qrtosvg.cpp
TARGET=build/openrouter
default: all default: all
all: build all: build
.PHONY: build
build: build:
@if [ ! -d bin ]; then \ @if [ ! -d build ]; then \
mkdir bin; \ mkdir build; \
fi fi
$(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS) $(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS)
$(STRIP) $(TARGET) $(STRIP) $(TARGET)
+2 -7
View File
@@ -33,12 +33,7 @@ executable(
'src/libs/QR-Code-generator/qrcodegen.cpp', 'src/libs/QR-Code-generator/qrcodegen.cpp',
'src/libs/QR-Code-generator/qrtosvg.cpp', 'src/libs/QR-Code-generator/qrtosvg.cpp',
include_directories: include_dirs, include_directories: include_dirs,
install: true install: true,
) )
install_subdir( install_subdir('src/web', install_dir: 'share/openrouter')
'src/web',
install_dir: 'share/openrouter'
)
+106 -53
View File
@@ -37,24 +37,28 @@ using std::size_t;
using std::vector; using std::vector;
namespace qrcodegen { namespace qrcodegen
{
/*---- Class QrSegment ----*/ /*---- Class QrSegment ----*/
QrSegment::Mode::Mode(int mode, int cc0, int cc1, int cc2) : QrSegment::Mode::Mode(int mode, int cc0, int cc1, int cc2) :
modeBits(mode) { modeBits(mode)
{
numBitsCharCount[0] = cc0; numBitsCharCount[0] = cc0;
numBitsCharCount[1] = cc1; numBitsCharCount[1] = cc1;
numBitsCharCount[2] = cc2; numBitsCharCount[2] = cc2;
} }
int QrSegment::Mode::getModeBits() const { int QrSegment::Mode::getModeBits() const
{
return modeBits; return modeBits;
} }
int QrSegment::Mode::numCharCountBits(int ver) const { int QrSegment::Mode::numCharCountBits(int ver) const
{
return numBitsCharCount[(ver + 7) / 17]; return numBitsCharCount[(ver + 7) / 17];
} }
@@ -66,7 +70,8 @@ const QrSegment::Mode QrSegment::Mode::KANJI (0x8, 8, 10, 12);
const QrSegment::Mode QrSegment::Mode::ECI(0x7, 0, 0, 0); const QrSegment::Mode QrSegment::Mode::ECI(0x7, 0, 0, 0);
QrSegment QrSegment::makeBytes(const vector<uint8_t> &data) { QrSegment QrSegment::makeBytes(const vector<uint8_t>& data)
{
if (data.size() > static_cast<unsigned int>(INT_MAX)) if (data.size() > static_cast<unsigned int>(INT_MAX))
throw std::length_error("Data too long"); throw std::length_error("Data too long");
BitBuffer bb; BitBuffer bb;
@@ -76,7 +81,8 @@ QrSegment QrSegment::makeBytes(const vector<uint8_t> &data) {
} }
QrSegment QrSegment::makeNumeric(const char *digits) { QrSegment QrSegment::makeNumeric(const char* digits)
{
BitBuffer bb; BitBuffer bb;
int accumData = 0; int accumData = 0;
int accumCount = 0; int accumCount = 0;
@@ -99,7 +105,8 @@ QrSegment QrSegment::makeNumeric(const char *digits) {
} }
QrSegment QrSegment::makeAlphanumeric(const char *text) { QrSegment QrSegment::makeAlphanumeric(const char* text)
{
BitBuffer bb; BitBuffer bb;
int accumData = 0; int accumData = 0;
int accumCount = 0; int accumCount = 0;
@@ -122,7 +129,8 @@ QrSegment QrSegment::makeAlphanumeric(const char *text) {
} }
vector<QrSegment> QrSegment::makeSegments(const char *text) { vector<QrSegment> QrSegment::makeSegments(const char* text)
{
// Select the most efficient segment encoding automatically // Select the most efficient segment encoding automatically
vector<QrSegment> result; vector<QrSegment> result;
if (*text == '\0'); // Leave result empty if (*text == '\0'); // Leave result empty
@@ -140,7 +148,8 @@ vector<QrSegment> QrSegment::makeSegments(const char *text) {
} }
QrSegment QrSegment::makeEci(long assignVal) { QrSegment QrSegment::makeEci(long assignVal)
{
BitBuffer bb; BitBuffer bb;
if (assignVal < 0) if (assignVal < 0)
throw std::domain_error("ECI assignment value out of range"); throw std::domain_error("ECI assignment value out of range");
@@ -149,10 +158,12 @@ QrSegment QrSegment::makeEci(long assignVal) {
else if (assignVal < (1 << 14)) { else if (assignVal < (1 << 14)) {
bb.appendBits(2, 2); bb.appendBits(2, 2);
bb.appendBits(static_cast<uint32_t>(assignVal), 14); bb.appendBits(static_cast<uint32_t>(assignVal), 14);
} else if (assignVal < 1000000L) { }
else if (assignVal < 1000000L) {
bb.appendBits(6, 3); bb.appendBits(6, 3);
bb.appendBits(static_cast<uint32_t>(assignVal), 21); bb.appendBits(static_cast<uint32_t>(assignVal), 21);
} else }
else
throw std::domain_error("ECI assignment value out of range"); throw std::domain_error("ECI assignment value out of range");
return QrSegment(Mode::ECI, 0, std::move(bb)); return QrSegment(Mode::ECI, 0, std::move(bb));
} }
@@ -161,7 +172,8 @@ QrSegment QrSegment::makeEci(long assignVal) {
QrSegment::QrSegment(const Mode& md, int numCh, const std::vector<bool>& dt) : QrSegment::QrSegment(const Mode& md, int numCh, const std::vector<bool>& dt) :
mode(&md), mode(&md),
numChars(numCh), numChars(numCh),
data(dt) { data(dt)
{
if (numCh < 0) if (numCh < 0)
throw std::domain_error("Invalid value"); throw std::domain_error("Invalid value");
} }
@@ -170,13 +182,15 @@ QrSegment::QrSegment(const Mode &md, int numCh, const std::vector<bool> &dt) :
QrSegment::QrSegment(const Mode& md, int numCh, std::vector<bool>&& dt) : QrSegment::QrSegment(const Mode& md, int numCh, std::vector<bool>&& dt) :
mode(&md), mode(&md),
numChars(numCh), numChars(numCh),
data(std::move(dt)) { data(std::move(dt))
{
if (numCh < 0) if (numCh < 0)
throw std::domain_error("Invalid value"); throw std::domain_error("Invalid value");
} }
int QrSegment::getTotalBits(const vector<QrSegment> &segs, int version) { int QrSegment::getTotalBits(const vector<QrSegment>& segs, int version)
{
int result = 0; int result = 0;
for (const QrSegment& seg : segs) { for (const QrSegment& seg : segs) {
int ccbits = seg.mode->numCharCountBits(version); int ccbits = seg.mode->numCharCountBits(version);
@@ -193,7 +207,8 @@ int QrSegment::getTotalBits(const vector<QrSegment> &segs, int version) {
} }
bool QrSegment::isNumeric(const char *text) { bool QrSegment::isNumeric(const char* text)
{
for (; *text != '\0'; text++) { for (; *text != '\0'; text++) {
char c = *text; char c = *text;
if (c < '0' || c > '9') if (c < '0' || c > '9')
@@ -203,7 +218,8 @@ bool QrSegment::isNumeric(const char *text) {
} }
bool QrSegment::isAlphanumeric(const char *text) { bool QrSegment::isAlphanumeric(const char* text)
{
for (; *text != '\0'; text++) { for (; *text != '\0'; text++) {
if (std::strchr(ALPHANUMERIC_CHARSET, *text) == nullptr) if (std::strchr(ALPHANUMERIC_CHARSET, *text) == nullptr)
return false; return false;
@@ -212,17 +228,20 @@ bool QrSegment::isAlphanumeric(const char *text) {
} }
const QrSegment::Mode &QrSegment::getMode() const { const QrSegment::Mode& QrSegment::getMode() const
{
return *mode; return *mode;
} }
int QrSegment::getNumChars() const { int QrSegment::getNumChars() const
{
return numChars; return numChars;
} }
const std::vector<bool> &QrSegment::getData() const { const std::vector<bool>& QrSegment::getData() const
{
return data; return data;
} }
@@ -233,7 +252,8 @@ const char *QrSegment::ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVW
/*---- Class QrCode ----*/ /*---- Class QrCode ----*/
int QrCode::getFormatBits(Ecc ecl) { int QrCode::getFormatBits(Ecc ecl)
{
switch (ecl) { switch (ecl) {
case Ecc::LOW: return 1; case Ecc::LOW: return 1;
case Ecc::MEDIUM: return 0; case Ecc::MEDIUM: return 0;
@@ -244,20 +264,23 @@ int QrCode::getFormatBits(Ecc ecl) {
} }
QrCode QrCode::encodeText(const char *text, Ecc ecl) { QrCode QrCode::encodeText(const char* text, Ecc ecl)
{
vector<QrSegment> segs = QrSegment::makeSegments(text); vector<QrSegment> segs = QrSegment::makeSegments(text);
return encodeSegments(segs, ecl); return encodeSegments(segs, ecl);
} }
QrCode QrCode::encodeBinary(const vector<uint8_t> &data, Ecc ecl) { QrCode QrCode::encodeBinary(const vector<uint8_t>& data, Ecc ecl)
{
vector<QrSegment> segs{ QrSegment::makeBytes(data) }; vector<QrSegment> segs{ QrSegment::makeBytes(data) };
return encodeSegments(segs, ecl); return encodeSegments(segs, ecl);
} }
QrCode QrCode::encodeSegments(const vector<QrSegment>& segs, Ecc ecl, QrCode QrCode::encodeSegments(const vector<QrSegment>& segs, Ecc ecl,
int minVersion, int maxVersion, int mask, bool boostEcl) { int minVersion, int maxVersion, int mask, bool boostEcl)
{
if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7)
throw std::invalid_argument("Invalid value"); throw std::invalid_argument("Invalid value");
@@ -320,7 +343,8 @@ QrCode QrCode::encodeSegments(const vector<QrSegment> &segs, Ecc ecl,
QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t>& dataCodewords, int msk) : QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t>& dataCodewords, int msk) :
// Initialize fields and check arguments // Initialize fields and check arguments
version(ver), version(ver),
errorCorrectionLevel(ecl) { errorCorrectionLevel(ecl)
{
if (ver < MIN_VERSION || ver > MAX_VERSION) if (ver < MIN_VERSION || ver > MAX_VERSION)
throw std::domain_error("Version value out of range"); throw std::domain_error("Version value out of range");
if (msk < -1 || msk > 7) if (msk < -1 || msk > 7)
@@ -359,32 +383,38 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int msk)
} }
int QrCode::getVersion() const { int QrCode::getVersion() const
{
return version; return version;
} }
int QrCode::getSize() const { int QrCode::getSize() const
{
return size; return size;
} }
QrCode::Ecc QrCode::getErrorCorrectionLevel() const { QrCode::Ecc QrCode::getErrorCorrectionLevel() const
{
return errorCorrectionLevel; return errorCorrectionLevel;
} }
int QrCode::getMask() const { int QrCode::getMask() const
{
return mask; return mask;
} }
bool QrCode::getModule(int x, int y) const { bool QrCode::getModule(int x, int y) const
{
return 0 <= x && x < size && 0 <= y && y < size && module(x, y); return 0 <= x && x < size && 0 <= y && y < size && module(x, y);
} }
void QrCode::drawFunctionPatterns() { void QrCode::drawFunctionPatterns()
{
// Draw horizontal and vertical timing patterns // Draw horizontal and vertical timing patterns
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
setFunctionModule(6, i, i % 2 == 0); setFunctionModule(6, i, i % 2 == 0);
@@ -413,7 +443,8 @@ void QrCode::drawFunctionPatterns() {
} }
void QrCode::drawFormatBits(int msk) { void QrCode::drawFormatBits(int msk)
{
// Calculate error correction code and pack bits // Calculate error correction code and pack bits
int data = getFormatBits(errorCorrectionLevel) << 3 | msk; // errCorrLvl is uint2, msk is uint3 int data = getFormatBits(errorCorrectionLevel) << 3 | msk; // errCorrLvl is uint2, msk is uint3
int rem = data; int rem = data;
@@ -440,7 +471,8 @@ void QrCode::drawFormatBits(int msk) {
} }
void QrCode::drawVersion() { void QrCode::drawVersion()
{
if (version < 7) if (version < 7)
return; return;
@@ -462,7 +494,8 @@ void QrCode::drawVersion() {
} }
void QrCode::drawFinderPattern(int x, int y) { void QrCode::drawFinderPattern(int x, int y)
{
for (int dy = -4; dy <= 4; dy++) { for (int dy = -4; dy <= 4; dy++) {
for (int dx = -4; dx <= 4; dx++) { for (int dx = -4; dx <= 4; dx++) {
int dist = std::max(std::abs(dx), std::abs(dy)); // Chebyshev/infinity norm int dist = std::max(std::abs(dx), std::abs(dy)); // Chebyshev/infinity norm
@@ -474,7 +507,8 @@ void QrCode::drawFinderPattern(int x, int y) {
} }
void QrCode::drawAlignmentPattern(int x, int y) { void QrCode::drawAlignmentPattern(int x, int y)
{
for (int dy = -2; dy <= 2; dy++) { for (int dy = -2; dy <= 2; dy++) {
for (int dx = -2; dx <= 2; dx++) for (int dx = -2; dx <= 2; dx++)
setFunctionModule(x + dx, y + dy, std::max(std::abs(dx), std::abs(dy)) != 1); setFunctionModule(x + dx, y + dy, std::max(std::abs(dx), std::abs(dy)) != 1);
@@ -482,7 +516,8 @@ void QrCode::drawAlignmentPattern(int x, int y) {
} }
void QrCode::setFunctionModule(int x, int y, bool isDark) { void QrCode::setFunctionModule(int x, int y, bool isDark)
{
size_t ux = static_cast<size_t>(x); size_t ux = static_cast<size_t>(x);
size_t uy = static_cast<size_t>(y); size_t uy = static_cast<size_t>(y);
modules.at(uy).at(ux) = isDark; modules.at(uy).at(ux) = isDark;
@@ -490,12 +525,14 @@ void QrCode::setFunctionModule(int x, int y, bool isDark) {
} }
bool QrCode::module(int x, int y) const { bool QrCode::module(int x, int y) const
{
return modules.at(static_cast<size_t>(y)).at(static_cast<size_t>(x)); return modules.at(static_cast<size_t>(y)).at(static_cast<size_t>(x));
} }
vector<uint8_t> QrCode::addEccAndInterleave(const vector<uint8_t> &data) const { vector<uint8_t> QrCode::addEccAndInterleave(const vector<uint8_t>& data) const
{
if (data.size() != static_cast<unsigned int>(getNumDataCodewords(version, errorCorrectionLevel))) if (data.size() != static_cast<unsigned int>(getNumDataCodewords(version, errorCorrectionLevel)))
throw std::invalid_argument("Invalid argument"); throw std::invalid_argument("Invalid argument");
@@ -533,7 +570,8 @@ vector<uint8_t> QrCode::addEccAndInterleave(const vector<uint8_t> &data) const {
} }
void QrCode::drawCodewords(const vector<uint8_t> &data) { void QrCode::drawCodewords(const vector<uint8_t>& data)
{
if (data.size() != static_cast<unsigned int>(getNumRawDataModules(version) / 8)) if (data.size() != static_cast<unsigned int>(getNumRawDataModules(version) / 8))
throw std::invalid_argument("Invalid argument"); throw std::invalid_argument("Invalid argument");
@@ -560,7 +598,8 @@ void QrCode::drawCodewords(const vector<uint8_t> &data) {
} }
void QrCode::applyMask(int msk) { void QrCode::applyMask(int msk)
{
if (msk < 0 || msk > 7) if (msk < 0 || msk > 7)
throw std::domain_error("Mask value out of range"); throw std::domain_error("Mask value out of range");
size_t sz = static_cast<size_t>(size); size_t sz = static_cast<size_t>(size);
@@ -584,7 +623,8 @@ void QrCode::applyMask(int msk) {
} }
long QrCode::getPenaltyScore() const { long QrCode::getPenaltyScore() const
{
long result = 0; long result = 0;
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
@@ -599,7 +639,8 @@ long QrCode::getPenaltyScore() const {
result += PENALTY_N1; result += PENALTY_N1;
else if (runX > 5) else if (runX > 5)
result++; result++;
} else { }
else {
finderPenaltyAddHistory(runX, runHistory); finderPenaltyAddHistory(runX, runHistory);
if (!runColor) if (!runColor)
result += finderPenaltyCountPatterns(runHistory) * PENALTY_N3; result += finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
@@ -621,7 +662,8 @@ long QrCode::getPenaltyScore() const {
result += PENALTY_N1; result += PENALTY_N1;
else if (runY > 5) else if (runY > 5)
result++; result++;
} else { }
else {
finderPenaltyAddHistory(runY, runHistory); finderPenaltyAddHistory(runY, runHistory);
if (!runColor) if (!runColor)
result += finderPenaltyCountPatterns(runHistory) * PENALTY_N3; result += finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
@@ -661,7 +703,8 @@ long QrCode::getPenaltyScore() const {
} }
vector<int> QrCode::getAlignmentPatternPositions() const { vector<int> QrCode::getAlignmentPatternPositions() const
{
if (version == 1) if (version == 1)
return vector<int>(); return vector<int>();
else { else {
@@ -677,7 +720,8 @@ vector<int> QrCode::getAlignmentPatternPositions() const {
} }
int QrCode::getNumRawDataModules(int ver) { int QrCode::getNumRawDataModules(int ver)
{
if (ver < MIN_VERSION || ver > MAX_VERSION) if (ver < MIN_VERSION || ver > MAX_VERSION)
throw std::domain_error("Version number out of range"); throw std::domain_error("Version number out of range");
int result = (16 * ver + 128) * ver + 64; int result = (16 * ver + 128) * ver + 64;
@@ -692,14 +736,16 @@ int QrCode::getNumRawDataModules(int ver) {
} }
int QrCode::getNumDataCodewords(int ver, Ecc ecl) { int QrCode::getNumDataCodewords(int ver, Ecc ecl)
{
return getNumRawDataModules(ver) / 8 return getNumRawDataModules(ver) / 8
- ECC_CODEWORDS_PER_BLOCK[static_cast<int>(ecl)][ver] - ECC_CODEWORDS_PER_BLOCK[static_cast<int>(ecl)][ver]
* NUM_ERROR_CORRECTION_BLOCKS[static_cast<int>(ecl)][ver]; * NUM_ERROR_CORRECTION_BLOCKS[static_cast<int>(ecl)][ver];
} }
vector<uint8_t> QrCode::reedSolomonComputeDivisor(int degree) { vector<uint8_t> QrCode::reedSolomonComputeDivisor(int degree)
{
if (degree < 1 || degree > 255) if (degree < 1 || degree > 255)
throw std::domain_error("Degree out of range"); throw std::domain_error("Degree out of range");
// Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1. // Polynomial coefficients are stored from highest to lowest power, excluding the leading term which is always 1.
@@ -724,7 +770,8 @@ vector<uint8_t> QrCode::reedSolomonComputeDivisor(int degree) {
} }
vector<uint8_t> QrCode::reedSolomonComputeRemainder(const vector<uint8_t> &data, const vector<uint8_t> &divisor) { vector<uint8_t> QrCode::reedSolomonComputeRemainder(const vector<uint8_t>& data, const vector<uint8_t>& divisor)
{
vector<uint8_t> result(divisor.size()); vector<uint8_t> result(divisor.size());
for (uint8_t b : data) { // Polynomial division for (uint8_t b : data) { // Polynomial division
uint8_t factor = b ^ result.at(0); uint8_t factor = b ^ result.at(0);
@@ -737,7 +784,8 @@ vector<uint8_t> QrCode::reedSolomonComputeRemainder(const vector<uint8_t> &data,
} }
uint8_t QrCode::reedSolomonMultiply(uint8_t x, uint8_t y) { uint8_t QrCode::reedSolomonMultiply(uint8_t x, uint8_t y)
{
// Russian peasant multiplication // Russian peasant multiplication
int z = 0; int z = 0;
for (int i = 7; i >= 0; i--) { for (int i = 7; i >= 0; i--) {
@@ -749,7 +797,8 @@ uint8_t QrCode::reedSolomonMultiply(uint8_t x, uint8_t y) {
} }
int QrCode::finderPenaltyCountPatterns(const std::array<int,7> &runHistory) const { int QrCode::finderPenaltyCountPatterns(const std::array<int, 7>& runHistory) const
{
int n = runHistory.at(1); int n = runHistory.at(1);
assert(n <= size * 3); assert(n <= size * 3);
bool core = n > 0 && runHistory.at(2) == n && runHistory.at(3) == n * 3 && runHistory.at(4) == n && runHistory.at(5) == n; bool core = n > 0 && runHistory.at(2) == n && runHistory.at(3) == n * 3 && runHistory.at(4) == n && runHistory.at(5) == n;
@@ -758,7 +807,8 @@ int QrCode::finderPenaltyCountPatterns(const std::array<int,7> &runHistory) cons
} }
int QrCode::finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLength, std::array<int,7> &runHistory) const { int QrCode::finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLength, std::array<int, 7>& runHistory) const
{
if (currentRunColor) { // Terminate dark run if (currentRunColor) { // Terminate dark run
finderPenaltyAddHistory(currentRunLength, runHistory); finderPenaltyAddHistory(currentRunLength, runHistory);
currentRunLength = 0; currentRunLength = 0;
@@ -769,7 +819,8 @@ int QrCode::finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunL
} }
void QrCode::finderPenaltyAddHistory(int currentRunLength, std::array<int,7> &runHistory) const { void QrCode::finderPenaltyAddHistory(int currentRunLength, std::array<int, 7>& runHistory) const
{
if (runHistory.at(0) == 0) if (runHistory.at(0) == 0)
currentRunLength += size; // Add light border to initial run currentRunLength += size; // Add light border to initial run
std::copy_backward(runHistory.cbegin(), runHistory.cend() - 1, runHistory.end()); std::copy_backward(runHistory.cbegin(), runHistory.cend() - 1, runHistory.end());
@@ -777,7 +828,8 @@ void QrCode::finderPenaltyAddHistory(int currentRunLength, std::array<int,7> &ru
} }
bool QrCode::getBit(long x, int i) { bool QrCode::getBit(long x, int i)
{
return ((x >> i) & 1) != 0; return ((x >> i) & 1) != 0;
} }
@@ -820,7 +872,8 @@ BitBuffer::BitBuffer()
: std::vector<bool>() {} : std::vector<bool>() {}
void BitBuffer::appendBits(std::uint32_t val, int len) { void BitBuffer::appendBits(std::uint32_t val, int len)
{
if (len < 0 || len > 31 || val >> len != 0) if (len < 0 || len > 31 || val >> len != 0)
throw std::domain_error("Value out of range"); throw std::domain_error("Value out of range");
for (int i = len - 1; i >= 0; i--) // Append bit by bit for (int i = len - 1; i >= 0; i--) // Append bit by bit
+2 -1
View File
@@ -30,7 +30,8 @@
#include <vector> #include <vector>
namespace qrcodegen { namespace qrcodegen
{
/* /*
* A segment of character/binary/control data in a QR Code symbol. * A segment of character/binary/control data in a QR Code symbol.
+2 -1
View File
@@ -2,7 +2,8 @@
#include <sstream> #include <sstream>
#include <climits> #include <climits>
std::string toSvgString(const qrcodegen::QrCode &qr, int border) { std::string toSvgString(const qrcodegen::QrCode& qr, int border)
{
if (border < 0) if (border < 0)
throw std::domain_error("Border must be non-negative"); throw std::domain_error("Border must be non-negative");
if (border > INT_MAX / 2 || border * 2 > INT_MAX - qr.getSize()) if (border > INT_MAX / 2 || border * 2 > INT_MAX - qr.getSize())
+1410 -697
View File
File diff suppressed because it is too large. Load diff
+114 -54
View File
@@ -2976,7 +2976,8 @@ inline void replace_substring(StringType& s, const StringType& f,
pos != StringType::npos; // make sure f was found pos != StringType::npos; // make sure f was found
s.replace(pos, f.size(), t), // replace with t, and s.replace(pos, f.size(), t), // replace with t, and
pos = s.find(f, pos + t.size())) // find next occurrence of f pos = s.find(f, pos + t.size())) // find next occurrence of f
{} {
}
} }
/*! /*!
@@ -3473,7 +3474,8 @@ struct is_basic_json_context :
std::integral_constant < bool, std::integral_constant < bool,
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
|| std::is_same<BasicJsonContext, std::nullptr_t>::value > || std::is_same<BasicJsonContext, std::nullptr_t>::value >
{}; {
};
////////////////////// //////////////////////
// json_ref helpers // // json_ref helpers //
@@ -3602,7 +3604,8 @@ using actual_object_comparator_t = typename actual_object_comparator<BasicJsonTy
// Primary template of char_traits calls std char_traits // Primary template of char_traits calls std char_traits
template<typename T> template<typename T>
struct char_traits : std::char_traits<T> struct char_traits : std::char_traits<T>
{}; {
};
// Explicitly define char traits for unsigned char since it is not standard // Explicitly define char traits for unsigned char since it is not standard
template<> template<>
@@ -3661,7 +3664,8 @@ template<class...> struct conjunction : std::true_type { };
template<class B> struct conjunction<B> : B {}; template<class B> struct conjunction<B> : B {};
template<class B, class... Bn> template<class B, class... Bn>
struct conjunction<B, Bn...> struct conjunction<B, Bn...>
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {}; : std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {
};
// https://en.cppreference.com/w/cpp/types/negation // https://en.cppreference.com/w/cpp/types/negation
template<class B> struct negation : std::integral_constant < bool, !B::value > {}; template<class B> struct negation : std::integral_constant < bool, !B::value > {};
@@ -3674,19 +3678,23 @@ struct is_default_constructible : std::is_default_constructible<T> {};
template <typename T1, typename T2> template <typename T1, typename T2>
struct is_default_constructible<std::pair<T1, T2>> struct is_default_constructible<std::pair<T1, T2>>
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {
};
template <typename T1, typename T2> template <typename T1, typename T2>
struct is_default_constructible<const std::pair<T1, T2>> struct is_default_constructible<const std::pair<T1, T2>>
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {}; : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {
};
template <typename... Ts> template <typename... Ts>
struct is_default_constructible<std::tuple<Ts...>> struct is_default_constructible<std::tuple<Ts...>>
: conjunction<is_default_constructible<Ts>...> {}; : conjunction<is_default_constructible<Ts>...> {
};
template <typename... Ts> template <typename... Ts>
struct is_default_constructible<const std::tuple<Ts...>> struct is_default_constructible<const std::tuple<Ts...>>
: conjunction<is_default_constructible<Ts>...> {}; : conjunction<is_default_constructible<Ts>...> {
};
template <typename T, typename... Args> template <typename T, typename... Args>
struct is_constructible : std::is_constructible<T, Args...> {}; struct is_constructible : std::is_constructible<T, Args...> {};
@@ -3778,7 +3786,8 @@ struct is_compatible_object_type_impl <
template<typename BasicJsonType, typename CompatibleObjectType> template<typename BasicJsonType, typename CompatibleObjectType>
struct is_compatible_object_type struct is_compatible_object_type
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {}; : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {
};
template<typename BasicJsonType, typename ConstructibleObjectType, template<typename BasicJsonType, typename ConstructibleObjectType,
typename = void> typename = void>
@@ -3811,7 +3820,8 @@ struct is_constructible_object_type_impl <
template<typename BasicJsonType, typename ConstructibleObjectType> template<typename BasicJsonType, typename ConstructibleObjectType>
struct is_constructible_object_type struct is_constructible_object_type
: is_constructible_object_type_impl<BasicJsonType, : is_constructible_object_type_impl<BasicJsonType,
ConstructibleObjectType> {}; ConstructibleObjectType> {
};
template<typename BasicJsonType, typename CompatibleStringType> template<typename BasicJsonType, typename CompatibleStringType>
struct is_compatible_string_type struct is_compatible_string_type
@@ -3857,7 +3867,8 @@ struct is_compatible_array_type_impl <
template<typename BasicJsonType, typename CompatibleArrayType> template<typename BasicJsonType, typename CompatibleArrayType>
struct is_compatible_array_type struct is_compatible_array_type
: is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {}; : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {
};
template<typename BasicJsonType, typename ConstructibleArrayType, typename = void> template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
struct is_constructible_array_type_impl : std::false_type {}; struct is_constructible_array_type_impl : std::false_type {};
@@ -3901,7 +3912,8 @@ is_detected<range_value_t, ConstructibleArrayType>::value&&
template<typename BasicJsonType, typename ConstructibleArrayType> template<typename BasicJsonType, typename ConstructibleArrayType>
struct is_constructible_array_type struct is_constructible_array_type
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {}; : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {
};
template<typename RealIntegerType, typename CompatibleNumberIntegerType, template<typename RealIntegerType, typename CompatibleNumberIntegerType,
typename = void> typename = void>
@@ -3928,7 +3940,8 @@ struct is_compatible_integer_type_impl <
template<typename RealIntegerType, typename CompatibleNumberIntegerType> template<typename RealIntegerType, typename CompatibleNumberIntegerType>
struct is_compatible_integer_type struct is_compatible_integer_type
: is_compatible_integer_type_impl<RealIntegerType, : is_compatible_integer_type_impl<RealIntegerType,
CompatibleNumberIntegerType> {}; CompatibleNumberIntegerType> {
};
template<typename BasicJsonType, typename CompatibleType, typename = void> template<typename BasicJsonType, typename CompatibleType, typename = void>
struct is_compatible_type_impl : std::false_type {}; struct is_compatible_type_impl : std::false_type {};
@@ -3944,7 +3957,8 @@ struct is_compatible_type_impl <
template<typename BasicJsonType, typename CompatibleType> template<typename BasicJsonType, typename CompatibleType>
struct is_compatible_type struct is_compatible_type
: is_compatible_type_impl<BasicJsonType, CompatibleType> {}; : is_compatible_type_impl<BasicJsonType, CompatibleType> {
};
template<typename T1, typename T2> template<typename T1, typename T2>
struct is_constructible_tuple : std::false_type {}; struct is_constructible_tuple : std::false_type {};
@@ -3960,7 +3974,8 @@ struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : st
template<typename BasicJsonType> template<typename BasicJsonType>
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
{}; {
};
// checks if a given type T is a template specialization of Primary // checks if a given type T is a template specialization of Primary
template<template <typename...> class Primary, typename T> template<template <typename...> class Primary, typename T>
@@ -4263,7 +4278,8 @@ inline std::size_t concat_length(const StringType& str, const Args& ... rest)
template<typename OutStringType> template<typename OutStringType>
inline void concat_into(OutStringType& /*out*/) inline void concat_into(OutStringType& /*out*/)
{} {
}
template<typename StringType, typename Arg> template<typename StringType, typename Arg>
using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg&& >())); using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg&& >()));
@@ -4508,7 +4524,9 @@ class parse_error : public exception
private: private:
parse_error(int id_, std::size_t byte_, const char* what_arg) parse_error(int id_, std::size_t byte_, const char* what_arg)
: exception(id_, what_arg), byte(byte_) {} : exception(id_, what_arg), byte(byte_)
{
}
static std::string position_string(const position_t& pos) static std::string position_string(const position_t& pos)
{ {
@@ -4532,7 +4550,9 @@ class invalid_iterator : public exception
private: private:
JSON_HEDLEY_NON_NULL(3) JSON_HEDLEY_NON_NULL(3)
invalid_iterator(int id_, const char* what_arg) invalid_iterator(int id_, const char* what_arg)
: exception(id_, what_arg) {} : exception(id_, what_arg)
{
}
}; };
/// @brief exception indicating executing a member function with a wrong type /// @brief exception indicating executing a member function with a wrong type
@@ -5211,7 +5231,8 @@ template<typename IteratorType> class iteration_proxy_value
&& std::is_nothrow_default_constructible<string_type>::value) && std::is_nothrow_default_constructible<string_type>::value)
: anchor(std::move(it)) : anchor(std::move(it))
, array_index(array_index_) , array_index(array_index_)
{} {
}
iteration_proxy_value(iteration_proxy_value const&) = default; iteration_proxy_value(iteration_proxy_value const&) = default;
iteration_proxy_value& operator=(iteration_proxy_value const&) = default; iteration_proxy_value& operator=(iteration_proxy_value const&) = default;
@@ -5314,7 +5335,9 @@ template<typename IteratorType> class iteration_proxy
/// construct iteration proxy from a container /// construct iteration proxy from a container
explicit iteration_proxy(typename IteratorType::reference cont) noexcept explicit iteration_proxy(typename IteratorType::reference cont) noexcept
: container(&cont) {} : container(&cont)
{
}
iteration_proxy(iteration_proxy const&) = default; iteration_proxy(iteration_proxy const&) = default;
iteration_proxy& operator=(iteration_proxy const&) = default; iteration_proxy& operator=(iteration_proxy const&) = default;
@@ -5369,7 +5392,8 @@ namespace std
#endif #endif
template<typename IteratorType> template<typename IteratorType>
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp) class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
: public std::integral_constant<std::size_t, 2> {}; : public std::integral_constant<std::size_t, 2> {
};
template<std::size_t N, typename IteratorType> template<std::size_t N, typename IteratorType>
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp) class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)
@@ -5897,31 +5921,36 @@ class byte_container_with_subtype : public BinaryType
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype() noexcept(noexcept(container_type())) byte_container_with_subtype() noexcept(noexcept(container_type()))
: container_type() : container_type()
{} {
}
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
: container_type(b) : container_type(b)
{} {
}
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b)) : container_type(std::move(b))
{} {
}
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
: container_type(b) : container_type(b)
, m_subtype(subtype_) , m_subtype(subtype_)
, m_has_subtype(true) , m_has_subtype(true)
{} {
}
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b)) : container_type(std::move(b))
, m_subtype(subtype_) , m_subtype(subtype_)
, m_has_subtype(true) , m_has_subtype(true)
{} {
}
bool operator==(const byte_container_with_subtype& rhs) const bool operator==(const byte_container_with_subtype& rhs) const
{ {
@@ -6240,7 +6269,8 @@ class input_stream_adapter
explicit input_stream_adapter(std::istream& i) explicit input_stream_adapter(std::istream& i)
: is(&i), sb(i.rdbuf()) : is(&i), sb(i.rdbuf())
{} {
}
// delete because of pointer members // delete because of pointer members
input_stream_adapter(const input_stream_adapter&) = delete; input_stream_adapter(const input_stream_adapter&) = delete;
@@ -6285,7 +6315,8 @@ class iterator_input_adapter
iterator_input_adapter(IteratorType first, IteratorType last) iterator_input_adapter(IteratorType first, IteratorType last)
: current(std::move(first)), end(std::move(last)) : current(std::move(first)), end(std::move(last))
{} {
}
typename char_traits<char_type>::int_type get_character() typename char_traits<char_type>::int_type get_character()
{ {
@@ -6443,7 +6474,9 @@ class wide_string_input_adapter
using char_type = char; using char_type = char;
wide_string_input_adapter(BaseInputAdapter base) wide_string_input_adapter(BaseInputAdapter base)
: base_adapter(base) {} : base_adapter(base)
{
}
typename std::char_traits<char>::int_type get_character() noexcept typename std::char_traits<char>::int_type get_character() noexcept
{ {
@@ -6612,14 +6645,18 @@ class span_input_adapter
sizeof(typename std::remove_pointer<CharT>::type) == 1, sizeof(typename std::remove_pointer<CharT>::type) == 1,
int >::type = 0 > int >::type = 0 >
span_input_adapter(CharT b, std::size_t l) span_input_adapter(CharT b, std::size_t l)
: ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {} : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l)
{
}
template<class IteratorType, template<class IteratorType,
typename std::enable_if< typename std::enable_if<
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value, std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
int>::type = 0> int>::type = 0>
span_input_adapter(IteratorType first, IteratorType last) span_input_adapter(IteratorType first, IteratorType last)
: ia(input_adapter(first, last)) {} : ia(input_adapter(first, last))
{
}
contiguous_bytes_input_adapter&& get() contiguous_bytes_input_adapter&& get()
{ {
@@ -6813,7 +6850,8 @@ class json_sax_dom_parser
*/ */
explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true) explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
: root(r), allow_exceptions(allow_exceptions_) : root(r), allow_exceptions(allow_exceptions_)
{} {
}
// make class move-only // make class move-only
json_sax_dom_parser(const json_sax_dom_parser&) = delete; json_sax_dom_parser(const json_sax_dom_parser&) = delete;
@@ -7497,7 +7535,8 @@ class lexer : public lexer_base<BasicJsonType>
: ia(std::move(adapter)) : ia(std::move(adapter))
, ignore_comments(ignore_comments_) , ignore_comments(ignore_comments_)
, decimal_point_char(static_cast<char_int_type>(get_decimal_point())) , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
{} {
}
// delete because of pointer members // delete because of pointer members
lexer(const lexer&) = delete; lexer(const lexer&) = delete;
@@ -8875,8 +8914,7 @@ scan_number_done:
do do
{ {
get(); get();
} } while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
} }
token_type scan() token_type scan()
@@ -11908,8 +11946,7 @@ class binary_reader
do do
{ {
get(); get();
} } while (current == 'N');
while (current == 'N');
return current; return current;
} }
@@ -13018,7 +13055,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
*/ */
iter_impl(const iter_impl<const BasicJsonType>& other) noexcept iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
: m_object(other.m_object), m_it(other.m_it) : m_object(other.m_object), m_it(other.m_it)
{} {
}
/*! /*!
@brief converting assignment @brief converting assignment
@@ -13043,7 +13081,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
*/ */
iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
: m_object(other.m_object), m_it(other.m_it) : m_object(other.m_object), m_it(other.m_it)
{} {
}
/*! /*!
@brief converting assignment @brief converting assignment
@@ -13677,7 +13716,9 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
/// create reverse iterator from iterator /// create reverse iterator from iterator
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
: base_iterator(it) {} : base_iterator(it)
{
}
/// create reverse iterator from base class /// create reverse iterator from base class
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
@@ -13867,7 +13908,8 @@ class json_pointer
/// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/ /// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/
explicit json_pointer(const string_t& s = "") explicit json_pointer(const string_t& s = "")
: reference_tokens(split(s)) : reference_tokens(split(s))
{} {
}
/// @brief return a string representation of the JSON pointer /// @brief return a string representation of the JSON pointer
/// @sa https://json.nlohmann.me/api/json_pointer/to_string/ /// @sa https://json.nlohmann.me/api/json_pointer/to_string/
@@ -14824,22 +14866,26 @@ class json_ref
json_ref(value_type&& value) json_ref(value_type&& value)
: owned_value(std::move(value)) : owned_value(std::move(value))
{} {
}
json_ref(const value_type& value) json_ref(const value_type& value)
: value_ref(&value) : value_ref(&value)
{} {
}
json_ref(std::initializer_list<json_ref> init) json_ref(std::initializer_list<json_ref> init)
: owned_value(init) : owned_value(init)
{} {
}
template < template <
class... Args, class... Args,
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 > enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
json_ref(Args && ... args) json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...) : owned_value(std::forward<Args>(args)...)
{} {
}
// class should be movable only // class should be movable only
json_ref(json_ref&&) noexcept = default; json_ref(json_ref&&) noexcept = default;
@@ -14966,7 +15012,8 @@ class output_vector_adapter : public output_adapter_protocol<CharType>
public: public:
explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
: v(vec) : v(vec)
{} {
}
void write_character(CharType c) override void write_character(CharType c) override
{ {
@@ -14991,7 +15038,8 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
public: public:
explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
: stream(s) : stream(s)
{} {
}
void write_character(CharType c) override void write_character(CharType c) override
{ {
@@ -15016,7 +15064,8 @@ class output_string_adapter : public output_adapter_protocol<CharType>
public: public:
explicit output_string_adapter(StringType& s) noexcept explicit output_string_adapter(StringType& s) noexcept
: str(s) : str(s)
{} {
}
void write_character(CharType c) override void write_character(CharType c) override
{ {
@@ -15039,15 +15088,21 @@ class output_adapter
public: public:
template<typename AllocatorType = std::allocator<CharType>> template<typename AllocatorType = std::allocator<CharType>>
output_adapter(std::vector<CharType, AllocatorType>& vec) output_adapter(std::vector<CharType, AllocatorType>& vec)
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {} : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec))
{
}
#ifndef JSON_NO_IO #ifndef JSON_NO_IO
output_adapter(std::basic_ostream<CharType>& s) output_adapter(std::basic_ostream<CharType>& s)
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {} : oa(std::make_shared<output_stream_adapter<CharType>>(s))
{
}
#endif // JSON_NO_IO #endif // JSON_NO_IO
output_adapter(StringType& s) output_adapter(StringType& s)
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {} : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s))
{
}
operator output_adapter_t<CharType>() operator output_adapter_t<CharType>()
{ {
@@ -18082,7 +18137,8 @@ class serializer
, indent_char(ichar) , indent_char(ichar)
, indent_string(512, indent_char) , indent_string(512, indent_char)
, error_handler(error_handler_) , error_handler(error_handler_)
{} {
}
// delete because of pointer members // delete because of pointer members
serializer(const serializer&) = delete; serializer(const serializer&) = delete;
@@ -19052,9 +19108,13 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{ alloc } {} explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{ alloc } {}
template <class It> template <class It>
ordered_map(It first, It last, const Allocator& alloc = Allocator()) ordered_map(It first, It last, const Allocator& alloc = Allocator())
: Container{first, last, alloc} {} : Container{ first, last, alloc }
{
}
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator()) ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
: Container{init, alloc} {} : Container{ init, alloc }
{
}
std::pair<iterator, bool> emplace(const key_type& key, T&& t) std::pair<iterator, bool> emplace(const key_type& key, T&& t)
{ {
+4 -2
View File
@@ -76,7 +76,8 @@ namespace api
if (get_ssh_server() == DROPBEAR_SSH) if (get_ssh_server() == DROPBEAR_SSH)
{ {
systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" /etc/default/dropbear"; systemrequest << "sed -i \"s/DROPBEAR_PORT=" << old_ssh_port << "/DROPBEAR_PORT=" << new_ssh_port << "/g\" /etc/default/dropbear";
} else if (get_ssh_server() == OPENSSH_SSH) }
else if (get_ssh_server() == OPENSSH_SSH)
{ {
systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config"; systemrequest << "sed -i \"/Port " << old_ssh_port << "/s//Port " << new_ssh_port << "/\" /etc/ssh/sshd_config";
} }
@@ -85,7 +86,8 @@ namespace api
if (get_ssh_server() == OPENSSH_SSH) if (get_ssh_server() == OPENSSH_SSH)
{ {
system("rc restart ssh"); system("rc restart ssh");
} else if (get_ssh_server() == DROPBEAR_SSH) }
else if (get_ssh_server() == DROPBEAR_SSH)
{ {
system("rc restart dropbear"); system("rc restart dropbear");
} }
+2 -1
View File
@@ -81,7 +81,8 @@ namespace api
system("rc del ssh"); system("rc del ssh");
system("rc start dropbear"); system("rc start dropbear");
system("rc add dropbear"); system("rc add dropbear");
} else if (new_server == OPENSSH_SSH) { }
else if (new_server == OPENSSH_SSH) {
system("rc stop dropbear"); system("rc stop dropbear");
system("rc del dropbear"); system("rc del dropbear");
system("rc start ssh"); system("rc start ssh");
+4 -2
View File
@@ -66,7 +66,8 @@ namespace api
{ {
system("rc stop dropbear"); system("rc stop dropbear");
system("rc del dropbear"); system("rc del dropbear");
} else if (get_ssh_server() == OPENSSH_SSH) { }
else if (get_ssh_server() == OPENSSH_SSH) {
system("rc stop ssh"); system("rc stop ssh");
system("rc del ssh"); system("rc del ssh");
} }
@@ -78,7 +79,8 @@ namespace api
{ {
system("rc start dropbear"); system("rc start dropbear");
system("rc add dropbear"); system("rc add dropbear");
} else if (get_ssh_server() == OPENSSH_SSH) { }
else if (get_ssh_server() == OPENSSH_SSH) {
system("rc start ssh"); system("rc start ssh");
system("rc add ssh"); system("rc add ssh");
} }