f28605655614446768d3bf591d2c22bde37d3148
[cascardo/rnetproxy.git] / pop.c
1 /*
2 ** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
3 ** Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 **  
19 */
20
21 #include <gnet.h>
22 #include <glib.h>
23 #include "nethook.h"
24 #include "pop.h"
25
26 typedef struct
27 {
28   net_read orig_read;
29   gpointer orig_data;
30 } pop_t;
31
32 static void
33 pop_read (net_hook_t *hook, gchar *buffer, size_t len)
34 {
35   pop_t *pop = hook->data;
36   hook->data = pop->orig_data;
37   pop->orig_read (hook, buffer, len);
38   hook->data = pop;
39 }
40
41 net_hook_t *
42 pop_hook_new (net_hook_t *layer)
43 {
44   pop_t *pop;
45   pop = g_slice_new (pop_t);
46   pop->orig_read = layer->read;
47   pop->orig_data = layer->data;
48   layer->read = pop_read;
49   layer->data = pop;
50   return layer;
51 }
52
53 void
54 pop_destroy (net_hook_t *hook)
55 {
56   g_slice_free (net_hook_t, hook->data);
57 }