Mercurial > pidgin
annotate src/protocols/msn/user.c @ 5326:9737d5ce9dcd
[gaim-migrate @ 5699]
The progress bar on connect no longer jumps back, and it now displays
"Retrieving buddy list," as requested by somebody (I forgot the name!) This
looks a little nicer.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Wed, 07 May 2003 08:42:47 +0000 |
| parents | d5690ed70085 |
| children | ebebc833cf77 |
| rev | line source |
|---|---|
| 5309 | 1 /** |
| 2 * @file user.c User functions | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 * | |
| 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 "user.h" | |
| 24 | |
| 25 MsnUser * | |
| 26 msn_user_new(MsnSession *session, const char *passport, const char *name) | |
| 27 { | |
| 28 MsnUser *user; | |
| 29 | |
| 30 user = msn_users_find_with_passport(session->users, passport); | |
| 31 | |
| 32 if (user != NULL) { | |
| 33 if (name != NULL) | |
| 34 msn_user_set_name(user, name); | |
| 35 | |
| 36 msn_user_ref(user); | |
| 37 | |
| 38 return user; | |
| 39 } | |
| 40 | |
| 41 user = g_new0(MsnUser, 1); | |
| 42 | |
| 43 user->session = session; | |
| 44 | |
| 45 if (name != NULL) | |
| 46 msn_user_set_name(user, name); | |
| 47 | |
| 48 msn_user_set_passport(user, passport); | |
| 49 msn_user_set_group_id(user, -1); | |
| 50 | |
| 51 msn_users_add(session->users, user); | |
| 52 | |
| 53 msn_user_ref(user); | |
| 54 | |
| 55 return user; | |
| 56 } | |
| 57 | |
| 58 void | |
| 59 msn_user_destroy(MsnUser *user) | |
| 60 { | |
| 61 g_return_if_fail(user != NULL); | |
| 62 | |
| 63 if (user->ref_count > 0) { | |
| 64 msn_user_unref(user); | |
| 65 | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 if (user->session != NULL && user->session->users != NULL) | |
| 70 msn_users_remove(user->session->users, user); | |
| 71 | |
|
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
72 if (user->clientinfo != NULL) |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
73 g_hash_table_destroy(user->clientinfo); |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
74 |
| 5309 | 75 if (user->passport != NULL) |
| 76 g_free(user->passport); | |
| 77 | |
| 78 if (user->name != NULL) | |
| 79 g_free(user->name); | |
| 80 | |
| 81 g_free(user); | |
| 82 } | |
| 83 | |
| 84 MsnUser * | |
| 85 msn_user_ref(MsnUser *user) | |
| 86 { | |
| 87 g_return_val_if_fail(user != NULL, NULL); | |
| 88 | |
| 89 user->ref_count++; | |
| 90 | |
| 91 return user; | |
| 92 } | |
| 93 | |
| 94 MsnUser * | |
| 95 msn_user_unref(MsnUser *user) | |
| 96 { | |
| 97 g_return_val_if_fail(user != NULL, NULL); | |
| 98 | |
| 99 if (user->ref_count <= 0) | |
| 100 return NULL; | |
| 101 | |
| 102 user->ref_count--; | |
| 103 | |
| 104 if (user->ref_count == 0) { | |
| 105 msn_user_destroy(user); | |
| 106 | |
| 107 return NULL; | |
| 108 } | |
| 109 | |
| 110 return user; | |
| 111 } | |
| 112 | |
| 113 void | |
| 114 msn_user_set_passport(MsnUser *user, const char *passport) | |
| 115 { | |
| 116 g_return_if_fail(user != NULL); | |
| 117 | |
| 118 if (user->passport != NULL) | |
| 119 g_free(user->passport); | |
| 120 | |
| 121 user->passport = g_strdup(passport); | |
| 122 } | |
| 123 | |
| 124 void | |
| 125 msn_user_set_name(MsnUser *user, const char *name) | |
| 126 { | |
| 127 g_return_if_fail(user != NULL); | |
| 128 | |
| 129 if (user->name != NULL) | |
| 130 g_free(user->name); | |
| 131 | |
| 132 user->name = g_strdup(name); | |
| 133 } | |
| 134 | |
| 135 void | |
| 136 msn_user_set_group_id(MsnUser *user, int id) | |
| 137 { | |
| 138 g_return_if_fail(user != NULL); | |
| 139 | |
| 140 user->group_id = id; | |
| 141 } | |
| 142 | |
| 143 const char * | |
| 144 msn_user_get_passport(const MsnUser *user) | |
| 145 { | |
| 146 g_return_val_if_fail(user != NULL, NULL); | |
| 147 | |
| 148 return user->passport; | |
| 149 } | |
| 150 | |
| 151 const char * | |
| 152 msn_user_get_name(const MsnUser *user) | |
| 153 { | |
| 154 g_return_val_if_fail(user != NULL, NULL); | |
| 155 | |
| 156 return user->name; | |
| 157 } | |
| 158 | |
| 159 int | |
| 160 msn_user_get_group_id(const MsnUser *user) | |
| 161 { | |
| 162 g_return_val_if_fail(user != NULL, -1); | |
| 163 | |
| 164 return user->group_id; | |
| 165 } | |
| 166 | |
|
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
167 void |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
168 msn_user_set_client_info(MsnUser *user, GHashTable *info) |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
169 { |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
170 g_return_if_fail(user != NULL); |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
171 g_return_if_fail(info != NULL); |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
172 |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
173 if (user->clientinfo != NULL) |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
174 g_hash_table_destroy(user->clientinfo); |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
175 |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
176 user->clientinfo = info; |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
177 } |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
178 |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
179 GHashTable * |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
180 msn_user_get_client_info(const MsnUser *user) |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
181 { |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
182 g_return_val_if_fail(user != NULL, NULL); |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
183 |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
184 return user->clientinfo; |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
185 } |
|
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
186 |
| 5309 | 187 MsnUsers * |
| 188 msn_users_new(void) | |
| 189 { | |
| 190 MsnUsers *users = g_new0(MsnUsers, 1); | |
| 191 | |
| 192 return users; | |
| 193 } | |
| 194 | |
| 195 void | |
| 196 msn_users_destroy(MsnUsers *users) | |
| 197 { | |
| 198 g_return_if_fail(users != NULL); | |
| 199 | |
| 200 while (users->users != NULL) | |
| 201 msn_user_destroy(users->users->data); | |
| 202 | |
| 203 /* See if we've leaked anybody. */ | |
| 204 while (users->users != NULL) { | |
| 205 gaim_debug(GAIM_DEBUG_WARNING, "msn", | |
| 206 "Leaking user %s\n", | |
| 207 msn_user_get_passport(users->users->data)); | |
| 208 } | |
| 209 | |
| 210 g_free(users); | |
| 211 } | |
| 212 | |
| 213 void | |
| 214 msn_users_add(MsnUsers *users, MsnUser *user) | |
| 215 { | |
| 216 g_return_if_fail(users != NULL); | |
| 217 g_return_if_fail(user != NULL); | |
| 218 | |
| 219 users->users = g_list_append(users->users, user); | |
| 220 } | |
| 221 | |
| 222 void | |
| 223 msn_users_remove(MsnUsers *users, MsnUser *user) | |
| 224 { | |
| 225 g_return_if_fail(users != NULL); | |
| 226 g_return_if_fail(user != NULL); | |
| 227 | |
| 228 users->users = g_list_remove(users->users, user); | |
| 229 } | |
| 230 | |
| 231 MsnUser * | |
| 232 msn_users_find_with_passport(MsnUsers *users, const char *passport) | |
| 233 { | |
| 234 GList *l; | |
| 235 | |
| 236 g_return_val_if_fail(users != NULL, NULL); | |
| 237 g_return_val_if_fail(passport != NULL, NULL); | |
| 238 | |
| 239 for (l = users->users; l != NULL; l = l->next) { | |
| 240 MsnUser *user = (MsnUser *)l->data; | |
| 241 | |
| 242 if (user->passport != NULL && | |
| 243 !g_ascii_strcasecmp(passport, user->passport)) { | |
| 244 | |
| 245 return user; | |
| 246 } | |
| 247 } | |
| 248 | |
| 249 return NULL; | |
| 250 } |
