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