aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
m---------grecs0
-rw-r--r--include/wydawca/wydawca.h2
-rw-r--r--modules/Makefile.am2
-rw-r--r--modules/logstat/Makefile.am12
-rw-r--r--modules/logstat/mod_logstat.c74
-rw-r--r--src/config.c57
-rw-r--r--src/module.c40
8 files changed, 159 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac
index afe0bb5..6e8e6f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -174,6 +174,7 @@ AC_CONFIG_FILES([Makefile
174 include/wydawca/Makefile 174 include/wydawca/Makefile
175 src/Makefile 175 src/Makefile
176 modules/Makefile 176 modules/Makefile
177 modules/logstat/Makefile
177 modules/mailutils/Makefile 178 modules/mailutils/Makefile
178 etc/Makefile]) 179 etc/Makefile])
179 180
diff --git a/grecs b/grecs
Subproject 588bb9898edcc8b531980fcb180e4955d29ed40 Subproject 487e2cfa988d6c3a5232011ab83897ef23bdb88
diff --git a/include/wydawca/wydawca.h b/include/wydawca/wydawca.h
index 9b5c7df..3bda88c 100644
--- a/include/wydawca/wydawca.h
+++ b/include/wydawca/wydawca.h
@@ -17,7 +17,7 @@
17#define wy_s_cat2(a,b) a ## b 17#define wy_s_cat2(a,b) a ## b
18#define wy_s_cat3(a,b,c) a ## b ## c 18#define wy_s_cat3(a,b,c) a ## b ## c
19 19
20#define WY_EXPORT(module,name) wy_s_cat3(module,_LTX_,name) 20#define WY_EXPORT(module,name) wy_s_cat3(module,_LTX_wy_,name)
21#define wy_notify WY_EXPORT(WY_MODULE,notify) 21#define wy_notify WY_EXPORT(WY_MODULE,notify)
22#define wy_help WY_EXPORT(WY_MODULE,help) 22#define wy_help WY_EXPORT(WY_MODULE,help)
23#define wy_open WY_EXPORT(WY_MODULE,open) 23#define wy_open WY_EXPORT(WY_MODULE,open)
diff --git a/modules/Makefile.am b/modules/Makefile.am
index d430de8..537248e 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -1,4 +1,4 @@
1if COND_MAILUTILS 1if COND_MAILUTILS
2 MAILUTILS = mailutils 2 MAILUTILS = mailutils
3endif 3endif
4SUBDIRS = $(MAILUTILS) \ No newline at end of file 4SUBDIRS = logstat $(MAILUTILS) \ No newline at end of file
diff --git a/modules/logstat/Makefile.am b/modules/logstat/Makefile.am
new file mode 100644
index 0000000..2f7d752
--- /dev/null
+++ b/modules/logstat/Makefile.am
@@ -0,0 +1,12 @@
1moddir=@WYDAWCA_MODDIR@
2
3mod_LTLIBRARIES=mod_logstat.la
4
5mod_logstat_la_SOURCES = mod_logstat.c
6
7AM_LDFLAGS = -module -avoid-version -no-undefined
8AM_CPPFLAGS = \
9 -I$(top_srcdir)\
10 -I$(top_srcdir)/include\
11 -I$(top_builddir)/src\
12 @GRECS_INCLUDES@
diff --git a/modules/logstat/mod_logstat.c b/modules/logstat/mod_logstat.c
new file mode 100644
index 0000000..874b05f
--- /dev/null
+++ b/modules/logstat/mod_logstat.c
@@ -0,0 +1,74 @@
1#include <config.h>
2#include <stdlib.h>
3#include <syslog.h>
4#include <grecs.h>
5#include <wydawca/wydawca.h>
6#include <wydawca/cfg.h>
7
8#define WY_MODULE mod_logstat
9
10static int stat_mask;
11static struct grecs_list *log_msg;
12
13static struct grecs_keyword logstat_kw[] = {
14 { "statistics", N_("items"),
15 N_("Log these statistics items"),
16 grecs_type_string, GRECS_DFLT, &stat_mask, 0,
17 wy_cb_statistics },
18 { "message", N_("text"),
19 N_("Log additional message"),
20 grecs_type_string, GRECS_LIST|GRECS_AGGR, &log_msg, 0, NULL },
21 { NULL }
22};
23
24
25void *
26wy_config(grecs_node_t *node)
27{
28 grecs_tree_reduce(node, logstat_kw, 0);
29 if (grecs_tree_process(node->down, logstat_kw))
30 return NULL;
31 return &stat_mask;
32}
33
34void
35wy_notify(void *data, int ev, wy_triplet_t trp)
36{
37 struct grecs_list_entry *ep;
38 char *text;
39
40 if (ev != wy_ev_statistics)
41 return;
42
43 if (log_msg) {
44 for (ep = log_msg->head; ep; ep = ep->next) {
45 text = wy_expand_stats(ep->data);
46 wy_log(LOG_INFO, "%s", text);
47 free(text);
48 }
49 }
50}
51
52void
53wy_help(void)
54{
55 static struct grecs_keyword top[] = {
56 { "module-config", NULL,
57 "module configuration",
58 grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
59 logstat_kw },
60 { NULL }
61 };
62
63 printf("\n\n# Usage in notify-event statement:\n");
64 printf("notify-event {\n event statistics;\n module logstat;");
65 grecs_print_statement_array(top, 1, 1, stdout);
66 printf("}\n");
67}
68
69wd()
70{
71 volatile int _st=0;
72 while (!_st)
73 _st=_st;
74}
diff --git a/src/config.c b/src/config.c
index eef4ee1..f5860d4 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1004,7 +1004,7 @@ static struct grecs_keyword spool_kw[] = {
1004 NULL, offsetof(struct spool, archive), 1004 NULL, offsetof(struct spool, archive),
1005 cb_archive, NULL, archive_kw }, 1005 cb_archive, NULL, archive_kw },
1006 { "notify-event", NULL, N_("Configure notification"), 1006 { "notify-event", NULL, N_("Configure notification"),
1007 grecs_type_section, GRECS_DFLT, 1007 grecs_type_section, GRECS_MULT,
1008 NULL, offsetof(struct spool, notification), 1008 NULL, offsetof(struct spool, notification),
1009 cb_notify_event, NULL, notify_event_kw }, 1009 cb_notify_event, NULL, notify_event_kw },
1010 { "check-script", NULL, N_("A /bin/sh script to verify the tarball"), 1010 { "check-script", NULL, N_("A /bin/sh script to verify the tarball"),
@@ -1197,6 +1197,48 @@ cb_locking(enum grecs_callback_command cmd, grecs_node_t *node,
1197} 1197}
1198 1198
1199static int 1199static int
1200cb_load_path(enum grecs_callback_command cmd, grecs_node_t *node,
1201 void *varptr, void *cb_data)
1202{
1203 struct grecs_list **lpp = varptr, *lp;
1204 grecs_locus_t *locus = &node->locus;
1205 grecs_value_t *value = node->v.value;
1206
1207 if (*lpp)
1208 lp = *lpp;
1209 else {
1210 lp = _grecs_simple_list_create(1);
1211 *lpp = lp;
1212 }
1213 switch (value->type) {
1214 case GRECS_TYPE_STRING:
1215 grecs_list_append(lp, grecs_strdup(value->v.string));
1216 break;
1217
1218 case GRECS_TYPE_LIST: {
1219 struct grecs_list_entry *ep;
1220
1221 for (ep = value->v.list->head; ep; ep = ep->next) {
1222 const grecs_value_t *vp = ep->data;
1223
1224 if (vp->type != GRECS_TYPE_STRING) {
1225 grecs_error(&vp->locus, 0,
1226 _("list element must be a string"));
1227 return 1;
1228 }
1229 grecs_list_append(lp, grecs_strdup(vp->v.string));
1230 }
1231 break;
1232 }
1233
1234 case GRECS_TYPE_ARRAY:
1235 grecs_error(locus, 0, _("too many arguments"));
1236 return 1;
1237 }
1238 return 0;
1239}
1240
1241static int
1200cb_upload_version(enum grecs_callback_command cmd, grecs_node_t *node, 1242cb_upload_version(enum grecs_callback_command cmd, grecs_node_t *node,
1201 void *varptr, void *cb_data) 1243 void *varptr, void *cb_data)
1202{ 1244{
@@ -1240,19 +1282,16 @@ static struct grecs_keyword wydawca_kw[] = {
1240 { "module-prepend-load-path", N_("path"), 1282 { "module-prepend-load-path", N_("path"),
1241 N_("List of directories searched for modules prior to " 1283 N_("List of directories searched for modules prior to "
1242 "the default module directory"), 1284 "the default module directory"),
1243 grecs_type_string, GRECS_LIST, 1285 grecs_type_string, GRECS_LIST|GRECS_AGGR,
1244 &module_prepend_load_path }, 1286 &module_prepend_load_path, 0, cb_load_path },
1245 { "module-load-path", N_("path"), 1287 { "module-load-path", N_("path"),
1246 N_("List of directories searched for database modules."), 1288 N_("List of directories searched for database modules."),
1247 grecs_type_string, GRECS_LIST, 1289 grecs_type_string, GRECS_LIST|GRECS_AGGR,
1248 &module_load_path }, 1290 &module_load_path, 0, cb_load_path },
1249 1291
1250 { "module", N_("name: string> <path: string"), 1292 { "module", N_("name: string> <path: string"),
1251 N_("Load the specified module"), 1293 N_("Load the specified module"),
1252 grecs_type_string, GRECS_MULT, NULL, 0, cb_module }, 1294 grecs_type_string, GRECS_MULT, NULL, 0, cb_module },
1253 { "module", N_("name: string> <path: string"),
1254 N_("Load the specified module"),
1255 grecs_type_string, GRECS_MULT, NULL, 0, cb_module },
1256 { "module-init", N_("modname"), 1295 { "module-init", N_("modname"),
1257 N_("Module-specific initialization data"), 1296 N_("Module-specific initialization data"),
1258 grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, NULL }, 1297 grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, NULL },
@@ -1372,7 +1411,7 @@ void
1372config_finish(struct grecs_node *tree) 1411config_finish(struct grecs_node *tree)
1373{ 1412{
1374 struct grecs_node *p; 1413 struct grecs_node *p;
1375 1414
1376 if (grecs_tree_process(tree, wydawca_kw)) 1415 if (grecs_tree_process(tree, wydawca_kw))