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