comparison libpurple/protocols/silc/silc.c @ 20776:f3cfcbbac3d8

propagate from branch 'im.pidgin.pidgin' (head 294731552d0baf5f1f37a45e0c119b2188f34ba8) to branch 'im.pidgin.cpw.resiak.disconnectreason' (head 548e06334e7772c9583776ecbd80e8d2a68fcd79)
author Will Thompson <will.thompson@collabora.co.uk>
date Fri, 05 Oct 2007 15:50:17 +0000
parents 6aca488bd8ab
children 8174f6999308
comparison
equal deleted inserted replaced
20775:d3443cb6a60f 20776:f3cfcbbac3d8
212 if (sg->resuming && !sg->detaching) 212 if (sg->resuming && !sg->detaching)
213 g_unlink(silcpurple_session_file(purple_account_get_username(sg->account))); 213 g_unlink(silcpurple_session_file(purple_account_get_username(sg->account)));
214 214
215 /* Close the connection */ 215 /* Close the connection */
216 if (!sg->detaching) 216 if (!sg->detaching)
217 purple_connection_error(gc, _("Disconnected by server")); 217 purple_connection_error_reason(gc,
218 PURPLE_REASON_NETWORK_ERROR,
219 _("Disconnected by server"));
218 else 220 else
219 /* TODO: Does this work correctly? Maybe we need to set wants_to_die? */ 221 /* TODO: Does this work correctly? Maybe we need to set wants_to_die? */
220 purple_account_disconnect(purple_connection_get_account(gc)); 222 purple_account_disconnect(purple_connection_get_account(gc));
221 break; 223 break;
222 224
223 case SILC_CLIENT_CONN_ERROR: 225 case SILC_CLIENT_CONN_ERROR:
224 purple_connection_error(gc, _("Error during connecting to SILC Server")); 226 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR,
227 _("Error during connecting to SILC Server"));
225 g_unlink(silcpurple_session_file(purple_account_get_username(sg->account))); 228 g_unlink(silcpurple_session_file(purple_account_get_username(sg->account)));
226 break; 229 break;
227 230
228 case SILC_CLIENT_CONN_ERROR_KE: 231 case SILC_CLIENT_CONN_ERROR_KE:
229 purple_connection_error(gc, _("Key Exchange failed")); 232 purple_connection_error_reason(gc, PURPLE_REASON_ENCRYPTION_ERROR,
233 _("Key Exchange failed"));
230 break; 234 break;
231 235
232 case SILC_CLIENT_CONN_ERROR_AUTH: 236 case SILC_CLIENT_CONN_ERROR_AUTH:
233 purple_connection_error(gc, _("Authentication failed")); 237 purple_connection_error_reason(gc, PURPLE_REASON_AUTHENTICATION_FAILED,
238 _("Authentication failed"));
234 break; 239 break;
235 240
236 case SILC_CLIENT_CONN_ERROR_RESUME: 241 case SILC_CLIENT_CONN_ERROR_RESUME:
237 purple_connection_error(gc, 242 purple_connection_error_reason(gc, PURPLE_REASON_OTHER_ERROR,
238 _("Resuming detached session failed. " 243 _("Resuming detached session failed. "
239 "Press Reconnect to create new connection.")); 244 "Press Reconnect to create new connection."));
240 g_unlink(silcpurple_session_file(purple_account_get_username(sg->account))); 245 g_unlink(silcpurple_session_file(purple_account_get_username(sg->account)));
241 break; 246 break;
242 247
243 case SILC_CLIENT_CONN_ERROR_TIMEOUT: 248 case SILC_CLIENT_CONN_ERROR_TIMEOUT:
244 purple_connection_error(gc, _("Connection Timeout")); 249 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR,
250 _("Connection Timeout"));
245 break; 251 break;
246 } 252 }
247 253
248 /* Error */ 254 /* Error */
249 sg->conn = NULL; 255 sg->conn = NULL;
260 const char *dfile; 266 const char *dfile;
261 267
262 sg = gc->proto_data; 268 sg = gc->proto_data;
263 269
264 if (status != SILC_SOCKET_OK) { 270 if (status != SILC_SOCKET_OK) {
265 purple_connection_error(gc, _("Connection failed")); 271 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR,
272 _("Connection failed"));
266 silc_pkcs_public_key_free(sg->public_key); 273 silc_pkcs_public_key_free(sg->public_key);
267 silc_pkcs_private_key_free(sg->private_key); 274 silc_pkcs_private_key_free(sg->private_key);
268 silc_free(sg); 275 silc_free(sg);
269 gc->proto_data = NULL; 276 gc->proto_data = NULL;
270 return; 277 return;
306 g_return_if_fail(gc != NULL); 313 g_return_if_fail(gc != NULL);
307 314
308 sg = gc->proto_data; 315 sg = gc->proto_data;
309 316
310 if (source < 0) { 317 if (source < 0) {
311 purple_connection_error(gc, _("Connection failed")); 318 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR,
319 _("Connection failed"));
312 silc_pkcs_public_key_free(sg->public_key); 320 silc_pkcs_public_key_free(sg->public_key);
313 silc_pkcs_private_key_free(sg->private_key); 321 silc_pkcs_private_key_free(sg->private_key);
314 silc_free(sg); 322 silc_free(sg);
315 gc->proto_data = NULL; 323 gc->proto_data = NULL;
316 return; 324 return;
347 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir()); 355 g_snprintf(prd, sizeof(prd), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcpurple_silcdir());
348 if (!silc_load_key_pair((char *)purple_account_get_string(account, "public-key", pkd), 356 if (!silc_load_key_pair((char *)purple_account_get_string(account, "public-key", pkd),
349 (char *)purple_account_get_string(account, "private-key", prd), 357 (char *)purple_account_get_string(account, "private-key", prd),
350 (gc->password == NULL) ? "" : gc->password, 358 (gc->password == NULL) ? "" : gc->password,
351 &sg->public_key, &sg->private_key)) { 359 &sg->public_key, &sg->private_key)) {
352 g_snprintf(pkd, sizeof(pkd), _("Could not load SILC key pair")); 360 purple_connection_error_reason(gc, PURPLE_REASON_OTHER_ERROR,
353 purple_connection_error(gc, pkd); 361 _("Could not load SILC key pair"));
354 gc->proto_data = NULL; 362 gc->proto_data = NULL;
355 silc_free(sg); 363 silc_free(sg);
356 return; 364 return;
357 } 365 }
358 366
361 purple_account_get_string(account, "server", 369 purple_account_get_string(account, "server",
362 "silc.silcnet.org"), 370 "silc.silcnet.org"),
363 purple_account_get_int(account, "port", 706), 371 purple_account_get_int(account, "port", 706),
364 silcpurple_login_connected, gc) == NULL) 372 silcpurple_login_connected, gc) == NULL)
365 { 373 {
366 purple_connection_error(gc, _("Unable to create connection")); 374 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR,
375 _("Unable to create connection"));
367 gc->proto_data = NULL; 376 gc->proto_data = NULL;
368 silc_free(sg); 377 silc_free(sg);
369 return; 378 return;
370 } 379 }
371 } 380 }
390 strcat(params.nickname_format, "%n#a"); 399 strcat(params.nickname_format, "%n#a");
391 400
392 /* Allocate SILC client */ 401 /* Allocate SILC client */
393 client = silc_client_alloc(&ops, &params, gc, NULL); 402 client = silc_client_alloc(&ops, &params, gc, NULL);
394 if (!client) { 403 if (!client) {
395 purple_connection_error(gc, _("Out of memory")); 404 purple_connection_error_reason(gc, PURPLE_REASON_OTHER_ERROR,
405 _("Out of memory"));
396 return; 406 return;
397 } 407 }
398 408
399 /* Get username, real name and local hostname for SILC library */ 409 /* Get username, real name and local hostname for SILC library */
400 if (!purple_account_get_username(account)) 410 if (!purple_account_get_username(account))
433 443
434 /* Init SILC client */ 444 /* Init SILC client */
435 if (!silc_client_init(client, username, hostname, realname, 445 if (!silc_client_init(client, username, hostname, realname,
436 silcpurple_running, account)) { 446 silcpurple_running, account)) {
437 gc->wants_to_die = TRUE; 447 gc->wants_to_die = TRUE;
438 purple_connection_error(gc, _("Cannot initialize SILC protocol")); 448 purple_connection_error_reason(gc, PURPLE_REASON_OTHER_ERROR,
449 _("Cannot initialize SILC protocol"));
439 return; 450 return;
440 } 451 }
441 452
442 /* Check the ~/.silc dir and create it, and new key pair if necessary. */ 453 /* Check the ~/.silc dir and create it, and new key pair if necessary. */
443 if (!silcpurple_check_silc_dir(gc)) { 454 if (!silcpurple_check_silc_dir(gc)) {
444 gc->wants_to_die = TRUE; 455 gc->wants_to_die = TRUE;
445 purple_connection_error(gc, _("Error loading SILC key pair")); 456 purple_connection_error_reason(gc, PURPLE_REASON_OTHER_ERROR,
457 _("Error loading SILC key pair"));
446 return; 458 return;
447 } 459 }
448 460
449 /* Schedule SILC using Glib's event loop */ 461 /* Schedule SILC using Glib's event loop */
450 scheduler = purple_timeout_add(300, (GSourceFunc)silcpurple_scheduler, client); 462 scheduler = purple_timeout_add(300, (GSourceFunc)silcpurple_scheduler, client);