2015-03-27 08:44:40 -07:00
|
|
|
#include "irc.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "events.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
void load_module(struct irc_conn *bot, char *where, int stype, char *file)
|
|
|
|
{
|
|
|
|
void *handle;
|
2015-04-07 11:18:24 -07:00
|
|
|
void (*mod_init)();
|
2015-03-27 08:44:40 -07:00
|
|
|
char *error = (char *)malloc(sizeof(char *)*1024);
|
|
|
|
|
|
|
|
|
2015-04-06 23:56:50 -07:00
|
|
|
handle = dlopen(file, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
|
2015-03-27 08:44:40 -07:00
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
sprintf(error, "Error: %s", dlerror());
|
|
|
|
|
2015-04-07 11:18:24 -07:00
|
|
|
if (stype == 3)
|
|
|
|
{
|
|
|
|
eprint("%s\n", error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (stype == PRIVMSG_CHAN)
|
2015-03-27 08:44:40 -07:00
|
|
|
{
|
|
|
|
irc_privmsg(bot, where, error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
irc_notice(bot, where, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dlerror();
|
|
|
|
|
|
|
|
*(void **)(&mod_init) = dlsym(handle, "mod_init");
|
|
|
|
|
|
|
|
if ((error = dlerror()) != NULL)
|
|
|
|
{
|
|
|
|
//sprintf(error, "Error: %s", error);
|
|
|
|
eprint("Error: %s\n", error);
|
2015-04-07 11:18:24 -07:00
|
|
|
|
|
|
|
if (stype == 3)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (stype == PRIVMSG_CHAN)
|
2015-03-27 08:44:40 -07:00
|
|
|
{
|
|
|
|
irc_privmsg(bot, where, error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
irc_notice(bot, where, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 11:18:24 -07:00
|
|
|
(*mod_init)();
|
2015-03-27 08:44:40 -07:00
|
|
|
|
|
|
|
dlclose(handle);
|
|
|
|
|
2015-04-07 11:18:24 -07:00
|
|
|
if (stype != 3)
|
|
|
|
{
|
|
|
|
irc_privmsg(bot, where, "Module '%s' loaded.", file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Module '%s' loaded.\n", file);
|
|
|
|
}
|
2015-03-27 08:44:40 -07:00
|
|
|
free(error);
|
|
|
|
}
|