Mercurial > pidgin.yaz
comparison libpurple/protocols/yahoo/yahoo_doodle.c @ 18769:cddf062baa71
Fix yahoo doodling to work with newer yahoo messenger clients. This breaks doodling with older Pidgin clients (trying to support both looked too painful). Fixes #1445.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 01 Aug 2007 22:38:47 +0000 |
parents | 9b2cd6920475 |
children | 44b4e8bd759b |
comparison
equal
deleted
inserted
replaced
18768:1b130825466c | 18769:cddf062baa71 |
---|---|
123 | 123 |
124 /* NOTE Perhaps some careful handling of remote assumed established | 124 /* NOTE Perhaps some careful handling of remote assumed established |
125 * sessions | 125 * sessions |
126 */ | 126 */ |
127 | 127 |
128 yahoo_doodle_command_send_ready(gc, to); | |
128 yahoo_doodle_command_send_request(gc, to); | 129 yahoo_doodle_command_send_request(gc, to); |
129 yahoo_doodle_command_send_ready(gc, to); | 130 |
130 | 131 } |
131 } | 132 |
132 | 133 static void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from) |
133 void yahoo_doodle_process(PurpleConnection *gc, const char *me, const char *from, | |
134 const char *command, const char *message) | |
135 { | |
136 if(!command) | |
137 return; | |
138 | |
139 /* Now check to see what sort of Doodle message it is */ | |
140 switch(atoi(command)) | |
141 { | |
142 case DOODLE_CMD_REQUEST: | |
143 yahoo_doodle_command_got_request(gc, from); | |
144 break; | |
145 | |
146 case DOODLE_CMD_READY: | |
147 yahoo_doodle_command_got_ready(gc, from); | |
148 break; | |
149 | |
150 case DOODLE_CMD_CLEAR: | |
151 yahoo_doodle_command_got_clear(gc, from); | |
152 break; | |
153 | |
154 case DOODLE_CMD_DRAW: | |
155 yahoo_doodle_command_got_draw(gc, from, message); | |
156 break; | |
157 | |
158 case DOODLE_CMD_EXTRA: | |
159 yahoo_doodle_command_got_extra(gc, from, message); | |
160 break; | |
161 | |
162 case DOODLE_CMD_CONFIRM: | |
163 yahoo_doodle_command_got_confirm(gc, from); | |
164 break; | |
165 } | |
166 } | |
167 | |
168 void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from) | |
169 { | 134 { |
170 PurpleAccount *account; | 135 PurpleAccount *account; |
171 PurpleWhiteboard *wb; | 136 PurpleWhiteboard *wb; |
172 | 137 |
173 purple_debug_info("yahoo", "doodle: Got Request (%s)\n", from); | 138 purple_debug_info("yahoo", "doodle: Got Request (%s)\n", from); |
195 dialog_message, NULL, NULL, NULL); | 160 dialog_message, NULL, NULL, NULL); |
196 */ | 161 */ |
197 | 162 |
198 purple_whiteboard_create(account, from, DOODLE_STATE_REQUESTED); | 163 purple_whiteboard_create(account, from, DOODLE_STATE_REQUESTED); |
199 | 164 |
200 yahoo_doodle_command_send_request(gc, from); | 165 yahoo_doodle_command_send_ready(gc, from); |
201 } | 166 } |
202 | 167 |
203 /* TODO Might be required to clear the canvas of an existing doodle | 168 /* TODO Might be required to clear the canvas of an existing doodle |
204 * session at this point | 169 * session at this point |
205 */ | 170 */ |
206 } | 171 } |
207 | 172 |
208 void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from) | 173 static void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from) |
209 { | 174 { |
210 PurpleAccount *account; | 175 PurpleAccount *account; |
211 PurpleWhiteboard *wb; | 176 PurpleWhiteboard *wb; |
212 | 177 |
213 purple_debug_info("yahoo", "doodle: Got Ready (%s)\n", from); | 178 purple_debug_info("yahoo", "doodle: Got Ready(%s)\n", from); |
214 | 179 |
215 account = purple_connection_get_account(gc); | 180 account = purple_connection_get_account(gc); |
216 | 181 |
217 /* Only handle this if local client requested Doodle session (else local | 182 /* Only handle this if local client requested Doodle session (else local |
218 * client would have sent one) | 183 * client would have sent one) |
228 | 193 |
229 wb->state = DOODLE_STATE_ESTABLISHED; | 194 wb->state = DOODLE_STATE_ESTABLISHED; |
230 | 195 |
231 yahoo_doodle_command_send_confirm(gc, from); | 196 yahoo_doodle_command_send_confirm(gc, from); |
232 } | 197 } |
233 | 198 else if(wb->state == DOODLE_STATE_ESTABLISHED) |
234 if(wb->state == DOODLE_STATE_ESTABLISHED) | |
235 { | 199 { |
236 /* TODO Ask whether to save picture too */ | 200 /* TODO Ask whether to save picture too */ |
237 purple_whiteboard_clear(wb); | 201 purple_whiteboard_clear(wb); |
238 } | 202 } |
239 | 203 |
240 /* NOTE Not sure about this... I am trying to handle if the remote user | 204 /* NOTE Not sure about this... I am trying to handle if the remote user |
241 * already thinks we're in a session with them (when their chat message | 205 * already thinks we're in a session with them (when their chat message |
242 * contains the doodle;11 imv key) | 206 * contains the doodle imv key) |
243 */ | 207 */ |
244 if(wb->state == DOODLE_STATE_REQUESTED) | 208 else if(wb->state == DOODLE_STATE_REQUESTED) |
245 { | 209 { |
246 /* purple_whiteboard_start(wb); */ | 210 /* purple_whiteboard_start(wb); */ |
247 yahoo_doodle_command_send_request(gc, from); | 211 yahoo_doodle_command_send_ready(gc, from); |
248 } | 212 } |
249 } | 213 } |
250 | 214 |
251 void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message) | 215 static void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message) |
252 { | 216 { |
253 PurpleAccount *account; | 217 PurpleAccount *account; |
254 PurpleWhiteboard *wb; | 218 PurpleWhiteboard *wb; |
255 char **tokens; | 219 char **tokens; |
256 int i; | 220 int i; |
302 /* goodle_doodle_session_set_canvas_as_icon(ds); */ | 266 /* goodle_doodle_session_set_canvas_as_icon(ds); */ |
303 | 267 |
304 g_list_free(d_list); | 268 g_list_free(d_list); |
305 } | 269 } |
306 | 270 |
307 void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from) | 271 |
272 static void yahoo_doodle_command_got_clear(PurpleConnection *gc, const char *from) | |
308 { | 273 { |
309 PurpleAccount *account; | 274 PurpleAccount *account; |
310 PurpleWhiteboard *wb; | 275 PurpleWhiteboard *wb; |
311 | 276 |
312 purple_debug_info("yahoo", "doodle: Got Clear (%s)\n", from); | 277 purple_debug_info("yahoo", "doodle: Got Clear (%s)\n", from); |
327 | 292 |
328 purple_whiteboard_clear(wb); | 293 purple_whiteboard_clear(wb); |
329 } | 294 } |
330 } | 295 } |
331 | 296 |
332 void | 297 |
298 static void | |
333 yahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message) | 299 yahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message) |
334 { | 300 { |
335 purple_debug_info("yahoo", "doodle: Got Extra (%s)\n", from); | 301 purple_debug_info("yahoo", "doodle: Got Extra (%s)\n", from); |
336 | 302 |
337 /* I do not like these 'extra' features, so I'll only handle them in one | 303 /* I do not like these 'extra' features, so I'll only handle them in one |
338 * way, which is returning them with the command/packet to turn them off | 304 * way, which is returning them with the command/packet to turn them off |
339 */ | 305 */ |
340 yahoo_doodle_command_send_extra(gc, from, DOODLE_EXTRA_NONE); | 306 yahoo_doodle_command_send_extra(gc, from, DOODLE_EXTRA_NONE); |
341 } | 307 } |
342 | 308 |
343 void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from) | 309 static void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from) |
344 { | 310 { |
345 PurpleAccount *account; | 311 PurpleAccount *account; |
346 PurpleWhiteboard *wb; | 312 PurpleWhiteboard *wb; |
347 | 313 |
348 purple_debug_info("yahoo", "doodle: Got Confirm (%s)\n", from); | 314 purple_debug_info("yahoo", "doodle: Got Confirm (%s)\n", from); |
359 return; | 325 return; |
360 | 326 |
361 /* TODO Combine the following IF's? */ | 327 /* TODO Combine the following IF's? */ |
362 | 328 |
363 /* Check if we requested a doodle session */ | 329 /* Check if we requested a doodle session */ |
364 if(wb->state == DOODLE_STATE_REQUESTING) | 330 /*if(wb->state == DOODLE_STATE_REQUESTING) |
365 { | 331 { |
366 wb->state = DOODLE_STATE_ESTABLISHED; | 332 wb->state = DOODLE_STATE_ESTABLISHED; |
367 | 333 |
368 purple_whiteboard_start(wb); | 334 purple_whiteboard_start(wb); |
369 | 335 |
370 yahoo_doodle_command_send_confirm(gc, from); | 336 yahoo_doodle_command_send_confirm(gc, from); |
371 } | 337 }*/ |
372 | 338 |
373 /* Check if we accepted a request for a doodle session */ | 339 /* Check if we accepted a request for a doodle session */ |
374 if(wb->state == DOODLE_STATE_REQUESTED) | 340 if(wb->state == DOODLE_STATE_REQUESTED) |
375 { | 341 { |
376 wb->state = DOODLE_STATE_ESTABLISHED; | 342 wb->state = DOODLE_STATE_ESTABLISHED; |
393 /* Only handle this if local client requested Doodle session (else local | 359 /* Only handle this if local client requested Doodle session (else local |
394 * client would have sent one) | 360 * client would have sent one) |
395 */ | 361 */ |
396 wb = purple_whiteboard_get_session(account, from); | 362 wb = purple_whiteboard_get_session(account, from); |
397 | 363 |
398 /* TODO Ask if user wants to save picture before the session is closed */ | |
399 | |
400 /* If this session doesn't exist, don't try and kill it */ | |
401 if(wb == NULL) | 364 if(wb == NULL) |
402 return; | 365 return; |
403 else | 366 |
404 { | 367 /* TODO Ask if user wants to save picture before the session is closed */ |
405 purple_whiteboard_destroy(wb); | 368 |
406 | 369 wb->state = DOODLE_STATE_CANCELED; |
407 /* yahoo_doodle_command_send_shutdown(gc, from); */ | 370 purple_whiteboard_destroy(wb); |
408 } | |
409 } | 371 } |
410 | 372 |
411 static void yahoo_doodle_command_send_generic(const char *type, | 373 static void yahoo_doodle_command_send_generic(const char *type, |
412 PurpleConnection *gc, | 374 PurpleConnection *gc, |
413 const char *to, | 375 const char *to, |
414 const char *message, | 376 const char *message, |
415 const char *thirteen, | 377 int command, |
416 const char *sixtythree, | 378 const char *imv, |
417 const char *sixtyfour) | 379 const char *sixtyfour) |
418 { | 380 { |
419 struct yahoo_data *yd; | 381 struct yahoo_data *yd; |
420 struct yahoo_packet *pkt; | 382 struct yahoo_packet *pkt; |
421 | 383 |
426 /* Make and send an acknowledge (ready) Doodle packet */ | 388 /* Make and send an acknowledge (ready) Doodle packet */ |
427 pkt = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0); | 389 pkt = yahoo_packet_new(YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0); |
428 yahoo_packet_hash_str(pkt, 49, "IMVIRONMENT"); | 390 yahoo_packet_hash_str(pkt, 49, "IMVIRONMENT"); |
429 yahoo_packet_hash_str(pkt, 1, purple_account_get_username(gc->account)); | 391 yahoo_packet_hash_str(pkt, 1, purple_account_get_username(gc->account)); |
430 yahoo_packet_hash_str(pkt, 14, message); | 392 yahoo_packet_hash_str(pkt, 14, message); |
431 yahoo_packet_hash_str(pkt, 13, thirteen); | 393 yahoo_packet_hash_int(pkt, 13, command); |
432 yahoo_packet_hash_str(pkt, 5, to); | 394 yahoo_packet_hash_str(pkt, 5, to); |
433 yahoo_packet_hash_str(pkt, 63, sixtythree ? sixtythree : "doodle;11"); | 395 yahoo_packet_hash_str(pkt, 63, imv ? imv : DOODLE_IMV_KEY); |
434 yahoo_packet_hash_str(pkt, 64, sixtyfour); | 396 yahoo_packet_hash_str(pkt, 64, sixtyfour); |
435 yahoo_packet_hash_str(pkt, 1002, "1"); | 397 yahoo_packet_hash_str(pkt, 1002, "1"); |
436 | 398 |
437 yahoo_packet_send_and_free(pkt, yd); | 399 yahoo_packet_send_and_free(pkt, yd); |
438 } | 400 } |
439 | 401 |
402 void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to) | |
403 { | |
404 yahoo_doodle_command_send_generic("Ready", gc, to, "1", DOODLE_CMD_READY, NULL, "1"); | |
405 } | |
406 | |
440 void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to) | 407 void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to) |
441 { | 408 { |
442 yahoo_doodle_command_send_generic("Request", gc, to, "1", "1", NULL, "1"); | 409 yahoo_doodle_command_send_generic("Request", gc, to, "", DOODLE_CMD_REQUEST, NULL, "0"); |
443 } | |
444 | |
445 void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to) | |
446 { | |
447 yahoo_doodle_command_send_generic("Ready", gc, to, "", "0", NULL, "0"); | |
448 } | 410 } |
449 | 411 |
450 void yahoo_doodle_command_send_draw(PurpleConnection *gc, const char *to, const char *message) | 412 void yahoo_doodle_command_send_draw(PurpleConnection *gc, const char *to, const char *message) |
451 { | 413 { |
452 yahoo_doodle_command_send_generic("Draw", gc, to, message, "3", NULL, "1"); | 414 yahoo_doodle_command_send_generic("Draw", gc, to, message, DOODLE_CMD_DRAW, NULL, "1"); |
453 } | 415 } |
454 | 416 |
455 void yahoo_doodle_command_send_clear(PurpleConnection *gc, const char *to) | 417 void yahoo_doodle_command_send_clear(PurpleConnection *gc, const char *to) |
456 { | 418 { |
457 yahoo_doodle_command_send_generic("Clear", gc, to, " ", "2", NULL, "1"); | 419 yahoo_doodle_command_send_generic("Clear", gc, to, " ", DOODLE_CMD_CLEAR, NULL, "1"); |
458 } | 420 } |
459 | 421 |
460 void yahoo_doodle_command_send_extra(PurpleConnection *gc, const char *to, const char *message) | 422 void yahoo_doodle_command_send_extra(PurpleConnection *gc, const char *to, const char *message) |
461 { | 423 { |
462 yahoo_doodle_command_send_generic("Extra", gc, to, message, "4", NULL, "1"); | 424 yahoo_doodle_command_send_generic("Extra", gc, to, message, DOODLE_CMD_EXTRA, NULL, "1"); |
463 } | 425 } |
464 | 426 |
465 void yahoo_doodle_command_send_confirm(PurpleConnection *gc, const char *to) | 427 void yahoo_doodle_command_send_confirm(PurpleConnection *gc, const char *to) |
466 { | 428 { |
467 yahoo_doodle_command_send_generic("Confirm", gc, to, "1", "5", NULL, "1"); | 429 yahoo_doodle_command_send_generic("Confirm", gc, to, "1", DOODLE_CMD_CONFIRM, NULL, "1"); |
468 } | 430 } |
469 | 431 |
470 void yahoo_doodle_command_send_shutdown(PurpleConnection *gc, const char *to) | 432 void yahoo_doodle_command_send_shutdown(PurpleConnection *gc, const char *to) |
471 { | 433 { |
472 yahoo_doodle_command_send_generic("Shutdown", gc, to, "", "0", ";0", "0"); | 434 yahoo_doodle_command_send_generic("Shutdown", gc, to, "", DOODLE_CMD_SHUTDOWN, ";0", "0"); |
473 } | 435 } |
474 | 436 |
475 void yahoo_doodle_start(PurpleWhiteboard *wb) | 437 void yahoo_doodle_start(PurpleWhiteboard *wb) |
476 { | 438 { |
477 doodle_session *ds = g_new0(doodle_session, 1); | 439 doodle_session *ds = g_new0(doodle_session, 1); |
489 { | 451 { |
490 PurpleConnection *gc = purple_account_get_connection(wb->account); | 452 PurpleConnection *gc = purple_account_get_connection(wb->account); |
491 | 453 |
492 /* g_debug_debug("yahoo", "doodle: yahoo_doodle_end()\n"); */ | 454 /* g_debug_debug("yahoo", "doodle: yahoo_doodle_end()\n"); */ |
493 | 455 |
494 if (gc) | 456 if (gc && wb->state != DOODLE_STATE_CANCELED) |
495 yahoo_doodle_command_send_shutdown(gc, wb->who); | 457 yahoo_doodle_command_send_shutdown(gc, wb->who); |
496 | 458 |
497 g_free(wb->proto_data); | 459 g_free(wb->proto_data); |
498 } | 460 } |
499 | 461 |
528 char *message; | 490 char *message; |
529 | 491 |
530 g_return_if_fail(draw_list != NULL); | 492 g_return_if_fail(draw_list != NULL); |
531 | 493 |
532 message = yahoo_doodle_build_draw_string(ds, draw_list); | 494 message = yahoo_doodle_build_draw_string(ds, draw_list); |
533 yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message); | 495 yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message); |
534 g_free(message); | 496 g_free(message); |
535 } | 497 } |
536 | 498 |
537 void yahoo_doodle_clear(PurpleWhiteboard *wb) | 499 void yahoo_doodle_clear(PurpleWhiteboard *wb) |
538 { | 500 { |
602 | 564 |
603 /* Notify the core about the changes */ | 565 /* Notify the core about the changes */ |
604 purple_whiteboard_set_brush(wb, size, color); | 566 purple_whiteboard_set_brush(wb, size, color); |
605 } | 567 } |
606 | 568 |
569 void yahoo_doodle_process(PurpleConnection *gc, const char *me, const char *from, | |
570 const char *command, const char *message) | |
571 { | |
572 if(!command) | |
573 return; | |
574 | |
575 /* Now check to see what sort of Doodle message it is */ | |
576 switch(atoi(command)) | |
577 { | |
578 case DOODLE_CMD_REQUEST: | |
579 yahoo_doodle_command_got_request(gc, from); | |
580 break; | |
581 | |
582 case DOODLE_CMD_READY: | |
583 yahoo_doodle_command_got_ready(gc, from); | |
584 break; | |
585 | |
586 case DOODLE_CMD_CLEAR: | |
587 yahoo_doodle_command_got_clear(gc, from); | |
588 break; | |
589 | |
590 case DOODLE_CMD_DRAW: | |
591 yahoo_doodle_command_got_draw(gc, from, message); | |
592 break; | |
593 | |
594 case DOODLE_CMD_EXTRA: | |
595 yahoo_doodle_command_got_extra(gc, from, message); | |
596 break; | |
597 | |
598 case DOODLE_CMD_CONFIRM: | |
599 yahoo_doodle_command_got_confirm(gc, from); | |
600 break; | |
601 } | |
602 } |