summaryrefslogtreecommitdiff
path: root/src/plugins/irc/irc-redirect.h
blob: 3186c9186420e8c04bf97622c28e71083627e390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (C) 2010 Sebastien Helleu <flashcode@flashtux.org>
 *
 * This file is part of WeeChat, the extensible chat client.
 *
 * WeeChat 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.
 *
 * WeeChat 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 WeeChat.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __WEECHAT_IRC_REDIRECT_H
#define __WEECHAT_IRC_REDIRECT_H 1

#define IRC_REDIRECT_TIMEOUT_DEFAULT 60

struct t_irc_server;

/* template for redirections (IRC plugin creates some templates at startup) */

struct t_irc_redirect_pattern
{
    char *name;                     /* name                                  */
    int temp_pattern;               /* temporary pattern (created by         */
                                    /* external plugin/script)               */
    int timeout;                    /* default timeout (in seconds)          */
    char *cmd_start;                /* command(s) starting redirection       */
                                    /* (can be NULL or empty)                */
    char *cmd_stop;                 /* command(s) stopping redirection       */
                                    /* (not NULL, at least one command)      */
    char *cmd_extra;                /* extra command(s) after end commands   */
    struct t_irc_redirect_pattern *prev_redirect; /* link to previous redir. */
    struct t_irc_redirect_pattern *next_redirect; /* link to next redir.     */
};

/* command redirection (created when a command is redirected) */

struct t_irc_redirect
{
    struct t_irc_server *server;    /* server for this redirection           */
    char *pattern;                  /* name of pattern used for this redir.  */
    char *signal;                   /* name of signal sent after redirection */
    int count;                      /* how many times redirect is executed   */
    int current_count;              /* current count                         */
    char *string;                   /* we search this string in messages     */
    int timeout;                    /* timeout (in seconds)                  */
    char *command;                  /* command sent to server, which is      */
                                    /* redirected                            */
    time_t start_time;              /* time when command is sent to server   */
                                    /* (this is begining of this redirect)   */
    struct t_hashtable *cmd_start;  /* command(s) starting redirection       */
                                    /* (can be NULL or empty)                */
    struct t_hashtable *cmd_stop;   /* command(s) stopping redirection       */
                                    /* (not NULL, at least one command)      */
    struct t_hashtable *cmd_extra;  /* extra command(s) after end command(s) */
    int cmd_start_received;         /* one of start commands received ?      */
    int cmd_stop_received;          /* one of stop commands received ?       */
    struct t_hashtable *cmd_filter; /* command(s) to add to output           */
                                    /* (if NULL or empty, all cmds are sent) */
    char *output;                   /* output of IRC command (gradually      */
                                    /* filled with IRC messages)             */
    int output_size;                /* size (in bytes) of output string      */
    struct t_irc_redirect *prev_redirect; /* link to previous redirect       */
    struct t_irc_redirect *next_redirect; /* link to next redirect           */
};

extern struct t_irc_redirect_pattern *irc_redirect_patterns;
extern struct t_irc_redirect_pattern *last_irc_redirect_pattern;

extern struct t_irc_redirect_pattern *irc_redirect_pattern_new (const char *name,
                                                                int temp_pattern,
                                                                int timeout,
                                                                const char *cmd_start,
                                                                const char *cmd_stop,
                                                                const char *cmd_extra);
extern struct t_irc_redirect *irc_redirect_new_with_commands (struct t_irc_server *server,
                                                              const char *pattern,
                                                              const char *signal,
                                                              int count,
                                                              const char *string,
                                                              int timeout,
                                                              const char *cmd_start,
                                                              const char *cmd_stop,
                                                              const char *cmd_extra,
                                                              const char *cmd_filter);
extern struct t_irc_redirect *irc_redirect_new (struct t_irc_server *server,
                                                const char *pattern,
                                                const char *signal,
                                                int count,
                                                const char *string,
                                                int timeout,
                                                const char *cmd_filter);
extern struct t_irc_redirect *irc_redirect_search_available (struct t_irc_server *server);
extern void irc_redirect_init_command (struct t_irc_redirect *redirect,
                                       const char *command);
extern void irc_redirect_stop (struct t_irc_redirect *redirect,
                               const char *error);
extern int irc_redirect_message (struct t_irc_server *server,
                                 const char *message, const char *command,
                                 const char *arguments);
extern void irc_redirect_free (struct t_irc_redirect *redirect);
extern void irc_redirect_free_all (struct t_irc_server *server);
extern int irc_redirect_pattern_add_to_infolist (struct t_infolist *infolist,
                                                 struct t_irc_redirect_pattern *redirect_pattern);
extern int irc_redirect_add_to_infolist (struct t_infolist *infolist,
                                         struct t_irc_redirect *redirect);
extern void irc_redirect_pattern_print_log ();
extern void irc_redirect_print_log (struct t_irc_server *server);
extern int irc_redirect_pattern_hsignal_cb (void *data, const char *signal,
                                            struct t_hashtable *hashtable);
extern int irc_redirect_command_hsignal_cb (void *data, const char *signal,
                                            struct t_hashtable *hashtable);
extern void irc_redirect_init ();
extern void irc_redirect_end ();

#endif /* __WEECHAT_IRC_REDIRECT_H */