add event plugin type

This commit is contained in:
Ron Pedde 2006-05-04 06:20:26 +00:00
parent 0c407a7eca
commit 4440ac7013
9 changed files with 298 additions and 21 deletions

View File

@ -16,6 +16,7 @@
#include "win32.h"
#include "err.h"
#include "os-win32.h"
#include "plugin.h"
#include "w32-eventlog.h"
#include "w32-service.h"
@ -127,6 +128,7 @@ int os_closesyslog(void) {
* @return TRUE on success, FALSE otherwise
*/
int os_syslog(int level, char *msg) {
plugin_event_dispatch(PLUGIN_EVENT_LOG, level, msg, (int)strlen(msg)+1);
return elog_message(level, msg);
}

View File

@ -49,7 +49,8 @@ typedef struct tag_pluginentry {
int type;
char *versionstring;
regex_t regex;
void *functions;
PLUGIN_OUTPUT_FN *output_fns;
PLUGIN_EVENT_FN *event_fns;
PLUGIN_REND_INFO *rend_info;
struct tag_pluginentry *next;
} PLUGIN_ENTRY;
@ -233,13 +234,14 @@ int plugin_load(char **pe, char *path) {
ppi->type = pinfo->type;
ppi->versionstring = pinfo->server;
if(ppi->type == PLUGIN_OUTPUT) {
if(ppi->type & PLUGIN_OUTPUT) {
/* build the regex */
if(regcomp(&ppi->regex,pinfo->url,REG_EXTENDED | REG_NOSUB)) {
DPRINTF(E_LOG,L_PLUG,"Bad regex in %s: %s\n",path,pinfo->url);
}
}
ppi->functions = pinfo->handler_functions;
ppi->output_fns = pinfo->output_fns;
ppi->event_fns = pinfo->event_fns;
ppi->rend_info = pinfo->rend_info;
DPRINTF(E_INF,L_PLUG,"Loaded plugin %s (%s)\n",path,ppi->versionstring);
@ -271,7 +273,7 @@ int plugin_url_candispatch(WS_CONNINFO *pwsc) {
_plugin_readlock();
ppi = _plugin_list.next;
while(ppi) {
if(ppi->type == PLUGIN_OUTPUT) {
if(ppi->type & PLUGIN_OUTPUT) {
if(!regexec(&ppi->regex,pwsc->uri,0,NULL,0)) {
/* we have a winner */
_plugin_unlock();
@ -298,14 +300,14 @@ void plugin_url_handle(WS_CONNINFO *pwsc) {
_plugin_readlock();
ppi = _plugin_list.next;
while(ppi) {
if(ppi->type == PLUGIN_OUTPUT) {
if(ppi->type & PLUGIN_OUTPUT) {
if(!regexec(&ppi->regex,pwsc->uri,0,NULL,0)) {
/* we have a winner */
DPRINTF(E_DBG,L_PLUG,"Dispatching %s to %s\n", pwsc->uri,
ppi->versionstring);
/* so functions must be a tag_plugin_output_fn */
disp_fn=(((PLUGIN_OUTPUT_FN*)ppi->functions)->handler);
disp_fn=(ppi->output_fns)->handler;
disp_fn(pwsc);
_plugin_unlock();
return;
@ -382,14 +384,14 @@ int plugin_auth_handle(WS_CONNINFO *pwsc, char *username, char *pw) {
_plugin_readlock();
ppi = _plugin_list.next;
while(ppi) {
if(ppi->type == PLUGIN_OUTPUT) {
if(ppi->type & PLUGIN_OUTPUT) {
if(!regexec(&ppi->regex,pwsc->uri,0,NULL,0)) {
/* we have a winner */
DPRINTF(E_DBG,L_PLUG,"Dispatching %s to %s\n", pwsc->uri,
ppi->versionstring);
/* so functions must be a tag_plugin_output_fn */
auth_fn=(((PLUGIN_OUTPUT_FN*)ppi->functions)->auth);
auth_fn=(ppi->output_fns)->auth;
if(auth_fn) {
result=auth_fn(pwsc,username,pw);
_plugin_unlock();
@ -409,6 +411,30 @@ int plugin_auth_handle(WS_CONNINFO *pwsc, char *username, char *pw) {
return FALSE;
}
/**
* send an event to a plugin... this can be a connection, disconnection, etc.
*/
void plugin_event_dispatch(int event_id, int intval, void *vp, int len) {
PLUGIN_ENTRY *ppi;
_plugin_readlock();
ppi = _plugin_list.next;
while(ppi) {
if(ppi->type & PLUGIN_EVENT) {
DPRINTF(E_DBG,L_PLUG,"Dispatching event %d to %s\n",
event_id,ppi->versionstring);
if((ppi->event_fns) && (ppi->event_fns->handler)) {
ppi->event_fns->handler(event_id, intval, vp, len);
}
}
ppi=ppi->next;
}
_plugin_unlock();
}
/* plugin wrappers for utility functions & stuff
*

View File

@ -24,6 +24,7 @@
#include "webserver.h"
#include "xml-rpc.h"
#include "db-generic.h"
extern int plugin_init(void);
extern int plugin_load(char **pe, char *path);
@ -34,18 +35,29 @@ extern int plugin_url_candispatch(WS_CONNINFO *pwsc);
extern void plugin_url_handle(WS_CONNINFO *pwsc);
extern int plugin_auth_handle(WS_CONNINFO *pwsc, char *username, char *pw);
extern int plugin_rend_register(char *name, int port, char *iface);
extern void plugin_event_dispatch(int event_id, int intval, void *vp, int len);
#define PLUGIN_E_SUCCESS 0
#define PLUGIN_E_NOLOAD 1
#define PLUGIN_E_BADFUNCS 2
#define PLUGIN_OUTPUT 0
#define PLUGIN_SCANNER 1
#define PLUGIN_DATABASE 2
#define PLUGIN_OTHER 3
#define PLUGIN_OUTPUT 1
#define PLUGIN_SCANNER 2
#define PLUGIN_DATABASE 4
#define PLUGIN_EVENT 8
#define PLUGIN_VERSION 1
#define PLUGIN_EVENT_LOG 0
#define PLUGIN_EVENT_FULLSCAN_START 1
#define PLUGIN_EVENT_FULLSCAN_END 2
#define PLUGIN_EVENT_STARTING 3
#define PLUGIN_EVENT_SHUTDOWN 4
#define PLUGIN_EVENT_STARTSTREAM 5
#define PLUGIN_EVENT_ABORTSTREAM 6
#define PLUGIN_EVENT_ENDSTREAM 7
#define PLUGIN_VERSION 1
typedef struct tag_plugin_output_fn {
@ -53,6 +65,10 @@ typedef struct tag_plugin_output_fn {
int(*auth)(WS_CONNINFO *pwsc, char *username, char *pw);
} PLUGIN_OUTPUT_FN;
typedef struct tag_plugin_event_fn {
void(*handler)(int event_id, int intval, void *vp, int len);
} PLUGIN_EVENT_FN;
/* version 1 plugin info */
typedef struct tag_plugin_rend_info {
char *type;
@ -64,7 +80,8 @@ typedef struct tag_plugin_info {
int type;
char *server;
char *url; /* for output plugins */
void *handler_functions;
PLUGIN_OUTPUT_FN *output_fns;
PLUGIN_EVENT_FN *event_fns;
void *pi; /* exported functions */
PLUGIN_REND_INFO *rend_info;
} PLUGIN_INFO;

View File

@ -5,13 +5,21 @@
#ifndef _MTD_PLUGINS_H_
#define _MTD_PLUGINS_H_
#define PLUGIN_OUTPUT 0
#define PLUGIN_SCANNER 1
#define PLUGIN_DATABASE 2
#define PLUGIN_OTHER 3
#define PLUGIN_OUTPUT 1
#define PLUGIN_SCANNER 2
#define PLUGIN_DATABASE 4
#define PLUGIN_EVENT 8
#define PLUGIN_VERSION 1
#define PLUGIN_EVENT_LOG 0
#define PLUGIN_EVENT_FULLSCAN_START 1
#define PLUGIN_EVENT_FULLSCAN_END 2
#define PLUGIN_EVENT_STARTING 3
#define PLUGIN_EVENT_SHUTDOWN 4
#define PLUGIN_EVENT_STARTSTREAM 5
#define PLUGIN_EVENT_ABORTSTREAM 6
#define PLUGIN_EVENT_ENDSTREAM 7
typedef void* PARSETREE;
@ -23,6 +31,10 @@ typedef struct tag_plugin_output_fn {
int(*auth)(WS_CONNINFO *pwsc, char *username, char *pw);
} PLUGIN_OUTPUT_FN;
typedef struct tag_plugin_event_fn {
void(*handler)(int event_id, int intval, void *vp, int len);
} PLUGIN_EVENT_FN;
typedef struct tag_plugin_rend_info {
char *type;
char *txt;
@ -33,8 +45,9 @@ typedef struct tag_plugin_info {
int type;
char *server;
char *url; /* regex of namespace to handle if OUTPUT type */
void *handler_functions;
void *fn; /* input functions*/
PLUGIN_OUTPUT_FN *output_fns;
PLUGIN_EVENT_FN *event_fns;
void *pi; /* exported functions */
PLUGIN_REND_INFO *rend_info;
} PLUGIN_INFO;

View File

@ -8,7 +8,7 @@
#define RSP_VERSION "1.0"
extern PLUGIN_INFO _pi;
#define infn ((PLUGIN_INPUT_FN *)(_pi.fn))
#define infn ((PLUGIN_INPUT_FN *)(_pi.pi))
#ifndef TRUE
# define TRUE 1

65
src/plugins/w32-event.c Normal file
View File

@ -0,0 +1,65 @@
/*
* $Id: $
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "compat.h"
#include "mtd-plugins.h"
/* Forwards */
PLUGIN_INFO *plugin_info(void);
void plugin_handler(int, int, void *, int);
#define PIPE_BUFFER_SIZE 4096
/* Globals */
PLUGIN_EVENT_FN _pefn = { plugin_handler };
PLUGIN_INFO _pi = {
PLUGIN_VERSION,
PLUGIN_EVENT,
"w32-event/1.0",
NULL,
NULL,
&_pefn,
NULL,
NULL
};
typedef struct tag_plugin_msg {
int size;
int event_id;
int intval;
char vp[1];
} PLUGIN_MSG;
#define infn ((PLUGIN_INPUT_FN *)(_pi.pi))
PLUGIN_INFO *plugin_info(void) {
return &_pi;
}
void plugin_handler(int event_id, int intval, void *vp, int len) {
int total_len = 3 * sizeof(int) + len + 1;
PLUGIN_MSG *pmsg;
pmsg = (PLUGIN_MSG*)malloc(total_len);
if(!pmsg) {
infn->log(E_LOG,"Malloc error in w32-event.c/plugin_handler\n");
return;
}
memset(pmsg,0,total_len);
pmsg->size = total_len;
pmsg->event_id = event_id;
pmsg->intval = intval;
memcpy(&pmsg->vp,vp,len);
CallNamedPipe("\\\\.\\pipe\\firefly",NULL,0,pmsg,total_len,NULL,NMPWAIT_NOWAIT);
free(pmsg);
return;
}

View File

@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FireflyConfig", "FireflyCon
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "w32-event", "w32-event.vcproj", "{E60F90F1-A1E5-49D8-A565-B990CA4BA860}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@ -29,6 +33,10 @@ Global
{842826B0-521A-4296-B2B4-5746BF1C91C2}.Debug.Build.0 = Debug|.NET
{842826B0-521A-4296-B2B4-5746BF1C91C2}.Release.ActiveCfg = Release|.NET
{842826B0-521A-4296-B2B4-5746BF1C91C2}.Release.Build.0 = Release|.NET
{E60F90F1-A1E5-49D8-A565-B990CA4BA860}.Debug.ActiveCfg = Debug|Win32
{E60F90F1-A1E5-49D8-A565-B990CA4BA860}.Debug.Build.0 = Debug|Win32
{E60F90F1-A1E5-49D8-A565-B990CA4BA860}.Release.ActiveCfg = Release|Win32
{E60F90F1-A1E5-49D8-A565-B990CA4BA860}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

4
win32/w32-event.def Normal file
View File

@ -0,0 +1,4 @@
LIBRARY w32-event
EXPORTS
plugin_info

142
win32/w32-event.vcproj Normal file
View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="w32-event"
ProjectGUID="{E60F90F1-A1E5-49D8-A565-B990CA4BA860}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\win32;.;..\src"
PreprocessorDefinitions="HAVE_CONFIG_H;_WIN32"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/w32-event.dll"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/w32-event.pdb"
SubSystem="2"
ImportLibrary="$(OutDir)/w32-event.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\win32;.;..\src"
PreprocessorDefinitions="HAVE_CONFIG_H;_WIN32"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/w32-event.dll"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
ImportLibrary="$(OutDir)/w32-event.lib"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath="..\src\plugins\w32-event.c">
</File>
<File
RelativePath=".\w32-event.def">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath="..\src\plugins\mtd-plugins.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>