comparison libpurple/protocols/silc/wb.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents f07501af8bae
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
103 103
104 /* Initialize whiteboard */ 104 /* Initialize whiteboard */
105 105
106 PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry) 106 PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry)
107 { 107 {
108 SilcClientConnection conn;
109 PurpleWhiteboard *wb; 108 PurpleWhiteboard *wb;
110 SilcPurpleWb wbs; 109 SilcPurpleWb wbs;
111 110
112 conn = sg->conn;
113 wb = purple_whiteboard_get_session(sg->account, client_entry->nickname); 111 wb = purple_whiteboard_get_session(sg->account, client_entry->nickname);
114 if (!wb) 112 if (!wb)
115 wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0); 113 wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0);
116 if (!wb) 114 if (!wb)
117 return NULL; 115 return NULL;
118 116
119 if (!wb->proto_data) { 117 if (!purple_whiteboard_get_protocol_data(wb)) {
120 wbs = silc_calloc(1, sizeof(*wbs)); 118 wbs = silc_calloc(1, sizeof(*wbs));
121 if (!wbs) 119 if (!wbs)
122 return NULL; 120 return NULL;
123 wbs->type = 0; 121 wbs->type = 0;
124 wbs->u.client = client_entry; 122 wbs->u.client = client_entry;
125 wbs->width = SILCPURPLE_WB_WIDTH; 123 wbs->width = SILCPURPLE_WB_WIDTH;
126 wbs->height = SILCPURPLE_WB_HEIGHT; 124 wbs->height = SILCPURPLE_WB_HEIGHT;
127 wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; 125 wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL;
128 wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; 126 wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK;
129 wb->proto_data = wbs; 127 purple_whiteboard_set_protocol_data(wb, wbs);
130 128
131 /* Start the whiteboard */ 129 /* Start the whiteboard */
132 purple_whiteboard_start(wb); 130 purple_whiteboard_start(wb);
133 purple_whiteboard_clear(wb); 131 purple_whiteboard_clear(wb);
134 } 132 }
145 if (!wb) 143 if (!wb)
146 wb = purple_whiteboard_create(sg->account, channel->channel_name, 0); 144 wb = purple_whiteboard_create(sg->account, channel->channel_name, 0);
147 if (!wb) 145 if (!wb)
148 return NULL; 146 return NULL;
149 147
150 if (!wb->proto_data) { 148 if (!purple_whiteboard_get_protocol_data(wb)) {
151 wbs = silc_calloc(1, sizeof(*wbs)); 149 wbs = silc_calloc(1, sizeof(*wbs));
152 if (!wbs) 150 if (!wbs)
153 return NULL; 151 return NULL;
154 wbs->type = 1; 152 wbs->type = 1;
155 wbs->u.channel = channel; 153 wbs->u.channel = channel;
156 wbs->width = SILCPURPLE_WB_WIDTH; 154 wbs->width = SILCPURPLE_WB_WIDTH;
157 wbs->height = SILCPURPLE_WB_HEIGHT; 155 wbs->height = SILCPURPLE_WB_HEIGHT;
158 wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; 156 wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL;
159 wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; 157 wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK;
160 wb->proto_data = wbs; 158 purple_whiteboard_set_protocol_data(wb, wbs);
161 159
162 /* Start the whiteboard */ 160 /* Start the whiteboard */
163 purple_whiteboard_start(wb); 161 purple_whiteboard_start(wb);
164 purple_whiteboard_clear(wb); 162 purple_whiteboard_clear(wb);
165 } 163 }
166 164
167 return wb; 165 return wb;
168 } 166 }
169 167
170 static void 168 static void
171 silcpurple_wb_parse(SilcPurpleWb wbs, PurpleWhiteboard *wb, 169 silcpurple_wb_parse(PurpleWhiteboard *wb,
172 unsigned char *message, SilcUInt32 message_len) 170 unsigned char *message, SilcUInt32 message_len)
173 { 171 {
172 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
174 SilcUInt8 command; 173 SilcUInt8 command;
175 SilcUInt16 width, height, brush_size; 174 SilcUInt16 width, height, brush_size;
176 SilcUInt32 brush_color, x, y, dx, dy; 175 SilcUInt32 brush_color, x, y, dx, dy;
177 SilcBufferStruct buf; 176 SilcBufferStruct buf;
178 int ret; 177 int ret;
236 static void 235 static void
237 silcpurple_wb_request_cb(SilcPurpleWbRequest req, gint id) 236 silcpurple_wb_request_cb(SilcPurpleWbRequest req, gint id)
238 { 237 {
239 PurpleWhiteboard *wb; 238 PurpleWhiteboard *wb;
240 239
241 if (id != 1) 240 if (id != 1)
242 goto out; 241 goto out;
243 242
244 if (!req->channel) 243 if (!req->channel)
245 wb = silcpurple_wb_init(req->sg, req->sender); 244 wb = silcpurple_wb_init(req->sg, req->sender);
246 else 245 else
247 wb = silcpurple_wb_init_ch(req->sg, req->channel); 246 wb = silcpurple_wb_init_ch(req->sg, req->channel);
248 247
249 silcpurple_wb_parse(wb->proto_data, wb, req->message, req->message_len); 248 silcpurple_wb_parse(wb, req->message, req->message_len);
250 249
251 out: 250 out:
252 silc_free(req->message); 251 silc_free(req->message);
253 silc_free(req); 252 silc_free(req);
254 } 253 }
262 SilcPurpleWbRequest req; 261 SilcPurpleWbRequest req;
263 PurpleConnection *gc; 262 PurpleConnection *gc;
264 SilcPurple sg; 263 SilcPurple sg;
265 264
266 gc = client->application; 265 gc = client->application;
267 sg = gc->proto_data; 266 sg = purple_connection_get_protocol_data(gc);
268 267
269 /* Open whiteboard automatically if requested */ 268 /* Open whiteboard automatically if requested */
270 if (purple_account_get_bool(sg->account, "open-wb", FALSE)) { 269 if (purple_account_get_bool(sg->account, "open-wb", FALSE)) {
271 PurpleWhiteboard *wb; 270 PurpleWhiteboard *wb;
272 271
273 if (!channel) 272 if (!channel)
274 wb = silcpurple_wb_init(sg, sender); 273 wb = silcpurple_wb_init(sg, sender);
275 else 274 else
276 wb = silcpurple_wb_init_ch(sg, channel); 275 wb = silcpurple_wb_init_ch(sg, channel);
277 276
278 silcpurple_wb_parse(wb->proto_data, wb, 277 silcpurple_wb_parse(wb,
279 (unsigned char *)message, 278 (unsigned char *)message,
280 message_len); 279 message_len);
281 return; 280 return;
282 } 281 }
283 282
316 SilcClientEntry sender, SilcMessagePayload payload, 315 SilcClientEntry sender, SilcMessagePayload payload,
317 SilcMessageFlags flags, const unsigned char *message, 316 SilcMessageFlags flags, const unsigned char *message,
318 SilcUInt32 message_len) 317 SilcUInt32 message_len)
319 { 318 {
320 SilcPurple sg; 319 SilcPurple sg;
321 PurpleConnection *gc; 320 PurpleConnection *gc;
322 PurpleWhiteboard *wb; 321 PurpleWhiteboard *wb;
323 SilcPurpleWb wbs;
324 322
325 gc = client->application; 323 gc = client->application;
326 sg = gc->proto_data; 324 sg = purple_connection_get_protocol_data(gc);
327 325
328 wb = purple_whiteboard_get_session(sg->account, sender->nickname); 326 wb = purple_whiteboard_get_session(sg->account, sender->nickname);
329 if (!wb) { 327 if (!wb) {
330 /* Ask user if they want to open the whiteboard */ 328 /* Ask user if they want to open the whiteboard */
331 silcpurple_wb_request(client, message, message_len, 329 silcpurple_wb_request(client, message, message_len,
332 sender, NULL); 330 sender, NULL);
333 return; 331 return;
334 } 332 }
335 333
336 wbs = wb->proto_data; 334 silcpurple_wb_parse(wb, (unsigned char *)message, message_len);
337 silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len);
338 } 335 }
339 336
340 /* Process incoming whiteboard message on channel */ 337 /* Process incoming whiteboard message on channel */
341 338
342 void silcpurple_wb_receive_ch(SilcClient client, SilcClientConnection conn, 339 void silcpurple_wb_receive_ch(SilcClient client, SilcClientConnection conn,
345 SilcMessageFlags flags, 342 SilcMessageFlags flags,
346 const unsigned char *message, 343 const unsigned char *message,
347 SilcUInt32 message_len) 344 SilcUInt32 message_len)
348 { 345 {
349 SilcPurple sg; 346 SilcPurple sg;
350 PurpleConnection *gc; 347 PurpleConnection *gc;
351 PurpleWhiteboard *wb; 348 PurpleWhiteboard *wb;
352 SilcPurpleWb wbs;
353 349
354 gc = client->application; 350 gc = client->application;
355 sg = gc->proto_data; 351 sg = purple_connection_get_protocol_data(gc);
356 352
357 wb = purple_whiteboard_get_session(sg->account, channel->channel_name); 353 wb = purple_whiteboard_get_session(sg->account, channel->channel_name);
358 if (!wb) { 354 if (!wb) {
359 /* Ask user if they want to open the whiteboard */ 355 /* Ask user if they want to open the whiteboard */
360 silcpurple_wb_request(client, message, message_len, 356 silcpurple_wb_request(client, message, message_len,
361 sender, channel); 357 sender, channel);
362 return; 358 return;
363 } 359 }
364 360
365 wbs = wb->proto_data; 361 silcpurple_wb_parse(wb, (unsigned char *)message, message_len);
366 silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len);
367 } 362 }
368 363
369 /* Send whiteboard message */ 364 /* Send whiteboard message */
370 365
371 void silcpurple_wb_send(PurpleWhiteboard *wb, GList *draw_list) 366 void silcpurple_wb_send(PurpleWhiteboard *wb, GList *draw_list)
372 { 367 {
373 SilcPurpleWb wbs = wb->proto_data; 368 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
374 SilcBuffer packet; 369 SilcBuffer packet;
375 GList *list; 370 GList *list;
376 int len; 371 int len;
377 PurpleConnection *gc; 372 PurpleConnection *gc;
378 SilcPurple sg; 373 SilcPurple sg;
379 374
380 g_return_if_fail(draw_list); 375 g_return_if_fail(draw_list);
381 gc = purple_account_get_connection(wb->account); 376 gc = purple_account_get_connection(purple_whiteboard_get_account(wb));
382 g_return_if_fail(gc); 377 g_return_if_fail(gc);
383 sg = gc->proto_data; 378 sg = purple_connection_get_protocol_data(gc);
384 g_return_if_fail(sg); 379 g_return_if_fail(sg);
385 380
386 len = SILCPURPLE_WB_HEADER; 381 len = SILCPURPLE_WB_HEADER;
387 for (list = draw_list; list; list = list->next) 382 for (list = draw_list; list; list = list->next)
388 len += 4; 383 len += 4;
433 /* Nothing here. Everything is in initialization */ 428 /* Nothing here. Everything is in initialization */
434 } 429 }
435 430
436 void silcpurple_wb_end(PurpleWhiteboard *wb) 431 void silcpurple_wb_end(PurpleWhiteboard *wb)
437 { 432 {
438 silc_free(wb->proto_data); 433 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
439 wb->proto_data = NULL; 434
435 silc_free(wbs);
436 purple_whiteboard_set_protocol_data(wb, NULL);
440 } 437 }
441 438
442 void silcpurple_wb_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height) 439 void silcpurple_wb_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height)
443 { 440 {
444 SilcPurpleWb wbs = wb->proto_data; 441 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
445 *width = wbs->width; 442 *width = wbs->width;
446 *height = wbs->height; 443 *height = wbs->height;
447 } 444 }
448 445
449 void silcpurple_wb_set_dimensions(PurpleWhiteboard *wb, int width, int height) 446 void silcpurple_wb_set_dimensions(PurpleWhiteboard *wb, int width, int height)
450 { 447 {
451 SilcPurpleWb wbs = wb->proto_data; 448 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
452 wbs->width = width > SILCPURPLE_WB_WIDTH_MAX ? SILCPURPLE_WB_WIDTH_MAX : 449 wbs->width = width > SILCPURPLE_WB_WIDTH_MAX ? SILCPURPLE_WB_WIDTH_MAX :
453 width; 450 width;
454 wbs->height = height > SILCPURPLE_WB_HEIGHT_MAX ? SILCPURPLE_WB_HEIGHT_MAX : 451 wbs->height = height > SILCPURPLE_WB_HEIGHT_MAX ? SILCPURPLE_WB_HEIGHT_MAX :
455 height; 452 height;
456 453
458 purple_whiteboard_set_dimensions(wb, wbs->width, wbs->height); 455 purple_whiteboard_set_dimensions(wb, wbs->width, wbs->height);
459 } 456 }
460 457
461 void silcpurple_wb_get_brush(const PurpleWhiteboard *wb, int *size, int *color) 458 void silcpurple_wb_get_brush(const PurpleWhiteboard *wb, int *size, int *color)
462 { 459 {
463 SilcPurpleWb wbs = wb->proto_data; 460 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
464 *size = wbs->brush_size; 461 *size = wbs->brush_size;
465 *color = wbs->brush_color; 462 *color = wbs->brush_color;
466 } 463 }
467 464
468 void silcpurple_wb_set_brush(PurpleWhiteboard *wb, int size, int color) 465 void silcpurple_wb_set_brush(PurpleWhiteboard *wb, int size, int color)
469 { 466 {
470 SilcPurpleWb wbs = wb->proto_data; 467 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
471 wbs->brush_size = size; 468 wbs->brush_size = size;
472 wbs->brush_color = color; 469 wbs->brush_color = color;
473 470
474 /* Update whiteboard */ 471 /* Update whiteboard */
475 purple_whiteboard_set_brush(wb, size, color); 472 purple_whiteboard_set_brush(wb, size, color);
476 } 473 }
477 474
478 void silcpurple_wb_clear(PurpleWhiteboard *wb) 475 void silcpurple_wb_clear(PurpleWhiteboard *wb)
479 { 476 {
480 SilcPurpleWb wbs = wb->proto_data; 477 SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb);
481 SilcBuffer packet; 478 SilcBuffer packet;
482 int len; 479 int len;
483 PurpleConnection *gc; 480 PurpleConnection *gc;
484 SilcPurple sg; 481 SilcPurple sg;
485 482
486 gc = purple_account_get_connection(wb->account); 483 gc = purple_account_get_connection(purple_whiteboard_get_account(wb));
487 g_return_if_fail(gc); 484 g_return_if_fail(gc);
488 sg = gc->proto_data; 485 sg = purple_connection_get_protocol_data(gc);
489 g_return_if_fail(sg); 486 g_return_if_fail(sg);
490 487
491 len = SILCPURPLE_WB_HEADER; 488 len = SILCPURPLE_WB_HEADER;
492 packet = silc_buffer_alloc_size(len); 489 packet = silc_buffer_alloc_size(len);
493 if (!packet) 490 if (!packet)