8849
|
1 /*
|
|
2
|
|
3 silcgaim_chat.c
|
|
4
|
|
5 Author: Pekka Riikonen <priikone@silcnet.org>
|
|
6
|
|
7 Copyright (C) 2004 Pekka Riikonen
|
|
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
|
|
20 #include "silcincludes.h"
|
|
21 #include "silcclient.h"
|
|
22 #include "silcgaim.h"
|
|
23
|
|
24 /***************************** Channel Routines ******************************/
|
|
25
|
|
26 GList *silcgaim_chat_info(GaimConnection *gc)
|
|
27 {
|
|
28 GList *ci = NULL;
|
|
29 struct proto_chat_entry *pce;
|
|
30
|
|
31 pce = g_new0(struct proto_chat_entry, 1);
|
|
32 pce->label = _("_Channel:");
|
|
33 pce->identifier = "channel";
|
|
34 ci = g_list_append(ci, pce);
|
|
35
|
|
36 pce = g_new0(struct proto_chat_entry, 1);
|
|
37 pce->label = _("_Passphrase:");
|
|
38 pce->identifier = "passphrase";
|
|
39 pce->secret = TRUE;
|
|
40 ci = g_list_append(ci, pce);
|
|
41
|
|
42 return ci;
|
|
43 }
|
|
44
|
|
45 static void
|
9030
|
46 silcgaim_chat_getinfo(GaimBlistNode *node, gpointer data);
|
8849
|
47
|
|
48 static void
|
|
49 silcgaim_chat_getinfo_res(SilcClient client,
|
|
50 SilcClientConnection conn,
|
|
51 SilcChannelEntry *channels,
|
|
52 SilcUInt32 channels_count,
|
|
53 void *context)
|
|
54 {
|
|
55 GHashTable *components = context;
|
|
56 GaimConnection *gc = client->application;
|
|
57 const char *chname;
|
|
58 char tmp[256];
|
|
59
|
|
60 chname = g_hash_table_lookup(components, "channel");
|
|
61 if (!chname)
|
|
62 return;
|
|
63
|
|
64 if (!channels) {
|
|
65 g_snprintf(tmp, sizeof(tmp),
|
|
66 _("Channel %s does not exist in the network"), chname);
|
|
67 gaim_notify_error(gc, _("Channel Information"),
|
|
68 _("Cannot get channel information"), tmp);
|
|
69 return;
|
|
70 }
|
|
71
|
|
72 silcgaim_chat_getinfo(gc, components);
|
|
73 }
|
|
74
|
|
75 static void
|
9030
|
76 silcgaim_chat_getinfo(GaimBlistNode *node, gpointer data)
|
8849
|
77 {
|
9030
|
78 GaimChat *chat;
|
|
79 GaimConnection *gc;
|
|
80 SilcGaim sg;
|
|
81
|
8849
|
82 const char *chname;
|
|
83 char *buf, tmp[256];
|
|
84 GString *s;
|
|
85 SilcChannelEntry channel;
|
|
86 SilcHashTableList htl;
|
|
87 SilcChannelUser chu;
|
|
88
|
9030
|
89 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
8849
|
90
|
9030
|
91 chat = (GaimChat *) node;
|
|
92 gc = gaim_account_get_connection(chat->account);
|
|
93 sg = gc->proto_data;
|
|
94
|
|
95 chname = g_hash_table_lookup(chat->components, "channel");
|
8849
|
96 if (!chname)
|
|
97 return;
|
|
98 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
99 (char *)chname);
|
|
100 if (!channel) {
|
|
101 silc_client_get_channel_resolve(sg->client, sg->conn,
|
|
102 (char *)chname,
|
|
103 silcgaim_chat_getinfo_res,
|
9030
|
104 chat->components);
|
8849
|
105 return;
|
|
106 }
|
|
107
|
|
108 s = g_string_new("");
|
|
109 g_string_append_printf(s, "Channel Name:\t\t%s\n", channel->channel_name);
|
|
110 if (channel->user_list && silc_hash_table_count(channel->user_list))
|
|
111 g_string_append_printf(s, "User Count:\t\t%d\n",
|
|
112 (int)silc_hash_table_count(channel->user_list));
|
|
113
|
|
114 silc_hash_table_list(channel->user_list, &htl);
|
|
115 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
116 if (chu->mode & SILC_CHANNEL_UMODE_CHANFO) {
|
|
117 g_string_append_printf(s, "Channel Founder:\t%s\n",
|
|
118 chu->client->nickname);
|
|
119 break;
|
|
120 }
|
|
121 }
|
|
122 silc_hash_table_list_reset(&htl);
|
|
123
|
|
124 if (channel->channel_key)
|
|
125 g_string_append_printf(s, "Channel Cipher:\t\t%s\n",
|
|
126 silc_cipher_get_name(channel->channel_key));
|
|
127 if (channel->hmac)
|
|
128 g_string_append_printf(s, "Channel HMAC:\t\t%s\n",
|
|
129 silc_hmac_get_name(channel->hmac));
|
|
130
|
|
131 if (channel->topic)
|
|
132 g_string_append_printf(s, "\nChannel Topic:\n\%s\n", channel->topic);
|
|
133
|
|
134 if (channel->mode) {
|
|
135 g_string_append_printf(s, "\nChannel Modes:\n");
|
|
136 silcgaim_get_chmode_string(channel->mode, tmp, sizeof(tmp));
|
|
137 g_string_append_printf(s, tmp);
|
|
138 g_string_append_printf(s, "\n");
|
|
139 }
|
|
140
|
|
141 if (channel->founder_key) {
|
|
142 char *fingerprint, *babbleprint;
|
|
143 unsigned char *pk;
|
|
144 SilcUInt32 pk_len;
|
|
145 pk = silc_pkcs_public_key_encode(channel->founder_key, &pk_len);
|
|
146 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
147 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
|
|
148
|
|
149 g_string_append_printf(s, "\nFounder Key Fingerprint:\n%s\n\n", fingerprint);
|
|
150 g_string_append_printf(s, "Founder Key Babbleprint:\n%s", babbleprint);
|
|
151
|
|
152 silc_free(fingerprint);
|
|
153 silc_free(babbleprint);
|
|
154 silc_free(pk);
|
|
155 }
|
|
156
|
|
157 buf = g_string_free(s, FALSE);
|
|
158 gaim_notify_message(NULL, GAIM_NOTIFY_MSG_INFO,
|
|
159 _("Channel Information"),
|
|
160 _("Channel Information"),
|
|
161 buf, NULL, NULL);
|
|
162 g_free(buf);
|
|
163 }
|
|
164
|
|
165
|
|
166 #if 0 /* XXX For now these are not implemented. We need better
|
|
167 listview dialog from Gaim for these. */
|
|
168 /************************** Channel Invite List ******************************/
|
|
169
|
|
170 static void
|
9030
|
171 silcgaim_chat_invitelist(GaimBlistNode *node, gpointer data);
|
8849
|
172 {
|
|
173
|
|
174 }
|
|
175
|
|
176
|
|
177 /**************************** Channel Ban List *******************************/
|
|
178
|
|
179 static void
|
9030
|
180 silcgaim_chat_banlist(GaimBlistNode *node, gpointer data);
|
8849
|
181 {
|
|
182
|
|
183 }
|
|
184 #endif
|
|
185
|
|
186
|
|
187 /************************* Channel Authentication ****************************/
|
|
188
|
|
189 typedef struct {
|
|
190 SilcGaim sg;
|
|
191 SilcChannelEntry channel;
|
|
192 GaimChat *c;
|
|
193 SilcBuffer pubkeys;
|
|
194 } *SilcGaimChauth;
|
|
195
|
|
196 static void
|
|
197 silcgaim_chat_chpk_add(void *user_data, const char *name)
|
|
198 {
|
|
199 SilcGaimChauth sgc = (SilcGaimChauth)user_data;
|
|
200 SilcGaim sg = sgc->sg;
|
|
201 SilcClient client = sg->client;
|
|
202 SilcClientConnection conn = sg->conn;
|
|
203 SilcPublicKey public_key;
|
|
204 SilcBuffer chpks, pk, chidp;
|
|
205 unsigned char mode[4];
|
|
206 SilcUInt32 m;
|
|
207
|
|
208 /* Load the public key */
|
|
209 if (!silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_PEM) &&
|
|
210 !silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_BIN)) {
|
|
211 silcgaim_chat_chauth_show(sgc->sg, sgc->channel, sgc->pubkeys);
|
|
212 silc_buffer_free(sgc->pubkeys);
|
|
213 silc_free(sgc);
|
|
214 gaim_notify_error(client->application,
|
|
215 _("Add Channel Public Key"),
|
|
216 _("Could not load public key"), NULL);
|
|
217 return;
|
|
218 }
|
|
219
|
|
220 pk = silc_pkcs_public_key_payload_encode(public_key);
|
|
221 chpks = silc_buffer_alloc_size(2);
|
|
222 SILC_PUT16_MSB(1, chpks->head);
|
|
223 chpks = silc_argument_payload_encode_one(chpks, pk->data,
|
|
224 pk->len, 0x00);
|
|
225 silc_buffer_free(pk);
|
|
226
|
|
227 m = sgc->channel->mode;
|
|
228 m |= SILC_CHANNEL_MODE_CHANNEL_AUTH;
|
|
229
|
|
230 /* Send CMODE */
|
|
231 SILC_PUT32_MSB(m, mode);
|
|
232 chidp = silc_id_payload_encode(sgc->channel->id, SILC_ID_CHANNEL);
|
|
233 silc_client_command_send(client, conn, SILC_COMMAND_CMODE,
|
|
234 ++conn->cmd_ident, 3,
|
|
235 1, chidp->data, chidp->len,
|
|
236 2, mode, sizeof(mode),
|
|
237 9, chpks->data, chpks->len);
|
|
238 silc_buffer_free(chpks);
|
|
239 silc_buffer_free(chidp);
|
|
240 silc_buffer_free(sgc->pubkeys);
|
|
241 silc_free(sgc);
|
|
242 }
|
|
243
|
|
244 static void
|
|
245 silcgaim_chat_chpk_cancel(void *user_data, const char *name)
|
|
246 {
|
|
247 SilcGaimChauth sgc = (SilcGaimChauth)user_data;
|
|
248 silcgaim_chat_chauth_show(sgc->sg, sgc->channel, sgc->pubkeys);
|
|
249 silc_buffer_free(sgc->pubkeys);
|
|
250 silc_free(sgc);
|
|
251 }
|
|
252
|
|
253 static void
|
|
254 silcgaim_chat_chpk_cb(SilcGaimChauth sgc, GaimRequestFields *fields)
|
|
255 {
|
|
256 SilcGaim sg = sgc->sg;
|
|
257 SilcClient client = sg->client;
|
|
258 SilcClientConnection conn = sg->conn;
|
|
259 GaimRequestField *f;
|
|
260 const GList *list;
|
|
261 SilcPublicKey public_key;
|
|
262 SilcBuffer chpks, pk, chidp;
|
|
263 SilcUInt16 c = 0, ct;
|
|
264 unsigned char mode[4];
|
|
265 SilcUInt32 m;
|
|
266
|
|
267 f = gaim_request_fields_get_field(fields, "list");
|
|
268 if (!gaim_request_field_list_get_selected(f)) {
|
|
269 /* Add new public key */
|
8877
|
270 gaim_request_file(NULL, _("Open Public Key..."), "",
|
8849
|
271 G_CALLBACK(silcgaim_chat_chpk_add),
|
|
272 G_CALLBACK(silcgaim_chat_chpk_cancel), sgc);
|
|
273 return;
|
|
274 }
|
|
275
|
|
276 list = gaim_request_field_list_get_items(f);
|
|
277 chpks = silc_buffer_alloc_size(2);
|
|
278
|
|
279 for (ct = 0; list; list = list->next, ct++) {
|
|
280 public_key = gaim_request_field_list_get_data(f, list->data);
|
|
281 if (gaim_request_field_list_is_selected(f, list->data)) {
|
|
282 /* Delete this public key */
|
|
283 pk = silc_pkcs_public_key_payload_encode(public_key);
|
|
284 chpks = silc_argument_payload_encode_one(chpks, pk->data,
|
|
285 pk->len, 0x01);
|
|
286 silc_buffer_free(pk);
|
|
287 c++;
|
|
288 }
|
|
289 silc_pkcs_public_key_free(public_key);
|
|
290 }
|
|
291 if (!c) {
|
|
292 silc_buffer_free(chpks);
|
|
293 return;
|
|
294 }
|
|
295 SILC_PUT16_MSB(c, chpks->head);
|
|
296
|
|
297 m = sgc->channel->mode;
|
|
298 if (ct == c)
|
|
299 m &= ~SILC_CHANNEL_MODE_CHANNEL_AUTH;
|
|
300
|
|
301 /* Send CMODE */
|
|
302 SILC_PUT32_MSB(m, mode);
|
|
303 chidp = silc_id_payload_encode(sgc->channel->id, SILC_ID_CHANNEL);
|
|
304 silc_client_command_send(client, conn, SILC_COMMAND_CMODE,
|
|
305 ++conn->cmd_ident, 3,
|
|
306 1, chidp->data, chidp->len,
|
|
307 2, mode, sizeof(mode),
|
|
308 9, chpks->data, chpks->len);
|
|
309 silc_buffer_free(chpks);
|
|
310 silc_buffer_free(chidp);
|
|
311 silc_buffer_free(sgc->pubkeys);
|
|
312 silc_free(sgc);
|
|
313 }
|
|
314
|
|
315 static void
|
|
316 silcgaim_chat_chauth_ok(SilcGaimChauth sgc, GaimRequestFields *fields)
|
|
317 {
|
|
318 SilcGaim sg = sgc->sg;
|
|
319 GaimRequestField *f;
|
|
320 const char *curpass, *val;
|
|
321 int set;
|
|
322
|
|
323 f = gaim_request_fields_get_field(fields, "passphrase");
|
|
324 val = gaim_request_field_string_get_value(f);
|
|
325 curpass = gaim_blist_node_get_string((GaimBlistNode *)sgc->c, "passphrase");
|
|
326
|
|
327 if (!val && curpass)
|
|
328 set = 0;
|
|
329 else if (val && !curpass)
|
|
330 set = 1;
|
|
331 else if (val && curpass && strcmp(val, curpass))
|
|
332 set = 1;
|
|
333 else
|
|
334 set = -1;
|
|
335
|
|
336 if (set == 1) {
|
|
337 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
|
338 sgc->channel->channel_name, "+a", val, NULL);
|
|
339 gaim_blist_node_set_string((GaimBlistNode *)sgc->c, "passphrase", val);
|
|
340 gaim_blist_save();
|
|
341 } else if (set == 0) {
|
|
342 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
|
343 sgc->channel->channel_name, "-a", NULL);
|
|
344 gaim_blist_node_remove_setting((GaimBlistNode *)sgc->c, "passphrase");
|
|
345 gaim_blist_save();
|
|
346 }
|
|
347
|
|
348 silc_buffer_free(sgc->pubkeys);
|
|
349 silc_free(sgc);
|
|
350 }
|
|
351
|
|
352 void silcgaim_chat_chauth_show(SilcGaim sg, SilcChannelEntry channel,
|
|
353 SilcBuffer channel_pubkeys)
|
|
354 {
|
|
355 SilcUInt16 argc;
|
|
356 SilcArgumentPayload chpks;
|
|
357 unsigned char *pk;
|
|
358 SilcUInt32 pk_len, type;
|
|
359 char *fingerprint, *babbleprint;
|
|
360 SilcPublicKey pubkey;
|
|
361 SilcPublicKeyIdentifier ident;
|
|
362 char tmp2[1024], t[512];
|
|
363 GaimRequestFields *fields;
|
|
364 GaimRequestFieldGroup *g;
|
|
365 GaimRequestField *f;
|
|
366 SilcGaimChauth sgc;
|
|
367 const char *curpass = NULL;
|
|
368
|
|
369 sgc = silc_calloc(1, sizeof(*sgc));
|
|
370 if (!sgc)
|
|
371 return;
|
|
372 sgc->sg = sg;
|
|
373 sgc->channel = channel;
|
|
374
|
|
375 fields = gaim_request_fields_new();
|
|
376
|
|
377 if (sgc->c)
|
|
378 curpass = gaim_blist_node_get_string((GaimBlistNode *)sgc->c, "passphrase");
|
|
379
|
|
380 g = gaim_request_field_group_new(NULL);
|
|
381 f = gaim_request_field_string_new("passphrase", _("Channel Passphrase"),
|
|
382 curpass, FALSE);
|
|
383 gaim_request_field_string_set_masked(f, TRUE);
|
|
384 gaim_request_field_group_add_field(g, f);
|
|
385 gaim_request_fields_add_group(fields, g);
|
|
386
|
|
387 g = gaim_request_field_group_new(NULL);
|
|
388 f = gaim_request_field_label_new("l1", _("Channel Public Keys List"));
|
|
389 gaim_request_field_group_add_field(g, f);
|
|
390 gaim_request_fields_add_group(fields, g);
|
|
391
|
|
392 g_snprintf(t, sizeof(t),
|
|
393 _("Channel authentication is used to secure the channel from "
|
|
394 "unauthorized access. The authentication may be based on "
|
|
395 "passphrase and digital signatures. If passphrase is set, it "
|
|
396 "is required to be able to join. If channel public keys are set "
|
|
397 "then only users whose public keys are listed are able to join."));
|
|
398
|
|
399 if (!channel_pubkeys) {
|
|
400 f = gaim_request_field_list_new("list", NULL);
|
|
401 gaim_request_field_group_add_field(g, f);
|
|
402 gaim_request_fields(NULL, _("Channel Authentication"),
|
|
403 _("Channel Authentication"), t, fields,
|
|
404 "Add / Remove", G_CALLBACK(silcgaim_chat_chpk_cb),
|
|
405 "OK", G_CALLBACK(silcgaim_chat_chauth_ok), sgc);
|
|
406 return;
|
|
407 }
|
|
408 sgc->pubkeys = silc_buffer_copy(channel_pubkeys);
|
|
409
|
|
410 g = gaim_request_field_group_new(NULL);
|
|
411 f = gaim_request_field_list_new("list", NULL);
|
|
412 gaim_request_field_group_add_field(g, f);
|
|
413 gaim_request_fields_add_group(fields, g);
|
|
414
|
|
415 SILC_GET16_MSB(argc, channel_pubkeys->data);
|
|
416 chpks = silc_argument_payload_parse(channel_pubkeys->data + 2,
|
|
417 channel_pubkeys->len - 2, argc);
|
|
418 if (!chpks)
|
|
419 return;
|
|
420
|
|
421 pk = silc_argument_get_first_arg(chpks, &type, &pk_len);
|
|
422 while (pk) {
|
|
423 fingerprint = silc_hash_fingerprint(NULL, pk + 4, pk_len - 4);
|
|
424 babbleprint = silc_hash_babbleprint(NULL, pk + 4, pk_len - 4);
|
|
425 silc_pkcs_public_key_payload_decode(pk, pk_len, &pubkey);
|
|
426 ident = silc_pkcs_decode_identifier(pubkey->identifier);
|
|
427
|
|
428 g_snprintf(tmp2, sizeof(tmp2), "%s\n %s\n %s",
|
|
429 ident->realname ? ident->realname : ident->username ?
|
|
430 ident->username : "", fingerprint, babbleprint);
|
|
431 gaim_request_field_list_add(f, tmp2, pubkey);
|
|
432
|
|
433 silc_free(fingerprint);
|
|
434 silc_free(babbleprint);
|
|
435 silc_pkcs_free_identifier(ident);
|
|
436 pk = silc_argument_get_next_arg(chpks, &type, &pk_len);
|
|
437 }
|
|
438
|
|
439 gaim_request_field_list_set_multi_select(f, FALSE);
|
|
440 gaim_request_fields(NULL, _("Channel Authentication"),
|
|
441 _("Channel Authentication"), t, fields,
|
|
442 "Add / Remove", G_CALLBACK(silcgaim_chat_chpk_cb),
|
|
443 "OK", G_CALLBACK(silcgaim_chat_chauth_ok), sgc);
|
|
444
|
|
445 silc_argument_payload_free(chpks);
|
|
446 }
|
|
447
|
|
448 static void
|
9030
|
449 silcgaim_chat_chauth(GaimBlistNode *node, gpointer data)
|
8849
|
450 {
|
9030
|
451 GaimChat *chat;
|
|
452 GaimConnection *gc;
|
|
453 SilcGaim sg;
|
|
454
|
|
455 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
456
|
|
457 chat = (GaimChat *) node;
|
|
458 gc = gaim_account_get_connection(chat->account);
|
|
459 sg = gc->proto_data;
|
|
460
|
8849
|
461 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
462 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
463 "+C", NULL);
|
|
464 }
|
|
465
|
|
466
|
|
467 /************************** Channel Private Groups **************************/
|
|
468
|
|
469 /* Private groups are "virtual" channels. They are groups inside a channel.
|
|
470 This is implemented by using channel private keys. By knowing a channel
|
|
471 private key user becomes part of that group and is able to talk on that
|
|
472 group. Other users, on the same channel, won't be able to see the
|
|
473 messages of that group. It is possible to have multiple groups inside
|
|
474 a channel - and thus having multiple private keys on the channel. */
|
|
475
|
|
476 typedef struct {
|
|
477 SilcGaim sg;
|
|
478 GaimChat *c;
|
|
479 const char *channel;
|
|
480 } *SilcGaimCharPrv;
|
|
481
|
|
482 static void
|
|
483 silcgaim_chat_prv_add(SilcGaimCharPrv p, GaimRequestFields *fields)
|
|
484 {
|
|
485 SilcGaim sg = p->sg;
|
|
486 char tmp[512];
|
|
487 GaimRequestField *f;
|
|
488 const char *name, *passphrase, *alias;
|
|
489 GHashTable *comp;
|
|
490 GaimGroup *g;
|
|
491 GaimChat *cn;
|
|
492
|
|
493 f = gaim_request_fields_get_field(fields, "name");
|
|
494 name = gaim_request_field_string_get_value(f);
|
|
495 if (!name) {
|
|
496 silc_free(p);
|
|
497 return;
|
|
498 }
|
|
499 f = gaim_request_fields_get_field(fields, "passphrase");
|
|
500 passphrase = gaim_request_field_string_get_value(f);
|
|
501 f = gaim_request_fields_get_field(fields, "alias");
|
|
502 alias = gaim_request_field_string_get_value(f);
|
|
503
|
|
504 /* Add private group to buddy list */
|
|
505 g_snprintf(tmp, sizeof(tmp), "%s [Private Group]", name);
|
|
506 comp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
507 g_hash_table_replace(comp, g_strdup("channel"), g_strdup(tmp));
|
|
508 g_hash_table_replace(comp, g_strdup("passphrase"), g_strdup(passphrase));
|
|
509
|
|
510 cn = gaim_chat_new(sg->account, alias, comp);
|
|
511 g = (GaimGroup *)p->c->node.parent;
|
|
512 gaim_blist_add_chat(cn, g, (GaimBlistNode *)p->c);
|
|
513
|
|
514 /* Associate to a real channel */
|
|
515 gaim_blist_node_set_string((GaimBlistNode *)cn, "parentch", p->channel);
|
|
516 gaim_blist_save();
|
|
517
|
|
518 /* Join the group */
|
|
519 silcgaim_chat_join(sg->gc, comp);
|
|
520
|
|
521 silc_free(p);
|
|
522 }
|
|
523
|
|
524 static void
|
|
525 silcgaim_chat_prv_cancel(SilcGaimCharPrv p, GaimRequestFields *fields)
|
|
526 {
|
|
527 silc_free(p);
|
|
528 }
|
|
529
|
|
530 static void
|
9030
|
531 silcgaim_chat_prv(GaimBlistNode *node, gpointer data)
|
8849
|
532 {
|
9030
|
533 GaimChat *chat;
|
|
534 GaimConnection *gc;
|
|
535 SilcGaim sg;
|
|
536
|
8849
|
537 SilcGaimCharPrv p;
|
|
538 GaimRequestFields *fields;
|
|
539 GaimRequestFieldGroup *g;
|
|
540 GaimRequestField *f;
|
|
541 char tmp[512];
|
|
542
|
9030
|
543 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
544
|
|
545 chat = (GaimChat *) node;
|
|
546 gc = gaim_account_get_connection(chat->account);
|
|
547 sg = gc->proto_data;
|
|
548
|
8849
|
549 p = silc_calloc(1, sizeof(*p));
|
|
550 if (!p)
|
|
551 return;
|
|
552 p->sg = sg;
|
|
553
|
9030
|
554 p->channel = g_hash_table_lookup(chat->components, "channel");
|
8849
|
555 p->c = gaim_blist_find_chat(sg->account, p->channel);
|
|
556
|
|
557 fields = gaim_request_fields_new();
|
|
558
|
|
559 g = gaim_request_field_group_new(NULL);
|
|
560 f = gaim_request_field_string_new("name", _("Group Name"),
|
|
561 NULL, FALSE);
|
|
562 gaim_request_field_group_add_field(g, f);
|
|
563
|
|
564 f = gaim_request_field_string_new("passphrase", _("Passphrase"),
|
|
565 NULL, FALSE);
|
|
566 gaim_request_field_string_set_masked(f, TRUE);
|
|
567 gaim_request_field_group_add_field(g, f);
|
|
568
|
|
569 f = gaim_request_field_string_new("alias", _("Alias"),
|
|
570 NULL, FALSE);
|
|
571 gaim_request_field_group_add_field(g, f);
|
|
572 gaim_request_fields_add_group(fields, g);
|
|
573
|
|
574 g_snprintf(tmp, sizeof(tmp),
|
|
575 _("Please enter the %s channel private group name and passphrase."),
|
|
576 p->channel);
|
|
577 gaim_request_fields(NULL, _("Add Channel Private Group"), NULL, tmp, fields,
|
|
578 "Add", G_CALLBACK(silcgaim_chat_prv_add),
|
|
579 "Cancel", G_CALLBACK(silcgaim_chat_prv_cancel), p);
|
|
580 }
|
|
581
|
|
582
|
|
583 /****************************** Channel Modes ********************************/
|
|
584
|
|
585 static void
|
9030
|
586 silcgaim_chat_permanent_reset(GaimBlistNode *node, gpointer data)
|
8849
|
587 {
|
9030
|
588 GaimChat *chat;
|
|
589 GaimConnection *gc;
|
|
590 SilcGaim sg;
|
|
591
|
|
592 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
593
|
|
594 chat = (GaimChat *) node;
|
|
595 gc = gaim_account_get_connection(chat->account);
|
|
596 sg = gc->proto_data;
|
|
597
|
8849
|
598 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
599 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
600 "-f", NULL);
|
|
601 }
|
|
602
|
|
603 static void
|
9030
|
604 silcgaim_chat_permanent(GaimBlistNode *node, gpointer data)
|
8849
|
605 {
|
9030
|
606 GaimChat *chat;
|
|
607 GaimConnection *gc;
|
|
608 SilcGaim sg;
|
8849
|
609 const char *channel;
|
|
610
|
9030
|
611 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
612
|
|
613 chat = (GaimChat *) node;
|
|
614 gc = gaim_account_get_connection(chat->account);
|
|
615 sg = gc->proto_data;
|
|
616
|
8849
|
617 if (!sg->conn)
|
|
618 return;
|
|
619
|
|
620 /* XXX we should have ability to define which founder
|
|
621 key to use. Now we use the user's own public key
|
|
622 (default key). */
|
|
623
|
|
624 /* Call CMODE */
|
9030
|
625 channel = g_hash_table_lookup(chat->components, "channel");
|
8849
|
626 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE", channel,
|
|
627 "+f", NULL);
|
|
628 }
|
|
629
|
|
630 typedef struct {
|
|
631 SilcGaim sg;
|
|
632 const char *channel;
|
|
633 } *SilcGaimChatInput;
|
|
634
|
|
635 static void
|
|
636 silcgaim_chat_ulimit_cb(SilcGaimChatInput s, const char *limit)
|
|
637 {
|
|
638 SilcChannelEntry channel;
|
|
639 int ulimit = 0;
|
|
640
|
|
641 channel = silc_client_get_channel(s->sg->client, s->sg->conn,
|
|
642 (char *)s->channel);
|
|
643 if (!channel)
|
|
644 return;
|
|
645 if (limit)
|
|
646 ulimit = atoi(limit);
|
|
647
|
|
648 if (!limit || !(*limit) || *limit == '0') {
|
|
649 if (limit && ulimit == channel->user_limit) {
|
|
650 silc_free(s);
|
|
651 return;
|
|
652 }
|
|
653 silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
|
|
654 s->channel, "-l", NULL);
|
|
655
|
|
656 silc_free(s);
|
|
657 return;
|
|
658 }
|
|
659
|
|
660 if (ulimit == channel->user_limit) {
|
|
661 silc_free(s);
|
|
662 return;
|
|
663 }
|
|
664
|
|
665 /* Call CMODE */
|
|
666 silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
|
|
667 s->channel, "+l", limit, NULL);
|
|
668
|
|
669 silc_free(s);
|
|
670 }
|
|
671
|
|
672 static void
|
9030
|
673 silcgaim_chat_ulimit(GaimBlistNode *node, gpointer data)
|
8849
|
674 {
|
9030
|
675 GaimChat *chat;
|
|
676 GaimConnection *gc;
|
|
677 SilcGaim sg;
|
|
678
|
8849
|
679 SilcGaimChatInput s;
|
|
680 SilcChannelEntry channel;
|
|
681 const char *ch;
|
|
682 char tmp[32];
|
|
683
|
9030
|
684 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
685
|
|
686 chat = (GaimChat *) node;
|
|
687 gc = gaim_account_get_connection(chat->account);
|
|
688 sg = gc->proto_data;
|
|
689
|
8849
|
690 if (!sg->conn)
|
|
691 return;
|
|
692
|
9030
|
693 ch = g_strdup(g_hash_table_lookup(chat->components, "channel"));
|
8849
|
694 channel = silc_client_get_channel(sg->client, sg->conn, (char *)ch);
|
|
695 if (!channel)
|
|
696 return;
|
|
697
|
|
698 s = silc_calloc(1, sizeof(*s));
|
|
699 if (!s)
|
|
700 return;
|
|
701 s->channel = ch;
|
|
702 s->sg = sg;
|
|
703 g_snprintf(tmp, sizeof(tmp), "%d", (int)channel->user_limit);
|
|
704 gaim_request_input(NULL, _("User Limit"), NULL,
|
|
705 _("Set user limit on channel. Set to zero to reset user limit."),
|
|
706 tmp, FALSE, FALSE, NULL,
|
|
707 _("OK"), G_CALLBACK(silcgaim_chat_ulimit_cb),
|
|
708 _("Cancel"), G_CALLBACK(silcgaim_chat_ulimit_cb), s);
|
|
709 }
|
|
710
|
|
711 static void
|
9030
|
712 silcgaim_chat_resettopic(GaimBlistNode *node, gpointer data)
|
8849
|
713 {
|
9030
|
714 GaimChat *chat;
|
|
715 GaimConnection *gc;
|
|
716 SilcGaim sg;
|
|
717
|
|
718 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
719
|
|
720 chat = (GaimChat *) node;
|
|
721 gc = gaim_account_get_connection(chat->account);
|
|
722 sg = gc->proto_data;
|
|
723
|
8849
|
724 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
725 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
726 "-t", NULL);
|
|
727 }
|
|
728
|
|
729 static void
|
9030
|
730 silcgaim_chat_settopic(GaimBlistNode *node, gpointer data)
|
8849
|
731 {
|
9030
|
732 GaimChat *chat;
|
|
733 GaimConnection *gc;
|
|
734 SilcGaim sg;
|
|
735
|
|
736 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
737
|
|
738 chat = (GaimChat *) node;
|
|
739 gc = gaim_account_get_connection(chat->account);
|
|
740 sg = gc->proto_data;
|
|
741
|
8849
|
742 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
743 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
744 "+t", NULL);
|
|
745 }
|
|
746
|
|
747 static void
|
9030
|
748 silcgaim_chat_resetprivate(GaimBlistNode *node, gpointer data)
|
8849
|
749 {
|
9030
|
750 GaimChat *chat;
|
|
751 GaimConnection *gc;
|
|
752 SilcGaim sg;
|
|
753
|
|
754 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
755
|
|
756 chat = (GaimChat *) node;
|
|
757 gc = gaim_account_get_connection(chat->account);
|
|
758 sg = gc->proto_data;
|
|
759
|
8849
|
760 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
761 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
762 "-p", NULL);
|
|
763 }
|
|
764
|
|
765 static void
|
9030
|
766 silcgaim_chat_setprivate(GaimBlistNode *node, gpointer data)
|
8849
|
767 {
|
9030
|
768 GaimChat *chat;
|
|
769 GaimConnection *gc;
|
|
770 SilcGaim sg;
|
|
771
|
|
772 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
773
|
|
774 chat = (GaimChat *) node;
|
|
775 gc = gaim_account_get_connection(chat->account);
|
|
776 sg = gc->proto_data;
|
|
777
|
8849
|
778 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
779 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
780 "+p", NULL);
|
|
781 }
|
|
782
|
|
783 static void
|
9030
|
784 silcgaim_chat_resetsecret(GaimBlistNode *node, gpointer data)
|
8849
|
785 {
|
9030
|
786 GaimChat *chat;
|
|
787 GaimConnection *gc;
|
|
788 SilcGaim sg;
|
|
789
|
|
790 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
791
|
|
792 chat = (GaimChat *) node;
|
|
793 gc = gaim_account_get_connection(chat->account);
|
|
794 sg = gc->proto_data;
|
|
795
|
8849
|
796 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
797 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
798 "-s", NULL);
|
|
799 }
|
|
800
|
|
801 static void
|
9030
|
802 silcgaim_chat_setsecret(GaimBlistNode *node, gpointer data)
|
8849
|
803 {
|
9030
|
804 GaimChat *chat;
|
|
805 GaimConnection *gc;
|
|
806 SilcGaim sg;
|
|
807
|
|
808 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
809
|
|
810 chat = (GaimChat *) node;
|
|
811 gc = gaim_account_get_connection(chat->account);
|
|
812 sg = gc->proto_data;
|
|
813
|
8849
|
814 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
815 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
816 "+s", NULL);
|
|
817 }
|
|
818
|
9030
|
819 GList *silcgaim_chat_menu(GaimChat *chat)
|
8849
|
820 {
|
9030
|
821 GHashTable components = chat->components;
|
|
822 GaimConnection *gc = gaim_account_get_connection(chat->account);
|
8849
|
823 SilcGaim sg = gc->proto_data;
|
|
824 SilcClientConnection conn = sg->conn;
|
|
825 const char *chname = NULL;
|
|
826 SilcChannelEntry channel = NULL;
|
|
827 SilcChannelUser chu = NULL;
|
|
828 SilcUInt32 mode = 0;
|
|
829
|
9030
|
830 GList *m;
|
|
831 GaimBlistNodeAction *act;
|
|
832
|
8849
|
833 if (components)
|
|
834 chname = g_hash_table_lookup(components, "channel");
|
|
835 if (chname)
|
|
836 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
837 (char *)chname);
|
|
838 if (channel) {
|
|
839 chu = silc_client_on_channel(channel, conn->local_entry);
|
|
840 if (chu)
|
|
841 mode = chu->mode;
|
|
842 }
|
|
843
|
|
844 if (strstr(chname, "[Private Group]"))
|
|
845 return NULL;
|
|
846
|
9030
|
847 act = gaim_blist_node_action_new(_("Get Info"),
|
|
848 silcgaim_chat_getinfo, NULL);
|
|
849 m = g_list_append(m, act);
|
8849
|
850
|
|
851 #if 0 /* XXX For now these are not implemented. We need better
|
|
852 listview dialog from Gaim for these. */
|
|
853 if (mode & SILC_CHANNEL_UMODE_CHANOP) {
|
9030
|
854 act = gaim_blist_node_action_new(_("Invite List"),
|
|
855 silcgaim_chat_invitelist, NULL);
|
|
856 m = g_list_append(m, act);
|
8849
|
857
|
9030
|
858 act = gaim_blist_node_action_new(_("Ban List"),
|
|
859 silcgaim_chat_banlist, NULL);
|
|
860 m = g_list_append(m, act);
|
8849
|
861 }
|
|
862 #endif
|
|
863
|
|
864 if (chu) {
|
9030
|
865 act = gaim_blist_node_action_new(_("Add Private Group"),
|
|
866 silcgaim_chat_prv, NULL);
|
|
867 m = g_list_append(m, act);
|
8849
|
868 }
|
|
869
|
|
870 if (mode & SILC_CHANNEL_UMODE_CHANFO) {
|
9030
|
871 act = gaim_blist_node_action_new(_("Channel Authentication"),
|
|
872 silcgaim_chat_chauth, NULL);
|
|
873 m = g_list_append(m, act);
|
8849
|
874
|
|
875 if (channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
|
9030
|
876 act = gaim_blist_node_action_new(_("Reset Permanent"),
|
|
877 silcgaim_chat_permanent_reset, NULL);
|
|
878 m = g_list_append(m, act);
|
8849
|
879 } else {
|
9030
|
880 act = gaim_blist_node_action_new(_("Set Permanent"),
|
|
881 silcgaim_chat_permanent, NULL);
|
|
882 m = g_list_append(m, act);
|
8849
|
883 }
|
|
884 }
|
|
885
|
|
886 if (mode & SILC_CHANNEL_UMODE_CHANOP) {
|
9030
|
887 act = gaim_blist_node_action_new(_("Set User Limit"),
|
|
888 silcgaim_chat_ulimit, NULL);
|
|
889 m = g_list_append(m, act);
|
8849
|
890
|
|
891 if (channel->mode & SILC_CHANNEL_MODE_TOPIC) {
|
9030
|
892 act = gaim_blist_node_action_new(_("Reset Topic Restriction"),
|
|
893 silcgaim_chat_resettopic, NULL);
|
|
894 m = g_list_append(m, act);
|
8849
|
895 } else {
|
9030
|
896 act = gaim_blist_node_action_new(_("Set Topic Restriction"),
|
|
897 silcgaim_chat_settopic, NULL);
|
|
898 m = g_list_append(m, act);
|
8849
|
899 }
|
|
900
|
|
901 if (channel->mode & SILC_CHANNEL_MODE_PRIVATE) {
|
9030
|
902 act = gaim_blist_node_action_new(_("Reset Private Channel"),
|
|
903 silcgaim_chat_resetprivate, NULL);
|
|
904 m = g_list_append(m, act);
|
8849
|
905 } else {
|
9030
|
906 act = gaim_blist_node_action_new(_("Set Private Channel"),
|
|
907 silcgaim_chat_setprivate, NULL);
|
|
908 m = g_list_append(m, act);
|
8849
|
909 }
|
|
910
|
|
911 if (channel->mode & SILC_CHANNEL_MODE_SECRET) {
|
9030
|
912 act = gaim_blist_node_action_new(_("Reset Secret Channel"),
|
|
913 silcgaim_chat_resetsecret, NULL);
|
|
914 m = g_list_append(m, act);
|
8849
|
915 } else {
|
9030
|
916 act = gaim_blist_node_action_new(_("Set Secret Channel"),
|
|
917 silcgaim_chat_setsecret, NULL);
|
|
918 m = g_list_append(m, act);
|
8849
|
919 }
|
|
920 }
|
|
921
|
|
922 return m;
|
|
923 }
|
|
924
|
|
925
|
|
926 /******************************* Joining Etc. ********************************/
|
|
927
|
|
928 void silcgaim_chat_join_done(SilcClient client,
|
|
929 SilcClientConnection conn,
|
|
930 SilcClientEntry *clients,
|
|
931 SilcUInt32 clients_count,
|
|
932 void *context)
|
|
933 {
|
|
934 GaimConnection *gc = client->application;
|
|
935 SilcGaim sg = gc->proto_data;
|
|
936 SilcChannelEntry channel = context;
|
|
937 GaimConversation *convo;
|
|
938 SilcUInt32 retry = SILC_PTR_TO_32(channel->context);
|
|
939 SilcHashTableList htl;
|
|
940 SilcChannelUser chu;
|
|
941 GList *users = NULL;
|
|
942 char tmp[256];
|
|
943
|
|
944 if (!clients && retry < 1) {
|
|
945 /* Resolving users failed, try again. */
|
|
946 channel->context = SILC_32_TO_PTR(retry + 1);
|
|
947 silc_client_get_clients_by_channel(client, conn, channel,
|
|
948 silcgaim_chat_join_done, channel);
|
|
949 return;
|
|
950 }
|
|
951
|
|
952 /* Add channel to Gaim */
|
|
953 channel->context = SILC_32_TO_PTR(++sg->channel_ids);
|
|
954 serv_got_joined_chat(gc, sg->channel_ids, channel->channel_name);
|
|
955 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
956 sg->account);
|
|
957 if (!convo)
|
|
958 return;
|
|
959
|
|
960 /* Add all users to channel */
|
|
961 silc_hash_table_list(channel->user_list, &htl);
|
|
962 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
963 if (!chu->client->nickname)
|
|
964 continue;
|
|
965 chu->context = SILC_32_TO_PTR(sg->channel_ids);
|
|
966
|
|
967 #if 0 /* XXX don't append mode char to nick because Gaim doesn't
|
|
968 give a way to change it afterwards when mode changes. */
|
|
969 tmp2 = silc_client_chumode_char(chu->mode);
|
|
970 if (tmp2)
|
8891
|
971 g_snprintf(tmp, sizeof(tmp), "%s%s", tmp2,
|
8849
|
972 chu->client->nickname);
|
|
973 else
|
8891
|
974 g_snprintf(tmp, sizeof(tmp), "%s",
|
8849
|
975 chu->client->nickname);
|
|
976 silc_free(tmp2);
|
|
977
|
|
978 users = g_list_append(users, g_strdup(tmp));
|
|
979 #else
|
|
980 users = g_list_append(users, g_strdup(chu->client->nickname));
|
|
981 #endif
|
|
982
|
|
983 if (chu->mode & SILC_CHANNEL_UMODE_CHANFO) {
|
|
984 if (chu->client == conn->local_entry)
|
|
985 g_snprintf(tmp, sizeof(tmp),
|
|
986 _("You are channel founder on <I>%s</I>"),
|
|
987 channel->channel_name);
|
|
988 else
|
|
989 g_snprintf(tmp, sizeof(tmp),
|
|
990 _("Channel founder on <I>%s</I> is <I>%s</I>"),
|
|
991 channel->channel_name, chu->client->nickname);
|
|
992
|
|
993 gaim_conversation_write(convo, NULL, tmp,
|
|
994 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
995
|
|
996 }
|
|
997 }
|
|
998 silc_hash_table_list_reset(&htl);
|
|
999
|
|
1000 gaim_conv_chat_add_users(GAIM_CONV_CHAT(convo), users);
|
|
1001 g_list_free(users);
|
|
1002
|
|
1003 /* Set topic */
|
|
1004 if (channel->topic)
|
|
1005 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, channel->topic);
|
|
1006 }
|
|
1007
|
|
1008 void silcgaim_chat_join(GaimConnection *gc, GHashTable *data)
|
|
1009 {
|
|
1010 SilcGaim sg = gc->proto_data;
|
|
1011 SilcClient client = sg->client;
|
|
1012 SilcClientConnection conn = sg->conn;
|
|
1013 const char *channel, *passphrase, *parentch;
|
|
1014
|
|
1015 if (!conn)
|
|
1016 return;
|
|
1017
|
|
1018 channel = g_hash_table_lookup(data, "channel");
|
|
1019 passphrase = g_hash_table_lookup(data, "passphrase");
|
|
1020
|
|
1021 /* Check if we are joining a private group. Handle it
|
|
1022 purely locally as it's not a real channel */
|
|
1023 if (strstr(channel, "[Private Group]")) {
|
|
1024 SilcChannelEntry channel_entry;
|
|
1025 SilcChannelPrivateKey key;
|
|
1026 GaimChat *c;
|
|
1027 SilcGaimPrvgrp grp;
|
|
1028
|
|
1029 c = gaim_blist_find_chat(sg->account, channel);
|
|
1030 parentch = gaim_blist_node_get_string((GaimBlistNode *)c, "parentch");
|
|
1031 if (!parentch)
|
|
1032 return;
|
|
1033
|
|
1034 channel_entry = silc_client_get_channel(sg->client, sg->conn,
|
|
1035 (char *)parentch);
|
|
1036 if (!channel_entry ||
|
|
1037 !silc_client_on_channel(channel_entry, sg->conn->local_entry)) {
|
|
1038 char tmp[512];
|
|
1039 g_snprintf(tmp, sizeof(tmp),
|
|
1040 _("You have to join the %s channel before you are "
|
|
1041 "able to join the private group"), parentch);
|
|
1042 gaim_notify_error(gc, _("Join Private Group"),
|
|
1043 _("Cannot join private group"), tmp);
|
|
1044 return;
|
|
1045 }
|
|
1046
|
|
1047 /* Add channel private key */
|
|
1048 if (!silc_client_add_channel_private_key(client, conn,
|
|
1049 channel_entry, channel,
|
|
1050 NULL, NULL,
|
|
1051 (unsigned char *)passphrase,
|
|
1052 strlen(passphrase), &key))
|
|
1053 return;
|
|
1054
|
|
1055 /* Join the group */
|
|
1056 grp = silc_calloc(1, sizeof(*grp));
|
|
1057 if (!grp)
|
|
1058 return;
|
|
1059 grp->id = ++sg->channel_ids + SILCGAIM_PRVGRP;
|
|
1060 grp->chid = SILC_PTR_TO_32(channel_entry->context);
|
|
1061 grp->parentch = parentch;
|
|
1062 grp->channel = channel;
|
|
1063 grp->key = key;
|
|
1064 sg->grps = g_list_append(sg->grps, grp);
|
|
1065 serv_got_joined_chat(gc, grp->id, channel);
|
|
1066 return;
|
|
1067 }
|
|
1068
|
|
1069 /* XXX We should have other properties here as well:
|
|
1070 1. whether to try to authenticate to the channel
|
|
1071 1a. with default key,
|
|
1072 1b. with specific key.
|
|
1073 2. whether to try to authenticate to become founder.
|
|
1074 2a. with default key,
|
|
1075 2b. with specific key.
|
|
1076
|
|
1077 Since now such variety is not possible in the join dialog
|
|
1078 we always use -founder and -auth options, which try to
|
|
1079 do both 1 and 2 with default keys. */
|
|
1080
|
|
1081 /* Call JOIN */
|
|
1082 if (passphrase)
|
|
1083 silc_client_command_call(client, conn, NULL, "JOIN",
|
|
1084 channel, passphrase, "-auth", "-founder", NULL);
|
|
1085 else
|
|
1086 silc_client_command_call(client, conn, NULL, "JOIN",
|
|
1087 channel, "-auth", "-founder", NULL);
|
|
1088 }
|
|
1089
|
|
1090 void silcgaim_chat_invite(GaimConnection *gc, int id, const char *msg,
|
|
1091 const char *name)
|
|
1092 {
|
|
1093 SilcGaim sg = gc->proto_data;
|
|
1094 SilcClient client = sg->client;
|
|
1095 SilcClientConnection conn = sg->conn;
|
|
1096 SilcHashTableList htl;
|
|
1097 SilcChannelUser chu;
|
|
1098 gboolean found = FALSE;
|
|
1099
|
|
1100 if (!conn)
|
|
1101 return;
|
|
1102
|
|
1103 /* See if we are inviting on a private group. Invite
|
|
1104 to the actual channel */
|
|
1105 if (id > SILCGAIM_PRVGRP) {
|
|
1106 GList *l;
|
|
1107 SilcGaimPrvgrp prv;
|
|
1108
|
|
1109 for (l = sg->grps; l; l = l->next)
|
|
1110 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1111 break;
|
|
1112 if (!l)
|
|
1113 return;
|
|
1114 prv = l->data;
|
|
1115 id = prv->chid;
|
|
1116 }
|
|
1117
|
|
1118 /* Find channel by id */
|
|
1119 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1120 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1121 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1122 found = TRUE;
|
|
1123 break;
|
|
1124 }
|
|
1125 }
|
|
1126 silc_hash_table_list_reset(&htl);
|
|
1127 if (!found)
|
|
1128 return;
|
|
1129
|
|
1130 /* Call INVITE */
|
|
1131 silc_client_command_call(client, conn, NULL, "INVITE",
|
|
1132 chu->channel->channel_name,
|
|
1133 name);
|
|
1134 }
|
|
1135
|
|
1136 void silcgaim_chat_leave(GaimConnection *gc, int id)
|
|
1137 {
|
|
1138 SilcGaim sg = gc->proto_data;
|
|
1139 SilcClient client = sg->client;
|
|
1140 SilcClientConnection conn = sg->conn;
|
|
1141 SilcHashTableList htl;
|
|
1142 SilcChannelUser chu;
|
|
1143 gboolean found = FALSE;
|
|
1144 GList *l;
|
|
1145 SilcGaimPrvgrp prv;
|
|
1146
|
|
1147 if (!conn)
|
|
1148 return;
|
|
1149
|
|
1150 /* See if we are leaving a private group */
|
|
1151 if (id > SILCGAIM_PRVGRP) {
|
|
1152 SilcChannelEntry channel;
|
|
1153
|
|
1154 for (l = sg->grps; l; l = l->next)
|
|
1155 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1156 break;
|
|
1157 if (!l)
|
|
1158 return;
|
|
1159 prv = l->data;
|
|
1160 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
1161 (char *)prv->parentch);
|
|
1162 if (!channel)
|
|
1163 return;
|
|
1164 silc_client_del_channel_private_key(client, conn,
|
|
1165 channel, prv->key);
|
|
1166 silc_free(prv);
|
|
1167 sg->grps = g_list_remove(sg->grps, prv);
|
|
1168 serv_got_chat_left(gc, id);
|
|
1169 return;
|
|
1170 }
|
|
1171
|
|
1172 /* Find channel by id */
|
|
1173 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1174 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1175 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1176 found = TRUE;
|
|
1177 break;
|
|
1178 }
|
|
1179 }
|
|
1180 silc_hash_table_list_reset(&htl);
|
|
1181 if (!found)
|
|
1182 return;
|
|
1183
|
|
1184 /* Call LEAVE */
|
|
1185 silc_client_command_call(client, conn, NULL, "LEAVE",
|
|
1186 chu->channel->channel_name, NULL);
|
|
1187
|
|
1188 serv_got_chat_left(gc, id);
|
|
1189
|
|
1190 /* Leave from private groups on this channel as well */
|
|
1191 for (l = sg->grps; l; l = l->next)
|
|
1192 if (((SilcGaimPrvgrp)l->data)->chid == id) {
|
|
1193 prv = l->data;
|
|
1194 silc_client_del_channel_private_key(client, conn,
|
|
1195 chu->channel,
|
|
1196 prv->key);
|
|
1197 serv_got_chat_left(gc, prv->id);
|
|
1198 silc_free(prv);
|
|
1199 sg->grps = g_list_remove(sg->grps, prv);
|
|
1200 if (!sg->grps)
|
|
1201 break;
|
|
1202 }
|
|
1203 }
|
|
1204
|
|
1205 int silcgaim_chat_send(GaimConnection *gc, int id, const char *msg)
|
|
1206 {
|
|
1207 SilcGaim sg = gc->proto_data;
|
|
1208 SilcClient client = sg->client;
|
|
1209 SilcClientConnection conn = sg->conn;
|
|
1210 SilcHashTableList htl;
|
|
1211 SilcChannelUser chu;
|
|
1212 SilcChannelEntry channel = NULL;
|
|
1213 SilcChannelPrivateKey key = NULL;
|
|
1214 SilcUInt32 flags;
|
|
1215 int ret;
|
|
1216 gboolean found = FALSE;
|
|
1217 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_chat");
|
|
1218
|
|
1219 if (!msg || !conn)
|
|
1220 return 0;
|
|
1221
|
|
1222 /* See if command */
|
|
1223 if (strlen(msg) > 1 && msg[0] == '/') {
|
|
1224 if (!silc_client_command_call(client, conn, msg + 1))
|
|
1225 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"),
|
|
1226 _("Unknown command"));
|
|
1227 return 0;
|
|
1228 }
|
|
1229
|
|
1230 flags = SILC_MESSAGE_FLAG_UTF8;
|
|
1231 if (sign)
|
|
1232 flags |= SILC_MESSAGE_FLAG_SIGNED;
|
|
1233
|
|
1234 /* Get the channel private key if we are sending on
|
|
1235 private group */
|
|
1236 if (id > SILCGAIM_PRVGRP) {
|
|
1237 GList *l;
|
|
1238 SilcGaimPrvgrp prv;
|
|
1239
|
|
1240 for (l = sg->grps; l; l = l->next)
|
|
1241 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1242 break;
|
|
1243 if (!l)
|
|
1244 return 0;
|
|
1245 prv = l->data;
|
|
1246 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
1247 (char *)prv->parentch);
|
|
1248 if (!channel)
|
|
1249 return 0;
|
|
1250 key = prv->key;
|
|
1251 }
|
|
1252
|
|
1253 if (!channel) {
|
|
1254 /* Find channel by id */
|
|
1255 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1256 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1257 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1258 found = TRUE;
|
|
1259 break;
|
|
1260 }
|
|
1261 }
|
|
1262 silc_hash_table_list_reset(&htl);
|
|
1263 if (!found)
|
|
1264 return 0;
|
|
1265 channel = chu->channel;
|
|
1266 }
|
|
1267
|
|
1268 /* Send channel message */
|
|
1269 ret = silc_client_send_channel_message(client, conn, channel, key,
|
|
1270 flags, (unsigned char *)msg,
|
|
1271 strlen(msg), TRUE);
|
|
1272 if (ret)
|
|
1273 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, msg,
|
|
1274 time(NULL));
|
|
1275
|
|
1276 return ret;
|
|
1277 }
|
|
1278
|
|
1279 void silcgaim_chat_set_topic(GaimConnection *gc, int id, const char *topic)
|
|
1280 {
|
|
1281 SilcGaim sg = gc->proto_data;
|
|
1282 SilcClient client = sg->client;
|
|
1283 SilcClientConnection conn = sg->conn;
|
|
1284 SilcHashTableList htl;
|
|
1285 SilcChannelUser chu;
|
|
1286 gboolean found = FALSE;
|
|
1287
|
|
1288 if (!topic || !conn)
|
|
1289 return;
|
|
1290
|
|
1291 /* See if setting topic on private group. Set it
|
|
1292 on the actual channel */
|
|
1293 if (id > SILCGAIM_PRVGRP) {
|
|
1294 GList *l;
|
|
1295 SilcGaimPrvgrp prv;
|
|
1296
|
|
1297 for (l = sg->grps; l; l = l->next)
|
|
1298 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1299 break;
|
|
1300 if (!l)
|
|
1301 return;
|
|
1302 prv = l->data;
|
|
1303 id = prv->chid;
|
|
1304 }
|
|
1305
|
|
1306 /* Find channel by id */
|
|
1307 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1308 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1309 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1310 found = TRUE;
|
|
1311 break;
|
|
1312 }
|
|
1313 }
|
|
1314 silc_hash_table_list_reset(&htl);
|
|
1315 if (!found)
|
|
1316 return;
|
|
1317
|
|
1318 /* Call TOPIC */
|
|
1319 silc_client_command_call(client, conn, NULL, "TOPIC",
|
|
1320 chu->channel->channel_name, topic, NULL);
|
|
1321 }
|
|
1322
|
|
1323 GaimRoomlist *silcgaim_roomlist_get_list(GaimConnection *gc)
|
|
1324 {
|
|
1325 SilcGaim sg = gc->proto_data;
|
|
1326 SilcClient client = sg->client;
|
|
1327 SilcClientConnection conn = sg->conn;
|
|
1328 GList *fields = NULL;
|
|
1329 GaimRoomlistField *f;
|
|
1330
|
|
1331 if (!conn)
|
|
1332 return NULL;
|
|
1333
|
|
1334 if (sg->roomlist)
|
|
1335 gaim_roomlist_unref(sg->roomlist);
|
|
1336
|
|
1337 sg->roomlist_canceled = FALSE;
|
|
1338
|
|
1339 sg->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc));
|
|
1340 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE);
|
|
1341 fields = g_list_append(fields, f);
|
|
1342 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT,
|
|
1343 _("Users"), "users", FALSE);
|
|
1344 fields = g_list_append(fields, f);
|
|
1345 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING,
|
|
1346 _("Topic"), "topic", FALSE);
|
|
1347 fields = g_list_append(fields, f);
|
|
1348 gaim_roomlist_set_fields(sg->roomlist, fields);
|
|
1349
|
|
1350 /* Call LIST */
|
|
1351 silc_client_command_call(client, conn, "LIST");
|
|
1352
|
|
1353 gaim_roomlist_set_in_progress(sg->roomlist, TRUE);
|
|
1354
|
|
1355 return sg->roomlist;
|
|
1356 }
|
|
1357
|
|
1358 void silcgaim_roomlist_cancel(GaimRoomlist *list)
|
|
1359 {
|
|
1360 GaimConnection *gc = gaim_account_get_connection(list->account);
|
|
1361 SilcGaim sg;
|
|
1362
|
|
1363 if (!gc)
|
|
1364 return;
|
|
1365 sg = gc->proto_data;
|
|
1366
|
|
1367 gaim_roomlist_set_in_progress(list, FALSE);
|
|
1368 if (sg->roomlist == list) {
|
|
1369 gaim_roomlist_unref(sg->roomlist);
|
|
1370 sg->roomlist = NULL;
|
|
1371 sg->roomlist_canceled = TRUE;
|
|
1372 }
|
|
1373 }
|