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