File: user.c

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 (105 lines) | stat: -rw-r--r-- 2,353 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
/*
	ctrlproxy: A modular IRC proxy
	(c) 2002-2006 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.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "internals.h"

static GList *load_notifies = NULL, *save_notifies = NULL;

void register_load_config_notify(config_load_notify_fn fn)
{
	load_notifies = g_list_append(load_notifies, fn);
}

void register_save_config_notify(config_save_notify_fn fn)
{
	save_notifies = g_list_append(save_notifies, fn);
}

void config_load_notify(struct global *global)
{
	GList *gl;
	for (gl = load_notifies; gl; gl = gl->next) {
		config_load_notify_fn fn = gl->data;

		fn(global);
	}
}

void config_save_notify(struct global *global, const char *dest)
{
	GList *gl;
	for (gl = save_notifies; gl; gl = gl->next) {
		config_save_notify_fn fn = gl->data;

		fn(global, dest);
	}
}

/* globals */
struct global *my_global;

struct global *init_global(void)
{
	struct global *global = g_new0(struct global, 1);

	return global;
}

struct global *load_global(const char *config_dir)
{
	struct global *global;
	struct ctrlproxy_config *cfg;
	cfg = load_configuration(config_dir);

	if (cfg == NULL)
		return NULL;

	global = init_global();
	global->config = cfg;

	load_networks(global, global->config);

	nickserv_load(global);

	config_load_notify(global);
	
	return global;
}

void free_listeners(struct global *global)
{
	while (global->listeners)
		free_listener((struct irc_listener *)global->listeners->data);
}

void free_global(struct global *global)
{
	if (global == NULL)
		return;
	free_listeners(global);
	fini_networks(global);
	if (global->config != NULL)
		free_config(global->config);
	global->config = NULL;
	fini_networks(global);
}