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