drogonframework / drogonframework/drogon
Plugins don't load correctly
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
**Describe the bug**
Plugins in the plugins folder Do not load
v1.9.0 c++20 using WSL g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
**To Reproduce**
Steps to reproduce the behavior:
try using plugins in plugins folder as explained in the documentation.
the following 2 files are as plain as possible generated with drogon_ctl
test.h (plugins folder)
```cpp
#pragma once
#include
class test : public drogon::Plugin
{
public:
test() {}
/// This method must be called by drogon to initialize and start the plugin.
/// It must be implemented by the user.
void initAndStart(const Json::Value &config) override;
/// This method must be called by drogon to shutdown the plugin.
/// It must be implemented by the user.
void shutdown() override;
};
```
test.cc (in plugins folder)
```cpp
#include "test.h"
using namespace drogon;
void test::initAndStart(const Json::Value &config)
{
LOG_INFO<<"test is starting";
}
void test::shutdown()
{
LOG_INFO<<"test shutting down";
}
```
just another test plugin with some config and a namespace
plugin_Mailio.hpp (in the plugins folder)
```cpp
#pragma once
#include
#include
namespace plugin{
struct MailioException:public std::runtime_error{
MailioException(const std::string& error):std::runtime_error(error){}
};
class Mailio : public drogon::Plugin{
private:
std::string email, password, smtpAddress;
unsigned int smtpPort;
public:
Mailio() = default;
/// This method must be called by drogon to initialize and start the plugin.
/// It must be implemented by the user.
void initAndStart(const Json::Value &config) override;
/// This method must be called by drogon to shutdown the plugin.
/// It must be implemented by the user.
void shutdown() override;
};
}
```
plugin_Mailio.cpp (in plugins folder)
```cpp
#include "plugin_Mailio.hpp"
using namespace drogon;
using namespace plugin;
void Mailio::initAndStart(const Json::Value &config){
email=config["email"].asString();
password=config["password"].asString();
smtpAddress=config["smtpAdress"].asString();
smtpPort=config["smtpPort"].asUInt();
if(email.empty())
throw MailioException("configuration error: email is required");
if(password.empty())
throw MailioException("configuration error: password is required");
if(smtpAddress.empty())
throw MailioException("configuration error: smtpAddress is required");
if(smtpPort==0)
throw MailioException("configuration error: smtpPort is required");
LOG_INFO<<"mailio initiated";
}
void Mailio::shutdown(){
}
```
configs (tried both JSON and YAML
YAML
```yaml
plugins:
# name: The class name of the plugin
- name: 'plugin::Mailio' # drogon::plugin::SecureSSLRedirector
# dependencies: Plugins that the plugin depends on. It can be commented out
dependencies: []
# config: The configuration of the plugin. This json object is the parameter to initialize the plugin.
# It can be commented out
config:
email: 'server@mail.com'
password: 'fdasfsaffadf'
smtpAddress: 'smtp.mail.company.com'
smtpPort: 531
- name: 'test'
dependencies: []
config:
```
JSON
```json
[{
"name": "plugin::Mailio",
"dependencies": [],
"config": {
"email": "server@mail.com",
"password": "fdadsafasf",
"smtpAddress": "smtp.mail.company.com",
"smtpPort": 432
}
},{
"name": "test",
"dependencies": [],
"config":{
}
}]
```
trying to get the plugin pointer from inside a request handler yields NULL pointer instead of a pointer to the plugin object
```cpp
#include "plugins/plugin_Mailio.hpp"
#include "plugins/test.h"
auto mailioPlug= app().getPlugin();
auto testPlug= app().getPlugin();
```
**Expected behaviour**
plugins load and can be used as explained [here](https://drogonframework.github.io/drogon-docs/#/ENG-09-Plugins)
Contributor guide
Assessment
This issue has not been assessed yet.