Mercurial > pidgin
comparison src/protocols/msn/user.c @ 9193:502707ca1836
[gaim-migrate @ 9988]
Patch by Felipe Contreras to add MSN file transfer and buddy icons. Please
test and report any bugs!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 06 Jun 2004 02:39:08 +0000 |
parents | 06f57183e29f |
children | ab6636c5a136 |
comparison
equal
deleted
inserted
replaced
9192:5655dcd94d0f | 9193:502707ca1836 |
---|---|
21 */ | 21 */ |
22 #include "msn.h" | 22 #include "msn.h" |
23 #include "user.h" | 23 #include "user.h" |
24 | 24 |
25 MsnUser * | 25 MsnUser * |
26 msn_user_new(MsnSession *session, const char *passport, const char *name) | 26 msn_user_new(MsnUserList *userlist, const char *passport, |
27 const char *store_name) | |
27 { | 28 { |
28 MsnUser *user; | 29 MsnUser *user; |
29 | 30 |
30 user = msn_users_find_with_passport(session->users, passport); | 31 user = g_new0(MsnUser, 1); |
31 | 32 |
32 if (user == NULL) | 33 user->userlist = userlist; |
33 { | 34 |
34 user = g_new0(MsnUser, 1); | 35 msn_user_set_passport(user, passport); |
35 | |
36 user->session = session; | |
37 | |
38 msn_user_set_passport(user, passport); | |
39 | |
40 msn_users_add(session->users, user); | |
41 } | |
42 | 36 |
43 /* | 37 /* |
44 * XXX This seems to reset the friendly name from what it should be | 38 * XXX This seems to reset the friendly name from what it should be |
45 * to the passport when moving users. So, screw it :) | 39 * to the passport when moving users. So, screw it :) |
46 */ | 40 */ |
47 #if 0 | 41 #if 0 |
48 if (name != NULL) | 42 if (name != NULL) |
49 msn_user_set_name(user, name); | 43 msn_user_set_name(user, name); |
50 #endif | 44 #endif |
51 | 45 |
52 msn_user_ref(user); | |
53 | |
54 return user; | 46 return user; |
55 } | 47 } |
56 | 48 |
57 void | 49 void |
58 msn_user_destroy(MsnUser *user) | 50 msn_user_destroy(MsnUser *user) |
59 { | 51 { |
60 g_return_if_fail(user != NULL); | 52 g_return_if_fail(user != NULL); |
61 | |
62 if (user->ref_count > 0) { | |
63 msn_user_unref(user); | |
64 | |
65 return; | |
66 } | |
67 | |
68 if (user->session != NULL && user->session->users != NULL) | |
69 msn_users_remove(user->session->users, user); | |
70 | 53 |
71 if (user->clientcaps != NULL) | 54 if (user->clientcaps != NULL) |
72 g_hash_table_destroy(user->clientcaps); | 55 g_hash_table_destroy(user->clientcaps); |
73 | 56 |
74 if (user->group_ids != NULL) | 57 if (user->group_ids != NULL) |
75 g_list_free(user->group_ids); | 58 g_list_free(user->group_ids); |
76 | 59 |
77 if (user->msnobj != NULL) | 60 if (user->msnobj != NULL) |
78 msn_object_destroy(user->msnobj); | 61 msn_object_destroy(user->msnobj); |
79 | 62 |
80 if (user->passport != NULL) g_free(user->passport); | |
81 if (user->name != NULL) g_free(user->name); | |
82 | |
83 if (user->phone.home != NULL) g_free(user->phone.home); | |
84 if (user->phone.work != NULL) g_free(user->phone.work); | |
85 if (user->phone.mobile != NULL) g_free(user->phone.mobile); | |
86 | |
87 g_free(user); | |
88 } | |
89 | |
90 MsnUser * | |
91 msn_user_ref(MsnUser *user) | |
92 { | |
93 g_return_val_if_fail(user != NULL, NULL); | |
94 | |
95 user->ref_count++; | |
96 | |
97 return user; | |
98 } | |
99 | |
100 MsnUser * | |
101 msn_user_unref(MsnUser *user) | |
102 { | |
103 g_return_val_if_fail(user != NULL, NULL); | |
104 | |
105 if (user->ref_count <= 0) | |
106 return NULL; | |
107 | |
108 user->ref_count--; | |
109 | |
110 if (user->ref_count == 0) { | |
111 msn_user_destroy(user); | |
112 | |
113 return NULL; | |
114 } | |
115 | |
116 return user; | |
117 } | |
118 | |
119 void | |
120 msn_user_set_passport(MsnUser *user, const char *passport) | |
121 { | |
122 g_return_if_fail(user != NULL); | |
123 | |
124 if (user->passport != NULL) | 63 if (user->passport != NULL) |
125 g_free(user->passport); | 64 g_free(user->passport); |
126 | 65 |
66 if (user->friendly_name != NULL) | |
67 g_free(user->friendly_name); | |
68 | |
69 if (user->store_name != NULL) | |
70 g_free(user->store_name); | |
71 | |
72 if (user->phone.home != NULL) | |
73 g_free(user->phone.home); | |
74 | |
75 if (user->phone.work != NULL) | |
76 g_free(user->phone.work); | |
77 | |
78 if (user->phone.mobile != NULL) | |
79 g_free(user->phone.mobile); | |
80 | |
81 g_free(user); | |
82 } | |
83 | |
84 void | |
85 msn_user_set_passport(MsnUser *user, const char *passport) | |
86 { | |
87 g_return_if_fail(user != NULL); | |
88 | |
89 if (user->passport != NULL) | |
90 g_free(user->passport); | |
91 | |
127 user->passport = g_strdup(passport); | 92 user->passport = g_strdup(passport); |
128 } | 93 } |
129 | 94 |
130 void | 95 void |
131 msn_user_set_name(MsnUser *user, const char *name) | 96 msn_user_set_friendly_name(MsnUser *user, const char *name) |
132 { | 97 { |
133 g_return_if_fail(user != NULL); | 98 g_return_if_fail(user != NULL); |
134 | 99 |
135 if (user->name != NULL) | 100 if (user->friendly_name != NULL) |
136 g_free(user->name); | 101 g_free(user->friendly_name); |
137 | 102 |
138 user->name = g_strdup(name); | 103 user->friendly_name = g_strdup(name); |
104 } | |
105 | |
106 void | |
107 msn_user_set_store_name(MsnUser *user, const char *name) | |
108 { | |
109 g_return_if_fail(user != NULL); | |
110 | |
111 if (user->store_name != NULL) | |
112 g_free(user->store_name); | |
113 | |
114 user->store_name = g_strdup(name); | |
139 } | 115 } |
140 | 116 |
141 void | 117 void |
142 msn_user_set_buddy_icon(MsnUser *user, const char *filename) | 118 msn_user_set_buddy_icon(MsnUser *user, const char *filename) |
143 { | 119 { |
146 MsnObject *msnobj = msn_user_get_object(user); | 122 MsnObject *msnobj = msn_user_get_object(user); |
147 | 123 |
148 g_return_if_fail(user != NULL); | 124 g_return_if_fail(user != NULL); |
149 | 125 |
150 if (filename == NULL || stat(filename, &st) == -1) | 126 if (filename == NULL || stat(filename, &st) == -1) |
127 { | |
151 msn_user_set_object(user, NULL); | 128 msn_user_set_object(user, NULL); |
129 } | |
152 else if ((fp = fopen(filename, "rb")) != NULL) | 130 else if ((fp = fopen(filename, "rb")) != NULL) |
153 { | 131 { |
154 unsigned char *buf; | 132 unsigned char *buf; |
155 SHA_CTX ctx; | 133 SHA_CTX ctx; |
156 size_t len; | 134 gsize len; |
157 char *base64; | 135 char *base64; |
158 unsigned char digest[20]; | 136 unsigned char digest[20]; |
159 | 137 |
160 if (msnobj == NULL) | 138 if (msnobj == NULL) |
161 { | 139 { |
162 msnobj = msn_object_new(); | 140 msnobj = msn_object_new(TRUE); |
141 msn_object_set_local(msnobj); | |
163 msn_object_set_type(msnobj, MSN_OBJECT_USERTILE); | 142 msn_object_set_type(msnobj, MSN_OBJECT_USERTILE); |
164 msn_object_set_location(msnobj, "TFR2C.tmp"); | 143 msn_object_set_location(msnobj, "TFR2C2.tmp"); |
165 msn_object_set_creator(msnobj, msn_user_get_passport(user)); | 144 msn_object_set_creator(msnobj, msn_user_get_passport(user)); |
166 | 145 |
167 msn_user_set_object(user, msnobj); | 146 msn_user_set_object(user, msnobj); |
168 } | 147 } |
148 | |
149 msn_object_set_real_location(msnobj, filename); | |
169 | 150 |
170 buf = g_malloc(st.st_size); | 151 buf = g_malloc(st.st_size); |
171 len = fread(buf, 1, st.st_size, fp); | 152 len = fread(buf, 1, st.st_size, fp); |
172 | 153 |
173 fclose(fp); | 154 fclose(fp); |
213 msn_user_set_object(user, NULL); | 194 msn_user_set_object(user, NULL); |
214 } | 195 } |
215 } | 196 } |
216 | 197 |
217 void | 198 void |
218 msn_user_set_group_ids(MsnUser *user, GList *ids) | |
219 { | |
220 g_return_if_fail(user != NULL); | |
221 | |
222 user->group_ids = ids; | |
223 } | |
224 | |
225 void | |
226 msn_user_add_group_id(MsnUser *user, int id) | 199 msn_user_add_group_id(MsnUser *user, int id) |
227 { | 200 { |
201 MsnUserList *userlist; | |
202 GaimAccount *account; | |
203 GaimBuddy *b; | |
204 GaimGroup *g; | |
205 const char *passport; | |
206 const char *group_name; | |
207 | |
228 g_return_if_fail(user != NULL); | 208 g_return_if_fail(user != NULL); |
229 g_return_if_fail(id > -1); | 209 g_return_if_fail(id > -1); |
230 | 210 |
231 if (!g_list_find(user->group_ids, GINT_TO_POINTER(id))) | 211 user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id)); |
232 user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id)); | 212 |
213 userlist = user->userlist; | |
214 account = userlist->session->account; | |
215 passport = msn_user_get_passport(user); | |
216 | |
217 group_name = msn_userlist_find_group_name(userlist, id); | |
218 | |
219 g = gaim_find_group(group_name); | |
220 | |
221 b = gaim_find_buddy_in_group(account, passport, g); | |
222 | |
223 if (b == NULL) | |
224 { | |
225 b = gaim_buddy_new(account, passport, NULL); | |
226 | |
227 gaim_blist_add_buddy(b, NULL, g, NULL); | |
228 } | |
229 | |
230 b->proto_data = user; | |
233 } | 231 } |
234 | 232 |
235 void | 233 void |
236 msn_user_remove_group_id(MsnUser *user, int id) | 234 msn_user_remove_group_id(MsnUser *user, int id) |
237 { | 235 { |
238 g_return_if_fail(user != NULL); | 236 g_return_if_fail(user != NULL); |
239 g_return_if_fail(id > -1); | 237 g_return_if_fail(id > -1); |
240 | 238 |
241 user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id)); | 239 user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id)); |
242 } | 240 } |
241 | |
243 void | 242 void |
244 msn_user_set_home_phone(MsnUser *user, const char *number) | 243 msn_user_set_home_phone(MsnUser *user, const char *number) |
245 { | 244 { |
246 g_return_if_fail(user != NULL); | 245 g_return_if_fail(user != NULL); |
247 | 246 |
280 | 279 |
281 if (user->msnobj != NULL) | 280 if (user->msnobj != NULL) |
282 msn_object_destroy(user->msnobj); | 281 msn_object_destroy(user->msnobj); |
283 | 282 |
284 user->msnobj = obj; | 283 user->msnobj = obj; |
284 | |
285 if (user->list_op & MSN_LIST_FL_OP) | |
286 { | |
287 /* TODO: I think we need better buddy icon core functions */ | |
288 GaimAccount *account; | |
289 const char *username; | |
290 | |
291 account = user->userlist->session->account; | |
292 username = msn_object_get_creator(obj);; | |
293 | |
294 if (gaim_find_conversation_with_account(username, account) != NULL) | |
295 msn_request_buddy_icon(account->gc, username); | |
296 } | |
285 } | 297 } |
286 | 298 |
287 void | 299 void |
288 msn_user_set_client_caps(MsnUser *user, GHashTable *info) | 300 msn_user_set_client_caps(MsnUser *user, GHashTable *info) |
289 { | 301 { |
303 | 315 |
304 return user->passport; | 316 return user->passport; |
305 } | 317 } |
306 | 318 |
307 const char * | 319 const char * |
308 msn_user_get_name(const MsnUser *user) | 320 msn_user_get_friendly_name(const MsnUser *user) |
309 { | 321 { |
310 g_return_val_if_fail(user != NULL, NULL); | 322 g_return_val_if_fail(user != NULL, NULL); |
311 | 323 |
312 return user->name; | 324 return user->friendly_name; |
313 } | 325 } |
314 | 326 |
315 GList * | 327 const char * |
316 msn_user_get_group_ids(const MsnUser *user) | 328 msn_user_get_store_name(const MsnUser *user) |
317 { | 329 { |
318 g_return_val_if_fail(user != NULL, NULL); | 330 g_return_val_if_fail(user != NULL, NULL); |
319 | 331 |
320 return user->group_ids; | 332 return user->store_name; |
321 } | 333 } |
322 | 334 |
323 const char * | 335 const char * |
324 msn_user_get_home_phone(const MsnUser *user) | 336 msn_user_get_home_phone(const MsnUser *user) |
325 { | 337 { |
357 { | 369 { |
358 g_return_val_if_fail(user != NULL, NULL); | 370 g_return_val_if_fail(user != NULL, NULL); |
359 | 371 |
360 return user->clientcaps; | 372 return user->clientcaps; |
361 } | 373 } |
362 | |
363 MsnUsers * | |
364 msn_users_new(void) | |
365 { | |
366 MsnUsers *users = g_new0(MsnUsers, 1); | |
367 | |
368 return users; | |
369 } | |
370 | |
371 void | |
372 msn_users_destroy(MsnUsers *users) | |
373 { | |
374 GList *l, *l_next = NULL; | |
375 | |
376 g_return_if_fail(users != NULL); | |
377 | |
378 for (l = users->users; l != NULL; l = l_next) { | |
379 l_next = l->next; | |
380 | |
381 msn_user_destroy(l->data); | |
382 | |
383 users->users = g_list_remove(users->users, l->data); | |
384 } | |
385 | |
386 g_free(users); | |
387 } | |
388 | |
389 void | |
390 msn_users_add(MsnUsers *users, MsnUser *user) | |
391 { | |
392 g_return_if_fail(users != NULL); | |
393 g_return_if_fail(user != NULL); | |
394 | |
395 users->users = g_list_append(users->users, user); | |
396 | |
397 users->count++; | |
398 } | |
399 | |
400 void | |
401 msn_users_remove(MsnUsers *users, MsnUser *user) | |
402 { | |
403 g_return_if_fail(users != NULL); | |
404 g_return_if_fail(user != NULL); | |
405 | |
406 users->users = g_list_remove(users->users, user); | |
407 | |
408 users->count--; | |
409 } | |
410 | |
411 size_t | |
412 msn_users_get_count(const MsnUsers *users) | |
413 { | |
414 g_return_val_if_fail(users != NULL, 0); | |
415 | |
416 return users->count; | |
417 } | |
418 | |
419 MsnUser * | |
420 msn_users_find_with_passport(MsnUsers *users, const char *passport) | |
421 { | |
422 GList *l; | |
423 | |
424 g_return_val_if_fail(users != NULL, NULL); | |
425 g_return_val_if_fail(passport != NULL, NULL); | |
426 | |
427 for (l = users->users; l != NULL; l = l->next) { | |
428 MsnUser *user = (MsnUser *)l->data; | |
429 | |
430 if (user->passport != NULL && | |
431 !g_ascii_strcasecmp(passport, user->passport)) { | |
432 | |
433 return user; | |
434 } | |
435 } | |
436 | |
437 return NULL; | |
438 } |