8849
|
1 /*
|
|
2
|
|
3 silcgaim_ops.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 /* Message sent to the application by library. `conn' associates the
|
|
25 message to a specific connection. `conn', however, may be NULL.
|
|
26 The `type' indicates the type of the message sent by the library.
|
|
27 The application can for example filter the message according the
|
|
28 type. */
|
|
29
|
|
30 static void
|
|
31 silc_say(SilcClient client, SilcClientConnection conn,
|
|
32 SilcClientMessageType type, char *msg, ...)
|
|
33 {
|
|
34 /* Nothing */
|
|
35 }
|
|
36
|
|
37
|
|
38 /* Message for a channel. The `sender' is the sender of the message
|
|
39 The `channel' is the channel. The `message' is the message. Note
|
|
40 that `message' maybe NULL. The `flags' indicates message flags
|
|
41 and it is used to determine how the message can be interpreted
|
|
42 (like it may tell the message is multimedia message). */
|
|
43
|
|
44 static void
|
|
45 silc_channel_message(SilcClient client, SilcClientConnection conn,
|
|
46 SilcClientEntry sender, SilcChannelEntry channel,
|
|
47 SilcMessagePayload payload, SilcChannelPrivateKey key,
|
|
48 SilcMessageFlags flags, const unsigned char *message,
|
|
49 SilcUInt32 message_len)
|
|
50 {
|
|
51 GaimConnection *gc = client->application;
|
|
52 SilcGaim sg = gc->proto_data;
|
|
53 GaimConversation *convo = NULL;
|
|
54 char *msg;
|
|
55
|
|
56 if (!message)
|
|
57 return;
|
|
58
|
|
59 if (key) {
|
|
60 GList *l;
|
|
61 SilcGaimPrvgrp prv;
|
|
62
|
|
63 for (l = sg->grps; l; l = l->next)
|
|
64 if (((SilcGaimPrvgrp)l->data)->key == key) {
|
|
65 prv = l->data;
|
|
66 convo = gaim_find_conversation_with_account(prv->channel,
|
|
67 sg->account);
|
|
68 break;
|
|
69 }
|
|
70 }
|
|
71 if (!convo)
|
|
72 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
73 sg->account);
|
|
74 if (!convo)
|
|
75 return;
|
|
76
|
|
77 if (flags & SILC_MESSAGE_FLAG_SIGNED &&
|
|
78 gaim_prefs_get_bool("/plugins/prpl/silc/verify_chat")) {
|
|
79 /* XXX */
|
|
80 }
|
|
81
|
|
82 if (flags & SILC_MESSAGE_FLAG_DATA) {
|
|
83 /* XXX */
|
|
84 return;
|
|
85 }
|
|
86
|
|
87 if (flags & SILC_MESSAGE_FLAG_ACTION) {
|
|
88 msg = g_strdup_printf("<I>%s</I> %s",
|
|
89 sender->nickname ?
|
|
90 sender->nickname : "<unknown>",
|
|
91 (const char *)message);
|
|
92 if (!msg)
|
|
93 return;
|
|
94
|
|
95 /* Send to Gaim */
|
|
96 gaim_conversation_write(convo, NULL, (const char *)msg,
|
|
97 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
98 g_free(msg);
|
|
99 return;
|
|
100 }
|
|
101
|
|
102 if (flags & SILC_MESSAGE_FLAG_NOTICE) {
|
|
103 msg = g_strdup_printf("(notice) <I>%s</I> %s",
|
|
104 sender->nickname ?
|
|
105 sender->nickname : "<unknown>",
|
|
106 (const char *)message);
|
|
107 if (!msg)
|
|
108 return;
|
|
109
|
|
110 /* Send to Gaim */
|
|
111 gaim_conversation_write(convo, NULL, (const char *)msg,
|
|
112 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
113 g_free(msg);
|
|
114 return;
|
|
115 }
|
|
116
|
|
117 if (flags & SILC_MESSAGE_FLAG_UTF8)
|
|
118 /* Send to Gaim */
|
|
119 serv_got_chat_in(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)),
|
|
120 sender->nickname ?
|
|
121 sender->nickname : "<unknown>", 0,
|
|
122 (const char *)message, time(NULL));
|
|
123 }
|
|
124
|
|
125
|
|
126 /* Private message to the client. The `sender' is the sender of the
|
|
127 message. The message is `message'and maybe NULL. The `flags'
|
|
128 indicates message flags and it is used to determine how the message
|
|
129 can be interpreted (like it may tell the message is multimedia
|
|
130 message). */
|
|
131
|
|
132 static void
|
|
133 silc_private_message(SilcClient client, SilcClientConnection conn,
|
|
134 SilcClientEntry sender, SilcMessagePayload payload,
|
|
135 SilcMessageFlags flags, const unsigned char *message,
|
|
136 SilcUInt32 message_len)
|
|
137 {
|
|
138 GaimConnection *gc = client->application;
|
|
139 SilcGaim sg = gc->proto_data;
|
|
140 GaimConversation *convo = NULL;
|
|
141 char *msg;
|
|
142
|
|
143 if (!message)
|
|
144 return;
|
|
145
|
|
146 if (sender->nickname)
|
|
147 convo = gaim_find_conversation_with_account(sender->nickname, sg->account);
|
|
148
|
|
149 if (flags & SILC_MESSAGE_FLAG_SIGNED &&
|
|
150 gaim_prefs_get_bool("/plugins/prpl/silc/verify_im")) {
|
|
151 /* XXX */
|
|
152 }
|
|
153
|
|
154 if (flags & SILC_MESSAGE_FLAG_DATA) {
|
|
155 /* XXX */
|
|
156 return;
|
|
157 }
|
|
158
|
|
159 if (flags & SILC_MESSAGE_FLAG_ACTION && convo) {
|
|
160 msg = g_strdup_printf("<I>%s</I> %s",
|
|
161 sender->nickname ?
|
|
162 sender->nickname : "<unknown>",
|
|
163 (const char *)message);
|
|
164 if (!msg)
|
|
165 return;
|
|
166
|
|
167 /* Send to Gaim */
|
|
168 gaim_conversation_write(convo, NULL, (const char *)msg,
|
|
169 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
170 g_free(msg);
|
|
171 return;
|
|
172 }
|
|
173
|
|
174 if (flags & SILC_MESSAGE_FLAG_NOTICE && convo) {
|
|
175 msg = g_strdup_printf("(notice) <I>%s</I> %s",
|
|
176 sender->nickname ?
|
|
177 sender->nickname : "<unknown>",
|
|
178 (const char *)message);
|
|
179 if (!msg)
|
|
180 return;
|
|
181
|
|
182 /* Send to Gaim */
|
|
183 gaim_conversation_write(convo, NULL, (const char *)msg,
|
|
184 GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
185 g_free(msg);
|
|
186 return;
|
|
187 }
|
|
188
|
|
189 if (flags & SILC_MESSAGE_FLAG_UTF8)
|
|
190 /* Send to Gaim */
|
|
191 serv_got_im(gc, sender->nickname ?
|
|
192 sender->nickname : "<unknown>",
|
|
193 (const char *)message, 0, time(NULL));
|
|
194 }
|
|
195
|
|
196
|
|
197 /* Notify message to the client. The notify arguments are sent in the
|
|
198 same order as servers sends them. The arguments are same as received
|
|
199 from the server except for ID's. If ID is received application receives
|
|
200 the corresponding entry to the ID. For example, if Client ID is received
|
|
201 application receives SilcClientEntry. Also, if the notify type is
|
|
202 for channel the channel entry is sent to application (even if server
|
|
203 does not send it because client library gets the channel entry from
|
|
204 the Channel ID in the packet's header). */
|
|
205
|
|
206 static void
|
|
207 silc_notify(SilcClient client, SilcClientConnection conn,
|
|
208 SilcNotifyType type, ...)
|
|
209 {
|
|
210 va_list va;
|
|
211 GaimConnection *gc = client->application;
|
|
212 SilcGaim sg = gc->proto_data;
|
|
213 GaimConversation *convo;
|
|
214 SilcClientEntry client_entry, client_entry2;
|
|
215 SilcChannelEntry channel;
|
|
216 SilcServerEntry server_entry;
|
|
217 SilcIdType idtype;
|
|
218 void *entry;
|
|
219 SilcUInt32 mode;
|
|
220 SilcHashTableList htl;
|
|
221 SilcChannelUser chu;
|
|
222 char buf[512], buf2[512], *tmp, *name;
|
|
223 SilcBuffer buffer;
|
|
224 SilcNotifyType notify;
|
|
225 GaimBuddy *b;
|
|
226 int i;
|
|
227
|
|
228 va_start(va, type);
|
|
229 memset(buf, 0, sizeof(buf));
|
|
230
|
|
231 switch (type) {
|
|
232
|
|
233 case SILC_NOTIFY_TYPE_NONE:
|
|
234 break;
|
|
235
|
|
236 case SILC_NOTIFY_TYPE_INVITE:
|
|
237 {
|
|
238 GHashTable *components;
|
|
239 channel = va_arg(va, SilcChannelEntry);
|
|
240 name = va_arg(va, char *);
|
|
241 client_entry = va_arg(va, SilcClientEntry);
|
|
242
|
|
243 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
244 g_hash_table_insert(components, strdup("channel"), name);
|
|
245 serv_got_chat_invite(gc, name, client_entry->nickname, NULL, NULL);
|
|
246 }
|
|
247 break;
|
|
248
|
|
249 case SILC_NOTIFY_TYPE_JOIN:
|
|
250 client_entry = va_arg(va, SilcClientEntry);
|
|
251 channel = va_arg(va, SilcChannelEntry);
|
|
252
|
|
253 /* If we joined channel, do nothing */
|
|
254 if (client_entry == conn->local_entry)
|
|
255 break;
|
|
256
|
|
257 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
258 sg->account);
|
|
259 if (!convo)
|
|
260 break;
|
|
261
|
|
262 /* Join user to channel */
|
8891
|
263 g_snprintf(buf, sizeof(buf), "%s@%s",
|
8849
|
264 client_entry->username, client_entry->hostname);
|
|
265 gaim_conv_chat_add_user(GAIM_CONV_CHAT(convo),
|
|
266 g_strdup(client_entry->nickname), buf);
|
|
267
|
|
268 break;
|
|
269
|
|
270 case SILC_NOTIFY_TYPE_LEAVE:
|
|
271 client_entry = va_arg(va, SilcClientEntry);
|
|
272 channel = va_arg(va, SilcChannelEntry);
|
|
273
|
|
274 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
275 sg->account);
|
|
276 if (!convo)
|
|
277 break;
|
|
278
|
|
279 /* Remove user from channel */
|
|
280 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
281 client_entry->nickname, NULL);
|
|
282
|
|
283 break;
|
|
284
|
|
285 case SILC_NOTIFY_TYPE_SIGNOFF:
|
|
286 client_entry = va_arg(va, SilcClientEntry);
|
|
287 tmp = va_arg(va, char *);
|
|
288
|
|
289 if (!client_entry->nickname)
|
|
290 break;
|
|
291
|
|
292 /* Remove from all channels */
|
|
293 silc_hash_table_list(client_entry->channels, &htl);
|
|
294 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
295 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
296 sg->account);
|
|
297 if (!convo)
|
|
298 continue;
|
|
299 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
300 client_entry->nickname,
|
|
301 tmp);
|
|
302 }
|
|
303 silc_hash_table_list_reset(&htl);
|
|
304
|
|
305 break;
|
|
306
|
|
307 case SILC_NOTIFY_TYPE_TOPIC_SET:
|
|
308 idtype = va_arg(va, int);
|
|
309 entry = va_arg(va, void *);
|
|
310 tmp = va_arg(va, char *);
|
|
311 channel = va_arg(va, SilcChannelEntry);
|
|
312
|
|
313 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
314 sg->account);
|
|
315 if (!convo)
|
|
316 break;
|
|
317
|
|
318 if (!tmp)
|
|
319 break;
|
|
320
|
|
321 if (idtype == SILC_ID_CLIENT) {
|
|
322 client_entry = (SilcClientEntry)entry;
|
|
323 g_snprintf(buf, sizeof(buf),
|
|
324 _("%s has changed the topic of <I>%s</I> to: %s"),
|
|
325 client_entry->nickname, channel->channel_name, tmp);
|
|
326 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), client_entry->nickname,
|
|
327 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
328 } else if (idtype == SILC_ID_SERVER) {
|
|
329 server_entry = (SilcServerEntry)entry;
|
|
330 g_snprintf(buf, sizeof(buf),
|
|
331 _("%s has changed the topic of <I>%s</I> to: %s"),
|
|
332 server_entry->server_name, channel->channel_name, tmp);
|
|
333 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), server_entry->server_name,
|
|
334 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
335 } else if (idtype == SILC_ID_CHANNEL) {
|
|
336 channel = (SilcChannelEntry)entry;
|
|
337 g_snprintf(buf, sizeof(buf),
|
|
338 _("%s has changed the topic of <I>%s</I> to: %s"),
|
|
339 channel->channel_name, channel->channel_name, tmp);
|
|
340 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), channel->channel_name,
|
|
341 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
342 }
|
|
343
|
|
344 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, tmp);
|
|
345
|
|
346 break;
|
|
347
|
|
348 case SILC_NOTIFY_TYPE_NICK_CHANGE:
|
|
349 client_entry = va_arg(va, SilcClientEntry);
|
|
350 client_entry2 = va_arg(va, SilcClientEntry);
|
|
351
|
|
352 if (!strcmp(client_entry->nickname, client_entry2->nickname))
|
|
353 break;
|
|
354
|
|
355 /* Change nick on all channels */
|
|
356 silc_hash_table_list(client_entry2->channels, &htl);
|
|
357 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
358 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
359 sg->account);
|
|
360 if (!convo)
|
|
361 continue;
|
|
362 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(convo),
|
|
363 client_entry->nickname,
|
|
364 client_entry2->nickname);
|
|
365 }
|
|
366 silc_hash_table_list_reset(&htl);
|
|
367
|
|
368 break;
|
|
369
|
|
370 case SILC_NOTIFY_TYPE_CMODE_CHANGE:
|
|
371 idtype = va_arg(va, int);
|
|
372 entry = va_arg(va, void *);
|
|
373 mode = va_arg(va, SilcUInt32);
|
|
374 (void)va_arg(va, char *);
|
|
375 (void)va_arg(va, char *);
|
|
376 (void)va_arg(va, char *);
|
|
377 (void)va_arg(va, SilcPublicKey);
|
|
378 buffer = va_arg(va, SilcBuffer);
|
|
379 channel = va_arg(va, SilcChannelEntry);
|
|
380
|
|
381 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
382 sg->account);
|
|
383 if (!convo)
|
|
384 break;
|
|
385
|
|
386 if (idtype == SILC_ID_CLIENT)
|
|
387 name = ((SilcClientEntry)entry)->nickname;
|
|
388 else if (idtype == SILC_ID_SERVER)
|
|
389 name = ((SilcServerEntry)entry)->server_name;
|
|
390 else
|
|
391 name = ((SilcChannelEntry)entry)->channel_name;
|
|
392 if (!name)
|
|
393 break;
|
|
394
|
|
395 if (mode) {
|
|
396 silcgaim_get_chmode_string(mode, buf2, sizeof(buf2));
|
|
397 g_snprintf(buf, sizeof(buf),
|
|
398 _("<I>%s</I> set channel <I>%s</I> modes to: %s"), name,
|
|
399 channel->channel_name, buf2);
|
|
400 } else {
|
|
401 g_snprintf(buf, sizeof(buf),
|
|
402 _("<I>%s</I> removed all channel <I>%s</I> modes"), name,
|
|
403 channel->channel_name);
|
|
404 }
|
|
405 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), channel->channel_name,
|
|
406 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
407 break;
|
|
408
|
|
409 case SILC_NOTIFY_TYPE_CUMODE_CHANGE:
|
|
410 idtype = va_arg(va, int);
|
|
411 entry = va_arg(va, void *);
|
|
412 mode = va_arg(va, SilcUInt32);
|
|
413 client_entry2 = va_arg(va, SilcClientEntry);
|
|
414 channel = va_arg(va, SilcChannelEntry);
|
|
415
|
|
416 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
417 sg->account);
|
|
418 if (!convo)
|
|
419 break;
|
|
420
|
|
421 if (idtype == SILC_ID_CLIENT)
|
|
422 name = ((SilcClientEntry)entry)->nickname;
|
|
423 else if (idtype == SILC_ID_SERVER)
|
|
424 name = ((SilcServerEntry)entry)->server_name;
|
|
425 else
|
|
426 name = ((SilcChannelEntry)entry)->channel_name;
|
|
427 if (!name)
|
|
428 break;
|
|
429
|
|
430 if (mode) {
|
|
431 silcgaim_get_chumode_string(mode, buf2, sizeof(buf2));
|
|
432 g_snprintf(buf, sizeof(buf),
|
|
433 _("<I>%s</I> set <I>%s's</I> modes to: %s"), name,
|
|
434 client_entry2->nickname, buf2);
|
|
435 } else {
|
|
436 g_snprintf(buf, sizeof(buf),
|
|
437 _("<I>%s</I> removed all <I>%s's</I> modes"), name,
|
|
438 client_entry2->nickname);
|
|
439 }
|
|
440 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), channel->channel_name,
|
|
441 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
442 break;
|
|
443
|
|
444 case SILC_NOTIFY_TYPE_MOTD:
|
|
445 tmp = va_arg(va, char *);
|
|
446 silc_free(sg->motd);
|
|
447 sg->motd = silc_memdup(tmp, strlen(tmp));
|
|
448 break;
|
|
449
|
|
450 case SILC_NOTIFY_TYPE_KICKED:
|
|
451 client_entry = va_arg(va, SilcClientEntry);
|
|
452 tmp = va_arg(va, char *);
|
|
453 client_entry2 = va_arg(va, SilcClientEntry);
|
|
454 channel = va_arg(va, SilcChannelEntry);
|
|
455
|
|
456 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
457 sg->account);
|
|
458 if (!convo)
|
|
459 break;
|
|
460
|
|
461 if (client_entry == conn->local_entry) {
|
|
462 /* Remove us from channel */
|
|
463 g_snprintf(buf, sizeof(buf),
|
|
464 _("You have been kicked off <I>%s</I> by <I>%s</I> (%s)"),
|
|
465 channel->channel_name, client_entry2->nickname,
|
|
466 tmp ? tmp : "");
|
|
467 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), client_entry->nickname,
|
|
468 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
469 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)));
|
|
470 } else {
|
|
471 /* Remove user from channel */
|
|
472 g_snprintf(buf, sizeof(buf), ("Kicked by %s (%s)"),
|
|
473 client_entry2->nickname, tmp ? tmp : "");
|
|
474 gaim_conv_chat_rename_user(GAIM_CONV_CHAT(convo),
|
|
475 client_entry->nickname,
|
|
476 buf);
|
|
477 }
|
|
478
|
|
479 break;
|
|
480
|
|
481 case SILC_NOTIFY_TYPE_KILLED:
|
|
482 client_entry = va_arg(va, SilcClientEntry);
|
|
483 tmp = va_arg(va, char *);
|
|
484 idtype = va_arg(va, int);
|
|
485 entry = va_arg(va, SilcClientEntry);
|
|
486
|
|
487 if (!client_entry->nickname)
|
|
488 break;
|
|
489
|
|
490 if (client_entry == conn->local_entry) {
|
|
491 if (idtype == SILC_ID_CLIENT) {
|
|
492 client_entry2 = (SilcClientEntry)entry;
|
|
493 g_snprintf(buf, sizeof(buf),
|
|
494 _("You have been killed by %s (%s)"),
|
|
495 client_entry2->nickname, tmp ? tmp : "");
|
|
496 } else if (idtype == SILC_ID_SERVER) {
|
|
497 server_entry = (SilcServerEntry)entry;
|
|
498 g_snprintf(buf, sizeof(buf),
|
|
499 _("You have been killed by %s (%s)"),
|
|
500 server_entry->server_name, tmp ? tmp : "");
|
|
501 } else if (idtype == SILC_ID_CHANNEL) {
|
|
502 channel = (SilcChannelEntry)entry;
|
|
503 g_snprintf(buf, sizeof(buf),
|
|
504 _("You have been killed by %s (%s)"),
|
|
505 channel->channel_name, tmp ? tmp : "");
|
|
506 }
|
|
507
|
|
508 /* Remove us from all channels */
|
|
509 silc_hash_table_list(client_entry->channels, &htl);
|
|
510 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
511 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
512 sg->account);
|
|
513 if (!convo)
|
|
514 continue;
|
|
515 gaim_conv_chat_write(GAIM_CONV_CHAT(convo), client_entry->nickname,
|
|
516 buf, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
517 serv_got_chat_left(gc, gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)));
|
|
518 }
|
|
519 silc_hash_table_list_reset(&htl);
|
|
520
|
|
521 } else {
|
|
522 if (idtype == SILC_ID_CLIENT) {
|
|
523 client_entry2 = (SilcClientEntry)entry;
|
|
524 g_snprintf(buf, sizeof(buf),
|
|
525 _("Killed by %s (%s)"),
|
|
526 client_entry2->nickname, tmp ? tmp : "");
|
|
527 } else if (idtype == SILC_ID_SERVER) {
|
|
528 server_entry = (SilcServerEntry)entry;
|
|
529 g_snprintf(buf, sizeof(buf),
|
|
530 _("Killed by %s (%s)"),
|
|
531 server_entry->server_name, tmp ? tmp : "");
|
|
532 } else if (idtype == SILC_ID_CHANNEL) {
|
|
533 channel = (SilcChannelEntry)entry;
|
|
534 g_snprintf(buf, sizeof(buf),
|
|
535 _("Killed by %s (%s)"),
|
|
536 channel->channel_name, tmp ? tmp : "");
|
|
537 }
|
|
538
|
|
539 /* Remove user from all channels */
|
|
540 silc_hash_table_list(client_entry->channels, &htl);
|
|
541 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
542 convo = gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
543 sg->account);
|
|
544 if (!convo)
|
|
545 continue;
|
|
546 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
547 client_entry->nickname, tmp);
|
|
548 }
|
|
549 silc_hash_table_list_reset(&htl);
|
|
550 }
|
|
551
|
|
552 break;
|
|
553
|
|
554 case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
|
|
555 break;
|
|
556
|
|
557 case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
|
|
558 {
|
|
559 int i;
|
|
560 SilcClientEntry *clients;
|
|
561 SilcUInt32 clients_count;
|
|
562
|
|
563 (void)va_arg(va, void *);
|
|
564 clients = va_arg(va, SilcClientEntry *);
|
|
565 clients_count = va_arg(va, SilcUInt32);
|
|
566
|
|
567 for (i = 0; i < clients_count; i++) {
|
|
568 if (!clients[i]->nickname)
|
|
569 break;
|
|
570
|
|
571 /* Remove from all channels */
|
|
572 silc_hash_table_list(clients[i]->channels, &htl);
|
|
573 while (silc_hash_table_get(&htl, NULL, (void *)&chu)) {
|
|
574 convo =
|
|
575 gaim_find_conversation_with_account(chu->channel->channel_name,
|
|
576 sg->account);
|
|
577 if (!convo)
|
|
578 continue;
|
|
579 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(convo),
|
|
580 clients[i]->nickname,
|
|
581 _("Server signoff"));
|
|
582 }
|
|
583 silc_hash_table_list_reset(&htl);
|
|
584 }
|
|
585 }
|
|
586 break;
|
|
587
|
|
588 case SILC_NOTIFY_TYPE_ERROR:
|
|
589 {
|
|
590 SilcStatus error = va_arg(va, int);
|
|
591 gaim_notify_error(gc, "Error Notify",
|
|
592 silc_get_status_message(error),
|
|
593 NULL);
|
|
594 }
|
|
595 break;
|
|
596
|
|
597 case SILC_NOTIFY_TYPE_WATCH:
|
|
598 {
|
|
599 SilcPublicKey public_key;
|
|
600 unsigned char *pk;
|
|
601 SilcUInt32 pk_len;
|
|
602 char *fingerprint;
|
|
603
|
|
604 client_entry = va_arg(va, SilcClientEntry);
|
|
605 (void)va_arg(va, char *);
|
|
606 mode = va_arg(va, SilcUInt32);
|
|
607 notify = va_arg(va, int);
|
|
608 public_key = va_arg(va, SilcPublicKey);
|
|
609
|
|
610 b = NULL;
|
|
611 if (public_key) {
|
|
612 GaimBlistNode *gnode, *cnode, *bnode;
|
|
613 const char *f;
|
|
614
|
|
615 pk = silc_pkcs_public_key_encode(public_key, &pk_len);
|
|
616 if (!pk)
|
|
617 break;
|
|
618 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
619 for (i = 0; i < strlen(fingerprint); i++)
|
|
620 if (fingerprint[i] == ' ')
|
|
621 fingerprint[i] = '_';
|
|
622 g_snprintf(buf, sizeof(buf) - 1,
|
|
623 "%s" G_DIR_SEPARATOR_S "clientkeys"
|
|
624 G_DIR_SEPARATOR_S "clientkey_%s.pub",
|
|
625 silcgaim_silcdir(), fingerprint);
|
|
626 silc_free(fingerprint);
|
|
627 silc_free(pk);
|
|
628
|
|
629 /* Find buddy by associated public key */
|
|
630 for (gnode = gaim_get_blist()->root; gnode;
|
|
631 gnode = gnode->next) {
|
|
632 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
|
|
633 continue;
|
|
634 for (cnode = gnode->child; cnode; cnode = cnode->next) {
|
|
635 if( !GAIM_BLIST_NODE_IS_CONTACT(cnode))
|
|
636 continue;
|
|
637 for (bnode = cnode->child; bnode;
|
|
638 bnode = bnode->next) {
|
|
639 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
|
|
640 continue;
|
|
641 b = (GaimBuddy *)bnode;
|
|
642 if (b->account != gc->account)
|
|
643 continue;
|
|
644 f = gaim_blist_node_get_string(bnode, "public-key");
|
|
645 if (!strcmp(f, buf))
|
|
646 goto cont;
|
|
647 }
|
|
648 }
|
|
649 }
|
|
650 }
|
|
651 cont:
|
|
652 if (!b) {
|
|
653 /* Find buddy by nickname */
|
|
654 b = gaim_find_buddy(sg->account, client_entry->nickname);
|
|
655 if (!b) {
|
|
656 fprintf(stderr, "WATCH for %s, unknown buddy",
|
|
657 client_entry->nickname);
|
|
658 break;
|
|
659 }
|
|
660 }
|
|
661
|
|
662 silc_free(b->proto_data);
|
|
663 b->proto_data = silc_memdup(client_entry->id,
|
|
664 sizeof(*client_entry->id));
|
|
665 if (notify == SILC_NOTIFY_TYPE_NICK_CHANGE) {
|
|
666 break;
|
|
667 } else if (notify == SILC_NOTIFY_TYPE_UMODE_CHANGE) {
|
|
668 /* See if client was away and is now present */
|
|
669 if (!(mode & (SILC_UMODE_GONE | SILC_UMODE_INDISPOSED |
|
|
670 SILC_UMODE_BUSY | SILC_UMODE_PAGE |
|
|
671 SILC_UMODE_DETACHED)) &&
|
|
672 (client_entry->mode & SILC_UMODE_GONE ||
|
|
673 client_entry->mode & SILC_UMODE_INDISPOSED ||
|
|
674 client_entry->mode & SILC_UMODE_BUSY ||
|
|
675 client_entry->mode & SILC_UMODE_PAGE ||
|
|
676 client_entry->mode & SILC_UMODE_DETACHED)) {
|
|
677 client_entry->mode = mode;
|
|
678 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_ONLINE);
|
|
679 }
|
|
680 else if ((mode & SILC_UMODE_GONE) ||
|
|
681 (mode & SILC_UMODE_INDISPOSED) ||
|
|
682 (mode & SILC_UMODE_BUSY) ||
|
|
683 (mode & SILC_UMODE_PAGE) ||
|
|
684 (mode & SILC_UMODE_DETACHED)) {
|
|
685 client_entry->mode = mode;
|
|
686 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_OFFLINE);
|
|
687 }
|
|
688 } else if (notify == SILC_NOTIFY_TYPE_SIGNOFF ||
|
|
689 notify == SILC_NOTIFY_TYPE_SERVER_SIGNOFF ||
|
|
690 notify == SILC_NOTIFY_TYPE_KILLED) {
|
|
691 client_entry->mode = mode;
|
|
692 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_OFFLINE);
|
|
693 } else if (notify == SILC_NOTIFY_TYPE_NONE) {
|
|
694 client_entry->mode = mode;
|
|
695 gaim_blist_update_buddy_presence(b, GAIM_BUDDY_ONLINE);
|
|
696 }
|
|
697 }
|
|
698 break;
|
|
699
|
|
700 default:
|
|
701 break;
|
|
702 }
|
|
703
|
|
704 va_end(va);
|
|
705 }
|
|
706
|
|
707
|
|
708 /* Command handler. This function is called always in the command function.
|
|
709 If error occurs it will be called as well. `conn' is the associated
|
|
710 client connection. `cmd_context' is the command context that was
|
|
711 originally sent to the command. `success' is FALSE if error occurred
|
|
712 during command. `command' is the command being processed. It must be
|
|
713 noted that this is not reply from server. This is merely called just
|
|
714 after application has called the command. Just to tell application
|
|
715 that the command really was processed. */
|
|
716
|
|
717 static void
|
|
718 silc_command(SilcClient client, SilcClientConnection conn,
|
|
719 SilcClientCommandContext cmd_context, bool success,
|
|
720 SilcCommand command, SilcStatus status)
|
|
721 {
|
|
722 GaimConnection *gc = client->application;
|
|
723 SilcGaim sg = gc->proto_data;
|
|
724
|
|
725 switch (command) {
|
|
726
|
|
727 case SILC_COMMAND_CMODE:
|
|
728 if (cmd_context->argc == 3 &&
|
|
729 !strcmp(cmd_context->argv[2], "+C"))
|
|
730 sg->chpk = TRUE;
|
|
731 else
|
|
732 sg->chpk = FALSE;
|
|
733 break;
|
|
734
|
|
735 default:
|
|
736 break;
|
|
737 }
|
|
738 }
|
|
739
|
9024
|
740 #if 0
|
8849
|
741 static void
|
|
742 silcgaim_whois_more(SilcClientEntry client_entry, gint id)
|
|
743 {
|
|
744 SilcAttributePayload attr;
|
|
745 SilcAttribute attribute;
|
|
746 char *buf;
|
|
747 GString *s;
|
|
748 SilcVCardStruct vcard;
|
|
749 int i;
|
|
750
|
|
751 if (id != 0)
|
|
752 return;
|
|
753
|
|
754 memset(&vcard, 0, sizeof(vcard));
|
|
755
|
|
756 s = g_string_new("");
|
|
757
|
|
758 silc_dlist_start(client_entry->attrs);
|
|
759 while ((attr = silc_dlist_get(client_entry->attrs)) != SILC_LIST_END) {
|
|
760 attribute = silc_attribute_get_attribute(attr);
|
|
761 switch (attribute) {
|
|
762
|
|
763 case SILC_ATTRIBUTE_USER_INFO:
|
|
764 if (!silc_attribute_get_object(attr, (void *)&vcard,
|
|
765 sizeof(vcard)))
|
|
766 continue;
|
9039
|
767 g_string_append_printf(s, "%s:\n\n", _("Personal Information"));
|
8849
|
768 if (vcard.full_name)
|
9039
|
769 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
770 _("Full Name"),
|
8849
|
771 vcard.full_name);
|
|
772 if (vcard.first_name)
|
9039
|
773 g_string_append_printf(s, "%s:\t%s\n",
|
|
774 _("First Name"),
|
8849
|
775 vcard.first_name);
|
|
776 if (vcard.middle_names)
|
9039
|
777 g_string_append_printf(s, "%s:\t%s\n",
|
|
778 _("Middle Name"),
|
8849
|
779 vcard.middle_names);
|
|
780 if (vcard.family_name)
|
9039
|
781 g_string_append_printf(s, "%s:\t%s\n",
|
|
782 _("Family Name"),
|
8849
|
783 vcard.family_name);
|
|
784 if (vcard.nickname)
|
9039
|
785 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
786 _("Nickname"),
|
8849
|
787 vcard.nickname);
|
|
788 if (vcard.bday)
|
9039
|
789 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
790 _("Birth Day"),
|
8849
|
791 vcard.bday);
|
|
792 if (vcard.title)
|
9039
|
793 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
794 _("Job Title"),
|
8849
|
795 vcard.title);
|
|
796 if (vcard.role)
|
9039
|
797 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
798 _("Job Role"),
|
8849
|
799 vcard.role);
|
|
800 if (vcard.org_name)
|
9039
|
801 g_string_append_printf(s, "%s:\t%s\n",
|
|
802 _("Organization"),
|
8849
|
803 vcard.org_name);
|
|
804 if (vcard.org_unit)
|
9039
|
805 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
806 _("Unit"),
|
8849
|
807 vcard.org_unit);
|
|
808 if (vcard.url)
|
9039
|
809 g_string_append_printf(s, "%s:\t%s\n",
|
|
810 _("Homepage"),
|
8849
|
811 vcard.url);
|
|
812 if (vcard.label)
|
9039
|
813 g_string_append_printf(s, "%s:\t%s\n",
|
|
814 _("Address"),
|
8849
|
815 vcard.label);
|
|
816 for (i = 0; i < vcard.num_tels; i++) {
|
|
817 if (vcard.tels[i].telnum)
|
9039
|
818 g_string_append_printf(s, "%s:\t\t\t%s\n",
|
|
819 _("Phone"),
|
8849
|
820 vcard.tels[i].telnum);
|
|
821 }
|
|
822 for (i = 0; i < vcard.num_emails; i++) {
|
|
823 if (vcard.emails[i].address)
|
9039
|
824 g_string_append_printf(s, "%s:\t\t%s\n",
|
|
825 _("EMail"),
|
8849
|
826 vcard.emails[i].address);
|
|
827 }
|
|
828 if (vcard.note)
|
9039
|
829 g_string_append_printf(s, "\n%s:\t\t%s\n",
|
|
830 _("Note"),
|
8849
|
831 vcard.note);
|
|
832 break;
|
|
833 }
|
|
834 }
|
|
835
|
|
836 buf = g_string_free(s, FALSE);
|
|
837 gaim_notify_info(NULL, _("User Information"), _("User Information"),
|
|
838 buf);
|
|
839 g_free(buf);
|
|
840 }
|
9024
|
841 #endif
|
8849
|
842
|
|
843 /* Command reply handler. This function is called always in the command reply
|
|
844 function. If error occurs it will be called as well. Normal scenario
|
|
845 is that it will be called after the received command data has been parsed
|
|
846 and processed. The function is used to pass the received command data to
|
|
847 the application.
|
|
848
|
|
849 `conn' is the associated client connection. `cmd_payload' is the command
|
|
850 payload data received from server and it can be ignored. It is provided
|
|
851 if the application would like to re-parse the received command data,
|
|
852 however, it must be noted that the data is parsed already by the library
|
|
853 thus the payload can be ignored. `success' is FALSE if error occurred.
|
|
854 In this case arguments are not sent to the application. The `status' is
|
|
855 the command reply status server returned. The `command' is the command
|
|
856 reply being processed. The function has variable argument list and each
|
|
857 command defines the number and type of arguments it passes to the
|
|
858 application (on error they are not sent). */
|
|
859
|
|
860 static void
|
|
861 silc_command_reply(SilcClient client, SilcClientConnection conn,
|
|
862 SilcCommandPayload cmd_payload, bool success,
|
|
863 SilcCommand command, SilcStatus status, ...)
|
|
864 {
|
|
865 GaimConnection *gc = client->application;
|
|
866 SilcGaim sg = gc->proto_data;
|
|
867 GaimConversation *convo;
|
|
868 va_list vp;
|
|
869
|
|
870 va_start(vp, status);
|
|
871
|
|
872 switch (command) {
|
|
873 case SILC_COMMAND_JOIN:
|
|
874 {
|
|
875 SilcChannelEntry channel_entry;
|
|
876
|
|
877 if (!success) {
|
|
878 gaim_notify_error(gc, _("Join Chat"), _("Cannot join channel"),
|
|
879 silc_get_status_message(status));
|
|
880 return;
|
|
881 }
|
|
882
|
|
883 (void)va_arg(vp, char *);
|
|
884 channel_entry = va_arg(vp, SilcChannelEntry);
|
|
885
|
|
886 /* Resolve users on channel */
|
|
887 silc_client_get_clients_by_channel(client, conn, channel_entry,
|
|
888 silcgaim_chat_join_done,
|
|
889 channel_entry);
|
|
890 }
|
|
891 break;
|
|
892
|
|
893 case SILC_COMMAND_LEAVE:
|
|
894 break;
|
|
895
|
|
896 case SILC_COMMAND_USERS:
|
|
897 break;
|
|
898
|
|
899 case SILC_COMMAND_WHOIS:
|
|
900 {
|
|
901 SilcUInt32 idle, mode;
|
|
902 SilcBuffer channels, user_modes;
|
|
903 SilcClientEntry client_entry;
|
|
904 char *buf, tmp[1024];
|
|
905 GString *s;
|
|
906
|
|
907 if (!success) {
|
|
908 gaim_notify_error(gc, _("User Information"),
|
|
909 _("Cannot get user information"),
|
|
910 silc_get_status_message(status));
|
|
911 break;
|
|
912 }
|
|
913
|
|
914 client_entry = va_arg(vp, SilcClientEntry);
|
|
915 if (!client_entry->nickname)
|
|
916 break;
|
|
917 (void)va_arg(vp, char *);
|
|
918 (void)va_arg(vp, char *);
|
|
919 (void)va_arg(vp, char *);
|
|
920 channels = va_arg(vp, SilcBuffer);
|
|
921 mode = va_arg(vp, SilcUInt32);
|
|
922 idle = va_arg(vp, SilcUInt32);
|
|
923 (void)va_arg(vp, unsigned char *);
|
|
924 user_modes = va_arg(vp, SilcBuffer);
|
|
925
|
|
926 s = g_string_new("");
|
9039
|
927 g_string_append_printf(s, "%s:\t\t%s\n", _("Nickname"), client_entry->nickname);
|
8849
|
928 if (client_entry->realname)
|
9039
|
929 g_string_append_printf(s, "%s:\t%s\n", _("Realname"), client_entry->realname);
|
8849
|
930 if (client_entry->username)
|
9039
|
931 g_string_append_printf(s, "%s:\t\t%s\n", _("Username"), client_entry->username);
|
8849
|
932 if (client_entry->hostname)
|
9039
|
933 g_string_append_printf(s, "%s:\t\t%s\n", _("Hostname"), client_entry->hostname);
|
8849
|
934 if (client_entry->server)
|
9039
|
935 g_string_append_printf(s, "%s:\t\t%s\n", _("Server"), client_entry->server);
|
8849
|
936
|
|
937 if (mode) {
|
|
938 memset(tmp, 0, sizeof(tmp));
|
|
939 silcgaim_get_umode_string(mode, tmp, sizeof(tmp) - 1);
|
9039
|
940 g_string_append_printf(s, "%s:\t%s\n", _("User Mode"), tmp);
|
8849
|
941 }
|
|
942
|
|
943 if (channels && user_modes) {
|
|
944 SilcUInt32 *umodes;
|
|
945 SilcDList list =
|
|
946 silc_channel_payload_parse_list(channels->data,
|
|
947 channels->len);
|
|
948 if (list && silc_get_mode_list(user_modes,
|
|
949 silc_dlist_count(list),
|
|
950 &umodes)) {
|
|
951 SilcChannelPayload entry;
|
|
952 int i = 0;
|
|
953
|
9039
|
954 g_string_append_printf(s, "\n%s:\n", _("Channels"));
|
8849
|
955 memset(tmp, 0, sizeof(tmp));
|
|
956 silc_dlist_start(list);
|
|
957 while ((entry = silc_dlist_get(list))
|
|
958 != SILC_LIST_END) {
|
|
959 SilcUInt32 name_len;
|
|
960 char *m = silc_client_chumode_char(umodes[i++]);
|
|
961 char *name = silc_channel_get_name(entry, &name_len);
|
|
962 if (m)
|
|
963 silc_strncat(tmp, sizeof(tmp) - 1, m, strlen(m));
|
|
964 silc_strncat(tmp, sizeof(tmp) - 1, name, name_len);
|
|
965 silc_strncat(tmp, sizeof(tmp) - 1, " ", 1);
|
|
966 silc_free(m);
|
|
967
|
|
968 }
|
8891
|
969 g_string_append_printf(s, "%s\n", tmp);
|
8849
|
970 silc_free(umodes);
|
|
971 }
|
|
972 }
|
|
973
|
|
974 if (client_entry->public_key) {
|
|
975 char *fingerprint, *babbleprint;
|
|
976 unsigned char *pk;
|
|
977 SilcUInt32 pk_len;
|
|
978 pk = silc_pkcs_public_key_encode(client_entry->public_key, &pk_len);
|
|
979 fingerprint = silc_hash_fingerprint(NULL, pk, pk_len);
|
|
980 babbleprint = silc_hash_babbleprint(NULL, pk, pk_len);
|
9039
|
981 g_string_append_printf(s, "\n%s:\n%s\n\n", _("Public Key Fingerprint"), fingerprint);
|
|
982 g_string_append_printf(s, "%s:\n%s", _("Public Key Babbleprint"), babbleprint);
|
8849
|
983 silc_free(fingerprint);
|
|
984 silc_free(babbleprint);
|
|
985 silc_free(pk);
|
|
986 }
|
|
987
|
|
988 buf = g_string_free(s, FALSE);
|
|
989 #if 0 /* XXX for now, let's not show attrs here */
|
|
990 if (client_entry->attrs)
|
|
991 gaim_request_action(NULL, _("User Information"),
|
|
992 _("User Information"),
|
|
993 buf, 1, client_entry, 2,
|
|
994 _("OK"), G_CALLBACK(silcgaim_whois_more),
|
|
995 _("More..."), G_CALLBACK(silcgaim_whois_more));
|
|
996 else
|
|
997 #endif
|
|
998 gaim_notify_info(NULL, _("User Information"),
|
|
999 _("User Information"), buf);
|
|
1000 g_free(buf);
|
|
1001 }
|
|
1002 break;
|
|
1003
|
|
1004 case SILC_COMMAND_DETACH:
|
|
1005 if (!success) {
|
|
1006 gaim_notify_error(gc, _("Detach From Server"), _("Cannot detach"),
|
|
1007 silc_get_status_message(status));
|
|
1008 return;
|
|
1009 }
|
|
1010 break;
|
|
1011
|
|
1012 case SILC_COMMAND_TOPIC:
|
|
1013 {
|
|
1014 SilcChannelEntry channel;
|
|
1015
|
|
1016 if (!success) {
|
|
1017 gaim_notify_error(gc, _("Topic"), _("Cannot set topic"),
|
|
1018 silc_get_status_message(status));
|
|
1019 return;
|
|
1020 }
|
|
1021
|
|
1022 channel = va_arg(vp, SilcChannelEntry);
|
|
1023
|
|
1024 convo = gaim_find_conversation_with_account(channel->channel_name,
|
|
1025 sg->account);
|
|
1026 if (!convo)
|
|
1027 break;
|
|
1028
|
|
1029 /* Set topic */
|
|
1030 if (channel->topic)
|
|
1031 gaim_conv_chat_set_topic(GAIM_CONV_CHAT(convo), NULL, channel->topic);
|
|
1032 }
|
|
1033 break;
|
|
1034
|
|
1035 case SILC_COMMAND_LIST:
|
|
1036 {
|
|
1037 char *topic, *name;
|
|
1038 int usercount;
|
|
1039 GaimRoomlistRoom *room;
|
|
1040
|
|
1041 if (sg->roomlist_canceled)
|
|
1042 break;
|
|
1043
|
|
1044 if (!success) {
|
|
1045 gaim_notify_error(gc, _("Roomlist"), _("Cannot get room list"),
|
|
1046 silc_get_status_message(status));
|
|
1047 gaim_roomlist_set_in_progress(sg->roomlist, FALSE);
|
|
1048 gaim_roomlist_unref(sg->roomlist);
|
|
1049 sg->roomlist = NULL;
|
|
1050 return;
|
|
1051 }
|
|
1052
|
|
1053 (void)va_arg(vp, SilcChannelEntry);
|
|
1054 name = va_arg(vp, char *);
|
|
1055 topic = va_arg(vp, char *);
|
|
1056 usercount = va_arg(vp, int);
|
|
1057
|
|
1058 room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, name, NULL);
|
|
1059 gaim_roomlist_room_add_field(sg->roomlist, room, name);
|
|
1060 gaim_roomlist_room_add_field(sg->roomlist, room,
|
|
1061 SILC_32_TO_PTR(usercount));
|
|
1062 gaim_roomlist_room_add_field(sg->roomlist, room,
|
|
1063 topic ? topic : "");
|
|
1064 gaim_roomlist_room_add(sg->roomlist, room);
|
|
1065
|
|
1066 if (status == SILC_STATUS_LIST_END ||
|
|
1067 status == SILC_STATUS_OK) {
|
|
1068 gaim_roomlist_set_in_progress(sg->roomlist, FALSE);
|
|
1069 gaim_roomlist_unref(sg->roomlist);
|
|
1070 sg->roomlist = NULL;
|
|
1071 }
|
|
1072 }
|
|
1073 break;
|
|
1074
|
|
1075 case SILC_COMMAND_GETKEY:
|
|
1076 {
|
|
1077 SilcPublicKey public_key;
|
|
1078
|
|
1079 if (!success) {
|
|
1080 gaim_notify_error(gc, _("Get Public Key"),
|
|
1081 _("Cannot fetch the public key"),
|
|
1082 silc_get_status_message(status));
|
|
1083 return;
|
|
1084 }
|
|
1085
|
|
1086 (void)va_arg(vp, SilcUInt32);
|
|
1087 (void)va_arg(vp, void *);
|
|
1088 public_key = va_arg(vp, SilcPublicKey);
|
|
1089
|
|
1090 if (!public_key)
|
|
1091 gaim_notify_error(gc, _("Get Public Key"),
|
|
1092 _("Cannot fetch the public key"),
|
|
1093 _("No public key was received"));
|
|
1094 }
|
|
1095 break;
|
|
1096
|
|
1097 case SILC_COMMAND_INFO:
|
|
1098 {
|
|
1099
|
|
1100 SilcServerEntry server_entry;
|
|
1101 char *server_name;
|
|
1102 char *server_info;
|
|
1103 char tmp[256];
|
|
1104
|
|
1105 if (!success) {
|
|
1106 gaim_notify_error(gc, _("Server Information"),
|
|
1107 _("Cannot get server information"),
|
|
1108 silc_get_status_message(status));
|
|
1109 return;
|
|
1110 }
|
|
1111
|
|
1112 server_entry = va_arg(vp, SilcServerEntry);
|
|
1113 server_name = va_arg(vp, char *);
|
|
1114 server_info = va_arg(vp, char *);
|
|
1115
|
|
1116 if (server_name && server_info) {
|
|
1117 g_snprintf(tmp, sizeof(tmp), "Server: %s\n%s",
|
|
1118 server_name, server_info);
|
|
1119 gaim_notify_info(NULL, _("Server Information"),
|
|
1120 _("Server Information"), tmp);
|
|
1121 }
|
|
1122 }
|
|
1123 break;
|
|
1124
|
|
1125 case SILC_COMMAND_KILL:
|
|
1126 if (!success) {
|
|
1127 gaim_notify_error(gc, _("Kill User"),
|
|
1128 _("Could not kill user"),
|
|
1129 silc_get_status_message(status));
|
|
1130 return;
|
|
1131 }
|
|
1132 break;
|
|
1133
|
|
1134 case SILC_COMMAND_CMODE:
|
|
1135 {
|
|
1136 SilcChannelEntry channel_entry;
|
|
1137 SilcBuffer channel_pubkeys;
|
|
1138
|
|
1139 if (!success)
|
|
1140 return;
|
|
1141
|
|
1142 channel_entry = va_arg(vp, SilcChannelEntry);
|
|
1143 (void)va_arg(vp, SilcUInt32);
|
|
1144 (void)va_arg(vp, SilcPublicKey);
|
|
1145 channel_pubkeys = va_arg(vp, SilcBuffer);
|
|
1146
|
|
1147 if (sg->chpk)
|
|
1148 silcgaim_chat_chauth_show(sg, channel_entry, channel_pubkeys);
|
|
1149 }
|
|
1150 break;
|
|
1151
|
|
1152 default:
|
|
1153 break;
|
|
1154 }
|
|
1155
|
|
1156 va_end(vp);
|
|
1157 }
|
|
1158
|
|
1159
|
|
1160 /* Called to indicate that connection was either successfully established
|
|
1161 or connecting failed. This is also the first time application receives
|
|
1162 the SilcClientConnection objecet which it should save somewhere.
|
|
1163 If the `success' is FALSE the application must always call the function
|
|
1164 silc_client_close_connection. */
|
|
1165
|
|
1166 static void
|
|
1167 silc_connected(SilcClient client, SilcClientConnection conn,
|
|
1168 SilcClientConnectionStatus status)
|
|
1169 {
|
|
1170 GaimConnection *gc = client->application;
|
|
1171 SilcGaim sg = gc->proto_data;
|
|
1172 gboolean reject_watch, block_invites, block_ims;
|
|
1173
|
|
1174 if (!gc) {
|
|
1175 sg->conn = NULL;
|
|
1176 silc_client_close_connection(client, conn);
|
|
1177 return;
|
|
1178 }
|
|
1179
|
|
1180 switch (status) {
|
|
1181 case SILC_CLIENT_CONN_SUCCESS:
|
|
1182 case SILC_CLIENT_CONN_SUCCESS_RESUME:
|
|
1183 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
|
1184 serv_finish_login(gc);
|
|
1185 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1186
|
|
1187 /* Send any UMODEs configured for account */
|
|
1188 reject_watch = gaim_account_get_bool(sg->account, "reject-watch", FALSE);
|
|
1189 block_invites = gaim_account_get_bool(sg->account, "block-invites", FALSE);
|
|
1190 block_ims = gaim_account_get_bool(sg->account, "block-ims", FALSE);
|
|
1191 if (reject_watch || block_invites || block_ims) {
|
|
1192 char m[5];
|
|
1193 g_snprintf(m, sizeof(m), "+%s%s%s",
|
|
1194 reject_watch ? "w" : "",
|
|
1195 block_invites ? "I" : "",
|
|
1196 block_ims ? "P" : "");
|
|
1197 silc_client_command_call(sg->client, sg->conn, NULL,
|
|
1198 "UMODE", m, NULL);
|
|
1199 }
|
|
1200
|
|
1201 return;
|
|
1202 break;
|
|
1203
|
|
1204 case SILC_CLIENT_CONN_ERROR:
|
|
1205 gaim_connection_error(gc, _("Error during connecting to SILC Server"));
|
|
1206 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1207 break;
|
|
1208
|
|
1209 case SILC_CLIENT_CONN_ERROR_KE:
|
|
1210 gaim_connection_error(gc, _("Key Exchange failed"));
|
|
1211 break;
|
|
1212
|
|
1213 case SILC_CLIENT_CONN_ERROR_AUTH:
|
|
1214 gaim_connection_error(gc, _("Authentication failed"));
|
|
1215 break;
|
|
1216
|
|
1217 case SILC_CLIENT_CONN_ERROR_RESUME:
|
|
1218 gaim_connection_error(gc,
|
8910
|
1219 _("Resuming detached session failed. "
|
8849
|
1220 "Press Reconnect to create new connection."));
|
|
1221 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1222 break;
|
|
1223
|
|
1224 case SILC_CLIENT_CONN_ERROR_TIMEOUT:
|
9039
|
1225 gaim_connection_error(gc, _("Connection Timeout"));
|
8849
|
1226 break;
|
|
1227 }
|
|
1228
|
|
1229 /* Error */
|
|
1230 sg->conn = NULL;
|
|
1231 silc_client_close_connection(client, conn);
|
|
1232 }
|
|
1233
|
|
1234
|
|
1235 /* Called to indicate that connection was disconnected to the server.
|
|
1236 The `status' may tell the reason of the disconnection, and if the
|
|
1237 `message' is non-NULL it may include the disconnection message
|
|
1238 received from server. */
|
|
1239
|
|
1240 static void
|
|
1241 silc_disconnected(SilcClient client, SilcClientConnection conn,
|
|
1242 SilcStatus status, const char *message)
|
|
1243 {
|
|
1244 GaimConnection *gc = client->application;
|
|
1245 SilcGaim sg = gc->proto_data;
|
|
1246
|
|
1247 if (sg->resuming && !sg->detaching)
|
|
1248 unlink(silcgaim_session_file(gaim_account_get_username(sg->account)));
|
|
1249
|
|
1250 sg->conn = NULL;
|
|
1251
|
|
1252 /* Close the connection */
|
|
1253 if (!sg->detaching)
|
|
1254 gaim_connection_error(gc, _("Disconnected by server"));
|
|
1255 else
|
|
1256 gaim_connection_destroy(gc);
|
|
1257 }
|
|
1258
|
|
1259
|
|
1260 typedef struct {
|
|
1261 SilcGetAuthMeth completion;
|
|
1262 void *context;
|
|
1263 } *SilcGaimGetAuthMethod;
|
|
1264
|
|
1265 /* Callback called when we've received the authentication method information
|
|
1266 from the server after we've requested it. */
|
|
1267
|
|
1268 static void silc_get_auth_method_callback(SilcClient client,
|
|
1269 SilcClientConnection conn,
|
|
1270 SilcAuthMethod auth_meth,
|
|
1271 void *context)
|
|
1272 {
|
|
1273 SilcGaimGetAuthMethod internal = context;
|
|
1274
|
|
1275 switch (auth_meth) {
|
|
1276 case SILC_AUTH_NONE:
|
|
1277 /* No authentication required. */
|
|
1278 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
|
|
1279 break;
|
|
1280
|
|
1281 case SILC_AUTH_PASSWORD:
|
|
1282 /* By returning NULL here the library will ask the passphrase from us
|
|
1283 by calling the silc_ask_passphrase. */
|
|
1284 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
|
|
1285 break;
|
|
1286
|
|
1287 case SILC_AUTH_PUBLIC_KEY:
|
|
1288 /* Do not get the authentication data now, the library will generate
|
|
1289 it using our default key, if we do not provide it here. */
|
|
1290 (*internal->completion)(TRUE, auth_meth, NULL, 0, internal->context);
|
|
1291 break;
|
|
1292 }
|
|
1293
|
|
1294 silc_free(internal);
|
|
1295 }
|
|
1296
|
|
1297 /* Find authentication method and authentication data by hostname and
|
|
1298 port. The hostname may be IP address as well. When the authentication
|
|
1299 method has been resolved the `completion' callback with the found
|
|
1300 authentication method and authentication data is called. The `conn'
|
|
1301 may be NULL. */
|
|
1302
|
|
1303 static void
|
|
1304 silc_get_auth_method(SilcClient client, SilcClientConnection conn,
|
|
1305 char *hostname, SilcUInt16 port,
|
|
1306 SilcGetAuthMeth completion, void *context)
|
|
1307 {
|
|
1308 GaimConnection *gc = client->application;
|
|
1309 SilcGaim sg = gc->proto_data;
|
|
1310 SilcGaimGetAuthMethod internal;
|
|
1311
|
|
1312 /* Progress */
|
|
1313 if (sg->resuming)
|
|
1314 gaim_connection_update_progress(gc, _("Resuming session"), 4, 5);
|
|
1315 else
|
|
1316 gaim_connection_update_progress(gc, _("Authenticating connection"), 4, 5);
|
|
1317
|
|
1318 /* Check configuration if we have this connection configured. If we
|
|
1319 have then return that data immediately, as it's faster way. */
|
|
1320 if (gc->account->password && *gc->account->password) {
|
|
1321 completion(TRUE, SILC_AUTH_PASSWORD, gc->account->password,
|
|
1322 strlen(gc->account->password), context);
|
|
1323 return;
|
|
1324 }
|
|
1325 if (gaim_account_get_bool(sg->account, "pubkey-auth", FALSE)) {
|
|
1326 completion(TRUE, SILC_AUTH_PUBLIC_KEY, NULL, 0, context);
|
|
1327 return;
|
|
1328 }
|
|
1329
|
|
1330 /* Resolve the authentication method from server, as we may not know it. */
|
|
1331 internal = silc_calloc(1, sizeof(*internal));
|
|
1332 if (!internal)
|
|
1333 return;
|
|
1334 internal->completion = completion;
|
|
1335 internal->context = context;
|
|
1336 silc_client_request_authentication_method(client, conn,
|
|
1337 silc_get_auth_method_callback,
|
|
1338 internal);
|
|
1339 }
|
|
1340
|
|
1341
|
|
1342 /* Verifies received public key. The `conn_type' indicates which entity
|
|
1343 (server, client etc.) has sent the public key. If user decides to trust
|
|
1344 the application may save the key as trusted public key for later
|
|
1345 use. The `completion' must be called after the public key has been
|
|
1346 verified. */
|
|
1347
|
|
1348 static void
|
|
1349 silc_verify_public_key(SilcClient client, SilcClientConnection conn,
|
|
1350 SilcSocketType conn_type, unsigned char *pk,
|
|
1351 SilcUInt32 pk_len, SilcSKEPKType pk_type,
|
|
1352 SilcVerifyPublicKey completion, void *context)
|
|
1353 {
|
|
1354 GaimConnection *gc = client->application;
|
|
1355 SilcGaim sg = gc->proto_data;
|
|
1356
|
|
1357 if (!sg->conn && (conn_type == SILC_SOCKET_TYPE_SERVER ||
|
|
1358 conn_type == SILC_SOCKET_TYPE_ROUTER)) {
|
|
1359 /* Progress */
|
|
1360 if (sg->resuming)
|
|
1361 gaim_connection_update_progress(gc, _("Resuming session"), 3, 5);
|
|
1362 else
|
|
1363 gaim_connection_update_progress(gc, _("Verifying server public key"),
|
|
1364 3, 5);
|
|
1365 }
|
|
1366
|
|
1367 /* Verify public key */
|
|
1368 silcgaim_verify_public_key(client, conn, NULL, conn_type, pk,
|
|
1369 pk_len, pk_type, completion, context);
|
|
1370 }
|
|
1371
|
|
1372 typedef struct {
|
|
1373 SilcAskPassphrase completion;
|
|
1374 void *context;
|
|
1375 } *SilcGaimAskPassphrase;
|
|
1376
|
|
1377 static void
|
|
1378 silc_ask_passphrase_cb(SilcGaimAskPassphrase internal, const char *passphrase)
|
|
1379 {
|
|
1380 if (!passphrase || !(*passphrase))
|
|
1381 internal->completion(NULL, 0, internal->context);
|
|
1382 else
|
|
1383 internal->completion((unsigned char *)passphrase,
|
|
1384 strlen(passphrase), internal->context);
|
|
1385 silc_free(internal);
|
|
1386 }
|
|
1387
|
|
1388 /* Ask (interact, that is) a passphrase from user. The passphrase is
|
|
1389 returned to the library by calling the `completion' callback with
|
|
1390 the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
|
|
1391 if not then the library will attempt to encode. */
|
|
1392
|
|
1393 static void
|
|
1394 silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
|
|
1395 SilcAskPassphrase completion, void *context)
|
|
1396 {
|
|
1397 SilcGaimAskPassphrase internal = silc_calloc(1, sizeof(*internal));
|
|
1398
|
|
1399 if (!internal)
|
|
1400 return;
|
|
1401 internal->completion = completion;
|
|
1402 internal->context = context;
|
|
1403 gaim_request_input(NULL, _("Passphrase"), NULL,
|
|
1404 _("Passphrase required"), NULL, FALSE, TRUE, NULL,
|
|
1405 _("OK"), G_CALLBACK(silc_ask_passphrase_cb),
|
|
1406 _("Cancel"), G_CALLBACK(silc_ask_passphrase_cb),
|
|
1407 internal);
|
|
1408 }
|
|
1409
|
|
1410
|
|
1411 /* Notifies application that failure packet was received. This is called
|
|
1412 if there is some protocol active in the client. The `protocol' is the
|
|
1413 protocol context. The `failure' is opaque pointer to the failure
|
|
1414 indication. Note, that the `failure' is protocol dependant and
|
|
1415 application must explicitly cast it to correct type. Usually `failure'
|
|
1416 is 32 bit failure type (see protocol specs for all protocol failure
|
|
1417 types). */
|
|
1418
|
|
1419 static void
|
|
1420 silc_failure(SilcClient client, SilcClientConnection conn,
|
|
1421 SilcProtocol protocol, void *failure)
|
|
1422 {
|
|
1423 GaimConnection *gc = client->application;
|
|
1424 char buf[128];
|
|
1425
|
|
1426 memset(buf, 0, sizeof(buf));
|
|
1427
|
|
1428 if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_KEY_EXCHANGE) {
|
|
1429 SilcSKEStatus status = (SilcSKEStatus)SILC_PTR_TO_32(failure);
|
|
1430
|
|
1431 if (status == SILC_SKE_STATUS_BAD_VERSION)
|
|
1432 g_snprintf(buf, sizeof(buf),
|
|
1433 _("Failure: Version mismatch, upgrade your client"));
|
|
1434 if (status == SILC_SKE_STATUS_UNSUPPORTED_PUBLIC_KEY)
|
|
1435 g_snprintf(buf, sizeof(buf),
|
|
1436 _("Failure: Remote does not trust/support your public key"));
|
|
1437 if (status == SILC_SKE_STATUS_UNKNOWN_GROUP)
|
|
1438 g_snprintf(buf, sizeof(buf),
|
|
1439 _("Failure: Remote does not support proposed KE group"));
|
|
1440 if (status == SILC_SKE_STATUS_UNKNOWN_CIPHER)
|
|
1441 g_snprintf(buf, sizeof(buf),
|
|
1442 _("Failure: Remote does not support proposed cipher"));
|
|
1443 if (status == SILC_SKE_STATUS_UNKNOWN_PKCS)
|
|
1444 g_snprintf(buf, sizeof(buf),
|
|
1445 _("Failure: Remote does not support proposed PKCS"));
|
|
1446 if (status == SILC_SKE_STATUS_UNKNOWN_HASH_FUNCTION)
|
|
1447 g_snprintf(buf, sizeof(buf),
|
|
1448 _("Failure: Remote does not support proposed hash function"));
|
|
1449 if (status == SILC_SKE_STATUS_UNKNOWN_HMAC)
|
|
1450 g_snprintf(buf, sizeof(buf),
|
|
1451 _("Failure: Remote does not support proposed HMAC"));
|
|
1452 if (status == SILC_SKE_STATUS_INCORRECT_SIGNATURE)
|
|
1453 g_snprintf(buf, sizeof(buf), _("Failure: Incorrect signature"));
|
|
1454 if (status == SILC_SKE_STATUS_INVALID_COOKIE)
|
|
1455 g_snprintf(buf, sizeof(buf), _("Failure: Invalid cookie"));
|
|
1456
|
|
1457 /* Show the error on the progress bar. A more generic error message
|
|
1458 is going to be showed to user after this in the silc_connected. */
|
|
1459 gaim_connection_update_progress(gc, buf, 2, 5);
|
|
1460 }
|
|
1461
|
|
1462 if (protocol->protocol->type == SILC_PROTOCOL_CLIENT_CONNECTION_AUTH) {
|
|
1463 SilcUInt32 err = SILC_PTR_TO_32(failure);
|
|
1464
|
|
1465 if (err == SILC_AUTH_FAILED)
|
|
1466 g_snprintf(buf, sizeof(buf), _("Failure: Authentication failed"));
|
|
1467
|
|
1468 /* Show the error on the progress bar. A more generic error message
|
|
1469 is going to be showed to user after this in the silc_connected. */
|
|
1470 gaim_connection_update_progress(gc, buf, 4, 5);
|
|
1471 }
|
|
1472 }
|
|
1473
|
|
1474 /* Asks whether the user would like to perform the key agreement protocol.
|
|
1475 This is called after we have received an key agreement packet or an
|
|
1476 reply to our key agreement packet. This returns TRUE if the user wants
|
|
1477 the library to perform the key agreement protocol and FALSE if it is not
|
|
1478 desired (application may start it later by calling the function
|
|
1479 silc_client_perform_key_agreement). If TRUE is returned also the
|
|
1480 `completion' and `context' arguments must be set by the application. */
|
|
1481
|
|
1482 static bool
|
|
1483 silc_key_agreement(SilcClient client, SilcClientConnection conn,
|
|
1484 SilcClientEntry client_entry, const char *hostname,
|
|
1485 SilcUInt16 port, SilcKeyAgreementCallback *completion,
|
|
1486 void **context)
|
|
1487 {
|
|
1488 silcgaim_buddy_keyagr_request(client, conn, client_entry, hostname, port);
|
|
1489 *completion = NULL;
|
|
1490 *context = NULL;
|
|
1491 return FALSE;
|
|
1492 }
|
|
1493
|
|
1494
|
|
1495 /* Notifies application that file transfer protocol session is being
|
|
1496 requested by the remote client indicated by the `client_entry' from
|
|
1497 the `hostname' and `port'. The `session_id' is the file transfer
|
|
1498 session and it can be used to either accept or reject the file
|
|
1499 transfer request, by calling the silc_client_file_receive or
|
|
1500 silc_client_file_close, respectively. */
|
|
1501
|
|
1502 static void
|
|
1503 silc_ftp(SilcClient client, SilcClientConnection conn,
|
|
1504 SilcClientEntry client_entry, SilcUInt32 session_id,
|
|
1505 const char *hostname, SilcUInt16 port)
|
|
1506 {
|
|
1507 silcgaim_ftp_request(client, conn, client_entry, session_id,
|
|
1508 hostname, port);
|
|
1509 }
|
|
1510
|
|
1511
|
|
1512 /* Delivers SILC session detachment data indicated by `detach_data' to the
|
|
1513 application. If application has issued SILC_COMMAND_DETACH command
|
|
1514 the client session in the SILC network is not quit. The client remains
|
|
1515 in the network but is detached. The detachment data may be used later
|
|
1516 to resume the session in the SILC Network. The appliation is
|
|
1517 responsible of saving the `detach_data', to for example in a file.
|
|
1518
|
|
1519 The detachment data can be given as argument to the functions
|
|
1520 silc_client_connect_to_server, or silc_client_add_connection when
|
|
1521 creating connection to remote server, inside SilcClientConnectionParams
|
|
1522 structure. If it is provided the client library will attempt to resume
|
|
1523 the session in the network. After the connection is created
|
|
1524 successfully, the application is responsible of setting the user
|
|
1525 interface for user into the same state it was before detaching (showing
|
|
1526 same channels, channel modes, etc). It can do this by fetching the
|
|
1527 information (like joined channels) from the client library. */
|
|
1528
|
|
1529 static void
|
|
1530 silc_detach(SilcClient client, SilcClientConnection conn,
|
|
1531 const unsigned char *detach_data, SilcUInt32 detach_data_len)
|
|
1532 {
|
|
1533 GaimConnection *gc = client->application;
|
|
1534 SilcGaim sg = gc->proto_data;
|
|
1535 const char *file;
|
|
1536
|
|
1537 /* Save the detachment data to file. */
|
|
1538 file = silcgaim_session_file(gaim_account_get_username(sg->account));
|
|
1539 unlink(file);
|
|
1540 silc_file_writefile(file, detach_data, detach_data_len);
|
|
1541 }
|
|
1542
|
|
1543 SilcClientOperations ops = {
|
|
1544 silc_say,
|
|
1545 silc_channel_message,
|
|
1546 silc_private_message,
|
|
1547 silc_notify,
|
|
1548 silc_command,
|
|
1549 silc_command_reply,
|
|
1550 silc_connected,
|
|
1551 silc_disconnected,
|
|
1552 silc_get_auth_method,
|
|
1553 silc_verify_public_key,
|
|
1554 silc_ask_passphrase,
|
|
1555 silc_failure,
|
|
1556 silc_key_agreement,
|
|
1557 silc_ftp,
|
|
1558 silc_detach
|
|
1559 };
|