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 if (user->clientcaps != NULL)
|
|
59 g_hash_table_destroy(user->clientcaps);
|
|
60
|
|
61 if (user->group_ids != NULL)
|
|
62 g_list_free(user->group_ids);
|
|
63
|
|
64 if (user->msnobj != NULL)
|
|
65 msn_object_destroy(user->msnobj);
|
|
66
|
|
67 g_free(user->passport);
|
|
68 g_free(user->friendly_name);
|
|
69 g_free(user->store_name);
|
|
70 g_free(user->phone.home);
|
|
71 g_free(user->phone.work);
|
|
72 g_free(user->phone.mobile);
|
|
73
|
|
74 g_free(user);
|
|
75 }
|
|
76
|
|
77 void
|
|
78 msn_user_update(MsnUser *user)
|
|
79 {
|
|
80 GaimAccount *account;
|
|
81
|
|
82 account = user->userlist->session->account;
|
|
83
|
|
84 if (user->status != NULL)
|
|
85 gaim_prpl_got_user_status(account, user->passport, user->status, NULL);
|
|
86
|
|
87 if (user->idle)
|
|
88 gaim_prpl_got_user_idle(account, user->passport, TRUE, -1);
|
|
89 else
|
|
90 gaim_prpl_got_user_idle(account, user->passport, FALSE, 0);
|
|
91 }
|
|
92
|
|
93 void
|
|
94 msn_user_set_state(MsnUser *user, const char *state)
|
|
95 {
|
|
96 const char *status;
|
|
97
|
|
98 if (!g_ascii_strcasecmp(state, "BSY"))
|
|
99 status = "busy";
|
|
100 else if (!g_ascii_strcasecmp(state, "BRB"))
|
|
101 status = "brb";
|
|
102 else if (!g_ascii_strcasecmp(state, "AWY"))
|
|
103 status = "away";
|
|
104 else if (!g_ascii_strcasecmp(state, "PHN"))
|
|
105 status = "phone";
|
|
106 else if (!g_ascii_strcasecmp(state, "LUN"))
|
|
107 status = "lunch";
|
|
108 else
|
|
109 status = "available";
|
|
110
|
|
111 if (!g_ascii_strcasecmp(state, "IDL"))
|
|
112 user->idle = TRUE;
|
|
113 else
|
|
114 user->idle = FALSE;
|
|
115
|
|
116 user->status = status;
|
|
117 }
|
|
118
|
|
119 void
|
|
120 msn_user_set_passport(MsnUser *user, const char *passport)
|
|
121 {
|
|
122 g_return_if_fail(user != NULL);
|
|
123
|
|
124 g_free(user->passport);
|
|
125 user->passport = g_strdup(passport);
|
|
126 }
|
|
127
|
|
128 void
|
|
129 msn_user_set_friendly_name(MsnUser *user, const char *name)
|
|
130 {
|
|
131 g_return_if_fail(user != NULL);
|
|
132
|
|
133 g_free(user->friendly_name);
|
|
134 user->friendly_name = g_strdup(name);
|
|
135 }
|
|
136
|
|
137 void
|
|
138 msn_user_set_store_name(MsnUser *user, const char *name)
|
|
139 {
|
|
140 g_return_if_fail(user != NULL);
|
|
141
|
|
142 g_free(user->store_name);
|
|
143 user->store_name = g_strdup(name);
|
|
144 }
|
|
145
|
|
146 void
|
|
147 msn_user_set_buddy_icon(MsnUser *user, const char *filename)
|
|
148 {
|
|
149 struct stat st;
|
|
150 FILE *fp;
|
|
151 MsnObject *msnobj = msn_user_get_object(user);
|
|
152
|
|
153 g_return_if_fail(user != NULL);
|
|
154
|
|
155 if (filename == NULL || g_stat(filename, &st) == -1)
|
|
156 {
|
|
157 msn_user_set_object(user, NULL);
|
|
158 }
|
|
159 else if ((fp = g_fopen(filename, "rb")) != NULL)
|
|
160 {
|
|
161 GaimCipherContext *ctx;
|
|
162 char *buf;
|
|
163 gsize len;
|
|
164 char *base64;
|
|
165 unsigned char digest[20];
|
|
166
|
|
167 if (msnobj == NULL)
|
|
168 {
|
|
169 msnobj = msn_object_new();
|
|
170 msn_object_set_local(msnobj);
|
|
171 msn_object_set_type(msnobj, MSN_OBJECT_USERTILE);
|
|
172 msn_object_set_location(msnobj, "TFR2C2.tmp");
|
|
173 msn_object_set_creator(msnobj, msn_user_get_passport(user));
|
|
174
|
|
175 msn_user_set_object(user, msnobj);
|
|
176 }
|
|
177
|
|
178 msn_object_set_real_location(msnobj, filename);
|
|
179
|
|
180 buf = g_malloc(st.st_size);
|
|
181 len = fread(buf, 1, st.st_size, fp);
|
|
182
|
|
183 fclose(fp);
|
|
184
|
|
185 /* Compute the SHA1D field. */
|
|
186 memset(digest, 0, sizeof(digest));
|
|
187
|
|
188 ctx = gaim_cipher_context_new_by_name("sha1", NULL);
|
|
189 gaim_cipher_context_append(ctx, (const guchar *)buf, st.st_size);
|
|
190 gaim_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
|
|
191 g_free(buf);
|
|
192
|
|
193 base64 = gaim_base64_encode(digest, sizeof(digest));
|
|
194 msn_object_set_sha1d(msnobj, base64);
|
|
195 g_free(base64);
|
|
196
|
|
197 msn_object_set_size(msnobj, st.st_size);
|
|
198
|
|
199 /* Compute the SHA1C field. */
|
|
200 buf = g_strdup_printf(
|
|
201 "Creator%sSize%dType%dLocation%sFriendly%sSHA1D%s",
|
|
202 msn_object_get_creator(msnobj),
|
|
203 msn_object_get_size(msnobj),
|
|
204 msn_object_get_type(msnobj),
|
|
205 msn_object_get_location(msnobj),
|
|
206 msn_object_get_friendly(msnobj),
|
|
207 msn_object_get_sha1d(msnobj));
|
|
208
|
|
209 memset(digest, 0, sizeof(digest));
|
|
210
|
|
211 gaim_cipher_context_reset(ctx, NULL);
|
|
212 gaim_cipher_context_append(ctx, (const guchar *)buf, strlen(buf));
|
|
213 gaim_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
|
|
214 gaim_cipher_context_destroy(ctx);
|
|
215 g_free(buf);
|
|
216
|
|
217 base64 = gaim_base64_encode(digest, sizeof(digest));
|
|
218 msn_object_set_sha1c(msnobj, base64);
|
|
219 g_free(base64);
|
|
220 }
|
|
221 else
|
|
222 {
|
|
223 gaim_debug_error("msn", "Unable to open buddy icon %s!\n", filename);
|
|
224 msn_user_set_object(user, NULL);
|
|
225 }
|
|
226 }
|
|
227
|
|
228 void
|
|
229 msn_user_add_group_id(MsnUser *user, int id)
|
|
230 {
|
|
231 MsnUserList *userlist;
|
|
232 GaimAccount *account;
|
|
233 GaimBuddy *b;
|
|
234 GaimGroup *g;
|
|
235 const char *passport;
|
|
236 const char *group_name;
|
|
237
|
|
238 g_return_if_fail(user != NULL);
|
|
239 g_return_if_fail(id >= 0);
|
|
240
|
|
241 user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id));
|
|
242
|
|
243 userlist = user->userlist;
|
|
244 account = userlist->session->account;
|
|
245 passport = msn_user_get_passport(user);
|
|
246
|
|
247 group_name = msn_userlist_find_group_name(userlist, id);
|
|
248
|
|
249 g = gaim_find_group(group_name);
|
|
250
|
|
251 if ((id == 0) && (g == NULL))
|
|
252 {
|
|
253 g = gaim_group_new(group_name);
|
|
254 gaim_blist_add_group(g, NULL);
|
|
255 }
|
|
256
|
|
257 b = gaim_find_buddy_in_group(account, passport, g);
|
|
258
|
|
259 if (b == NULL)
|
|
260 {
|
|
261 b = gaim_buddy_new(account, passport, NULL);
|
|
262
|
|
263 gaim_blist_add_buddy(b, NULL, g, NULL);
|
|
264 }
|
|
265
|
|
266 b->proto_data = user;
|
|
267 }
|
|
268
|
|
269 void
|
|
270 msn_user_remove_group_id(MsnUser *user, int id)
|
|
271 {
|
|
272 g_return_if_fail(user != NULL);
|
|
273 g_return_if_fail(id >= 0);
|
|
274
|
|
275 user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id));
|
|
276 }
|
|
277
|
|
278 void
|
|
279 msn_user_set_home_phone(MsnUser *user, const char *number)
|
|
280 {
|
|
281 g_return_if_fail(user != NULL);
|
|
282
|
|
283 if (user->phone.home != NULL)
|
|
284 g_free(user->phone.home);
|
|
285
|
|
286 user->phone.home = (number == NULL ? NULL : g_strdup(number));
|
|
287 }
|
|
288
|
|
289 void
|
|
290 msn_user_set_work_phone(MsnUser *user, const char *number)
|
|
291 {
|
|
292 g_return_if_fail(user != NULL);
|
|
293
|
|
294 if (user->phone.work != NULL)
|
|
295 g_free(user->phone.work);
|
|
296
|
|
297 user->phone.work = (number == NULL ? NULL : g_strdup(number));
|
|
298 }
|
|
299
|
|
300 void
|
|
301 msn_user_set_mobile_phone(MsnUser *user, const char *number)
|
|
302 {
|
|
303 g_return_if_fail(user != NULL);
|
|
304
|
|
305 if (user->phone.mobile != NULL)
|
|
306 g_free(user->phone.mobile);
|
|
307
|
|
308 user->phone.mobile = (number == NULL ? NULL : g_strdup(number));
|
|
309 }
|
|
310
|
|
311 void
|
|
312 msn_user_set_object(MsnUser *user, MsnObject *obj)
|
|
313 {
|
|
314 g_return_if_fail(user != NULL);
|
|
315
|
|
316 if (user->msnobj != NULL)
|
|
317 msn_object_destroy(user->msnobj);
|
|
318
|
|
319 user->msnobj = obj;
|
|
320
|
|
321 if (user->list_op & MSN_LIST_FL_OP)
|
|
322 msn_queue_buddy_icon_request(user);
|
|
323 }
|
|
324
|
|
325 void
|
|
326 msn_user_set_client_caps(MsnUser *user, GHashTable *info)
|
|
327 {
|
|
328 g_return_if_fail(user != NULL);
|
|
329 g_return_if_fail(info != NULL);
|
|
330
|
|
331 if (user->clientcaps != NULL)
|
|
332 g_hash_table_destroy(user->clientcaps);
|
|
333
|
|
334 user->clientcaps = info;
|
|
335 }
|
|
336
|
|
337 const char *
|
|
338 msn_user_get_passport(const MsnUser *user)
|
|
339 {
|
|
340 g_return_val_if_fail(user != NULL, NULL);
|
|
341
|
|
342 return user->passport;
|
|
343 }
|
|
344
|
|
345 const char *
|
|
346 msn_user_get_friendly_name(const MsnUser *user)
|
|
347 {
|
|
348 g_return_val_if_fail(user != NULL, NULL);
|
|
349
|
|
350 return user->friendly_name;
|
|
351 }
|
|
352
|
|
353 const char *
|
|
354 msn_user_get_store_name(const MsnUser *user)
|
|
355 {
|
|
356 g_return_val_if_fail(user != NULL, NULL);
|
|
357
|
|
358 return user->store_name;
|
|
359 }
|
|
360
|
|
361 const char *
|
|
362 msn_user_get_home_phone(const MsnUser *user)
|
|
363 {
|
|
364 g_return_val_if_fail(user != NULL, NULL);
|
|
365
|
|
366 return user->phone.home;
|
|
367 }
|
|
368
|
|
369 const char *
|
|
370 msn_user_get_work_phone(const MsnUser *user)
|
|
371 {
|
|
372 g_return_val_if_fail(user != NULL, NULL);
|
|
373
|
|
374 return user->phone.work;
|
|
375 }
|
|
376
|
|
377 const char *
|
|
378 msn_user_get_mobile_phone(const MsnUser *user)
|
|
379 {
|
|
380 g_return_val_if_fail(user != NULL, NULL);
|
|
381
|
|
382 return user->phone.mobile;
|
|
383 }
|
|
384
|
|
385 MsnObject *
|
|
386 msn_user_get_object(const MsnUser *user)
|
|
387 {
|
|
388 g_return_val_if_fail(user != NULL, NULL);
|
|
389
|
|
390 return user->msnobj;
|
|
391 }
|
|
392
|
|
393 GHashTable *
|
|
394 msn_user_get_client_caps(const MsnUser *user)
|
|
395 {
|
|
396 g_return_val_if_fail(user != NULL, NULL);
|
|
397
|
|
398 return user->clientcaps;
|
|
399 }
|