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