28
28
#include "drizzled/definitions.h"
29
29
#include "drizzled/error.h"
30
30
#include "drizzled/errmsg_print.h"
31
#include "drizzled/plugin/library.h"
31
#include "drizzled/module/library.h"
33
33
using namespace std;
38
plugin::Library::Library(const std::string &name_arg,
38
module::Library::Library(const std::string &name_arg,
40
40
const Manifest *manifest_arg)
41
41
: name(name_arg), handle(handle_arg), manifest(manifest_arg)
44
plugin::Library::~Library()
44
module::Library::~Library()
47
47
* @TODO: This breaks valgrind at the moment.
53
plugin::Library *plugin::Library::loadLibrary(const string &plugin_name)
53
const string module::Library::getLibraryPath(const string &plugin_name)
56
Ensure that the dll doesn't have a path.
57
This is done to ensure that only approved libraries from the
58
plugin directory are used (to make this even remotely secure).
60
size_t found= plugin_name.find(FN_LIBCHAR);
61
if (found != string::npos)
63
errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_PLUGIN_NO_PATHS));
67
55
/* Compile dll path */
69
57
dlpath.reserve(FN_REFLEN);
78
66
dlpath.append(".so");
71
module::Library *module::Library::loadLibrary(const string &plugin_name, bool builtin)
74
Ensure that the dll doesn't have a path.
75
This is done to ensure that only approved libraries from the
76
plugin directory are used (to make this even remotely secure).
78
size_t found= plugin_name.find(FN_LIBCHAR);
79
if (found != string::npos)
81
errmsg_printf(ERRMSG_LVL_ERROR, "%s",ER(ER_PLUGIN_NO_PATHS));
90
dlpath.assign("<builtin>");
91
handle= dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
94
const char *errmsg= dlerror();
95
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY),
96
dlpath.c_str(), errno, errmsg);
81
104
/* Open new dll handle */
82
void *handle= dlopen(dlpath.c_str(), RTLD_NOW|RTLD_GLOBAL);
85
const char *errmsg= dlerror();
86
uint32_t dlpathlen= dlpath.length();
87
if (!dlpath.compare(0, dlpathlen, errmsg))
88
{ // if errmsg starts from dlpath, trim this prefix.
90
if (*errmsg == ':') errmsg++;
91
if (*errmsg == ' ') errmsg++;
105
dlpath.assign(Library::getLibraryPath(plugin_name));
106
handle= dlopen(dlpath.c_str(), RTLD_NOW|RTLD_GLOBAL);
109
const char *errmsg= dlerror();
110
uint32_t dlpathlen= dlpath.length();
111
if (not dlpath.compare(0, dlpathlen, errmsg))
112
{ // if errmsg starts from dlpath, trim this prefix.
114
if (*errmsg == ':') errmsg++;
115
if (*errmsg == ' ') errmsg++;
117
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY),
118
dlpath.c_str(), errno, errmsg);
120
// This, in theory, should cause dlerror() to deallocate the error
121
// message. Found this via Google'ing :)
93
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_OPEN_LIBRARY),
94
dlpath.c_str(), errno, errmsg);
96
// This is, in theory, should cause dlerror() to deallocate the error
97
// message. Found this via Google'ing :)
104
128
string plugin_decl_sym("_drizzled_");
105
129
plugin_decl_sym.append(plugin_name);
106
130
plugin_decl_sym.append("_plugin_");