+#ifndef SILC_PLUGIN
+ 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 }
+ };
+#endif
+
+ CHAT_PROTOCOL_REC *rec;
+ SilcClientParams params;
+ const char *def_cipher, *def_hash, *def_hmac;
+
+#ifndef SILC_PLUGIN
+ args_register(silc_options);
+#endif
+
+ /* Settings */
+#ifndef SILC_PLUGIN
+ settings_add_bool("server", "skip_motd", FALSE);
+ settings_add_str("server", "alternate_nick", NULL);
+#endif
+ 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_bool("server", "key_exchange_rekey_pfs", FALSE);
+ settings_add_int("server", "heartbeat", 300);
+ settings_add_bool("server", "ignore_message_signatures", FALSE);
+ settings_add_str("server", "session_filename", "session.$chatnet");
+ settings_add_bool("server", "sign_channel_messages", FALSE);
+ settings_add_bool("server", "sign_private_messages", FALSE);
+ settings_add_str("silc", "nickname_format", "%n#%a");
+
+ /* 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);
+#ifndef SILC_PLUGIN
+ signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+#endif
+
+#if defined (SILC_PLUGIN) && defined (SILC_DEBUG)
+ if (settings_get_bool("debug") == TRUE)
+ sig_setup_changed();
+#endif
+
+ silc_init_userinfo();
+
+ silc_log_set_callback(SILC_LOG_INFO, silc_log_stderr, NULL);
+ silc_log_set_callback(SILC_LOG_WARNING, silc_log_stderr, NULL);
+ silc_log_set_callback(SILC_LOG_ERROR, silc_log_stderr, NULL);
+ silc_log_set_callback(SILC_LOG_FATAL, silc_log_stderr, NULL);
+
+ /* Initialize client parameters */
+ memset(¶ms, 0, sizeof(params));
+ strcat(params.nickname_format, settings_get_str("nickname_format"));
+ params.full_channel_names = TRUE;
+
+ /* 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);
+#ifdef SILC_PLUGIN
+ if (init_failed)
+ return;
+#endif
+ silc_register_hash(silc_client, def_hash);
+#ifdef SILC_PLUGIN
+ if (init_failed)
+ return;
+#endif
+ silc_register_hmac(silc_client, def_hmac);
+#ifdef SILC_PLUGIN
+ if (init_failed)
+ return;
+#endif
+ silc_pkcs_register_default();
+
+#ifdef SILC_PLUGIN
+ command_bind("silc", MODULE_NAME, (SIGNAL_FUNC) silc_opt_callback);
+#endif
+
+ /* Register SILC to the irssi */
+ rec = g_new0(CHAT_PROTOCOL_REC, 1);
+ rec->name = "SILC";
+ rec->fullname = "Secure Internet Live Conferencing";
+ rec->chatnet = "silcnet";
+ rec->create_chatnet = create_chatnet;
+ rec->create_server_setup = create_server_setup;
+ rec->create_channel_setup = create_channel_setup;
+ rec->create_server_connect = create_server_connect;
+ rec->destroy_server_connect = destroy_server_connect;
+ rec->server_init_connect = silc_server_init_connect;
+ rec->server_connect = silc_server_connect;
+ rec->channel_create = (CHANNEL_REC *(*) (SERVER_REC *, const char *,
+ const char *, int))
+ silc_channel_create;
+ rec->query_create = (QUERY_REC *(*) (const char *, const char *, int))
+ silc_query_create;
+
+ chat_protocol_register(rec);
+ g_free(rec);
+
+ silc_queue_init();
+ silc_server_init();
+ silc_channels_init();
+ silc_queries_init();
+ silc_expandos_init();
+ silc_lag_init();
+ silc_chatnets_init();
+
+#ifdef SILC_PLUGIN
+ sig_init_finished();
+ if (init_failed) {
+ silc_core_deinit();
+ return;
+ }
+#endif
+
+ module_register("silc", "core");