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