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