Commit 2b3b36fd authored by jan.koester's avatar jan.koester
Browse files

test

parent 77a6587a
Loading
Loading
Loading
Loading
+24 −3
Changes for src/blogi.cpp: 24 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -113,23 +113,40 @@ static std::unique_ptr<blogi::PluginApi, blogi::PluginApiDeleter>
loadDeployPluginFile(const std::filesystem::path &path) {
#ifdef Windows
    HMODULE handle = LoadLibraryA(path.string().c_str());
    if (!handle)
    if (!handle) {
        std::cerr << "[deploy] failed to load " << path.string() << std::endl;
        return {};
    }

    auto *create_plugin = reinterpret_cast<blogi::create_t*>(GetProcAddress(handle, "create"));
    auto *destroy_plugin = reinterpret_cast<blogi::destroy_t*>(GetProcAddress(handle, "destroy"));
    if (!create_plugin || !destroy_plugin) {
        std::cerr << "[deploy] missing create/destroy symbols in " << path.string() << std::endl;
        FreeLibrary(handle);
        return {};
    }
#else
    void *handle = dlopen(path.string().c_str(), RTLD_LAZY);
    if (!handle)
    if (!handle) {
        const char *loadError = dlerror();
        std::cerr << "[deploy] failed to dlopen " << path.string() << ": "
                  << (loadError ? loadError : "unknown error") << std::endl;
        return {};
    }

    dlerror();
    auto *create_plugin = reinterpret_cast<blogi::create_t*>(dlsym(handle, "create"));
    const char *createError = dlerror();
    dlerror();
    auto *destroy_plugin = reinterpret_cast<blogi::destroy_t*>(dlsym(handle, "destroy"));
    const char *destroyError = dlerror();
    if (!create_plugin || !destroy_plugin) {
        std::cerr << "[deploy] missing create/destroy symbols in " << path.string();
        if (createError)
            std::cerr << " create: " << createError;
        if (destroyError)
            std::cerr << " destroy: " << destroyError;
        std::cerr << std::endl;
        dlclose(handle);
        return {};
    }
@@ -177,8 +194,12 @@ static bool handleDeployFallback(libhttppp::HttpRequest &curreq, const int tid,
                continue;

            plugin->setArgs(&args);
            if (plugin->getName() != "_deploy")
            if (plugin->getName() != "_deploy") {
                std::cerr << "[deploy] plugin " << entry.path().string()
                          << " reported name " << plugin->getName()
                          << ", expected _deploy" << std::endl;
                continue;
            }

            if (plugin->Response(tid, curreq))
                return true;