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 gaim_blist_save();
|
|
344 } else if (set == 0) {
|
|
345 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
|
346 sgc->channel->channel_name, "-a", NULL);
|
|
347 gaim_blist_node_remove_setting((GaimBlistNode *)sgc->c, "passphrase");
|
|
348 gaim_blist_save();
|
|
349 }
|
|
350
|
|
351 silc_buffer_free(sgc->pubkeys);
|
|
352 silc_free(sgc);
|
|
353 }
|
|
354
|
|
355 void silcgaim_chat_chauth_show(SilcGaim sg, SilcChannelEntry channel,
|
|
356 SilcBuffer channel_pubkeys)
|
|
357 {
|
|
358 SilcUInt16 argc;
|
|
359 SilcArgumentPayload chpks;
|
|
360 unsigned char *pk;
|
|
361 SilcUInt32 pk_len, type;
|
|
362 char *fingerprint, *babbleprint;
|
|
363 SilcPublicKey pubkey;
|
|
364 SilcPublicKeyIdentifier ident;
|
|
365 char tmp2[1024], t[512];
|
|
366 GaimRequestFields *fields;
|
|
367 GaimRequestFieldGroup *g;
|
|
368 GaimRequestField *f;
|
|
369 SilcGaimChauth sgc;
|
|
370 const char *curpass = NULL;
|
|
371
|
|
372 sgc = silc_calloc(1, sizeof(*sgc));
|
|
373 if (!sgc)
|
|
374 return;
|
|
375 sgc->sg = sg;
|
|
376 sgc->channel = channel;
|
|
377
|
|
378 fields = gaim_request_fields_new();
|
|
379
|
|
380 if (sgc->c)
|
|
381 curpass = gaim_blist_node_get_string((GaimBlistNode *)sgc->c, "passphrase");
|
|
382
|
|
383 g = gaim_request_field_group_new(NULL);
|
|
384 f = gaim_request_field_string_new("passphrase", _("Channel Passphrase"),
|
|
385 curpass, FALSE);
|
|
386 gaim_request_field_string_set_masked(f, TRUE);
|
|
387 gaim_request_field_group_add_field(g, f);
|
|
388 gaim_request_fields_add_group(fields, g);
|
|
389
|
|
390 g = gaim_request_field_group_new(NULL);
|
|
391 f = gaim_request_field_label_new("l1", _("Channel Public Keys List"));
|
|
392 gaim_request_field_group_add_field(g, f);
|
|
393 gaim_request_fields_add_group(fields, g);
|
|
394
|
|
395 g_snprintf(t, sizeof(t),
|
|
396 _("Channel authentication is used to secure the channel from "
|
|
397 "unauthorized access. The authentication may be based on "
|
|
398 "passphrase and digital signatures. If passphrase is set, it "
|
|
399 "is required to be able to join. If channel public keys are set "
|
|
400 "then only users whose public keys are listed are able to join."));
|
|
401
|
|
402 if (!channel_pubkeys) {
|
|
403 f = gaim_request_field_list_new("list", NULL);
|
|
404 gaim_request_field_group_add_field(g, f);
|
|
405 gaim_request_fields(NULL, _("Channel Authentication"),
|
|
406 _("Channel Authentication"), t, fields,
|
9275
|
407 _("Add / Remove"), G_CALLBACK(silcgaim_chat_chpk_cb),
|
|
408 _("OK"), G_CALLBACK(silcgaim_chat_chauth_ok), sgc);
|
8849
|
409 return;
|
|
410 }
|
|
411 sgc->pubkeys = silc_buffer_copy(channel_pubkeys);
|
|
412
|
|
413 g = gaim_request_field_group_new(NULL);
|
|
414 f = gaim_request_field_list_new("list", NULL);
|
|
415 gaim_request_field_group_add_field(g, f);
|
|
416 gaim_request_fields_add_group(fields, g);
|
|
417
|
|
418 SILC_GET16_MSB(argc, channel_pubkeys->data);
|
|
419 chpks = silc_argument_payload_parse(channel_pubkeys->data + 2,
|
|
420 channel_pubkeys->len - 2, argc);
|
|
421 if (!chpks)
|
|
422 return;
|
|
423
|
|
424 pk = silc_argument_get_first_arg(chpks, &type, &pk_len);
|
|
425 while (pk) {
|
|
426 fingerprint = silc_hash_fingerprint(NULL, pk + 4, pk_len - 4);
|
|
427 babbleprint = silc_hash_babbleprint(NULL, pk + 4, pk_len - 4);
|
|
428 silc_pkcs_public_key_payload_decode(pk, pk_len, &pubkey);
|
|
429 ident = silc_pkcs_decode_identifier(pubkey->identifier);
|
|
430
|
|
431 g_snprintf(tmp2, sizeof(tmp2), "%s\n %s\n %s",
|
|
432 ident->realname ? ident->realname : ident->username ?
|
|
433 ident->username : "", fingerprint, babbleprint);
|
|
434 gaim_request_field_list_add(f, tmp2, pubkey);
|
|
435
|
|
436 silc_free(fingerprint);
|
|
437 silc_free(babbleprint);
|
|
438 silc_pkcs_free_identifier(ident);
|
|
439 pk = silc_argument_get_next_arg(chpks, &type, &pk_len);
|
|
440 }
|
|
441
|
|
442 gaim_request_field_list_set_multi_select(f, FALSE);
|
|
443 gaim_request_fields(NULL, _("Channel Authentication"),
|
|
444 _("Channel Authentication"), t, fields,
|
9275
|
445 _("Add / Remove"), G_CALLBACK(silcgaim_chat_chpk_cb),
|
|
446 _("OK"), G_CALLBACK(silcgaim_chat_chauth_ok), sgc);
|
8849
|
447
|
|
448 silc_argument_payload_free(chpks);
|
|
449 }
|
|
450
|
|
451 static void
|
9030
|
452 silcgaim_chat_chauth(GaimBlistNode *node, gpointer data)
|
8849
|
453 {
|
9030
|
454 GaimChat *chat;
|
|
455 GaimConnection *gc;
|
|
456 SilcGaim sg;
|
|
457
|
|
458 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
459
|
|
460 chat = (GaimChat *) node;
|
|
461 gc = gaim_account_get_connection(chat->account);
|
|
462 sg = gc->proto_data;
|
|
463
|
8849
|
464 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
465 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
466 "+C", NULL);
|
|
467 }
|
|
468
|
|
469
|
|
470 /************************** Channel Private Groups **************************/
|
|
471
|
|
472 /* Private groups are "virtual" channels. They are groups inside a channel.
|
|
473 This is implemented by using channel private keys. By knowing a channel
|
|
474 private key user becomes part of that group and is able to talk on that
|
|
475 group. Other users, on the same channel, won't be able to see the
|
|
476 messages of that group. It is possible to have multiple groups inside
|
|
477 a channel - and thus having multiple private keys on the channel. */
|
|
478
|
|
479 typedef struct {
|
|
480 SilcGaim sg;
|
|
481 GaimChat *c;
|
|
482 const char *channel;
|
|
483 } *SilcGaimCharPrv;
|
|
484
|
|
485 static void
|
|
486 silcgaim_chat_prv_add(SilcGaimCharPrv p, GaimRequestFields *fields)
|
|
487 {
|
|
488 SilcGaim sg = p->sg;
|
|
489 char tmp[512];
|
|
490 GaimRequestField *f;
|
|
491 const char *name, *passphrase, *alias;
|
|
492 GHashTable *comp;
|
|
493 GaimGroup *g;
|
|
494 GaimChat *cn;
|
|
495
|
|
496 f = gaim_request_fields_get_field(fields, "name");
|
|
497 name = gaim_request_field_string_get_value(f);
|
|
498 if (!name) {
|
|
499 silc_free(p);
|
|
500 return;
|
|
501 }
|
|
502 f = gaim_request_fields_get_field(fields, "passphrase");
|
|
503 passphrase = gaim_request_field_string_get_value(f);
|
|
504 f = gaim_request_fields_get_field(fields, "alias");
|
|
505 alias = gaim_request_field_string_get_value(f);
|
|
506
|
|
507 /* Add private group to buddy list */
|
|
508 g_snprintf(tmp, sizeof(tmp), "%s [Private Group]", name);
|
|
509 comp = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
510 g_hash_table_replace(comp, g_strdup("channel"), g_strdup(tmp));
|
|
511 g_hash_table_replace(comp, g_strdup("passphrase"), g_strdup(passphrase));
|
|
512
|
|
513 cn = gaim_chat_new(sg->account, alias, comp);
|
|
514 g = (GaimGroup *)p->c->node.parent;
|
|
515 gaim_blist_add_chat(cn, g, (GaimBlistNode *)p->c);
|
|
516
|
|
517 /* Associate to a real channel */
|
|
518 gaim_blist_node_set_string((GaimBlistNode *)cn, "parentch", p->channel);
|
|
519 gaim_blist_save();
|
|
520
|
|
521 /* Join the group */
|
|
522 silcgaim_chat_join(sg->gc, comp);
|
|
523
|
|
524 silc_free(p);
|
|
525 }
|
|
526
|
|
527 static void
|
|
528 silcgaim_chat_prv_cancel(SilcGaimCharPrv p, GaimRequestFields *fields)
|
|
529 {
|
|
530 silc_free(p);
|
|
531 }
|
|
532
|
|
533 static void
|
9030
|
534 silcgaim_chat_prv(GaimBlistNode *node, gpointer data)
|
8849
|
535 {
|
9030
|
536 GaimChat *chat;
|
|
537 GaimConnection *gc;
|
|
538 SilcGaim sg;
|
|
539
|
8849
|
540 SilcGaimCharPrv p;
|
|
541 GaimRequestFields *fields;
|
|
542 GaimRequestFieldGroup *g;
|
|
543 GaimRequestField *f;
|
|
544 char tmp[512];
|
|
545
|
9030
|
546 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
547
|
|
548 chat = (GaimChat *) node;
|
|
549 gc = gaim_account_get_connection(chat->account);
|
|
550 sg = gc->proto_data;
|
|
551
|
8849
|
552 p = silc_calloc(1, sizeof(*p));
|
|
553 if (!p)
|
|
554 return;
|
|
555 p->sg = sg;
|
|
556
|
9030
|
557 p->channel = g_hash_table_lookup(chat->components, "channel");
|
8849
|
558 p->c = gaim_blist_find_chat(sg->account, p->channel);
|
|
559
|
|
560 fields = gaim_request_fields_new();
|
|
561
|
|
562 g = gaim_request_field_group_new(NULL);
|
|
563 f = gaim_request_field_string_new("name", _("Group Name"),
|
|
564 NULL, FALSE);
|
|
565 gaim_request_field_group_add_field(g, f);
|
|
566
|
|
567 f = gaim_request_field_string_new("passphrase", _("Passphrase"),
|
|
568 NULL, FALSE);
|
|
569 gaim_request_field_string_set_masked(f, TRUE);
|
|
570 gaim_request_field_group_add_field(g, f);
|
|
571
|
|
572 f = gaim_request_field_string_new("alias", _("Alias"),
|
|
573 NULL, FALSE);
|
|
574 gaim_request_field_group_add_field(g, f);
|
|
575 gaim_request_fields_add_group(fields, g);
|
|
576
|
|
577 g_snprintf(tmp, sizeof(tmp),
|
|
578 _("Please enter the %s channel private group name and passphrase."),
|
|
579 p->channel);
|
|
580 gaim_request_fields(NULL, _("Add Channel Private Group"), NULL, tmp, fields,
|
9275
|
581 _("Add"), G_CALLBACK(silcgaim_chat_prv_add),
|
|
582 _("Cancel"), G_CALLBACK(silcgaim_chat_prv_cancel), p);
|
8849
|
583 }
|
|
584
|
|
585
|
|
586 /****************************** Channel Modes ********************************/
|
|
587
|
|
588 static void
|
9030
|
589 silcgaim_chat_permanent_reset(GaimBlistNode *node, gpointer data)
|
8849
|
590 {
|
9030
|
591 GaimChat *chat;
|
|
592 GaimConnection *gc;
|
|
593 SilcGaim sg;
|
|
594
|
|
595 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
596
|
|
597 chat = (GaimChat *) node;
|
|
598 gc = gaim_account_get_connection(chat->account);
|
|
599 sg = gc->proto_data;
|
|
600
|
8849
|
601 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
602 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
603 "-f", NULL);
|
|
604 }
|
|
605
|
|
606 static void
|
9030
|
607 silcgaim_chat_permanent(GaimBlistNode *node, gpointer data)
|
8849
|
608 {
|
9030
|
609 GaimChat *chat;
|
|
610 GaimConnection *gc;
|
|
611 SilcGaim sg;
|
8849
|
612 const char *channel;
|
|
613
|
9030
|
614 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
615
|
|
616 chat = (GaimChat *) node;
|
|
617 gc = gaim_account_get_connection(chat->account);
|
|
618 sg = gc->proto_data;
|
|
619
|
8849
|
620 if (!sg->conn)
|
|
621 return;
|
|
622
|
|
623 /* XXX we should have ability to define which founder
|
|
624 key to use. Now we use the user's own public key
|
|
625 (default key). */
|
|
626
|
|
627 /* Call CMODE */
|
9030
|
628 channel = g_hash_table_lookup(chat->components, "channel");
|
8849
|
629 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE", channel,
|
|
630 "+f", NULL);
|
|
631 }
|
|
632
|
|
633 typedef struct {
|
|
634 SilcGaim sg;
|
|
635 const char *channel;
|
|
636 } *SilcGaimChatInput;
|
|
637
|
|
638 static void
|
|
639 silcgaim_chat_ulimit_cb(SilcGaimChatInput s, const char *limit)
|
|
640 {
|
|
641 SilcChannelEntry channel;
|
|
642 int ulimit = 0;
|
|
643
|
|
644 channel = silc_client_get_channel(s->sg->client, s->sg->conn,
|
|
645 (char *)s->channel);
|
|
646 if (!channel)
|
|
647 return;
|
|
648 if (limit)
|
|
649 ulimit = atoi(limit);
|
|
650
|
|
651 if (!limit || !(*limit) || *limit == '0') {
|
|
652 if (limit && ulimit == channel->user_limit) {
|
|
653 silc_free(s);
|
|
654 return;
|
|
655 }
|
|
656 silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
|
|
657 s->channel, "-l", NULL);
|
|
658
|
|
659 silc_free(s);
|
|
660 return;
|
|
661 }
|
|
662
|
|
663 if (ulimit == channel->user_limit) {
|
|
664 silc_free(s);
|
|
665 return;
|
|
666 }
|
|
667
|
|
668 /* Call CMODE */
|
|
669 silc_client_command_call(s->sg->client, s->sg->conn, NULL, "CMODE",
|
|
670 s->channel, "+l", limit, NULL);
|
|
671
|
|
672 silc_free(s);
|
|
673 }
|
|
674
|
|
675 static void
|
9030
|
676 silcgaim_chat_ulimit(GaimBlistNode *node, gpointer data)
|
8849
|
677 {
|
9030
|
678 GaimChat *chat;
|
|
679 GaimConnection *gc;
|
|
680 SilcGaim sg;
|
|
681
|
8849
|
682 SilcGaimChatInput s;
|
|
683 SilcChannelEntry channel;
|
|
684 const char *ch;
|
|
685 char tmp[32];
|
|
686
|
9030
|
687 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
688
|
|
689 chat = (GaimChat *) node;
|
|
690 gc = gaim_account_get_connection(chat->account);
|
|
691 sg = gc->proto_data;
|
|
692
|
8849
|
693 if (!sg->conn)
|
|
694 return;
|
|
695
|
9030
|
696 ch = g_strdup(g_hash_table_lookup(chat->components, "channel"));
|
8849
|
697 channel = silc_client_get_channel(sg->client, sg->conn, (char *)ch);
|
|
698 if (!channel)
|
|
699 return;
|
|
700
|
|
701 s = silc_calloc(1, sizeof(*s));
|
|
702 if (!s)
|
|
703 return;
|
|
704 s->channel = ch;
|
|
705 s->sg = sg;
|
|
706 g_snprintf(tmp, sizeof(tmp), "%d", (int)channel->user_limit);
|
|
707 gaim_request_input(NULL, _("User Limit"), NULL,
|
|
708 _("Set user limit on channel. Set to zero to reset user limit."),
|
|
709 tmp, FALSE, FALSE, NULL,
|
|
710 _("OK"), G_CALLBACK(silcgaim_chat_ulimit_cb),
|
|
711 _("Cancel"), G_CALLBACK(silcgaim_chat_ulimit_cb), s);
|
|
712 }
|
|
713
|
|
714 static void
|
9030
|
715 silcgaim_chat_resettopic(GaimBlistNode *node, gpointer data)
|
8849
|
716 {
|
9030
|
717 GaimChat *chat;
|
|
718 GaimConnection *gc;
|
|
719 SilcGaim sg;
|
|
720
|
|
721 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
722
|
|
723 chat = (GaimChat *) node;
|
|
724 gc = gaim_account_get_connection(chat->account);
|
|
725 sg = gc->proto_data;
|
|
726
|
8849
|
727 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
728 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
729 "-t", NULL);
|
|
730 }
|
|
731
|
|
732 static void
|
9030
|
733 silcgaim_chat_settopic(GaimBlistNode *node, gpointer data)
|
8849
|
734 {
|
9030
|
735 GaimChat *chat;
|
|
736 GaimConnection *gc;
|
|
737 SilcGaim sg;
|
|
738
|
|
739 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
740
|
|
741 chat = (GaimChat *) node;
|
|
742 gc = gaim_account_get_connection(chat->account);
|
|
743 sg = gc->proto_data;
|
|
744
|
8849
|
745 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
746 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
747 "+t", NULL);
|
|
748 }
|
|
749
|
|
750 static void
|
9030
|
751 silcgaim_chat_resetprivate(GaimBlistNode *node, gpointer data)
|
8849
|
752 {
|
9030
|
753 GaimChat *chat;
|
|
754 GaimConnection *gc;
|
|
755 SilcGaim sg;
|
|
756
|
|
757 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
758
|
|
759 chat = (GaimChat *) node;
|
|
760 gc = gaim_account_get_connection(chat->account);
|
|
761 sg = gc->proto_data;
|
|
762
|
8849
|
763 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
764 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
765 "-p", NULL);
|
|
766 }
|
|
767
|
|
768 static void
|
9030
|
769 silcgaim_chat_setprivate(GaimBlistNode *node, gpointer data)
|
8849
|
770 {
|
9030
|
771 GaimChat *chat;
|
|
772 GaimConnection *gc;
|
|
773 SilcGaim sg;
|
|
774
|
|
775 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
776
|
|
777 chat = (GaimChat *) node;
|
|
778 gc = gaim_account_get_connection(chat->account);
|
|
779 sg = gc->proto_data;
|
|
780
|
8849
|
781 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
782 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
783 "+p", NULL);
|
|
784 }
|
|
785
|
|
786 static void
|
9030
|
787 silcgaim_chat_resetsecret(GaimBlistNode *node, gpointer data)
|
8849
|
788 {
|
9030
|
789 GaimChat *chat;
|
|
790 GaimConnection *gc;
|
|
791 SilcGaim sg;
|
|
792
|
|
793 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
794
|
|
795 chat = (GaimChat *) node;
|
|
796 gc = gaim_account_get_connection(chat->account);
|
|
797 sg = gc->proto_data;
|
|
798
|
8849
|
799 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
800 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
801 "-s", NULL);
|
|
802 }
|
|
803
|
|
804 static void
|
9030
|
805 silcgaim_chat_setsecret(GaimBlistNode *node, gpointer data)
|
8849
|
806 {
|
9030
|
807 GaimChat *chat;
|
|
808 GaimConnection *gc;
|
|
809 SilcGaim sg;
|
|
810
|
|
811 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node));
|
|
812
|
|
813 chat = (GaimChat *) node;
|
|
814 gc = gaim_account_get_connection(chat->account);
|
|
815 sg = gc->proto_data;
|
|
816
|
8849
|
817 silc_client_command_call(sg->client, sg->conn, NULL, "CMODE",
|
9030
|
818 g_hash_table_lookup(chat->components, "channel"),
|
8849
|
819 "+s", NULL);
|
|
820 }
|
|
821
|
9030
|
822 GList *silcgaim_chat_menu(GaimChat *chat)
|
8849
|
823 {
|
9038
|
824 GHashTable *components = chat->components;
|
9030
|
825 GaimConnection *gc = gaim_account_get_connection(chat->account);
|
8849
|
826 SilcGaim sg = gc->proto_data;
|
|
827 SilcClientConnection conn = sg->conn;
|
|
828 const char *chname = NULL;
|
|
829 SilcChannelEntry channel = NULL;
|
|
830 SilcChannelUser chu = NULL;
|
|
831 SilcUInt32 mode = 0;
|
|
832
|
9038
|
833 GList *m = NULL;
|
9030
|
834 GaimBlistNodeAction *act;
|
|
835
|
8849
|
836 if (components)
|
|
837 chname = g_hash_table_lookup(components, "channel");
|
|
838 if (chname)
|
|
839 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
840 (char *)chname);
|
|
841 if (channel) {
|
|
842 chu = silc_client_on_channel(channel, conn->local_entry);
|
|
843 if (chu)
|
|
844 mode = chu->mode;
|
|
845 }
|
|
846
|
|
847 if (strstr(chname, "[Private Group]"))
|
|
848 return NULL;
|
|
849
|
9030
|
850 act = gaim_blist_node_action_new(_("Get Info"),
|
9038
|
851 silcgaim_chat_getinfo_menu, NULL);
|
9030
|
852 m = g_list_append(m, act);
|
8849
|
853
|
|
854 #if 0 /* XXX For now these are not implemented. We need better
|
|
855 listview dialog from Gaim for these. */
|
|
856 if (mode & SILC_CHANNEL_UMODE_CHANOP) {
|
9030
|
857 act = gaim_blist_node_action_new(_("Invite List"),
|
|
858 silcgaim_chat_invitelist, NULL);
|
|
859 m = g_list_append(m, act);
|
8849
|
860
|
9030
|
861 act = gaim_blist_node_action_new(_("Ban List"),
|
|
862 silcgaim_chat_banlist, NULL);
|
|
863 m = g_list_append(m, act);
|
8849
|
864 }
|
|
865 #endif
|
|
866
|
|
867 if (chu) {
|
9030
|
868 act = gaim_blist_node_action_new(_("Add Private Group"),
|
|
869 silcgaim_chat_prv, NULL);
|
|
870 m = g_list_append(m, act);
|
8849
|
871 }
|
|
872
|
|
873 if (mode & SILC_CHANNEL_UMODE_CHANFO) {
|
9030
|
874 act = gaim_blist_node_action_new(_("Channel Authentication"),
|
|
875 silcgaim_chat_chauth, NULL);
|
|
876 m = g_list_append(m, act);
|
8849
|
877
|
|
878 if (channel->mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) {
|
9030
|
879 act = gaim_blist_node_action_new(_("Reset Permanent"),
|
|
880 silcgaim_chat_permanent_reset, NULL);
|
|
881 m = g_list_append(m, act);
|
8849
|
882 } else {
|
9030
|
883 act = gaim_blist_node_action_new(_("Set Permanent"),
|
|
884 silcgaim_chat_permanent, NULL);
|
|
885 m = g_list_append(m, act);
|
8849
|
886 }
|
|
887 }
|
|
888
|
|
889 if (mode & SILC_CHANNEL_UMODE_CHANOP) {
|
9030
|
890 act = gaim_blist_node_action_new(_("Set User Limit"),
|
|
891 silcgaim_chat_ulimit, NULL);
|
|
892 m = g_list_append(m, act);
|
8849
|
893
|
|
894 if (channel->mode & SILC_CHANNEL_MODE_TOPIC) {
|
9030
|
895 act = gaim_blist_node_action_new(_("Reset Topic Restriction"),
|
|
896 silcgaim_chat_resettopic, NULL);
|
|
897 m = g_list_append(m, act);
|
8849
|
898 } else {
|
9030
|
899 act = gaim_blist_node_action_new(_("Set Topic Restriction"),
|
|
900 silcgaim_chat_settopic, NULL);
|
|
901 m = g_list_append(m, act);
|
8849
|
902 }
|
|
903
|
|
904 if (channel->mode & SILC_CHANNEL_MODE_PRIVATE) {
|
9030
|
905 act = gaim_blist_node_action_new(_("Reset Private Channel"),
|
|
906 silcgaim_chat_resetprivate, NULL);
|
|
907 m = g_list_append(m, act);
|
8849
|
908 } else {
|
9030
|
909 act = gaim_blist_node_action_new(_("Set Private Channel"),
|
|
910 silcgaim_chat_setprivate, NULL);
|
|
911 m = g_list_append(m, act);
|
8849
|
912 }
|
|
913
|
|
914 if (channel->mode & SILC_CHANNEL_MODE_SECRET) {
|
9030
|
915 act = gaim_blist_node_action_new(_("Reset Secret Channel"),
|
|
916 silcgaim_chat_resetsecret, NULL);
|
|
917 m = g_list_append(m, act);
|
8849
|
918 } else {
|
9030
|
919 act = gaim_blist_node_action_new(_("Set Secret Channel"),
|
|
920 silcgaim_chat_setsecret, NULL);
|
|
921 m = g_list_append(m, act);
|
8849
|
922 }
|
|
923 }
|
|
924
|
|
925 return m;
|
|
926 }
|
|
927
|
|
928
|
|
929 /******************************* Joining Etc. ********************************/
|
|
930
|
|
931 void silcgaim_chat_join_done(SilcClient client,
|
|
932 SilcClientConnection conn,
|
|
933 SilcClientEntry *clients,
|
|
934 SilcUInt32 clients_count,
|
|
935 void *context)
|
|
936 {
|
|
937 GaimConnection *gc = client->application;
|
|
938 SilcGaim sg = gc->proto_data;
|
|
939 SilcChannelEntry channel = context;
|
|
940 GaimConversation *convo;
|
|
941 SilcUInt32 retry = SILC_PTR_TO_32(channel->context);
|
|
942 SilcHashTableList htl;
|
|
943 SilcChannelUser chu;
|
|
944 GList *users = NULL;
|
|
945 char tmp[256];
|
|
946
|
|
947 if (!clients && retry < 1) {
|
|
948 /* Resolving users failed, try again. */
|
|
949 channel->context = SILC_32_TO_PTR(retry + 1);
|
|
950 silc_client_get_clients_by_channel(client, conn, channel,
|
|
951 silcgaim_chat_join_done, channel);
|
|
952 return;
|
|
953 }
|
|
954
|
|
955 /* Add channel to Gaim */
|
|
956 channel->context = SILC_32_TO_PTR(++sg->channel_ids);
|
|
957 serv_got_joined_chat(gc, sg->channel_ids, channel->channel_name);
|
|
958 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
959 sg->account);
|
|
960 if (!convo)
|
|
961 return;
|
|
962
|
|
963 /* Add all users to channel */
|
|
964 silc_hash_table_list(channel->user_list, &htl);
|
|
965 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
966 if (!chu->client->nickname)
|
|
967 continue;
|
|
968 chu->context = SILC_32_TO_PTR(sg->channel_ids);
|
|
969
|
|
970 #if 0 /* XXX don't append mode char to nick because Gaim doesn't
|
|
971 give a way to change it afterwards when mode changes. */
|
|
972 tmp2 = silc_client_chumode_char(chu->mode);
|
|
973 if (tmp2)
|
8891
|
974 g_snprintf(tmp, sizeof(tmp), "%s%s", tmp2,
|
8849
|
975 chu->client->nickname);
|
|
976 else
|
8891
|
977 g_snprintf(tmp, sizeof(tmp), "%s",
|
8849
|
978 chu->client->nickname);
|
|
979 silc_free(tmp2);
|
|
980
|
|
981 users = g_list_append(users, g_strdup(tmp));
|
|
982 #else
|
|
983 users = g_list_append(users, g_strdup(chu->client->nickname));
|
|
984 #endif
|
|
985
|
|
986 if (chu->mode & SILC_CHANNEL_UMODE_CHANFO) {
|
|
987 if (chu->client == conn->local_entry)
|
|
988 g_snprintf(tmp, sizeof(tmp),
|
|
989 _("You are channel founder on <I>%s</I>"),
|
|
990 channel->channel_name);
|
|
991 else
|
|
992 g_snprintf(tmp, sizeof(tmp),
|
|
993 _("Channel founder on <I>%s</I> is <I>%s</I>"),
|
|
994 channel->channel_name, chu->client->nickname);
|
|
995
|
|
996 gaim_conversation_write(convo, NULL, tmp,
|
|
997 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
998
|
|
999 }
|
|
1000 }
|
|
1001 silc_hash_table_list_reset(&htl);
|
|
1002
|
|
1003 gaim_conv_chat_add_users(GAIM_CONV_CHAT(convo), users);
|
|
1004 g_list_free(users);
|
|
1005
|
|
1006 /* Set topic */
|
|
1007 if (channel->topic)
|
|
1008 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, channel->topic);
|
|
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,
|
|
1136 name);
|
|
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;
|
|
1219 gboolean found = FALSE;
|
|
1220 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_chat");
|
|
1221
|
|
1222 if (!msg || !conn)
|
|
1223 return 0;
|
|
1224
|
|
1225 /* See if command */
|
|
1226 if (strlen(msg) > 1 && msg[0] == '/') {
|
|
1227 if (!silc_client_command_call(client, conn, msg + 1))
|
|
1228 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"),
|
|
1229 _("Unknown command"));
|
|
1230 return 0;
|
|
1231 }
|
|
1232
|
|
1233 flags = SILC_MESSAGE_FLAG_UTF8;
|
|
1234 if (sign)
|
|
1235 flags |= SILC_MESSAGE_FLAG_SIGNED;
|
|
1236
|
|
1237 /* Get the channel private key if we are sending on
|
|
1238 private group */
|
|
1239 if (id > SILCGAIM_PRVGRP) {
|
|
1240 GList *l;
|
|
1241 SilcGaimPrvgrp prv;
|
|
1242
|
|
1243 for (l = sg->grps; l; l = l->next)
|
|
1244 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1245 break;
|
|
1246 if (!l)
|
|
1247 return 0;
|
|
1248 prv = l->data;
|
|
1249 channel = silc_client_get_channel(sg->client, sg->conn,
|
|
1250 (char *)prv->parentch);
|
|
1251 if (!channel)
|
|
1252 return 0;
|
|
1253 key = prv->key;
|
|
1254 }
|
|
1255
|
|
1256 if (!channel) {
|
|
1257 /* Find channel by id */
|
|
1258 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1259 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1260 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1261 found = TRUE;
|
|
1262 break;
|
|
1263 }
|
|
1264 }
|
|
1265 silc_hash_table_list_reset(&htl);
|
|
1266 if (!found)
|
|
1267 return 0;
|
|
1268 channel = chu->channel;
|
|
1269 }
|
|
1270
|
|
1271 /* Send channel message */
|
|
1272 ret = silc_client_send_channel_message(client, conn, channel, key,
|
|
1273 flags, (unsigned char *)msg,
|
|
1274 strlen(msg), TRUE);
|
|
1275 if (ret)
|
|
1276 serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, msg,
|
|
1277 time(NULL));
|
|
1278
|
|
1279 return ret;
|
|
1280 }
|
|
1281
|
|
1282 void silcgaim_chat_set_topic(GaimConnection *gc, int id, const char *topic)
|
|
1283 {
|
|
1284 SilcGaim sg = gc->proto_data;
|
|
1285 SilcClient client = sg->client;
|
|
1286 SilcClientConnection conn = sg->conn;
|
|
1287 SilcHashTableList htl;
|
|
1288 SilcChannelUser chu;
|
|
1289 gboolean found = FALSE;
|
|
1290
|
|
1291 if (!topic || !conn)
|
|
1292 return;
|
|
1293
|
|
1294 /* See if setting topic on private group. Set it
|
|
1295 on the actual channel */
|
|
1296 if (id > SILCGAIM_PRVGRP) {
|
|
1297 GList *l;
|
|
1298 SilcGaimPrvgrp prv;
|
|
1299
|
|
1300 for (l = sg->grps; l; l = l->next)
|
|
1301 if (((SilcGaimPrvgrp)l->data)->id == id)
|
|
1302 break;
|
|
1303 if (!l)
|
|
1304 return;
|
|
1305 prv = l->data;
|
|
1306 id = prv->chid;
|
|
1307 }
|
|
1308
|
|
1309 /* Find channel by id */
|
|
1310 silc_hash_table_list(conn->local_entry->channels, &htl);
|
|
1311 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
1312 if (SILC_PTR_TO_32(chu->channel->context) == id ) {
|
|
1313 found = TRUE;
|
|
1314 break;
|
|
1315 }
|
|
1316 }
|
|
1317 silc_hash_table_list_reset(&htl);
|
|
1318 if (!found)
|
|
1319 return;
|
|
1320
|
|
1321 /* Call TOPIC */
|
|
1322 silc_client_command_call(client, conn, NULL, "TOPIC",
|
|
1323 chu->channel->channel_name, topic, NULL);
|
|
1324 }
|
|
1325
|
|
1326 GaimRoomlist *silcgaim_roomlist_get_list(GaimConnection *gc)
|
|
1327 {
|
|
1328 SilcGaim sg = gc->proto_data;
|
|
1329 SilcClient client = sg->client;
|
|
1330 SilcClientConnection conn = sg->conn;
|
|
1331 GList *fields = NULL;
|
|
1332 GaimRoomlistField *f;
|
|
1333
|
|
1334 if (!conn)
|
|
1335 return NULL;
|
|
1336
|
|
1337 if (sg->roomlist)
|
|
1338 gaim_roomlist_unref(sg->roomlist);
|
|
1339
|
|
1340 sg->roomlist_canceled = FALSE;
|
|
1341
|
|
1342 sg->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc));
|
|
1343 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE);
|
|
1344 fields = g_list_append(fields, f);
|
|
1345 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT,
|
|
1346 _("Users"), "users", FALSE);
|
|
1347 fields = g_list_append(fields, f);
|
|
1348 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING,
|
|
1349 _("Topic"), "topic", FALSE);
|
|
1350 fields = g_list_append(fields, f);
|
|
1351 gaim_roomlist_set_fields(sg->roomlist, fields);
|
|
1352
|
|
1353 /* Call LIST */
|
|
1354 silc_client_command_call(client, conn, "LIST");
|
|
1355
|
|
1356 gaim_roomlist_set_in_progress(sg->roomlist, TRUE);
|
|
1357
|
|
1358 return sg->roomlist;
|
|
1359 }
|
|
1360
|
|
1361 void silcgaim_roomlist_cancel(GaimRoomlist *list)
|
|
1362 {
|
|
1363 GaimConnection *gc = gaim_account_get_connection(list->account);
|
|
1364 SilcGaim sg;
|
|
1365
|
|
1366 if (!gc)
|
|
1367 return;
|
|
1368 sg = gc->proto_data;
|
|
1369
|
|
1370 gaim_roomlist_set_in_progress(list, FALSE);
|
|
1371 if (sg->roomlist == list) {
|
|
1372 gaim_roomlist_unref(sg->roomlist);
|
|
1373 sg->roomlist = NULL;
|
|
1374 sg->roomlist_canceled = TRUE;
|
|
1375 }
|
|
1376 }
|