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