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
|
9038
|
46 silcgaim_chat_getinfo(GaimConnection *gc, GHashTable *components);
|
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
|
9038
|
75
|
8849
|
76 static void
|
9038
|
77 silcgaim_chat_getinfo(GaimConnection *gc, GHashTable *components)
|
8849
|
78 {
|
9038
|
79 SilcGaim sg = gc->proto_data;
|
8849
|
80 const char *chname;
|
|
81 char *buf, tmp[256];
|
|
82 GString *s;
|
|
83 SilcChannelEntry channel;
|
|
84 SilcHashTableList htl;
|
|
85 SilcChannelUser chu;
|
|
86
|
9038
|
87 if (!components)
|
|
88 return;
|
8849
|
89
|
9038
|
90 chname = g_hash_table_lookup(components, "channel");
|
8849
|
91 if (!chname)
|
|
92 return;
|
|
93 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
94 (char *)chname);
|
|
95 if (!channel) {
|
|
96 silc_client_get_channel_resolve(sg->client, sg->conn,
|
|
97 (char *)chname,
|
|
98 silcgaim_chat_getinfo_res,
|
9038
|
99 components);
|
8849
|
100 return;
|
|
101 }
|
|
102
|
|
103 s = g_string_new("");
|
9275
|
104 g_string_append_printf(s, _("Channel Name:\t\t%s\n"), channel->channel_name);
|
8849
|
105 if (channel->user_list && silc_hash_table_count(channel->user_list))
|
9275
|
106 g_string_append_printf(s, _("User Count:\t\t%d\n"),
|
8849
|
107 (int)silc_hash_table_count(channel->user_list));
|
|
108
|
|
109 silc_hash_table_list(channel->user_list, &htl);
|
|
110 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
111 if (chu->mode & SILC_CHANNEL_UMODE_CHANFO) {
|
9275
|
112 g_string_append_printf(s, _("Channel Founder:\t%s\n"),
|
8849
|
113 chu->client->nickname);
|
|
114 break;
|
|
115 }
|
|
116 }
|
|
117 silc_hash_table_list_reset(&htl);
|
|
118
|
|
119 if (channel->channel_key)
|
9275
|
120 g_string_append_printf(s, _("Channel Cipher:\t\t%s\n"),
|
8849
|
121 silc_cipher_get_name(channel->channel_key));
|
|
122 if (channel->hmac)
|
9275
|
123 g_string_append_printf(s, _("Channel HMAC:\t\t%s\n"),
|
8849
|
124 silc_hmac_get_name(channel->hmac));
|
|
125
|
|
126 if (channel->topic)
|
9275
|
127 g_string_append_printf(s, _("\nChannel Topic:\n\t%s\n"), channel->topic);
|
8849
|
128
|
|
129 if (channel->mode) {
|
9275
|
130 g_string_append_printf(s, _("\nChannel Modes:\n"));
|
8849
|
131 silcgaim_get_chmode_string(channel->mode, tmp, sizeof(tmp));
|
|
132 g_string_append_printf(s, tmp);
|
|
133 g_string_append_printf(s, "\n");
|
|
134 }
|
|
135
|
|
136 if (channel->founder_key) {
|
|
137 char *fingerprint, *babbleprint;
|
|
138 unsigned char *pk;
|
|
139 SilcUInt32 pk_len;
|
|
140 pk = silc_pkcs_public_key_encode(channel->founder_key, &pk_len);
|
|
141 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
142 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
|
|
143
|
9275
|
144 g_string_append_printf(s, _("\nFounder Key Fingerprint:\n%s\n\n"), fingerprint);
|
|
145 g_string_append_printf(s, _("Founder Key Babbleprint:\n%s"), babbleprint);
|
8849
|
146
|
|
147 silc_free(fingerprint);
|
|
148 silc_free(babbleprint);
|
|
149 silc_free(pk);
|
|
150 }
|
|
151
|
|
152 buf = g_string_free(s, FALSE);
|
|
153 gaim_notify_message(NULL, GAIM_NOTIFY_MSG_INFO,
|
|
154 _("Channel Information"),
|
|
155 _("Channel Information"),
|
|
156 buf, NULL, NULL);
|
|
157 g_free(buf);
|
|
158 }
|
|
159
|
|
160
|
9038
|
161 static void
|
|
162 silcgaim_chat_getinfo_menu(GaimBlistNode *node, gpointer data)
|
|
163 {
|
9272
|
164 GaimChat *chat = (GaimChat *)node;
|
|
165 silcgaim_chat_getinfo(chat->account->gc, chat->components);
|
9038
|
166 }
|
|
167
|
|
168
|
8849
|
169 #if 0 /* XXX For now these are not implemented. We need better
|
|
170 listview dialog from Gaim for these. */
|
|
171 /************************** Channel Invite List ******************************/
|
|
172
|
|
173 static void
|
9030
|
174 silcgaim_chat_invitelist(GaimBlistNode *node, gpointer data);
|
8849
|
175 {
|
|
176
|
|
177 }
|
|
178
|
|
179
|
|
180 /**************************** Channel Ban List *******************************/
|
|
181
|
|
182 static void
|
9030
|
183 silcgaim_chat_banlist(GaimBlistNode *node, gpointer data);
|
8849
|
184 {
|
|
185
|
|
186 }
|
|
187 #endif
|
|
188
|
|
189
|
|
190 /************************* Channel Authentication ****************************/
|
|
191
|
|
192 typedef struct {
|
|
193 SilcGaim sg;
|
|
194 SilcChannelEntry channel;
|
|
195 GaimChat *c;
|
|
196 SilcBuffer pubkeys;
|
|
197 } *SilcGaimChauth;
|
|
198
|
|
199 static void
|
|
200 silcgaim_chat_chpk_add(void *user_data, const char *name)
|
|
201 {
|
|
202 SilcGaimChauth sgc = (SilcGaimChauth)user_data;
|
|
203 SilcGaim sg = sgc->sg;
|
|
204 SilcClient client = sg->client;
|
|
205 SilcClientConnection conn = sg->conn;
|
|
206 SilcPublicKey public_key;
|
|
207 SilcBuffer chpks, pk, chidp;
|
|
208 unsigned char mode[4];
|
|
209 SilcUInt32 m;
|
|
210
|
|
211 /* Load the public key */
|
|
212 if (!silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_PEM) &&
|
|
213 !silc_pkcs_load_public_key(name, &public_key, SILC_PKCS_FILE_BIN)) {
|
|
214 silcgaim_chat_chauth_show(sgc->sg, sgc->channel, sgc->pubkeys);
|
|
215 silc_buffer_free(sgc->pubkeys);
|
|
216 silc_free(sgc);
|
|
217 gaim_notify_error(client->application,
|
|
218 _("Add Channel Public Key"),
|
|
219 _("Could not load public key"), NULL);
|
|
220 return;
|
|
221 }
|
|
222
|
|
223 pk = silc_pkcs_public_key_payload_encode(public_key);
|
|
224 chpks = silc_buffer_alloc_size(2);
|
|
225 SILC_PUT16_MSB(1, chpks->head);
|
|
226 chpks = silc_argument_payload_encode_one(chpks, pk->data,
|
|
227 pk->len, 0x00);
|
|
228 silc_buffer_free(pk);
|
|
229
|
|
230 m = sgc->channel->mode;
|
|
231 m |= SILC_CHANNEL_MODE_CHANNEL_AUTH;
|
|
232
|
|
233 /* Send CMODE */
|
|
234 SILC_PUT32_MSB(m, mode);
|
|
235 chidp = silc_id_payload_encode(sgc->channel->id, SILC_ID_CHANNEL);
|
|
236 silc_client_command_send(client, conn, SILC_COMMAND_CMODE,
|
|
237 ++conn->cmd_ident, 3,
|
|
238 1, chidp->data, chidp->len,
|
|
239 2, mode, sizeof(mode),
|
|
240 9, chpks->data, chpks->len);
|
|
241 silc_buffer_free(chpks);
|
|
242 silc_buffer_free(chidp);
|
|
243 silc_buffer_free(sgc->pubkeys);
|
|
244 silc_free(sgc);
|
|
245 }
|
|
246
|
|
247 static void
|
|
248 silcgaim_chat_chpk_cancel(void *user_data, const char *name)
|
|
249 {
|
|
250 SilcGaimChauth sgc = (SilcGaimChauth)user_data;
|
|
251 silcgaim_chat_chauth_show(sgc->sg, sgc->channel, sgc->pubkeys);
|
|
252 silc_buffer_free(sgc->pubkeys);
|
|
253 silc_free(sgc);
|
|
254 }
|
|
255
|
|
256 static void
|
|
257 silcgaim_chat_chpk_cb(SilcGaimChauth sgc, GaimRequestFields *fields)
|
|
258 {
|
|
259 SilcGaim sg = sgc->sg;
|
|
260 SilcClient client = sg->client;
|
|
261 SilcClientConnection conn = sg->conn;
|
|
262 GaimRequestField *f;
|
|
263 const GList *list;
|
|
264 SilcPublicKey public_key;
|
|
265 SilcBuffer chpks, pk, chidp;
|
|
266 SilcUInt16 c = 0, ct;
|
|
267 unsigned char mode[4];
|
|
268 SilcUInt32 m;
|
|
269
|
|
270 f = gaim_request_fields_get_field(fields, "list");
|
|
271 if (!gaim_request_field_list_get_selected(f)) {
|
|
272 /* Add new public key */
|
8877
|
273 gaim_request_file(NULL, _("Open Public Key..."), "",
|
8849
|
274 G_CALLBACK(silcgaim_chat_chpk_add),
|
|
275 G_CALLBACK(silcgaim_chat_chpk_cancel), sgc);
|
|
276 return;
|
|
277 }
|
|
278
|
|
279 list = gaim_request_field_list_get_items(f);
|
|
280 chpks = silc_buffer_alloc_size(2);
|
|
281
|
|
282 for (ct = 0; list; list = list->next, ct++) {
|
|
283 public_key = gaim_request_field_list_get_data(f, list->data);
|
|
284 if (gaim_request_field_list_is_selected(f, list->data)) {
|
|
285 /* Delete this public key */
|
|
286 pk = silc_pkcs_public_key_payload_encode(public_key);
|
|
287 chpks = silc_argument_payload_encode_one(chpks, pk->data,
|
|
288 pk->len, 0x01);
|
|
289 silc_buffer_free(pk);
|
|
290 c++;
|
|
291 }
|
|
292 silc_pkcs_public_key_free(public_key);
|
|
293 }
|
|
294 if (!c) {
|
|
295 silc_buffer_free(chpks);
|
|
296 return;
|
|
297 }
|
|
298 SILC_PUT16_MSB(c, chpks->head);
|
|
299
|
|
300 m = sgc->channel->mode;
|
|
301 if (ct == c)
|
|
302 m &= ~SILC_CHANNEL_MODE_CHANNEL_AUTH;
|
|
303
|
|
304 /* Send CMODE */
|
|
305 SILC_PUT32_MSB(m, mode);
|
|
306 chidp = silc_id_payload_encode(sgc->channel->id, SILC_ID_CHANNEL);
|
|
307 silc_client_command_send(client, conn, SILC_COMMAND_CMODE,
|
|
308 ++conn->cmd_ident, 3,
|
|
309 1, chidp->data, chidp->len,
|
|
310 2, mode, sizeof(mode),
|
|
311 9, chpks->data, chpks->len);
|
|
312 silc_buffer_free(chpks);
|
|
313 silc_buffer_free(chidp);
|
|
314 silc_buffer_free(sgc->pubkeys);
|
|
315 silc_free(sgc);
|
|
316 }
|
|
317
|
|
318 static void
|
|
319 silcgaim_chat_chauth_ok(SilcGaimChauth sgc, GaimRequestFields *fields)
|
|
320 {
|
|
321 SilcGaim sg = sgc->sg;
|
|
322 GaimRequestField *f;
|
|
323 const char *curpass, *val;
|
|
324 int set;
|
|
325
|
|
326 f = gaim_request_fields_get_field(fields, "passphrase");
|
|
327 val = gaim_request_field_string_get_value(f);
|
|
328 curpass = gaim_blist_node_get_string((GaimBlistNode *)sgc->c, "passphrase");
|
|
329
|
|
330 if (!val && curpass)
|
|
331 set = 0;
|
|
332 else if (val && !curpass)
|
|
333 set = 1;
|
|
334 else if (val && curpass && strcmp(val, curpass))
|
|
335 set = 1;
|
|
336 else
|
|
337 set = -1;
|
|
338
|
|
339 if (set == 1) {
|
|
340 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
|
341 sgc->channel->channel_name, "+a", val, NULL);
|
|
342 gaim_blist_node_set_string((GaimBlistNode *)sgc->c, "passphrase", val);
|
|
343 } else if (set == 0) {
|
|
344 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
|
345 sgc->channel->channel_name, "-a", NULL);
|
|
346 gaim_blist_node_remove_setting((GaimBlistNode *)sgc->c, "passphrase");
|
|
347 }
|
|
348
|
|
349 silc_buffer_free(sgc->pubkeys);
|
|
350 silc_free(sgc);
|
|
351 }
|
|
352
|
|
353 void silcgaim_chat_chauth_show(SilcGaim sg, SilcChannelEntry channel,
|
|
354 SilcBuffer channel_pubkeys)
|
|
355 {
|
|
356 SilcUInt16 argc;
|
|
357 SilcArgumentPayload chpks;
|
|
358 unsigned char *pk;
|
|
359 SilcUInt32 pk_len, type;
|
|
360 char *fingerprint, *babbleprint;
|
|
361 SilcPublicKey pubkey;
|
|
362 SilcPublicKeyIdentifier ident;
|
|
363 char tmp2[1024], t[512];
|
|
364 GaimRequestFields *fields;
|
|
365 GaimRequestFieldGroup *g;
|
|
366 GaimRequestField *f;
|
|
367 SilcGaimChauth sgc;
|
|
368 const char *curpass = NULL;
|
|
369
|
|
370 sgc = silc_calloc(1, sizeof(*sgc));
|
|
371 if (!sgc)
|
|
372 return;
|
|
373 sgc->sg = sg;
|
|
374 sgc->channel = channel;
|
|
375
|
|
376 fields = gaim_request_fields_new();
|
|
377
|
|
378 if (sgc->c)
|
|
379 curpass = gaim_blist_node_get_string((GaimBlistNode *)sgc->c, "passphrase");
|
|
380
|
|
381 g = gaim_request_field_group_new(NULL);
|
|
382 f = gaim_request_field_string_new("passphrase", _("Channel Passphrase"),
|
|
383 curpass, FALSE);
|
|
384 gaim_request_field_string_set_masked(f, TRUE);
|
|
385 gaim_request_field_group_add_field(g, f);
|
|
386 gaim_request_fields_add_group(fields, g);
|
|
387
|
|
388 g = gaim_request_field_group_new(NULL);
|
|
389 f = gaim_request_field_label_new("l1", _("Channel Public Keys List"));
|
|
390 gaim_request_field_group_add_field(g, f);
|
|
391 gaim_request_fields_add_group(fields, g);
|
|
392
|
|
393 g_snprintf(t, sizeof(t),
|
|
394 _("Channel authentication is used to secure the channel from "
|
|
395 "unauthorized access. The authentication may be based on "
|
|
396 "passphrase and digital signatures. If passphrase is set, it "
|
|
397 "is required to be able to join. If channel public keys are set "
|
|
398 "then only users whose public keys are listed are able to join."));
|
|
399
|
|
400 if (!channel_pubkeys) {
|
|
401 f = gaim_request_field_list_new("list", NULL);
|
|
402 gaim_request_field_group_add_field(g, f);
|
|
403 gaim_request_fields(NULL, _("Channel Authentication"),
|
|
404 _("Channel Authentication"), t, fields,
|
9275
|
405 _("Add / Remove"), G_CALLBACK(silcgaim_chat_chpk_cb),
|
|
406 _("OK"), G_CALLBACK(silcgaim_chat_chauth_ok), sgc);
|
8849
|
407 return;
|
|
408 }
|
|
409 sgc->pubkeys = silc_buffer_copy(channel_pubkeys);
|
|
410
|
|
411 g = gaim_request_field_group_new(NULL);
|
|
412 f = gaim_request_field_list_new("list", NULL);
|
|
413 gaim_request_field_group_add_field(g, f);
|
|
414 gaim_request_fields_add_group(fields, g);
|
|
415
|
|
416 SILC_GET16_MSB(argc, channel_pubkeys->data);
|
|
417 chpks = silc_argument_payload_parse(channel_pubkeys->data + 2,
|
|
418 channel_pubkeys->len - 2, argc);
|
|
419 if (!chpks)
|
|
420 return;
|
|
421
|
|
422 pk = silc_argument_get_first_arg(chpks, &type, &pk_len);
|
|
423 while (pk) {
|
|
424 fingerprint = silc_hash_fingerprint(NULL, pk + 4, pk_len - 4);
|
|
425 babbleprint = silc_hash_babbleprint(NULL, pk + 4, pk_len - 4);
|
|
426 silc_pkcs_public_key_payload_decode(pk, pk_len, &pubkey);
|
|
427 ident = silc_pkcs_decode_identifier(pubkey->identifier);
|
|
428
|
|
429 g_snprintf(tmp2, sizeof(tmp2), "%s\n %s\n %s",
|
|
430 ident->realname ? ident->realname : ident->username ?
|
|
431 ident->username : "", fingerprint, babbleprint);
|
|
432 gaim_request_field_list_add(f, tmp2, pubkey);
|
|
433
|
|
434 silc_free(fingerprint);
|
|
435 silc_free(babbleprint);
|
|
436 silc_pkcs_free_identifier(ident);
|
|
437 pk = silc_argument_get_next_arg(chpks, &type, &pk_len);
|
|
438 }
|
|
439
|
|
440 gaim_request_field_list_set_multi_select(f, FALSE);
|
|
441 gaim_request_fields(NULL, _("Channel Authentication"),
|
|
442 _("Channel Authentication"), t, fields,
|
9275
|
443 _("Add / Remove"), G_CALLBACK(silcgaim_chat_chpk_cb),
|
|
444 _("OK"), G_CALLBACK(silcgaim_chat_chauth_ok), sgc);
|
8849
|
445
|
|
446 silc_argument_payload_free(chpks);
|
|
447 }
|
|
448
|
|
449 static void
|
9030
|
450 silcgaim_chat_chauth(GaimBlistNode *node, gpointer data)
|
8849
|
451 {
|
9030
|
452 GaimChat *chat;
|
|
453 GaimConnection *gc;
|
|
454 SilcGaim sg;
|
|
455
|
|
456 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
457
|
|
458 chat = (GaimChat *) node;
|
|
459 gc = gaim_account_get_connection(chat->account);
|
|
460 sg = gc->proto_data;
|
|
461
|
8849
|
462 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
463 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
464 "+C", NULL);
|
|
465 }
|
|
466
|
|
467
|
|
468 /************************** Channel Private Groups **************************/
|
|
469
|
|
470 /* Private groups are "virtual" channels. They are groups inside a channel.
|
|
471 This is implemented by using channel private keys. By knowing a channel
|
|
472 private key user becomes part of that group and is able to talk on that
|
|
473 group. Other users, on the same channel, won't be able to see the
|
|
474 messages of that group. It is possible to have multiple groups inside
|
|
475 a channel - and thus having multiple private keys on the channel. */
|
|
476
|
|
477 typedef struct {
|
|
478 SilcGaim sg;
|
|
479 GaimChat *c;
|
|
480 const char *channel;
|
|
481 } *SilcGaimCharPrv;
|
|
482
|
|
483 static void
|
|
484 silcgaim_chat_prv_add(SilcGaimCharPrv p, GaimRequestFields *fields)
|
|
485 {
|
|
486 SilcGaim sg = p->sg;
|
|
487 char tmp[512];
|
|
488 GaimRequestField *f;
|
|
489 const char *name, *passphrase, *alias;
|
|
490 GHashTable *comp;
|
|
491 GaimGroup *g;
|
|
492 GaimChat *cn;
|
|
493
|
|
494 f = gaim_request_fields_get_field(fields, "name");
|
|
495 name = gaim_request_field_string_get_value(f);
|
|
496 if (!name) {
|
|
497 silc_free(p);
|
|
498 return;
|
|
499 }
|
|
500 f = gaim_request_fields_get_field(fields, "passphrase");
|
|
501 passphrase = gaim_request_field_string_get_value(f);
|
|
502 f = gaim_request_fields_get_field(fields, "alias");
|
|
503 alias = gaim_request_field_string_get_value(f);
|
|
504
|
|
505 /* Add private group to buddy list */
|
|
506 g_snprintf(tmp, sizeof(tmp), "%s [Private Group]", name);
|
|
507 comp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
508 g_hash_table_replace(comp, g_strdup("channel"), g_strdup(tmp));
|
|
509 g_hash_table_replace(comp, g_strdup("passphrase"), g_strdup(passphrase));
|
|
510
|
|
511 cn = gaim_chat_new(sg->account, alias, comp);
|
|
512 g = (GaimGroup *)p->c->node.parent;
|
|
513 gaim_blist_add_chat(cn, g, (GaimBlistNode *)p->c);
|
|
514
|
|
515 /* Associate to a real channel */
|
|
516 gaim_blist_node_set_string((GaimBlistNode *)cn, "parentch", p->channel);
|
|
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,
|
9275
|
578 _("Add"), G_CALLBACK(silcgaim_chat_prv_add),
|
|
579 _("Cancel"), G_CALLBACK(silcgaim_chat_prv_cancel), p);
|
8849
|
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 {
|
9038
|
821 GHashTable *components = chat->components;
|
9030
|
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
|
9038
|
830 GList *m = NULL;
|
9030
|
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"),
|
9038
|
848 silcgaim_chat_getinfo_menu, NULL);
|
9030
|
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);
|
9353
|
1006
|
|
1007 /* Set nick */
|
|
1008 gaim_conv_chat_set_nick(GAIM_CONV_CHAT(convo), conn->local_entry->nickname);
|
8849
|
1009 }
|
|
1010
|
|
1011 void silcgaim_chat_join(GaimConnection *gc, GHashTable *data)
|
|
1012 {
|
|
1013 SilcGaim sg = gc->proto_data;
|
|
1014 SilcClient client = sg->client;
|
|
1015 SilcClientConnection conn = sg->conn;
|
|
1016 const char *channel, *passphrase, *parentch;
|
|
1017
|
|
1018 if (!conn)
|
|
1019 return;
|
|
1020
|
|
1021 channel = g_hash_table_lookup(data, "channel");
|
|
1022 passphrase = g_hash_table_lookup(data, "passphrase");
|
|
1023
|
|
1024 /* Check if we are joining a private group. Handle it
|
|
1025 purely locally as it's not a real channel */
|
|
1026 if (strstr(channel, "[Private Group]")) {
|
|
1027 SilcChannelEntry channel_entry;
|
|
1028 SilcChannelPrivateKey key;
|
|
1029 GaimChat *c;
|
|
1030 SilcGaimPrvgrp grp;
|
|
1031
|
|
1032 c = gaim_blist_find_chat(sg->account, channel);
|
|
1033 parentch = gaim_blist_node_get_string((GaimBlistNode *)c, "parentch");
|
|
1034 if (!parentch)
|
|
1035 return;
|
|
1036
|
|
1037 channel_entry = silc_client_get_channel(sg->client, sg->conn,
|
|
1038 (char *)parentch);
|
|
1039 if (!channel_entry ||
|
|
1040 !silc_client_on_channel(channel_entry, sg->conn->local_entry)) {
|
|
1041 char tmp[512];
|
|
1042 g_snprintf(tmp, sizeof(tmp),
|
|
1043 _("You have to join the %s channel before you are "
|
|
1044 "able to join the private group"), parentch);
|
|
1045 gaim_notify_error(gc, _("Join Private Group"),
|
|
1046 _("Cannot join private group"), tmp);
|
|
1047 return;
|
|
1048 }
|
|
1049
|
|
1050 /* Add channel private key */
|
|
1051 if (!silc_client_add_channel_private_key(client, conn,
|
|
1052 channel_entry, channel,
|
|
1053 NULL, NULL,
|
|
1054 (unsigned char *)passphrase,
|
|
1055 strlen(passphrase), &key))
|
|
1056 return;
|
|
1057
|
|
1058 /* Join the group */
|
|
1059 grp = silc_calloc(1, sizeof(*grp));
|
|
1060 if (!grp)
|
|
1061 return;
|
|
1062 grp->id = ++sg->channel_ids + SILCGAIM_PRVGRP;
|
|
1063 grp->chid = SILC_PTR_TO_32(channel_entry->context);
|
|
1064 grp->parentch = parentch;
|
|
1065 grp->channel = channel;
|
|
1066 grp->key = key;
|
|
1067 sg->grps = g_list_append(sg->grps, grp);
|
|
1068 serv_got_joined_chat(gc, grp->id, channel);
|
|
1069 return;
|
|
1070 }
|
|
1071
|
|
1072 /* XXX We should have other properties here as well:
|
|
1073 1. whether to try to authenticate to the channel
|
|
1074 1a. with default key,
|
|
1075 1b. with specific key.
|
|
1076 2. whether to try to authenticate to become founder.
|
|
1077 2a. with default key,
|
|
1078 2b. with specific key.
|
|
1079
|
|
1080 Since now such variety is not possible in the join dialog
|
|
1081 we always use -founder and -auth options, which try to
|
|
1082 do both 1 and 2 with default keys. */
|
|
1083
|
|
1084 /* Call JOIN */
|
9172
|
1085 if ((passphrase != NULL) && (*passphrase != '\0'))
|
8849
|
1086 silc_client_command_call(client, conn, NULL, "JOIN",
|
|
1087 channel, passphrase, "-auth", "-founder", NULL);
|
|
1088 else
|
|
1089 silc_client_command_call(client, conn, NULL, "JOIN",
|
|
1090 channel, "-auth", "-founder", NULL);
|
|
1091 }
|
|
1092
|
|
1093 void silcgaim_chat_invite(GaimConnection *gc, int id, const char *msg,
|
|
1094 const char *name)
|
|
1095 {
|
|
1096 SilcGaim sg = gc->proto_data;
|
|
1097 SilcClient client = sg->client;
|
|
1098 SilcClientConnection conn = sg->conn;
|
|
1099 SilcHashTableList htl;
|
|
1100 SilcChannelUser chu;
|
|
1101 gboolean found = FALSE;
|
|
1102
|
|
1103 if (!conn)
|
|
1104 return;
|
|
1105
|
|
1106 /* See if we are inviting on a private group. Invite
|
|
1107 to the actual channel */
|
|
1108 if (id > SILCGAIM_PRVGRP) {
|
|
1109 GList *l;
|
|
1110 SilcGaimPrvgrp prv;
|
|
1111
|
|
1112 for (l = sg->grps; l; l = l->next)
|
|
1113 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1114 break;
|
|
1115 if (!l)
|
|
1116 return;
|
|
1117 prv = l->data;
|
|
1118 id = prv->chid;
|
|
1119 }
|
|
1120
|
|
1121 /* Find channel by id */
|
|
1122 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1123 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1124 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1125 found = TRUE;
|
|
1126 break;
|
|
1127 }
|
|
1128 }
|
|
1129 silc_hash_table_list_reset(&htl);
|
|
1130 if (!found)
|
|
1131 return;
|
|
1132
|
|
1133 /* Call INVITE */
|
|
1134 silc_client_command_call(client, conn, NULL, "INVITE",
|
|
1135 chu->channel->channel_name,
|
9353
|
1136 name, NULL);
|
8849
|
1137 }
|
|
1138
|
|
1139 void silcgaim_chat_leave(GaimConnection *gc, int id)
|
|
1140 {
|
|
1141 SilcGaim sg = gc->proto_data;
|
|
1142 SilcClient client = sg->client;
|
|
1143 SilcClientConnection conn = sg->conn;
|
|
1144 SilcHashTableList htl;
|
|
1145 SilcChannelUser chu;
|
|
1146 gboolean found = FALSE;
|
|
1147 GList *l;
|
|
1148 SilcGaimPrvgrp prv;
|
|
1149
|
|
1150 if (!conn)
|
|
1151 return;
|
|
1152
|
|
1153 /* See if we are leaving a private group */
|
|
1154 if (id > SILCGAIM_PRVGRP) {
|
|
1155 SilcChannelEntry channel;
|
|
1156
|
|
1157 for (l = sg->grps; l; l = l->next)
|
|
1158 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1159 break;
|
|
1160 if (!l)
|
|
1161 return;
|
|
1162 prv = l->data;
|
|
1163 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
1164 (char *)prv->parentch);
|
|
1165 if (!channel)
|
|
1166 return;
|
|
1167 silc_client_del_channel_private_key(client, conn,
|
|
1168 channel, prv->key);
|
|
1169 silc_free(prv);
|
|
1170 sg->grps = g_list_remove(sg->grps, prv);
|
|
1171 serv_got_chat_left(gc, id);
|
|
1172 return;
|
|
1173 }
|
|
1174
|
|
1175 /* Find channel by id */
|
|
1176 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1177 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1178 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1179 found = TRUE;
|
|
1180 break;
|
|
1181 }
|
|
1182 }
|
|
1183 silc_hash_table_list_reset(&htl);
|
|
1184 if (!found)
|
|
1185 return;
|
|
1186
|
|
1187 /* Call LEAVE */
|
|
1188 silc_client_command_call(client, conn, NULL, "LEAVE",
|
|
1189 chu->channel->channel_name, NULL);
|
|
1190
|
|
1191 serv_got_chat_left(gc, id);
|
|
1192
|
|
1193 /* Leave from private groups on this channel as well */
|
|
1194 for (l = sg->grps; l; l = l->next)
|
|
1195 if (((SilcGaimPrvgrp)l->data)->chid == id) {
|
|
1196 prv = l->data;
|
|
1197 silc_client_del_channel_private_key(client, conn,
|
|
1198 chu->channel,
|
|
1199 prv->key);
|
|
1200 serv_got_chat_left(gc, prv->id);
|
|
1201 silc_free(prv);
|
|
1202 sg->grps = g_list_remove(sg->grps, prv);
|
|
1203 if (!sg->grps)
|
|
1204 break;
|
|
1205 }
|
|
1206 }
|
|
1207
|
|
1208 int silcgaim_chat_send(GaimConnection *gc, int id, const char *msg)
|
|
1209 {
|
|
1210 SilcGaim sg = gc->proto_data;
|
|
1211 SilcClient client = sg->client;
|
|
1212 SilcClientConnection conn = sg->conn;
|
|
1213 SilcHashTableList htl;
|
|
1214 SilcChannelUser chu;
|
|
1215 SilcChannelEntry channel = NULL;
|
|
1216 SilcChannelPrivateKey key = NULL;
|
|
1217 SilcUInt32 flags;
|
|
1218 int ret;
|
9353
|
1219 const char *msg2;
|
8849
|
1220 gboolean found = FALSE;
|
|
1221 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_chat");
|
|
1222
|
|
1223 if (!msg || !conn)
|
|
1224 return 0;
|
|
1225
|
9353
|
1226 flags = SILC_MESSAGE_FLAG_UTF8;
|
|
1227
|
|
1228 msg2 = msg;
|
|
1229
|
|
1230 if (!g_ascii_strncasecmp(msg2, "/me ", 4))
|
|
1231 {
|
|
1232 msg2 += 4;
|
|
1233 if (!msg2)
|
|
1234 return 0;
|
|
1235 flags |= SILC_MESSAGE_FLAG_ACTION;
|
|
1236 } else if (strlen(msg) > 1 && msg[0] == '/') {
|
8849
|
1237 if (!silc_client_command_call(client, conn, msg + 1))
|
|
1238 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"),
|
9353
|
1239 _("Unknown command"));
|
8849
|
1240 return 0;
|
|
1241 }
|
|
1242
|
9353
|
1243
|
8849
|
1244 if (sign)
|
|
1245 flags |= SILC_MESSAGE_FLAG_SIGNED;
|
|
1246
|
|
1247 /* Get the channel private key if we are sending on
|
|
1248 private group */
|
|
1249 if (id > SILCGAIM_PRVGRP) {
|
|
1250 GList *l;
|
|
1251 SilcGaimPrvgrp prv;
|
|
1252
|
|
1253 for (l = sg->grps; l; l = l->next)
|
|
1254 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1255 break;
|
|
1256 if (!l)
|
|
1257 return 0;
|
|
1258 prv = l->data;
|
|
1259 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
1260 (char *)prv->parentch);
|
|
1261 if (!channel)
|
|
1262 return 0;
|
|
1263 key = prv->key;
|
|
1264 }
|
|
1265
|
|
1266 if (!channel) {
|
|
1267 /* Find channel by id */
|
|
1268 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1269 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1270 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1271 found = TRUE;
|
|
1272 break;
|
|
1273 }
|
|
1274 }
|
|
1275 silc_hash_table_list_reset(&htl);
|
|
1276 if (!found)
|
|
1277 return 0;
|
|
1278 channel = chu->channel;
|
|
1279 }
|
|
1280
|
|
1281 /* Send channel message */
|
|
1282 ret = silc_client_send_channel_message(client, conn, channel, key,
|
9353
|
1283 flags, (unsigned char *)msg2,
|
|
1284 strlen(msg2), TRUE);
|
8849
|
1285 if (ret)
|
|
1286 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, msg,
|
|
1287 time(NULL));
|
|
1288
|
|
1289 return ret;
|
|
1290 }
|
|
1291
|
|
1292 void silcgaim_chat_set_topic(GaimConnection *gc, int id, const char *topic)
|
|
1293 {
|
|
1294 SilcGaim sg = gc->proto_data;
|
|
1295 SilcClient client = sg->client;
|
|
1296 SilcClientConnection conn = sg->conn;
|
|
1297 SilcHashTableList htl;
|
|
1298 SilcChannelUser chu;
|
|
1299 gboolean found = FALSE;
|
|
1300
|
9353
|
1301 if (!conn)
|
8849
|
1302 return;
|
|
1303
|
|
1304 /* See if setting topic on private group. Set it
|
|
1305 on the actual channel */
|
|
1306 if (id > SILCGAIM_PRVGRP) {
|
|
1307 GList *l;
|
|
1308 SilcGaimPrvgrp prv;
|
|
1309
|
|
1310 for (l = sg->grps; l; l = l->next)
|
|
1311 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1312 break;
|
|
1313 if (!l)
|
|
1314 return;
|
|
1315 prv = l->data;
|
|
1316 id = prv->chid;
|
|
1317 }
|
|
1318
|
|
1319 /* Find channel by id */
|
|
1320 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1321 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1322 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1323 found = TRUE;
|
|
1324 break;
|
|
1325 }
|
|
1326 }
|
|
1327 silc_hash_table_list_reset(&htl);
|
|
1328 if (!found)
|
|
1329 return;
|
|
1330
|
|
1331 /* Call TOPIC */
|
|
1332 silc_client_command_call(client, conn, NULL, "TOPIC",
|
|
1333 chu->channel->channel_name, topic, NULL);
|
|
1334 }
|
|
1335
|
|
1336 GaimRoomlist *silcgaim_roomlist_get_list(GaimConnection *gc)
|
|
1337 {
|
|
1338 SilcGaim sg = gc->proto_data;
|
|
1339 SilcClient client = sg->client;
|
|
1340 SilcClientConnection conn = sg->conn;
|
|
1341 GList *fields = NULL;
|
|
1342 GaimRoomlistField *f;
|
|
1343
|
|
1344 if (!conn)
|
|
1345 return NULL;
|
|
1346
|
|
1347 if (sg->roomlist)
|
|
1348 gaim_roomlist_unref(sg->roomlist);
|
|
1349
|
|
1350 sg->roomlist_canceled = FALSE;
|
|
1351
|
|
1352 sg->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc));
|
|
1353 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE);
|
|
1354 fields = g_list_append(fields, f);
|
|
1355 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT,
|
|
1356 _("Users"), "users", FALSE);
|
|
1357 fields = g_list_append(fields, f);
|
|
1358 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING,
|
|
1359 _("Topic"), "topic", FALSE);
|
|
1360 fields = g_list_append(fields, f);
|
|
1361 gaim_roomlist_set_fields(sg->roomlist, fields);
|
|
1362
|
|
1363 /* Call LIST */
|
|
1364 silc_client_command_call(client, conn, "LIST");
|
|
1365
|
|
1366 gaim_roomlist_set_in_progress(sg->roomlist, TRUE);
|
|
1367
|
|
1368 return sg->roomlist;
|
|
1369 }
|
|
1370
|
|
1371 void silcgaim_roomlist_cancel(GaimRoomlist *list)
|
|
1372 {
|
|
1373 GaimConnection *gc = gaim_account_get_connection(list->account);
|
|
1374 SilcGaim sg;
|
|
1375
|
|
1376 if (!gc)
|
|
1377 return;
|
|
1378 sg = gc->proto_data;
|
|
1379
|
|
1380 gaim_roomlist_set_in_progress(list, FALSE);
|
|
1381 if (sg->roomlist == list) {
|
|
1382 gaim_roomlist_unref(sg->roomlist);
|
|
1383 sg->roomlist = NULL;
|
|
1384 sg->roomlist_canceled = TRUE;
|
|
1385 }
|
|
1386 }
|