Fri, 27 Nov 2009 07:12:35 +0000
Include 'internal.h' before all other headers to make some non-gcc compilers happy.
This in particular impacts Solaris8, where the system headers set
_FILE_OFFSET_BITS to 32, even when it's detected by the config scripts
as 64.
Refs #10523
| 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 | { |
| 108 | SilcClientConnection conn; | |
| 15884 | 109 | PurpleWhiteboard *wb; |
| 110 | SilcPurpleWb wbs; | |
| 12058 | 111 | |
| 112 | conn = sg->conn; | |
| 15884 | 113 | wb = purple_whiteboard_get_session(sg->account, client_entry->nickname); |
| 12058 | 114 | if (!wb) |
| 15884 | 115 | wb = purple_whiteboard_create(sg->account, client_entry->nickname, 0); |
| 12058 | 116 | if (!wb) |
| 117 | return NULL; | |
| 118 | ||
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
119 | if (!wb->proto_data) { |
|
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; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
129 | wb->proto_data = 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) |
| 15884 | 146 | wb = purple_whiteboard_create(sg->account, channel->channel_name, 0); |
| 12058 | 147 | if (!wb) |
| 148 | return NULL; | |
| 149 | ||
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
150 | if (!wb->proto_data) { |
|
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; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
160 | wb->proto_data = 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 | |
| 15884 | 171 | silcpurple_wb_parse(SilcPurpleWb wbs, PurpleWhiteboard *wb, |
| 12058 | 172 | unsigned char *message, SilcUInt32 message_len) |
| 173 | { | |
| 174 | SilcUInt8 command; | |
| 175 | SilcUInt16 width, height, brush_size; | |
| 176 | SilcUInt32 brush_color, x, y, dx, dy; | |
| 177 | SilcBufferStruct buf; | |
| 178 | int ret; | |
| 179 | ||
| 180 | /* Parse the packet */ | |
| 181 | silc_buffer_set(&buf, message, message_len); | |
| 182 | ret = silc_buffer_unformat(&buf, | |
| 183 | SILC_STR_UI_CHAR(&command), | |
| 184 | SILC_STR_UI_SHORT(&width), | |
| 185 | SILC_STR_UI_SHORT(&height), | |
| 186 | SILC_STR_UI_INT(&brush_color), | |
| 187 | SILC_STR_UI_SHORT(&brush_size), | |
| 188 | SILC_STR_END); | |
| 189 | if (ret < 0) | |
| 190 | return; | |
| 191 | silc_buffer_pull(&buf, ret); | |
| 192 | ||
| 193 | /* Update whiteboard if its dimensions changed */ | |
| 194 | if (width != wbs->width || height != wbs->height) | |
| 15884 | 195 | silcpurple_wb_set_dimensions(wb, height, width); |
| 12058 | 196 | |
| 15884 | 197 | if (command == SILCPURPLE_WB_DRAW) { |
| 12058 | 198 | /* Parse data and draw it */ |
| 199 | ret = silc_buffer_unformat(&buf, | |
| 200 | SILC_STR_UI_INT(&dx), | |
| 201 | SILC_STR_UI_INT(&dy), | |
| 202 | SILC_STR_END); | |
| 203 | if (ret < 0) | |
| 204 | return; | |
| 205 | silc_buffer_pull(&buf, 8); | |
| 206 | x = dx; | |
| 207 | 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
|
208 | while (silc_buffer_len(&buf) > 0) { |
| 12058 | 209 | ret = silc_buffer_unformat(&buf, |
| 210 | SILC_STR_UI_INT(&dx), | |
| 211 | SILC_STR_UI_INT(&dy), | |
| 212 | SILC_STR_END); | |
| 213 | if (ret < 0) | |
| 214 | return; | |
| 215 | silc_buffer_pull(&buf, 8); | |
| 216 | ||
| 15884 | 217 | 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
|
218 | brush_color, brush_size); |
| 12058 | 219 | x += dx; |
| 220 | y += dy; | |
| 221 | } | |
| 222 | } | |
| 223 | ||
| 15884 | 224 | if (command == SILCPURPLE_WB_CLEAR) |
| 225 | purple_whiteboard_clear(wb); | |
| 12058 | 226 | } |
| 227 | ||
| 228 | typedef struct { | |
| 229 | unsigned char *message; | |
| 230 | SilcUInt32 message_len; | |
| 15884 | 231 | SilcPurple sg; |
| 12058 | 232 | SilcClientEntry sender; |
| 233 | SilcChannelEntry channel; | |
| 15884 | 234 | } *SilcPurpleWbRequest; |
| 12058 | 235 | |
| 236 | static void | |
| 15884 | 237 | silcpurple_wb_request_cb(SilcPurpleWbRequest req, gint id) |
| 12058 | 238 | { |
| 15884 | 239 | PurpleWhiteboard *wb; |
| 12058 | 240 | |
| 241 | if (id != 1) | |
| 242 | goto out; | |
| 243 | ||
| 244 | if (!req->channel) | |
| 15884 | 245 | wb = silcpurple_wb_init(req->sg, req->sender); |
| 12058 | 246 | else |
| 15884 | 247 | wb = silcpurple_wb_init_ch(req->sg, req->channel); |
| 12058 | 248 | |
| 15884 | 249 | silcpurple_wb_parse(wb->proto_data, wb, req->message, req->message_len); |
| 12058 | 250 | |
| 251 | out: | |
| 252 | silc_free(req->message); | |
| 253 | silc_free(req); | |
| 254 | } | |
| 255 | ||
| 256 | 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
|
257 | silcpurple_wb_request(SilcClient client, const unsigned char *message, |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
258 | SilcUInt32 message_len, SilcClientEntry sender, |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
259 | SilcChannelEntry channel) |
| 12058 | 260 | { |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
261 | char tmp[256]; |
| 15884 | 262 | SilcPurpleWbRequest req; |
| 263 | PurpleConnection *gc; | |
| 264 | SilcPurple sg; | |
| 12058 | 265 | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
266 | gc = client->application; |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16396
diff
changeset
|
267 | sg = gc->proto_data; |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
268 | |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
269 | /* Open whiteboard automatically if requested */ |
| 15884 | 270 | if (purple_account_get_bool(sg->account, "open-wb", FALSE)) { |
| 271 | PurpleWhiteboard *wb; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
272 | |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
273 | if (!channel) |
| 15884 | 274 | wb = silcpurple_wb_init(sg, sender); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
275 | else |
| 15884 | 276 | wb = silcpurple_wb_init_ch(sg, channel); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
277 | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
278 | silcpurple_wb_parse(wb->proto_data, wb, |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
279 | (unsigned char *)message, |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
280 | message_len); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
281 | return; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
282 | } |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
283 | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
284 | /* Close any previous unaccepted requests */ |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
285 | purple_request_close_with_handle(sender); |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
286 | |
| 12058 | 287 | if (!channel) { |
| 288 | g_snprintf(tmp, sizeof(tmp), | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
289 | _("%s sent message to whiteboard. Would you like " |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
290 | "to open the whiteboard?"), sender->nickname); |
| 12058 | 291 | } else { |
| 292 | g_snprintf(tmp, sizeof(tmp), | |
|
20289
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
293 | _("%s sent message to whiteboard on %s channel. " |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
294 | "Would you like to open the whiteboard?"), |
|
5c844288fbec
applied changes from 32f31e981f0618a4167aa98bcc22c2dab13d1550
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17675
diff
changeset
|
295 | sender->nickname, channel->channel_name); |
| 12058 | 296 | } |
| 297 | ||
| 298 | req = silc_calloc(1, sizeof(*req)); | |
| 299 | if (!req) | |
| 300 | return; | |
| 301 | req->message = silc_memdup(message, message_len); | |
| 302 | req->message_len = message_len; | |
| 303 | req->sender = sender; | |
| 304 | req->channel = channel; | |
| 305 | req->sg = sg; | |
| 306 | ||
|
21175
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
307 | purple_request_action(gc, _("Whiteboard"), tmp, NULL, 1, |
|
c6d76b49c206
disapproval of revision '8ba833993a115415727bb1b70362e0bd1603c169'
Richard Laager <rlaager@pidgin.im>
parents:
21174
diff
changeset
|
308 | sg->account, sender->nickname, NULL, req, 2, |
| 15884 | 309 | _("Yes"), G_CALLBACK(silcpurple_wb_request_cb), |
| 310 | _("No"), G_CALLBACK(silcpurple_wb_request_cb)); | |
| 12058 | 311 | } |
| 312 | ||
| 313 | /* Process incoming whiteboard message */ | |
| 314 | ||
| 15884 | 315 | void silcpurple_wb_receive(SilcClient client, SilcClientConnection conn, |
| 12058 | 316 | SilcClientEntry sender, SilcMessagePayload payload, |
| 317 | SilcMessageFlags flags, const unsigned char *message, | |
| 318 | SilcUInt32 message_len) | |
| 319 | { | |
| 15884 | 320 | SilcPurple sg; |
| 321 | PurpleConnection *gc; | |
| 322 | PurpleWhiteboard *wb; | |
| 323 | SilcPurpleWb wbs; | |
| 12058 | 324 | |
| 325 | gc = client->application; | |
| 326 | sg = gc->proto_data; | |
| 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 | ||
| 336 | wbs = wb->proto_data; | |
| 15884 | 337 | silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len); |
| 12058 | 338 | } |
| 339 | ||
| 340 | /* Process incoming whiteboard message on channel */ | |
| 341 | ||
| 15884 | 342 | void silcpurple_wb_receive_ch(SilcClient client, SilcClientConnection conn, |
| 12058 | 343 | SilcClientEntry sender, SilcChannelEntry channel, |
| 344 | SilcMessagePayload payload, | |
| 345 | SilcMessageFlags flags, | |
| 346 | const unsigned char *message, | |
| 347 | SilcUInt32 message_len) | |
| 348 | { | |
| 15884 | 349 | SilcPurple sg; |
| 350 | PurpleConnection *gc; | |
| 351 | PurpleWhiteboard *wb; | |
| 352 | SilcPurpleWb wbs; | |
| 12058 | 353 | |
| 354 | gc = client->application; | |
| 355 | sg = gc->proto_data; | |
| 356 | ||
| 15884 | 357 | wb = purple_whiteboard_get_session(sg->account, channel->channel_name); |
| 12058 | 358 | if (!wb) { |
| 359 | /* Ask user if they want to open the whiteboard */ | |
| 15884 | 360 | silcpurple_wb_request(client, message, message_len, |
| 12058 | 361 | sender, channel); |
| 362 | return; | |
| 363 | } | |
| 364 | ||
| 365 | wbs = wb->proto_data; | |
| 15884 | 366 | silcpurple_wb_parse(wbs, wb, (unsigned char *)message, message_len); |
| 12058 | 367 | } |
| 368 | ||
| 369 | /* Send whiteboard message */ | |
| 370 | ||
| 15884 | 371 | void silcpurple_wb_send(PurpleWhiteboard *wb, GList *draw_list) |
| 12058 | 372 | { |
| 15884 | 373 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 374 | SilcBuffer packet; |
| 375 | GList *list; | |
| 376 | int len; | |
| 15884 | 377 | PurpleConnection *gc; |
| 378 | SilcPurple sg; | |
| 12058 | 379 | |
| 380 | g_return_if_fail(draw_list); | |
| 15884 | 381 | gc = purple_account_get_connection(wb->account); |
| 12058 | 382 | g_return_if_fail(gc); |
| 383 | sg = gc->proto_data; | |
| 384 | g_return_if_fail(sg); | |
| 385 | ||
| 15884 | 386 | len = SILCPURPLE_WB_HEADER; |
| 12058 | 387 | for (list = draw_list; list; list = list->next) |
| 388 | len += 4; | |
| 389 | ||
| 390 | packet = silc_buffer_alloc_size(len); | |
| 391 | if (!packet) | |
| 392 | return; | |
| 393 | ||
| 394 | /* Assmeble packet */ | |
| 395 | silc_buffer_format(packet, | |
| 15884 | 396 | SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME), |
| 397 | SILC_STR_UI_CHAR(SILCPURPLE_WB_DRAW), | |
| 12058 | 398 | SILC_STR_UI_SHORT(wbs->width), |
| 399 | SILC_STR_UI_SHORT(wbs->height), | |
| 400 | SILC_STR_UI_INT(wbs->brush_color), | |
| 401 | SILC_STR_UI_SHORT(wbs->brush_size), | |
| 402 | SILC_STR_END); | |
| 15884 | 403 | silc_buffer_pull(packet, SILCPURPLE_WB_HEADER); |
| 12058 | 404 | for (list = draw_list; list; list = list->next) { |
| 405 | silc_buffer_format(packet, | |
| 406 | SILC_STR_UI_INT(GPOINTER_TO_INT(list->data)), | |
| 407 | SILC_STR_END); | |
| 408 | silc_buffer_pull(packet, 4); | |
| 409 | } | |
| 410 | ||
| 411 | /* Send the message */ | |
| 412 | if (wbs->type == 0) { | |
| 413 | /* 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
|
414 | 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
|
415 | 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
|
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 | } else if (wbs->type == 1) { |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12058
diff
changeset
|
419 | /* Channel message. Channel private keys are not supported. */ |
| 12058 | 420 | silc_client_send_channel_message(sg->client, sg->conn, |
| 421 | 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
|
422 | 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
|
423 | packet->head, len); |
| 12058 | 424 | } |
| 425 | ||
| 426 | silc_buffer_free(packet); | |
| 427 | } | |
| 428 | ||
| 15884 | 429 | /* Purple Whiteboard operations */ |
| 12058 | 430 | |
| 15884 | 431 | void silcpurple_wb_start(PurpleWhiteboard *wb) |
| 12058 | 432 | { |
| 433 | /* Nothing here. Everything is in initialization */ | |
| 434 | } | |
| 435 | ||
| 15884 | 436 | void silcpurple_wb_end(PurpleWhiteboard *wb) |
| 12058 | 437 | { |
| 438 | silc_free(wb->proto_data); | |
| 439 | wb->proto_data = NULL; | |
| 440 | } | |
| 441 | ||
|
16396
2217b2765e58
Fix two minor compile warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
442 | void silcpurple_wb_get_dimensions(const PurpleWhiteboard *wb, int *width, int *height) |
| 12058 | 443 | { |
| 15884 | 444 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 445 | *width = wbs->width; |
| 446 | *height = wbs->height; | |
| 447 | } | |
| 448 | ||
| 15884 | 449 | void silcpurple_wb_set_dimensions(PurpleWhiteboard *wb, int width, int height) |
| 12058 | 450 | { |
| 15884 | 451 | SilcPurpleWb wbs = wb->proto_data; |
| 452 | wbs->width = width > SILCPURPLE_WB_WIDTH_MAX ? SILCPURPLE_WB_WIDTH_MAX : | |
| 12058 | 453 | width; |
| 15884 | 454 | wbs->height = height > SILCPURPLE_WB_HEIGHT_MAX ? SILCPURPLE_WB_HEIGHT_MAX : |
| 12058 | 455 | height; |
| 456 | ||
| 457 | /* Update whiteboard */ | |
| 15884 | 458 | purple_whiteboard_set_dimensions(wb, wbs->width, wbs->height); |
| 12058 | 459 | } |
| 460 | ||
|
16396
2217b2765e58
Fix two minor compile warnings
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
461 | void silcpurple_wb_get_brush(const PurpleWhiteboard *wb, int *size, int *color) |
| 12058 | 462 | { |
| 15884 | 463 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 464 | *size = wbs->brush_size; |
| 465 | *color = wbs->brush_color; | |
| 466 | } | |
| 467 | ||
| 15884 | 468 | void silcpurple_wb_set_brush(PurpleWhiteboard *wb, int size, int color) |
| 12058 | 469 | { |
| 15884 | 470 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 471 | wbs->brush_size = size; |
| 472 | wbs->brush_color = color; | |
| 473 | ||
| 474 | /* Update whiteboard */ | |
| 15884 | 475 | purple_whiteboard_set_brush(wb, size, color); |
| 12058 | 476 | } |
| 477 | ||
| 15884 | 478 | void silcpurple_wb_clear(PurpleWhiteboard *wb) |
| 12058 | 479 | { |
| 15884 | 480 | SilcPurpleWb wbs = wb->proto_data; |
| 12058 | 481 | SilcBuffer packet; |
| 482 | int len; | |
| 15884 | 483 | PurpleConnection *gc; |
| 484 | SilcPurple sg; | |
| 12058 | 485 | |
| 15884 | 486 | gc = purple_account_get_connection(wb->account); |
| 12058 | 487 | g_return_if_fail(gc); |
| 488 | sg = gc->proto_data; | |
| 489 | g_return_if_fail(sg); | |
| 490 | ||
| 15884 | 491 | len = SILCPURPLE_WB_HEADER; |
| 12058 | 492 | packet = silc_buffer_alloc_size(len); |
| 493 | if (!packet) | |
| 494 | return; | |
| 495 | ||
| 496 | /* Assmeble packet */ | |
| 497 | silc_buffer_format(packet, | |
| 15884 | 498 | SILC_STR_UI32_STRING(SILCPURPLE_WB_MIME), |
| 499 | SILC_STR_UI_CHAR(SILCPURPLE_WB_CLEAR), | |
| 12058 | 500 | SILC_STR_UI_SHORT(wbs->width), |
| 501 | SILC_STR_UI_SHORT(wbs->height), | |
| 502 | SILC_STR_UI_INT(wbs->brush_color), | |
| 503 | SILC_STR_UI_SHORT(wbs->brush_size), | |
| 504 | SILC_STR_END); | |
| 505 | ||
| 506 | /* Send the message */ | |
| 507 | if (wbs->type == 0) { | |
| 508 | /* 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
|
509 | 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
|
510 | 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
|
511 | 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
|
512 | packet->head, len); |
| 12058 | 513 | } else if (wbs->type == 1) { |
| 514 | /* Channel message */ | |
| 515 | silc_client_send_channel_message(sg->client, sg->conn, | |
| 516 | 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
|
517 | 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
|
518 | packet->head, len); |
| 12058 | 519 | } |
| 520 | ||
| 521 | silc_buffer_free(packet); | |
| 522 | } |