+ if (!silc_client_init(silc_client))
+ exit(1);
+
+ /* register SILC scheduler */
+ idletag = g_timeout_add(5, (GSourceFunc) my_silc_scheduler, NULL);
+}
+
+/* Init SILC. Called from src/fe-text/silc.c */
+
+void silc_core_init(void)
+{
+ static struct poptOption silc_options[] = {
+ { NULL, '\0', POPT_ARG_CALLBACK, (void *)&silc_opt_callback, '\0', NULL },
+ { "list-ciphers", 0, POPT_ARG_NONE, NULL, 0,
+ "List supported ciphers", NULL },
+ { "list-hash-funcs", 0, POPT_ARG_NONE, NULL, 0,
+ "List supported hash functions", NULL },
+ { "list-hmacs", 0, POPT_ARG_NONE, NULL, 0,
+ "List supported HMACs", NULL },
+ { "list-pkcs", 0, POPT_ARG_NONE, NULL, 0,
+ "List supported PKCSs", NULL },
+#ifdef SILC_DEBUG
+ { "debug", 'd', POPT_ARG_STRING, NULL, 0,
+ "Enable debugging", "STRING" },
+#endif /* SILC_DEBUG */
+ { "create-key-pair", 'C', POPT_ARG_NONE, NULL, 0,
+ "Create new public key pair", NULL },
+ { "pkcs", 0, POPT_ARG_STRING, &opt_pkcs, 0,
+ "Set the PKCS of the public key pair (-C)", "PKCS" },
+ { "bits", 0, POPT_ARG_INT, &opt_bits, 0,
+ "Set the length of the public key pair (-C)", "VALUE" },
+ { "passphrase-change", 'P', POPT_ARG_STRING, NULL, 0,
+ "Change the passphrase of private key file", "FILE" },
+ { "show-key", 'S', POPT_ARG_STRING, NULL, 0,
+ "Show the contents of the public key", "FILE" },
+ { NULL, '\0', 0, NULL }
+ };
+
+ CHAT_PROTOCOL_REC *rec;
+ SilcClientParams params;
+ const char *def_cipher, *def_hash, *def_hmac;
+
+ args_register(silc_options);
+
+ /* Settings */
+ settings_add_bool("server", "skip_motd", FALSE);
+ settings_add_str("server", "alternate_nick", NULL);
+ settings_add_bool("server", "use_auto_addr", FALSE);
+ settings_add_str("server", "auto_bind_ip", "");
+ settings_add_str("server", "auto_public_ip", "");
+ settings_add_int("server", "auto_bind_port", 0);
+ settings_add_str("server", "crypto_default_cipher", SILC_DEFAULT_CIPHER);
+ settings_add_str("server", "crypto_default_hash", SILC_DEFAULT_HASH);
+ settings_add_str("server", "crypto_default_hmac", SILC_DEFAULT_HMAC);
+ settings_add_int("server", "key_exchange_timeout_secs", 120);
+ settings_add_int("server", "key_exchange_rekey_secs", 3600);
+ settings_add_int("server", "connauth_request_secs", 2);
+ settings_add_int("server", "heartbeat", 300);
+ settings_add_bool("server", "ignore_message_signatures", FALSE);
+ settings_add_str("server", "session_filename", "session.$chatnet");
+
+ /* Requested Attributes settings */
+ settings_add_bool("silc", "attr_allow", TRUE);
+ settings_add_str("silc", "attr_vcard", "");
+ settings_add_str("silc", "attr_services", "");
+ settings_add_str("silc", "attr_status_mood", "NORMAL");
+ settings_add_str("silc", "attr_status_text", "");
+ settings_add_str("silc", "attr_status_message", NULL);
+ settings_add_str("silc", "attr_preferred_language", "");
+ settings_add_str("silc", "attr_preferred_contact", "CHAT");
+ settings_add_bool("silc", "attr_timezone", TRUE);
+ settings_add_str("silc", "attr_geolocation", "");
+ settings_add_str("silc", "attr_device_info", NULL);
+ settings_add_str("silc", "attr_public_keys", "");
+
+#ifdef SILC_DEBUG
+ settings_add_bool("debug", "debug", FALSE);
+ settings_add_str("debug", "debug_string", "");
+#endif
+
+ signal_add("setup changed", (SIGNAL_FUNC) sig_setup_changed);
+ signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+
+ silc_init_userinfo();
+
+ /* Initialize client parameters */
+ memset(¶ms, 0, sizeof(params));
+ strcat(params.nickname_format, "%n@%h%a");
+ params.nickname_parse = silc_nickname_format_parse;
+ params.rekey_secs = settings_get_int("key_exchange_rekey_secs");
+ params.connauth_request_secs = settings_get_int("connauth_request_secs");
+
+ /* Allocate SILC client */
+ silc_client = silc_client_alloc(&ops, ¶ms, NULL, silc_version_string);
+
+ /* Get the ciphers and stuff from config file */
+ def_cipher = settings_get_str("crypto_default_cipher");
+ def_hash = settings_get_str("crypto_default_hash");
+ def_hmac = settings_get_str("crypto_default_hmac");
+ silc_register_cipher(silc_client, def_cipher);
+ silc_register_hash(silc_client, def_hash);
+ silc_register_hmac(silc_client, def_hmac);
+ silc_pkcs_register_default();
+
+ /* Get user information */
+ silc_client->username = g_strdup(settings_get_str("user_name"));
+ silc_client->nickname = g_strdup(settings_get_str("nick"));
+ silc_client->hostname = silc_net_localhost();
+ silc_client->realname = g_strdup(settings_get_str("real_name"));
+
+ silc_log_set_callback(SILC_LOG_INFO, silc_log_misc, NULL);
+ silc_log_set_callback(SILC_LOG_WARNING, silc_log_misc, NULL);
+ silc_log_set_callback(SILC_LOG_ERROR, silc_log_misc, NULL);
+ silc_log_set_callback(SILC_LOG_FATAL, silc_log_misc, NULL);