Mercurial > pidgin
annotate src/protocols/msn/group.c @ 8658:4133c85d76f7
[gaim-migrate @ 9410]
Fix the problem mentioned on gaim-devel:
"Crash when 'Log your own signons/idleness/awayness' is on and a
connection is cancelled while connecting"
There is a flaw in Gaim here.
"You have signed on" can be written to the system log before "You have
signed off." This happens when you disconnect an account while it is
connected. It's an extremely minor problem and I don't feel like
fixing it.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 14 Apr 2004 04:04:42 +0000 |
parents | 06f57183e29f |
children | 502707ca1836 |
rev | line source |
---|---|
5518 | 1 /** |
2 * @file group.c Group functions | |
3 * | |
4 * gaim | |
5 * | |
8475
06f57183e29f
[gaim-migrate @ 9208]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
6 * Copyright (C) 2003-2004 Christian Hammond <chipx86@gnupdate.org> |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5518
diff
changeset
|
7 * |
5518 | 8 * This program is free software; you can redistribute it and/or modify |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "msn.h" | |
23 #include "group.h" | |
24 | |
25 MsnGroup * | |
26 msn_group_new(MsnSession *session, int id, const char *name) | |
27 { | |
28 MsnGroup *group; | |
29 | |
30 g_return_val_if_fail(session != NULL, NULL); | |
31 g_return_val_if_fail(id >= 0, NULL); | |
32 g_return_val_if_fail(name != NULL, NULL); | |
33 | |
34 group = msn_groups_find_with_id(session->groups, id); | |
35 | |
36 if (group == NULL) { | |
37 group = g_new0(MsnGroup, 1); | |
38 | |
39 group->session = session; | |
40 group->id = id; | |
41 group->name = g_strdup(name); | |
42 group->users = msn_users_new(); | |
43 } | |
44 | |
45 msn_group_ref(group); | |
46 | |
47 return group; | |
48 } | |
49 | |
50 void | |
51 msn_group_destroy(MsnGroup *group) | |
52 { | |
53 g_return_if_fail(group != NULL); | |
54 | |
55 if (group->ref_count > 0) { | |
56 msn_group_unref(group); | |
57 | |
58 return; | |
59 } | |
60 | |
61 if (group->session != NULL && group->session->groups != NULL) | |
62 msn_groups_remove(group->session->groups, group); | |
63 | |
64 msn_users_destroy(group->users); | |
65 | |
66 g_free(group->name); | |
67 g_free(group); | |
68 } | |
69 | |
70 MsnGroup * | |
71 msn_group_ref(MsnGroup *group) | |
72 { | |
73 g_return_val_if_fail(group != NULL, NULL); | |
74 | |
75 group->ref_count++; | |
76 | |
77 return group; | |
78 } | |
79 | |
80 MsnGroup * | |
81 msn_group_unref(MsnGroup *group) | |
82 { | |
83 g_return_val_if_fail(group != NULL, NULL); | |
84 | |
85 if (group->ref_count <= 0) | |
86 return NULL; | |
87 | |
88 group->ref_count--; | |
89 | |
90 if (group->ref_count == 0) { | |
91 msn_group_destroy(group); | |
92 | |
93 return NULL; | |
94 } | |
95 | |
96 return group; | |
97 } | |
98 | |
99 void | |
100 msn_group_set_id(MsnGroup *group, int id) | |
101 { | |
102 g_return_if_fail(group != NULL); | |
103 g_return_if_fail(id >= 0); | |
104 | |
105 group->id = id; | |
106 } | |
107 | |
108 void | |
109 msn_group_set_name(MsnGroup *group, const char *name) | |
110 { | |
111 g_return_if_fail(group != NULL); | |
112 g_return_if_fail(name != NULL); | |
113 | |
114 if (group->name != NULL) | |
115 g_free(group->name); | |
116 | |
117 group->name = g_strdup(name); | |
118 } | |
119 | |
120 int | |
121 msn_group_get_id(const MsnGroup *group) | |
122 { | |
123 g_return_val_if_fail(group != NULL, -1); | |
124 | |
125 return group->id; | |
126 } | |
127 | |
128 const char * | |
129 msn_group_get_name(const MsnGroup *group) | |
130 { | |
131 g_return_val_if_fail(group != NULL, NULL); | |
132 | |
133 return group->name; | |
134 } | |
135 | |
136 void | |
137 msn_group_add_user(MsnGroup *group, MsnUser *user) | |
138 { | |
139 g_return_if_fail(group != NULL); | |
140 g_return_if_fail(user != NULL); | |
141 | |
142 msn_users_add(group->users, user); | |
143 | |
144 msn_user_ref(user); | |
145 | |
146 gaim_debug(GAIM_DEBUG_INFO, "msn", "Adding user %s to group %s (%d)\n", | |
147 msn_user_get_passport(user), msn_group_get_name(group), | |
148 msn_group_get_id(group)); | |
149 } | |
150 | |
151 void | |
152 msn_group_remove_user(MsnGroup *group, MsnUser *user) | |
153 { | |
154 g_return_if_fail(group != NULL); | |
155 g_return_if_fail(user != NULL); | |
156 | |
157 msn_users_remove(group->users, user); | |
158 | |
159 msn_user_unref(user); | |
160 } | |
161 | |
162 MsnUsers * | |
163 msn_group_get_users(const MsnGroup *group) | |
164 { | |
165 g_return_val_if_fail(group != NULL, NULL); | |
166 | |
167 return group->users; | |
168 } | |
169 | |
170 | |
171 MsnGroups * | |
172 msn_groups_new(void) | |
173 { | |
174 return g_new0(MsnGroups, 1); | |
175 } | |
176 | |
177 void | |
178 msn_groups_destroy(MsnGroups *groups) | |
179 { | |
180 g_return_if_fail(groups != NULL); | |
181 | |
182 while (groups->groups != NULL) | |
183 msn_group_destroy(groups->groups->data); | |
184 | |
185 /* See if we've leaked anybody. */ | |
186 while (groups->groups != NULL) { | |
187 gaim_debug(GAIM_DEBUG_WARNING, "msn", | |
188 "Leaking group %s (id %d)\n", | |
189 msn_group_get_name(groups->groups->data), | |
190 msn_group_get_id(groups->groups->data)); | |
191 } | |
192 | |
193 g_free(groups); | |
194 } | |
195 | |
196 void | |
197 msn_groups_add(MsnGroups *groups, MsnGroup *group) | |
198 { | |
199 g_return_if_fail(groups != NULL); | |
200 g_return_if_fail(group != NULL); | |
201 | |
202 groups->groups = g_list_append(groups->groups, group); | |
203 | |
204 groups->count++; | |
205 | |
206 gaim_debug(GAIM_DEBUG_INFO, "msn", "Adding group %s (%d)\n", | |
207 msn_group_get_name(group), msn_group_get_id(group)); | |
208 } | |
209 | |
210 void | |
211 msn_groups_remove(MsnGroups *groups, MsnGroup *group) | |
212 { | |
213 g_return_if_fail(groups != NULL); | |
214 g_return_if_fail(group != NULL); | |
215 | |
216 gaim_debug(GAIM_DEBUG_INFO, "msn", "Removing group %s (%d)\n", | |
217 msn_group_get_name(group), msn_group_get_id(group)); | |
218 | |
219 groups->groups = g_list_remove(groups->groups, group); | |
220 | |
221 groups->count--; | |
222 } | |
223 | |
224 size_t | |
225 msn_groups_get_count(const MsnGroups *groups) | |
226 { | |
227 g_return_val_if_fail(groups != NULL, 0); | |
228 | |
229 return groups->count; | |
230 } | |
231 | |
232 GList * | |
233 msn_groups_get_list(const MsnGroups *groups) | |
234 { | |
235 g_return_val_if_fail(groups != NULL, NULL); | |
236 | |
237 return groups->groups; | |
238 } | |
239 | |
240 MsnGroup * | |
241 msn_groups_find_with_id(MsnGroups *groups, int id) | |
242 { | |
243 GList *l; | |
244 | |
245 g_return_val_if_fail(groups != NULL, NULL); | |
246 g_return_val_if_fail(id >= 0, NULL); | |
247 | |
248 for (l = groups->groups; l != NULL; l = l->next) { | |
249 MsnGroup *group = l->data; | |
250 | |
251 if (group->id == id) | |
252 return group; | |
253 } | |
254 | |
255 return NULL; | |
256 } | |
257 | |
258 MsnGroup * | |
259 msn_groups_find_with_name(MsnGroups *groups, const char *name) | |
260 { | |
261 GList *l; | |
262 | |
263 g_return_val_if_fail(groups != NULL, NULL); | |
264 g_return_val_if_fail(name != NULL, NULL); | |
265 | |
266 for (l = groups->groups; l != NULL; l = l->next) { | |
267 MsnGroup *group = l->data; | |
268 | |
269 if (group->name != NULL && !g_ascii_strcasecmp(name, group->name)) | |
270 return group; | |
271 } | |
272 | |
273 return NULL; | |
274 } |