Mercurial > pidgin
annotate src/protocols/msn/buddyicon.c @ 6800:8f228a7d5076
[gaim-migrate @ 7340]
Added what I have of MSNSLP in my tree. It's broken, and therefore
disabled, but I need to get this out so I can do other stuff too, and have
something to revert back to if I break something :)
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 10 Sep 2003 00:24:48 +0000 |
parents | 8efafdc38718 |
children |
rev | line source |
---|---|
5351 | 1 /** |
2 * @file buddyicon.c Buddy icon support | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
7 * |
5351 | 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 "buddyicon.h" | |
24 | |
25 #define PACKET_LENGTH 1500 | |
26 | |
5355
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
27 #define MAX_BUDDY_ICON_FILE_SIZE 8192 |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
28 |
5351 | 29 static const char alphabet[] = |
30 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
31 "0123456789+/"; | |
32 | |
33 static char * | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
34 base64_enc(const char *data, int len) |
5351 | 35 { |
36 char *dest; | |
37 char *buf; | |
38 | |
39 buf = dest = g_malloc(4 * len / 3 + 4); | |
40 | |
41 /* Encode 3 bytes at a time */ | |
42 while (len >= 3) { | |
43 buf[0] = alphabet[(data[0] >> 2) & 0x3F]; | |
44 buf[1] = alphabet[((data[0] << 4) & 0x30) | ((data[1] >> 4) & 0x0F)]; | |
45 buf[2] = alphabet[((data[1] << 2) & 0x3C) | ((data[2] >> 6) & 0x03)]; | |
46 buf[3] = alphabet[data[2] & 0x3F]; | |
47 data += 3; | |
48 buf += 4; | |
49 len -= 3; | |
50 } | |
51 | |
52 if (len > 0) { | |
53 buf[0] = alphabet[(data[0] >> 2) & 0x3F]; | |
54 buf[1] = alphabet[(data[0] << 4) & 0x30]; | |
55 | |
56 if (len > 1) { | |
57 buf[1] += (data[1] >> 4) & 0x0F; | |
58 buf[2] = alphabet[(data[1] << 2) & 0x3C]; | |
59 } | |
60 | |
61 else | |
62 buf[2] = '='; | |
63 | |
64 buf[3] = '='; | |
65 buf += 4; | |
66 } | |
67 | |
68 *buf = '\0'; | |
69 | |
70 return dest; | |
71 } | |
72 | |
73 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
74 get_buddy_icon_info(GaimAccount *account, char **base64, |
6478
338147ea6896
[gaim-migrate @ 6991]
Christian Hammond <chipx86@chipx86.com>
parents:
5793
diff
changeset
|
75 char **md5sum, size_t *file_size, size_t *base64_size) |
5351 | 76 { |
77 FILE *fp; | |
78 struct stat sb; | |
79 md5_state_t st; | |
80 md5_byte_t di[16]; | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
81 const char *icon; |
5351 | 82 |
83 if (base64 != NULL) *base64 = NULL; | |
84 if (md5sum != NULL) *md5sum = NULL; | |
85 if (file_size != NULL) *file_size = 0; | |
86 if (base64_size != NULL) *base64_size = 0; | |
87 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
88 icon = gaim_account_get_buddy_icon(account); |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
89 |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
90 if (!stat(icon, &sb)) { |
5351 | 91 if (file_size != NULL) |
92 *file_size = sb.st_size; | |
93 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
94 if ((fp = fopen(icon, "rb")) != NULL) { |
5351 | 95 char *buf = g_malloc(sb.st_size + 1); |
96 char *temp; | |
97 | |
98 fread(buf, 1, sb.st_size, fp); | |
99 | |
100 buf[sb.st_size] = '\0'; | |
101 | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
102 temp = base64_enc(buf, sb.st_size); |
5351 | 103 |
104 if (base64_size != NULL) | |
105 *base64_size = strlen(temp); | |
106 | |
107 if (base64 != NULL) | |
108 *base64 = temp; | |
109 else | |
110 g_free(temp); | |
111 | |
112 if (md5sum != NULL) { | |
113 char buf2[3]; | |
114 int i; | |
115 | |
116 md5_init(&st); | |
117 md5_append(&st, (const md5_byte_t *)buf, sb.st_size); | |
118 md5_finish(&st, di); | |
119 | |
120 *md5sum = g_new0(char, 33); | |
121 | |
122 for (i = 0; i < 16; i++) { | |
123 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
124 strcat(*md5sum, buf2); | |
125 } | |
126 } | |
127 | |
128 g_free(buf); | |
129 | |
130 fclose(fp); | |
131 } | |
132 else { | |
133 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
134 "Cannot open buddy icon file!\n"); | |
135 | |
136 return FALSE; | |
137 } | |
138 } | |
139 | |
140 return TRUE; | |
141 } | |
142 | |
143 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
144 send_icon_data(MsnSwitchBoard *swboard, MsnBuddyIconXfer *buddyicon) |
5351 | 145 { |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
146 GaimConnection *gc = swboard->servconn->session->account->gc; |
5351 | 147 char buf[MSN_BUF_LEN]; |
148 MsnMessage *msg; | |
149 int len; | |
150 | |
151 len = MIN(PACKET_LENGTH - 4, | |
152 buddyicon->total_size - buddyicon->bytes_xfer); | |
153 | |
154 strcpy(buf, "ICON"); | |
155 | |
156 strncat(buf, buddyicon->data + buddyicon->bytes_xfer, len); | |
157 | |
158 msg = msn_message_new(); | |
159 msn_message_set_content_type(msg, "application/x-buddyicon"); | |
160 msn_message_set_receiver(msg, buddyicon->user); | |
161 msn_message_set_charset(msg, NULL); | |
162 msn_message_set_attr(msg, "User-Agent", NULL); | |
163 | |
164 msn_message_set_body(msg, buf); | |
165 | |
166 if (!msn_switchboard_send_msg(swboard, msg)) { | |
167 msn_message_destroy(msg); | |
168 | |
169 msn_buddy_icon_xfer_destroy(swboard->buddy_icon_xfer); | |
170 swboard->buddy_icon_xfer = NULL; | |
171 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
172 gaim_connection_error(gc, _("Write error")); |
5351 | 173 |
174 return FALSE; | |
175 } | |
176 | |
177 msn_message_destroy(msg); | |
178 | |
179 buddyicon->bytes_xfer += len; | |
180 | |
181 if (buddyicon->bytes_xfer == buddyicon->total_size) { | |
182 msg = msn_message_new(); | |
183 msn_message_set_content_type(msg, "application/x-buddyicon"); | |
184 msn_message_set_receiver(msg, buddyicon->user); | |
185 msn_message_set_charset(msg, NULL); | |
186 msn_message_set_attr(msg, "User-Agent", NULL); | |
187 | |
188 msn_message_set_body(msg, "Command: COMPLETE\r\n"); | |
189 | |
190 msn_switchboard_send_msg(swboard, msg); | |
191 | |
192 msn_buddy_icon_xfer_destroy(swboard->buddy_icon_xfer); | |
193 swboard->buddy_icon_xfer = NULL; | |
194 } | |
195 | |
196 return TRUE; | |
197 } | |
198 | |
199 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
200 process_invite(MsnServConn *servconn, const MsnMessage *msg) |
5351 | 201 { |
202 MsnSession *session = servconn->session; | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
203 GaimConnection *gc = session->account->gc; |
5351 | 204 MsnMessage *new_msg; |
205 MsnSwitchBoard *swboard; | |
206 MsnBuddyIconXfer *buddyicon; | |
6695 | 207 GaimBuddy *b; |
5351 | 208 GHashTable *table; |
209 const char *command; | |
210 | |
211 table = msn_message_get_hashtable_from_body(msg); | |
212 | |
213 command = g_hash_table_lookup(table, "Command"); | |
214 | |
215 if (command == NULL) { | |
216 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
217 "Missing Command from buddy icon message.\n"); | |
218 return TRUE; | |
219 } | |
220 | |
221 if (!strcmp(command, "INVITE")) { | |
222 MsnUser *user; | |
223 const char *md5sum = g_hash_table_lookup(table, "MD5SUM"); | |
224 const char *size_s = g_hash_table_lookup(table, "File-Size"); | |
225 const char *base64_size_s = g_hash_table_lookup(table, "Base64-Size"); | |
226 const char *passport; | |
227 | |
228 if (md5sum == NULL) { | |
229 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
230 "Missing MD5SUM from buddy icon message.\n"); | |
231 | |
232 return TRUE; | |
233 } | |
234 | |
235 if (size_s == NULL) { | |
236 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
237 "Missing File-Size from buddy icon message.\n"); | |
238 | |
239 return TRUE; | |
240 } | |
241 | |
242 if (base64_size_s == NULL) { | |
243 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
244 "Missing Bas64-Size from buddy icon message.\n"); | |
245 | |
246 return TRUE; | |
247 } | |
248 | |
5355
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
249 if (atoi(size_s) > MAX_BUDDY_ICON_FILE_SIZE) { |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
250 gaim_debug(GAIM_DEBUG_ERROR, "msn", |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
251 "User tried to send a buddy icon over 8KB! " |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
252 "Not accepting."); |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
253 return TRUE; |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
254 } |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
255 |
5351 | 256 user = msn_message_get_sender(msg); |
257 | |
258 passport = msn_user_get_passport(user); | |
259 | |
260 /* See if we actually need a new icon. */ | |
261 if ((b = gaim_find_buddy(gc->account, passport)) != NULL) { | |
262 const char *cur_md5sum; | |
263 | |
264 cur_md5sum = gaim_buddy_get_setting(b, "icon_checksum"); | |
265 | |
266 if (cur_md5sum != NULL && !strcmp(cur_md5sum, md5sum)) | |
267 return TRUE; | |
268 } | |
269 | |
270 /* Send a request for transfer. */ | |
271 new_msg = msn_message_new(); | |
272 msn_message_set_content_type(new_msg, "application/x-buddyicon"); | |
273 msn_message_set_receiver(new_msg, user); | |
274 msn_message_set_charset(new_msg, NULL); | |
275 msn_message_set_attr(new_msg, "User-Agent", NULL); | |
276 | |
277 msn_message_set_body(new_msg, "Command: REQUEST\r\n"); | |
278 | |
279 if ((swboard = msn_session_open_switchboard(session)) == NULL) { | |
280 msn_message_destroy(new_msg); | |
281 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
282 gaim_connection_error(gc, _("Write error")); |
5351 | 283 |
284 return FALSE; | |
285 } | |
286 | |
287 swboard->hidden = TRUE; | |
288 msn_switchboard_set_user(swboard, user); | |
289 msn_switchboard_send_msg(swboard, new_msg); | |
290 | |
291 msn_message_destroy(new_msg); | |
292 | |
293 buddyicon = swboard->buddy_icon_xfer = msn_buddy_icon_xfer_new(); | |
294 | |
295 buddyicon->user = user; | |
296 msn_user_ref(buddyicon->user); | |
297 | |
298 buddyicon->md5sum = g_strdup(md5sum); | |
299 buddyicon->total_size = atoi(base64_size_s); | |
300 buddyicon->file_size = atoi(size_s); | |
301 | |
302 buddyicon->data = g_malloc(buddyicon->total_size + 1); | |
303 } | |
304 else if (!strcmp(command, "REQUEST")) { | |
305 swboard = (MsnSwitchBoard *)servconn->data; | |
306 | |
307 swboard->hidden = TRUE; | |
308 | |
309 swboard->buddy_icon_xfer = buddyicon = msn_buddy_icon_xfer_new(); | |
310 | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
311 if (!get_buddy_icon_info(gc->account, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
312 &buddyicon->data, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
313 &buddyicon->md5sum, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
314 &buddyicon->file_size, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
315 &buddyicon->total_size)) { |
5351 | 316 |
317 msn_buddy_icon_xfer_destroy(buddyicon); | |
318 | |
319 new_msg = msn_message_new(); | |
320 msn_message_set_content_type(new_msg, "application/x-buddyicon"); | |
321 msn_message_set_receiver(new_msg, msn_message_get_sender(msg)); | |
322 msn_message_set_charset(new_msg, NULL); | |
323 msn_message_set_attr(new_msg, "User-Agent", NULL); | |
324 | |
325 msn_message_set_body(new_msg, "Command: CANCEL\r\n"); | |
326 | |
327 if ((swboard = msn_session_open_switchboard(session)) == NULL) { | |
328 msn_message_destroy(new_msg); | |
329 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
330 gaim_connection_error(gc, _("Write error")); |
5351 | 331 |
332 return FALSE; | |
333 } | |
334 | |
335 swboard->hidden = TRUE; | |
336 | |
337 msn_switchboard_send_msg(swboard, new_msg); | |
338 | |
339 msn_message_destroy(new_msg); | |
340 | |
341 msn_switchboard_destroy(swboard); | |
342 } | |
343 | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
344 return send_icon_data(swboard, buddyicon); |
5351 | 345 } |
346 else if (!strcmp(command, "ACK")) { | |
347 swboard = (MsnSwitchBoard *)servconn->data; | |
348 | |
349 buddyicon = swboard->buddy_icon_xfer; | |
350 | |
351 if (buddyicon != NULL) | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
352 return send_icon_data(swboard, buddyicon); |
5351 | 353 } |
354 else if (!strcmp(command, "COMPLETE")) { | |
355 const char *passport; | |
356 char *icon; | |
357 int icon_len; | |
358 | |
359 swboard = (MsnSwitchBoard *)servconn->data; | |
360 | |
361 buddyicon = swboard->buddy_icon_xfer; | |
362 | |
363 passport = msn_user_get_passport(buddyicon->user); | |
364 swboard->hidden = TRUE; | |
365 | |
366 frombase64(buddyicon->data, &icon, &icon_len); | |
367 | |
368 if ((b = gaim_find_buddy(gc->account, passport)) != NULL) { | |
369 gaim_buddy_set_setting(b, "icon_checksum", buddyicon->md5sum); | |
370 gaim_blist_save(); | |
371 } | |
372 | |
373 set_icon_data(gc, passport, icon, icon_len); | |
374 | |
375 g_free(icon); | |
376 | |
377 msn_buddy_icon_xfer_destroy(swboard->buddy_icon_xfer); | |
378 swboard->buddy_icon_xfer = NULL; | |
379 | |
380 msn_switchboard_destroy(swboard); | |
381 } | |
382 else if (!strcmp(command, "CANCEL")) { | |
383 swboard = (MsnSwitchBoard *)servconn->data; | |
384 | |
385 msn_buddy_icon_xfer_destroy(swboard->buddy_icon_xfer); | |
386 swboard->buddy_icon_xfer = NULL; | |
387 | |
388 msn_switchboard_destroy(swboard); | |
389 } | |
390 else { | |
391 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
392 "Unknown buddy icon message command: %s\n", command); | |
393 } | |
394 | |
395 return TRUE; | |
396 } | |
397 | |
398 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
399 process_data(MsnServConn *servconn, const MsnMessage *msg) |
5351 | 400 { |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
401 GaimConnection *gc = servconn->session->account->gc; |
5351 | 402 MsnSwitchBoard *swboard; |
403 MsnBuddyIconXfer *buddyicon; | |
404 MsnMessage *ack_msg; | |
405 const char *data; | |
406 int len; | |
407 | |
408 swboard = (MsnSwitchBoard *)servconn->data; | |
409 buddyicon = swboard->buddy_icon_xfer; | |
410 | |
411 data = msn_message_get_body(msg) + 4; | |
412 | |
413 len = strlen(data); | |
414 | |
415 /* Copy the data into our buffer. */ | |
416 strncpy(buddyicon->data + buddyicon->bytes_xfer, data, | |
417 buddyicon->total_size - buddyicon->bytes_xfer); | |
418 | |
419 buddyicon->bytes_xfer += len; | |
420 | |
421 /* Acknowledge this data. */ | |
422 ack_msg = msn_message_new(); | |
423 msn_message_set_content_type(ack_msg, "application/x-buddyicon"); | |
424 msn_message_set_receiver(ack_msg, msn_message_get_sender(msg)); | |
425 msn_message_set_charset(ack_msg, NULL); | |
426 msn_message_set_attr(ack_msg, "User-Agent", NULL); | |
427 msn_message_set_body(ack_msg, "Command: ACK\r\n"); | |
428 | |
429 if (!msn_switchboard_send_msg(swboard, ack_msg)) { | |
430 msn_message_destroy(ack_msg); | |
431 | |
432 msn_buddy_icon_xfer_destroy(swboard->buddy_icon_xfer); | |
433 swboard->buddy_icon_xfer = NULL; | |
434 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
435 gaim_connection_error(gc, _("Write error")); |
5351 | 436 |
437 return FALSE; | |
438 } | |
439 | |
440 msn_message_destroy(ack_msg); | |
441 | |
442 return TRUE; | |
443 } | |
444 | |
445 MsnBuddyIconXfer * | |
446 msn_buddy_icon_xfer_new(void) | |
447 { | |
448 return g_new0(MsnBuddyIconXfer, 1); | |
449 } | |
450 | |
451 void | |
452 msn_buddy_icon_xfer_destroy(MsnBuddyIconXfer *xfer) | |
453 { | |
454 g_return_if_fail(xfer != NULL); | |
455 | |
456 if (xfer->user != NULL) | |
457 msn_user_unref(xfer->user); | |
458 | |
459 if (xfer->data != NULL) | |
460 g_free(xfer->data); | |
461 | |
462 g_free(xfer); | |
463 } | |
464 | |
465 gboolean | |
5506
4f72b611f0ee
[gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents:
5355
diff
changeset
|
466 msn_buddy_icon_msg(MsnServConn *servconn, MsnMessage *msg) |
5351 | 467 { |
468 if (!strncmp(msn_message_get_body(msg), "ICON", 4)) | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
469 return process_data(servconn, msg); |
5351 | 470 else |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
471 return process_invite(servconn, msg); |
5351 | 472 } |
473 | |
474 void | |
475 msn_buddy_icon_invite(MsnSwitchBoard *swboard) | |
476 { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
477 GaimAccount *account = swboard->servconn->session->account; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
478 GaimConnection *gc = account->gc; |
5351 | 479 MsnMessage *msg; |
480 char buf[MSN_BUF_LEN]; | |
481 char *md5sum; | |
482 int file_size, base64_size; | |
483 | |
484 g_return_if_fail(swboard != NULL); | |
485 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
486 if (gaim_account_get_buddy_icon(account) == NULL) |
5351 | 487 return; /* We don't have an icon to send. */ |
488 | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
489 if (!get_buddy_icon_info(account, NULL, &md5sum, |
6786
8efafdc38718
[gaim-migrate @ 7325]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
490 &file_size, &base64_size)) |
8efafdc38718
[gaim-migrate @ 7325]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
491 { |
5351 | 492 return; |
493 } | |
494 | |
6786
8efafdc38718
[gaim-migrate @ 7325]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
495 if (file_size > MAX_BUDDY_ICON_FILE_SIZE) |
8efafdc38718
[gaim-migrate @ 7325]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
496 { |
5355
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
497 gaim_debug(GAIM_DEBUG_ERROR, "msn", |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
498 "The buddy icon is too large to send. Must be no more " |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
499 "than %d bytes!\n", MAX_BUDDY_ICON_FILE_SIZE); |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
500 return; |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
501 } |
6a57fd9b45e1
[gaim-migrate @ 5731]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
502 |
5351 | 503 msg = msn_message_new(); |
504 msn_message_set_content_type(msg, "application/x-buddyicon"); | |
505 msn_message_set_receiver(msg, msn_message_get_sender(msg)); | |
506 msn_message_set_charset(msg, NULL); | |
507 msn_message_set_attr(msg, "User-Agent", NULL); | |
508 | |
509 g_snprintf(buf, sizeof(buf), | |
510 "Command: INVITE\r\n" | |
511 "MD5SUM: %s\r\n" | |
512 "File-Size: %d\r\n" | |
513 "Base64-Size: %d\r\n", | |
514 md5sum, file_size, base64_size); | |
515 | |
516 g_free(md5sum); | |
517 | |
518 msn_message_set_body(msg, buf); | |
519 | |
520 if (!msn_switchboard_send_msg(swboard, msg)) { | |
521 msn_message_destroy(msg); | |
522 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5506
diff
changeset
|
523 gaim_connection_error(gc, _("Write error")); |
5351 | 524 |
525 return; | |
526 } | |
527 | |
528 msn_message_destroy(msg); | |
529 } |