comparison libpurple/protocols/yahoo/yahoo_doodle.c @ 20254:f379a2e9e939

applied changes from 80e3a515775c28b61c4c155c4a524374ef3360ff through 45dd8a34b6dda68660a7f026677c9478247610ad
author Richard Laager <rlaager@wiktel.com>
date Fri, 28 Sep 2007 16:58:29 +0000
parents 44b4e8bd759b
children 9656dbf35fb0
comparison
equal deleted inserted replaced
20253:6f4defb6f399 20254:f379a2e9e939
116 if(wb == NULL) 116 if(wb == NULL)
117 { 117 {
118 /* Insert this 'session' in the list. At this point, it's only a 118 /* Insert this 'session' in the list. At this point, it's only a
119 * requested session. 119 * requested session.
120 */ 120 */
121 purple_whiteboard_create(account, to, DOODLE_STATE_REQUESTING); 121 wb = purple_whiteboard_create(account, to, DOODLE_STATE_REQUESTING);
122 } 122 }
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_ready(gc, to, DOODLE_IMV_KEY);
129 yahoo_doodle_command_send_request(gc, to); 129 yahoo_doodle_command_send_request(gc, to, DOODLE_IMV_KEY);
130 130
131 } 131 }
132 132
133 static void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from) 133 static void yahoo_doodle_command_got_request(PurpleConnection *gc, const char *from, const char *imv_key)
134 { 134 {
135 PurpleAccount *account; 135 PurpleAccount *account;
136 PurpleWhiteboard *wb; 136 PurpleWhiteboard *wb;
137 137
138 purple_debug_info("yahoo", "doodle: Got Request (%s)\n", from); 138 purple_debug_info("yahoo", "doodle: Got Request (%s)\n", from);
145 wb = purple_whiteboard_get_session(account, from); 145 wb = purple_whiteboard_get_session(account, from);
146 146
147 /* If a session with the remote user doesn't exist */ 147 /* If a session with the remote user doesn't exist */
148 if(wb == NULL) 148 if(wb == NULL)
149 { 149 {
150 doodle_session *ds;
150 /* Ask user if they wish to accept the request for a doodle session */ 151 /* Ask user if they wish to accept the request for a doodle session */
151 /* TODO Ask local user to start Doodle session with remote user */ 152 /* TODO Ask local user to start Doodle session with remote user */
152 /* NOTE This if/else statement won't work right--must use dialog 153 /* NOTE This if/else statement won't work right--must use dialog
153 * results 154 * results
154 */ 155 */
158 159
159 purple_notify_message(NULL, PURPLE_NOTIFY_MSG_INFO, "Doodle", 160 purple_notify_message(NULL, PURPLE_NOTIFY_MSG_INFO, "Doodle",
160 dialog_message, NULL, NULL, NULL); 161 dialog_message, NULL, NULL, NULL);
161 */ 162 */
162 163
163 purple_whiteboard_create(account, from, DOODLE_STATE_REQUESTED); 164 wb = purple_whiteboard_create(account, from, DOODLE_STATE_REQUESTED);
164 165 ds = wb->proto_data;
165 yahoo_doodle_command_send_ready(gc, from); 166 ds->imv_key = g_strdup(imv_key);
167
168 yahoo_doodle_command_send_ready(gc, from, imv_key);
166 } 169 }
167 170
168 /* TODO Might be required to clear the canvas of an existing doodle 171 /* TODO Might be required to clear the canvas of an existing doodle
169 * session at this point 172 * session at this point
170 */ 173 */
171 } 174 }
172 175
173 static void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from) 176 static void yahoo_doodle_command_got_ready(PurpleConnection *gc, const char *from, const char *imv_key)
174 { 177 {
175 PurpleAccount *account; 178 PurpleAccount *account;
176 PurpleWhiteboard *wb; 179 PurpleWhiteboard *wb;
177 180
178 purple_debug_info("yahoo", "doodle: Got Ready(%s)\n", from); 181 purple_debug_info("yahoo", "doodle: Got Ready(%s)\n", from);
187 if(wb == NULL) 190 if(wb == NULL)
188 return; 191 return;
189 192
190 if(wb->state == DOODLE_STATE_REQUESTING) 193 if(wb->state == DOODLE_STATE_REQUESTING)
191 { 194 {
195 doodle_session *ds = wb->proto_data;
192 purple_whiteboard_start(wb); 196 purple_whiteboard_start(wb);
193 197
194 wb->state = DOODLE_STATE_ESTABLISHED; 198 wb->state = DOODLE_STATE_ESTABLISHED;
195 199
196 yahoo_doodle_command_send_confirm(gc, from); 200 yahoo_doodle_command_send_confirm(gc, from, imv_key);
201 /* Let's steal the imv_key and reuse it */
202 g_free(ds->imv_key);
203 ds->imv_key = g_strdup(imv_key);
197 } 204 }
198 else if(wb->state == DOODLE_STATE_ESTABLISHED) 205 else if(wb->state == DOODLE_STATE_ESTABLISHED)
199 { 206 {
200 /* TODO Ask whether to save picture too */ 207 /* TODO Ask whether to save picture too */
201 purple_whiteboard_clear(wb); 208 purple_whiteboard_clear(wb);
206 * contains the doodle imv key) 213 * contains the doodle imv key)
207 */ 214 */
208 else if(wb->state == DOODLE_STATE_REQUESTED) 215 else if(wb->state == DOODLE_STATE_REQUESTED)
209 { 216 {
210 /* purple_whiteboard_start(wb); */ 217 /* purple_whiteboard_start(wb); */
211 yahoo_doodle_command_send_ready(gc, from); 218 yahoo_doodle_command_send_ready(gc, from, imv_key);
212 } 219 }
213 } 220 }
214 221
215 static void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message) 222 static void yahoo_doodle_command_got_draw(PurpleConnection *gc, const char *from, const char *message)
216 { 223 {
294 } 301 }
295 } 302 }
296 303
297 304
298 static void 305 static void
299 yahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message) 306 yahoo_doodle_command_got_extra(PurpleConnection *gc, const char *from, const char *message, const char *imv_key)
300 { 307 {
301 purple_debug_info("yahoo", "doodle: Got Extra (%s)\n", from); 308 purple_debug_info("yahoo", "doodle: Got Extra (%s)\n", from);
302 309
303 /* I do not like these 'extra' features, so I'll only handle them in one 310 /* I do not like these 'extra' features, so I'll only handle them in one
304 * way, which is returning them with the command/packet to turn them off 311 * way, which is returning them with the command/packet to turn them off
305 */ 312 */
306 yahoo_doodle_command_send_extra(gc, from, DOODLE_EXTRA_NONE); 313 yahoo_doodle_command_send_extra(gc, from, DOODLE_EXTRA_NONE, imv_key);
307 } 314 }
308 315
309 static void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from) 316 static void yahoo_doodle_command_got_confirm(PurpleConnection *gc, const char *from)
310 { 317 {
311 PurpleAccount *account; 318 PurpleAccount *account;
397 yahoo_packet_hash_str(pkt, 1002, "1"); 404 yahoo_packet_hash_str(pkt, 1002, "1");
398 405
399 yahoo_packet_send_and_free(pkt, yd); 406 yahoo_packet_send_and_free(pkt, yd);
400 } 407 }
401 408
402 void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to) 409 void yahoo_doodle_command_send_ready(PurpleConnection *gc, const char *to, const char *imv_key)
403 { 410 {
404 yahoo_doodle_command_send_generic("Ready", gc, to, "1", DOODLE_CMD_READY, NULL, "1"); 411 yahoo_doodle_command_send_generic("Ready", gc, to, "1", DOODLE_CMD_READY, imv_key, "1");
405 } 412 }
406 413
407 void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to) 414 void yahoo_doodle_command_send_request(PurpleConnection *gc, const char *to, const char *imv_key)
408 { 415 {
409 yahoo_doodle_command_send_generic("Request", gc, to, "", DOODLE_CMD_REQUEST, NULL, "0"); 416 yahoo_doodle_command_send_generic("Request", gc, to, "", DOODLE_CMD_REQUEST, imv_key, "0");
410 } 417 }
411 418
412 void yahoo_doodle_command_send_draw(PurpleConnection *gc, const char *to, const char *message) 419 void yahoo_doodle_command_send_draw(PurpleConnection *gc, const char *to, const char *message, const char *imv_key)
413 { 420 {
414 yahoo_doodle_command_send_generic("Draw", gc, to, message, DOODLE_CMD_DRAW, NULL, "1"); 421 yahoo_doodle_command_send_generic("Draw", gc, to, message, DOODLE_CMD_DRAW, imv_key, "1");
415 } 422 }
416 423
417 void yahoo_doodle_command_send_clear(PurpleConnection *gc, const char *to) 424 void yahoo_doodle_command_send_clear(PurpleConnection *gc, const char *to, const char *imv_key)
418 { 425 {
419 yahoo_doodle_command_send_generic("Clear", gc, to, " ", DOODLE_CMD_CLEAR, NULL, "1"); 426 yahoo_doodle_command_send_generic("Clear", gc, to, " ", DOODLE_CMD_CLEAR, imv_key, "1");
420 } 427 }
421 428
422 void yahoo_doodle_command_send_extra(PurpleConnection *gc, const char *to, const char *message) 429 void yahoo_doodle_command_send_extra(PurpleConnection *gc, const char *to, const char *message, const char *imv_key)
423 { 430 {
424 yahoo_doodle_command_send_generic("Extra", gc, to, message, DOODLE_CMD_EXTRA, NULL, "1"); 431 yahoo_doodle_command_send_generic("Extra", gc, to, message, DOODLE_CMD_EXTRA, imv_key, "1");
425 } 432 }
426 433
427 void yahoo_doodle_command_send_confirm(PurpleConnection *gc, const char *to) 434 void yahoo_doodle_command_send_confirm(PurpleConnection *gc, const char *to, const char *imv_key)
428 { 435 {
429 yahoo_doodle_command_send_generic("Confirm", gc, to, "1", DOODLE_CMD_CONFIRM, NULL, "1"); 436 yahoo_doodle_command_send_generic("Confirm", gc, to, "1", DOODLE_CMD_CONFIRM, imv_key, "1");
430 } 437 }
431 438
432 void yahoo_doodle_command_send_shutdown(PurpleConnection *gc, const char *to) 439 void yahoo_doodle_command_send_shutdown(PurpleConnection *gc, const char *to)
433 { 440 {
434 yahoo_doodle_command_send_generic("Shutdown", gc, to, "", DOODLE_CMD_SHUTDOWN, ";0", "0"); 441 yahoo_doodle_command_send_generic("Shutdown", gc, to, "", DOODLE_CMD_SHUTDOWN, ";0", "0");
448 } 455 }
449 456
450 void yahoo_doodle_end(PurpleWhiteboard *wb) 457 void yahoo_doodle_end(PurpleWhiteboard *wb)
451 { 458 {
452 PurpleConnection *gc = purple_account_get_connection(wb->account); 459 PurpleConnection *gc = purple_account_get_connection(wb->account);
460 doodle_session *ds = wb->proto_data;
453 461
454 /* g_debug_debug("yahoo", "doodle: yahoo_doodle_end()\n"); */ 462 /* g_debug_debug("yahoo", "doodle: yahoo_doodle_end()\n"); */
455 463
456 if (gc && wb->state != DOODLE_STATE_CANCELED) 464 if (gc && wb->state != DOODLE_STATE_CANCELED)
457 yahoo_doodle_command_send_shutdown(gc, wb->who); 465 yahoo_doodle_command_send_shutdown(gc, wb->who);
458 466
467 g_free(ds->imv_key);
459 g_free(wb->proto_data); 468 g_free(wb->proto_data);
460 } 469 }
461 470
462 void yahoo_doodle_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height) 471 void yahoo_doodle_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height)
463 { 472 {
490 char *message; 499 char *message;
491 500
492 g_return_if_fail(draw_list != NULL); 501 g_return_if_fail(draw_list != NULL);
493 502
494 message = yahoo_doodle_build_draw_string(ds, draw_list); 503 message = yahoo_doodle_build_draw_string(ds, draw_list);
495 yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message); 504 yahoo_doodle_command_send_draw(wb->account->gc, wb->who, message, ds->imv_key);
496 g_free(message); 505 g_free(message);
497 } 506 }
498 507
499 void yahoo_doodle_clear(PurpleWhiteboard *wb) 508 void yahoo_doodle_clear(PurpleWhiteboard *wb)
500 { 509 {
501 yahoo_doodle_command_send_clear(wb->account->gc, wb->who); 510 doodle_session *ds = wb->proto_data;
511 yahoo_doodle_command_send_clear(wb->account->gc, wb->who, ds->imv_key);
502 } 512 }
503 513
504 514
505 /* Traverse through the list and draw the points and lines */ 515 /* Traverse through the list and draw the points and lines */
506 void yahoo_doodle_draw_stroke(PurpleWhiteboard *wb, GList *draw_list) 516 void yahoo_doodle_draw_stroke(PurpleWhiteboard *wb, GList *draw_list)
549 } 559 }
550 } 560 }
551 561
552 void yahoo_doodle_get_brush(const PurpleWhiteboard *wb, int *size, int *color) 562 void yahoo_doodle_get_brush(const PurpleWhiteboard *wb, int *size, int *color)
553 { 563 {
554 doodle_session *ds = (doodle_session *)wb->proto_data; 564 doodle_session *ds = wb->proto_data;
555 *size = ds->brush_size; 565 *size = ds->brush_size;
556 *color = ds->brush_color; 566 *color = ds->brush_color;
557 } 567 }
558 568
559 void yahoo_doodle_set_brush(PurpleWhiteboard *wb, int size, int color) 569 void yahoo_doodle_set_brush(PurpleWhiteboard *wb, int size, int color)
560 { 570 {
561 doodle_session *ds = (doodle_session *)wb->proto_data; 571 doodle_session *ds = wb->proto_data;
562 ds->brush_size = size; 572 ds->brush_size = size;
563 ds->brush_color = color; 573 ds->brush_color = color;
564 574
565 /* Notify the core about the changes */ 575 /* Notify the core about the changes */
566 purple_whiteboard_set_brush(wb, size, color); 576 purple_whiteboard_set_brush(wb, size, color);
567 } 577 }
568 578
569 void yahoo_doodle_process(PurpleConnection *gc, const char *me, const char *from, 579 void yahoo_doodle_process(PurpleConnection *gc, const char *me, const char *from,
570 const char *command, const char *message) 580 const char *command, const char *message, const char *imv_key)
571 { 581 {
572 if(!command) 582 if(!command)
573 return; 583 return;
574 584
575 /* Now check to see what sort of Doodle message it is */ 585 /* Now check to see what sort of Doodle message it is */
576 switch(atoi(command)) 586 switch(atoi(command))
577 { 587 {
578 case DOODLE_CMD_REQUEST: 588 case DOODLE_CMD_REQUEST:
579 yahoo_doodle_command_got_request(gc, from); 589 yahoo_doodle_command_got_request(gc, from, imv_key);
580 break; 590 break;
581 591
582 case DOODLE_CMD_READY: 592 case DOODLE_CMD_READY:
583 yahoo_doodle_command_got_ready(gc, from); 593 yahoo_doodle_command_got_ready(gc, from, imv_key);
584 break; 594 break;
585 595
586 case DOODLE_CMD_CLEAR: 596 case DOODLE_CMD_CLEAR:
587 yahoo_doodle_command_got_clear(gc, from); 597 yahoo_doodle_command_got_clear(gc, from);
588 break; 598 break;
590 case DOODLE_CMD_DRAW: 600 case DOODLE_CMD_DRAW:
591 yahoo_doodle_command_got_draw(gc, from, message); 601 yahoo_doodle_command_got_draw(gc, from, message);
592 break; 602 break;
593 603
594 case DOODLE_CMD_EXTRA: 604 case DOODLE_CMD_EXTRA:
595 yahoo_doodle_command_got_extra(gc, from, message); 605 yahoo_doodle_command_got_extra(gc, from, message, imv_key);
596 break; 606 break;
597 607
598 case DOODLE_CMD_CONFIRM: 608 case DOODLE_CMD_CONFIRM:
599 yahoo_doodle_command_got_confirm(gc, from); 609 yahoo_doodle_command_got_confirm(gc, from);
600 break; 610 break;