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