8849
|
1 /*
|
|
2
|
|
3 silcgaim.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 extern SilcClientOperations ops;
|
|
25 static GaimPlugin *silc_plugin = NULL;
|
|
26
|
|
27 static const char *
|
|
28 silcgaim_list_icon(GaimAccount *a, GaimBuddy *b)
|
|
29 {
|
|
30 return (const char *)"silc";
|
|
31 }
|
|
32
|
|
33 static void
|
|
34 silcgaim_list_emblems(GaimBuddy *b, char **se, char **sw,
|
|
35 char **nw, char **ne)
|
|
36 {
|
|
37 }
|
|
38
|
|
39 static GList *
|
|
40 silcgaim_away_states(GaimConnection *gc)
|
|
41 {
|
|
42 GList *st = NULL;
|
|
43
|
|
44 st = g_list_append(st, _("Online"));
|
|
45 st = g_list_append(st, _("Hyper Active"));
|
|
46 st = g_list_append(st, _("Away"));
|
|
47 st = g_list_append(st, _("Busy"));
|
|
48 st = g_list_append(st, _("Indisposed"));
|
|
49 st = g_list_append(st, _("Wake Me Up"));
|
|
50
|
|
51 return st;
|
|
52 }
|
|
53
|
|
54 static void
|
|
55 silcgaim_set_away(GaimConnection *gc, const char *state, const char *msg)
|
|
56 {
|
|
57 SilcGaim sg = gc->proto_data;
|
|
58 SilcUInt32 mode;
|
|
59 SilcBuffer idp;
|
|
60 unsigned char mb[4];
|
|
61
|
|
62 if (!state)
|
|
63 return;
|
|
64 if (!sg->conn)
|
|
65 return;
|
|
66
|
|
67 mode = sg->conn->local_entry->mode;
|
|
68 mode &= ~(SILC_UMODE_GONE |
|
|
69 SILC_UMODE_HYPER |
|
|
70 SILC_UMODE_BUSY |
|
|
71 SILC_UMODE_INDISPOSED |
|
|
72 SILC_UMODE_PAGE);
|
|
73
|
|
74 if (!strcmp(state, _("Hyper Active")))
|
|
75 mode |= SILC_UMODE_HYPER;
|
|
76 else if (!strcmp(state, _("Away")))
|
|
77 mode |= SILC_UMODE_GONE;
|
|
78 else if (!strcmp(state, _("Busy")))
|
|
79 mode |= SILC_UMODE_BUSY;
|
|
80 else if (!strcmp(state, _("Indisposed")))
|
|
81 mode |= SILC_UMODE_INDISPOSED;
|
|
82 else if (!strcmp(state, _("Wake Me Up")))
|
|
83 mode |= SILC_UMODE_PAGE;
|
|
84
|
|
85 /* Send UMODE */
|
|
86 idp = silc_id_payload_encode(sg->conn->local_id, SILC_ID_CLIENT);
|
|
87 SILC_PUT32_MSB(mode, mb);
|
|
88 silc_client_command_send(sg->client, sg->conn, SILC_COMMAND_UMODE,
|
|
89 ++sg->conn->cmd_ident, 2,
|
|
90 1, idp->data, idp->len,
|
|
91 2, mb, sizeof(mb));
|
|
92 silc_buffer_free(idp);
|
|
93 }
|
|
94
|
|
95
|
|
96 /*************************** Connection Routines *****************************/
|
|
97
|
|
98 static void
|
|
99 silcgaim_keepalive(GaimConnection *gc)
|
|
100 {
|
|
101 SilcGaim sg = gc->proto_data;
|
|
102 silc_client_send_packet(sg->client, sg->conn, SILC_PACKET_HEARTBEAT,
|
|
103 NULL, 0);
|
|
104 }
|
|
105
|
|
106 static int
|
|
107 silcgaim_scheduler(gpointer *context)
|
|
108 {
|
|
109 SilcGaim sg = (SilcGaim)context;
|
|
110 silc_client_run_one(sg->client);
|
|
111 return 1;
|
|
112 }
|
|
113
|
|
114 static void
|
|
115 silcgaim_nickname_parse(const char *nickname,
|
|
116 char **ret_nickname)
|
|
117 {
|
|
118 silc_parse_userfqdn(nickname, ret_nickname, NULL);
|
|
119 }
|
|
120
|
|
121 static void
|
|
122 silcgaim_login_connected(gpointer data, gint source, GaimInputCondition cond)
|
|
123 {
|
|
124 GaimConnection *gc = data;
|
|
125 SilcGaim sg = gc->proto_data;
|
|
126 SilcClient client = sg->client;
|
|
127 SilcClientConnection conn;
|
|
128 GaimAccount *account = sg->account;
|
|
129 SilcClientConnectionParams params;
|
|
130 const char *dfile;
|
|
131
|
|
132 if (source < 0) {
|
|
133 gaim_connection_error(gc, _("Connection failed"));
|
|
134 return;
|
|
135 }
|
|
136 if (!g_list_find(gaim_connections_get_all(), gc)) {
|
|
137 close(source);
|
|
138 g_source_remove(sg->scheduler);
|
|
139 silc_client_stop(sg->client);
|
|
140 silc_client_free(sg->client);
|
|
141 silc_free(sg);
|
|
142 return;
|
|
143 }
|
|
144
|
|
145 /* Get session detachment data, if available */
|
|
146 memset(¶ms, 0, sizeof(params));
|
|
147 dfile = silcgaim_session_file(gaim_account_get_username(sg->account));
|
|
148 params.detach_data = silc_file_readfile(dfile, ¶ms.detach_data_len);
|
|
149 if (params.detach_data)
|
|
150 params.detach_data[params.detach_data_len] = 0;
|
|
151
|
|
152 /* Add connection to SILC client library */
|
|
153 conn = silc_client_add_connection(
|
|
154 sg->client, ¶ms,
|
|
155 (char *)gaim_account_get_string(account, "server",
|
|
156 "silc.silcnet.org"),
|
|
157 gaim_account_get_int(account, "port", 706), sg);
|
|
158 if (!conn) {
|
|
159 gaim_connection_error(gc, _("Cannot initialize SILC Client connection"));
|
|
160 gc->proto_data = NULL;
|
|
161 return;
|
|
162 }
|
|
163 sg->conn = conn;
|
|
164
|
|
165 /* Progress */
|
|
166 if (params.detach_data) {
|
|
167 gaim_connection_update_progress(gc, _("Resuming session"), 2, 5);
|
|
168 sg->resuming = TRUE;
|
|
169 } else {
|
|
170 gaim_connection_update_progress(gc, _("Performing key exchange"), 2, 5);
|
|
171 }
|
|
172
|
|
173 /* Perform SILC Key Exchange. The "silc_connected" will be called
|
|
174 eventually. */
|
|
175 silc_client_start_key_exchange(sg->client, sg->conn, source);
|
|
176
|
|
177 /* Set default attributes */
|
|
178 if (!gaim_account_get_bool(account, "reject-attrs", FALSE)) {
|
|
179 SilcUInt32 mask;
|
|
180 const char *tmp;
|
|
181 #ifdef HAVE_SYS_UTSNAME_H
|
|
182 struct utsname u;
|
|
183 #endif
|
|
184
|
|
185 mask = SILC_ATTRIBUTE_MOOD_NORMAL;
|
|
186 silc_client_attribute_add(client, conn,
|
|
187 SILC_ATTRIBUTE_STATUS_MOOD,
|
|
188 SILC_32_TO_PTR(mask),
|
|
189 sizeof(SilcUInt32));
|
|
190 mask = SILC_ATTRIBUTE_CONTACT_CHAT;
|
|
191 silc_client_attribute_add(client, conn,
|
|
192 SILC_ATTRIBUTE_PREFERRED_CONTACT,
|
|
193 SILC_32_TO_PTR(mask),
|
|
194 sizeof(SilcUInt32));
|
|
195 #ifdef HAVE_SYS_UTSNAME_H
|
|
196 if (!uname(&u)) {
|
|
197 SilcAttributeObjDevice dev;
|
|
198 memset(&dev, 0, sizeof(dev));
|
|
199 dev.type = SILC_ATTRIBUTE_DEVICE_COMPUTER;
|
|
200 dev.version = u.release;
|
|
201 dev.model = u.sysname;
|
|
202 silc_client_attribute_add(client, conn,
|
|
203 SILC_ATTRIBUTE_DEVICE_INFO,
|
|
204 (void *)&dev, sizeof(dev));
|
|
205 }
|
|
206 #endif
|
|
207 #ifdef _WIN32
|
|
208 tmp = _tzname[0];
|
|
209 #else
|
|
210 tmp = tzname[0];
|
|
211 #endif
|
|
212 silc_client_attribute_add(client, conn,
|
|
213 SILC_ATTRIBUTE_TIMEZONE,
|
|
214 (void *)tmp, strlen(tmp));
|
|
215 }
|
|
216
|
|
217 silc_free(params.detach_data);
|
|
218 }
|
|
219
|
|
220 static void
|
|
221 silcgaim_login(GaimAccount *account)
|
|
222 {
|
|
223 SilcGaim sg;
|
|
224 SilcClient client;
|
|
225 SilcClientParams params;
|
|
226 GaimConnection *gc;
|
|
227
|
|
228 gc = account->gc;
|
|
229 if (!gc)
|
|
230 return;
|
|
231 gc->proto_data = NULL;
|
|
232
|
|
233 memset(¶ms, 0, sizeof(params));
|
|
234 strcat(params.nickname_format, "%n@%h%a");
|
|
235 params.nickname_parse = silcgaim_nickname_parse;
|
|
236 params.ignore_requested_attributes =
|
|
237 gaim_account_get_bool(account, "reject-attrs", FALSE);
|
|
238
|
|
239 /* Allocate SILC client */
|
|
240 client = silc_client_alloc(&ops, ¶ms, gc, NULL);
|
|
241 if (!client) {
|
|
242 gaim_connection_error(gc, _("Out of memory"));
|
|
243 return;
|
|
244 }
|
|
245
|
|
246 /* Get username, real name and local hostname for SILC library */
|
|
247 if (gaim_account_get_username(account)) {
|
|
248 client->username = strdup(gaim_account_get_username(account));
|
|
249 } else {
|
|
250 client->username = silc_get_username();
|
|
251 gaim_account_set_username(account, client->username);
|
|
252 }
|
|
253 if (gaim_account_get_user_info(account)) {
|
|
254 client->realname = strdup(gaim_account_get_user_info(account));
|
|
255 } else {
|
|
256 client->realname = silc_get_real_name();
|
|
257 gaim_account_set_user_info(account, client->realname);
|
|
258 }
|
|
259 client->hostname = silc_net_localhost();
|
|
260
|
|
261 gaim_connection_set_display_name(gc, client->username);
|
|
262
|
|
263 /* Init SILC client */
|
|
264 if (!silc_client_init(client)) {
|
|
265 gaim_connection_error(gc, ("Cannot initialize SILC protocol"));
|
|
266 return;
|
|
267 }
|
|
268
|
|
269 /* Check the ~/.silc dir and create it, and new key pair if necessary. */
|
|
270 if (!silcgaim_check_silc_dir(gc)) {
|
|
271 gaim_connection_error(gc, ("Cannot find/access ~/.silc directory"));
|
|
272 return;
|
|
273 }
|
|
274
|
|
275 /* Progress */
|
|
276 gaim_connection_update_progress(gc, _("Connecting to SILC Server"), 1, 5);
|
|
277
|
|
278 /* Load SILC key pair */
|
|
279 if (!silc_load_key_pair(gaim_prefs_get_string("/plugins/prpl/silc/pubkey"),
|
|
280 gaim_prefs_get_string("/plugins/prpl/silc/privkey"),
|
9272
|
281 (account->password == NULL) ? "" : account->password, &client->pkcs,
|
|
282 &client->public_key, &client->private_key)) {
|
8849
|
283 gaim_connection_error(gc, ("Could not load SILC key pair"));
|
|
284 return;
|
|
285 }
|
|
286
|
|
287 sg = silc_calloc(1, sizeof(*sg));
|
|
288 if (!sg)
|
|
289 return;
|
|
290 memset(sg, 0, sizeof(*sg));
|
|
291 sg->client = client;
|
|
292 sg->gc = gc;
|
|
293 sg->account = account;
|
|
294 gc->proto_data = sg;
|
|
295
|
|
296 /* Connect to the SILC server */
|
|
297 if (gaim_proxy_connect(account,
|
|
298 gaim_account_get_string(account, "server",
|
|
299 "silc.silcnet.org"),
|
|
300 gaim_account_get_int(account, "port", 706),
|
|
301 silcgaim_login_connected, gc)) {
|
|
302 gaim_connection_error(gc, ("Unable to create connection"));
|
|
303 return;
|
|
304 }
|
|
305
|
|
306 /* Schedule SILC using Glib's event loop */
|
|
307 sg->scheduler = g_timeout_add(5, (GSourceFunc)silcgaim_scheduler, sg);
|
|
308 }
|
|
309
|
|
310 static int
|
|
311 silcgaim_close_final(gpointer *context)
|
|
312 {
|
|
313 SilcGaim sg = (SilcGaim)context;
|
|
314 silc_client_stop(sg->client);
|
|
315 silc_client_free(sg->client);
|
|
316 silc_free(sg);
|
|
317 return 0;
|
|
318 }
|
|
319
|
|
320 static void
|
|
321 silcgaim_close(GaimConnection *gc)
|
|
322 {
|
9272
|
323 GList *l;
|
|
324 GaimConversation *conv;
|
8849
|
325 SilcGaim sg = gc->proto_data;
|
|
326 if (!sg)
|
|
327 return;
|
|
328
|
9272
|
329 /* Close all conversations for this connection */
|
|
330 for (l = gaim_get_conversations(); l; l = l->next)
|
|
331 {
|
|
332 conv = l->data;
|
|
333 if (gc == conv->account->gc)
|
|
334 gaim_conversation_destroy(conv);
|
|
335 }
|
8849
|
336
|
|
337 /* Send QUIT */
|
|
338 silc_client_command_call(sg->client, sg->conn, NULL,
|
|
339 "QUIT", "Leaving", NULL);
|
|
340
|
|
341 if (sg->conn)
|
|
342 silc_client_close_connection(sg->client, sg->conn);
|
|
343
|
|
344 g_source_remove(sg->scheduler);
|
|
345 g_timeout_add(1, (GSourceFunc)silcgaim_close_final, sg);
|
|
346 }
|
|
347
|
|
348
|
|
349 /****************************** Protocol Actions *****************************/
|
|
350
|
|
351 static void
|
|
352 silcgaim_attrs_cancel(GaimConnection *gc, GaimRequestFields *fields)
|
|
353 {
|
|
354 /* Nothing */
|
|
355 }
|
|
356
|
|
357 static void
|
|
358 silcgaim_attrs_cb(GaimConnection *gc, GaimRequestFields *fields)
|
|
359 {
|
|
360 SilcGaim sg = gc->proto_data;
|
|
361 SilcClient client = sg->client;
|
|
362 SilcClientConnection conn = sg->conn;
|
|
363 GaimRequestField *f;
|
|
364 char *tmp;
|
|
365 SilcUInt32 tmp_len, mask;
|
|
366 SilcAttributeObjService service;
|
|
367 SilcAttributeObjDevice dev;
|
|
368 SilcVCardStruct vcard;
|
|
369 const char *val;
|
|
370
|
|
371 sg = gc->proto_data;
|
|
372 if (!sg)
|
|
373 return;
|
|
374
|
|
375 memset(&service, 0, sizeof(service));
|
|
376 memset(&dev, 0, sizeof(dev));
|
|
377 memset(&vcard, 0, sizeof(vcard));
|
|
378
|
|
379 silc_client_attribute_del(client, conn,
|
|
380 SILC_ATTRIBUTE_USER_INFO, NULL);
|
|
381 silc_client_attribute_del(client, conn,
|
|
382 SILC_ATTRIBUTE_SERVICE, NULL);
|
|
383 silc_client_attribute_del(client, conn,
|
|
384 SILC_ATTRIBUTE_STATUS_MOOD, NULL);
|
|
385 silc_client_attribute_del(client, conn,
|
|
386 SILC_ATTRIBUTE_STATUS_FREETEXT, NULL);
|
|
387 silc_client_attribute_del(client, conn,
|
|
388 SILC_ATTRIBUTE_STATUS_MESSAGE, NULL);
|
|
389 silc_client_attribute_del(client, conn,
|
|
390 SILC_ATTRIBUTE_PREFERRED_LANGUAGE, NULL);
|
|
391 silc_client_attribute_del(client, conn,
|
|
392 SILC_ATTRIBUTE_PREFERRED_CONTACT, NULL);
|
|
393 silc_client_attribute_del(client, conn,
|
|
394 SILC_ATTRIBUTE_TIMEZONE, NULL);
|
|
395 silc_client_attribute_del(client, conn,
|
|
396 SILC_ATTRIBUTE_GEOLOCATION, NULL);
|
|
397 silc_client_attribute_del(client, conn,
|
|
398 SILC_ATTRIBUTE_DEVICE_INFO, NULL);
|
|
399
|
|
400 /* Set mood */
|
|
401 mask = 0;
|
|
402 f = gaim_request_fields_get_field(fields, "mood_normal");
|
|
403 if (f && gaim_request_field_bool_get_value(f))
|
|
404 mask |= SILC_ATTRIBUTE_MOOD_NORMAL;
|
|
405 f = gaim_request_fields_get_field(fields, "mood_happy");
|
|
406 if (f && gaim_request_field_bool_get_value(f))
|
|
407 mask |= SILC_ATTRIBUTE_MOOD_HAPPY;
|
|
408 f = gaim_request_fields_get_field(fields, "mood_sad");
|
|
409 if (f && gaim_request_field_bool_get_value(f))
|
|
410 mask |= SILC_ATTRIBUTE_MOOD_SAD;
|
|
411 f = gaim_request_fields_get_field(fields, "mood_angry");
|
|
412 if (f && gaim_request_field_bool_get_value(f))
|
|
413 mask |= SILC_ATTRIBUTE_MOOD_ANGRY;
|
|
414 f = gaim_request_fields_get_field(fields, "mood_jealous");
|
|
415 if (f && gaim_request_field_bool_get_value(f))
|
|
416 mask |= SILC_ATTRIBUTE_MOOD_JEALOUS;
|
|
417 f = gaim_request_fields_get_field(fields, "mood_ashamed");
|
|
418 if (f && gaim_request_field_bool_get_value(f))
|
|
419 mask |= SILC_ATTRIBUTE_MOOD_ASHAMED;
|
|
420 f = gaim_request_fields_get_field(fields, "mood_invincible");
|
|
421 if (f && gaim_request_field_bool_get_value(f))
|
|
422 mask |= SILC_ATTRIBUTE_MOOD_INVINCIBLE;
|
|
423 f = gaim_request_fields_get_field(fields, "mood_inlove");
|
|
424 if (f && gaim_request_field_bool_get_value(f))
|
|
425 mask |= SILC_ATTRIBUTE_MOOD_INLOVE;
|
|
426 f = gaim_request_fields_get_field(fields, "mood_sleepy");
|
|
427 if (f && gaim_request_field_bool_get_value(f))
|
|
428 mask |= SILC_ATTRIBUTE_MOOD_SLEEPY;
|
|
429 f = gaim_request_fields_get_field(fields, "mood_bored");
|
|
430 if (f && gaim_request_field_bool_get_value(f))
|
|
431 mask |= SILC_ATTRIBUTE_MOOD_BORED;
|
|
432 f = gaim_request_fields_get_field(fields, "mood_excited");
|
|
433 if (f && gaim_request_field_bool_get_value(f))
|
|
434 mask |= SILC_ATTRIBUTE_MOOD_EXCITED;
|
|
435 f = gaim_request_fields_get_field(fields, "mood_anxious");
|
|
436 if (f && gaim_request_field_bool_get_value(f))
|
|
437 mask |= SILC_ATTRIBUTE_MOOD_ANXIOUS;
|
|
438 silc_client_attribute_add(client, conn,
|
|
439 SILC_ATTRIBUTE_STATUS_MOOD,
|
|
440 SILC_32_TO_PTR(mask),
|
|
441 sizeof(SilcUInt32));
|
|
442
|
|
443 /* Set preferred contact */
|
|
444 mask = 0;
|
|
445 f = gaim_request_fields_get_field(fields, "contact_chat");
|
|
446 if (f && gaim_request_field_bool_get_value(f))
|
|
447 mask |= SILC_ATTRIBUTE_CONTACT_CHAT;
|
|
448 f = gaim_request_fields_get_field(fields, "contact_email");
|
|
449 if (f && gaim_request_field_bool_get_value(f))
|
|
450 mask |= SILC_ATTRIBUTE_CONTACT_EMAIL;
|
|
451 f = gaim_request_fields_get_field(fields, "contact_call");
|
|
452 if (f && gaim_request_field_bool_get_value(f))
|
|
453 mask |= SILC_ATTRIBUTE_CONTACT_CALL;
|
|
454 f = gaim_request_fields_get_field(fields, "contact_sms");
|
|
455 if (f && gaim_request_field_bool_get_value(f))
|
|
456 mask |= SILC_ATTRIBUTE_CONTACT_SMS;
|
|
457 f = gaim_request_fields_get_field(fields, "contact_mms");
|
|
458 if (f && gaim_request_field_bool_get_value(f))
|
|
459 mask |= SILC_ATTRIBUTE_CONTACT_MMS;
|
|
460 f = gaim_request_fields_get_field(fields, "contact_video");
|
|
461 if (f && gaim_request_field_bool_get_value(f))
|
|
462 mask |= SILC_ATTRIBUTE_CONTACT_VIDEO;
|
|
463 if (mask)
|
|
464 silc_client_attribute_add(client, conn,
|
|
465 SILC_ATTRIBUTE_PREFERRED_CONTACT,
|
|
466 SILC_32_TO_PTR(mask),
|
|
467 sizeof(SilcUInt32));
|
|
468
|
|
469 /* Set status text */
|
|
470 val = NULL;
|
|
471 f = gaim_request_fields_get_field(fields, "status_text");
|
|
472 if (f)
|
|
473 val = gaim_request_field_string_get_value(f);
|
|
474 if (val && *val)
|
|
475 silc_client_attribute_add(client, conn,
|
|
476 SILC_ATTRIBUTE_STATUS_FREETEXT,
|
|
477 (void *)val, strlen(val));
|
|
478
|
|
479 /* Set vcard */
|
|
480 val = NULL;
|
|
481 f = gaim_request_fields_get_field(fields, "vcard");
|
|
482 if (f)
|
|
483 val = gaim_request_field_string_get_value(f);
|
|
484 if (val && *val) {
|
|
485 gaim_prefs_set_string("/plugins/prpl/silc/vcard", val);
|
|
486 gaim_prefs_sync();
|
|
487 tmp = silc_file_readfile(val, &tmp_len);
|
|
488 if (tmp) {
|
|
489 tmp[tmp_len] = 0;
|
|
490 if (silc_vcard_decode(tmp, tmp_len, &vcard))
|
|
491 silc_client_attribute_add(client, conn,
|
|
492 SILC_ATTRIBUTE_USER_INFO,
|
|
493 (void *)&vcard,
|
|
494 sizeof(vcard));
|
|
495 }
|
|
496 silc_vcard_free(&vcard);
|
|
497 silc_free(tmp);
|
|
498 }
|
|
499
|
|
500 #ifdef HAVE_SYS_UTSNAME_H
|
|
501 /* Set device info */
|
|
502 f = gaim_request_fields_get_field(fields, "device");
|
|
503 if (f && gaim_request_field_bool_get_value(f)) {
|
|
504 struct utsname u;
|
|
505 if (!uname(&u)) {
|
|
506 dev.type = SILC_ATTRIBUTE_DEVICE_COMPUTER;
|
|
507 dev.version = u.release;
|
|
508 dev.model = u.sysname;
|
|
509 silc_client_attribute_add(client, conn,
|
|
510 SILC_ATTRIBUTE_DEVICE_INFO,
|
|
511 (void *)&dev, sizeof(dev));
|
|
512 }
|
|
513 }
|
|
514 #endif
|
|
515
|
|
516 /* Set timezone */
|
|
517 val = NULL;
|
|
518 f = gaim_request_fields_get_field(fields, "timezone");
|
|
519 if (f)
|
|
520 val = gaim_request_field_string_get_value(f);
|
|
521 if (val && *val)
|
|
522 silc_client_attribute_add(client, conn,
|
|
523 SILC_ATTRIBUTE_TIMEZONE,
|
|
524 (void *)val, strlen(val));
|
|
525 }
|
|
526
|
|
527 static void
|
9015
|
528 silcgaim_attrs(GaimPluginAction *action)
|
8849
|
529 {
|
9015
|
530 GaimConnection *gc = (GaimConnection *) action->context;
|
8849
|
531 SilcGaim sg = gc->proto_data;
|
|
532 SilcClient client = sg->client;
|
|
533 SilcClientConnection conn = sg->conn;
|
|
534 GaimRequestFields *fields;
|
|
535 GaimRequestFieldGroup *g;
|
|
536 GaimRequestField *f;
|
|
537 SilcHashTable attrs;
|
|
538 SilcAttributePayload attr;
|
|
539 gboolean mnormal = TRUE, mhappy = FALSE, msad = FALSE,
|
|
540 mangry = FALSE, mjealous = FALSE, mashamed = FALSE,
|
|
541 minvincible = FALSE, minlove = FALSE, msleepy = FALSE,
|
|
542 mbored = FALSE, mexcited = FALSE, manxious = FALSE;
|
|
543 gboolean cemail = FALSE, ccall = FALSE, csms = FALSE,
|
|
544 cmms = FALSE, cchat = TRUE, cvideo = FALSE;
|
|
545 gboolean device = TRUE;
|
|
546 char status[1024];
|
|
547
|
|
548 sg = gc->proto_data;
|
|
549 if (!sg)
|
|
550 return;
|
|
551
|
|
552 memset(status, 0, sizeof(status));
|
|
553
|
|
554 attrs = silc_client_attributes_get(client, conn);
|
|
555 if (attrs) {
|
|
556 if (silc_hash_table_find(attrs,
|
|
557 SILC_32_TO_PTR(SILC_ATTRIBUTE_STATUS_MOOD),
|
|
558 NULL, (void *)&attr)) {
|
|
559 SilcUInt32 mood = 0;
|
|
560 silc_attribute_get_object(attr, &mood, sizeof(mood));
|
|
561 mnormal = !mood;
|
|
562 mhappy = (mood & SILC_ATTRIBUTE_MOOD_HAPPY);
|
|
563 msad = (mood & SILC_ATTRIBUTE_MOOD_SAD);
|
|
564 mangry = (mood & SILC_ATTRIBUTE_MOOD_ANGRY);
|
|
565 mjealous = (mood & SILC_ATTRIBUTE_MOOD_JEALOUS);
|
|
566 mashamed = (mood & SILC_ATTRIBUTE_MOOD_ASHAMED);
|
|
567 minvincible = (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE);
|
|
568 minlove = (mood & SILC_ATTRIBUTE_MOOD_INLOVE);
|
|
569 msleepy = (mood & SILC_ATTRIBUTE_MOOD_SLEEPY);
|
|
570 mbored = (mood & SILC_ATTRIBUTE_MOOD_BORED);
|
|
571 mexcited = (mood & SILC_ATTRIBUTE_MOOD_EXCITED);
|
|
572 manxious = (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS);
|
|
573 }
|
|
574
|
|
575 if (silc_hash_table_find(attrs,
|
|
576 SILC_32_TO_PTR(SILC_ATTRIBUTE_PREFERRED_CONTACT),
|
|
577 NULL, (void *)&attr)) {
|
|
578 SilcUInt32 contact = 0;
|
|
579 silc_attribute_get_object(attr, &contact, sizeof(contact));
|
|
580 cemail = (contact & SILC_ATTRIBUTE_CONTACT_EMAIL);
|
|
581 ccall = (contact & SILC_ATTRIBUTE_CONTACT_CALL);
|
|
582 csms = (contact & SILC_ATTRIBUTE_CONTACT_SMS);
|
|
583 cmms = (contact & SILC_ATTRIBUTE_CONTACT_MMS);
|
|
584 cchat = (contact & SILC_ATTRIBUTE_CONTACT_CHAT);
|
|
585 cvideo = (contact & SILC_ATTRIBUTE_CONTACT_VIDEO);
|
|
586 }
|
|
587
|
|
588 if (silc_hash_table_find(attrs,
|
|
589 SILC_32_TO_PTR(SILC_ATTRIBUTE_STATUS_FREETEXT),
|
|
590 NULL, (void *)&attr))
|
|
591 silc_attribute_get_object(attr, &status, sizeof(status));
|
|
592
|
|
593 if (!silc_hash_table_find(attrs,
|
|
594 SILC_32_TO_PTR(SILC_ATTRIBUTE_DEVICE_INFO),
|
|
595 NULL, (void *)&attr))
|
|
596 device = FALSE;
|
|
597 }
|
|
598
|
|
599 fields = gaim_request_fields_new();
|
|
600
|
|
601 g = gaim_request_field_group_new(NULL);
|
|
602 f = gaim_request_field_label_new("l3", _("Your Current Mood"));
|
|
603 gaim_request_field_group_add_field(g, f);
|
|
604 f = gaim_request_field_bool_new("mood_normal", _("Normal"), mnormal);
|
|
605 gaim_request_field_group_add_field(g, f);
|
|
606 f = gaim_request_field_bool_new("mood_happy", _("Happy"), mhappy);
|
|
607 gaim_request_field_group_add_field(g, f);
|
|
608 f = gaim_request_field_bool_new("mood_sad", _("Sad"), msad);
|
|
609 gaim_request_field_group_add_field(g, f);
|
|
610 f = gaim_request_field_bool_new("mood_angry", _("Angry"), mangry);
|
|
611 gaim_request_field_group_add_field(g, f);
|
|
612 f = gaim_request_field_bool_new("mood_jealous", _("Jealous"), mjealous);
|
|
613 gaim_request_field_group_add_field(g, f);
|
|
614 f = gaim_request_field_bool_new("mood_ashamed", _("Ashamed"), mashamed);
|
|
615 gaim_request_field_group_add_field(g, f);
|
|
616 f = gaim_request_field_bool_new("mood_invincible", _("Invincible"), minvincible);
|
|
617 gaim_request_field_group_add_field(g, f);
|
|
618 f = gaim_request_field_bool_new("mood_inlove", _("In Love"), minlove);
|
|
619 gaim_request_field_group_add_field(g, f);
|
|
620 f = gaim_request_field_bool_new("mood_sleepy", _("Sleepy"), msleepy);
|
|
621 gaim_request_field_group_add_field(g, f);
|
|
622 f = gaim_request_field_bool_new("mood_bored", _("Bored"), mbored);
|
|
623 gaim_request_field_group_add_field(g, f);
|
|
624 f = gaim_request_field_bool_new("mood_excited", _("Excited"), mexcited);
|
|
625 gaim_request_field_group_add_field(g, f);
|
|
626 f = gaim_request_field_bool_new("mood_anxious", _("Anxious"), manxious);
|
|
627 gaim_request_field_group_add_field(g, f);
|
|
628
|
|
629 f = gaim_request_field_label_new("l4", _("\nYour Preferred Contact Methods"));
|
|
630 gaim_request_field_group_add_field(g, f);
|
|
631 f = gaim_request_field_bool_new("contact_chat", _("Chat"), cchat);
|
|
632 gaim_request_field_group_add_field(g, f);
|
|
633 f = gaim_request_field_bool_new("contact_email", _("Email"), cemail);
|
|
634 gaim_request_field_group_add_field(g, f);
|
|
635 f = gaim_request_field_bool_new("contact_call", _("Phone"), ccall);
|
|
636 gaim_request_field_group_add_field(g, f);
|
|
637 f = gaim_request_field_bool_new("contact_sms", _("SMS"), csms);
|
|
638 gaim_request_field_group_add_field(g, f);
|
|
639 f = gaim_request_field_bool_new("contact_mms", _("MMS"), cmms);
|
|
640 gaim_request_field_group_add_field(g, f);
|
|
641 f = gaim_request_field_bool_new("contact_video", _("Video Conferencing"), cvideo);
|
|
642 gaim_request_field_group_add_field(g, f);
|
|
643 gaim_request_fields_add_group(fields, g);
|
|
644
|
|
645 g = gaim_request_field_group_new(NULL);
|
|
646 f = gaim_request_field_string_new("status_text", _("Your Current Status"),
|
|
647 status[0] ? status : NULL, TRUE);
|
|
648 gaim_request_field_group_add_field(g, f);
|
|
649 gaim_request_fields_add_group(fields, g);
|
|
650
|
|
651 g = gaim_request_field_group_new(NULL);
|
|
652 #if 0
|
|
653 f = gaim_request_field_label_new("l2", _("Online Services"));
|
|
654 gaim_request_field_group_add_field(g, f);
|
|
655 f = gaim_request_field_bool_new("services",
|
|
656 _("Let others see what services you are using"),
|
|
657 TRUE);
|
|
658 gaim_request_field_group_add_field(g, f);
|
|
659 #endif
|
|
660 #ifdef HAVE_SYS_UTSNAME_H
|
|
661 f = gaim_request_field_bool_new("device",
|
|
662 _("Let others see what computer you are using"),
|
|
663 device);
|
|
664 gaim_request_field_group_add_field(g, f);
|
|
665 #endif
|
|
666 gaim_request_fields_add_group(fields, g);
|
|
667
|
|
668 g = gaim_request_field_group_new(NULL);
|
|
669 f = gaim_request_field_string_new("vcard", _("Your VCard File"),
|
|
670 gaim_prefs_get_string("/plugins/prpl/silc/vcard"),
|
|
671 FALSE);
|
|
672 gaim_request_field_group_add_field(g, f);
|
|
673 #ifdef _WIN32
|
|
674 f = gaim_request_field_string_new("timezone", _("Timezone"), _tzname[0], FALSE);
|
|
675 #else
|
|
676 f = gaim_request_field_string_new("timezone", _("Timezone"), tzname[0], FALSE);
|
|
677 #endif
|
|
678 gaim_request_field_group_add_field(g, f);
|
|
679 gaim_request_fields_add_group(fields, g);
|
|
680
|
|
681
|
|
682 gaim_request_fields(NULL, _("User Online Status Attributes"),
|
|
683 _("User Online Status Attributes"),
|
|
684 _("You can let other users see your online status information "
|
|
685 "and your personal information. Please fill the information "
|
|
686 "you would like other users to see about yourself."),
|
|
687 fields,
|
8906
|
688 _("OK"), G_CALLBACK(silcgaim_attrs_cb),
|
|
689 _("Cancel"), G_CALLBACK(silcgaim_attrs_cancel), gc);
|
8849
|
690 }
|
|
691
|
|
692 static void
|
9015
|
693 silcgaim_detach(GaimPluginAction *action)
|
8849
|
694 {
|
9015
|
695 GaimConnection *gc = (GaimConnection *) action->context;
|
8849
|
696 SilcGaim sg;
|
|
697
|
|
698 if (!gc)
|
|
699 return;
|
|
700 sg = gc->proto_data;
|
|
701 if (!sg)
|
|
702 return;
|
|
703
|
|
704 /* Call DETACH */
|
|
705 silc_client_command_call(sg->client, sg->conn, "DETACH");
|
|
706 sg->detaching = TRUE;
|
|
707 }
|
|
708
|
|
709 static void
|
9015
|
710 silcgaim_view_motd(GaimPluginAction *action)
|
8849
|
711 {
|
9015
|
712 GaimConnection *gc = (GaimConnection *) action->context;
|
8849
|
713 SilcGaim sg;
|
|
714
|
|
715 if (!gc)
|
|
716 return;
|
|
717 sg = gc->proto_data;
|
|
718 if (!sg)
|
|
719 return;
|
|
720
|
|
721 if (!sg->motd) {
|
|
722 gaim_notify_error(
|
|
723 gc, _("Message of the Day"), _("No Message of the Day available"),
|
|
724 _("There is no Message of the Day associated with this connection"));
|
|
725 return;
|
|
726 }
|
|
727
|
9039
|
728 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL,
|
8849
|
729 sg->motd, NULL, NULL);
|
|
730 }
|
|
731
|
9272
|
732 static void
|
|
733 silcgaim_change_pass(GaimPluginAction *action)
|
|
734 {
|
|
735 GaimConnection *gc = (GaimConnection *) action->context;
|
|
736 gaim_account_request_change_password(gaim_connection_get_account(gc));
|
|
737 }
|
|
738
|
|
739 static void
|
|
740 silcgaim_change_passwd(GaimConnection *gc, const char *old, const char *new)
|
|
741 {
|
|
742 silc_change_private_key_passphrase(gaim_prefs_get_string("/plugins/prpl/silc/privkey"), old, new);
|
|
743 }
|
|
744
|
|
745 static void
|
|
746 silcgaim_show_set_info(GaimPluginAction *action)
|
|
747 {
|
|
748 GaimConnection *gc = (GaimConnection *) action->context;
|
|
749 gaim_account_request_change_user_info(gaim_connection_get_account(gc));
|
|
750 }
|
|
751
|
|
752 static void
|
|
753 silcgaim_set_info(GaimConnection *gc, const char *text)
|
|
754 {
|
|
755 }
|
|
756
|
8849
|
757 static GList *
|
9015
|
758 silcgaim_actions(GaimPlugin *plugin, gpointer context)
|
8849
|
759 {
|
9024
|
760 GaimConnection *gc = context;
|
8849
|
761 GList *list = NULL;
|
9015
|
762 GaimPluginAction *act;
|
8849
|
763
|
|
764 if (!gaim_account_get_bool(gc->account, "reject-attrs", FALSE)) {
|
9015
|
765 act = gaim_plugin_action_new(_("Online Status"),
|
|
766 silcgaim_attrs);
|
|
767 list = g_list_append(list, act);
|
8849
|
768 }
|
|
769
|
9015
|
770 act = gaim_plugin_action_new(_("Detach From Server"),
|
|
771 silcgaim_detach);
|
|
772 list = g_list_append(list, act);
|
8849
|
773
|
9015
|
774 act = gaim_plugin_action_new(_("View Message of the Day"),
|
|
775 silcgaim_view_motd);
|
|
776 list = g_list_append(list, act);
|
8849
|
777
|
9272
|
778 act = gaim_plugin_action_new(_("Change Password..."),
|
|
779 silcgaim_change_pass);
|
|
780 list = g_list_append(list, act);
|
|
781
|
|
782 act = gaim_plugin_action_new(_("Set User Info..."),
|
|
783 silcgaim_show_set_info);
|
|
784 list = g_list_append(list, act);
|
|
785
|
8849
|
786 return list;
|
|
787 }
|
|
788
|
|
789
|
|
790 /******************************* IM Routines *********************************/
|
|
791
|
|
792 typedef struct {
|
|
793 char *nick;
|
|
794 unsigned char *message;
|
|
795 SilcUInt32 message_len;
|
|
796 SilcMessageFlags flags;
|
|
797 } *SilcGaimIM;
|
|
798
|
|
799 static void
|
|
800 silcgaim_send_im_resolved(SilcClient client,
|
|
801 SilcClientConnection conn,
|
|
802 SilcClientEntry *clients,
|
|
803 SilcUInt32 clients_count,
|
|
804 void *context)
|
|
805 {
|
|
806 GaimConnection *gc = client->application;
|
|
807 SilcGaim sg = gc->proto_data;
|
|
808 SilcGaimIM im = context;
|
|
809 GaimConversation *convo;
|
|
810 char tmp[256], *nickname = NULL;
|
|
811 SilcClientEntry client_entry;
|
|
812
|
|
813 convo = gaim_find_conversation_with_account(im->nick, sg->account);
|
|
814 if (!convo)
|
|
815 return;
|
|
816
|
|
817 if (!clients)
|
|
818 goto err;
|
|
819
|
|
820 if (clients_count > 1) {
|
|
821 silc_parse_userfqdn(im->nick, &nickname, NULL);
|
|
822
|
|
823 /* Find the correct one. The im->nick might be a formatted nick
|
|
824 so this will find the correct one. */
|
|
825 clients = silc_client_get_clients_local(client, conn,
|
|
826 nickname, im->nick,
|
|
827 &clients_count);
|
|
828 if (!clients)
|
|
829 goto err;
|
|
830 client_entry = clients[0];
|
|
831 silc_free(clients);
|
|
832 } else {
|
|
833 client_entry = clients[0];
|
|
834 }
|
|
835
|
|
836 /* Send the message */
|
|
837 silc_client_send_private_message(client, conn, client_entry, im->flags,
|
|
838 im->message, im->message_len, TRUE);
|
|
839 gaim_conv_im_write(GAIM_CONV_IM(convo), conn->local_entry->nickname,
|
|
840 im->message, 0, time(NULL));
|
|
841
|
|
842 goto out;
|
|
843
|
|
844 err:
|
|
845 g_snprintf(tmp, sizeof(tmp),
|
|
846 _("User <I>%s</I> is not present in the network"), im->nick);
|
|
847 gaim_conversation_write(convo, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
848
|
|
849 out:
|
|
850 g_free(im->nick);
|
|
851 g_free(im->message);
|
|
852 silc_free(im);
|
|
853 silc_free(nickname);
|
|
854 }
|
|
855
|
|
856 static int
|
|
857 silcgaim_send_im(GaimConnection *gc, const char *who, const char *msg,
|
|
858 GaimConvImFlags flags)
|
|
859 {
|
|
860 SilcGaim sg = gc->proto_data;
|
|
861 SilcClient client = sg->client;
|
|
862 SilcClientConnection conn = sg->conn;
|
|
863 SilcClientEntry *clients;
|
|
864 SilcUInt32 clients_count, mflags;
|
|
865 char *nickname;
|
|
866 int ret;
|
|
867 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_im");
|
|
868
|
|
869 if (!who || !msg)
|
|
870 return 0;
|
|
871
|
|
872 /* See if command */
|
|
873 if (strlen(msg) > 1 && msg[0] == '/') {
|
|
874 if (!silc_client_command_call(client, conn, msg + 1))
|
|
875 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"),
|
|
876 _("Unknown command"));
|
|
877 return 0;
|
|
878 }
|
|
879
|
|
880 if (!silc_parse_userfqdn(who, &nickname, NULL))
|
|
881 return 0;
|
|
882
|
|
883 mflags = SILC_MESSAGE_FLAG_UTF8;
|
|
884 if (sign)
|
|
885 mflags |= SILC_MESSAGE_FLAG_SIGNED;
|
|
886
|
|
887 /* Find client entry */
|
|
888 clients = silc_client_get_clients_local(client, conn, nickname, who,
|
|
889 &clients_count);
|
|
890 if (!clients) {
|
|
891 /* Resolve unknown user */
|
|
892 SilcGaimIM im = silc_calloc(1, sizeof(*im));
|
|
893 if (!im)
|
|
894 return 0;
|
|
895 im->nick = g_strdup(who);
|
|
896 im->message = g_strdup(msg);
|
|
897 im->message_len = strlen(im->message);
|
|
898 im->flags = mflags;
|
|
899 silc_client_get_clients(client, conn, nickname, NULL,
|
|
900 silcgaim_send_im_resolved, im);
|
|
901 silc_free(nickname);
|
|
902 return 0;
|
|
903 }
|
|
904
|
|
905 /* Send private message directly */
|
|
906 ret = silc_client_send_private_message(client, conn, clients[0],
|
|
907 mflags, (char *)msg,
|
|
908 strlen(msg), TRUE);
|
|
909
|
|
910 silc_free(nickname);
|
|
911 silc_free(clients);
|
|
912 return ret;
|
|
913 }
|
|
914
|
|
915
|
9030
|
916 GList *silcgaim_blist_node_menu(GaimBlistNode *node) {
|
|
917 /* split this single menu building function back into the two
|
|
918 original: one for buddies and one for chats */
|
|
919
|
|
920 if(GAIM_BLIST_NODE_IS_CHAT(node)) {
|
9038
|
921 return silcgaim_chat_menu((GaimChat *) node);
|
9030
|
922 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
|
|
923 return silcgaim_buddy_menu((GaimBuddy *) node);
|
|
924 } else {
|
9038
|
925 g_return_val_if_reached(NULL);
|
9030
|
926 }
|
|
927 }
|
|
928
|
9272
|
929 /********************************* Commands **********************************/
|
|
930
|
|
931 static GaimCmdRet silcgaim_cmd_chat_part(GaimConversation *conv,
|
|
932 const char *cmd, char **args, char **error)
|
|
933 {
|
|
934 GaimConnection *gc;
|
|
935 int id = 0;
|
|
936
|
|
937 gc = gaim_conversation_get_gc(conv);
|
|
938 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
|
|
939
|
|
940 if (gc == NULL || id == 0)
|
|
941 return GAIM_CMD_RET_FAILED;
|
|
942
|
|
943 silcgaim_chat_leave(gc, id);
|
|
944
|
|
945 return GAIM_CMD_RET_OK;
|
|
946
|
|
947 }
|
|
948
|
|
949 static GaimCmdRet silcgaim_cmd_chat_topic(GaimConversation *conv,
|
|
950 const char *cmd, char **args, char **error)
|
|
951 {
|
|
952 GaimConnection *gc;
|
|
953 int id = 0;
|
|
954
|
|
955 gc = gaim_conversation_get_gc(conv);
|
|
956 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
|
|
957
|
|
958 if (gc == NULL || id == 0)
|
|
959 return GAIM_CMD_RET_FAILED;
|
|
960
|
|
961 silcgaim_chat_set_topic(gc, id, args ? args[0] : NULL);
|
|
962
|
|
963 return GAIM_CMD_RET_OK;
|
|
964 }
|
|
965
|
|
966 static GaimCmdRet silcgaim_cmd_chat_join(GaimConversation *conv,
|
|
967 const char *cmd, char **args, char **error)
|
|
968 {
|
|
969 GHashTable *comp;
|
|
970
|
|
971 if(!args || !args[0])
|
|
972 return GAIM_CMD_RET_FAILED;
|
|
973
|
|
974 comp = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
975
|
|
976 g_hash_table_replace(comp, "channel", args[0]);
|
|
977 if(args[1])
|
|
978 g_hash_table_replace(comp, "passphrase", args[1]);
|
|
979
|
|
980 silcgaim_chat_join(gaim_conversation_get_gc(conv), comp);
|
|
981
|
|
982 g_hash_table_destroy(comp);
|
|
983 return GAIM_CMD_RET_OK;
|
|
984 }
|
|
985
|
|
986 static GaimCmdRet silcgaim_cmd_chat_list(GaimConversation *conv,
|
|
987 const char *cmd, char **args, char **error)
|
|
988 {
|
|
989 GaimConnection *gc;
|
|
990 gc = gaim_conversation_get_gc(conv);
|
|
991 gaim_roomlist_show_with_account(gaim_connection_get_account(gc));
|
|
992 return GAIM_CMD_RET_OK;
|
|
993 }
|
|
994
|
|
995 static GaimCmdRet silcgaim_cmd_whois(GaimConversation *conv,
|
|
996 const char *cmd, char **args, char **error)
|
|
997 {
|
|
998 GaimConnection *gc;
|
|
999
|
|
1000 gc = gaim_conversation_get_gc(conv);
|
|
1001
|
|
1002 if (gc == NULL)
|
|
1003 return GAIM_CMD_RET_FAILED;
|
|
1004
|
|
1005 silcgaim_get_info(gc, args[0]);
|
|
1006
|
|
1007 return GAIM_CMD_RET_OK;
|
|
1008 }
|
|
1009
|
|
1010 static GaimCmdRet silcgaim_cmd_chat_invite(GaimConversation *conv,
|
|
1011 const char *cmd, char **args, char **error)
|
|
1012 {
|
|
1013 int id;
|
|
1014 GaimConnection *gc;
|
|
1015
|
|
1016 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
|
|
1017 gc = gaim_conversation_get_gc(conv);
|
|
1018
|
|
1019 if (gc == NULL)
|
|
1020 return GAIM_CMD_RET_FAILED;
|
|
1021
|
|
1022 silcgaim_chat_invite(gc, id, NULL, args[0]);
|
|
1023
|
|
1024 return GAIM_CMD_RET_OK;
|
|
1025 }
|
|
1026
|
|
1027 static GaimCmdRet silcgaim_cmd_msg(GaimConversation *conv,
|
|
1028 const char *cmd, char **args, char **error)
|
|
1029 {
|
|
1030 int ret;
|
|
1031 GaimConnection *gc;
|
|
1032
|
|
1033 gc = gaim_conversation_get_gc(conv);
|
|
1034
|
|
1035 if (gc == NULL)
|
|
1036 return GAIM_CMD_RET_FAILED;
|
|
1037
|
|
1038 ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND);
|
|
1039
|
|
1040 if (ret)
|
|
1041 return GAIM_CMD_RET_OK;
|
|
1042 else
|
|
1043 return GAIM_CMD_RET_FAILED;
|
|
1044 }
|
|
1045
|
|
1046 static GaimCmdRet silcgaim_cmd_query(GaimConversation *conv,
|
|
1047 const char *cmd, char **args, char **error)
|
|
1048 {
|
|
1049 int ret = 1;
|
|
1050 GaimConversation *convo;
|
|
1051 GaimConnection *gc;
|
|
1052 GaimAccount *account;
|
|
1053
|
|
1054 if (!args || !args[0])
|
|
1055 return GAIM_CMD_RET_FAILED;
|
|
1056
|
|
1057 gc = gaim_conversation_get_gc(conv);
|
|
1058
|
|
1059 if (gc == NULL)
|
|
1060 return GAIM_CMD_RET_FAILED;
|
|
1061
|
|
1062 account = gaim_connection_get_account(gc);
|
|
1063
|
|
1064 convo = gaim_conversation_new(GAIM_CONV_IM, account, args[0]);
|
|
1065
|
|
1066 if (args[1]) {
|
|
1067 ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND);
|
|
1068 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc),
|
|
1069 args[1], GAIM_MESSAGE_SEND, time(NULL));
|
|
1070 }
|
|
1071
|
|
1072 if (ret)
|
|
1073 return GAIM_CMD_RET_OK;
|
|
1074 else
|
|
1075 return GAIM_CMD_RET_FAILED;
|
|
1076 }
|
|
1077
|
|
1078 static GaimCmdRet silcgaim_cmd_motd(GaimConversation *conv,
|
|
1079 const char *cmd, char **args, char **error)
|
|
1080 {
|
|
1081 GaimConnection *gc;
|
|
1082 SilcGaim sg;
|
|
1083
|
|
1084 gc = gaim_conversation_get_gc(conv);
|
|
1085
|
|
1086 if (gc == NULL)
|
|
1087 return GAIM_CMD_RET_FAILED;
|
|
1088
|
|
1089 sg = gc->proto_data;
|
|
1090
|
|
1091 if (sg == NULL)
|
|
1092 return GAIM_CMD_RET_FAILED;
|
|
1093
|
|
1094 if (!sg->motd) {
|
|
1095 gaim_notify_error(
|
|
1096 gc, _("Message of the Day"), _("No Message of the Day available"),
|
|
1097 _("There is no Message of the Day associated with this connection"));
|
|
1098 return GAIM_CMD_RET_FAILED;
|
|
1099 }
|
|
1100
|
|
1101 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL,
|
|
1102 sg->motd, NULL, NULL);
|
|
1103
|
|
1104 return GAIM_CMD_RET_OK;
|
|
1105 }
|
|
1106
|
|
1107 static GaimCmdRet silcgaim_cmd_detach(GaimConversation *conv,
|
|
1108 const char *cmd, char **args, char **error)
|
|
1109 {
|
|
1110 GaimConnection *gc;
|
|
1111 SilcGaim sg;
|
|
1112
|
|
1113 gc = gaim_conversation_get_gc(conv);
|
|
1114
|
|
1115 if (gc == NULL)
|
|
1116 return GAIM_CMD_RET_FAILED;
|
|
1117
|
|
1118 sg = gc->proto_data;
|
|
1119
|
|
1120 if (sg == NULL)
|
|
1121 return GAIM_CMD_RET_FAILED;
|
|
1122
|
|
1123 silc_client_command_call(sg->client, sg->conn, "DETACH");
|
|
1124 sg->detaching = TRUE;
|
|
1125
|
|
1126 return GAIM_CMD_RET_OK;
|
|
1127 }
|
|
1128
|
|
1129 static GaimCmdRet silcgaim_cmd_umode(GaimConversation *conv,
|
|
1130 const char *cmd, char **args, char **error)
|
|
1131 {
|
|
1132 GaimConnection *gc;
|
|
1133 SilcGaim sg;
|
|
1134
|
|
1135 gc = gaim_conversation_get_gc(conv);
|
|
1136
|
|
1137 if (gc == NULL)
|
|
1138 return GAIM_CMD_RET_FAILED;
|
|
1139
|
|
1140 sg = gc->proto_data;
|
|
1141
|
|
1142 if (sg == NULL)
|
|
1143 return GAIM_CMD_RET_FAILED;
|
|
1144
|
|
1145 silc_client_command_call(sg->client, sg->conn, NULL, "UMODE",
|
|
1146 args[0], NULL);
|
|
1147
|
|
1148 return GAIM_CMD_RET_OK;
|
|
1149 }
|
|
1150
|
9030
|
1151
|
8849
|
1152 /************************** Plugin Initialization ****************************/
|
|
1153
|
9272
|
1154 static void
|
|
1155 silcgaim_register_commands(void)
|
|
1156 {
|
|
1157 gaim_cmd_register("part", "", GAIM_CMD_P_PRPL,
|
|
1158 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1159 "prpl-silc", silcgaim_cmd_chat_part, _("part: Leave the chat"));
|
|
1160 gaim_cmd_register("leave", "", GAIM_CMD_P_PRPL,
|
|
1161 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1162 "prpl-silc", silcgaim_cmd_chat_part, _("leave: Leave the chat"));
|
|
1163 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL,
|
|
1164 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1165 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc",
|
|
1166 silcgaim_cmd_chat_topic, _("topic [<new topic>]: View or change the topic"));
|
|
1167 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL,
|
|
1168 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT |
|
|
1169 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS,
|
|
1170 "prpl-silc", silcgaim_cmd_chat_join,
|
|
1171 _("join <channel> [<password>]: Join a chat on this network"));
|
|
1172 gaim_cmd_register("list", "", GAIM_CMD_P_PRPL,
|
|
1173 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1174 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc",
|
|
1175 silcgaim_cmd_chat_list, _("list: List channels on this network"));
|
|
1176 gaim_cmd_register("whois", "w", GAIM_CMD_P_PRPL,
|
|
1177 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1178 "prpl-silc",
|
|
1179 silcgaim_cmd_whois, _("whois <nick>: View nick's informationc"));
|
|
1180 gaim_cmd_register("invite", "w", GAIM_CMD_P_PRPL,
|
|
1181 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1182 "prpl-silc", silcgaim_cmd_chat_invite,
|
|
1183 _("invite <nick>: Invite nick to join this channel"));
|
|
1184 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL,
|
|
1185 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1186 "prpl-silc", silcgaim_cmd_msg,
|
|
1187 _("msg <nick> <message>: Send a private message to a user"));
|
|
1188 gaim_cmd_register("query", "ws", GAIM_CMD_P_PRPL,
|
|
1189 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1190 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_query,
|
|
1191 _("query <nick> [<message>]: Send a private message to a user"));
|
|
1192 gaim_cmd_register("motd", "", GAIM_CMD_P_PRPL,
|
|
1193 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1194 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_motd,
|
|
1195 _("motd: View the server's Message Of The Day"));
|
|
1196 gaim_cmd_register("detach", "", GAIM_CMD_P_PRPL,
|
|
1197 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
|
|
1198 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_detach,
|
|
1199 _("detach: Detach this session"));
|
|
1200 gaim_cmd_register("umode", "w", GAIM_CMD_P_PRPL,
|
|
1201 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
|
|
1202 "prpl-silc", silcgaim_cmd_umode,
|
|
1203 _("umode <usermodes>: Set your user options"));
|
|
1204 }
|
|
1205
|
8849
|
1206 static GaimPluginPrefFrame *
|
|
1207 silcgaim_pref_frame(GaimPlugin *plugin)
|
|
1208 {
|
|
1209 GaimPluginPrefFrame *frame;
|
|
1210 GaimPluginPref *ppref;
|
|
1211
|
|
1212 frame = gaim_plugin_pref_frame_new();
|
|
1213
|
|
1214 ppref = gaim_plugin_pref_new_with_label(_("Instant Messages"));
|
|
1215 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1216
|
|
1217 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
1218 "/plugins/prpl/silc/sign_im",
|
|
1219 _("Digitally sign all IM messages"));
|
|
1220 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1221
|
|
1222 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
1223 "/plugins/prpl/silc/verify_im",
|
|
1224 _("Verify all IM message signatures"));
|
|
1225 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1226
|
|
1227 ppref = gaim_plugin_pref_new_with_label(_("Channel Messages"));
|
|
1228 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1229
|
|
1230 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
1231 "/plugins/prpl/silc/sign_chat",
|
|
1232 _("Digitally sign all channel messages"));
|
|
1233 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1234
|
|
1235 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
1236 "/plugins/prpl/silc/verify_chat",
|
|
1237 _("Verify all channel message signatures"));
|
|
1238 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1239
|
|
1240 ppref = gaim_plugin_pref_new_with_label(_("Default SILC Key Pair"));
|
|
1241 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1242
|
|
1243 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
1244 "/plugins/prpl/silc/pubkey",
|
|
1245 _("SILC Public Key"));
|
|
1246 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1247
|
|
1248 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
1249 "/plugins/prpl/silc/privkey",
|
|
1250 _("SILC Private Key"));
|
|
1251 gaim_plugin_pref_frame_add(frame, ppref);
|
|
1252
|
|
1253 return frame;
|
|
1254 }
|
|
1255
|
|
1256 static GaimPluginUiInfo prefs_info =
|
|
1257 {
|
|
1258 silcgaim_pref_frame,
|
|
1259 };
|
|
1260
|
|
1261 static GaimPluginProtocolInfo prpl_info =
|
|
1262 {
|
|
1263 GAIM_PRPL_API_VERSION,
|
|
1264 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
|
|
1265 OPT_PROTO_PASSWORD_OPTIONAL,
|
|
1266 NULL,
|
|
1267 NULL,
|
|
1268 silcgaim_list_icon,
|
|
1269 silcgaim_list_emblems,
|
|
1270 silcgaim_status_text,
|
|
1271 silcgaim_tooltip_text,
|
|
1272 silcgaim_away_states,
|
9030
|
1273 silcgaim_blist_node_menu,
|
8849
|
1274 silcgaim_chat_info,
|
|
1275 silcgaim_login,
|
|
1276 silcgaim_close,
|
|
1277 silcgaim_send_im,
|
9272
|
1278 silcgaim_set_info,
|
8849
|
1279 NULL,
|
|
1280 silcgaim_get_info,
|
|
1281 silcgaim_set_away,
|
|
1282 silcgaim_idle_set,
|
9272
|
1283 silcgaim_change_passwd,
|
8849
|
1284 silcgaim_add_buddy,
|
|
1285 silcgaim_add_buddies,
|
|
1286 silcgaim_remove_buddy,
|
|
1287 NULL,
|
|
1288 NULL,
|
|
1289 NULL,
|
|
1290 NULL,
|
|
1291 NULL,
|
|
1292 NULL,
|
|
1293 NULL,
|
|
1294 silcgaim_chat_join,
|
|
1295 NULL,
|
|
1296 silcgaim_chat_invite,
|
|
1297 silcgaim_chat_leave,
|
|
1298 NULL,
|
|
1299 silcgaim_chat_send,
|
|
1300 silcgaim_keepalive,
|
|
1301 NULL,
|
|
1302 NULL,
|
|
1303 NULL,
|
|
1304 NULL,
|
|
1305 NULL,
|
|
1306 NULL,
|
|
1307 NULL,
|
|
1308 NULL,
|
|
1309 NULL,
|
|
1310 NULL,
|
|
1311 NULL,
|
|
1312 NULL,
|
|
1313 silcgaim_chat_set_topic,
|
|
1314 NULL,
|
|
1315 silcgaim_roomlist_get_list,
|
|
1316 silcgaim_roomlist_cancel,
|
9030
|
1317 NULL
|
8849
|
1318 };
|
|
1319
|
|
1320 static GaimPluginInfo info =
|
|
1321 {
|
|
1322 GAIM_PLUGIN_API_VERSION, /**< api_version */
|
|
1323 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
1324 NULL, /**< ui_requirement */
|
|
1325 0, /**< flags */
|
|
1326 NULL, /**< dependencies */
|
|
1327 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
1328
|
|
1329 "prpl-silc", /**< id */
|
|
1330 "SILC", /**< name */
|
|
1331 "1.0", /**< version */
|
|
1332 /** summary */
|
|
1333 N_("SILC Protocol Plugin"),
|
|
1334 /** description */
|
|
1335 N_("Secure Internet Live Conferencing (SILC) Protocol"),
|
8891
|
1336 "Pekka Riikonen", /**< author */
|
|
1337 "http://silcnet.org/", /**< homepage */
|
8849
|
1338
|
|
1339 NULL, /**< load */
|
|
1340 NULL, /**< unload */
|
|
1341 NULL, /**< destroy */
|
|
1342
|
|
1343 NULL, /**< ui_info */
|
|
1344 &prpl_info, /**< extra_info */
|
8993
|
1345 &prefs_info, /**< prefs_info */
|
9015
|
1346 silcgaim_actions
|
8849
|
1347 };
|
|
1348
|
|
1349 static void
|
|
1350 init_plugin(GaimPlugin *plugin)
|
|
1351 {
|
|
1352 GaimAccountOption *option;
|
|
1353 char tmp[256];
|
|
1354
|
|
1355 silc_plugin = plugin;
|
|
1356
|
|
1357 /* Account options */
|
|
1358 option = gaim_account_option_string_new(_("Connect server"),
|
|
1359 "server",
|
|
1360 "silc.silcnet.org");
|
|
1361 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1362 option = gaim_account_option_int_new(_("Port"), "port", 706);
|
|
1363 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1364
|
|
1365 option = gaim_account_option_bool_new(_("Public key authentication"),
|
|
1366 "pubkey-auth", FALSE);
|
|
1367 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1368 #if 0 /* XXX Public key auth interface with explicit key pair is
|
|
1369 broken in SILC Toolkit */
|
8891
|
1370 g_snprintf(tmp, sizeof(tmp), "%s/public_key.pub", silcgaim_silcdir());
|
8849
|
1371 option = gaim_account_option_string_new(_("Public Key File"),
|
|
1372 "public-key", tmp);
|
|
1373 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
8891
|
1374 g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir());
|
8849
|
1375 option = gaim_account_option_string_new(_("Private Key File"),
|
|
1376 "public-key", tmp);
|
|
1377 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1378 #endif
|
|
1379
|
|
1380 option = gaim_account_option_bool_new(_("Reject watching by other users"),
|
|
1381 "reject-watch", FALSE);
|
|
1382 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1383 option = gaim_account_option_bool_new(_("Block invites"),
|
|
1384 "block-invites", FALSE);
|
|
1385 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1386 option = gaim_account_option_bool_new(_("Block IMs without Key Exchange"),
|
|
1387 "block-ims", FALSE);
|
|
1388 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1389 option = gaim_account_option_bool_new(_("Reject online status attribute requests"),
|
|
1390 "reject-attrs", FALSE);
|
|
1391 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
1392
|
|
1393 /* Preferences */
|
|
1394 gaim_prefs_add_none("/plugins/prpl/silc");
|
|
1395 gaim_prefs_add_bool("/plugins/prpl/silc/sign_im", FALSE);
|
|
1396 gaim_prefs_add_bool("/plugins/prpl/silc/verify_im", FALSE);
|
|
1397 gaim_prefs_add_bool("/plugins/prpl/silc/sign_chat", FALSE);
|
|
1398 gaim_prefs_add_bool("/plugins/prpl/silc/verify_chat", FALSE);
|
8891
|
1399 g_snprintf(tmp, sizeof(tmp), "%s/public_key.pub", silcgaim_silcdir());
|
8849
|
1400 gaim_prefs_add_string("/plugins/prpl/silc/pubkey", tmp);
|
8891
|
1401 g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir());
|
8849
|
1402 gaim_prefs_add_string("/plugins/prpl/silc/privkey", tmp);
|
|
1403 gaim_prefs_add_string("/plugins/prpl/silc/vcard", "");
|
9272
|
1404
|
|
1405 silcgaim_register_commands();
|
8849
|
1406 }
|
|
1407
|
|
1408 GAIM_INIT_PLUGIN(silc, init_plugin, info);
|