Commit 11360e30 authored by jan.koester's avatar jan.koester
Browse files

removed legacy redis support

parent 625249b0
Loading
Loading
Loading
Loading
+2 −2
Changes for Dockerfile: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ FROM node:alpine AS build
WORKDIR /build/alpine

RUN apk update --no-cache  && apk upgrade --no-cache 
RUN apk add --no-cache cmake ninja clang alpine-sdk lua-aports sudo openssh-keygen fakeroot openssh-client yaml-dev hiredis-dev brotli-dev openssl-dev json-c-dev sqlite-dev libpq-dev util-linux-dev hiredis-dev libc-dev tinyxml2-dev
RUN apk add --no-cache cmake ninja clang alpine-sdk lua-aports sudo openssh-keygen fakeroot openssh-client yaml-dev brotli-dev openssl-dev json-c-dev sqlite-dev libpq-dev util-linux-dev libc-dev tinyxml2-dev

RUN git clone https://git.tuxist.de/git/jan.koester/libcmdplus.git
RUN mkdir libcmdplus/build
@@ -59,7 +59,7 @@ FROM node:alpine
RUN addgroup blogi
RUN adduser blogi -h /var/lib/blogi -S -G blogi
RUN apk update && apk upgrade
RUN apk add --no-cache yaml brotli openssl json-c libuuid hiredis libpq sqlite-libs libstdc++ pwgen sed tinyxml2
RUN apk add --no-cache yaml brotli openssl json-c libuuid libpq sqlite-libs libstdc++ pwgen sed tinyxml2

RUN mkdir /etc/blogi
RUN mkdir /usr/local/share/blogi

cmake/FindHiredis.cmake

deleted100644 → 0
+0 −68
Changes for cmake/FindHiredis.cmake: 0 added lines, 68 removed lines.
Original line number Diff line number Diff line
include(CMakePushCheckState)
include(CheckSymbolExists)

############################################################################
#
# - Find the libhiredis library
#
#  HIREDIS_FOUND - system has libhiredis
#  HIREDIS_INCLUDE_DIRS - the libhiredis include directory
#  HIREDIS_LIBRARIES - The libraries needed to use libhiredis
#  HIREDIS_ASYNC_ENABLED - The found libhiredis library supports async commands


# Find out the include directory
find_path(HIREDIS_INCLUDE_DIRS
	NAMES hiredis/hiredis.h
	PATH_SUFFIXES include
)

# Find out the path to the library
find_library(HIREDIS_LIBRARIES
	NAMES hiredis
)

if(HIREDIS_INCLUDE_DIRS AND HIREDIS_LIBRARIES)
	# Extract the version number from the header files
	function(extract_version version_header range output_var)
		string(TOUPPER ${range} range)
		set(define_line_regex "^#define HIREDIS_${range} ([0-9]+)$")
		file(STRINGS ${version_header} define_line REGEX "${define_line_regex}")
		if(NOT define_line)
			message(FATAL_ERROR "HIREDIS_${range} isn't defined in '${version_header}'")
		endif()
		string(REGEX REPLACE ${define_line_regex} "\\1" version_range_value "${define_line}")
		set(${output_var} ${version_range_value} PARENT_SCOPE)
	endfunction()
	set(version_header "${HIREDIS_INCLUDE_DIRS}/hiredis/hiredis.h")
	extract_version(${version_header} major HIREDIS_VERSION_MAJOR)
	extract_version(${version_header} minor HIREDIS_VERSION_MINOR)
	extract_version(${version_header} patch HIREDIS_VERSION_PATCH)
	set(HIREDIS_VERSION "${HIREDIS_VERSION_MAJOR}.${HIREDIS_VERSION_MINOR}.${HIREDIS_VERSION_PATCH}")

	# Check that the async mode is supported
	cmake_push_check_state(RESET)
	list(APPEND CMAKE_REQUIRED_INCLUDES ${HIREDIS_INCLUDE_DIRS})
	list(APPEND CMAKE_REQUIRED_LIBRARIES ${HIREDIS_LIBRARIES})
	check_symbol_exists("redisAsyncCommand" "hiredis/async.h" HIREDIS_ASYNC_ENABLED)
	cmake_pop_check_state()
	if(NOT HIREDIS_ASYNC_ENABLED)
		message(FATAL_ERROR "redisAsyncCommand() not found")
	endif()
endif()

# Define HIREDIS_FOUND output variable and define the 'hiredis' imported target
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Hiredis
	REQUIRED_VARS HIREDIS_INCLUDE_DIRS HIREDIS_LIBRARIES
	VERSION_VAR HIREDIS_VERSION
)
if (HIREDIS_FOUND)
	add_library(hiredis::hiredis SHARED IMPORTED)
	set_target_properties(hiredis::hiredis PROPERTIES
		INTERFACE_INCLUDE_DIRECTORIES "${HIREDIS_INCLUDE_DIR}"
		IMPORTED_LOCATION "${HIREDIS_LIBRARIES}"
	)
endif()

mark_as_advanced(HIREDIS_INCLUDE_DIRS HIREDIS_LIBRARIES HIREDIS_ASYNC_ENABLED)
+0 −4
Changes for config.yaml: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -20,10 +20,6 @@ BLOGI:
      CLIENTNAME: "blogiclient"
      CLIENTSECRET: "clientsecret"
      DOMAIN: "example.com"
  REDIS:
    HOST: "127.0.0.1"
    PORT: 6379
    TIMEOUT: 1000
  NGINXFILER:
    HOST: "nginx.example.com"
    PORT: 80

plugins/media/backend.h

deleted100644 → 0
+0 −66
Changes for plugins/media/backend.h: 0 added lines, 66 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2024, Jan Koester jan.koester@gmx.net
 * 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 <organization> 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 <COPYRIGHT HOLDER> 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.
 *******************************************************************************/

#pragma once

#include <string>
#include <vector>

#include <hiredis/hiredis.h>

#include <httppp/http.h>

namespace blogi {
    class Store {
    public:
        Store(){};
        virtual ~Store(){};

        virtual size_t getSize(int tid,const char *key)=0;

        virtual void save(int tid,const char *key, const char *data,size_t datalen)=0;
        virtual void load(int tid,libhttppp::HttpRequest &req,const char *key,std::vector<char> &data,size_t pos,size_t blocksize) =0;
        virtual void loadAll(int tid,const char *key,std::vector<char> &data) =0;

    };

    class RedisStore : public Store {
    public:
        RedisStore(const char *host,int port,const char *password,int timeout,int threads=0);
        ~RedisStore();

        size_t getSize(int tid,const char *key) override;

        void save(int tid,const char *key,const char *data,size_t datalen) override;
        void load(int tid,libhttppp::HttpRequest &req,const char *key,std::vector<char> &data,size_t pos,size_t blocksize) override;
        void loadAll(int tid,const char *key,std::vector<char> &data) override;
    private:
        std::vector<redisContext*> _RedisCTX;
        std::string                             _RedisPassword;
        int                                         _Threads;
    };
};

plugins/media/redis.cpp

deleted100644 → 0
+0 −152
Changes for plugins/media/redis.cpp: 0 added lines, 152 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2024, Jan Koester jan.koester@gmx.net
 * 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 <organization> 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 <COPYRIGHT HOLDER> 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.
 *******************************************************************************/

#include <algorithm>
#include <cstring>
#include <iterator>

#include <httppp/exception.h>
#include <httppp/httpd.h>

#include "backend.h"

blogi::RedisStore::RedisStore(const char *host,int port,const char *password,int timeout,int threads){
    _Threads=threads;
    _RedisCTX.resize(_Threads);
    for(int i = 0; i<_Threads; ++i){

        struct timeval tv={0,timeout};

        _RedisCTX[i]=redisConnectWithTimeout(host,port,tv);

        if (_RedisCTX[i]->err) {
            libhttppp::HTTPException exp;
            exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX[i]->errstr;
            throw exp;
        }

        if(password){
            _RedisPassword=password;
            redisReply *rep=(redisReply*)redisCommand(_RedisCTX[i],"AUTH %s", password);
            if (rep == nullptr) {
                 libhttppp::HTTPException exp;
                 exp[libhttppp::HTTPException::Error] << "media plugin err: AUTH command failed: " << _RedisCTX[i]->errstr;
                 throw exp;
            }

            if (rep->type == REDIS_REPLY_ERROR) {
                libhttppp::HTTPException exp;
                exp[libhttppp::HTTPException::Error] << "media plugin err: Redis AUTH failed: " << rep->str;
                freeReplyObject(rep);
                throw exp;
            }
            freeReplyObject(rep);
        }

    }

}
blogi::RedisStore::~RedisStore(){
    for(int i = 0; i<_Threads; ++i){
        redisFree(_RedisCTX[i]);
    }
}

size_t blogi::RedisStore::getSize(int tid,const char* key){

        if(_RedisCTX[tid]->err!=REDIS_OK){
            libhttppp::HTTPException e;
            e[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX[tid]->errstr;
            throw e;
        }

        redisReply *rep=(redisReply*)redisCommand(_RedisCTX[tid],"STRLEN %s",key);

        size_t ret = 0; // Initialize return value

       if(!rep || rep->type != REDIS_REPLY_INTEGER){
           // Check if rep is not NULL before calling freeReplyObject on it
           if (rep) {
               freeReplyObject(rep);
           }
           libhttppp::HTTPException e;
           e[libhttppp::HTTPException::Error] << "media plugin err: wrong redis reply in getsize !";
           throw e;
       }

        ret = rep->integer;

        freeReplyObject(rep); // <-- Correct location: free the object before returning

        return ret;
}


void blogi::RedisStore::save(int tid,const char *key, const char *data,size_t datalen){
    redisReply *rep=(redisReply*)redisCommand(_RedisCTX[tid],"SET %s %b",key,data,datalen);
    freeReplyObject(rep);
    rep=(redisReply*)redisCommand(_RedisCTX[tid],"save");
    freeReplyObject(rep);
}

void blogi::RedisStore::load(int tid,libhttppp::HttpRequest &req,const char *key,std::vector<char> &data,size_t pos,size_t blocksize) {
    try{
        redisReply *rep=(redisReply*)redisCommand(_RedisCTX[tid],"GETRANGE %s %d %d",key,pos,pos+blocksize);

        if(_RedisCTX[tid]->err!=REDIS_OK){
            freeReplyObject(rep);
            libhttppp::HTTPException e;
            e[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX[tid]->errstr;
            throw e;
        }

        std::copy(rep->str,rep->str+rep->len,std::inserter<std::vector<char>>(data,data.begin()));

        freeReplyObject(rep);
    }catch(libhttppp::HTTPException &e){
        throw e;
    }
}

void blogi::RedisStore::loadAll(int tid,const char *key,std::vector<char> &data) {
    redisReply *rep=(redisReply*)redisCommand(_RedisCTX[tid],"GET %s",key);

    if(_RedisCTX[tid]->err!=REDIS_OK){
        if(rep) freeReplyObject(rep);
        libhttppp::HTTPException e;
        e[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX[tid]->errstr;
        throw e;
    }

    if(!rep || rep->type != REDIS_REPLY_STRING){
        if(rep) freeReplyObject(rep);
        return;
    }

    data.assign(rep->str, rep->str + rep->len);
    freeReplyObject(rep);
}
Loading