1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-21 17:47:13 +02:00

Major plugin refactor and cleanup.

Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
This commit is contained in:
Sandu Liviu Catalin
2021-01-30 08:51:39 +02:00
parent e0e34b4030
commit 4a6bfc086c
6219 changed files with 1209835 additions and 454916 deletions

67
vendor/POCO/Redis/src/Array.cpp vendored Normal file
View File

@ -0,0 +1,67 @@
//
// Array.h
//
// Library: Redis
// Package: Redis
// Module: Array
//
// Implementation of the Array class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Array.h"
namespace Poco {
namespace Redis {
Array::Array()
{
}
Array::Array(const Array& copy):
_elements(copy._elements)
{
}
Array::~Array()
{
}
Array& Array::addRedisType(RedisType::Ptr value)
{
checkNull();
_elements.value().push_back(value);
return *this;
}
int Array::getType(size_t pos) const
{
if (_elements.isNull()) throw NullValueException();
if (pos >= _elements.value().size()) throw InvalidArgumentException();
RedisType::Ptr element = _elements.value().at(pos);
return element->type();
}
std::string Array::toString() const
{
return RedisTypeTraits<Array>::toString(*this);
}
} } // namespace Poco::Redis

61
vendor/POCO/Redis/src/AsyncReader.cpp vendored Normal file
View File

@ -0,0 +1,61 @@
//
// AsyncReader.cpp
//
// Library: Redis
// Package: Redis
// Module: AsyncReader
//
// Implementation of the AsyncReader class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/AsyncReader.h"
namespace Poco {
namespace Redis {
AsyncReader::AsyncReader(Client& client):
_client(client),
_activity(this, &AsyncReader::runActivity)
{
}
AsyncReader::~AsyncReader()
{
stop();
}
void AsyncReader::runActivity()
{
while (!_activity.isStopped())
{
try
{
RedisType::Ptr reply = _client.readReply();
RedisEventArgs args(reply);
redisResponse.notify(this, args);
if ( args.isStopped() ) stop();
}
catch (Exception& e)
{
RedisEventArgs args(&e);
redisException.notify(this, args);
stop();
}
if (!_activity.isStopped()) Thread::trySleep(100);
}
}
} } // namespace Poco::Redis

213
vendor/POCO/Redis/src/Client.cpp vendored Normal file
View File

@ -0,0 +1,213 @@
//
// Client.cpp
//
// Library: Redis
// Package: Redis
// Module: Client
//
// Implementation of the Client class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Client.h"
#include "Poco/Redis/Exception.h"
namespace Poco {
namespace Redis {
Client::Client():
_address(),
_socket(),
_input(0),
_output(0)
{
}
Client::Client(const std::string& hostAndPort):
_address(hostAndPort),
_socket(),
_input(0),
_output(0)
{
connect();
}
Client::Client(const std::string& host, int port):
_address(host, port),
_socket(),
_input(0),
_output(0)
{
connect();
}
Client::Client(const Net::SocketAddress& addrs):
_address(addrs),
_socket(),
_input(0),
_output(0)
{
connect();
}
Client::~Client()
{
delete _input;
delete _output;
}
void Client::connect()
{
poco_assert(! _input);
poco_assert(! _output);
_socket = Net::StreamSocket(_address);
_input = new RedisInputStream(_socket);
_output = new RedisOutputStream(_socket);
}
void Client::connect(const std::string& hostAndPort)
{
_address = Net::SocketAddress(hostAndPort);
connect();
}
void Client::connect(const std::string& host, int port)
{
_address = Net::SocketAddress(host, port);
connect();
}
void Client::connect(const Net::SocketAddress& addrs)
{
_address = addrs;
connect();
}
void Client::connect(const Timespan& timeout)
{
poco_assert(! _input);
poco_assert(! _output);
_socket = Net::StreamSocket();
_socket.connect(_address, timeout);
_input = new RedisInputStream(_socket);
_output = new RedisOutputStream(_socket);
}
void Client::connect(const std::string& hostAndPort, const Timespan& timeout)
{
_address = Net::SocketAddress(hostAndPort);
connect(timeout);
}
void Client::connect(const std::string& host, int port, const Timespan& timeout)
{
_address = Net::SocketAddress(host, port);
connect(timeout);
}
void Client::connect(const Net::SocketAddress& addrs, const Timespan& timeout)
{
_address = addrs;
connect(timeout);
}
void Client::disconnect()
{
delete _input;
_input = 0;
delete _output;
_output = 0;
_socket.close();
}
bool Client::isConnected() const
{
return _input != 0;
}
void Client::writeCommand(const Array& command, bool doFlush)
{
poco_assert(_output);
std::string commandStr = command.toString();
_output->write(commandStr.c_str(), commandStr.length());
if (doFlush) _output->flush();
}
RedisType::Ptr Client::readReply()
{
poco_assert(_input);
int c = _input->get();
if (c == -1)
{
disconnect();
throw RedisException("Lost connection to Redis server");
}
RedisType::Ptr result = RedisType::createRedisType(c);
if (result.isNull())
{
throw RedisException("Invalid Redis type returned");
}
result->read(*_input);
return result;
}
RedisType::Ptr Client::sendCommand(const Array& command)
{
writeCommand(command, true);
return readReply();
}
Array Client::sendCommands(const std::vector<Array>& commands)
{
Array results;
for (std::vector<Array>::const_iterator it = commands.begin(); it != commands.end(); ++it)
{
writeCommand(*it, false);
}
_output->flush();
for (int i = 0; i < commands.size(); ++i)
{
results.addRedisType(readReply());
}
return results;
}
} } // namespace Poco::Redis

738
vendor/POCO/Redis/src/Command.cpp vendored Normal file
View File

@ -0,0 +1,738 @@
//
// Command.cpp
//
// Library: Redis
// Package: Redis
// Module: Command
//
// Implementation of the Command class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Command.h"
#include "Poco/NumberFormatter.h"
namespace Poco {
namespace Redis {
Command::Command(const std::string& command): Array()
{
add(command);
}
Command::Command(const Command& copy): Array(copy)
{
}
Command::~Command()
{
}
Command Command::append(const std::string& key, const std::string& value)
{
Command cmd("APPEND");
cmd << key << value;
return cmd;
}
Command Command::blpop(const StringVec& lists, Int64 timeout)
{
Command cmd("BLPOP");
cmd << lists << NumberFormatter::format(timeout);
return cmd;
}
Command Command::brpop(const StringVec& lists, Int64 timeout)
{
Command cmd("BRPOP");
cmd << lists << NumberFormatter::format(timeout);
return cmd;
}
Command Command::brpoplpush(const std::string& sourceList, const std::string& destinationList, Int64 timeout)
{
Command cmd("BRPOPLPUSH");
cmd << sourceList << destinationList << NumberFormatter::format(timeout);
return cmd;
}
Command Command::decr(const std::string& key, Int64 by)
{
Command cmd(by == 0 ? "DECR" : "DECRBY");
cmd << key;
if ( by > 0 ) cmd << NumberFormatter::format(by);
return cmd;
}
Command Command::del(const std::string& key)
{
Command cmd("DEL");
cmd << key;
return cmd;
}
Command Command::del(const StringVec& keys)
{
Command cmd("DEL");
cmd << keys;
return cmd;
}
Command Command::get(const std::string& key)
{
Command cmd("GET");
cmd << key;
return cmd;
}
Command Command::exists(const std::string& key)
{
Command cmd("EXISTS");
cmd << key;
return cmd;
}
Command Command::hdel(const std::string& hash, const std::string& field)
{
Command cmd("HDEL");
cmd << hash << field;
return cmd;
}
Command Command::hdel(const std::string& hash, const StringVec& fields)
{
Command cmd("HDEL");
cmd << hash << fields;
return cmd;
}
Command Command::hexists(const std::string& hash, const std::string& field)
{
Command cmd("HEXISTS");
cmd << hash << field;
return cmd;
}
Command Command::hget(const std::string& hash, const std::string& field)
{
Command cmd("HGET");
cmd << hash << field;
return cmd;
}
Command Command::hgetall(const std::string& hash)
{
Command cmd("HGETALL");
cmd << hash;
return cmd;
}
Command Command::hincrby(const std::string& hash, const std::string& field, Int64 by)
{
Command cmd("HINCRBY");
cmd << hash << field << NumberFormatter::format(by);
return cmd;
}
Command Command::hkeys(const std::string& hash)
{
Command cmd("HKEYS");
cmd << hash;
return cmd;
}
Command Command::hlen(const std::string& hash)
{
Command cmd("HLEN");
cmd << hash;
return cmd;
}
Command Command::hmget(const std::string& hash, const StringVec& fields)
{
Command cmd("HMGET");
cmd << hash << fields;
return cmd;
}
Command Command::hmset(const std::string& hash, std::map<std::string, std::string>& fields)
{
Command cmd("HMSET");
cmd << hash;
for(std::map<std::string, std::string>::const_iterator it = fields.begin(); it != fields.end(); ++it)
{
cmd << it->first << it->second;
}
return cmd;
}
Command Command::hset(const std::string& hash, const std::string& field, const std::string& value, bool create)
{
Command cmd(create ? "HSET" : "HSETNX");
cmd << hash << field << value;
return cmd;
}
Command Command::hset(const std::string& hash, const std::string& field, Int64 value, bool create)
{
return hset(hash, field, NumberFormatter::format(value), create);
}
Command Command::hstrlen(const std::string& hash, const std::string& field)
{
Command cmd("HSTRLEN");
cmd << hash << field;
return cmd;
}
Command Command::hvals(const std::string& hash)
{
Command cmd("HVALS");
cmd << hash;
return cmd;
}
Command Command::incr(const std::string& key, Int64 by)
{
Command cmd(by == 0 ? "INCR" : "INCRBY");
cmd << key;
if ( by > 0 ) cmd << NumberFormatter::format(by);
return cmd;
}
Command Command::lindex(const std::string& list, Int64 index)
{
Command cmd("LINDEX");
cmd << list << NumberFormatter::format(index);
return cmd;
}
Command Command::linsert(const std::string& list, bool before, const std::string& reference, const std::string& value)
{
Command cmd("LINSERT");
cmd << list << (before ? "BEFORE" : "AFTER") << reference << value;
return cmd;
}
Command Command::llen(const std::string& list)
{
Command cmd("LLEN");
cmd << list;
return cmd;
}
Command Command::lpop(const std::string& list)
{
Command cmd("LPOP");
cmd << list;
return cmd;
}
Command Command::lpush(const std::string& list, const std::string& value, bool create)
{
Command cmd(create ? "LPUSH" : "LPUSHX");
cmd << list << value;
return cmd;
}
Command Command::lpush(const std::string& list, const StringVec& values, bool create)
{
Command cmd(create ? "LPUSH" : "LPUSHX");
cmd << list << values;
return cmd;
}
Command Command::lrange(const std::string& list, Int64 start, Int64 stop)
{
Command cmd("LRANGE");
cmd << list << NumberFormatter::format(start) << NumberFormatter::format(stop);
return cmd;
}
Command Command::lrem(const std::string& list, Int64 count, const std::string& value)
{
Command cmd("LREM");
cmd << list << NumberFormatter::format(count) << value;
return cmd;
}
Command Command::lset(const std::string& list, Int64 index, const std::string& value)
{
Command cmd("LSET");
cmd << list << NumberFormatter::format(index) << value;
return cmd;
}
Command Command::ltrim(const std::string& list, Int64 start, Int64 stop)
{
Command cmd("LTRIM");
cmd << list << NumberFormatter::format(start) << NumberFormatter::format(stop);
return cmd;
}
Command Command::mget(const StringVec& keys)
{
Command cmd("MGET");
cmd << keys;
return cmd;
}
Command Command::mset(const std::map<std::string, std::string>& keyvalues, bool create)
{
Command cmd(create ? "MSET" : "MSETNX");
for(std::map<std::string, std::string>::const_iterator it = keyvalues.begin(); it != keyvalues.end(); ++it)
{
cmd << it->first << it->second;
}
return cmd;
}
Command Command::sadd(const std::string& set, const std::string& value)
{
Command cmd("SADD");
cmd << set << value;
return cmd;
}
Command Command::sadd(const std::string& set, const StringVec& values)
{
Command cmd("SADD");
cmd << set << values;
return cmd;
}
Command Command::scard(const std::string& set)
{
Command cmd("SCARD");
cmd << set;
return cmd;
}
Command Command::sdiff(const std::string& set1, const std::string& set2)
{
Command cmd("SDIFF");
cmd << set1 << set2;
return cmd;
}
Command Command::sdiff(const std::string& set, const StringVec& sets)
{
Command cmd("SDIFF");
cmd << set << sets;
return cmd;
}
Command Command::sdiffstore(const std::string& set, const std::string& set1, const std::string& set2)
{
Command cmd("SDIFFSTORE");
cmd << set << set1 << set2;
return cmd;
}
Command Command::sdiffstore(const std::string& set, const StringVec& sets)
{
Command cmd("SDIFFSTORE");
cmd << set << sets;
return cmd;
}
Command Command::set(const std::string& key, const std::string& value, bool overwrite, const Poco::Timespan& expireTime, bool create)
{
Command cmd("SET");
cmd << key << value;
if (! overwrite) cmd << "NX";
if (! create) cmd << "XX";
if (expireTime.totalMicroseconds() > 0) cmd << "PX" << expireTime.totalMilliseconds();
return cmd;
}
Command Command::set(const std::string& key, Int64 value, bool overwrite, const Poco::Timespan& expireTime, bool create)
{
return set(key, NumberFormatter::format(value), overwrite, expireTime, create);
}
Command Command::sinter(const std::string& set1, const std::string& set2)
{
Command cmd("SINTER");
cmd << set1 << set2;
return cmd;
}
Command Command::sinter(const std::string& set, const StringVec& sets)
{
Command cmd("SINTER");
cmd << set << sets;
return cmd;
}
Command Command::sinterstore(const std::string& set, const std::string& set1, const std::string& set2)
{
Command cmd("SINTERSTORE");
cmd << set << set1 << set2;
return cmd;
}
Command Command::sinterstore(const std::string& set, const StringVec& sets)
{
Command cmd("SINTERSTORE");
cmd << set << sets;
return cmd;
}
Command Command::sismember(const std::string& set, const std::string& member)
{
Command cmd("SISMEMBER");
cmd << set << member;
return cmd;
}
Command Command::smembers(const std::string& set)
{
Command cmd("SMEMBERS");
cmd << set;
return cmd;
}
Command Command::smove(const std::string& source, const std::string& destination, const std::string& member)
{
Command cmd("SMOVE");
cmd << source << destination << member;
return cmd;
}
Command Command::spop(const std::string& set, Int64 count)
{
Command cmd("SPOP");
cmd << set;
if( count != 0 ) cmd << NumberFormatter::format(count);
return cmd;
}
Command Command::srandmember(const std::string& set, Int64 count)
{
Command cmd("SRANDMEMBER");
cmd << set;
if( count != 0 ) cmd << NumberFormatter::format(count);
return cmd;
}
Command Command::srem(const std::string& set1, const std::string& member)
{
Command cmd("SREM");
cmd << set1 << member;
return cmd;
}
Command Command::srem(const std::string& set, const StringVec& members)
{
Command cmd("SREM");
cmd << set << members;
return cmd;
}
Command Command::sunion(const std::string& set1, const std::string& set2)
{
Command cmd("SUNION");
cmd << set1 << set2;
return cmd;
}
Command Command::sunion(const std::string& set, const StringVec& sets)
{
Command cmd("SUNION");
cmd << set << sets;
return cmd;
}
Command Command::sunionstore(const std::string& set, const std::string& set1, const std::string& set2)
{
Command cmd("SUNIONSTORE");
cmd << set << set1 << set2;
return cmd;
}
Command Command::sunionstore(const std::string& set, const StringVec& sets)
{
Command cmd("SUNIONSTORE");
cmd << set << sets;
return cmd;
}
Command Command::rename(const std::string& key, const std::string& newName, bool overwrite)
{
Command cmd(overwrite ? "RENAME" : "RENAMENX");
cmd << key << newName;
return cmd;
}
Command Command::rpop(const std::string& list)
{
Command cmd("RPOP");
cmd << list;
return cmd;
}
Command Command::rpoplpush(const std::string& sourceList, const std::string& destinationList)
{
Command cmd("RPOPLPUSH");
cmd << sourceList << destinationList;
return cmd;
}
Command Command::rpush(const std::string& list, const std::string& value, bool create)
{
Command cmd(create ? "RPUSH" : "RPUSHX");
cmd << list << value;
return cmd;
}
Command Command::rpush(const std::string& list, const StringVec& values, bool create)
{
Command cmd(create ? "RPUSH" : "RPUSHX");
cmd << list << values;
return cmd;
}
Command Command::expire(const std::string& key, Int64 seconds)
{
Command cmd("EXPIRE");
cmd << key << NumberFormatter::format(seconds);
return cmd;
}
Command Command::ping()
{
Command cmd("PING");
return cmd;
}
Command Command::multi()
{
Command cmd("MULTI");
return cmd;
}
Command Command::exec()
{
Command cmd("EXEC");
return cmd;
}
Command Command::discard()
{
Command cmd("DISCARD");
return cmd;
}
} } // namespace Poco::Redis

39
vendor/POCO/Redis/src/Error.cpp vendored Normal file
View File

@ -0,0 +1,39 @@
//
// Error.cpp
//
// Library: Redis
// Package: Redis
// Module: Error
//
// Implementation of the Error class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Error.h"
namespace Poco {
namespace Redis {
Error::Error()
{
}
Error::Error(const std::string& message): _message(message)
{
}
Error::~Error()
{
}
} } // namespace Poco::Redis

27
vendor/POCO/Redis/src/Exception.cpp vendored Normal file
View File

@ -0,0 +1,27 @@
//
// Exception.h
//
// Library: Redis
// Package: Redis
// Module: Exception
//
// Implementation of the Exception class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Exception.h"
namespace Poco {
namespace Redis {
POCO_IMPLEMENT_EXCEPTION(RedisException, Exception, "Redis Exception")
} } // namespace Poco::Redis

View File

@ -0,0 +1,46 @@
//
// RedisEventArgs.cpp
//
// Library: Redis
// Package: Redis
// Module: RedisEventArgs
//
// Implementation of the RedisEventArgs class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/RedisEventArgs.h"
namespace Poco {
namespace Redis {
RedisEventArgs::RedisEventArgs(RedisType::Ptr pMessage):
_message(pMessage),
_exception(0),
_stop(false)
{
}
RedisEventArgs::RedisEventArgs(Exception* pException):
_message(),
_exception(pException ? pException->clone() : 0),
_stop(false)
{
}
RedisEventArgs::~RedisEventArgs()
{
delete _exception;
}
} } // namespace Poco::Redis

133
vendor/POCO/Redis/src/RedisStream.cpp vendored Normal file
View File

@ -0,0 +1,133 @@
//
// RedisStream.cpp
//
// Library: Redis
// Package: Redis
// Module: RedisStream
//
// Implementation of the RedisStream class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/RedisStream.h"
#include <iostream>
namespace Poco {
namespace Redis {
//
// RedisStreamBuf
//
RedisStreamBuf::RedisStreamBuf(Net::StreamSocket& redis):
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out),
_redis(redis)
{
}
RedisStreamBuf::~RedisStreamBuf()
{
}
int RedisStreamBuf::readFromDevice(char* buffer, std::streamsize len)
{
return _redis.receiveBytes(buffer, len);
}
int RedisStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
{
return _redis.sendBytes(buffer, length);
}
//
// RedisIOS
//
RedisIOS::RedisIOS(Net::StreamSocket& redis):
_buf(redis)
{
poco_ios_init(&_buf);
}
RedisIOS::~RedisIOS()
{
try
{
_buf.sync();
}
catch (...)
{
}
}
RedisStreamBuf* RedisIOS::rdbuf()
{
return &_buf;
}
void RedisIOS::close()
{
_buf.sync();
}
//
// RedisOutputStream
//
RedisOutputStream::RedisOutputStream(Net::StreamSocket& redis):
RedisIOS(redis),
std::ostream(&_buf)
{
}
RedisOutputStream::~RedisOutputStream()
{
}
RedisInputStream::RedisInputStream(Net::StreamSocket& redis):
RedisIOS(redis),
std::istream(&_buf)
{
}
//
// RedisInputStream
//
RedisInputStream::~RedisInputStream()
{
}
std::string RedisInputStream::getline()
{
std::string line;
std::getline(*this, line);
if ( line.size() > 0 ) line.erase(line.end() - 1);
return line;
}
} } // namespace Poco::Redis

62
vendor/POCO/Redis/src/Type.cpp vendored Normal file
View File

@ -0,0 +1,62 @@
//
// Type.h
//
// Library: Redis
// Package: Redis
// Module: Type
//
// Implementation of the Type class.
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Redis/Type.h"
#include "Poco/Redis/Error.h"
#include "Poco/Redis/Array.h"
namespace Poco {
namespace Redis {
RedisType::RedisType()
{
}
RedisType::~RedisType()
{
}
RedisType::Ptr RedisType::createRedisType(char marker)
{
RedisType::Ptr result;
switch(marker)
{
case RedisTypeTraits<Int64>::marker :
result = new Type<Int64>();
break;
case RedisTypeTraits<std::string>::marker :
result = new Type<std::string>();
break;
case RedisTypeTraits<BulkString>::marker :
result = new Type<BulkString>();
break;
case RedisTypeTraits<Array>::marker :
result = new Type<Array>();
break;
case RedisTypeTraits<Error>::marker :
result = new Type<Error>();
break;
}
return result;
}
} } // namespace Poco::Redis