Commit 80707141 authored by jan.koester's avatar jan.koester
Browse files

test

parent e30171bd
Loading
Loading
Loading
Loading
+3 −2
Changes for src/CMakeLists.txt: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -11,8 +11,7 @@ add_library(blogidev STATIC
    theme.cpp
    cookie.cpp
    mail.cpp
    webedit/edit.cpp
    webedit/plugin.cpp
    edit.cpp
)

target_include_directories(blogidev PRIVATE ${SMTPCLIENT_INCLUDE_DIR})
@@ -100,3 +99,5 @@ if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows" )
    set(CPACK_PACKAGE_INSTALL_DIRECTORY "blogi")
    INCLUDE(CPack)
endif()

add_subdirectory(webedit)
+1 −1
Changes for src/blogi.cpp: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "blogi.h"

#include "webedit/edit.h"
#include "edit.h"

#define cookieid "2d1b0348-1491-11f0-8c81-3cecefce9ac2"

+2 −2
Changes for src/edit.cpp: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@
#include "edit.h"
#include "plugin.h"

#include "../blogi.h"
#include "../theme.h"
#include "blogi.h"
#include "theme.h"

void blogi::webedit::WebEditor::Editor(PluginArgs &plgars,libhttppp::HttpRequest& curreq, const int tid, const std::string &sessionid){
    libhtmlpp::HtmlElement edithtml;
+1 −1
Changes for src/edit.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@
#include <httppp/http.h>
#include <tinyxml2.h>

#include "../plugin.h"
#include "plugin.h"

#pragma once

+98 −0
Changes for src/plugin.cpp: 98 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -244,3 +244,101 @@ blogi::PluginApi * blogi::Plugin::PluginData::getInstace() const{
const blogi::Plugin::PluginData *blogi::Plugin::PluginData::getNextPlg() const{
    return next.get();
}

blogi::webedit::EditPluginLoad::EditPluginLoad(const std::string& path){
    try {
        if (std::filesystem::is_directory(path)) {
            for (const auto& entry : std::filesystem::directory_iterator(path)) {
                 std::unique_ptr<PluginData> ldplg = std::make_unique<PluginData>();
#ifdef Windows
                if (entry.path().extension() == ".dll") {
                    try {
                        std::string ppath = entry.path().string();
                        ldplg->pldata = LoadLibraryA(ppath.c_str());

                        if (ldplg->pldata == nullptr) {
                            DWORD lastError = GetLastError();
                            throw std::runtime_error("Cannot load library. Error code: " + std::to_string(lastError));
                        }

                        create_t *create_plugin = (create_t*)GetProcAddress(ldplg->pldata, "create");

                        if (create_plugin == nullptr) {
                            DWORD lastError = GetLastError();
                            FreeLibrary(ldplg->pldata);
                            throw std::runtime_error("Cannot load symbol 'create'. Error code: " + std::to_string(lastError));
                        }

                        destroy_t* destroy_plugin = (destroy_t*)GetProcAddress(ldplg->pldata, "destroy");
                        if (destroy_plugin == nullptr) {
                            DWORD lastError = GetLastError();
                            FreeLibrary(ldplg->pldata);
                            throw std::runtime_error("Cannot load symbol 'destroy'. Error code: " + std::to_string(lastError));
                        }

#else // Linux/Unix
                if (entry.path().extension() == ".so") {
                    try{


                        ldplg->pldata = dlopen(entry.path().c_str(), RTLD_LAZY);

                        const char * dlsym_error = nullptr;

                        if (!ldplg->pldata) { // FIX: Check ldplg->pldata, not !ldplg->pldata && dlsym_error
                            dlsym_error = dlerror();
                            libhttppp::HTTPException err;
                            err[libhttppp::HTTPException::Error] << "Cannot load library: " << (dlsym_error ? dlsym_error : "Unknown error");
                            throw err;
                        }

                        // Get the address of the 'create' function
                        create_t* create_plugin= (create_t*) dlsym(ldplg->pldata, "create");

                        if (create_plugin == nullptr) {
                            dlsym_error = dlerror();
                            libhttppp::HTTPException err;
                            // The custom deleter will call dlclose when ldplg goes out of scope/is destroyed
                            err[libhttppp::HTTPException::Error] << "Cannot load symbol create: " << (dlsym_error ? dlsym_error : "Unknown error") << '\n';
                            throw err;
                        }
                        destroy_t* destroy_plugin = (destroy_t*) dlsym(ldplg->pldata, "destroy");
#endif
                        EditPlugin *plg=create_plugin();
                        ldplg->ins=std::unique_ptr<EditPlugin, EditPluginDeleter>(plg, EditPluginDeleter(destroy_plugin,ldplg->pldata));

                        if(_lastPlugin){
                            _lastPlugin->next=std::move(ldplg);
                            _lastPlugin = _lastPlugin->next.get();
                        }else{
                            _firstPlugin=std::move(ldplg);
                            _lastPlugin = _firstPlugin.get();
                        }
                    }
                    catch (const std::exception& e) {
                        std::cerr << "Error processing file " << entry.path().filename().string() << ": " << e.what() << std::endl;
                    }catch(libhttppp::HTTPException &e){
                         std::cerr << "Error processing file " << e.what() << ": " << e.what() << std::endl;
                    }
                }
            }
        }
    }catch (const std::exception& e) {
        std::cerr << "Error loading plugins directory: " << e.what() << std::endl;
    }
}

blogi::webedit::EditPluginLoad::~EditPluginLoad(){
}

const blogi::webedit::EditPluginLoad::PluginData* blogi::webedit::EditPluginLoad::EditPluginLoad::getFirstPlugin() const{
    return _firstPlugin.get();
}

const blogi::webedit::EditPluginLoad::PluginData *blogi::webedit::EditPluginLoad::PluginData::getNextPlg() const{
    return next.get();
}

blogi::webedit::EditPlugin *blogi::webedit::EditPluginLoad::PluginData::getInstace() const{
    return ins.get();
}
Loading