14192
|
1 /**
|
|
2 * @file user.c User functions
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Gaim is the legal property of its developers, whose names are too numerous
|
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
8 * source distribution.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * This program is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 */
|
|
24 #include "msn.h"
|
|
25 #include "user.h"
|
|
26 #include "slp.h"
|
|
27
|
|
28 MsnUser *
|
|
29 msn_user_new(MsnUserList *userlist, const char *passport,
|
|
30 const char *store_name)
|
|
31 {
|
|
32 MsnUser *user;
|
|
33
|
|
34 user = g_new0(MsnUser, 1);
|
|
35
|
|
36 user->userlist = userlist;
|
|
37
|
|
38 msn_user_set_passport(user, passport);
|
|
39 msn_user_set_store_name(user, store_name);
|
|
40
|
|
41 /*
|
|
42 * XXX This seems to reset the friendly name from what it should be
|
|
43 * to the passport when moving users. So, screw it :)
|
|
44 */
|
|
45 #if 0
|
|
46 if (name != NULL)
|
|
47 msn_user_set_name(user, name);
|
|
48 #endif
|
|
49
|
|
50 return user;
|
|
51 }
|
|
52
|
|
53 void
|
|
54 msn_user_destroy(MsnUser *user)
|
|
55 {
|
|
56 g_return_if_fail(user != NULL);
|
|
57
|
|
58 /*
|
|
59 * TODO: If any GaimBuddy->proto_data pointers point to this
|
|
60 * MsnUser then set them to NULL. Or possibly even better,
|
|
61 * don't set GaimBuddy->proto_data in the first place.
|
|
62 */
|
|
63
|
|
64 if (user->clientcaps != NULL)
|
|
65 g_hash_table_destroy(user->clientcaps);
|
|
66
|
|
67 if (user->group_ids != NULL)
|
|
68 g_list_free(user->group_ids);
|
|
69
|
|
70 if (user->msnobj != NULL)
|
|
71 msn_object_destroy(user->msnobj);
|
|
72
|
|
73 g_free(user->passport);
|
|
74 g_free(user->friendly_name);
|
|
75 g_free(user->store_name);
|
|
76 g_free(user->phone.home);
|
|
77 g_free(user->phone.work);
|
|
78 g_free(user->phone.mobile);
|
|
79
|
|
80 g_free(user);
|
|
81 }
|
|
82
|
|
83 void
|
|
84 msn_user_update(MsnUser *user)
|
|
85 {
|
|
86 GaimAccount *account;
|
|
87
|
|
88 account = user->userlist->session->account;
|
|
89
|
|
90 if (user->status != NULL)
|
|
91 gaim_prpl_got_user_status(account, user->passport, user->status, NULL);
|
|
92
|
|
93 if (user->idle)
|
|
94 gaim_prpl_got_user_idle(account, user->passport, TRUE, -1);
|
|
95 else
|
|
96 gaim_prpl_got_user_idle(account, user->passport, FALSE, 0);
|
|
97 }
|
|
98
|
|
99 void
|
|
100 msn_user_set_state(MsnUser *user, const char *state)
|
|
101 {
|
|
102 const char *status;
|
|
103
|
|
104 if (!g_ascii_strcasecmp(state, "BSY"))
|
|
105 status = "busy";
|
|
106 else if (!g_ascii_strcasecmp(state, "BRB"))
|
|
107 status = "brb";
|
|
108 else if (!g_ascii_strcasecmp(state, "AWY"))
|
|
109 status = "away";
|
|
110 else if (!g_ascii_strcasecmp(state, "PHN"))
|
|
111 status = "phone";
|
|
112 else if (!g_ascii_strcasecmp(state, "LUN"))
|
|
113 status = "lunch";
|
|
114 else
|
|
115 status = "available";
|
|
116
|
|
117 if (!g_ascii_strcasecmp(state, "IDL"))
|
|
118 user->idle = TRUE;
|
|
119 else
|
|
120 user->idle = FALSE;
|
|
121
|
|
122 user->status = status;
|
|
123 }
|
|
124
|
|
125 void
|
|
126 msn_user_set_passport(MsnUser *user, const char *passport)
|
|
127 {
|
|
128 g_return_if_fail(user != NULL);
|
|
129
|
|
130 g_free(user->passport);
|
|
131 user->passport = g_strdup(passport);
|
|
132 }
|
|
133
|
|
134 void
|
|
135 msn_user_set_friendly_name(MsnUser *user, const char *name)
|
|
136 {
|
|
137 g_return_if_fail(user != NULL);
|
|
138
|
|
139 g_free(user->friendly_name);
|
|
140 user->friendly_name = g_strdup(name);
|
|
141 }
|
|
142
|
|
143 void
|
|
144 msn_user_set_store_name(MsnUser *user, const char *name)
|
|
145 {
|
|
146 g_return_if_fail(user != NULL);
|
|
147
|
|
148 g_free(user->store_name);
|
|
149 user->store_name = g_strdup(name);
|
|
150 }
|
|
151
|
|
152 void
|
|
153 msn_user_set_buddy_icon(MsnUser *user, const char *filename)
|
|
154 {
|
|
155 struct stat st;
|
|
156 FILE *fp;
|
|
157 MsnObject *msnobj = msn_user_get_object(user);
|
|
158
|
|
159 g_return_if_fail(user != NULL);
|
|
160
|
|
161 if (filename == NULL || g_stat(filename, &st) == -1)
|
|
162 {
|
|
163 msn_user_set_object(user, NULL);
|
|
164 }
|
|
165 else if ((fp = g_fopen(filename, "rb")) != NULL)
|
|
166 {
|
|
167 GaimCipherContext *ctx;
|
|
168 char *buf;
|
|
169 gsize len;
|
|
170 char *base64;
|
|
171 unsigned char digest[20];
|
|
172
|
|
173 if (msnobj == NULL)
|
|
174 {
|
|
175 msnobj = msn_object_new();
|
|
176 msn_object_set_local(msnobj);
|
|
177 msn_object_set_type(msnobj, MSN_OBJECT_USERTILE);
|
|
178 msn_object_set_location(msnobj, "TFR2C2.tmp");
|
|
179 msn_object_set_creator(msnobj, msn_user_get_passport(user));
|
|
180
|
|
181 msn_user_set_object(user, msnobj);
|
|
182 }
|
|
183
|
|
184 msn_object_set_real_location(msnobj, filename);
|
|
185
|
|
186 buf = g_malloc(st.st_size);
|
|
187 len = fread(buf, 1, st.st_size, fp);
|
|
188
|
|
189 fclose(fp);
|
|
190
|
|
191 /* Compute the SHA1D field. */
|
|
192 memset(digest, 0, sizeof(digest));
|
|
193
|
|
194 ctx = gaim_cipher_context_new_by_name("sha1", NULL);
|
|
195 gaim_cipher_context_append(ctx, (const guchar *)buf, st.st_size);
|
|
196 gaim_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
|
|
197 g_free(buf);
|
|
198
|
|
199 base64 = gaim_base64_encode(digest, sizeof(digest));
|
|
200 msn_object_set_sha1d(msnobj, base64);
|
|
201 g_free(base64);
|
|
202
|
|
203 msn_object_set_size(msnobj, st.st_size);
|
|
204
|
|
205 /* Compute the SHA1C field. */
|
|
206 buf = g_strdup_printf(
|
|
207 "Creator%sSize%dType%dLocation%sFriendly%sSHA1D%s",
|
|
208 msn_object_get_creator(msnobj),
|
|
209 msn_object_get_size(msnobj),
|
|
210 msn_object_get_type(msnobj),
|
|
211 msn_object_get_location(msnobj),
|
|
212 msn_object_get_friendly(msnobj),
|
|
213 msn_object_get_sha1d(msnobj));
|
|
214
|
|
215 memset(digest, 0, sizeof(digest));
|
|
216
|
|
217 gaim_cipher_context_reset(ctx, NULL);
|
|
218 gaim_cipher_context_append(ctx, (const guchar *)buf, strlen(buf));
|
|
219 gaim_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
|
|
220 gaim_cipher_context_destroy(ctx);
|
|
221 g_free(buf);
|
|
222
|
|
223 base64 = gaim_base64_encode(digest, sizeof(digest));
|
|
224 msn_object_set_sha1c(msnobj, base64);
|
|
225 g_free(base64);
|
|
226 }
|
|
227 else
|
|
228 {
|
|
229 gaim_debug_error("msn", "Unable to open buddy icon %s!\n", filename);
|
|
230 msn_user_set_object(user, NULL);
|
|
231 }
|
|
232 }
|
|
233
|
|
234 void
|
|
235 msn_user_add_group_id(MsnUser *user, int id)
|
|
236 {
|
|
237 MsnUserList *userlist;
|
|
238 GaimAccount *account;
|
|
239 GaimBuddy *b;
|
|
240 GaimGroup *g;
|
|
241 const char *passport;
|
|
242 const char *group_name;
|
|
243
|
|
244 g_return_if_fail(user != NULL);
|
|
245 g_return_if_fail(id >= 0);
|
|
246
|
|
247 user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id));
|
|
248
|
|
249 userlist = user->userlist;
|
|
250 account = userlist->session->account;
|
|
251 passport = msn_user_get_passport(user);
|
|
252
|
|
253 group_name = msn_userlist_find_group_name(userlist, id);
|
|
254
|
|
255 g = gaim_find_group(group_name);
|
|
256
|
|
257 if ((id == 0) && (g == NULL))
|
|
258 {
|
|
259 g = gaim_group_new(group_name);
|
|
260 gaim_blist_add_group(g, NULL);
|
|
261 }
|
|
262
|
|
263 b = gaim_find_buddy_in_group(account, passport, g);
|
|
264
|
|
265 if (b == NULL)
|
|
266 {
|
|
267 b = gaim_buddy_new(account, passport, NULL);
|
|
268
|
|
269 gaim_blist_add_buddy(b, NULL, g, NULL);
|
|
270 }
|
|
271
|
|
272 b->proto_data = user;
|
|
273 }
|
|
274
|
|
275 void
|
|
276 msn_user_remove_group_id(MsnUser *user, int id)
|
|
277 {
|
|
278 g_return_if_fail(user != NULL);
|
|
279 g_return_if_fail(id >= 0);
|
|
280
|
|
281 user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id));
|
|
282 }
|
|
283
|
|
284 void
|
|
285 msn_user_set_home_phone(MsnUser *user, const char *number)
|
|
286 {
|
|
287 g_return_if_fail(user != NULL);
|
|
288
|
|
289 if (user->phone.home != NULL)
|
|
290 g_free(user->phone.home);
|
|
291
|
|
292 user->phone.home = (number == NULL ? NULL : g_strdup(number));
|
|
293 }
|
|
294
|
|
295 void
|
|
296 msn_user_set_work_phone(MsnUser *user, const char *number)
|
|
297 {
|
|
298 g_return_if_fail(user != NULL);
|
|
299
|
|
300 if (user->phone.work != NULL)
|
|
301 g_free(user->phone.work);
|
|
302
|
|
303 user->phone.work = (number == NULL ? NULL : g_strdup(number));
|
|
304 }
|
|
305
|
|
306 void
|
|
307 msn_user_set_mobile_phone(MsnUser *user, const char *number)
|
|
308 {
|
|
309 g_return_if_fail(user != NULL);
|
|
310
|
|
311 if (user->phone.mobile != NULL)
|
|
312 g_free(user->phone.mobile);
|
|
313
|
|
314 user->phone.mobile = (number == NULL ? NULL : g_strdup(number));
|
|
315 }
|
|
316
|
|
317 void
|
|
318 msn_user_set_object(MsnUser *user, MsnObject *obj)
|
|
319 {
|
|
320 g_return_if_fail(user != NULL);
|
|
321
|
|
322 if (user->msnobj != NULL)
|
|
323 msn_object_destroy(user->msnobj);
|
|
324
|
|
325 user->msnobj = obj;
|
|
326
|
|
327 if (user->list_op & MSN_LIST_FL_OP)
|
|
328 msn_queue_buddy_icon_request(user);
|
|
329 }
|
|
330
|
|
331 void
|
|
332 msn_user_set_client_caps(MsnUser *user, GHashTable *info)
|
|
333 {
|
|
334 g_return_if_fail(user != NULL);
|
|
335 g_return_if_fail(info != NULL);
|
|
336
|
|
337 if (user->clientcaps != NULL)
|
|
338 g_hash_table_destroy(user->clientcaps);
|
|
339
|
|
340 user->clientcaps = info;
|
|
341 }
|
|
342
|
|
343 const char *
|
|
344 msn_user_get_passport(const MsnUser *user)
|
|
345 {
|
|
346 g_return_val_if_fail(user != NULL, NULL);
|
|
347
|
|
348 return user->passport;
|
|
349 }
|
|
350
|
|
351 const char *
|
|
352 msn_user_get_friendly_name(const MsnUser *user)
|
|
353 {
|
|
354 g_return_val_if_fail(user != NULL, NULL);
|
|
355
|
|
356 return user->friendly_name;
|
|
357 }
|
|
358
|
|
359 const char *
|
|
360 msn_user_get_store_name(const MsnUser *user)
|
|
361 {
|
|
362 g_return_val_if_fail(user != NULL, NULL);
|
|
363
|
|
364 return user->store_name;
|
|
365 }
|
|
366
|
|
367 const char *
|
|
368 msn_user_get_home_phone(const MsnUser *user)
|
|
369 {
|
|
370 g_return_val_if_fail(user != NULL, NULL);
|
|
371
|
|
372 return user->phone.home;
|
|
373 }
|
|
374
|
|
375 const char *
|
|
376 msn_user_get_work_phone(const MsnUser *user)
|
|
377 {
|
|
378 g_return_val_if_fail(user != NULL, NULL);
|
|
379
|
|
380 return user->phone.work;
|
|
381 }
|
|
382
|
|
383 const char *
|
|
384 msn_user_get_mobile_phone(const MsnUser *user)
|
|
385 {
|
|
386 g_return_val_if_fail(user != NULL, NULL);
|
|
387
|
|
388 return user->phone.mobile;
|
|
389 }
|
|
390
|
|
391 MsnObject *
|
|
392 msn_user_get_object(const MsnUser *user)
|
|
393 {
|
|
394 g_return_val_if_fail(user != NULL, NULL);
|
|
395
|
|
396 return user->msnobj;
|
|
397 }
|
|
398
|
|
399 GHashTable *
|
|
400 msn_user_get_client_caps(const MsnUser *user)
|
|
401 {
|
|
402 g_return_val_if_fail(user != NULL, NULL);
|
|
403
|
|
404 return user->clientcaps;
|
|
405 }
|