Mon, 05 Apr 2021 20:20:33 -0500
Avoid manual handling of icons in request field list items
* Use `PurpleKeyValuePair` as field list items
* Replace `icons` list with `has_icons` flag, thus fixing memleak
* Replace `purple_request_field_list_get_icons` with `purple_request_field_list_has_icons`
Testing Done:
Compile and run.
Reviewed at https://reviews.imfreedom.org/r/563/
| 12058 | 1 | /* |
| 2 | ||
| 3 | wb.c | |
| 4 | ||
| 5 | Author: Pekka Riikonen <priikone@silcnet.org> | |
| 6 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
7 | Copyright (C) 2005 - 2007 Pekka Riikonen |
| 12058 | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | it under the terms of the GNU General Public License as published by | |
| 11 | the Free Software Foundation; version 2 of the License. | |
| 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 | */ | |
| 19 | ||
|
40769
2214cc7b95ca
Fix SILC compilation
Arkadiy Illarionov <qarkai@gmail.com>
parents:
35989
diff
changeset
|
20 | #include <glib/gi18n-lib.h> |
|
2214cc7b95ca
Fix SILC compilation
Arkadiy Illarionov <qarkai@gmail.com>
parents:
35989
diff
changeset
|
21 | |
| 15884 | 22 | #include "silcpurple.h" |
| 12058 | 23 | #include "wb.h" |
| 24 | ||
| 25 | /* | |
| 26 | SILC Whiteboard packet: | |
| 27 | ||
| 28 | 1 byte command | |
| 29 | 2 bytes width | |
| 30 | 2 bytes height | |
| 31 | 4 bytes brush color | |
| 32 | 2 bytes brush size | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
33 | n bytes data |
| 12058 | 34 | |
| 35 | Data: | |
| 36 | ||
| 37 | 4 bytes x | |
| 38 | 4 bytes y | |
| 39 | ||
| 40 | Commands: | |
| 41 | ||
| 42 | 0x01 draw | |
| 43 | 0x02 clear | |
| 44 | ||
| 45 | MIME: | |
| 46 | ||
| 47 | MIME-Version: 1.0 | |
| 48 | Content-Type: application/x-wb | |
| 49 | Content-Transfer-Encoding: binary | |
| 50 | ||
| 51 | */ | |
| 52 | ||
| 15884 | 53 | #define SILCPURPLE_WB_MIME "MIME-Version: 1.0\r\nContent-Type: application/x-wb\r\nContent-Transfer-Encoding: binary\r\n\r\n" |
| 54 | #define SILCPURPLE_WB_HEADER strlen(SILCPURPLE_WB_MIME) + 11 | |
| 12058 | 55 | |
| 15884 | 56 | #define SILCPURPLE_WB_WIDTH 500 |
| 57 | #define SILCPURPLE_WB_HEIGHT 400 | |
| 58 | #define SILCPURPLE_WB_WIDTH_MAX 1024 | |
| 59 | #define SILCPURPLE_WB_HEIGHT_MAX 1024 | |
| 12058 | 60 | |
| 61 | /* Commands */ | |
| 62 | typedef enum { | |
| 15884 | 63 | SILCPURPLE_WB_DRAW = 0x01, |
| 64 | SILCPURPLE_WB_CLEAR = 0x02, | |
| 65 | } SilcPurpleWbCommand; | |
| 12058 | 66 | |
| 67 | /* Brush size */ | |
| 68 | typedef enum { | |
| 15884 | 69 | SILCPURPLE_WB_BRUSH_SMALL = 2, |
| 70 | SILCPURPLE_WB_BRUSH_MEDIUM = 5, | |
| 71 | SILCPURPLE_WB_BRUSH_LARGE = 10, | |
| 72 | } SilcPurpleWbBrushSize; | |
| 12058 | 73 | |
| 15884 | 74 | /* Brush color (XXX Purple should provide default colors) */ |
| 12058 | 75 | typedef enum { |
| 15884 | 76 | SILCPURPLE_WB_COLOR_BLACK = 0, |
| 77 | SILCPURPLE_WB_COLOR_RED = 13369344, | |
| 78 | SILCPURPLE_WB_COLOR_GREEN = 52224, | |
| 79 | SILCPURPLE_WB_COLOR_BLUE = 204, | |
| 80 | SILCPURPLE_WB_COLOR_YELLOW = 15658496, | |
| 81 | SILCPURPLE_WB_COLOR_ORANGE = 16737792, | |
| 82 | SILCPURPLE_WB_COLOR_CYAN = 52428, | |
| 83 | SILCPURPLE_WB_COLOR_VIOLET = 5381277, | |
| 84 | SILCPURPLE_WB_COLOR_PURPLE = 13369548, | |
| 85 | SILCPURPLE_WB_COLOR_TAN = 12093547, | |
| 86 | SILCPURPLE_WB_COLOR_BROWN = 5256485, | |
| 87 | SILCPURPLE_WB_COLOR_GREY = 11184810, | |
| 88 | SILCPURPLE_WB_COLOR_WHITE = 16777215, | |
| 89 | } SilcPurpleWbColor; | |
| 12058 | 90 | |
| 91 | typedef struct { | |
| 92 | int type; /* 0 = buddy, 1 = channel */ | |
| 93 | union { | |
| 94 | SilcClientEntry client; | |
| 95 | SilcChannelEntry channel; | |
| 96 | } u; | |
| 97 | int width; | |
| 98 | int height; | |
| 99 | int brush_size; | |
| 100 | int brush_color; | |
| 15884 | 101 | } *SilcPurpleWb; |
| 12058 | 102 | |
| 103 | /* Initialize whiteboard */ | |
| 104 | ||
| 15884 | 105 | PurpleWhiteboard *silcpurple_wb_init(SilcPurple sg, SilcClientEntry client_entry) |
| 12058 | 106 | { |
| 15884 | 107 | PurpleWhiteboard *wb; |
| 108 | SilcPurpleWb wbs; | |
| 12058 | 109 | |
| 15884 | 110 | wb = purple_whiteboard_get_session(sg->account, client_entry->nickname); |
| 12058 | 111 | if (!wb) |
|
34937
ca1dab25bd7a
Removed purple_whiteboard_destroy(). Renamed purple_whiteboard_create() to purple_whiteboard_new().
Ankit Vani <a@nevitus.org>
parents:
33774
diff
changeset
|
112 | wb = purple_whiteboard_new(sg->account, client_entry->nickname, 0); |
| 12058 | 113 | if (!wb) |
| 114 | return NULL; | |
| 115 | ||
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
116 | if (!purple_whiteboard_get_protocol_data(wb)) { |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
117 | wbs = silc_calloc(1, sizeof(*wbs)); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
118 | if (!wbs) |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
119 | return NULL; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
120 | wbs->type = 0; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
121 | wbs->u.client = client_entry; |
| 15884 | 122 | wbs->width = SILCPURPLE_WB_WIDTH; |
| 123 | wbs->height = SILCPURPLE_WB_HEIGHT; | |
| 124 | wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; | |
| 125 | wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; | |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
126 | purple_whiteboard_set_protocol_data(wb, wbs); |
| 12058 | 127 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
128 | /* Start the whiteboard */ |
| 15884 | 129 | purple_whiteboard_start(wb); |
| 130 | purple_whiteboard_clear(wb); | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
131 | } |
| 12058 | 132 | |
| 133 | return wb; | |
| 134 | } | |
| 135 | ||
| 15884 | 136 | PurpleWhiteboard *silcpurple_wb_init_ch(SilcPurple sg, SilcChannelEntry channel) |
| 12058 | 137 | { |
| 15884 | 138 | PurpleWhiteboard *wb; |
| 139 | SilcPurpleWb wbs; | |
| 12058 | 140 | |
| 15884 | 141 | wb = purple_whiteboard_get_session(sg->account, channel->channel_name); |
| 12058 | 142 | if (!wb) |
|
34937
ca1dab25bd7a
Removed purple_whiteboard_destroy(). Renamed purple_whiteboard_create() to purple_whiteboard_new().
Ankit Vani <a@nevitus.org>
parents:
33774
diff
changeset
|
143 | wb = purple_whiteboard_new(sg->account, channel->channel_name, 0); |
| 12058 | 144 | if (!wb) |
| 145 | return NULL; | |
| 146 | ||
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
147 | if (!purple_whiteboard_get_protocol_data(wb)) { |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
148 | wbs = silc_calloc(1, sizeof(*wbs)); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
149 | if (!wbs) |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
150 | return NULL; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
151 | wbs->type = 1; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
152 | wbs->u.channel = channel; |
| 15884 | 153 | wbs->width = SILCPURPLE_WB_WIDTH; |
| 154 | wbs->height = SILCPURPLE_WB_HEIGHT; | |
| 155 | wbs->brush_size = SILCPURPLE_WB_BRUSH_SMALL; | |
| 156 | wbs->brush_color = SILCPURPLE_WB_COLOR_BLACK; | |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
157 | purple_whiteboard_set_protocol_data(wb, wbs); |
| 12058 | 158 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
159 | /* Start the whiteboard */ |
| 15884 | 160 | purple_whiteboard_start(wb); |
| 161 | purple_whiteboard_clear(wb); | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
162 | } |
| 12058 | 163 | |
| 164 | return wb; | |
| 165 | } | |
| 166 | ||
| 167 | static void | |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
168 | silcpurple_wb_parse(PurpleWhiteboard *wb, |
| 12058 | 169 | unsigned char *message, SilcUInt32 message_len) |
| 170 | { | |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
171 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb); |
| 12058 | 172 | SilcUInt8 command; |
| 173 | SilcUInt16 width, height, brush_size; | |
| 174 | SilcUInt32 brush_color, x, y, dx, dy; | |
| 175 | SilcBufferStruct buf; | |
| 176 | int ret; | |
| 177 | ||
| 178 | /* Parse the packet */ | |
| 179 | silc_buffer_set(&buf, message, message_len); | |
| 180 | ret = silc_buffer_unformat(&buf, | |
| 181 | SILC_STR_UI_CHAR(&command), | |
| 182 | SILC_STR_UI_SHORT(&width), | |
| 183 | SILC_STR_UI_SHORT(&height), | |
| 184 | SILC_STR_UI_INT(&brush_color), | |
| 185 | SILC_STR_UI_SHORT(&brush_size), | |
| 186 | SILC_STR_END); | |
| 187 | if (ret < 0) | |
| 188 | return; | |
| 189 | silc_buffer_pull(&buf, ret); | |
| 190 | ||
| 191 | /* Update whiteboard if its dimensions changed */ | |
| 192 | if (width != wbs->width || height != wbs->height) | |
|
33767
624cf59658dc
CID 732106: Arguments in wrong order
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
193 | silcpurple_wb_set_dimensions(wb, width, height); |
| 12058 | 194 | |
| 15884 | 195 | if (command == SILCPURPLE_WB_DRAW) { |
| 12058 | 196 | /* Parse data and draw it */ |
| 197 | ret = silc_buffer_unformat(&buf, | |
| 198 | SILC_STR_UI_INT(&dx), | |
| 199 | SILC_STR_UI_INT(&dy), | |
| 200 | SILC_STR_END); | |
| 201 | if (ret < 0) | |
| 202 | return; | |
| 203 | silc_buffer_pull(&buf, 8); | |
| 204 | x = dx; | |
| 205 | y = dy; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
206 | while (silc_buffer_len(&buf) > 0) { |
| 12058 | 207 | ret = silc_buffer_unformat(&buf, |
| 208 | SILC_STR_UI_INT(&dx), | |
| 209 | SILC_STR_UI_INT(&dy), | |
| 210 | SILC_STR_END); | |
| 211 | if (ret < 0) | |
| 212 | return; | |
| 213 | silc_buffer_pull(&buf, 8); | |
| 214 | ||
| 15884 | 215 | purple_whiteboard_draw_line(wb, x, y, x + dx, y + dy, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
216 | brush_color, brush_size); |
| 12058 | 217 | x += dx; |
| 218 | y += dy; | |
| 219 | } | |
| 220 | } | |
| 221 | ||
| 15884 | 222 | if (command == SILCPURPLE_WB_CLEAR) |
| 223 | purple_whiteboard_clear(wb); | |
| 12058 | 224 | } |
| 225 | ||
| 226 | typedef struct { | |
| 227 | unsigned char *message; | |
| 228 | SilcUInt32 message_len; | |
| 15884 | 229 | SilcPurple sg; |
| 12058 | 230 | SilcClientEntry sender; |
| 231 | SilcChannelEntry channel; | |
| 15884 | 232 | } *SilcPurpleWbRequest; |
| 12058 | 233 | |
| 234 | static void | |
| 15884 | 235 | silcpurple_wb_request_cb(SilcPurpleWbRequest req, gint id) |
| 12058 | 236 | { |
| 15884 | 237 | PurpleWhiteboard *wb; |
| 12058 | 238 | |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
239 | if (id != 1) |
|
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
240 | goto out; |
| 12058 | 241 | |
| 242 | if (!req->channel) | |
| 15884 | 243 | wb = silcpurple_wb_init(req->sg, req->sender); |
| 12058 | 244 | else |
| 15884 | 245 | wb = silcpurple_wb_init_ch(req->sg, req->channel); |
| 12058 | 246 | |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
247 | silcpurple_wb_parse(wb, req->message, req->message_len); |
| 12058 | 248 | |
| 249 | out: | |
| 250 | silc_free(req->message); | |
| 251 | silc_free(req); | |
| 252 | } | |
| 253 | ||
| 254 | static void | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
255 | silcpurple_wb_request(SilcClient client, const unsigned char *message, |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
256 | SilcUInt32 message_len, SilcClientEntry sender, |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
257 | SilcChannelEntry channel) |
| 12058 | 258 | { |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
259 | char tmp[256]; |
| 15884 | 260 | SilcPurpleWbRequest req; |
| 261 | PurpleConnection *gc; | |
| 262 | SilcPurple sg; | |
| 12058 | 263 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
264 | gc = client->application; |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
265 | sg = purple_connection_get_protocol_data(gc); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
266 | |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
267 | /* Open whiteboard automatically if requested */ |
| 15884 | 268 | if (purple_account_get_bool(sg->account, "open-wb", FALSE)) { |
| 269 | PurpleWhiteboard *wb; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
270 | |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
271 | if (!channel) |
| 15884 | 272 | wb = silcpurple_wb_init(sg, sender); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
273 | else |
| 15884 | 274 | wb = silcpurple_wb_init_ch(sg, channel); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
275 | |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
276 | silcpurple_wb_parse(wb, |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
277 | (unsigned char *)message, |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
278 | message_len); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
279 | return; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
280 | } |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
281 | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
282 | /* Close any previous unaccepted requests */ |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
283 | purple_request_close_with_handle(sender); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
284 | |
| 12058 | 285 | if (!channel) { |
| 286 | g_snprintf(tmp, sizeof(tmp), | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
287 | _("%s sent message to whiteboard. Would you like " |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
288 | "to open the whiteboard?"), sender->nickname); |
| 12058 | 289 | } else { |
| 290 | g_snprintf(tmp, sizeof(tmp), | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
291 | _("%s sent message to whiteboard on %s channel. " |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
292 | "Would you like to open the whiteboard?"), |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
293 | sender->nickname, channel->channel_name); |
| 12058 | 294 | } |
| 295 | ||
| 296 | req = silc_calloc(1, sizeof(*req)); | |
| 297 | if (!req) | |
| 298 | return; | |
| 299 | req->message = silc_memdup(message, message_len); | |
| 300 | req->message_len = message_len; | |
| 301 | req->sender = sender; | |
| 302 | req->channel = channel; | |
| 303 | req->sg = sg; | |
| 304 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
305 | purple_request_action(gc, _("Whiteboard"), tmp, NULL, 1, |
|
34331
c8486462bb63
Request API refactoring: switch purple_request_action to PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
306 | purple_request_cpar_from_connection(gc), req, 2, |
| 15884 | 307 | _("Yes"), G_CALLBACK(silcpurple_wb_request_cb), |
| 308 | _("No"), G_CALLBACK(silcpurple_wb_request_cb)); | |
| 12058 | 309 | } |
| 310 | ||
| 311 | /* Process incoming whiteboard message */ | |
| 312 | ||
| 15884 | 313 | void silcpurple_wb_receive(SilcClient client, SilcClientConnection conn, |
| 12058 | 314 | SilcClientEntry sender, SilcMessagePayload payload, |
| 315 | SilcMessageFlags flags, const unsigned char *message, | |
| 316 | SilcUInt32 message_len) | |
| 317 | { | |
| 15884 | 318 | SilcPurple sg; |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
319 | PurpleConnection *gc; |
| 15884 | 320 | PurpleWhiteboard *wb; |
| 12058 | 321 | |
| 322 | gc = client->application; | |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
323 | sg = purple_connection_get_protocol_data(gc); |
| 12058 | 324 | |
| 15884 | 325 | wb = purple_whiteboard_get_session(sg->account, sender->nickname); |
| 12058 | 326 | if (!wb) { |
| 327 | /* Ask user if they want to open the whiteboard */ | |
| 15884 | 328 | silcpurple_wb_request(client, message, message_len, |
| 12058 | 329 | sender, NULL); |
| 330 | return; | |
| 331 | } | |
| 332 | ||
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
333 | silcpurple_wb_parse(wb, (unsigned char *)message, message_len); |
| 12058 | 334 | } |
| 335 | ||
| 336 | /* Process incoming whiteboard message on channel */ | |
| 337 | ||
| 15884 | 338 | void silcpurple_wb_receive_ch(SilcClient client, SilcClientConnection conn, |
| 12058 | 339 | SilcClientEntry sender, SilcChannelEntry channel, |
| 340 | SilcMessagePayload payload, | |
| 341 | SilcMessageFlags flags, | |
| 342 | const unsigned char *message, | |
| 343 | SilcUInt32 message_len) | |
| 344 | { | |
| 15884 | 345 | SilcPurple sg; |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
346 | PurpleConnection *gc; |
| 15884 | 347 | PurpleWhiteboard *wb; |
| 12058 | 348 | |
| 349 | gc = client->application; | |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
350 | sg = purple_connection_get_protocol_data(gc); |
| 12058 | 351 | |
| 15884 | 352 | wb = purple_whiteboard_get_session(sg->account, channel->channel_name); |
| 12058 | 353 | if (!wb) { |
| 354 | /* Ask user if they want to open the whiteboard */ | |
| 15884 | 355 | silcpurple_wb_request(client, message, message_len, |
| 12058 | 356 | sender, channel); |
| 357 | return; | |
| 358 | } | |
| 359 | ||
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
360 | silcpurple_wb_parse(wb, (unsigned char *)message, message_len); |
| 12058 | 361 | } |
| 362 | ||
| 363 | /* Send whiteboard message */ | |
| 364 | ||
| 15884 | 365 | void silcpurple_wb_send(PurpleWhiteboard *wb, GList *draw_list) |
| 12058 | 366 | { |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
367 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb); |
| 12058 | 368 | SilcBuffer packet; |
| 369 | GList *list; | |
| 370 | int len; | |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
371 | PurpleConnection *gc; |
|
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
372 | SilcPurple sg; |
| 12058 | 373 | |
| 374 | g_return_if_fail(draw_list); | |
|
32286
316da124dc0e
Use the new accessor functions of PidginWhiteboard.
Andrew Victor <andrew.victor@mxit.com>
parents:
32283
diff
changeset
|
375 | gc = purple_account_get_connection(purple_whiteboard_get_account(wb)); |
| 12058 | 376 | g_return_if_fail(gc); |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
377 | sg = purple_connection_get_protocol_data(gc); |
| 12058 | 378 | g_return_if_fail(sg); |
| 379 | ||
| 15884 | 380 | len = SILCPURPLE_WB_HEADER; |
| 12058 | 381 | for (list = draw_list; list; list = list->next) |
| 382 | len += 4; | |
| 383 | ||
| 384 | packet = silc_buffer_alloc_size(len); | |
| 385 | if (!packet) | |
| 386 | return; | |
| 387 | ||
| 388 | /* Assmeble packet */ | |
| 389 | silc_buffer_format(packet, | |
| 15884 | 390 | SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME), |
| 391 | SILC_STR_UI_CHAR(SILCPURPLE_WB_DRAW), | |
| 12058 | 392 | SILC_STR_UI_SHORT(wbs->width), |
| 393 | SILC_STR_UI_SHORT(wbs->height), | |
| 394 | SILC_STR_UI_INT(wbs->brush_color), | |
| 395 | SILC_STR_UI_SHORT(wbs->brush_size), | |
| 396 | SILC_STR_END); | |
| 15884 | 397 | silc_buffer_pull(packet, SILCPURPLE_WB_HEADER); |
| 12058 | 398 | for (list = draw_list; list; list = list->next) { |
| 399 | silc_buffer_format(packet, | |
| 400 | SILC_STR_UI_INT(GPOINTER_TO_INT(list->data)), | |
| 401 | SILC_STR_END); | |
| 402 | silc_buffer_pull(packet, 4); | |
| 403 | } | |
| 404 | ||
| 405 | /* Send the message */ | |
| 406 | if (wbs->type == 0) { | |
| 407 | /* Private message */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
408 | silc_client_send_private_message(sg->client, sg->conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
409 | wbs->u.client, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
410 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
411 | packet->head, len); |
| 12058 | 412 | } else if (wbs->type == 1) { |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
413 | /* Channel message. Channel private keys are not supported. */ |
| 12058 | 414 | silc_client_send_channel_message(sg->client, sg->conn, |
| 415 | wbs->u.channel, NULL, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
416 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
417 | packet->head, len); |
| 12058 | 418 | } |
| 419 | ||
| 420 | silc_buffer_free(packet); | |
| 421 | } | |
| 422 | ||
| 15884 | 423 | /* Purple Whiteboard operations */ |
| 12058 | 424 | |
| 15884 | 425 | void silcpurple_wb_start(PurpleWhiteboard *wb) |
| 12058 | 426 | { |
| 427 | /* Nothing here. Everything is in initialization */ | |
| 428 | } | |
| 429 | ||
| 15884 | 430 | void silcpurple_wb_end(PurpleWhiteboard *wb) |
| 12058 | 431 | { |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
432 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb); |
|
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
433 | |
|
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
434 | silc_free(wbs); |
|
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
435 | purple_whiteboard_set_protocol_data(wb, NULL); |
| 12058 | 436 | } |
| 437 | ||
|
16396
2217b2765e58
Fix two minor compile warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
438 | void silcpurple_wb_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height) |
| 12058 | 439 | { |
|
40779
a72067fee822
silc: Fix purple_core_get_ui_info usage
Arkadiy Illarionov <qarkai@gmail.com>
parents:
40769
diff
changeset
|
440 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data((PurpleWhiteboard *)wb); |
| 12058 | 441 | *width = wbs->width; |
| 442 | *height = wbs->height; | |
| 443 | } | |
| 444 | ||
| 15884 | 445 | void silcpurple_wb_set_dimensions(PurpleWhiteboard *wb, int width, int height) |
| 12058 | 446 | { |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
447 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb); |
| 15884 | 448 | wbs->width = width > SILCPURPLE_WB_WIDTH_MAX ? SILCPURPLE_WB_WIDTH_MAX : |
| 12058 | 449 | width; |
| 15884 | 450 | wbs->height = height > SILCPURPLE_WB_HEIGHT_MAX ? SILCPURPLE_WB_HEIGHT_MAX : |
| 12058 | 451 | height; |
| 452 | ||
| 453 | /* Update whiteboard */ | |
| 15884 | 454 | purple_whiteboard_set_dimensions(wb, wbs->width, wbs->height); |
| 12058 | 455 | } |
| 456 | ||
|
16396
2217b2765e58
Fix two minor compile warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
457 | void silcpurple_wb_get_brush(const PurpleWhiteboard *wb, int *size, int *color) |
| 12058 | 458 | { |
|
40779
a72067fee822
silc: Fix purple_core_get_ui_info usage
Arkadiy Illarionov <qarkai@gmail.com>
parents:
40769
diff
changeset
|
459 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data((PurpleWhiteboard *)wb); |
| 12058 | 460 | *size = wbs->brush_size; |
| 461 | *color = wbs->brush_color; | |
| 462 | } | |
| 463 | ||
| 15884 | 464 | void silcpurple_wb_set_brush(PurpleWhiteboard *wb, int size, int color) |
| 12058 | 465 | { |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
466 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb); |
| 12058 | 467 | wbs->brush_size = size; |
| 468 | wbs->brush_color = color; | |
| 469 | ||
| 470 | /* Update whiteboard */ | |
| 15884 | 471 | purple_whiteboard_set_brush(wb, size, color); |
| 12058 | 472 | } |
| 473 | ||
| 15884 | 474 | void silcpurple_wb_clear(PurpleWhiteboard *wb) |
| 12058 | 475 | { |
|
32283
06182504a2d4
Update silc prpl to use purple_whiteboard_get_protocol_data() and purple_whiteboard_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
476 | SilcPurpleWb wbs = purple_whiteboard_get_protocol_data(wb); |
| 12058 | 477 | SilcBuffer packet; |
| 478 | int len; | |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
479 | PurpleConnection *gc; |
|
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
480 | SilcPurple sg; |
| 12058 | 481 | |
|
32286
316da124dc0e
Use the new accessor functions of PidginWhiteboard.
Andrew Victor <andrew.victor@mxit.com>
parents:
32283
diff
changeset
|
482 | gc = purple_account_get_connection(purple_whiteboard_get_account(wb)); |
| 12058 | 483 | g_return_if_fail(gc); |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
28981
diff
changeset
|
484 | sg = purple_connection_get_protocol_data(gc); |
| 12058 | 485 | g_return_if_fail(sg); |
| 486 | ||
| 15884 | 487 | len = SILCPURPLE_WB_HEADER; |
| 12058 | 488 | packet = silc_buffer_alloc_size(len); |
| 489 | if (!packet) | |
| 490 | return; | |
| 491 | ||
| 492 | /* Assmeble packet */ | |
| 493 | silc_buffer_format(packet, | |
| 15884 | 494 | SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME), |
| 495 | SILC_STR_UI_CHAR(SILCPURPLE_WB_CLEAR), | |
| 12058 | 496 | SILC_STR_UI_SHORT(wbs->width), |
| 497 | SILC_STR_UI_SHORT(wbs->height), | |
| 498 | SILC_STR_UI_INT(wbs->brush_color), | |
| 499 | SILC_STR_UI_SHORT(wbs->brush_size), | |
| 500 | SILC_STR_END); | |
| 501 | ||
| 502 | /* Send the message */ | |
| 503 | if (wbs->type == 0) { | |
| 504 | /* Private message */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
505 | silc_client_send_private_message(sg->client, sg->conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
506 | wbs->u.client, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
507 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
508 | packet->head, len); |
| 12058 | 509 | } else if (wbs->type == 1) { |
| 510 | /* Channel message */ | |
| 511 | silc_client_send_channel_message(sg->client, sg->conn, | |
| 512 | wbs->u.channel, NULL, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
513 | SILC_MESSAGE_FLAG_DATA, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16492
diff
changeset
|
514 | packet->head, len); |
| 12058 | 515 | } |
| 516 | ||
| 517 | silc_buffer_free(packet); | |
| 518 | } |