plugin API

This commit is contained in:
Thomas Ries 2008-01-30 18:49:47 +00:00
parent e7c6407a7a
commit af78b380d7
4 changed files with 72 additions and 63 deletions

View File

@ -208,14 +208,16 @@ int unload_plugins(void) {
for (cur=siproxd_plugins; cur->next != NULL; cur = cur->next) {last=cur;}
plugin_end=cur->plugin_end;
DEBUGC(DBCLASS_PLUGIN, "unload_plugins: '%s' unloading ptr=%p",
cur->name, cur);
sts=(*plugin_end)(cur);
DEBUGC(DBCLASS_PLUGIN, "unload_plugins: '%s' unloaded with %s, ptr=%p",
cur->name, (sts==STS_SUCCESS)?"success":"failure", cur);
DEBUGC(DBCLASS_PLUGIN, "unload_plugins: status=%s",
(sts==STS_SUCCESS)?"success":"failure");
/* dlclose */
sts = lt_dlclose(cur->dlhandle);
if (sts != 0) {
ERROR("lt_dlclose() failed for plugin %s", cur->name);
ERROR("lt_dlclose() failed, ptr=%p", cur);
}
/* NOTE: cur->name and cur->desc must be cleaned up by the plugin! */

View File

@ -38,7 +38,7 @@ static char const ident[]="$Id$";
extern struct siproxd_config configuration;
/* prototypes used locally only */
static int parse_config (FILE *configfile);
static int parse_config (FILE *configfile, cfgopts_t cfgopts[]);
/* try to open (whichever is found first):
@ -52,7 +52,7 @@ static int parse_config (FILE *configfile);
* STS_SUCCESS on success
* STS_FAILURE on error
*/
int read_config(char *name, int search) {
int read_config(char *name, int search, cfgopts_t cfgopts[]) {
int sts;
FILE *configfile=NULL;
int i;
@ -97,7 +97,7 @@ int read_config(char *name, int search) {
return STS_FAILURE;
}
sts = parse_config(configfile);
sts = parse_config(configfile, cfgopts);
fclose(configfile);
/*
@ -130,7 +130,7 @@ int read_config(char *name, int search) {
* STS_SUCCESS on success
* STS_FAILURE on error
*/
static int parse_config (FILE *configfile) {
static int parse_config (FILE *configfile, cfgopts_t configoptions[]) {
char buff[1024];
char *ptr;
int i;
@ -139,58 +139,6 @@ static int parse_config (FILE *configfile) {
size_t len;
char *tmpptr;
struct cfgopts {
char *keyword;
enum type {TYP_INT4, TYP_STRING, TYP_FLOAT, TYP_STRINGA} type;
void *dest;
} configoptions[] = {
{ "debug_level", TYP_INT4, &configuration.debuglevel },
{ "debug_port", TYP_INT4, &configuration.debugport },
{ "sip_listen_port", TYP_INT4, &configuration.sip_listen_port },
{ "daemonize", TYP_INT4, &configuration.daemonize },
{ "silence_log", TYP_INT4, &configuration.silence_log },
{ "if_inbound", TYP_STRING, &configuration.inbound_if },
{ "if_outbound", TYP_STRING, &configuration.outbound_if },
{ "host_outbound", TYP_STRING, &configuration.outbound_host },
{ "rtp_port_low", TYP_INT4, &configuration.rtp_port_low },
{ "rtp_port_high", TYP_INT4, &configuration.rtp_port_high },
{ "rtp_timeout", TYP_INT4, &configuration.rtp_timeout },
{ "rtp_proxy_enable", TYP_INT4, &configuration.rtp_proxy_enable },
{ "rtp_dscp", TYP_INT4, &configuration.rtp_dscp },
{ "rtp_input_dejitter", TYP_INT4, &configuration.rtp_input_dejitter },
{ "rtp_output_dejitter", TYP_INT4, &configuration.rtp_output_dejitter },
{ "user", TYP_STRING, &configuration.user },
{ "chrootjail", TYP_STRING, &configuration.chrootjail },
{ "hosts_allow_reg", TYP_STRING, &configuration.hosts_allow_reg },
{ "hosts_allow_sip", TYP_STRING, &configuration.hosts_allow_sip },
{ "hosts_deny_sip", TYP_STRING, &configuration.hosts_deny_sip },
{ "hosts_deny_sip", TYP_STRING, &configuration.hosts_deny_sip },
{ "proxy_auth_realm", TYP_STRING, &configuration.proxy_auth_realm },
{ "proxy_auth_passwd", TYP_STRING, &configuration.proxy_auth_passwd },
{ "proxy_auth_pwfile", TYP_STRING, &configuration.proxy_auth_pwfile },
{ "mask_host", TYP_STRINGA,&configuration.mask_host },
{ "masked_host", TYP_STRINGA,&configuration.masked_host },
{ "outbound_proxy_host", TYP_STRING, &configuration.outbound_proxy_host },
{ "outbound_proxy_port", TYP_INT4, &configuration.outbound_proxy_port },
{ "outbound_domain_name",TYP_STRINGA,&configuration.outbound_proxy_domain_name },
{ "outbound_domain_host",TYP_STRINGA,&configuration.outbound_proxy_domain_host },
{ "outbound_domain_port",TYP_STRINGA,&configuration.outbound_proxy_domain_port },
{ "registration_file", TYP_STRING, &configuration.registrationfile },
{ "log_calls", TYP_INT4, &configuration.log_calls },
{ "pid_file", TYP_STRING, &configuration.pid_file },
{ "default_expires", TYP_INT4, &configuration.default_expires },
{ "autosave_registrations",TYP_INT4, &configuration.autosave_registrations },
{ "pi_shortdial_akey", TYP_STRING, &configuration.pi_shortdial_akey },
{ "pi_shortdial_entry", TYP_STRINGA,&configuration.pi_shortdial_entry },
{ "ua_string", TYP_STRING, &configuration.ua_string },
{ "use_rport", TYP_INT4, &configuration.use_rport },
{ "obscure_loops", TYP_INT4, &configuration.obscure_loops },
{ "plugin_dir", TYP_STRING, &configuration.plugin_dir },
{ "load_plugin", TYP_STRINGA,&configuration.load_plugin },
{0, 0, 0}
};
while (fgets(buff,sizeof(buff),configfile) != NULL) {
/* life insurance */
buff[sizeof(buff)-1]='\0';

View File

@ -44,6 +44,53 @@ static char const ident[]="$Id$";
/* configuration storage */
struct siproxd_config configuration;
/* instructions for config parser */
cfgopts_t main_cfg_opts[] = {
{ "debug_level", TYP_INT4, &configuration.debuglevel },
{ "debug_port", TYP_INT4, &configuration.debugport },
{ "sip_listen_port", TYP_INT4, &configuration.sip_listen_port },
{ "daemonize", TYP_INT4, &configuration.daemonize },
{ "silence_log", TYP_INT4, &configuration.silence_log },
{ "if_inbound", TYP_STRING, &configuration.inbound_if },
{ "if_outbound", TYP_STRING, &configuration.outbound_if },
{ "host_outbound", TYP_STRING, &configuration.outbound_host },
{ "rtp_port_low", TYP_INT4, &configuration.rtp_port_low },
{ "rtp_port_high", TYP_INT4, &configuration.rtp_port_high },
{ "rtp_timeout", TYP_INT4, &configuration.rtp_timeout },
{ "rtp_proxy_enable", TYP_INT4, &configuration.rtp_proxy_enable },
{ "rtp_dscp", TYP_INT4, &configuration.rtp_dscp },
{ "rtp_input_dejitter", TYP_INT4, &configuration.rtp_input_dejitter },
{ "rtp_output_dejitter", TYP_INT4, &configuration.rtp_output_dejitter },
{ "user", TYP_STRING, &configuration.user },
{ "chrootjail", TYP_STRING, &configuration.chrootjail },
{ "hosts_allow_reg", TYP_STRING, &configuration.hosts_allow_reg },
{ "hosts_allow_sip", TYP_STRING, &configuration.hosts_allow_sip },
{ "hosts_deny_sip", TYP_STRING, &configuration.hosts_deny_sip },
{ "hosts_deny_sip", TYP_STRING, &configuration.hosts_deny_sip },
{ "proxy_auth_realm", TYP_STRING, &configuration.proxy_auth_realm },
{ "proxy_auth_passwd", TYP_STRING, &configuration.proxy_auth_passwd },
{ "proxy_auth_pwfile", TYP_STRING, &configuration.proxy_auth_pwfile },
{ "mask_host", TYP_STRINGA,&configuration.mask_host },
{ "masked_host", TYP_STRINGA,&configuration.masked_host },
{ "outbound_proxy_host", TYP_STRING, &configuration.outbound_proxy_host },
{ "outbound_proxy_port", TYP_INT4, &configuration.outbound_proxy_port },
{ "outbound_domain_name",TYP_STRINGA,&configuration.outbound_proxy_domain_name },
{ "outbound_domain_host",TYP_STRINGA,&configuration.outbound_proxy_domain_host },
{ "outbound_domain_port",TYP_STRINGA,&configuration.outbound_proxy_domain_port },
{ "registration_file", TYP_STRING, &configuration.registrationfile },
{ "log_calls", TYP_INT4, &configuration.log_calls },
{ "pid_file", TYP_STRING, &configuration.pid_file },
{ "default_expires", TYP_INT4, &configuration.default_expires },
{ "autosave_registrations",TYP_INT4, &configuration.autosave_registrations },
{ "pi_shortdial_akey", TYP_STRING, &configuration.pi_shortdial_akey },
{ "pi_shortdial_entry", TYP_STRINGA,&configuration.pi_shortdial_entry },
{ "ua_string", TYP_STRING, &configuration.ua_string },
{ "use_rport", TYP_INT4, &configuration.use_rport },
{ "obscure_loops", TYP_INT4, &configuration.obscure_loops },
{ "plugin_dir", TYP_STRING, &configuration.plugin_dir },
{ "load_plugin", TYP_STRINGA,&configuration.load_plugin },
{0, 0, 0}
};
/* Global File instance on pw file */
FILE *siproxd_passwordfile;
@ -185,7 +232,9 @@ int main (int argc, char *argv[])
INFO(PACKAGE"-"VERSION"-"BUILDSTR" "UNAME" starting up");
/* read the config file */
if (read_config(configfile, config_search) == STS_FAILURE) exit(1);
if (read_config(configfile, config_search, main_cfg_opts) == STS_FAILURE) {
exit(1);
}
/* if a debug level > 0 has been given on the commandline use its
value and not what is in the config file */

View File

@ -43,6 +43,7 @@ struct urlmap_s {
*/
/*
* Array of strings - used within configuration store
*/
@ -53,7 +54,7 @@ typedef struct {
} stringa_t;
/*
* configuration option table
* global configuration option table
*/
struct siproxd_config {
unsigned int debuglevel;
@ -100,6 +101,15 @@ struct siproxd_config {
stringa_t load_plugin;
};
/*
* control structure for config file parser
*/
typedef struct {
char *keyword;
enum type {TYP_INT4, TYP_STRING, TYP_FLOAT, TYP_STRINGA} type;
void *dest;
} cfgopts_t;
/*
* SIP ticket
*/
@ -142,7 +152,7 @@ int sipsock_listen(void); /*X*/
int sipsock_wait(void);
int sipsock_read(void *buf, size_t bufsize,
struct sockaddr_in *from, int *protocol);
int sipsock_send(struct in_addr addr, int port, int protocol, /*X*/
int sipsock_send(struct in_addr addr, int port, int protocol, /*X*/
char *buffer, size_t size);
int sockbind(struct in_addr ipaddr, int localport, int errflg);
@ -199,7 +209,7 @@ int sip_fixup_asterisk(char *buff, int *buflen); /*X*/
int sip_obscure_callid(sip_ticket_t *ticket); /*X*/
/* readconf.c */
int read_config(char *name, int search); /*X*/
int read_config(char *name, int search, cfgopts_t cfgopts[]); /*X*/
int make_default_config(void); /*X*/
/* rtpproxy.c */