comparison src/protocols/yahoo/yahoo_doodle.c @ 11475:7fab28c991f3

[gaim-migrate @ 13717] merging gaim-doodle/whiteboard/whatever you like to call it. Needs some cleanups and doxygen comments, but has basic functionality committer: Tailor Script <tailor@pidgin.im>
author Gary Kramlich <grim@reaperworld.com>
date Fri, 09 Sep 2005 04:40:21 +0000
parents
children 4aa1de1f5545
comparison
equal deleted inserted replaced
11474:7e9635b73ed6 11475:7fab28c991f3
1 /*
2 * gaim
3 *
4 * Gaim is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
7 *
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 */
23
24 // INCLUDES ============================================================================================
25
26 #include "internal.h"
27
28 #include "account.h"
29 #include "accountopt.h"
30 #include "blist.h"
31 #include "cipher.h"
32 #include "cmds.h"
33 #include "debug.h"
34 #include "notify.h"
35 #include "privacy.h"
36 #include "prpl.h"
37 #include "proxy.h"
38 #include "request.h"
39 #include "server.h"
40 #include "util.h"
41 #include "version.h"
42
43 #include "yahoo.h"
44 #include "yahoo_packet.h"
45 #include "yahoo_friend.h"
46 #include "yahoochat.h"
47 #include "ycht.h"
48 #include "yahoo_auth.h"
49 #include "yahoo_filexfer.h"
50 #include "yahoo_picture.h"
51
52 #include "whiteboard.h"
53 #include "yahoo_doodle.h"
54
55 // GLOBALS =============================================================================================
56
57 const int DefaultColorRGB24[] =
58 {
59 DOODLE_COLOR_RED,
60 DOODLE_COLOR_ORANGE,
61 DOODLE_COLOR_YELLOW,
62 DOODLE_COLOR_GREEN,
63 DOODLE_COLOR_CYAN,
64 DOODLE_COLOR_BLUE,
65 DOODLE_COLOR_VIOLET,
66 DOODLE_COLOR_PURPLE,
67 DOODLE_COLOR_TAN,
68 DOODLE_COLOR_BROWN,
69 DOODLE_COLOR_BLACK,
70 DOODLE_COLOR_GREY,
71 DOODLE_COLOR_WHITE
72 };
73
74 // FUNCTIONS ============================================================================================
75
76 GaimCmdRet yahoo_doodle_gaim_cmd_start( GaimConversation *conv, const char *cmd, char **args, char **error, void *data )
77 {
78 if( *args && args[0] )
79 return( GAIM_CMD_RET_FAILED );
80
81 GaimAccount *account = gaim_conversation_get_account( conv );
82 GaimConnection *gc = gaim_account_get_connection( account );
83 char *to = ( char* )( gaim_conversation_get_name( conv ) );
84 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, to );
85
86 // NOTE Functionalize this code?
87
88 if( wb == NULL )
89 {
90 // Insert this 'session' in the list. At this point, it's only a requested session.
91 wb = gaim_whiteboard_create( account, to, DOODLE_STATE_REQUESTING );
92 }
93 //else
94 // ; // NOTE Perhaps some careful handling of remote assumed established sessions
95
96 yahoo_doodle_command_send_request( gc, to );
97 yahoo_doodle_command_send_ready( gc, to );
98
99 // Write a local message to this conversation showing that
100 // a request for a Doodle session has been made
101 gaim_conv_im_write( GAIM_CONV_IM( conv ), "", _("Sent Doodle request."),
102 GAIM_MESSAGE_NICK | GAIM_MESSAGE_RECV, time( NULL ) );
103
104 return( GAIM_CMD_RET_OK );
105 }
106
107 // ------------------------------------------------------------------------------------------------------
108
109 void yahoo_doodle_process( GaimConnection *gc, char *me, char *from, char *command, char *message )
110 {
111 // g_print( "-----------------------------------------------\n" );
112 // g_print( "%s : %s : %s -> %s\n", from, imv, command, message );
113
114 // Now check to see what sort of Doodle message it is
115 int cmd = atoi( command );
116
117 switch( cmd )
118 {
119 case DOODLE_CMD_REQUEST:
120 {
121 yahoo_doodle_command_got_request( gc, from );
122 } break;
123
124 case DOODLE_CMD_READY:
125 {
126 yahoo_doodle_command_got_ready( gc, from );
127 } break;
128
129 case DOODLE_CMD_CLEAR:
130 {
131 yahoo_doodle_command_got_clear( gc, from );
132 } break;
133
134 case DOODLE_CMD_DRAW:
135 {
136 yahoo_doodle_command_got_draw( gc, from, message );
137 } break;
138
139 case DOODLE_CMD_EXTRA:
140 {
141 yahoo_doodle_command_got_extra( gc, from, message );
142 } break;
143
144 case DOODLE_CMD_CONFIRM:
145 {
146 yahoo_doodle_command_got_confirm( gc, from );
147 } break;
148 }
149 }
150
151 // ------------------------------------------------------------------------------------------------------
152
153 void yahoo_doodle_command_got_request( GaimConnection *gc, char *from )
154 {
155 g_print( "-----------------------------------------------\n" );
156 g_print( "Got REQUEST (%s)\n", from );
157
158 GaimAccount *account = gaim_connection_get_account( gc );
159
160 // Only handle this if local client requested Doodle session (else local client would have sent one)
161 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, from );
162
163 // If a session with the remote user doesn't exist
164 if( wb == NULL )
165 {
166 // Ask user if he/she wishes to accept the request for a doodle session
167 // TODO Ask local user to start Doodle session with remote user
168 // NOTE This if/else statement won't work right--must use dialog results
169
170 /* char dialog_message[64];
171 g_sprintf( dialog_message, "%s is requesting to start a Doodle session with you.", from );
172
173 gaim_notify_message( NULL, GAIM_NOTIFY_MSG_INFO, "Doodle",
174 dialog_message, NULL, NULL, NULL );
175 */
176
177 wb = gaim_whiteboard_create( account, from, DOODLE_STATE_REQUESTED );
178
179 yahoo_doodle_command_send_request( gc, from );
180 }
181
182 // TODO Might be required to clear the canvas of an existing doodle session at this point
183 }
184
185 // ------------------------------------------------------------------------------------------------------
186
187 void yahoo_doodle_command_got_ready( GaimConnection *gc, char *from )
188 {
189 g_print( "-----------------------------------------------\n" );
190 g_print( "Got READY (%s)\n", from );
191
192 GaimAccount *account = gaim_connection_get_account( gc );
193
194 // Only handle this if local client requested Doodle session (else local client would have sent one)
195 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, from );
196
197 if( wb == NULL )
198 return;
199
200 if( wb->state == DOODLE_STATE_REQUESTING )
201 {
202 gaim_whiteboard_start( wb );
203
204 wb->state = DOODLE_STATE_ESTABLISHED;
205
206 yahoo_doodle_command_send_confirm( gc, from );
207 }
208
209 if( wb->state == DOODLE_STATE_ESTABLISHED )
210 {
211 // Ask whether to save picture too
212
213 gaim_whiteboard_clear( wb );
214 }
215
216 // NOTE Not sure about this... I am trying to handle if the remote user already
217 // thinks we're in a session with them (when their chat message contains the doodle;11 imv key)
218 if( wb->state == DOODLE_STATE_REQUESTED )
219 {
220 g_print( "Hmmmm\n" );
221
222 //gaim_whiteboard_start( wb );
223 yahoo_doodle_command_send_request( gc, from );
224 }
225 }
226
227 // ------------------------------------------------------------------------------------------------------
228
229 void yahoo_doodle_command_got_draw( GaimConnection *gc, char *from, char *message )
230 {
231 g_print( "-----------------------------------------------\n" );
232 g_print( "Got DRAW (%s)\n", from );
233
234 g_print( "Draw Message: %s\n", message );
235
236 GaimAccount *account = gaim_connection_get_account( gc );
237
238 // Only handle this if local client requested Doodle session (else local client would have sent one)
239 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, from );
240
241 if( wb == NULL )
242 return;
243
244 // TODO Functionalize
245 // Convert drawing packet message to an integer list
246
247 int *token = NULL;
248 int length = strlen( message );
249 char *token_end;
250
251 GList *d_list = NULL; // a local list of drawing info
252
253 // Check to see if the message begans and ends with quotes
254 if( ( message[0] != '\"' ) || ( message[length - 1] != '\"' ) )
255 return;
256
257 // Truncate the quotations off of our message (why the hell did they add them anyways!?)
258 message[length - 1] = ',';
259 message = message + 1;
260
261 // Traverse and extract all integers divided by commas
262 while( ( token_end = strchr( message, ',' ) ) )
263 {
264 token_end[0] = 0;
265
266 token = g_new0( int, 1 );
267
268 *token = atoi( message );
269
270 d_list = g_list_append( d_list, ( gpointer )( token ) );
271
272 message = token_end + 1;
273 }
274
275 yahoo_doodle_draw_stroke( wb, d_list );
276
277 //goodle_doodle_session_set_canvas_as_icon( ds );
278
279 // Remove that shit
280 int *n = NULL;
281 GList *l = d_list;
282 while( l )
283 {
284 n = l->data;
285
286 g_free( n );
287
288 l = l->next;
289 }
290
291 g_list_free( d_list );
292 d_list = NULL;
293 }
294
295 // ------------------------------------------------------------------------------------------------------
296
297 void yahoo_doodle_command_got_clear( GaimConnection *gc, char *from )
298 {
299 g_print( "-----------------------------------------------\n" );
300 g_print( "Got CLEAR (%s)\n", from );
301
302 GaimAccount *account = gaim_connection_get_account( gc );
303
304 // Only handle this if local client requested Doodle session (else local client would have sent one)
305 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, from );
306
307 if( wb == NULL )
308 return;
309
310 if( wb->state == DOODLE_STATE_ESTABLISHED )
311 {
312 // TODO Ask user whether to save the image before clearing it
313
314 gaim_whiteboard_clear( wb );
315 }
316 }
317
318 // ------------------------------------------------------------------------------------------------------
319
320 void yahoo_doodle_command_got_extra( GaimConnection *gc, char *from, char *message )
321 {
322 g_print( "-----------------------------------------------\n" );
323 g_print( "Got EXTRA (%s)\n", from );
324
325 // I do not like these 'extra' features, so I'll only handle them in one way,
326 // which is returning them with the command/packet to turn them off
327
328 yahoo_doodle_command_send_extra( gc, from, DOODLE_EXTRA_NONE );
329 }
330
331 // ------------------------------------------------------------------------------------------------------
332
333 void yahoo_doodle_command_got_confirm( GaimConnection *gc, char *from )
334 {
335 g_print( "-----------------------------------------------\n" );
336 g_print( "Got CONFIRM (%s)\n", from );
337
338 // Get the doodle session
339 GaimAccount *account = gaim_connection_get_account( gc );
340
341 // Only handle this if local client requested Doodle session (else local client would have sent one)
342 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, from );
343
344 if( wb == NULL )
345 return;
346
347 // TODO Combine the following IF's?
348
349 // Check if we requested a doodle session
350 if( wb->state == DOODLE_STATE_REQUESTING )
351 {
352 wb->state = DOODLE_STATE_ESTABLISHED;
353
354 gaim_whiteboard_start( wb );
355
356 yahoo_doodle_command_send_confirm( gc, from );
357 }
358
359 // Check if we accepted a request for a doodle session
360 if( wb->state == DOODLE_STATE_REQUESTED )
361 {
362 wb->state = DOODLE_STATE_ESTABLISHED;
363
364 gaim_whiteboard_start( wb );
365 }
366 }
367
368 // ------------------------------------------------------------------------------------------------------
369
370 void yahoo_doodle_command_got_shutdown( GaimConnection *gc, char *from )
371 {
372 g_print( "-----------------------------------------------\n" );
373 g_print( "Got SHUTDOWN (%s)\n", from );
374
375 GaimAccount *account = gaim_connection_get_account( gc );
376
377 // Only handle this if local client requested Doodle session (else local client would have sent one)
378 GaimWhiteboard *wb = gaim_whiteboard_get_session( account, from );
379
380 // TODO Ask if user wants to save picture before the session is closed
381
382 // If this session doesn't exist, don't try and kill it
383 if( wb == NULL )
384 return;
385 else
386 {
387 gaim_whiteboard_destroy( wb );
388
389 //yahoo_doodle_command_send_shutdown( gc, from );
390 }
391 }
392
393 // ------------------------------------------------------------------------------------------------------
394
395 void yahoo_doodle_command_send_request( GaimConnection *gc, char *to )
396 {
397 g_print( "-----------------------------------------------\n" );
398 g_print( "Sent REQUEST (%s)\n", to );
399
400 struct yahoo_data *yd;
401 struct yahoo_packet *pkt;
402
403 yd = gc->proto_data;
404
405 // Make and send an acknowledge (ready) Doodle packet
406 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
407 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
408 yahoo_packet_hash_str( pkt, 1, gaim_account_get_username( gc->account ) );
409 yahoo_packet_hash_str( pkt, 14, "1" );
410 yahoo_packet_hash_str( pkt, 13, "1" );
411 yahoo_packet_hash_str( pkt, 5, to );
412 yahoo_packet_hash_str( pkt, 63, "doodle;11" );
413 yahoo_packet_hash_str( pkt, 64, "1" );
414 yahoo_packet_hash_str( pkt, 1002, "1" );
415
416 yahoo_packet_send_and_free( pkt, yd );
417 }
418
419 // ------------------------------------------------------------------------------------------------------
420
421 void yahoo_doodle_command_send_ready( GaimConnection *gc, char *to )
422 {
423 g_print( "-----------------------------------------------\n" );
424 g_print( "Sent READY (%s)\n", to );
425
426 struct yahoo_data *yd;
427 struct yahoo_packet *pkt;
428
429 yd = gc->proto_data;
430
431 // Make and send a request to start a Doodle session
432 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
433 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
434 yahoo_packet_hash_str( pkt, 1, gaim_account_get_username( gc->account ) );
435 yahoo_packet_hash_str( pkt, 14, "" );
436 yahoo_packet_hash_str( pkt, 13, "0" );
437 yahoo_packet_hash_str( pkt, 5, to );
438 yahoo_packet_hash_str( pkt, 63, "doodle;11" );
439 yahoo_packet_hash_str( pkt, 64, "0" );
440 yahoo_packet_hash_str( pkt, 1002, "1" );
441
442 yahoo_packet_send_and_free( pkt, yd );
443 }
444
445 // ------------------------------------------------------------------------------------------------------
446
447 void yahoo_doodle_command_send_draw( GaimConnection *gc, char *to, char *message )
448 {
449 g_print( "-----------------------------------------------\n" );
450 g_print( "Sent DRAW (%s)\n", to );
451
452 struct yahoo_data *yd;
453 struct yahoo_packet *pkt;
454
455 yd = gc->proto_data;
456
457 // Make and send a drawing packet
458 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
459 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
460 yahoo_packet_hash_str( pkt, 1, gaim_account_get_username( gc->account ) );
461 yahoo_packet_hash_str( pkt, 14, message );
462 yahoo_packet_hash_str( pkt, 13, "3" );
463 yahoo_packet_hash_str( pkt, 5, to );
464 yahoo_packet_hash_str( pkt, 63, "doodle;11" );
465 yahoo_packet_hash_str( pkt, 64, "1" );
466 yahoo_packet_hash_str( pkt, 1002, "1" );
467
468 yahoo_packet_send_and_free( pkt, yd );
469 }
470
471 // ------------------------------------------------------------------------------------------------------
472
473 void yahoo_doodle_command_send_clear( GaimConnection *gc, char *to )
474 {
475 g_print( "-----------------------------------------------\n" );
476 g_print( "Sent CLEAR (%s)\n", to );
477
478 struct yahoo_data *yd;
479 struct yahoo_packet *pkt;
480
481 yd = gc->proto_data;
482
483 // Make and send a request to clear packet
484 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
485 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
486 yahoo_packet_hash_str( pkt, 1, gaim_account_get_username( gc->account ) );
487 yahoo_packet_hash_str( pkt, 14, " " );
488 yahoo_packet_hash_str( pkt, 13, "2" );
489 yahoo_packet_hash_str( pkt, 5, to );
490 yahoo_packet_hash_str( pkt, 63, "doodle;11" );
491 yahoo_packet_hash_str( pkt, 64, "1" );
492 yahoo_packet_hash_str( pkt, 1002, "1" );
493
494 yahoo_packet_send_and_free( pkt, yd );
495 }
496
497 // ------------------------------------------------------------------------------------------------------
498
499 void yahoo_doodle_command_send_extra( GaimConnection *gc, char *to, char *message )
500 {
501 g_print( "-----------------------------------------------\n" );
502 g_print( "Sent EXTRA (%s)\n", to );
503
504 struct yahoo_data *yd;
505 struct yahoo_packet *pkt;
506
507 yd = gc->proto_data;
508
509 // Send out a request to use a specified 'extra' feature (message)
510 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
511 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
512 yahoo_packet_hash_str( pkt, 1, gaim_account_get_username( gc->account ) );
513 yahoo_packet_hash_str( pkt, 14, message );
514 yahoo_packet_hash_str( pkt, 13, "4" );
515 yahoo_packet_hash_str( pkt, 5, to );
516 yahoo_packet_hash_str( pkt, 63, "doodle;11" );
517 yahoo_packet_hash_str( pkt, 64, "1" );
518 yahoo_packet_hash_str( pkt, 1002, "1" );
519
520 yahoo_packet_send_and_free( pkt, yd );
521 }
522
523 // ------------------------------------------------------------------------------------------------------
524
525 void yahoo_doodle_command_send_confirm( GaimConnection *gc, char *to )
526 {
527 g_print( "-----------------------------------------------\n" );
528 g_print( "Sent CONFIRM (%s)\n", to );
529
530 struct yahoo_data *yd;
531 struct yahoo_packet *pkt;
532
533 yd = gc->proto_data;
534
535 // Send ready packet (that local client accepted and is ready)
536 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
537 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
538 yahoo_packet_hash_str( pkt, 1, ( char* )( gaim_account_get_username( gc->account ) ) );
539 yahoo_packet_hash_str( pkt, 14, "1" );
540 yahoo_packet_hash_str( pkt, 13, "5" );
541 yahoo_packet_hash_str( pkt, 5, to );
542 yahoo_packet_hash_str( pkt, 63, "doodle;11" );
543 yahoo_packet_hash_str( pkt, 64, "1" );
544 yahoo_packet_hash_str( pkt, 1002, "1" );
545
546 yahoo_packet_send_and_free( pkt, yd );
547 }
548
549 // ------------------------------------------------------------------------------------------------------
550
551 void yahoo_doodle_command_send_shutdown( GaimConnection *gc, char *to )
552 {
553 g_print( "-----------------------------------------------\n" );
554 g_print( "Sent SHUTDOWN (%s)\n", to );
555
556 struct yahoo_data *yd;
557 struct yahoo_packet *pkt;
558
559 yd = gc->proto_data;
560
561 // Declare that you are ending the Doodle session
562 pkt = yahoo_packet_new( YAHOO_SERVICE_P2PFILEXFER, YAHOO_STATUS_AVAILABLE, 0 );
563 yahoo_packet_hash_str( pkt, 49, "IMVIRONMENT" );
564 yahoo_packet_hash_str( pkt, 1, gaim_account_get_username( gc->account ) );
565 yahoo_packet_hash_str( pkt, 14, "" );
566 yahoo_packet_hash_str( pkt, 13, "0" );
567 yahoo_packet_hash_str( pkt, 5, to );
568 yahoo_packet_hash_str( pkt, 63, ";0" );
569 yahoo_packet_hash_str( pkt, 64, "0" );
570 yahoo_packet_hash_str( pkt, 1002, "1" );
571
572 yahoo_packet_send_and_free( pkt, yd );
573 }
574
575 // ------------------------------------------------------------------------------------------------------
576
577 void yahoo_doodle_start( GaimWhiteboard *wb )
578 {
579 //g_print( "yahoo_doodle_start()\n" );
580
581 doodle_session *ds = g_new0( doodle_session, 1 );
582
583 // Set default brush size and color
584 ds->brush_size = DOODLE_BRUSH_MEDIUM;
585 ds->brush_color = 0; // black
586
587 wb->proto_data = ds;
588 }
589
590 // ------------------------------------------------------------------------------------------------------
591
592 void yahoo_doodle_end( GaimWhiteboard *wb )
593 {
594 //g_print( "yahoo_doodle_end()\n" );
595
596 GaimConnection *gc = gaim_account_get_connection( wb->account );
597
598 yahoo_doodle_command_send_shutdown( gc, wb->who );
599
600 doodle_session *ds = wb->proto_data;
601 if( ds )
602 g_free( ds );
603 }
604
605 // ------------------------------------------------------------------------------------------------------
606
607 void yahoo_doodle_get_dimensions( GaimWhiteboard *wb, int *width, int *height )
608 {
609 // Standard Doodle canvases are of one size: 368x256
610 *width = DOODLE_CANVAS_WIDTH;
611 *height = DOODLE_CANVAS_HEIGHT;
612 }
613
614 // ------------------------------------------------------------------------------------------------------
615
616 void yahoo_doodle_send_draw_list( GaimWhiteboard *wb, GList *draw_list )
617 {
618 //g_print( "yahoo_doodle_send_draw_list()\n" );
619
620 doodle_session *ds = wb->proto_data;
621 char *message = yahoo_doodle_build_draw_string( ds, draw_list );
622
623 if( message )
624 yahoo_doodle_command_send_draw( wb->account->gc, wb->who, message );
625
626 }
627
628 // ------------------------------------------------------------------------------------------------------
629
630 void yahoo_doodle_clear( GaimWhiteboard *wb )
631 {
632 yahoo_doodle_command_send_clear( wb->account->gc, wb->who );
633 }
634
635 // ------------------------------------------------------------------------------------------------------
636
637 void yahoo_doodle_draw_stroke( GaimWhiteboard *wb, GList *draw_list )
638 {
639 // Traverse through the list and draw the points and lines
640
641 //g_print( "Drawing: color=%d, size=%d, (%d,%d)\n", brush_color, brush_size, x, y );
642
643 GList *l = draw_list;
644
645 int *n = NULL;
646
647 int brush_color;
648 int brush_size;
649 int x;
650 int y;
651
652 int dx, dy;
653
654 n = l->data; brush_color = *n; l = l->next;
655 n = l->data; brush_size = *n; l = l->next;
656 n = l->data; x = *n; l = l->next;
657 n = l->data; y = *n; l = l->next;
658
659 int count = 0;
660
661 // Pray this works and pray that the list has an even number of elements
662 while( l )
663 {
664 count++;
665
666 n = l->data; dx = *n; l = l->next;
667 n = l->data; dy = *n; l = l->next;
668
669 gaim_whiteboard_draw_line( wb,
670 x, y,
671 x + dx, y + dy,
672 brush_color, brush_size );
673
674 x = x + dx;
675 y = y + dy;
676 }
677
678 //g_print( "Counted %d deltas\n", count );
679 }
680
681 // ------------------------------------------------------------------------------------------------------
682
683 char *yahoo_doodle_build_draw_string( doodle_session *ds, GList *draw_list )
684 {
685 //g_print( "yahoo_doodle_build_draw_string()\n" );
686
687 if( draw_list == NULL )
688 return( NULL );
689
690 GList *l = draw_list;
691
692 int *n = NULL;
693
694 static char message[1024]; // Hope that 1024 is enough
695 char token_string[16]; // Token string extracted from draw list
696
697 strcpy( message, "\"" );
698
699 sprintf( token_string, "%d,%d,", ds->brush_color, ds->brush_size );
700 strcat( message, token_string );
701
702 // Pray this works and pray that the list has an even number of elements
703 while( l )
704 {
705 n = l->data;
706
707 sprintf( token_string, "%d,", *n );
708
709 // This check prevents overflow
710 if( ( strlen( message ) + strlen( token_string ) ) < 1024 )
711 strcat( message, token_string );
712 else
713 break;
714
715 l = l->next;
716 }
717
718 message[strlen( message ) - 1] = '\"';
719 //message[strlen( message )] = 0;
720 //message[511] = 0;
721
722 //g_print( "Draw Message: %s\n", message );
723
724 return( message );
725 }
726
727 // ------------------------------------------------------------------------------------------------------
728