1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 06:16:40 +02:00

Add new hooks in plugins: info (fifo_filename) and infolists (alias, logger_buffer, xfer)

This commit is contained in:
Sebastien Helleu
2008-09-02 15:42:20 +02:00
parent b03393fd42
commit e756f4770a
29 changed files with 781 additions and 15 deletions
+8 -2
View File
@@ -87,6 +87,8 @@
./src/gui/wxwidgets/gui-input.c
./src/plugins/alias/alias.c
./src/plugins/alias/alias.h
./src/plugins/alias/alias-info.c
./src/plugins/alias/alias-info.h
./src/plugins/aspell/aspell.c
./src/plugins/aspell/aspell.h
./src/plugins/charset/charset.c
@@ -123,10 +125,12 @@
./src/plugins/irc/irc-protocol.h
./src/plugins/irc/irc-server.c
./src/plugins/irc/irc-server.h
./src/plugins/logger/logger-buffer.c
./src/plugins/logger/logger-buffer.h
./src/plugins/logger/logger.c
./src/plugins/logger/logger.h
./src/plugins/logger/logger-buffer.c
./src/plugins/logger/logger-buffer.h
./src/plugins/logger/logger-info.c
./src/plugins/logger/logger-info.h
./src/plugins/logger/logger-tail.c
./src/plugins/logger/logger-tail.h
./src/plugins/notify/notify.c
@@ -179,6 +183,8 @@
./src/plugins/xfer/xfer-dcc.h
./src/plugins/xfer/xfer-file.c
./src/plugins/xfer/xfer-file.h
./src/plugins/xfer/xfer-info.c
./src/plugins/xfer/xfer-info.h
./src/plugins/xfer/xfer.h
./src/plugins/xfer/xfer-network.c
./src/plugins/xfer/xfer-network.h
+8 -2
View File
@@ -88,6 +88,8 @@ SET(WEECHAT_SOURCES
./src/gui/wxwidgets/gui-input.c
./src/plugins/alias/alias.c
./src/plugins/alias/alias.h
./src/plugins/alias/alias-info.c
./src/plugins/alias/alias-info.h
./src/plugins/aspell/aspell.c
./src/plugins/aspell/aspell.h
./src/plugins/charset/charset.c
@@ -124,10 +126,12 @@ SET(WEECHAT_SOURCES
./src/plugins/irc/irc-protocol.h
./src/plugins/irc/irc-server.c
./src/plugins/irc/irc-server.h
./src/plugins/logger/logger-buffer.c
./src/plugins/logger/logger-buffer.h
./src/plugins/logger/logger.c
./src/plugins/logger/logger.h
./src/plugins/logger/logger-buffer.c
./src/plugins/logger/logger-buffer.h
./src/plugins/logger/logger-info.c
./src/plugins/logger/logger-info.h
./src/plugins/logger/logger-tail.c
./src/plugins/logger/logger-tail.h
./src/plugins/notify/notify.c
@@ -180,6 +184,8 @@ SET(WEECHAT_SOURCES
./src/plugins/xfer/xfer-dcc.h
./src/plugins/xfer/xfer-file.c
./src/plugins/xfer/xfer-file.h
./src/plugins/xfer/xfer-info.c
./src/plugins/xfer/xfer-info.h
./src/plugins/xfer/xfer.h
./src/plugins/xfer/xfer-network.c
./src/plugins/xfer/xfer-network.h
+3 -1
View File
@@ -14,7 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
ADD_LIBRARY(alias MODULE alias.c alias.h)
ADD_LIBRARY(alias MODULE
alias.c alias.h
alias-info.c alias-info.h)
SET_TARGET_PROPERTIES(alias PROPERTIES PREFIX "")
TARGET_LINK_LIBRARIES(alias)
+4 -1
View File
@@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins
lib_LTLIBRARIES = alias.la
alias_la_SOURCES = alias.c alias.h
alias_la_SOURCES = alias.c \
alias.h \
alias-info.c \
alias-info.h
alias_la_LDFLAGS = -module
alias_la_LIBADD = $(ALIAS_LFLAGS)
+93
View File
@@ -0,0 +1,93 @@
/*
* 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/>.
*/
/* alias-info.c: info and infolist hooks for alias plugin */
#include <stdlib.h>
#include "../weechat-plugin.h"
#include "alias.h"
/*
* alias_info_get_infolist_cb: callback called when alias infolist is asked
*/
struct t_infolist *
alias_info_get_infolist_cb (void *data, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_infolist *ptr_infolist;
struct t_alias *ptr_alias;
/* make C compiler happy */
(void) data;
(void) arguments;
if (!infolist_name || !infolist_name[0])
return NULL;
if (weechat_strcasecmp (infolist_name, "alias") == 0)
{
if (pointer && !alias_valid (pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (ptr_infolist)
{
if (pointer)
{
/* build list with only one alias */
if (!alias_add_to_infolist (ptr_infolist, pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
return ptr_infolist;
}
else
{
/* build list with all aliases */
for (ptr_alias = alias_list; ptr_alias;
ptr_alias = ptr_alias->next_alias)
{
if (!alias_add_to_infolist (ptr_infolist, ptr_alias))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
}
return ptr_infolist;
}
}
}
return NULL;
}
/*
* alias_info_init: initialize info and infolist hooks for alias plugin
*/
void
alias_info_init ()
{
/* alias infolist hooks */
weechat_hook_infolist ("alias", &alias_info_get_infolist_cb, NULL);
}
+25
View File
@@ -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_ALIAS_INFO_H
#define __WEECHAT_ALIAS_INFO_H 1
extern void alias_info_init ();
#endif /* alias-info.h */
+57 -1
View File
@@ -25,6 +25,7 @@
#include "../weechat-plugin.h"
#include "alias.h"
#include "alias-info.h"
WEECHAT_PLUGIN_NAME("alias");
@@ -37,7 +38,6 @@ WEECHAT_PLUGIN_LICENSE("GPL3");
#define ALIAS_CONFIG_NAME "alias"
struct t_weechat_plugin *weechat_alias_plugin = NULL;
#define weechat_plugin weechat_alias_plugin
struct t_config_file *alias_config_file = NULL;
struct t_config_section *alias_config_section_cmd = NULL;
@@ -46,6 +46,31 @@ struct t_alias *alias_list = NULL;
struct t_alias *last_alias = NULL;
/*
* alias_valid: check if an alias pointer exists
* return 1 if alias exists
* 0 if alias is not found
*/
int
alias_valid (struct t_alias *alias)
{
struct t_alias *ptr_alias;
if (!alias)
return 0;
for (ptr_alias = alias_list; ptr_alias;
ptr_alias = ptr_alias->next_alias)
{
if (ptr_alias == alias)
return 1;
}
/* alias not found */
return 0;
}
/*
* alias_search: search an alias
*/
@@ -833,6 +858,35 @@ alias_completion_cb (void *data, const char *completion_item,
return WEECHAT_RC_OK;
}
/*
* alias_add_to_infolist: add an alias in an infolist
* return 1 if ok, 0 if error
*/
int
alias_add_to_infolist (struct t_infolist *infolist, struct t_alias *alias)
{
struct t_infolist_item *ptr_item;
if (!infolist || !alias)
return 0;
ptr_item = weechat_infolist_new_item (infolist);
if (!ptr_item)
return 0;
if (!weechat_infolist_new_var_pointer (ptr_item, "hook", alias->hook))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "name", alias->name))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "command", alias->command))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "running", alias->running))
return 0;
return 1;
}
/*
* weechat_plugin_init: initialize alias plugin
*/
@@ -878,6 +932,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_completion ("alias", &alias_completion_cb, NULL);
alias_info_init ();
return WEECHAT_RC_OK;
}
+10
View File
@@ -20,6 +20,8 @@
#ifndef __WEECHAT_ALIAS_H
#define __WEECHAT_ALIAS_H 1
#define weechat_plugin weechat_alias_plugin
struct t_alias
{
struct t_hook *hook; /* command hook */
@@ -30,4 +32,12 @@ struct t_alias
struct t_alias *next_alias; /* link to next alias */
};
extern struct t_alias *alias_list;
extern struct t_weechat_plugin *weechat_alias_plugin;
extern int alias_valid (struct t_alias *alias);
extern int alias_add_to_infolist (struct t_infolist *infolist,
struct t_alias *alias);
#endif /* alias.h */
+3 -1
View File
@@ -14,7 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
ADD_LIBRARY(fifo MODULE fifo.c)
ADD_LIBRARY(fifo MODULE
fifo.c fifo.h
fifo-info.c fifo-info.h)
SET_TARGET_PROPERTIES(fifo PROPERTIES PREFIX "")
TARGET_LINK_LIBRARIES(fifo)
+4 -1
View File
@@ -20,6 +20,9 @@ libdir = ${weechat_libdir}/plugins
lib_LTLIBRARIES = fifo.la
fifo_la_SOURCES = fifo.c
fifo_la_SOURCES = fifo.c \
fifo.h \
fifo-info.c \
fifo-info.h
fifo_la_LDFLAGS = -module
fifo_la_LIBADD = $(FIFO_LFLAGS)
+57
View File
@@ -0,0 +1,57 @@
/*
* 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/>.
*/
/* fifo-info.c: info and infolist hooks for fifo plugin */
#include <stdlib.h>
#include "../weechat-plugin.h"
#include "fifo.h"
/*
* fifo_info_get_info_cb: callback called when fifo info is asked
*/
char *
fifo_info_get_info_cb (void *data, const char *info_name,
const char *arguments)
{
/* make C compiler happy */
(void) data;
(void) arguments;
if (weechat_strcasecmp (info_name, "fifo_filename") == 0)
{
return fifo_filename;
}
return NULL;
}
/*
* fifo_info_init: initialize info and infolist hooks for fifo plugin
*/
void
fifo_info_init ()
{
/* fifo info hooks */
weechat_hook_info ("fifo_filename", &fifo_info_get_info_cb, NULL);
}
+25
View File
@@ -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_FIFO_INFO_H
#define __WEECHAT_FIFO_INFO_H 1
extern void fifo_info_init ();
#endif /* fifo-info.h */
+4
View File
@@ -28,6 +28,8 @@
#include <fcntl.h>
#include "../weechat-plugin.h"
#include "fifo.h"
#include "fifo-info.h"
WEECHAT_PLUGIN_NAME("fifo");
@@ -367,6 +369,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_config ("plugins.var.fifo.fifo", &fifo_config_cb, NULL);
fifo_info_init ();
return WEECHAT_RC_OK;
}
+28
View File
@@ -0,0 +1,28 @@
/*
* 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_FIFO_H
#define __WEECHAT_FIFO_H 1
#define weechat_plugin weechat_fifo_plugin
extern struct t_weechat_plugin *weechat_fifo_plugin;
extern char *fifo_filename;
#endif /* fifo.h */
+1 -3
View File
@@ -25,7 +25,6 @@
#include "../weechat-plugin.h"
#include "irc.h"
#include "irc-info.h"
#include "irc-channel.h"
#include "irc-nick.h"
#include "irc-protocol.h"
@@ -177,8 +176,7 @@ irc_info_get_infolist_cb (void *data, const char *infolist_name,
/* make C compiler happy */
(void) data;
(void) arguments;
if (!infolist_name || !infolist_name[0])
return NULL;
+4 -1
View File
@@ -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 "")
+2
View File
@@ -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
+57
View File
@@ -27,6 +27,8 @@
#include <string.h>
#include <stdio.h>
#include "../weechat-plugin.h"
#include "logger.h"
#include "logger-buffer.h"
@@ -34,6 +36,31 @@ struct t_logger_buffer *logger_buffers = NULL;
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;
}
+5
View File
@@ -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 */
+96
View File
@@ -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);
}
+25
View File
@@ -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 */
+4
View File
@@ -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;
}
-2
View File
@@ -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)
+1
View File
@@ -22,6 +22,7 @@ xfer-command.c xfer-command.h
xfer-config.c xfer-config.h
xfer-dcc.c xfer-dcc.h
xfer-file.c xfer-file.h
xfer-info.c xfer-info.h
xfer-network.c xfer-network.h
xfer-upgrade.c xfer-upgrade.h)
SET_TARGET_PROPERTIES(xfer PROPERTIES PREFIX "")
+2
View File
@@ -34,6 +34,8 @@ xfer_la_SOURCES = xfer.c \
xfer-dcc.h \
xfer-file.c \
xfer-file.h \
xfer-info.c \
xfer-info.h \
xfer-network.c \
xfer-network.h \
xfer-upgrade.c \
+94
View File
@@ -0,0 +1,94 @@
/*
* 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/>.
*/
/* xfer-info.c: info and infolist hooks for xfer plugin */
#include <stdlib.h>
#include <stdio.h>
#include "../weechat-plugin.h"
#include "xfer.h"
/*
* xfer_info_get_infolist_cb: callback called when xfer infolist is asked
*/
struct t_infolist *
xfer_info_get_infolist_cb (void *data, const char *infolist_name,
void *pointer, const char *arguments)
{
struct t_infolist *ptr_infolist;
struct t_xfer *ptr_xfer;
/* make C compiler happy */
(void) data;
(void) arguments;
if (!infolist_name || !infolist_name[0])
return NULL;
if (weechat_strcasecmp (infolist_name, "xfer") == 0)
{
if (pointer && !xfer_valid (pointer))
return NULL;
ptr_infolist = weechat_infolist_new ();
if (ptr_infolist)
{
if (pointer)
{
/* build list with only one xfer */
if (!xfer_add_to_infolist (ptr_infolist, pointer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
return ptr_infolist;
}
else
{
/* build list with all xfers */
for (ptr_xfer = xfer_list; ptr_xfer;
ptr_xfer = ptr_xfer->next_xfer)
{
if (!xfer_add_to_infolist (ptr_infolist, ptr_xfer))
{
weechat_infolist_free (ptr_infolist);
return NULL;
}
}
return ptr_infolist;
}
}
}
return NULL;
}
/*
* xfer_info_init: initialize info and infolist hooks for xfer plugin
*/
void
xfer_info_init ()
{
/* xfer infolist hooks */
weechat_hook_infolist ("xfer", &xfer_info_get_infolist_cb, NULL);
}
+25
View File
@@ -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_XFER_INFO_H
#define __WEECHAT_XFER_INFO_H 1
extern void xfer_info_init ();
#endif /* xfer-info.h */
+133
View File
@@ -36,6 +36,7 @@
#include "xfer-command.h"
#include "xfer-config.h"
#include "xfer-file.h"
#include "xfer-info.h"
#include "xfer-network.h"
#include "xfer-upgrade.h"
@@ -74,6 +75,31 @@ int xfer_debug = 0;
int xfer_signal_upgrade_received = 0; /* signal "upgrade" received ? */
/*
* xfer_valid: check if a xfer pointer exists
* return 1 if xfer exists
* 0 if xfer is not found
*/
int
xfer_valid (struct t_xfer *xfer)
{
struct t_xfer *ptr_xfer;
if (!xfer)
return 0;
for (ptr_xfer = xfer_list; ptr_xfer;
ptr_xfer = ptr_xfer->next_xfer)
{
if (ptr_xfer == xfer)
return 1;
}
/* xfer not found */
return 0;
}
/*
* xfer_signal_upgrade_cb: callback for "upgrade" signal
*/
@@ -1134,6 +1160,111 @@ xfer_accept_resume_cb (void *data, const char *signal, const char *type_data,
return WEECHAT_RC_OK;
}
/*
* xfer_add_to_infolist: add a xfer in an infolist
* return 1 if ok, 0 if error
*/
int
xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer)
{
struct t_infolist_item *ptr_item;
char value[128];
if (!infolist || !xfer)
return 0;
ptr_item = weechat_infolist_new_item (infolist);
if (!ptr_item)
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "plugin_name", xfer->plugin_name))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "plugin_id", xfer->plugin_id))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "type", xfer->type))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "type_string", xfer_type_string[xfer->type]))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "protocol", xfer->protocol))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "protocol_string", xfer_protocol_string[xfer->protocol]))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "remote_nick", xfer->remote_nick))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "local_nick", xfer->local_nick))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "filename", xfer->filename))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->size);
if (!weechat_infolist_new_var_string (ptr_item, "size", value))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->address);
if (!weechat_infolist_new_var_string (ptr_item, "address", value))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "port", xfer->port))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "status", xfer->status))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "status_string", xfer_status_string[xfer->status]))
return 0;
if (!weechat_infolist_new_var_pointer (ptr_item, "buffer", xfer->buffer))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "fast_send", xfer->fast_send))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "blocksize", xfer->blocksize))
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "start_time", xfer->start_time))
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "start_transfer", xfer->start_transfer))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "sock", xfer->sock))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "child_pid", xfer->child_pid))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "child_read", xfer->child_read))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "child_write", xfer->child_write))
return 0;
if (!weechat_infolist_new_var_pointer (ptr_item, "hook_fd", xfer->hook_fd))
return 0;
if (!weechat_infolist_new_var_pointer (ptr_item, "hook_timer", xfer->hook_timer))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", xfer->unterminated_message))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "file", xfer->file))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "local_filename", xfer->local_filename))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "filename_suffix", xfer->filename_suffix))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->pos);
if (!weechat_infolist_new_var_string (ptr_item, "pos", value))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->ack);
if (!weechat_infolist_new_var_string (ptr_item, "ack", value))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->start_resume);
if (!weechat_infolist_new_var_string (ptr_item, "start_resume", value))
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "last_check_time", xfer->last_check_time))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->last_check_pos);
if (!weechat_infolist_new_var_string (ptr_item, "last_check_pos", value))
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "last_activity", xfer->last_activity))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->bytes_per_sec);
if (!weechat_infolist_new_var_string (ptr_item, "bytes_per_sec", value))
return 0;
snprintf (value, sizeof (value), "%lu", xfer->eta);
if (!weechat_infolist_new_var_string (ptr_item, "eta", value))
return 0;
return 1;
}
/*
* xfer_print_log: print DCC infos in log (usually for crash dump)
*/
@@ -1245,6 +1376,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
weechat_hook_signal ("xfer_accept_resume", &xfer_accept_resume_cb, NULL);
weechat_hook_signal ("debug_dump", &xfer_debug_dump_cb, NULL);
xfer_info_init ();
return WEECHAT_RC_OK;
}
+3
View File
@@ -154,9 +154,12 @@ extern struct t_xfer *xfer_list, *last_xfer;
extern int xfer_count;
extern int xfer_debug;
extern int xfer_valid (struct t_xfer *xfer);
extern struct t_xfer *xfer_search_by_number (int number);
extern void xfer_close (struct t_xfer *xfer, enum t_xfer_status status);
extern void xfer_send_signal (struct t_xfer *xfer, const char *signal);
extern void xfer_free (struct t_xfer *xfer);
extern int xfer_add_to_infolist (struct t_infolist *infolist,
struct t_xfer *xfer);
#endif /* xfer.h */