File: linestack.h

package info (click to toggle)
ctrlproxy 3.0.7-1
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,668 kB
  • ctags: 2,045
  • sloc: ansic: 15,358; sh: 2,805; xml: 1,078; python: 346; makefile: 302; perl: 18
file content (176 lines) | stat: -rw-r--r-- 4,848 bytes parent folder | download
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
	ctrlproxy: A modular IRC proxy
	(c) 2002-2005 Jelmer Vernooij <jelmer@nl.linux.org>

	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, write to the Free Software
	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __CTRLPROXY_LINESTACK_H__
#define __CTRLPROXY_LINESTACK_H__

/**
 * @file
 * @brief Linestack handling
 */

struct line;
struct network;
struct irc_client;
#include <sys/time.h>
#include <gmodule.h>

#include "hooks.h"

struct irc_network_state;
struct linestack_marker;
struct linestack_ops;
struct ctrlproxy_config;

/**
 * A linestack instance.
 */
struct linestack_context
{
	void *backend_data;
	const struct linestack_ops *ops;
};

/**
 * Mark set a specific point in time in a linestack.
 */
struct linestack_marker {
	void *data;
	void (*free_fn) (void *);
};

/* linestack.c */
typedef gboolean (*linestack_traverse_fn) (struct irc_line *, time_t, void *);
/**
 * Linestack functions
 */
struct linestack_ops {
	char *name;
	gboolean (*init) (struct linestack_context *, 
					  const char *name,
					  struct ctrlproxy_config *,
					  const struct irc_network_state *
					  );
	gboolean (*fini) (struct linestack_context *);

	/* Add a line */
	gboolean (*insert_line) (
		struct linestack_context *,
		const struct irc_line *,
		const struct irc_network_state *);
	
	/* Get marker for current position in stream */
	void *(*get_marker) 
		(struct linestack_context *);

	/* Optional */
	void *(*get_marker_numlines) 
		(struct linestack_context *, int numlines);

	void (*free_marker) (void *);
	
	gboolean (*traverse) (
		struct linestack_context *,
		void *from,
		void *to,
		linestack_traverse_fn, 
		void *userdata);

	/* Optional */
	struct irc_network_state *(*get_state) (
		struct linestack_context *,
		void *);

	/* Perhaps add other (optional) functions here such as searching for 
	 * a specific keyword ? */
};

G_MODULE_EXPORT void register_linestack(const struct linestack_ops *);
G_MODULE_EXPORT struct linestack_marker *linestack_get_marker_numlines (
		struct linestack_context *,
		int lines);

G_MODULE_EXPORT struct irc_network_state *linestack_get_state (
		struct linestack_context *,
		struct linestack_marker *);

G_MODULE_EXPORT gboolean linestack_traverse (
		struct linestack_context *,
		struct linestack_marker *from,
		struct linestack_marker *to, /* Can be NULL for 'now' */
		linestack_traverse_fn, 
		void *userdata);

G_MODULE_EXPORT gboolean linestack_traverse_object (
		struct linestack_context *,
		const char *object,
		struct linestack_marker *from,
		struct linestack_marker *to, /* Can be NULL for 'now' */
		linestack_traverse_fn,
		void *userdata);

G_MODULE_EXPORT gboolean linestack_send (
		struct linestack_context *,
		struct linestack_marker *from,
		struct linestack_marker *to, /* Can be NULL for 'now' */
		struct irc_client *, 
		gboolean dataonly, 
		gboolean timed,
		int time_offset);

G_MODULE_EXPORT gboolean linestack_send_object (
		struct linestack_context *,
		const char *object,
		struct linestack_marker *from,
		struct linestack_marker *to, /* Can be NULL for 'now' */
		struct irc_client *,
		gboolean dataonly,
		gboolean timed,
		int time_offset);

G_MODULE_EXPORT gboolean linestack_replay (
		struct linestack_context *,
		struct linestack_marker *from,
		struct linestack_marker *to,/* Can be NULL for 'now' */
		struct irc_network_state *st);

G_MODULE_EXPORT gboolean linestack_insert_line(
		struct linestack_context *, 
		const struct irc_line *l, 
		enum data_direction dir, 
		const struct irc_network_state *);

G_MODULE_EXPORT void linestack_free_marker(struct linestack_marker *);
G_MODULE_EXPORT struct linestack_marker *linestack_get_marker(struct linestack_context *);

/**
 * Create a new linestack context
 *
 * @param ops Linestack backend to use.
 * @param name Name of the network
 * @param cfg CtrlProxy configuration
 * @param state Current network state
 */
G_MODULE_EXPORT struct linestack_context *create_linestack(const struct linestack_ops *, const char *name, struct ctrlproxy_config *, const struct irc_network_state *);
G_MODULE_EXPORT void free_linestack_context(struct linestack_context *);
G_MODULE_EXPORT struct linestack_ops *linestack_find_ops(const char *name);

extern const struct linestack_ops linestack_file;

#endif /* __CTRLPROXY_LINESTACK_H__ */