File: gen_config.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 (97 lines) | stat: -rw-r--r-- 2,493 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
/*
	ctrlproxy: A modular IRC proxy
	(c) 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.
*/

#include "internals.h"

static struct channel_config *config_find_channel(struct irc_network_info *ni, struct network_config *nc, const char *name)
{
	GList *gl;

	g_assert(ni);
	g_assert(nc);
	g_assert(name);
	
	for (gl = nc->channels; gl; gl = gl->next) {
		struct channel_config *cc = gl->data;

		g_assert(cc->name);

		if (!irccmp(ni, cc->name, name))
			return cc;
	}

	return NULL;
}

void network_update_config(struct irc_network_state *ns, struct network_config *nc)
{
	GList *gl;

	if (ns == NULL)
		return;

	/* Network name */
	if (ns->info->name != NULL && 
		(nc->name == NULL || strcmp(ns->info->name, nc->name) != 0)) {
		g_free(nc->name);
		nc->name = g_strdup(ns->info->name);
	}
	
	/* nick */
	g_free(nc->nick);
	nc->nick = g_strdup(ns->me.nick);

	for (gl = nc->channels; gl; gl = gl->next) {
		struct channel_config *cc = gl->data;

		cc->autojoin = FALSE;
	}

	for (gl = ns->channels; gl; gl = gl->next) {
		struct irc_channel_state *cs = gl->data;
		struct channel_config *cc;

		/* Find channel */
		cc = config_find_channel(ns->info, nc, cs->name);
		if (!cc) {
			cc = g_new0(struct channel_config, 1);
			cc->name = g_strdup(cs->name);
			nc->channels = g_list_append(nc->channels, cc);
		}
		g_free(cc->key); 
		cc->key = NULL;
		if (cs->key) 
			cc->key = g_strdup(cs->key);
		cc->autojoin = TRUE;
	}
}

void global_update_config(struct global *my_global)
{
	GList *gl;
	for (gl = my_global->networks; gl; gl = gl->next) {
		struct irc_network *n = gl->data;
		struct network_config *nc = n->private_data;
	
		nc->autoconnect = (n->connection.state != NETWORK_CONNECTION_STATE_NOT_CONNECTED);

		if (n->connection.state == NETWORK_CONNECTION_STATE_MOTD_RECVD)
			network_update_config(n->state, nc);
	}
}