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