Mercurial > pidgin.yaz
annotate src/protocols/silc/silc.c @ 11412:4be6232ffcd3
[gaim-migrate @ 13649]
sync the oldstatus translations to head because I have not been updating
head, and while head _is_ significantly different, there now exist
translations in oldstatus that don't in head, and even where they exist in
both, the oldstatus one is often more updated
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 01 Sep 2005 19:24:17 +0000 |
parents | 17142948653e |
children | 9c7ca8a8c4b8 |
rev | line source |
---|---|
8849 | 1 /* |
2 | |
3 silcgaim.c | |
4 | |
5 Author: Pekka Riikonen <priikone@silcnet.org> | |
6 | |
10825 | 7 Copyright (C) 2004 - 2005 Pekka Riikonen |
8849 | 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" | |
9943 | 23 #include "version.h" |
8849 | 24 |
25 extern SilcClientOperations ops; | |
26 static GaimPlugin *silc_plugin = NULL; | |
27 | |
28 static const char * | |
29 silcgaim_list_icon(GaimAccount *a, GaimBuddy *b) | |
30 { | |
31 return (const char *)"silc"; | |
32 } | |
33 | |
34 static void | |
9968 | 35 silcgaim_list_emblems(GaimBuddy *b, const char **se, const char **sw, |
36 const char **nw, const char **ne) | |
8849 | 37 { |
38 } | |
39 | |
40 static GList * | |
9968 | 41 silcgaim_away_states(GaimAccount *account) |
8849 | 42 { |
9968 | 43 GaimStatusType *type; |
44 GList *types = NULL; | |
8849 | 45 |
10801 | 46 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, SILCGAIM_STATUS_ID_OFFLINE, _("Offline"), FALSE, FALSE, FALSE); |
9968 | 47 types = g_list_append(types, type); |
10801 | 48 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, SILCGAIM_STATUS_ID_ONLINE, _("Online"), FALSE, FALSE, FALSE); |
49 types = g_list_append(types, type); | |
50 type = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, SILCGAIM_STATUS_ID_AVAILABLE, _("Available"), FALSE, TRUE, FALSE); | |
9968 | 51 types = g_list_append(types, type); |
10050 | 52 type = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, SILCGAIM_STATUS_ID_HYPER, _("Hyper Active"), FALSE, TRUE, FALSE); |
9968 | 53 types = g_list_append(types, type); |
10050 | 54 type = gaim_status_type_new_full(GAIM_STATUS_AWAY, SILCGAIM_STATUS_ID_AWAY, _("Away"), FALSE, TRUE, FALSE); |
9968 | 55 types = g_list_append(types, type); |
10050 | 56 type = gaim_status_type_new_full(GAIM_STATUS_AWAY, SILCGAIM_STATUS_ID_BUSY, _("Busy"), FALSE, TRUE, FALSE); |
9968 | 57 types = g_list_append(types, type); |
10050 | 58 type = gaim_status_type_new_full(GAIM_STATUS_AWAY, SILCGAIM_STATUS_ID_INDISPOSED, _("Indisposed"), FALSE, TRUE, FALSE); |
9968 | 59 types = g_list_append(types, type); |
10050 | 60 type = gaim_status_type_new_full(GAIM_STATUS_AWAY, SILCGAIM_STATUS_ID_PAGE, _("Wake Me Up"), FALSE, TRUE, FALSE); |
9968 | 61 types = g_list_append(types, type); |
8849 | 62 |
9968 | 63 return types; |
8849 | 64 } |
65 | |
66 static void | |
9968 | 67 silcgaim_set_status(GaimAccount *account, GaimStatus *status) |
8849 | 68 { |
9968 | 69 GaimConnection *gc = gaim_account_get_connection(account); |
10801 | 70 SilcGaim sg = NULL; |
8849 | 71 SilcUInt32 mode; |
72 SilcBuffer idp; | |
73 unsigned char mb[4]; | |
9968 | 74 const char *state; |
8849 | 75 |
10801 | 76 if (gc != NULL) |
77 sg = gc->proto_data; | |
78 | |
79 if (status == NULL) | |
80 return; | |
81 | |
82 state = gaim_status_get_id(status); | |
10225 | 83 |
10801 | 84 if (state == NULL) |
85 return; | |
10225 | 86 |
10801 | 87 if (strcmp(state, "offline") && !gc) { |
88 gaim_account_connect(account); | |
89 return; | |
10802 | 90 } else if (!strcmp(state, "offline")) { |
91 return; | |
10801 | 92 } |
93 | |
94 if ((sg == NULL) || (sg->conn == NULL)) | |
8849 | 95 return; |
96 | |
97 mode = sg->conn->local_entry->mode; | |
98 mode &= ~(SILC_UMODE_GONE | | |
99 SILC_UMODE_HYPER | | |
100 SILC_UMODE_BUSY | | |
101 SILC_UMODE_INDISPOSED | | |
102 SILC_UMODE_PAGE); | |
103 | |
9968 | 104 if (!strcmp(state, "hyper")) |
8849 | 105 mode |= SILC_UMODE_HYPER; |
9968 | 106 else if (!strcmp(state, "away")) |
8849 | 107 mode |= SILC_UMODE_GONE; |
9968 | 108 else if (!strcmp(state, "busy")) |
8849 | 109 mode |= SILC_UMODE_BUSY; |
9968 | 110 else if (!strcmp(state, "indisposed")) |
8849 | 111 mode |= SILC_UMODE_INDISPOSED; |
9968 | 112 else if (!strcmp(state, "page")) |
8849 | 113 mode |= SILC_UMODE_PAGE; |
114 | |
115 /* Send UMODE */ | |
116 idp = silc_id_payload_encode(sg->conn->local_id, SILC_ID_CLIENT); | |
117 SILC_PUT32_MSB(mode, mb); | |
118 silc_client_command_send(sg->client, sg->conn, SILC_COMMAND_UMODE, | |
119 ++sg->conn->cmd_ident, 2, | |
120 1, idp->data, idp->len, | |
121 2, mb, sizeof(mb)); | |
122 silc_buffer_free(idp); | |
123 } | |
124 | |
125 | |
126 /*************************** Connection Routines *****************************/ | |
127 | |
128 static void | |
129 silcgaim_keepalive(GaimConnection *gc) | |
130 { | |
131 SilcGaim sg = gc->proto_data; | |
132 silc_client_send_packet(sg->client, sg->conn, SILC_PACKET_HEARTBEAT, | |
133 NULL, 0); | |
134 } | |
135 | |
136 static int | |
137 silcgaim_scheduler(gpointer *context) | |
138 { | |
139 SilcGaim sg = (SilcGaim)context; | |
140 silc_client_run_one(sg->client); | |
141 return 1; | |
142 } | |
143 | |
144 static void | |
145 silcgaim_nickname_parse(const char *nickname, | |
146 char **ret_nickname) | |
147 { | |
148 silc_parse_userfqdn(nickname, ret_nickname, NULL); | |
149 } | |
150 | |
151 static void | |
152 silcgaim_login_connected(gpointer data, gint source, GaimInputCondition cond) | |
153 { | |
154 GaimConnection *gc = data; | |
155 SilcGaim sg = gc->proto_data; | |
9732 | 156 SilcClient client; |
8849 | 157 SilcClientConnection conn; |
158 GaimAccount *account = sg->account; | |
159 SilcClientConnectionParams params; | |
160 const char *dfile; | |
161 | |
162 if (source < 0) { | |
163 gaim_connection_error(gc, _("Connection failed")); | |
164 return; | |
165 } | |
9732 | 166 |
167 if (sg == NULL) | |
168 return; | |
169 | |
170 client = sg->client; | |
171 | |
8849 | 172 if (!g_list_find(gaim_connections_get_all(), gc)) { |
173 close(source); | |
174 g_source_remove(sg->scheduler); | |
175 silc_client_stop(sg->client); | |
176 silc_client_free(sg->client); | |
177 silc_free(sg); | |
178 return; | |
179 } | |
180 | |
181 /* Get session detachment data, if available */ | |
182 memset(¶ms, 0, sizeof(params)); | |
183 dfile = silcgaim_session_file(gaim_account_get_username(sg->account)); | |
11318 | 184 params.detach_data = (unsigned char *)silc_file_readfile(dfile, ¶ms.detach_data_len); |
8849 | 185 if (params.detach_data) |
186 params.detach_data[params.detach_data_len] = 0; | |
187 | |
188 /* Add connection to SILC client library */ | |
189 conn = silc_client_add_connection( | |
190 sg->client, ¶ms, | |
191 (char *)gaim_account_get_string(account, "server", | |
192 "silc.silcnet.org"), | |
193 gaim_account_get_int(account, "port", 706), sg); | |
194 if (!conn) { | |
195 gaim_connection_error(gc, _("Cannot initialize SILC Client connection")); | |
196 gc->proto_data = NULL; | |
197 return; | |
198 } | |
199 sg->conn = conn; | |
200 | |
201 /* Progress */ | |
202 if (params.detach_data) { | |
203 gaim_connection_update_progress(gc, _("Resuming session"), 2, 5); | |
204 sg->resuming = TRUE; | |
205 } else { | |
206 gaim_connection_update_progress(gc, _("Performing key exchange"), 2, 5); | |
207 } | |
208 | |
209 /* Perform SILC Key Exchange. The "silc_connected" will be called | |
210 eventually. */ | |
211 silc_client_start_key_exchange(sg->client, sg->conn, source); | |
212 | |
213 /* Set default attributes */ | |
214 if (!gaim_account_get_bool(account, "reject-attrs", FALSE)) { | |
215 SilcUInt32 mask; | |
216 const char *tmp; | |
217 #ifdef HAVE_SYS_UTSNAME_H | |
218 struct utsname u; | |
219 #endif | |
220 | |
221 mask = SILC_ATTRIBUTE_MOOD_NORMAL; | |
222 silc_client_attribute_add(client, conn, | |
223 SILC_ATTRIBUTE_STATUS_MOOD, | |
224 SILC_32_TO_PTR(mask), | |
225 sizeof(SilcUInt32)); | |
226 mask = SILC_ATTRIBUTE_CONTACT_CHAT; | |
227 silc_client_attribute_add(client, conn, | |
228 SILC_ATTRIBUTE_PREFERRED_CONTACT, | |
229 SILC_32_TO_PTR(mask), | |
230 sizeof(SilcUInt32)); | |
231 #ifdef HAVE_SYS_UTSNAME_H | |
232 if (!uname(&u)) { | |
233 SilcAttributeObjDevice dev; | |
234 memset(&dev, 0, sizeof(dev)); | |
235 dev.type = SILC_ATTRIBUTE_DEVICE_COMPUTER; | |
236 dev.version = u.release; | |
237 dev.model = u.sysname; | |
238 silc_client_attribute_add(client, conn, | |
239 SILC_ATTRIBUTE_DEVICE_INFO, | |
240 (void *)&dev, sizeof(dev)); | |
241 } | |
242 #endif | |
243 #ifdef _WIN32 | |
244 tmp = _tzname[0]; | |
245 #else | |
246 tmp = tzname[0]; | |
247 #endif | |
248 silc_client_attribute_add(client, conn, | |
249 SILC_ATTRIBUTE_TIMEZONE, | |
250 (void *)tmp, strlen(tmp)); | |
251 } | |
252 | |
253 silc_free(params.detach_data); | |
254 } | |
255 | |
256 static void | |
10401 | 257 silcgaim_login(GaimAccount *account, GaimStatus *status) |
8849 | 258 { |
259 SilcGaim sg; | |
260 SilcClient client; | |
261 SilcClientParams params; | |
262 GaimConnection *gc; | |
10825 | 263 char pkd[256], prd[256]; |
8849 | 264 |
265 gc = account->gc; | |
266 if (!gc) | |
267 return; | |
268 gc->proto_data = NULL; | |
269 | |
270 memset(¶ms, 0, sizeof(params)); | |
271 strcat(params.nickname_format, "%n@%h%a"); | |
272 params.nickname_parse = silcgaim_nickname_parse; | |
273 params.ignore_requested_attributes = | |
274 gaim_account_get_bool(account, "reject-attrs", FALSE); | |
275 | |
276 /* Allocate SILC client */ | |
277 client = silc_client_alloc(&ops, ¶ms, gc, NULL); | |
278 if (!client) { | |
279 gaim_connection_error(gc, _("Out of memory")); | |
280 return; | |
281 } | |
282 | |
283 /* Get username, real name and local hostname for SILC library */ | |
284 if (gaim_account_get_username(account)) { | |
10825 | 285 const char *u = gaim_account_get_username(account); |
286 char **up = g_strsplit(u, "@", 2); | |
287 client->username = strdup(up[0]); | |
288 g_strfreev(up); | |
8849 | 289 } else { |
290 client->username = silc_get_username(); | |
291 gaim_account_set_username(account, client->username); | |
292 } | |
293 if (gaim_account_get_user_info(account)) { | |
294 client->realname = strdup(gaim_account_get_user_info(account)); | |
295 } else { | |
296 client->realname = silc_get_real_name(); | |
297 gaim_account_set_user_info(account, client->realname); | |
298 } | |
299 client->hostname = silc_net_localhost(); | |
300 | |
301 gaim_connection_set_display_name(gc, client->username); | |
302 | |
303 /* Init SILC client */ | |
304 if (!silc_client_init(client)) { | |
10909 | 305 gc->wants_to_die = TRUE; |
8849 | 306 gaim_connection_error(gc, ("Cannot initialize SILC protocol")); |
307 return; | |
308 } | |
309 | |
310 /* Check the ~/.silc dir and create it, and new key pair if necessary. */ | |
311 if (!silcgaim_check_silc_dir(gc)) { | |
10909 | 312 gc->wants_to_die = TRUE; |
8849 | 313 gaim_connection_error(gc, ("Cannot find/access ~/.silc directory")); |
314 return; | |
315 } | |
316 | |
317 /* Progress */ | |
318 gaim_connection_update_progress(gc, _("Connecting to SILC Server"), 1, 5); | |
319 | |
320 /* Load SILC key pair */ | |
10909 | 321 g_snprintf(pkd, sizeof(pkd), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcgaim_silcdir()); |
322 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir()); | |
323 if (!silc_load_key_pair((char *)gaim_account_get_string(account, "public-key", pkd), | |
10825 | 324 (char *)gaim_account_get_string(account, "private-key", prd), |
10751 | 325 (gc->password == NULL) ? "" : gc->password, &client->pkcs, |
9272 | 326 &client->public_key, &client->private_key)) { |
8849 | 327 gaim_connection_error(gc, ("Could not load SILC key pair")); |
328 return; | |
329 } | |
330 | |
331 sg = silc_calloc(1, sizeof(*sg)); | |
332 if (!sg) | |
333 return; | |
334 memset(sg, 0, sizeof(*sg)); | |
335 sg->client = client; | |
336 sg->gc = gc; | |
337 sg->account = account; | |
338 gc->proto_data = sg; | |
339 | |
340 /* Connect to the SILC server */ | |
341 if (gaim_proxy_connect(account, | |
342 gaim_account_get_string(account, "server", | |
343 "silc.silcnet.org"), | |
344 gaim_account_get_int(account, "port", 706), | |
345 silcgaim_login_connected, gc)) { | |
346 gaim_connection_error(gc, ("Unable to create connection")); | |
347 return; | |
348 } | |
349 | |
350 /* Schedule SILC using Glib's event loop */ | |
9353 | 351 #ifndef _WIN32 |
8849 | 352 sg->scheduler = g_timeout_add(5, (GSourceFunc)silcgaim_scheduler, sg); |
9353 | 353 #else |
354 sg->scheduler = g_timeout_add(300, (GSourceFunc)silcgaim_scheduler, sg); | |
355 #endif | |
8849 | 356 } |
357 | |
358 static int | |
359 silcgaim_close_final(gpointer *context) | |
360 { | |
361 SilcGaim sg = (SilcGaim)context; | |
362 silc_client_stop(sg->client); | |
363 silc_client_free(sg->client); | |
364 silc_free(sg); | |
365 return 0; | |
366 } | |
367 | |
368 static void | |
369 silcgaim_close(GaimConnection *gc) | |
370 { | |
371 SilcGaim sg = gc->proto_data; | |
372 | |
10547 | 373 g_return_if_fail(sg != NULL); |
8849 | 374 |
375 /* Send QUIT */ | |
376 silc_client_command_call(sg->client, sg->conn, NULL, | |
9353 | 377 "QUIT", "Download Gaim: " GAIM_WEBSITE, NULL); |
8849 | 378 |
379 if (sg->conn) | |
380 silc_client_close_connection(sg->client, sg->conn); | |
381 | |
382 g_source_remove(sg->scheduler); | |
383 g_timeout_add(1, (GSourceFunc)silcgaim_close_final, sg); | |
384 } | |
385 | |
386 | |
387 /****************************** Protocol Actions *****************************/ | |
388 | |
389 static void | |
390 silcgaim_attrs_cancel(GaimConnection *gc, GaimRequestFields *fields) | |
391 { | |
392 /* Nothing */ | |
393 } | |
394 | |
395 static void | |
396 silcgaim_attrs_cb(GaimConnection *gc, GaimRequestFields *fields) | |
397 { | |
398 SilcGaim sg = gc->proto_data; | |
399 SilcClient client = sg->client; | |
400 SilcClientConnection conn = sg->conn; | |
401 GaimRequestField *f; | |
402 char *tmp; | |
403 SilcUInt32 tmp_len, mask; | |
404 SilcAttributeObjService service; | |
405 SilcAttributeObjDevice dev; | |
406 SilcVCardStruct vcard; | |
407 const char *val; | |
408 | |
409 sg = gc->proto_data; | |
410 if (!sg) | |
411 return; | |
412 | |
413 memset(&service, 0, sizeof(service)); | |
414 memset(&dev, 0, sizeof(dev)); | |
415 memset(&vcard, 0, sizeof(vcard)); | |
416 | |
417 silc_client_attribute_del(client, conn, | |
418 SILC_ATTRIBUTE_USER_INFO, NULL); | |
419 silc_client_attribute_del(client, conn, | |
420 SILC_ATTRIBUTE_SERVICE, NULL); | |
421 silc_client_attribute_del(client, conn, | |
422 SILC_ATTRIBUTE_STATUS_MOOD, NULL); | |
423 silc_client_attribute_del(client, conn, | |
424 SILC_ATTRIBUTE_STATUS_FREETEXT, NULL); | |
425 silc_client_attribute_del(client, conn, | |
426 SILC_ATTRIBUTE_STATUS_MESSAGE, NULL); | |
427 silc_client_attribute_del(client, conn, | |
428 SILC_ATTRIBUTE_PREFERRED_LANGUAGE, NULL); | |
429 silc_client_attribute_del(client, conn, | |
430 SILC_ATTRIBUTE_PREFERRED_CONTACT, NULL); | |
431 silc_client_attribute_del(client, conn, | |
432 SILC_ATTRIBUTE_TIMEZONE, NULL); | |
433 silc_client_attribute_del(client, conn, | |
434 SILC_ATTRIBUTE_GEOLOCATION, NULL); | |
435 silc_client_attribute_del(client, conn, | |
436 SILC_ATTRIBUTE_DEVICE_INFO, NULL); | |
437 | |
438 /* Set mood */ | |
439 mask = 0; | |
440 f = gaim_request_fields_get_field(fields, "mood_normal"); | |
441 if (f && gaim_request_field_bool_get_value(f)) | |
442 mask |= SILC_ATTRIBUTE_MOOD_NORMAL; | |
443 f = gaim_request_fields_get_field(fields, "mood_happy"); | |
444 if (f && gaim_request_field_bool_get_value(f)) | |
445 mask |= SILC_ATTRIBUTE_MOOD_HAPPY; | |
446 f = gaim_request_fields_get_field(fields, "mood_sad"); | |
447 if (f && gaim_request_field_bool_get_value(f)) | |
448 mask |= SILC_ATTRIBUTE_MOOD_SAD; | |
449 f = gaim_request_fields_get_field(fields, "mood_angry"); | |
450 if (f && gaim_request_field_bool_get_value(f)) | |
451 mask |= SILC_ATTRIBUTE_MOOD_ANGRY; | |
452 f = gaim_request_fields_get_field(fields, "mood_jealous"); | |
453 if (f && gaim_request_field_bool_get_value(f)) | |
454 mask |= SILC_ATTRIBUTE_MOOD_JEALOUS; | |
455 f = gaim_request_fields_get_field(fields, "mood_ashamed"); | |
456 if (f && gaim_request_field_bool_get_value(f)) | |
457 mask |= SILC_ATTRIBUTE_MOOD_ASHAMED; | |
458 f = gaim_request_fields_get_field(fields, "mood_invincible"); | |
459 if (f && gaim_request_field_bool_get_value(f)) | |
460 mask |= SILC_ATTRIBUTE_MOOD_INVINCIBLE; | |
461 f = gaim_request_fields_get_field(fields, "mood_inlove"); | |
462 if (f && gaim_request_field_bool_get_value(f)) | |
463 mask |= SILC_ATTRIBUTE_MOOD_INLOVE; | |
464 f = gaim_request_fields_get_field(fields, "mood_sleepy"); | |
465 if (f && gaim_request_field_bool_get_value(f)) | |
466 mask |= SILC_ATTRIBUTE_MOOD_SLEEPY; | |
467 f = gaim_request_fields_get_field(fields, "mood_bored"); | |
468 if (f && gaim_request_field_bool_get_value(f)) | |
469 mask |= SILC_ATTRIBUTE_MOOD_BORED; | |
470 f = gaim_request_fields_get_field(fields, "mood_excited"); | |
471 if (f && gaim_request_field_bool_get_value(f)) | |
472 mask |= SILC_ATTRIBUTE_MOOD_EXCITED; | |
473 f = gaim_request_fields_get_field(fields, "mood_anxious"); | |
474 if (f && gaim_request_field_bool_get_value(f)) | |
475 mask |= SILC_ATTRIBUTE_MOOD_ANXIOUS; | |
476 silc_client_attribute_add(client, conn, | |
477 SILC_ATTRIBUTE_STATUS_MOOD, | |
478 SILC_32_TO_PTR(mask), | |
479 sizeof(SilcUInt32)); | |
480 | |
481 /* Set preferred contact */ | |
482 mask = 0; | |
483 f = gaim_request_fields_get_field(fields, "contact_chat"); | |
484 if (f && gaim_request_field_bool_get_value(f)) | |
485 mask |= SILC_ATTRIBUTE_CONTACT_CHAT; | |
486 f = gaim_request_fields_get_field(fields, "contact_email"); | |
487 if (f && gaim_request_field_bool_get_value(f)) | |
488 mask |= SILC_ATTRIBUTE_CONTACT_EMAIL; | |
489 f = gaim_request_fields_get_field(fields, "contact_call"); | |
490 if (f && gaim_request_field_bool_get_value(f)) | |
491 mask |= SILC_ATTRIBUTE_CONTACT_CALL; | |
492 f = gaim_request_fields_get_field(fields, "contact_sms"); | |
493 if (f && gaim_request_field_bool_get_value(f)) | |
494 mask |= SILC_ATTRIBUTE_CONTACT_SMS; | |
495 f = gaim_request_fields_get_field(fields, "contact_mms"); | |
496 if (f && gaim_request_field_bool_get_value(f)) | |
497 mask |= SILC_ATTRIBUTE_CONTACT_MMS; | |
498 f = gaim_request_fields_get_field(fields, "contact_video"); | |
499 if (f && gaim_request_field_bool_get_value(f)) | |
500 mask |= SILC_ATTRIBUTE_CONTACT_VIDEO; | |
501 if (mask) | |
502 silc_client_attribute_add(client, conn, | |
503 SILC_ATTRIBUTE_PREFERRED_CONTACT, | |
504 SILC_32_TO_PTR(mask), | |
505 sizeof(SilcUInt32)); | |
506 | |
507 /* Set status text */ | |
508 val = NULL; | |
509 f = gaim_request_fields_get_field(fields, "status_text"); | |
510 if (f) | |
511 val = gaim_request_field_string_get_value(f); | |
512 if (val && *val) | |
513 silc_client_attribute_add(client, conn, | |
514 SILC_ATTRIBUTE_STATUS_FREETEXT, | |
515 (void *)val, strlen(val)); | |
516 | |
517 /* Set vcard */ | |
518 val = NULL; | |
519 f = gaim_request_fields_get_field(fields, "vcard"); | |
520 if (f) | |
521 val = gaim_request_field_string_get_value(f); | |
522 if (val && *val) { | |
523 gaim_prefs_set_string("/plugins/prpl/silc/vcard", val); | |
524 tmp = silc_file_readfile(val, &tmp_len); | |
525 if (tmp) { | |
526 tmp[tmp_len] = 0; | |
11318 | 527 if (silc_vcard_decode((unsigned char *)tmp, tmp_len, &vcard)) |
8849 | 528 silc_client_attribute_add(client, conn, |
529 SILC_ATTRIBUTE_USER_INFO, | |
530 (void *)&vcard, | |
531 sizeof(vcard)); | |
532 } | |
533 silc_vcard_free(&vcard); | |
534 silc_free(tmp); | |
535 } | |
536 | |
537 #ifdef HAVE_SYS_UTSNAME_H | |
538 /* Set device info */ | |
539 f = gaim_request_fields_get_field(fields, "device"); | |
540 if (f && gaim_request_field_bool_get_value(f)) { | |
541 struct utsname u; | |
542 if (!uname(&u)) { | |
543 dev.type = SILC_ATTRIBUTE_DEVICE_COMPUTER; | |
544 dev.version = u.release; | |
545 dev.model = u.sysname; | |
546 silc_client_attribute_add(client, conn, | |
547 SILC_ATTRIBUTE_DEVICE_INFO, | |
548 (void *)&dev, sizeof(dev)); | |
549 } | |
550 } | |
551 #endif | |
552 | |
553 /* Set timezone */ | |
554 val = NULL; | |
555 f = gaim_request_fields_get_field(fields, "timezone"); | |
556 if (f) | |
557 val = gaim_request_field_string_get_value(f); | |
558 if (val && *val) | |
559 silc_client_attribute_add(client, conn, | |
560 SILC_ATTRIBUTE_TIMEZONE, | |
561 (void *)val, strlen(val)); | |
562 } | |
563 | |
564 static void | |
9015 | 565 silcgaim_attrs(GaimPluginAction *action) |
8849 | 566 { |
9015 | 567 GaimConnection *gc = (GaimConnection *) action->context; |
8849 | 568 SilcGaim sg = gc->proto_data; |
569 SilcClient client = sg->client; | |
570 SilcClientConnection conn = sg->conn; | |
571 GaimRequestFields *fields; | |
572 GaimRequestFieldGroup *g; | |
573 GaimRequestField *f; | |
574 SilcHashTable attrs; | |
575 SilcAttributePayload attr; | |
576 gboolean mnormal = TRUE, mhappy = FALSE, msad = FALSE, | |
577 mangry = FALSE, mjealous = FALSE, mashamed = FALSE, | |
578 minvincible = FALSE, minlove = FALSE, msleepy = FALSE, | |
579 mbored = FALSE, mexcited = FALSE, manxious = FALSE; | |
580 gboolean cemail = FALSE, ccall = FALSE, csms = FALSE, | |
581 cmms = FALSE, cchat = TRUE, cvideo = FALSE; | |
582 gboolean device = TRUE; | |
583 char status[1024]; | |
584 | |
585 sg = gc->proto_data; | |
586 if (!sg) | |
587 return; | |
588 | |
589 memset(status, 0, sizeof(status)); | |
590 | |
591 attrs = silc_client_attributes_get(client, conn); | |
592 if (attrs) { | |
593 if (silc_hash_table_find(attrs, | |
594 SILC_32_TO_PTR(SILC_ATTRIBUTE_STATUS_MOOD), | |
595 NULL, (void *)&attr)) { | |
596 SilcUInt32 mood = 0; | |
597 silc_attribute_get_object(attr, &mood, sizeof(mood)); | |
598 mnormal = !mood; | |
599 mhappy = (mood & SILC_ATTRIBUTE_MOOD_HAPPY); | |
600 msad = (mood & SILC_ATTRIBUTE_MOOD_SAD); | |
601 mangry = (mood & SILC_ATTRIBUTE_MOOD_ANGRY); | |
602 mjealous = (mood & SILC_ATTRIBUTE_MOOD_JEALOUS); | |
603 mashamed = (mood & SILC_ATTRIBUTE_MOOD_ASHAMED); | |
604 minvincible = (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE); | |
605 minlove = (mood & SILC_ATTRIBUTE_MOOD_INLOVE); | |
606 msleepy = (mood & SILC_ATTRIBUTE_MOOD_SLEEPY); | |
607 mbored = (mood & SILC_ATTRIBUTE_MOOD_BORED); | |
608 mexcited = (mood & SILC_ATTRIBUTE_MOOD_EXCITED); | |
609 manxious = (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS); | |
610 } | |
611 | |
612 if (silc_hash_table_find(attrs, | |
613 SILC_32_TO_PTR(SILC_ATTRIBUTE_PREFERRED_CONTACT), | |
614 NULL, (void *)&attr)) { | |
615 SilcUInt32 contact = 0; | |
616 silc_attribute_get_object(attr, &contact, sizeof(contact)); | |
617 cemail = (contact & SILC_ATTRIBUTE_CONTACT_EMAIL); | |
618 ccall = (contact & SILC_ATTRIBUTE_CONTACT_CALL); | |
619 csms = (contact & SILC_ATTRIBUTE_CONTACT_SMS); | |
620 cmms = (contact & SILC_ATTRIBUTE_CONTACT_MMS); | |
621 cchat = (contact & SILC_ATTRIBUTE_CONTACT_CHAT); | |
622 cvideo = (contact & SILC_ATTRIBUTE_CONTACT_VIDEO); | |
623 } | |
624 | |
625 if (silc_hash_table_find(attrs, | |
626 SILC_32_TO_PTR(SILC_ATTRIBUTE_STATUS_FREETEXT), | |
627 NULL, (void *)&attr)) | |
628 silc_attribute_get_object(attr, &status, sizeof(status)); | |
629 | |
630 if (!silc_hash_table_find(attrs, | |
631 SILC_32_TO_PTR(SILC_ATTRIBUTE_DEVICE_INFO), | |
632 NULL, (void *)&attr)) | |
633 device = FALSE; | |
634 } | |
635 | |
636 fields = gaim_request_fields_new(); | |
637 | |
638 g = gaim_request_field_group_new(NULL); | |
639 f = gaim_request_field_label_new("l3", _("Your Current Mood")); | |
640 gaim_request_field_group_add_field(g, f); | |
641 f = gaim_request_field_bool_new("mood_normal", _("Normal"), mnormal); | |
642 gaim_request_field_group_add_field(g, f); | |
643 f = gaim_request_field_bool_new("mood_happy", _("Happy"), mhappy); | |
644 gaim_request_field_group_add_field(g, f); | |
645 f = gaim_request_field_bool_new("mood_sad", _("Sad"), msad); | |
646 gaim_request_field_group_add_field(g, f); | |
647 f = gaim_request_field_bool_new("mood_angry", _("Angry"), mangry); | |
648 gaim_request_field_group_add_field(g, f); | |
649 f = gaim_request_field_bool_new("mood_jealous", _("Jealous"), mjealous); | |
650 gaim_request_field_group_add_field(g, f); | |
651 f = gaim_request_field_bool_new("mood_ashamed", _("Ashamed"), mashamed); | |
652 gaim_request_field_group_add_field(g, f); | |
653 f = gaim_request_field_bool_new("mood_invincible", _("Invincible"), minvincible); | |
654 gaim_request_field_group_add_field(g, f); | |
655 f = gaim_request_field_bool_new("mood_inlove", _("In Love"), minlove); | |
656 gaim_request_field_group_add_field(g, f); | |
657 f = gaim_request_field_bool_new("mood_sleepy", _("Sleepy"), msleepy); | |
658 gaim_request_field_group_add_field(g, f); | |
659 f = gaim_request_field_bool_new("mood_bored", _("Bored"), mbored); | |
660 gaim_request_field_group_add_field(g, f); | |
661 f = gaim_request_field_bool_new("mood_excited", _("Excited"), mexcited); | |
662 gaim_request_field_group_add_field(g, f); | |
663 f = gaim_request_field_bool_new("mood_anxious", _("Anxious"), manxious); | |
664 gaim_request_field_group_add_field(g, f); | |
665 | |
666 f = gaim_request_field_label_new("l4", _("\nYour Preferred Contact Methods")); | |
667 gaim_request_field_group_add_field(g, f); | |
668 f = gaim_request_field_bool_new("contact_chat", _("Chat"), cchat); | |
669 gaim_request_field_group_add_field(g, f); | |
670 f = gaim_request_field_bool_new("contact_email", _("Email"), cemail); | |
671 gaim_request_field_group_add_field(g, f); | |
672 f = gaim_request_field_bool_new("contact_call", _("Phone"), ccall); | |
673 gaim_request_field_group_add_field(g, f); | |
674 f = gaim_request_field_bool_new("contact_sms", _("SMS"), csms); | |
675 gaim_request_field_group_add_field(g, f); | |
676 f = gaim_request_field_bool_new("contact_mms", _("MMS"), cmms); | |
677 gaim_request_field_group_add_field(g, f); | |
678 f = gaim_request_field_bool_new("contact_video", _("Video Conferencing"), cvideo); | |
679 gaim_request_field_group_add_field(g, f); | |
680 gaim_request_fields_add_group(fields, g); | |
681 | |
682 g = gaim_request_field_group_new(NULL); | |
683 f = gaim_request_field_string_new("status_text", _("Your Current Status"), | |
684 status[0] ? status : NULL, TRUE); | |
685 gaim_request_field_group_add_field(g, f); | |
686 gaim_request_fields_add_group(fields, g); | |
687 | |
688 g = gaim_request_field_group_new(NULL); | |
689 #if 0 | |
690 f = gaim_request_field_label_new("l2", _("Online Services")); | |
691 gaim_request_field_group_add_field(g, f); | |
692 f = gaim_request_field_bool_new("services", | |
693 _("Let others see what services you are using"), | |
694 TRUE); | |
695 gaim_request_field_group_add_field(g, f); | |
696 #endif | |
697 #ifdef HAVE_SYS_UTSNAME_H | |
698 f = gaim_request_field_bool_new("device", | |
699 _("Let others see what computer you are using"), | |
700 device); | |
701 gaim_request_field_group_add_field(g, f); | |
702 #endif | |
703 gaim_request_fields_add_group(fields, g); | |
704 | |
705 g = gaim_request_field_group_new(NULL); | |
706 f = gaim_request_field_string_new("vcard", _("Your VCard File"), | |
707 gaim_prefs_get_string("/plugins/prpl/silc/vcard"), | |
708 FALSE); | |
709 gaim_request_field_group_add_field(g, f); | |
710 #ifdef _WIN32 | |
711 f = gaim_request_field_string_new("timezone", _("Timezone"), _tzname[0], FALSE); | |
712 #else | |
713 f = gaim_request_field_string_new("timezone", _("Timezone"), tzname[0], FALSE); | |
714 #endif | |
715 gaim_request_field_group_add_field(g, f); | |
716 gaim_request_fields_add_group(fields, g); | |
717 | |
718 | |
11201 | 719 gaim_request_fields(gc, _("User Online Status Attributes"), |
8849 | 720 _("User Online Status Attributes"), |
721 _("You can let other users see your online status information " | |
722 "and your personal information. Please fill the information " | |
723 "you would like other users to see about yourself."), | |
724 fields, | |
8906 | 725 _("OK"), G_CALLBACK(silcgaim_attrs_cb), |
726 _("Cancel"), G_CALLBACK(silcgaim_attrs_cancel), gc); | |
8849 | 727 } |
728 | |
729 static void | |
9015 | 730 silcgaim_detach(GaimPluginAction *action) |
8849 | 731 { |
9015 | 732 GaimConnection *gc = (GaimConnection *) action->context; |
8849 | 733 SilcGaim sg; |
734 | |
735 if (!gc) | |
736 return; | |
737 sg = gc->proto_data; | |
738 if (!sg) | |
739 return; | |
740 | |
741 /* Call DETACH */ | |
742 silc_client_command_call(sg->client, sg->conn, "DETACH"); | |
743 sg->detaching = TRUE; | |
744 } | |
745 | |
746 static void | |
9015 | 747 silcgaim_view_motd(GaimPluginAction *action) |
8849 | 748 { |
9015 | 749 GaimConnection *gc = (GaimConnection *) action->context; |
8849 | 750 SilcGaim sg; |
9488 | 751 char *tmp; |
8849 | 752 |
753 if (!gc) | |
754 return; | |
755 sg = gc->proto_data; | |
756 if (!sg) | |
757 return; | |
758 | |
759 if (!sg->motd) { | |
760 gaim_notify_error( | |
761 gc, _("Message of the Day"), _("No Message of the Day available"), | |
762 _("There is no Message of the Day associated with this connection")); | |
763 return; | |
764 } | |
765 | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10547
diff
changeset
|
766 tmp = g_markup_escape_text(sg->motd, -1); |
9488 | 767 gaim_notify_formatted(gc, NULL, _("Message of the Day"), NULL, |
768 tmp, NULL, NULL); | |
769 g_free(tmp); | |
8849 | 770 } |
771 | |
9272 | 772 static void |
773 silcgaim_change_pass(GaimPluginAction *action) | |
774 { | |
775 GaimConnection *gc = (GaimConnection *) action->context; | |
776 gaim_account_request_change_password(gaim_connection_get_account(gc)); | |
777 } | |
778 | |
779 static void | |
780 silcgaim_change_passwd(GaimConnection *gc, const char *old, const char *new) | |
781 { | |
10825 | 782 char prd[256]; |
783 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.pub", silcgaim_silcdir()); | |
784 silc_change_private_key_passphrase(gaim_account_get_string(gc->account, | |
785 "private-key", | |
786 prd), old, new); | |
9272 | 787 } |
788 | |
789 static void | |
790 silcgaim_show_set_info(GaimPluginAction *action) | |
791 { | |
792 GaimConnection *gc = (GaimConnection *) action->context; | |
793 gaim_account_request_change_user_info(gaim_connection_get_account(gc)); | |
794 } | |
795 | |
796 static void | |
797 silcgaim_set_info(GaimConnection *gc, const char *text) | |
798 { | |
799 } | |
800 | |
8849 | 801 static GList * |
9015 | 802 silcgaim_actions(GaimPlugin *plugin, gpointer context) |
8849 | 803 { |
9024 | 804 GaimConnection *gc = context; |
8849 | 805 GList *list = NULL; |
9015 | 806 GaimPluginAction *act; |
8849 | 807 |
808 if (!gaim_account_get_bool(gc->account, "reject-attrs", FALSE)) { | |
9015 | 809 act = gaim_plugin_action_new(_("Online Status"), |
810 silcgaim_attrs); | |
811 list = g_list_append(list, act); | |
8849 | 812 } |
813 | |
9015 | 814 act = gaim_plugin_action_new(_("Detach From Server"), |
815 silcgaim_detach); | |
816 list = g_list_append(list, act); | |
8849 | 817 |
9015 | 818 act = gaim_plugin_action_new(_("View Message of the Day"), |
819 silcgaim_view_motd); | |
820 list = g_list_append(list, act); | |
8849 | 821 |
9272 | 822 act = gaim_plugin_action_new(_("Change Password..."), |
823 silcgaim_change_pass); | |
824 list = g_list_append(list, act); | |
825 | |
826 act = gaim_plugin_action_new(_("Set User Info..."), | |
827 silcgaim_show_set_info); | |
828 list = g_list_append(list, act); | |
829 | |
8849 | 830 return list; |
831 } | |
832 | |
833 | |
834 /******************************* IM Routines *********************************/ | |
835 | |
836 typedef struct { | |
837 char *nick; | |
11318 | 838 char *message; |
8849 | 839 SilcUInt32 message_len; |
840 SilcMessageFlags flags; | |
841 } *SilcGaimIM; | |
842 | |
843 static void | |
844 silcgaim_send_im_resolved(SilcClient client, | |
845 SilcClientConnection conn, | |
846 SilcClientEntry *clients, | |
847 SilcUInt32 clients_count, | |
848 void *context) | |
849 { | |
850 GaimConnection *gc = client->application; | |
851 SilcGaim sg = gc->proto_data; | |
852 SilcGaimIM im = context; | |
853 GaimConversation *convo; | |
854 char tmp[256], *nickname = NULL; | |
855 SilcClientEntry client_entry; | |
856 | |
11338 | 857 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, im->nick, |
10246 | 858 sg->account); |
8849 | 859 if (!convo) |
860 return; | |
861 | |
862 if (!clients) | |
863 goto err; | |
864 | |
865 if (clients_count > 1) { | |
866 silc_parse_userfqdn(im->nick, &nickname, NULL); | |
867 | |
868 /* Find the correct one. The im->nick might be a formatted nick | |
869 so this will find the correct one. */ | |
870 clients = silc_client_get_clients_local(client, conn, | |
871 nickname, im->nick, | |
872 &clients_count); | |
873 if (!clients) | |
874 goto err; | |
875 client_entry = clients[0]; | |
876 silc_free(clients); | |
877 } else { | |
878 client_entry = clients[0]; | |
879 } | |
880 | |
881 /* Send the message */ | |
882 silc_client_send_private_message(client, conn, client_entry, im->flags, | |
11318 | 883 (unsigned char *)im->message, im->message_len, TRUE); |
8849 | 884 gaim_conv_im_write(GAIM_CONV_IM(convo), conn->local_entry->nickname, |
885 im->message, 0, time(NULL)); | |
886 | |
887 goto out; | |
888 | |
889 err: | |
890 g_snprintf(tmp, sizeof(tmp), | |
891 _("User <I>%s</I> is not present in the network"), im->nick); | |
892 gaim_conversation_write(convo, NULL, tmp, GAIM_MESSAGE_SYSTEM, time(NULL)); | |
893 | |
894 out: | |
895 g_free(im->nick); | |
896 g_free(im->message); | |
897 silc_free(im); | |
898 silc_free(nickname); | |
899 } | |
900 | |
901 static int | |
902 silcgaim_send_im(GaimConnection *gc, const char *who, const char *msg, | |
903 GaimConvImFlags flags) | |
904 { | |
905 SilcGaim sg = gc->proto_data; | |
906 SilcClient client = sg->client; | |
907 SilcClientConnection conn = sg->conn; | |
908 SilcClientEntry *clients; | |
909 SilcUInt32 clients_count, mflags; | |
910 char *nickname; | |
911 int ret; | |
912 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_im"); | |
913 | |
914 if (!who || !msg) | |
915 return 0; | |
916 | |
9353 | 917 mflags = SILC_MESSAGE_FLAG_UTF8; |
918 | |
919 if (!g_ascii_strncasecmp(msg, "/me ", 4)) { | |
920 msg += 4; | |
921 if (!msg) | |
922 return 0; | |
923 mflags |= SILC_MESSAGE_FLAG_ACTION; | |
924 } else if (strlen(msg) > 1 && msg[0] == '/') { | |
8849 | 925 if (!silc_client_command_call(client, conn, msg + 1)) |
926 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"), | |
9359 | 927 _("Unknown command")); |
8849 | 928 return 0; |
929 } | |
930 | |
9353 | 931 |
8849 | 932 if (!silc_parse_userfqdn(who, &nickname, NULL)) |
933 return 0; | |
934 | |
935 if (sign) | |
936 mflags |= SILC_MESSAGE_FLAG_SIGNED; | |
937 | |
938 /* Find client entry */ | |
939 clients = silc_client_get_clients_local(client, conn, nickname, who, | |
940 &clients_count); | |
941 if (!clients) { | |
942 /* Resolve unknown user */ | |
943 SilcGaimIM im = silc_calloc(1, sizeof(*im)); | |
944 if (!im) | |
945 return 0; | |
946 im->nick = g_strdup(who); | |
947 im->message = g_strdup(msg); | |
948 im->message_len = strlen(im->message); | |
949 im->flags = mflags; | |
950 silc_client_get_clients(client, conn, nickname, NULL, | |
951 silcgaim_send_im_resolved, im); | |
952 silc_free(nickname); | |
953 return 0; | |
954 } | |
955 | |
956 /* Send private message directly */ | |
957 ret = silc_client_send_private_message(client, conn, clients[0], | |
11318 | 958 mflags, (unsigned char *)msg, |
8849 | 959 strlen(msg), TRUE); |
960 | |
961 silc_free(nickname); | |
962 silc_free(clients); | |
963 return ret; | |
964 } | |
965 | |
966 | |
9030 | 967 GList *silcgaim_blist_node_menu(GaimBlistNode *node) { |
968 /* split this single menu building function back into the two | |
969 original: one for buddies and one for chats */ | |
970 | |
971 if(GAIM_BLIST_NODE_IS_CHAT(node)) { | |
9038 | 972 return silcgaim_chat_menu((GaimChat *) node); |
9030 | 973 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
974 return silcgaim_buddy_menu((GaimBuddy *) node); | |
975 } else { | |
9038 | 976 g_return_val_if_reached(NULL); |
9353 | 977 } |
9030 | 978 } |
979 | |
9272 | 980 /********************************* Commands **********************************/ |
981 | |
982 static GaimCmdRet silcgaim_cmd_chat_part(GaimConversation *conv, | |
9597 | 983 const char *cmd, char **args, char **error, void *data) |
9272 | 984 { |
985 GaimConnection *gc; | |
9353 | 986 GaimConversation *convo; |
9272 | 987 int id = 0; |
988 | |
989 gc = gaim_conversation_get_gc(conv); | |
9353 | 990 |
991 if (gc == NULL) | |
992 return GAIM_CMD_RET_FAILED; | |
9272 | 993 |
9353 | 994 if(args && args[0]) { |
11338 | 995 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, args[0], |
10246 | 996 gc->account); |
9353 | 997 } else |
998 convo = conv; | |
999 | |
1000 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)); | |
1001 | |
1002 if (id == 0) | |
9272 | 1003 return GAIM_CMD_RET_FAILED; |
1004 | |
1005 silcgaim_chat_leave(gc, id); | |
1006 | |
1007 return GAIM_CMD_RET_OK; | |
1008 | |
1009 } | |
1010 | |
1011 static GaimCmdRet silcgaim_cmd_chat_topic(GaimConversation *conv, | |
9597 | 1012 const char *cmd, char **args, char **error, void *data) |
9272 | 1013 { |
1014 GaimConnection *gc; | |
1015 int id = 0; | |
9762 | 1016 char *buf, *tmp, *tmp2; |
9488 | 1017 const char *topic; |
9272 | 1018 |
1019 gc = gaim_conversation_get_gc(conv); | |
1020 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)); | |
1021 | |
1022 if (gc == NULL || id == 0) | |
1023 return GAIM_CMD_RET_FAILED; | |
1024 | |
9488 | 1025 if (!args || !args[0]) { |
1026 topic = gaim_conv_chat_get_topic (GAIM_CONV_CHAT(conv)); | |
1027 if (topic) { | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10547
diff
changeset
|
1028 tmp = g_markup_escape_text(topic, -1); |
9762 | 1029 tmp2 = gaim_markup_linkify(tmp); |
1030 buf = g_strdup_printf(_("current topic is: %s"), tmp2); | |
9488 | 1031 g_free(tmp); |
9762 | 1032 g_free(tmp2); |
9488 | 1033 } else |
1034 buf = g_strdup(_("No topic is set")); | |
1035 gaim_conv_chat_write(GAIM_CONV_CHAT(conv), gc->account->username, buf, | |
1036 GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
1037 g_free(buf); | |
1038 | |
1039 } | |
1040 | |
1041 if (args && args[0] && (strlen(args[0]) > 255)) { | |
1042 *error = g_strdup(_("Topic too long")); | |
1043 return GAIM_CMD_RET_FAILED; | |
1044 } | |
1045 | |
9272 | 1046 silcgaim_chat_set_topic(gc, id, args ? args[0] : NULL); |
1047 | |
1048 return GAIM_CMD_RET_OK; | |
1049 } | |
1050 | |
1051 static GaimCmdRet silcgaim_cmd_chat_join(GaimConversation *conv, | |
9597 | 1052 const char *cmd, char **args, char **error, void *data) |
9272 | 1053 { |
1054 GHashTable *comp; | |
1055 | |
1056 if(!args || !args[0]) | |
1057 return GAIM_CMD_RET_FAILED; | |
1058 | |
1059 comp = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
1060 | |
1061 g_hash_table_replace(comp, "channel", args[0]); | |
1062 if(args[1]) | |
1063 g_hash_table_replace(comp, "passphrase", args[1]); | |
1064 | |
1065 silcgaim_chat_join(gaim_conversation_get_gc(conv), comp); | |
1066 | |
1067 g_hash_table_destroy(comp); | |
1068 return GAIM_CMD_RET_OK; | |
1069 } | |
1070 | |
1071 static GaimCmdRet silcgaim_cmd_chat_list(GaimConversation *conv, | |
9597 | 1072 const char *cmd, char **args, char **error, void *data) |
9272 | 1073 { |
1074 GaimConnection *gc; | |
1075 gc = gaim_conversation_get_gc(conv); | |
1076 gaim_roomlist_show_with_account(gaim_connection_get_account(gc)); | |
1077 return GAIM_CMD_RET_OK; | |
1078 } | |
1079 | |
1080 static GaimCmdRet silcgaim_cmd_whois(GaimConversation *conv, | |
9597 | 1081 const char *cmd, char **args, char **error, void *data) |
9272 | 1082 { |
1083 GaimConnection *gc; | |
1084 | |
1085 gc = gaim_conversation_get_gc(conv); | |
1086 | |
1087 if (gc == NULL) | |
1088 return GAIM_CMD_RET_FAILED; | |
1089 | |
1090 silcgaim_get_info(gc, args[0]); | |
1091 | |
1092 return GAIM_CMD_RET_OK; | |
1093 } | |
1094 | |
1095 static GaimCmdRet silcgaim_cmd_msg(GaimConversation *conv, | |
9597 | 1096 const char *cmd, char **args, char **error, void *data) |
9272 | 1097 { |
1098 int ret; | |
1099 GaimConnection *gc; | |
1100 | |
1101 gc = gaim_conversation_get_gc(conv); | |
1102 | |
1103 if (gc == NULL) | |
1104 return GAIM_CMD_RET_FAILED; | |
1105 | |
1106 ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND); | |
1107 | |
1108 if (ret) | |
1109 return GAIM_CMD_RET_OK; | |
1110 else | |
1111 return GAIM_CMD_RET_FAILED; | |
1112 } | |
1113 | |
1114 static GaimCmdRet silcgaim_cmd_query(GaimConversation *conv, | |
9597 | 1115 const char *cmd, char **args, char **error, void *data) |
9272 | 1116 { |
1117 int ret = 1; | |
1118 GaimConversation *convo; | |
1119 GaimConnection *gc; | |
1120 GaimAccount *account; | |
1121 | |
9488 | 1122 if (!args || !args[0]) { |
1123 *error = g_strdup(_("You must specify a nick")); | |
9272 | 1124 return GAIM_CMD_RET_FAILED; |
9488 | 1125 } |
9272 | 1126 |
1127 gc = gaim_conversation_get_gc(conv); | |
1128 | |
1129 if (gc == NULL) | |
1130 return GAIM_CMD_RET_FAILED; | |
1131 | |
1132 account = gaim_connection_get_account(gc); | |
1133 | |
11338 | 1134 convo = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, args[0]); |
9272 | 1135 |
1136 if (args[1]) { | |
1137 ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND); | |
1138 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc), | |
1139 args[1], GAIM_MESSAGE_SEND, time(NULL)); | |
1140 } | |
1141 | |
1142 if (ret) | |
1143 return GAIM_CMD_RET_OK; | |
1144 else | |
1145 return GAIM_CMD_RET_FAILED; | |
1146 } | |
1147 | |
1148 static GaimCmdRet silcgaim_cmd_motd(GaimConversation *conv, | |
9597 | 1149 const char *cmd, char **args, char **error, void *data) |
9272 | 1150 { |
1151 GaimConnection *gc; | |
1152 SilcGaim sg; | |
9488 | 1153 char *tmp; |
9272 | 1154 |
1155 gc = gaim_conversation_get_gc(conv); | |
1156 | |
1157 if (gc == NULL) | |
1158 return GAIM_CMD_RET_FAILED; | |
1159 | |
1160 sg = gc->proto_data; | |
1161 | |
1162 if (sg == NULL) | |
1163 return GAIM_CMD_RET_FAILED; | |
1164 | |
1165 if (!sg->motd) { | |
9488 | 1166 *error = g_strdup(_("There is no Message of the Day associated with this connection")); |
9272 | 1167 return GAIM_CMD_RET_FAILED; |
1168 } | |
1169 | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10547
diff
changeset
|
1170 tmp = g_markup_escape_text(sg->motd, -1); |
9488 | 1171 gaim_notify_formatted(gc, NULL, _("Message of the Day"), NULL, |
1172 tmp, NULL, NULL); | |
1173 g_free(tmp); | |
9272 | 1174 |
1175 return GAIM_CMD_RET_OK; | |
1176 } | |
1177 | |
1178 static GaimCmdRet silcgaim_cmd_detach(GaimConversation *conv, | |
9597 | 1179 const char *cmd, char **args, char **error, void *data) |
9272 | 1180 { |
1181 GaimConnection *gc; | |
1182 SilcGaim sg; | |
1183 | |
1184 gc = gaim_conversation_get_gc(conv); | |
1185 | |
1186 if (gc == NULL) | |
1187 return GAIM_CMD_RET_FAILED; | |
1188 | |
1189 sg = gc->proto_data; | |
1190 | |
1191 if (sg == NULL) | |
1192 return GAIM_CMD_RET_FAILED; | |
1193 | |
1194 silc_client_command_call(sg->client, sg->conn, "DETACH"); | |
1195 sg->detaching = TRUE; | |
1196 | |
1197 return GAIM_CMD_RET_OK; | |
1198 } | |
1199 | |
9488 | 1200 static GaimCmdRet silcgaim_cmd_cmode(GaimConversation *conv, |
9597 | 1201 const char *cmd, char **args, char **error, void *data) |
9488 | 1202 { |
1203 GaimConnection *gc; | |
1204 SilcGaim sg; | |
1205 SilcChannelEntry channel; | |
1206 char *silccmd, *silcargs, *msg, tmp[256]; | |
1207 const char *chname; | |
1208 | |
1209 gc = gaim_conversation_get_gc(conv); | |
1210 | |
1211 if (gc == NULL || !args || gc->proto_data == NULL) | |
1212 return GAIM_CMD_RET_FAILED; | |
1213 | |
1214 sg = gc->proto_data; | |
1215 | |
1216 if (args[0]) | |
1217 chname = args[0]; | |
1218 else | |
1219 chname = gaim_conversation_get_name(conv); | |
1220 | |
1221 if (!args[1]) { | |
1222 channel = silc_client_get_channel(sg->client, sg->conn, | |
1223 (char *)chname); | |
1224 if (!channel) { | |
1225 *error = g_strdup_printf(_("channel %s not found"), chname); | |
1226 return GAIM_CMD_RET_FAILED; | |
1227 } | |
1228 if (channel->mode) { | |
1229 silcgaim_get_chmode_string(channel->mode, tmp, sizeof(tmp)); | |
1230 msg = g_strdup_printf(_("channel modes for %s: %s"), chname, tmp); | |
1231 } else { | |
1232 msg = g_strdup_printf(_("no channel modes are set on %s"), chname); | |
1233 } | |
1234 gaim_conv_chat_write(GAIM_CONV_CHAT(conv), "", | |
1235 msg, GAIM_MESSAGE_SYSTEM|GAIM_MESSAGE_NO_LOG, time(NULL)); | |
1236 g_free(msg); | |
1237 return GAIM_CMD_RET_OK; | |
1238 } | |
1239 | |
1240 silcargs = g_strjoinv(" ", args); | |
1241 silccmd = g_strconcat(cmd, " ", args ? silcargs : NULL, NULL); | |
1242 g_free(silcargs); | |
1243 if (!silc_client_command_call(sg->client, sg->conn, silccmd)) { | |
1244 g_free(silccmd); | |
1245 *error = g_strdup_printf(_("Failed to set cmodes for %s"), args[0]); | |
1246 return GAIM_CMD_RET_FAILED; | |
1247 } | |
1248 g_free(silccmd); | |
1249 | |
1250 return GAIM_CMD_RET_OK; | |
1251 } | |
1252 | |
9353 | 1253 static GaimCmdRet silcgaim_cmd_generic(GaimConversation *conv, |
9597 | 1254 const char *cmd, char **args, char **error, void *data) |
9272 | 1255 { |
1256 GaimConnection *gc; | |
1257 SilcGaim sg; | |
9353 | 1258 char *silccmd, *silcargs; |
9272 | 1259 |
1260 gc = gaim_conversation_get_gc(conv); | |
1261 | |
1262 if (gc == NULL) | |
1263 return GAIM_CMD_RET_FAILED; | |
1264 | |
1265 sg = gc->proto_data; | |
1266 | |
1267 if (sg == NULL) | |
1268 return GAIM_CMD_RET_FAILED; | |
1269 | |
9353 | 1270 silcargs = g_strjoinv(" ", args); |
1271 silccmd = g_strconcat(cmd, " ", args ? silcargs : NULL, NULL); | |
1272 g_free(silcargs); | |
1273 if (!silc_client_command_call(sg->client, sg->conn, silccmd)) { | |
1274 g_free(silccmd); | |
9488 | 1275 *error = g_strdup_printf(_("Unknown command: %s, (may be a Gaim bug)"), cmd); |
9353 | 1276 return GAIM_CMD_RET_FAILED; |
1277 } | |
1278 g_free(silccmd); | |
9272 | 1279 |
1280 return GAIM_CMD_RET_OK; | |
1281 } | |
1282 | |
9359 | 1283 static GaimCmdRet silcgaim_cmd_quit(GaimConversation *conv, |
9597 | 1284 const char *cmd, char **args, char **error, void *data) |
9359 | 1285 { |
1286 GaimConnection *gc; | |
1287 SilcGaim sg; | |
1288 | |
1289 gc = gaim_conversation_get_gc(conv); | |
1290 | |
1291 if (gc == NULL) | |
1292 return GAIM_CMD_RET_FAILED; | |
1293 | |
1294 sg = gc->proto_data; | |
1295 | |
1296 if (sg == NULL) | |
1297 return GAIM_CMD_RET_FAILED; | |
1298 | |
1299 silc_client_command_call(sg->client, sg->conn, NULL, | |
1300 "QUIT", (args && args[0]) ? args[0] : "Download Gaim: " GAIM_WEBSITE, NULL); | |
1301 | |
1302 return GAIM_CMD_RET_OK; | |
1303 } | |
1304 | |
1305 static GaimCmdRet silcgaim_cmd_call(GaimConversation *conv, | |
9597 | 1306 const char *cmd, char **args, char **error, void *data) |
9359 | 1307 { |
1308 GaimConnection *gc; | |
1309 SilcGaim sg; | |
1310 | |
1311 gc = gaim_conversation_get_gc(conv); | |
1312 | |
1313 if (gc == NULL) | |
1314 return GAIM_CMD_RET_FAILED; | |
1315 | |
1316 sg = gc->proto_data; | |
1317 | |
1318 if (sg == NULL) | |
1319 return GAIM_CMD_RET_FAILED; | |
1320 | |
9488 | 1321 if (!silc_client_command_call(sg->client, sg->conn, args[0])) { |
1322 *error = g_strdup_printf(_("Unknown command: %s"), args[0]); | |
9359 | 1323 return GAIM_CMD_RET_FAILED; |
9488 | 1324 } |
9359 | 1325 |
1326 return GAIM_CMD_RET_OK; | |
1327 } | |
1328 | |
9030 | 1329 |
8849 | 1330 /************************** Plugin Initialization ****************************/ |
1331 | |
9272 | 1332 static void |
1333 silcgaim_register_commands(void) | |
1334 { | |
9353 | 1335 gaim_cmd_register("part", "w", GAIM_CMD_P_PRPL, |
1336 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | | |
1337 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, | |
9597 | 1338 "prpl-silc", silcgaim_cmd_chat_part, _("part [channel]: Leave the chat"), NULL); |
9353 | 1339 gaim_cmd_register("leave", "w", GAIM_CMD_P_PRPL, |
1340 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | | |
1341 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, | |
9597 | 1342 "prpl-silc", silcgaim_cmd_chat_part, _("leave [channel]: Leave the chat"), NULL); |
9272 | 1343 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL, |
1344 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1345 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", | |
9597 | 1346 silcgaim_cmd_chat_topic, _("topic [<new topic>]: View or change the topic"), NULL); |
9272 | 1347 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL, |
1348 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | | |
1349 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, | |
1350 "prpl-silc", silcgaim_cmd_chat_join, | |
9597 | 1351 _("join <channel> [<password>]: Join a chat on this network"), NULL); |
9272 | 1352 gaim_cmd_register("list", "", GAIM_CMD_P_PRPL, |
1353 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1354 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", | |
9597 | 1355 silcgaim_cmd_chat_list, _("list: List channels on this network"), NULL); |
9272 | 1356 gaim_cmd_register("whois", "w", GAIM_CMD_P_PRPL, |
1357 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1358 "prpl-silc", | |
9597 | 1359 silcgaim_cmd_whois, _("whois <nick>: View nick's information"), NULL); |
9272 | 1360 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL, |
1361 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1362 "prpl-silc", silcgaim_cmd_msg, | |
9597 | 1363 _("msg <nick> <message>: Send a private message to a user"), NULL); |
9272 | 1364 gaim_cmd_register("query", "ws", GAIM_CMD_P_PRPL, |
1365 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1366 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_query, | |
9597 | 1367 _("query <nick> [<message>]: Send a private message to a user"), NULL); |
9272 | 1368 gaim_cmd_register("motd", "", GAIM_CMD_P_PRPL, |
1369 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1370 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_motd, | |
9597 | 1371 _("motd: View the server's Message Of The Day"), NULL); |
9272 | 1372 gaim_cmd_register("detach", "", GAIM_CMD_P_PRPL, |
9353 | 1373 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1374 "prpl-silc", silcgaim_cmd_detach, | |
9597 | 1375 _("detach: Detach this session"), NULL); |
9359 | 1376 gaim_cmd_register("quit", "s", GAIM_CMD_P_PRPL, |
1377 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1378 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_quit, | |
9597 | 1379 _("quit [message]: Disconnect from the server, with an optional message"), NULL); |
9359 | 1380 gaim_cmd_register("call", "s", GAIM_CMD_P_PRPL, |
1381 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1382 "prpl-silc", silcgaim_cmd_call, | |
9597 | 1383 _("call <command>: Call any silc client command"), NULL); |
1384 /* These below just get passed through for the silc client library to deal | |
1385 * with */ | |
9359 | 1386 gaim_cmd_register("kill", "ws", GAIM_CMD_P_PRPL, |
1387 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1388 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1389 _("kill <nick> [-pubkey|<reason>]: Kill nick"), NULL); |
9359 | 1390 gaim_cmd_register("nick", "w", GAIM_CMD_P_PRPL, |
1391 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1392 "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1393 _("nick <newnick>: Change your nickname"), NULL); |
9488 | 1394 gaim_cmd_register("whowas", "ww", GAIM_CMD_P_PRPL, |
9359 | 1395 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1396 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1397 _("whowas <nick>: View nick's information"), NULL); |
9488 | 1398 gaim_cmd_register("cmode", "wws", GAIM_CMD_P_PRPL, |
1399 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1400 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_cmode, | |
9597 | 1401 _("cmode <channel> [+|-<modes>] [arguments]: Change or display channel modes"), NULL); |
9359 | 1402 gaim_cmd_register("cumode", "wws", GAIM_CMD_P_PRPL, |
1403 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1404 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1405 _("cumode <channel> +|-<modes> <nick>: Change nick's modes on channel"), NULL); |
9272 | 1406 gaim_cmd_register("umode", "w", GAIM_CMD_P_PRPL, |
1407 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
9353 | 1408 "prpl-silc", silcgaim_cmd_generic, |
9597 | 1409 _("umode <usermodes>: Set your modes in the network"), NULL); |
9359 | 1410 gaim_cmd_register("oper", "s", GAIM_CMD_P_PRPL, |
1411 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1412 "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1413 _("oper <nick> [-pubkey]: Get server operator privileges"), NULL); |
9359 | 1414 gaim_cmd_register("invite", "ws", GAIM_CMD_P_PRPL, |
1415 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1416 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1417 _("invite <channel> [-|+]<nick>: invite nick or add/remove from channel invite list"), NULL); |
9359 | 1418 gaim_cmd_register("kick", "wws", GAIM_CMD_P_PRPL, |
1419 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1420 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1421 _("kick <channel> <nick> [comment]: Kick client from channel"), NULL); |
9488 | 1422 gaim_cmd_register("info", "w", GAIM_CMD_P_PRPL, |
9359 | 1423 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1424 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1425 _("info [server]: View server administrative details"), NULL); |
9359 | 1426 gaim_cmd_register("ban", "ww", GAIM_CMD_P_PRPL, |
1427 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1428 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1429 _("ban [<channel> +|-<nick>]: Ban client from channel"), NULL); |
9488 | 1430 gaim_cmd_register("getkey", "w", GAIM_CMD_P_PRPL, |
1431 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1432 "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1433 _("getkey <nick|server>: Retrieve client's or server's public key"), NULL); |
9488 | 1434 gaim_cmd_register("stats", "", GAIM_CMD_P_PRPL, |
1435 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1436 "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1437 _("stats: View server and network statistics"), NULL); |
9359 | 1438 gaim_cmd_register("ping", "", GAIM_CMD_P_PRPL, |
1439 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1440 "prpl-silc", silcgaim_cmd_generic, | |
9597 | 1441 _("ping: Send PING to the connected server"), NULL); |
9488 | 1442 #if 0 /* Gaim doesn't handle these yet */ |
1443 gaim_cmd_register("users", "w", GAIM_CMD_P_PRPL, | |
1444 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1445 "prpl-silc", silcgaim_cmd_users, | |
1446 _("users <channel>: List users in channel")); | |
1447 gaim_cmd_register("names", "ww", GAIM_CMD_P_PRPL, | |
1448 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | |
1449 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_names, | |
1450 _("names [-count|-ops|-halfops|-voices|-normal] <channel(s)>: List specific users in channel(s)")); | |
9359 | 1451 #endif |
9272 | 1452 } |
1453 | |
8849 | 1454 static GaimPluginPrefFrame * |
1455 silcgaim_pref_frame(GaimPlugin *plugin) | |
1456 { | |
1457 GaimPluginPrefFrame *frame; | |
1458 GaimPluginPref *ppref; | |
1459 | |
1460 frame = gaim_plugin_pref_frame_new(); | |
1461 | |
1462 ppref = gaim_plugin_pref_new_with_label(_("Instant Messages")); | |
1463 gaim_plugin_pref_frame_add(frame, ppref); | |
1464 | |
1465 ppref = gaim_plugin_pref_new_with_name_and_label( | |
1466 "/plugins/prpl/silc/sign_im", | |
1467 _("Digitally sign all IM messages")); | |
1468 gaim_plugin_pref_frame_add(frame, ppref); | |
1469 | |
1470 ppref = gaim_plugin_pref_new_with_name_and_label( | |
1471 "/plugins/prpl/silc/verify_im", | |
1472 _("Verify all IM message signatures")); | |
1473 gaim_plugin_pref_frame_add(frame, ppref); | |
1474 | |
1475 ppref = gaim_plugin_pref_new_with_label(_("Channel Messages")); | |
1476 gaim_plugin_pref_frame_add(frame, ppref); | |
1477 | |
1478 ppref = gaim_plugin_pref_new_with_name_and_label( | |
1479 "/plugins/prpl/silc/sign_chat", | |
1480 _("Digitally sign all channel messages")); | |
1481 gaim_plugin_pref_frame_add(frame, ppref); | |
1482 | |
1483 ppref = gaim_plugin_pref_new_with_name_and_label( | |
1484 "/plugins/prpl/silc/verify_chat", | |
1485 _("Verify all channel message signatures")); | |
1486 gaim_plugin_pref_frame_add(frame, ppref); | |
1487 | |
1488 return frame; | |
1489 } | |
1490 | |
1491 static GaimPluginUiInfo prefs_info = | |
1492 { | |
1493 silcgaim_pref_frame, | |
1494 }; | |
1495 | |
1496 static GaimPluginProtocolInfo prpl_info = | |
1497 { | |
1498 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | | |
1499 OPT_PROTO_PASSWORD_OPTIONAL, | |
9488 | 1500 NULL, /* user_splits */ |
1501 NULL, /* protocol_options */ | |
1502 NO_BUDDY_ICONS, /* icon_spec */ | |
1503 silcgaim_list_icon, /* list_icon */ | |
1504 silcgaim_list_emblems, /* list_emblems */ | |
1505 silcgaim_status_text, /* status_text */ | |
1506 silcgaim_tooltip_text, /* tooltip_text */ | |
1507 silcgaim_away_states, /* away_states */ | |
1508 silcgaim_blist_node_menu, /* blist_node_menu */ | |
1509 silcgaim_chat_info, /* chat_info */ | |
9754 | 1510 silcgaim_chat_info_defaults,/* chat_info_defaults */ |
9488 | 1511 silcgaim_login, /* login */ |
1512 silcgaim_close, /* close */ | |
1513 silcgaim_send_im, /* send_im */ | |
1514 silcgaim_set_info, /* set_info */ | |
1515 NULL, /* send_typing */ | |
1516 silcgaim_get_info, /* get_info */ | |
9968 | 1517 silcgaim_set_status, /* set_status */ |
9488 | 1518 silcgaim_idle_set, /* set_idle */ |
1519 silcgaim_change_passwd, /* change_passwd */ | |
1520 silcgaim_add_buddy, /* add_buddy */ | |
10869 | 1521 NULL, /* add_buddies */ |
9488 | 1522 silcgaim_remove_buddy, /* remove_buddy */ |
1523 NULL, /* remove_buddies */ | |
1524 NULL, /* add_permit */ | |
1525 NULL, /* add_deny */ | |
1526 NULL, /* rem_permit */ | |
1527 NULL, /* rem_deny */ | |
1528 NULL, /* set_permit_deny */ | |
1529 silcgaim_chat_join, /* join_chat */ | |
1530 NULL, /* reject_chat */ | |
9917 | 1531 silcgaim_get_chat_name, /* get_chat_name */ |
9488 | 1532 silcgaim_chat_invite, /* chat_invite */ |
1533 silcgaim_chat_leave, /* chat_leave */ | |
1534 NULL, /* chat_whisper */ | |
1535 silcgaim_chat_send, /* chat_send */ | |
1536 silcgaim_keepalive, /* keepalive */ | |
1537 NULL, /* register_user */ | |
1538 NULL, /* get_cb_info */ | |
1539 NULL, /* get_cb_away */ | |
1540 NULL, /* alias_buddy */ | |
1541 NULL, /* group_buddy */ | |
1542 NULL, /* rename_group */ | |
1543 NULL, /* buddy_free */ | |
1544 NULL, /* convo_closed */ | |
1545 NULL, /* normalize */ | |
1546 NULL, /* set_buddy_icon */ | |
1547 NULL, /* remove_group */ | |
1548 NULL, /* get_cb_real_name */ | |
1549 silcgaim_chat_set_topic, /* set_chat_topic */ | |
1550 NULL, /* find_blist_chat */ | |
1551 silcgaim_roomlist_get_list, /* roomlist_get_list */ | |
1552 silcgaim_roomlist_cancel, /* roomlist_cancel */ | |
1553 NULL, /* roomlist_expand_category */ | |
1554 NULL, /* can_receive_file */ | |
1555 silcgaim_ftp_send_file /* send_file */ | |
8849 | 1556 }; |
1557 | |
1558 static GaimPluginInfo info = | |
1559 { | |
9943 | 1560 GAIM_PLUGIN_MAGIC, |
1561 GAIM_MAJOR_VERSION, | |
1562 GAIM_MINOR_VERSION, | |
8849 | 1563 GAIM_PLUGIN_PROTOCOL, /**< type */ |
1564 NULL, /**< ui_requirement */ | |
1565 0, /**< flags */ | |
1566 NULL, /**< dependencies */ | |
1567 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
1568 | |
1569 "prpl-silc", /**< id */ | |
1570 "SILC", /**< name */ | |
1571 "1.0", /**< version */ | |
1572 /** summary */ | |
1573 N_("SILC Protocol Plugin"), | |
1574 /** description */ | |
1575 N_("Secure Internet Live Conferencing (SILC) Protocol"), | |
8891 | 1576 "Pekka Riikonen", /**< author */ |
1577 "http://silcnet.org/", /**< homepage */ | |
8849 | 1578 |
1579 NULL, /**< load */ | |
1580 NULL, /**< unload */ | |
1581 NULL, /**< destroy */ | |
1582 | |
1583 NULL, /**< ui_info */ | |
1584 &prpl_info, /**< extra_info */ | |
8993 | 1585 &prefs_info, /**< prefs_info */ |
9015 | 1586 silcgaim_actions |
8849 | 1587 }; |
1588 | |
1589 static void | |
1590 init_plugin(GaimPlugin *plugin) | |
1591 { | |
1592 GaimAccountOption *option; | |
10825 | 1593 GaimAccountUserSplit *split; |
8849 | 1594 char tmp[256]; |
1595 | |
1596 silc_plugin = plugin; | |
1597 | |
10825 | 1598 split = gaim_account_user_split_new(_("Network"), "silcnet.org", '@'); |
1599 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); | |
1600 | |
8849 | 1601 /* Account options */ |
1602 option = gaim_account_option_string_new(_("Connect server"), | |
1603 "server", | |
1604 "silc.silcnet.org"); | |
1605 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1606 option = gaim_account_option_int_new(_("Port"), "port", 706); | |
1607 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
10825 | 1608 g_snprintf(tmp, sizeof(tmp), "%s" G_DIR_SEPARATOR_S "public_key.pub", silcgaim_silcdir()); |
1609 option = gaim_account_option_string_new(_("Public Key file"), | |
1610 "public-key", tmp); | |
1611 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1612 g_snprintf(tmp, sizeof(tmp), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir()); | |
1613 option = gaim_account_option_string_new(_("Private Key file"), | |
1614 "private-key", tmp); | |
1615 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8849 | 1616 option = gaim_account_option_bool_new(_("Public key authentication"), |
1617 "pubkey-auth", FALSE); | |
1618 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1619 | |
1620 option = gaim_account_option_bool_new(_("Reject watching by other users"), | |
1621 "reject-watch", FALSE); | |
1622 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1623 option = gaim_account_option_bool_new(_("Block invites"), | |
1624 "block-invites", FALSE); | |
1625 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1626 option = gaim_account_option_bool_new(_("Block IMs without Key Exchange"), | |
1627 "block-ims", FALSE); | |
1628 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1629 option = gaim_account_option_bool_new(_("Reject online status attribute requests"), | |
1630 "reject-attrs", FALSE); | |
1631 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1632 | |
1633 /* Preferences */ | |
1634 gaim_prefs_add_none("/plugins/prpl/silc"); | |
1635 gaim_prefs_add_bool("/plugins/prpl/silc/sign_im", FALSE); | |
1636 gaim_prefs_add_bool("/plugins/prpl/silc/verify_im", FALSE); | |
1637 gaim_prefs_add_bool("/plugins/prpl/silc/sign_chat", FALSE); | |
1638 gaim_prefs_add_bool("/plugins/prpl/silc/verify_chat", FALSE); | |
1639 gaim_prefs_add_string("/plugins/prpl/silc/vcard", ""); | |
9272 | 1640 |
1641 silcgaim_register_commands(); | |
9353 | 1642 |
1643 #ifdef _WIN32 | |
1644 silc_net_win32_init(); | |
1645 #endif | |
8849 | 1646 } |
1647 | |
1648 GAIM_INIT_PLUGIN(silc, init_plugin, info); |