~ctrlproxy/ctrlproxy/trunk

« back to all changes in this revision

Viewing changes to mods/repl_memory.c

  • Committer: jelmer
  • Date: 2003-10-18 22:02:02 UTC
  • Revision ID: jelmer@samba.org-20031018220202-6801a76318fb4d13
Update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
        ctrlproxy: A modular IRC proxy
 
3
        (c) 2002-2003 Jelmer Vernooij <jelmer@nl.linux.org>
 
4
 
 
5
        This program is free software; you can redistribute it and/or modify
 
6
        it under the terms of the GNU General Public License as published by
 
7
        the Free Software Foundation; either version 2 of the License, or
 
8
        (at your option) any later version.
 
9
 
 
10
        This program 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
 
13
        GNU General Public License for more details.
 
14
 
 
15
        You should have received a copy of the GNU General Public License
 
16
        along with this program; if not, write to the Free Software
 
17
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
*/
 
19
 
 
20
#define _GNU_SOURCE
 
21
#include "ctrlproxy.h"
 
22
#include <string.h>
 
23
 
 
24
static GHashTable *files = NULL;
 
25
 
 
26
void replicate_data(struct network *s, struct transport_context *io) {
 
27
        GSList *l = g_hash_table_lookup(files, s);
 
28
        if(!l) { default_replicate_function(s, io); return; }
 
29
        while(l) {
 
30
                struct line *rl = (struct line *)l->data;
 
31
                if(rl) {
 
32
                        irc_send_line(io, rl);
 
33
                        free_line(rl);
 
34
                }
 
35
                l = g_slist_next(l);
 
36
        }
 
37
        g_slist_free(l);
 
38
        g_hash_table_replace(files, s, NULL);
 
39
}
 
40
 
 
41
static gboolean log_data(struct line *l) {
 
42
        GSList *gl = g_hash_table_lookup(files, l->network);
 
43
        struct channel *c;
 
44
 
 
45
        if(l->argc < 1)return TRUE;
 
46
 
 
47
        if(l->direction == TO_SERVER &&  
 
48
           (!strcasecmp(l->args[0], "PRIVMSG") || !strcasecmp(l->args[0], "NOTICE"))) {
 
49
                GSList *gs = gl;
 
50
                while(gs) {
 
51
                        if(gs->data)free_line((struct line *)gs->data);
 
52
                        gs = g_slist_next(gs);
 
53
                }
 
54
                
 
55
                g_slist_free(gl);
 
56
                g_hash_table_replace(files, l->network, NULL);
 
57
                return TRUE;
 
58
        }
 
59
 
 
60
        if(l->direction == TO_SERVER)return TRUE;
 
61
 
 
62
        if(!gl) gl = gen_replication(l->network);
 
63
 
 
64
        if(!strcasecmp(l->args[0], "PRIVMSG") ||
 
65
           !strcasecmp(l->args[0], "NOTICE") ||
 
66
           !strcasecmp(l->args[0], "MODE") || 
 
67
           !strcasecmp(l->args[0], "JOIN") || 
 
68
           !strcasecmp(l->args[0], "PART") || 
 
69
           !strcasecmp(l->args[0], "KICK") || 
 
70
           !strcasecmp(l->args[0], "QUIT") ||
 
71
           !strcasecmp(l->args[0], "TOPIC") ||
 
72
           !strcasecmp(l->args[0], "NICK")) {
 
73
                gl = g_slist_append(gl, linedup(l));
 
74
        } else if(!strcasecmp(l->args[0], "353")) {
 
75
                c = find_channel(l->network, l->args[3]);
 
76
                if(c && !(c->introduced & 2)) {
 
77
                        gl = g_slist_append(gl, linedup(l));
 
78
                }
 
79
                /* Only do 366 if not & 2. Set | 2 */
 
80
        } else if(!strcasecmp(l->args[0], "366")) {
 
81
                c = find_channel(l->network, l->args[2]);
 
82
                if(c && !(c->introduced & 2)) {
 
83
                        gl = g_slist_append(gl, linedup(l));
 
84
                        c->introduced |= 2;
 
85
                }
 
86
                /* Only do 331 or 332 if not & 1. Set | 1 */
 
87
        } else if(!strcasecmp(l->args[0], "331") || !strcasecmp(l->args[0], "332")) {
 
88
                c = find_channel(l->network, l->args[2]);
 
89
                if(c && !(c->introduced & 1)) {
 
90
                        gl = g_slist_append(gl, linedup(l));
 
91
                        c->introduced |= 1;
 
92
                }
 
93
        }
 
94
 
 
95
        g_hash_table_replace(files, l->network, gl);
 
96
        return TRUE;
 
97
}
 
98
 
 
99
gboolean fini_plugin(struct plugin *p) {
 
100
        del_filter(log_data);
 
101
        replicate_function = default_replicate_function;
 
102
        return TRUE;
 
103
}
 
104
 
 
105
gboolean init_plugin(struct plugin *p) {
 
106
        files = g_hash_table_new(NULL, NULL);
 
107
        replicate_function = replicate_data;
 
108
        add_filter("repl_memory", log_data);
 
109
        return TRUE;
 
110
}