pass functions to plugins through struct, rather than relying on auto-exported functions from executable

This commit is contained in:
Ron Pedde 2006-04-23 04:42:18 +00:00
parent c2c4bb1542
commit e2fd480c78
3 changed files with 136 additions and 41 deletions

View File

@ -68,6 +68,65 @@ void _plugin_writelock(void);
void _plugin_unlock(void);
int _plugin_error(char **pe, int error, ...);
/* Helpers */
XMLSTRUCT *pi_xml_init(WS_CONNINFO *pwsc, int emit_header);
void pi_xml_push(XMLSTRUCT *pxml, char *term);
void pi_xml_pop(XMLSTRUCT *pxml);
void pi_xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...);
void pi_xml_deinit(XMLSTRUCT *pxml);
/* webserver helpers */
char *pi_ws_uri(WS_CONNINFO *pwsc);
void pi_ws_close(WS_CONNINFO *pwsc);
int pi_ws_returnerror(WS_CONNINFO *pwsc, int error, char *description);
char *pi_ws_getvar(WS_CONNINFO *pwsc, char *var);
/* misc helpers */
char *pi_server_ver(void);
int pi_server_name(char *, int *);
void pi_log(int, char *, ...);
/* db helpers */
int pi_db_count(void);
int pi_db_enum_start(char **pe, DBQUERYINFO *pinfo);
int pi_db_enum_fetch_row(char **pe, char ***row, DBQUERYINFO *pinfo);
int pi_db_enum_end(char **pe);
void pi_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id);
/* smart parser helpers */
PARSETREE pi_sp_init(void);
int pi_sp_parse(PARSETREE tree, char *term);
int pi_sp_dispose(PARSETREE tree);
char *pi_sp_get_error(PARSETREE tree);
PLUGIN_INPUT_FN pi = {
pi_xml_init,
pi_xml_push,
pi_xml_pop,
pi_xml_output,
pi_xml_deinit,
pi_ws_uri,
pi_ws_close,
pi_ws_returnerror,
pi_ws_getvar,
pi_server_ver,
pi_server_name,
pi_log,
pi_db_count,
pi_db_enum_start,
pi_db_enum_fetch_row,
pi_db_enum_end,
pi_stream,
pi_sp_init,
pi_sp_parse,
pi_sp_dispose,
pi_sp_get_error
};
/**
* initialize stuff for plugins
*
@ -191,6 +250,7 @@ int plugin_load(char **pe, char *path) {
ppi->functions = pinfo->handler_functions;
DPRINTF(E_INF,L_PLUG,"Loaded plugin %s (%s)\n",path,ppi->versionstring);
pinfo->pi = (void*)π
_plugin_writelock();
if(!_plugin_initialized) {
@ -355,8 +415,8 @@ void pi_ws_close(WS_CONNINFO *pwsc) {
pwsc->close=1;
}
void pi_ws_returnerror(WS_CONNINFO *pwsc, int error, char *description) {
ws_returnerror(pwsc,error,description);
int pi_ws_returnerror(WS_CONNINFO *pwsc, int error, char *description) {
return ws_returnerror(pwsc,error,description);
}
char *pi_ws_getvar(WS_CONNINFO *pwsc, char *var) {

View File

@ -23,6 +23,7 @@
#define _PLUGIN_H_
#include "webserver.h"
#include "xml-rpc.h"
extern int plugin_init(void);
extern int plugin_load(char **pe, char *path);
@ -57,7 +58,39 @@ typedef struct tag_plugin_info {
char *server;
char *url; /* for output plugins */
void *handler_functions;
void *pi; /* exported functions */
} PLUGIN_INFO;
/* version 1 plugin imports */
typedef struct tag_plugin_input_fn {
/* xml helpers */
XMLSTRUCT* (*xml_init)(WS_CONNINFO *, int);
void (*xml_push)(XMLSTRUCT *, char *);
void (*xml_pop)(XMLSTRUCT *);
void (*xml_output)(XMLSTRUCT *, char *, char *, ...);
void (*xml_deinit)(XMLSTRUCT *);
/* webserver helpers */
char* (*ws_uri)(WS_CONNINFO *);
void (*ws_close)(WS_CONNINFO *);
int (*ws_returnerror)(WS_CONNINFO *, int, char *);
char* (*ws_getvar)(WS_CONNINFO *, char *);
/* misc helpers */
char* (*server_ver)(void);
int (*server_name)(char *, int *);
void (*log)(int, char *, ...);
int (*db_count)(void);
int (*db_enum_start)(char **, DBQUERYINFO *);
int (*db_enum_fetch_row)(char **, char ***, DBQUERYINFO *);
int (*db_enum_end)(char **);
void (*stream)(WS_CONNINFO *, DBQUERYINFO *, char *);
PARSETREE (*sp_init)(void);
int (*sp_parse)(PARSETREE tree, char *term);
int (*sp_dispose)(PARSETREE tree);
char* (*sp_get_error)(PARSETREE tree);
} PLUGIN_INPUT_FN;
#endif /* _PLUGIN_H_ */

View File

@ -12,8 +12,14 @@
#define PLUGIN_VERSION 1
struct tag_wsconninfo;
typedef struct tag_wsconninfo WS_CONNINFO;
typedef void* PARSETREE;
struct tag_ws_conninfo;
typedef struct tag_ws_conninfo WS_CONNINFO;
struct tag_xmlstruct;
typedef struct tag_xmlstruct XMLSTRUCT;
typedef struct tag_plugin_output_fn {
void (*handler)(WS_CONNINFO *pwsc);
@ -25,31 +31,10 @@ typedef struct tag_plugin_info {
char *server;
char *url; /* regex of namespace to handle if OUTPUT type */
void *handler_functions;
void *input_functions;
} PLUGIN_INFO;
/* these are the functions that must be exported by the plugin */
PLUGIN_INFO *plugin_info(void);
/* xml helpers for output plugins */
struct tag_xmlstruct;
typedef struct tag_xmlstruct XMLSTRUCT;
typedef void *PARSETREE;
extern XMLSTRUCT *pi_xml_init(WS_CONNINFO *pwsc, int emit_header);
extern void pi_xml_push(XMLSTRUCT *pxml, char *term);
extern void pi_xml_pop(XMLSTRUCT *pxml);
extern void pi_xml_output(XMLSTRUCT *pxml, char *section, char *fmt, ...);
extern void pi_xml_deinit(XMLSTRUCT *pxml);
/* webserver helpers for output plugins */
extern char *pi_ws_uri(WS_CONNINFO *pwsc);
extern void pi_ws_close(WS_CONNINFO *pwsc);
extern int pi_ws_returnerror(WS_CONNINFO *pwsc, int error, char *description);
extern char *pi_ws_getvar(WS_CONNINFO *pwsc, char *var);
/* misc helpers */
extern char *pi_server_ver(void);
extern int pi_server_name(char *, int *);
/* logging */
#define E_FATAL 0
@ -57,10 +42,6 @@ extern int pi_server_name(char *, int *);
#define E_INF 5
#define E_DBG 9
void pi_log(int level, char *fmt, ...);
/* db stuff */
typedef enum {
queryTypeItems,
@ -165,19 +146,40 @@ typedef struct tag_dbqueryinfo {
void *output_info;
} DBQUERYINFO;
typedef struct tag_plugin_input_fn {
/* xml helpers */
XMLSTRUCT* (*xml_init)(WS_CONNINFO *, int);
void (*xml_push)(XMLSTRUCT *, char *);
void (*xml_pop)(XMLSTRUCT *);
void (*xml_output)(XMLSTRUCT *, char *, char *, ...);
void (*xml_deinit)(XMLSTRUCT *);
/* db helpers */
extern int pi_db_count(void);
extern int pi_db_enum_start(char **pe, DBQUERYINFO *pinfo);
extern int pi_db_enum_fetch_row(char **pe, char ***row, DBQUERYINFO *pinfo);
extern int pi_db_enum_end(char **pe);
extern void pi_stream(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, char *id);
/* webserver helpers */
char* (*ws_uri)(WS_CONNINFO *);
void (*ws_close)(WS_CONNINFO *);
int (*ws_returnerror)(WS_CONNINFO *, int, char *);
char* (*ws_getvar)(WS_CONNINFO *, char *);
/* smart parser helpers */
extern PARSETREE pi_sp_init(void);
extern int pi_sp_parse(PARSETREE tree, char *term);
extern int pi_sp_dispose(PARSETREE tree);
extern char *pi_sp_get_error(PARSETREE tree);
/* misc helpers */
char* (*server_ver)(void);
int (*server_name)(char *, int *);
void (*log)(int, char *, ...);
int (*db_count)(void);
int (*db_enum_start)(char **, DBQUERYINFO *);
int (*db_enum_fetch_row)(char **, char ***, DBQUERYINFO *);
int (*db_enum_end)(char **);
void (*stream)(WS_CONNINFO *, DBQUERYINFO *, char *);
PARSETREE (*sp_init)(void);
int (*sp_parse)(PARSETREE tree, char *term);
int (*sp_dispose)(PARSETREE tree);
char* (*sp_get_error)(PARSETREE tree);
} PLUGIN_INPUT_FN;
/* these are the functions that must be exported by the plugin */
PLUGIN_INFO *plugin_info(void);
#endif /* _MTD_PLUGINS_H_ */