module.h File Reference

Go to the source code of this file.

Data Structures

struct  ModuleInfo
struct  Module
struct  ModuleQEntry

Defines

#define MOD_ERR_DL   -2
#define MOD_ERR_MSG   -1
#define MOD_ERR_OK   0
#define MOD_ERR_STOP   1
#define MOD_ERR_CRIT   2
#define MOD_ERR_FATAL   3
#define MOD_ERR_EXISTS   4
#define MOD_ERR_NOFILE   5
#define MOD_ERR_IO   6
#define MOD_ERR_API   7
#define MOD_ERR_ABI   8
#define MOD_ERR_MEMORY   9
#define MOD_ERR_UNLOAD   10
#define MOD_ERR_SYNTAX   11
#define MOD_ERR_UNSAFE   12
#define MOD_ERR_NOMOD   13
#define MOD_ERR_SQL   14
#define MOD_CONT   MOD_ERR_OK
#define MOD_STOP   MOD_ERR_STOP
#define MOD_CRIT   MOD_ERR_CRIT
#define MOD_FATAL   MOD_ERR_FATAL
#define MOD_MEMORY   MOD_ERR_MEMORY
#define MOD_TYPE_UNKNOWN   0
#define MOD_TYPE_PROTOCOL   1
#define MOD_TYPE_CORE   2
#define MOD_TYPE_STD   3
#define MOD_TYPE_CLIENT   4
#define MOD_TYPE_3RD   5
#define throwModErr(msg,...)
#define format_filename(dest, filestr)
#define ABI_MAJOR   0
#define ABI_MINOR   5
#define ABI_PATCH   4
#define ABI_VERSION   ((ABI_MAJOR * 1000) + (ABI_MINOR * 100) + ABI_PATCH)
#define MAKE_ABI(maj, min, patch)   ((maj * 1000) + (min * 100) + patch)
#define MODHEADER(name, version, author, abi, load, unload)
#define RTLD_LAZY   RTLD_NOW
#define RTLD_GLOBAL   0
#define RTLD_LOCAL   0
#define MOD_ACT_LOAD   0
#define MOD_ACT_UNLOAD   1
#define MOD_ACT_RELOAD   2
#define MOD_LOAD_NONE   -1
#define MOD_LOAD_PRE   0
#define MOD_LOAD_STD   1
#define MOD_LOAD_POST   2

Functions

int load_protocol ()
int load_modules ()
void init_modules ()
void purge_modules ()
int module_open (char *, int)
Modulemodule_find (char *)
int module_exists (char *)
void module_free (Module *)
int module_close (char *)
char * find_module_dir (char *module)
char * create_mod_temp (char *)
ModuleQEntryfind_mod_que (char *)
int addto_mod_que (char *, int, int)
int run_mod_que (int)
int mod_event_rehash (int, void *)
int mod_event_shutdown (int, void *)

Variables

char mod_err_msg [512]
int nomodules
dlink_list modules
dlink_list moduleque

Define Documentation

#define ABI_MAJOR   0

Module ABI Stuff This logic kinda looks off at first glance however we need this to make sure that module API's match, note you can manually change the ABI version on a module however do that at your own risk, as the module ABI specifies which modules the core will work properly with.

Definition at line 98 of file module.h.

#define ABI_MINOR   5

Definition at line 99 of file module.h.

#define ABI_PATCH   4

Definition at line 100 of file module.h.

#define ABI_VERSION   ((ABI_MAJOR * 1000) + (ABI_MINOR * 100) + ABI_PATCH)

Definition at line 102 of file module.h.

Referenced by module_open().

#define format_filename ( dest,
filestr   ) 
Value:
char format_file_tmp[MAXPATH]; \
        snprintf(format_file_tmp, sizeof(format_file_tmp), "%s%s", (filestr), (strstr(filestr,".so"))? "" : ".so"); \
    snprintf((dest), sizeof(dest) - 1, "%s/%s",find_module_dir((format_file_tmp)), (format_file_tmp)); \
        memset(format_file_tmp,0,sizeof(format_file_tmp));

This just looks ugly but i wanted to take into account for directories not having a / and having a / So with this said :) this is what i came up with - Twitch

Definition at line 84 of file module.h.

Referenced by create_mod_temp().

#define MAKE_ABI ( maj,
min,
patch   )     ((maj * 1000) + (min * 100) + patch)

Definition at line 103 of file module.h.

#define MOD_ACT_LOAD   0

Definition at line 154 of file module.h.

Referenced by load_modules(), and run_mod_que().

#define MOD_ACT_RELOAD   2

Definition at line 156 of file module.h.

Referenced by run_mod_que().

#define MOD_ACT_UNLOAD   1

Definition at line 155 of file module.h.

Referenced by run_mod_que().

#define MOD_CONT   MOD_ERR_OK

Definition at line 55 of file module.h.

Referenced by Module_Init().

#define MOD_CRIT   MOD_ERR_CRIT

Definition at line 57 of file module.h.

#define MOD_ERR_ABI   8

Definition at line 44 of file module.h.

#define MOD_ERR_API   7

Definition at line 43 of file module.h.

Referenced by module_open().

#define MOD_ERR_CRIT   2

Definition at line 38 of file module.h.

#define MOD_ERR_DL   -2

Definition at line 30 of file module.h.

#define MOD_ERR_EXISTS   4

Definition at line 40 of file module.h.

Referenced by module_open().

#define MOD_ERR_FATAL   3

Definition at line 39 of file module.h.

#define MOD_ERR_IO   6

Definition at line 42 of file module.h.

Referenced by module_open().

#define MOD_ERR_MEMORY   9

Definition at line 45 of file module.h.

Referenced by addto_mod_que(), and module_open().

#define MOD_ERR_MSG   -1

Definition at line 31 of file module.h.

Referenced by GetModErr().

#define MOD_ERR_NOFILE   5

Definition at line 41 of file module.h.

Referenced by module_close().

#define MOD_ERR_NOMOD   13

Definition at line 49 of file module.h.

#define MOD_ERR_OK   0

Definition at line 34 of file module.h.

Referenced by addto_mod_que(), load_modules(), module_close(), and module_open().

#define MOD_ERR_SQL   14

Definition at line 50 of file module.h.

#define MOD_ERR_STOP   1

Definition at line 37 of file module.h.

#define MOD_ERR_SYNTAX   11

Definition at line 47 of file module.h.

#define MOD_ERR_UNLOAD   10

Definition at line 46 of file module.h.

Referenced by module_close().

#define MOD_ERR_UNSAFE   12

Definition at line 48 of file module.h.

#define MOD_FATAL   MOD_ERR_FATAL

Definition at line 58 of file module.h.

#define MOD_LOAD_NONE   -1

Definition at line 162 of file module.h.

Referenced by run_mod_que().

#define MOD_LOAD_POST   2

Definition at line 165 of file module.h.

Referenced by init_modules(), and mod_event_rehash().

#define MOD_LOAD_PRE   0

Definition at line 163 of file module.h.

Referenced by init_modules(), and mod_event_rehash().

#define MOD_LOAD_STD   1

Definition at line 164 of file module.h.

Referenced by init_modules(), load_modules(), and mod_event_rehash().

#define MOD_MEMORY   MOD_ERR_MEMORY

Definition at line 59 of file module.h.

#define MOD_STOP   MOD_ERR_STOP

Definition at line 56 of file module.h.

Referenced by Module_Init().

#define MOD_TYPE_3RD   5

Definition at line 68 of file module.h.

#define MOD_TYPE_CLIENT   4

Definition at line 67 of file module.h.

#define MOD_TYPE_CORE   2

Definition at line 65 of file module.h.

Referenced by load_modules().

#define MOD_TYPE_PROTOCOL   1

Definition at line 64 of file module.h.

Referenced by load_protocol(), and purge_modules().

#define MOD_TYPE_STD   3

Definition at line 66 of file module.h.

#define MOD_TYPE_UNKNOWN   0

Definition at line 63 of file module.h.

Referenced by run_mod_que().

#define MODHEADER ( name,
version,
author,
abi,
load,
unload   ) 
Value:
static int module_build_version() {     \
                return ABI_VERSION; \
} \
ModuleInfo ModInfo = {          \
        name, version, author, abi, \
        load, unload \
} \

Module Header This struct allows the core to pull in the nessicary information and place it into the module structure.

Parameters:
name - The module name -> This is just for personal referance as the core relies on aboslute paths to find and remove modules.
version - The modules version in free form
abi - The Binary interface version, this is the version of the API used to interact with this module.
load - The function called by the core when loading the module
unload - The function used when unloading a module from the core.

Definition at line 120 of file module.h.

#define RTLD_GLOBAL   0

Definition at line 144 of file module.h.

#define RTLD_LAZY   RTLD_NOW

Definition at line 141 of file module.h.

#define RTLD_LOCAL   0

Definition at line 147 of file module.h.

#define throwModErr ( msg,
...   ) 
Value:
snprintf(mod_err_msg, sizeof(mod_err_msg), msg, __VA_ARGS__); \
                return MOD_ERR_MSG; \

Definition at line 73 of file module.h.

Referenced by module_open().


Function Documentation

int addto_mod_que ( char *  ,
int  ,
int   
)
char* create_mod_temp ( char *  file  ) 

Create a temporary module file.

Parameters:
filename (string) Path to module file we are copying
Returns:
(string) Pointer to the file name that we just created.
Note:
- this file name must be free'd upon delete.

Definition at line 245 of file module.c.

References CfgSettings, format_filename, MAXPATH, MAXREADBUFFER, Conf::network, strlcat(), and TMP_DIR.

Referenced by module_open().

ModuleQEntry* find_mod_que ( char *  file  ) 

Module Que Functions

Module Que Opporations

Definition at line 605 of file module.c.

References DLINK_FOREACH, moduleque, and ModuleQEntry::name.

char* find_module_dir ( char *  module  ) 

Definition at line 446 of file module.c.

References CLIENT_MOD_DIR, CONTRIB_PATH, CPATH, module_exists(), MPATH, and PPATH.

void init_modules (  ) 
int load_modules (  ) 
int load_protocol (  ) 

load_protocol() - Load our given protocol if it fails toss a critical error and return

Returns:
bool true - Module has loaded successfully false - Module failed to load see logs

Definition at line 121 of file module.c.

References alog(), CfgSettings, get_config_entry(), GetModErr(), LOG_FATAL, MOD_TYPE_PROTOCOL, module_open(), Conf::protocol, sendto_console(), and strlcpy().

Referenced by init_modules().

int mod_event_rehash ( int  ,
void *   
)

Event Hooks

Definition at line 709 of file module.c.

References MOD_LOAD_POST, MOD_LOAD_PRE, MOD_LOAD_STD, and run_mod_que().

Referenced by init_modules().

int mod_event_shutdown ( int  ac,
void *  args 
)

Module Loader Event Hooks

Definition at line 703 of file module.c.

References purge_modules().

Referenced by init_modules().

int module_close ( char *   ) 
int module_exists ( char *   ) 

Definition at line 426 of file module.c.

Referenced by find_module_dir(), and module_free().

Module* module_find ( char *   ) 

Definition at line 540 of file module.c.

References DLINK_FOREACH, modules, and Module::name.

Referenced by load_modules(), module_close(), module_open(), and run_mod_que().

void module_free ( Module  ) 

Definition at line 493 of file module.c.

References dlink_find_delete(), dlink_free(), Module::file, module_exists(), and modules.

Referenced by module_close(), module_open(), and purge_modules().

int module_open ( char *  filename,
int  type 
)

module_open() - Load our module file symbols

Parameters:
filename The file we are trying to link against.
type Type of module we are loading.

  • 0 MOD_TYPE_UNKNOWN Unknown module type it was either loaded after or manualy.
  • 1 MOD_TYPE_PROTOCOL
  • 2 MOD_TYPE_CORE
  • 3 MOD_TYPE_STD
  • 4 MOD_TYPE_CLIENT
Returns:
int
  • 0 = MOD_ERR_OK Loading is successful no error.
    • 1 = MOD_ERR_STOP We recieve a stop either from the module or core.
  • 2 = MOD_ERR_CRIT Criticial error happened while loading.
  • 3 = MOD_ERR_FATAL Fatal error occured while loading.
  • 4 = MOD_ERR_EXISTS Module is already loaded.
  • 5 = MOD_ERR_NOFILE No such file/directory
  • 6 = MOD_ERR_IO We were unable to read symbols from the module file.
  • 7 = MOD_ERR_API No open/closeing functions loaded
  • 8 = MOD_ERR_ABI In Omega ABI refers to the BINARY INTERFACE version which is used to in dicate wether a module will run or not if this is returned the ABI values do not match.
  • 9 = MOD_ERR_MEMORY We were unable to allocate memory.
  • 10 = MOD_ERR_UNLOAD Module file is unsafe to unload
  • 11 = MOD_ERR_SYNTAX Someything funky was passed to us.
  • 13 = MOD_ERR_NOMOD Core is running in skeleton no moudles cannot be loaded
Note:
we dont wanna exit if a module fails just return fail status, so the caller can handle errors.

Definition at line 333 of file module.c.

References ABI_VERSION, Module::age, create_mod_temp(), dlink_add_tail(), dlink_create(), Module::file, Module::handle, Module::mi, MOD_ERR_API, MOD_ERR_EXISTS, MOD_ERR_IO, MOD_ERR_MEMORY, MOD_ERR_OK, ModuleInfo::mod_register, module_find(), module_free(), modules, Module::name, throwModErr, and Module::type.

Referenced by load_modules(), load_protocol(), and run_mod_que().

void purge_modules (  ) 
int run_mod_que ( int   ) 

Variable Documentation

char mod_err_msg[512]

Definition at line 70 of file module.h.

Referenced by GetModErr().

dlink_list moduleque

Definition at line 252 of file module.h.

Referenced by addto_mod_que(), find_mod_que(), and run_mod_que().

dlink_list modules

Module Linked List's

Definition at line 251 of file module.h.

Referenced by module_find(), module_free(), module_open(), and purge_modules().

int nomodules

Definition at line 131 of file module.h.

Referenced by main().

Generated on Mon Jul 19 21:53:05 2010 for Omega Security Services by  doxygen 1.6.3