syslog-ng source
plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2012 Balabit
3  * Copyright (c) 1998-2012 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 #ifndef PLUGIN_H_INCLUDED
26 #define PLUGIN_H_INCLUDED
27 
28 #include "cfg-parser.h"
29 
30 typedef struct _PluginFailureInfo
31 {
32  gconstpointer aux_data;
34 
35 typedef struct _PluginBase
36 {
37  /* NOTE: the start of this structure must match the Plugin struct,
38  thus it has to be changed together with Plugin */
39  gint type;
40  gchar *name;
42 } PluginBase;
43 
44 typedef struct _PluginCandidate
45 {
47  gchar *module_name;
49 
50 /* A plugin actually registered by a module. See PluginCandidate in
51  * the implementation module, which encapsulates a demand-loadable
52  * plugin, not yet loaded.
53  *
54  * A plugin serves as the factory for an extension point (=plugin). In
55  * contrast with the "module" which is the shared object itself which
56  * registers plugins. Each module can register a number of plugins,
57  * not just one. */
58 typedef struct _Plugin Plugin;
59 struct _Plugin
60 {
61  /* NOTE: the first three fields must match PluginCandidate struct defined
62  in the plugin.c module, please modify them both at the same time! It
63  is not referenced as "super" as it would make the using sites having to
64  use ugly braces when initializing the structure. */
65 
66  gint type;
67  const gchar *name;
70  gpointer (*construct)(Plugin *self);
71  void (*free_fn)(Plugin *s);
72 };
73 
74 gpointer plugin_construct(Plugin *self);
75 gpointer plugin_construct_from_config(Plugin *self, CfgLexer *lexer, gpointer arg);
76 
77 typedef struct _ModuleInfo ModuleInfo;
79 {
80  /* name of the module to be loaded as */
81  const gchar *canonical_name;
82  /* version number if any */
83  const gchar *version;
84  /* copyright information, homepage and other important information about the module */
85  const gchar *description;
86  /* git sha that identifies the core revision that this was compiled for */
87  const gchar *core_revision;
88  Plugin *plugins;
90  /* the higher the better */
91 };
92 
94 {
95  GList *plugins;
97  gchar *module_path;
98 };
99 
100 /* instantiate a new plugin */
101 Plugin *plugin_find(PluginContext *context, gint plugin_type, const gchar *plugin_name);
102 
103 /* plugin side API */
104 PluginCandidate *plugin_candidate_new(gint plugin_type, const gchar *name, const gchar *module_name);
106 
107 void plugin_register(PluginContext *context, Plugin *p, gint number);
108 gboolean plugin_load_module(PluginContext *context, const gchar *module_name, CfgArgs *args);
109 gboolean plugin_is_plugin_available(PluginContext *context, gint plugin_type, const gchar *plugin_name);
110 gboolean plugin_is_module_available(PluginContext *context, const gchar *module_name);
111 
112 void plugin_list_modules(FILE *out, gboolean verbose);
113 
114 gboolean plugin_has_discovery_run(PluginContext *context);
115 void plugin_discover_candidate_modules(PluginContext *context);
116 
117 void plugin_context_copy_candidates(PluginContext *context, PluginContext *src_context);
118 void plugin_context_set_module_path(PluginContext *context, const gchar *module_path);
119 void plugin_context_init_instance(PluginContext *context);
120 void plugin_context_deinit_instance(PluginContext *context);
121 
122 #endif
const gchar * name
Definition: debugger.c:265
gboolean plugin_is_module_available(PluginContext *context, const gchar *module_name)
Definition: plugin.c:416
gpointer plugin_construct(Plugin *self)
Definition: plugin.c:75
PluginCandidate * plugin_candidate_new(gint plugin_type, const gchar *name, const gchar *module_name)
Definition: plugin.c:53
void plugin_discover_candidate_modules(PluginContext *context)
Definition: plugin.c:462
void plugin_context_copy_candidates(PluginContext *context, PluginContext *src_context)
Definition: plugin.c:552
void plugin_register(PluginContext *context, Plugin *p, gint number)
Definition: plugin.c:298
void plugin_context_set_module_path(PluginContext *context, const gchar *module_path)
Definition: plugin.c:567
gboolean plugin_is_plugin_available(PluginContext *context, gint plugin_type, const gchar *plugin_name)
Definition: plugin.c:429
void plugin_list_modules(FILE *out, gboolean verbose)
Definition: plugin.c:592
gboolean plugin_load_module(PluginContext *context, const gchar *module_name, CfgArgs *args)
Definition: plugin.c:357
Plugin * plugin_find(PluginContext *context, gint plugin_type, const gchar *plugin_name)
Definition: plugin.c:320
void plugin_candidate_free(PluginCandidate *self)
Definition: plugin.c:66
void plugin_context_deinit_instance(PluginContext *context)
Definition: plugin.c:581
gpointer plugin_construct_from_config(Plugin *self, CfgLexer *lexer, gpointer arg)
Definition: plugin.c:107
gboolean plugin_has_discovery_run(PluginContext *context)
Definition: plugin.c:456
void plugin_context_init_instance(PluginContext *context)
Definition: plugin.c:574
Definition: cfg-parser.h:34
Definition: plugin.h:36
PluginFailureInfo failure_info
Definition: plugin.h:41
gchar * name
Definition: plugin.h:40
gint type
Definition: plugin.h:39
Definition: plugin.h:45
PluginBase super
Definition: plugin.h:46
gchar * module_name
Definition: plugin.h:47
Definition: plugin.h:31
gconstpointer aux_data
Definition: plugin.h:32
Definition: plugin.h:79
const gchar * version
Definition: plugin.h:83
const gchar * canonical_name
Definition: plugin.h:81
const gchar * description
Definition: plugin.h:85
gint plugins_len
Definition: plugin.h:89
Plugin * plugins
Definition: plugin.h:88
const gchar * core_revision
Definition: plugin.h:87
Definition: plugin.h:94
GList * plugins
Definition: plugin.h:95
GList * candidate_plugins
Definition: plugin.h:96
gchar * module_path
Definition: plugin.h:97
Definition: plugin.h:60
gint type
Definition: plugin.h:66
gpointer(* construct)(Plugin *self)
Definition: plugin.h:70
PluginFailureInfo failure_info
Definition: plugin.h:68
const gchar * name
Definition: plugin.h:67
CfgParser * parser
Definition: plugin.h:69
void(* free_fn)(Plugin *s)
Definition: plugin.h:71