summaryrefslogtreecommitdiff
path: root/src/plugins/logger
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2008-09-02 15:42:20 +0200
committerSebastien Helleu <flashcode@flashtux.org>2008-09-02 15:42:20 +0200
commite756f4770ae99b07c7aaf7d43d5f07d0c88f256f (patch)
tree03715590305b4a4fb4cd7018470fb1153f873bd0 /src/plugins/logger
parentb03393fd428a2cf78d2ce1cae81588f598b3d46c (diff)
downloadweechat-e756f4770ae99b07c7aaf7d43d5f07d0c88f256f.zip
Add new hooks in plugins: info (fifo_filename) and infolists (alias, logger_buffer, xfer)
Diffstat (limited to 'src/plugins/logger')
-rw-r--r--src/plugins/logger/CMakeLists.txt5
-rw-r--r--src/plugins/logger/Makefile.am2
-rw-r--r--src/plugins/logger/logger-buffer.c57
-rw-r--r--src/plugins/logger/logger-buffer.h5
-rw-r--r--src/plugins/logger/logger-info.c96
-rw-r--r--src/plugins/logger/logger-info.h25
-rw-r--r--src/plugins/logger/logger.c4
-rw-r--r--src/plugins/logger/logger.h2
8 files changed, 193 insertions, 3 deletions
diff --git a/src/plugins/logger/CMakeLists.txt b/src/plugins/logger/CMakeLists.txt
index 26d7b84b9..816d2cc6a 100644
--- a/src/plugins/logger/CMakeLists.txt
+++ b/src/plugins/logger/CMakeLists.txt
@@ -14,7 +14,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-ADD_LIBRARY(logger MODULE logger.c logger.h logger-buffer.c logger-buffer.h
+ADD_LIBRARY(logger MODULE
+logger.c logger.h
+logger-buffer.c logger-buffer.h
+logger-info.c logger-info.h
logger-tail.c logger-tail.h)
SET_TARGET_PROPERTIES(logger PROPERTIES PREFIX "")
diff --git a/src/plugins/logger/Makefile.am b/src/plugins/logger/Makefile.am
index 37bd6b9e4..89f7966e5 100644
--- a/src/plugins/logger/Makefile.am
+++ b/src/plugins/logger/Makefile.am
@@ -24,6 +24,8 @@ logger_la_SOURCES = logger.c \
logger.h \
logger-buffer.c \
logger-buffer.h \
+ logger-info.c \
+ logger-info.h \
logger-tail.c \
logger-tail.h
logger_la_LDFLAGS = -module
diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c
index 338566f88..446d48133 100644
--- a/src/plugins/logger/logger-buffer.c
+++ b/src/plugins/logger/logger-buffer.c
@@ -27,6 +27,8 @@
#include <string.h>
#include <stdio.h>
+#include "../weechat-plugin.h"
+#include "logger.h"
#include "logger-buffer.h"
@@ -35,6 +37,31 @@ struct t_logger_buffer *last_logger_buffer = NULL;
/*
+ * logger_buffer_valid: check if a logger buffer pointer exists
+ * return 1 if logger buffer exists
+ * 0 if logger buffer is not found
+ */
+
+int
+logger_buffer_valid (struct t_logger_buffer *logger_buffer)
+{
+ struct t_logger_buffer *ptr_logger_buffer;
+
+ if (!logger_buffer)
+ return 0;
+
+ for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer;
+ ptr_logger_buffer = ptr_logger_buffer->next_buffer)
+ {
+ if (ptr_logger_buffer == logger_buffer)
+ return 1;
+ }
+
+ /* logger_buffer not found */
+ return 0;
+}
+
+/*
* logger_buffer_add: add a new buffer for logging
*/
@@ -128,3 +155,33 @@ logger_buffer_free_all ()
logger_buffer_free (logger_buffers);
}
}
+
+/*
+ * logger_buffer_add_to_infolist: add a logger buffer in an infolist
+ * return 1 if ok, 0 if error
+ */
+
+int
+logger_buffer_add_to_infolist (struct t_infolist *infolist,
+ struct t_logger_buffer *logger_buffer)
+{
+ struct t_infolist_item *ptr_item;
+
+ if (!infolist || !logger_buffer)
+ return 0;
+
+ ptr_item = weechat_infolist_new_item (infolist);
+ if (!ptr_item)
+ return 0;
+
+ if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", logger_buffer->buffer))
+ return 0;
+ if (!weechat_infolist_new_var_string (ptr_item, "log_filename", logger_buffer->log_filename))
+ return 0;
+ if (!weechat_infolist_new_var_pointer (ptr_item, "log_file", logger_buffer->log_file))
+ return 0;
+ if (!weechat_infolist_new_var_integer (ptr_item, "log_enabled", logger_buffer->log_enabled))
+ return 0;
+
+ return 1;
+}
diff --git a/src/plugins/logger/logger-buffer.h b/src/plugins/logger/logger-buffer.h
index da17c3f10..d2d464461 100644
--- a/src/plugins/logger/logger-buffer.h
+++ b/src/plugins/logger/logger-buffer.h
@@ -20,6 +20,8 @@
#ifndef __WEECHAT_LOGGER_BUFFER_H
#define __WEECHAT_LOGGER_BUFFER_H 1
+struct t_infolist;
+
struct t_logger_buffer
{
struct t_gui_buffer *buffer; /* pointer to buffer */
@@ -33,10 +35,13 @@ struct t_logger_buffer
extern struct t_logger_buffer *logger_buffers;
extern struct t_logger_buffer *last_logger_buffer;
+extern int logger_buffer_valid (struct t_logger_buffer *logger_buffer);
extern struct t_logger_buffer *logger_buffer_add (struct t_gui_buffer *,
const char *log_filename);
extern struct t_logger_buffer *logger_buffer_search (struct t_gui_buffer *buffer);
extern void logger_buffer_free (struct t_logger_buffer *logger_buffer);
extern void logger_buffer_free_all ();
+extern int logger_buffer_add_to_infolist (struct t_infolist *infolist,
+ struct t_logger_buffer *logger_buffer);
#endif /* logger-buffer.h */
diff --git a/src/plugins/logger/logger-info.c b/src/plugins/logger/logger-info.c
new file mode 100644
index 000000000..0e75f7eb6
--- /dev/null
+++ b/src/plugins/logger/logger-info.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* logger-info.c: info and infolist hooks for logger plugin */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "../weechat-plugin.h"
+#include "logger.h"
+#include "logger-buffer.h"
+
+
+/*
+ * logger_info_get_infolist_cb: callback called when logger infolist is asked
+ */
+
+struct t_infolist *
+logger_info_get_infolist_cb (void *data, const char *infolist_name,
+ void *pointer, const char *arguments)
+{
+ struct t_infolist *ptr_infolist;
+ struct t_logger_buffer *ptr_logger_buffer;
+
+ /* make C compiler happy */
+ (void) data;
+ (void) arguments;
+
+ if (!infolist_name || !infolist_name[0])
+ return NULL;
+
+ if (weechat_strcasecmp (infolist_name, "logger_buffer") == 0)
+ {
+ if (pointer && !logger_buffer_valid (pointer))
+ return NULL;
+
+ ptr_infolist = weechat_infolist_new ();
+ if (ptr_infolist)
+ {
+ if (pointer)
+ {
+ /* build list with only one logger buffer */
+ if (!logger_buffer_add_to_infolist (ptr_infolist, pointer))
+ {
+ weechat_infolist_free (ptr_infolist);
+ return NULL;
+ }
+ return ptr_infolist;
+ }
+ else
+ {
+ /* build list with all logger buffers */
+ for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer;
+ ptr_logger_buffer = ptr_logger_buffer->next_buffer)
+ {
+ if (!logger_buffer_add_to_infolist (ptr_infolist,
+ ptr_logger_buffer))
+ {
+ weechat_infolist_free (ptr_infolist);
+ return NULL;
+ }
+ }
+ return ptr_infolist;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/*
+ * logger_info_init: initialize info and infolist hooks for logger plugin
+ */
+
+void
+logger_info_init ()
+{
+ /* irc infolist hooks */
+ weechat_hook_infolist ("logger_buffer", &logger_info_get_infolist_cb, NULL);
+}
diff --git a/src/plugins/logger/logger-info.h b/src/plugins/logger/logger-info.h
new file mode 100644
index 000000000..02c75fa67
--- /dev/null
+++ b/src/plugins/logger/logger-info.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
+ * See README for License detail, AUTHORS for developers list.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __WEECHAT_LOGGER_INFO_H
+#define __WEECHAT_LOGGER_INFO_H 1
+
+extern void logger_info_init ();
+
+#endif /* logger-info.h */
diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c
index dac2f267c..37d0d0035 100644
--- a/src/plugins/logger/logger.c
+++ b/src/plugins/logger/logger.c
@@ -34,8 +34,10 @@
#include <fcntl.h>
#include <time.h>
+#include "../weechat-plugin.h"
#include "logger.h"
#include "logger-buffer.h"
+#include "logger-info.h"
#include "logger-tail.h"
@@ -747,6 +749,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_config ("plugins.var.logger.*", &logger_config_cb, NULL);
+ logger_info_init ();
+
return WEECHAT_RC_OK;
}
diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h
index 6b1bb36d0..7f46a7b66 100644
--- a/src/plugins/logger/logger.h
+++ b/src/plugins/logger/logger.h
@@ -20,8 +20,6 @@
#ifndef __WEECHAT_LOGGER_H
#define __WEECHAT_LOGGER_H 1
-#include "../weechat-plugin.h"
-
#define weechat_plugin weechat_logger_plugin
#define LOGGER_BUF_WRITE_SIZE (16*1024)