X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Firssi%2Fsrc%2Fsilc%2Fcore%2Fsilc-channels.c;h=459dedd6a5d1d332b8c95d61f37703b026652749;hb=017dec75a98209fbef49eb496c2269b0c49e736d;hp=f57ff33cf9a9980adc48569088bc3f65ed516dbb;hpb=503a00a28b53f49f861035e3de759aed7ffc8111;p=silc.git diff --git a/apps/irssi/src/silc/core/silc-channels.c b/apps/irssi/src/silc/core/silc-channels.c index f57ff33c..459dedd6 100644 --- a/apps/irssi/src/silc/core/silc-channels.c +++ b/apps/irssi/src/silc/core/silc-channels.c @@ -41,6 +41,7 @@ #include "window-item-def.h" #include "fe-common/core/printtext.h" +#include "fe-common/silc/module-formats.h" SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server, const char *name, int automatic) @@ -75,15 +76,23 @@ static void silc_channels_join(SILC_SERVER_REC *server, const char *channels, int automatic) { char **list, **tmp, *channel; + SILC_CHANNEL_REC *chanrec; list = g_strsplit(channels, ",", -1); for (tmp = list; *tmp != NULL; tmp++) { channel = **tmp == '#' ? g_strdup(*tmp) : g_strconcat("#", *tmp, NULL); - silc_channel_create(server, channel, FALSE); + + chanrec = silc_channel_find(server, channel); + if (chanrec) { + g_free(channel); + continue; + } + silc_command_exec(server, "JOIN", channel); g_free(channel); } + g_strfreev(list); } @@ -93,6 +102,15 @@ static void sig_connected(SILC_SERVER_REC *server) server->channels_join = (void *) silc_channels_join; } +/* "server quit" signal from the core to indicate that QUIT command + was called. */ + +static void sig_server_quit(SILC_SERVER_REC *server, const char *msg) +{ + if (IS_SILC_SERVER(server) && server->conn && server->conn->sock) + silc_command_exec(server, "QUIT", msg); +} + /* * "event join". Joined to a channel. */ @@ -234,12 +252,14 @@ static void event_invite(SILC_SERVER_REC *server, va_list va) { SilcClientEntry client; SilcChannelEntry channel; + char *channel_name; - client = va_arg(va, SilcClientEntry); channel = va_arg(va, SilcChannelEntry); + channel_name = va_arg(va, char *); + client = va_arg(va, SilcClientEntry); - signal_emit("message invite", 4, server, channel->channel_name, - client->nickname, client->username); + signal_emit("message invite", 4, server, channel ? channel->channel_name : + channel_name, client->nickname, client->username); } /* @@ -268,15 +288,24 @@ static void event_nick(SILC_SERVER_REC *server, va_list va) static void event_cmode(SILC_SERVER_REC *server, va_list va) { SILC_CHANNEL_REC *chanrec; + void *entry; SilcClientEntry client; + SilcServerEntry server_entry; SilcChannelEntry channel; char *mode; uint32 modei; + SilcIdType idtype; - client = va_arg(va, SilcClientEntry); + idtype = va_arg(va, int); + entry = va_arg(va, void *); modei = va_arg(va, uint32); + (void)va_arg(va, char *); + (void)va_arg(va, char *); channel = va_arg(va, SilcChannelEntry); - mode = silc_client_chmode(modei, channel); + + mode = silc_client_chmode(modei, + channel->channel_key->cipher->name, + channel->hmac->hmac->name); chanrec = silc_channel_find_entry(server, channel); if (chanrec != NULL) { @@ -285,11 +314,19 @@ static void event_cmode(SILC_SERVER_REC *server, va_list va) signal_emit("channel mode changed", 1, chanrec); } - /*signal_emit("message mode", 5, server, chanrec->name, - client->nickname, client->username, mode);*/ - printtext(server, channel->channel_name, MSGLEVEL_MODES, - "mode/%s [%s] by %s", channel->channel_name, mode, - client->nickname); + if (idtype == SILC_ID_CLIENT) { + client = (SilcClientEntry)entry; + printformat_module("fe-common/silc", server, channel->channel_name, + MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE, + channel->channel_name, mode ? mode : "removed all", + client->nickname); + } else { + server_entry = (SilcServerEntry)entry; + printformat_module("fe-common/silc", server, channel->channel_name, + MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE, + channel->channel_name, mode ? mode : "removed all", + server_entry->server_name); + } g_free(mode); } @@ -320,20 +357,27 @@ static void event_cumode(SILC_SERVER_REC *server, va_list va) chanrec->chanop = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0; } - - nick = silc_nicklist_find(chanrec, client); + + nick = silc_nicklist_find(chanrec, destclient); if (nick != NULL) { nick->op = (mode & SILC_CHANNEL_UMODE_CHANOP) != 0; + nick->founder = (mode & SILC_CHANNEL_UMODE_CHANFO) != 0; signal_emit("nick mode changed", 2, chanrec, nick); } } - /*signal_emit("message mode", 5, server, chanrec->name, - client->nickname, client->username, modestr);*/ - printtext(server, channel->channel_name, MSGLEVEL_MODES, - "mode/%s [%s] by %s", channel->channel_name, modestr, - client->nickname); - + printformat_module("fe-common/silc", server, channel->channel_name, + MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE, + channel->channel_name, destclient->nickname, + modestr ? modestr : "removed all", + client->nickname); + + if (mode & SILC_CHANNEL_UMODE_CHANFO) + printformat_module("fe-common/silc", + server, channel->channel_name, MSGLEVEL_CRAP, + SILCTXT_CHANNEL_FOUNDER, + channel->channel_name, destclient->nickname); + g_free(modestr); } @@ -355,7 +399,7 @@ static void event_motd(SILC_SERVER_REC *server, va_list va) static void event_channel_change(SILC_SERVER_REC *server, va_list va) { - + /* Nothing interesting to do */ } /* @@ -364,7 +408,18 @@ static void event_channel_change(SILC_SERVER_REC *server, va_list va) static void event_server_signoff(SILC_SERVER_REC *server, va_list va) { - + SilcClientEntry *clients; + uint32 clients_count; + int i; + + (void)va_arg(va, void *); + clients = va_arg(va, SilcClientEntry *); + clients_count = va_arg(va, uint32); + + for (i = 0; i < clients_count; i++) + signal_emit("message quit", 4, server, clients[i]->nickname, + clients[i]->username ? clients[i]->username : "", + "server signoff"); } /* @@ -373,7 +428,38 @@ static void event_server_signoff(SILC_SERVER_REC *server, va_list va) static void event_kick(SILC_SERVER_REC *server, va_list va) { + SilcClientConnection conn = server->conn; + SilcClientEntry client_entry; + SilcChannelEntry channel_entry; + char *tmp; + SILC_CHANNEL_REC *chanrec; + + client_entry = va_arg(va, SilcClientEntry); + tmp = va_arg(va, char *); + channel_entry = va_arg(va, SilcChannelEntry); + chanrec = silc_channel_find_entry(server, channel_entry); + + if (client_entry == conn->local_entry) { + printformat_module("fe-common/silc", server, channel_entry->channel_name, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED_YOU, + channel_entry->channel_name, tmp ? tmp : ""); + if (chanrec) { + chanrec->kicked = TRUE; + channel_destroy((CHANNEL_REC *)chanrec); + } + } else { + printformat_module("fe-common/silc", server, channel_entry->channel_name, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED, + client_entry->nickname, + channel_entry->channel_name, tmp ? tmp : ""); + + if (chanrec) { + SILC_NICK_REC *nickrec = silc_nicklist_find(chanrec, client_entry); + if (nickrec != NULL) + nicklist_remove(CHANNEL(chanrec), NICK(nickrec)); + } + } } /* @@ -382,27 +468,44 @@ static void event_kick(SILC_SERVER_REC *server, va_list va) static void event_kill(SILC_SERVER_REC *server, va_list va) { + SilcClientConnection conn = server->conn; + SilcClientEntry client_entry; + char *tmp; -} - -/* - * "event ban". Someone was banned or ban list was modified. - */ - -static void event_ban(SILC_SERVER_REC *server, va_list va) -{ + client_entry = va_arg(va, SilcClientEntry); + tmp = va_arg(va, char *); + + if (client_entry == conn->local_entry) { + printformat_module("fe-common/silc", server, NULL, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED_YOU, + tmp ? tmp : ""); + } else { + GSList *nicks, *tmpn; + nicks = nicklist_get_same_unique(SERVER(server), client_entry); + for (tmpn = nicks; tmpn != NULL; tmpn = tmpn->next->next) { + CHANNEL_REC *channel = tmpn->data; + NICK_REC *nickrec = tmpn->next->data; + nicklist_remove(channel, nickrec); + } + printformat_module("fe-common/silc", server, NULL, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_KILLED, + client_entry->nickname, + tmp ? tmp : ""); + } } +/* PART (LEAVE) command. */ + static void command_part(const char *data, SILC_SERVER_REC *server, WI_ITEM_REC *item) { SILC_CHANNEL_REC *chanrec; if (!IS_SILC_SERVER(server) || !server->connected) - return; + cmd_return_error(CMDERR_NOT_CONNECTED); - if (*data == '\0') { + if (!strcmp(data, "*") || *data == '\0') { if (!IS_SILC_CHANNEL(item)) cmd_return_error(CMDERR_NOT_JOINED); data = item->name; @@ -421,10 +524,661 @@ static void command_part(const char *data, SILC_SERVER_REC *server, channel_destroy(CHANNEL(chanrec)); } +/* ME local command. */ + +static void command_me(const char *data, SILC_SERVER_REC *server, + WI_ITEM_REC *item) +{ + SILC_CHANNEL_REC *chanrec; + char *tmpcmd = "ME", *tmp; + uint32 argc = 0; + unsigned char **argv; + uint32 *argv_lens, *argv_types; + int i; + + if (!IS_SILC_SERVER(server) || !server->connected) + cmd_return_error(CMDERR_NOT_CONNECTED); + + if (!IS_SILC_CHANNEL(item)) + cmd_return_error(CMDERR_NOT_JOINED); + + /* Now parse all arguments */ + tmp = g_strconcat(tmpcmd, " ", data, NULL); + silc_parse_command_line(tmp, &argv, &argv_lens, + &argv_types, &argc, 2); + g_free(tmp); + + if (argc < 2) + cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); + + chanrec = silc_channel_find(server, item->name); + if (chanrec == NULL) + cmd_return_error(CMDERR_CHAN_NOT_FOUND); + + /* Send the action message */ + silc_client_send_channel_message(silc_client, server->conn, + chanrec->entry, NULL, + SILC_MESSAGE_FLAG_ACTION, + argv[1], argv_lens[1], TRUE); + + printformat_module("fe-common/silc", server, chanrec->entry->channel_name, + MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, + server->conn->local_entry->nickname, argv[1]); + + for (i = 0; i < argc; i++) + silc_free(argv[i]); + silc_free(argv_lens); + silc_free(argv_types); +} + +/* ACTION local command. Same as ME but takes the channel as mandatory + argument. */ + +static void command_action(const char *data, SILC_SERVER_REC *server, + WI_ITEM_REC *item) +{ + SILC_CHANNEL_REC *chanrec; + char *tmpcmd = "ME", *tmp; + uint32 argc = 0; + unsigned char **argv; + uint32 *argv_lens, *argv_types; + int i; + + if (!IS_SILC_SERVER(server) || !server->connected) + cmd_return_error(CMDERR_NOT_CONNECTED); + + if (!IS_SILC_CHANNEL(item)) + cmd_return_error(CMDERR_NOT_JOINED); + + /* Now parse all arguments */ + tmp = g_strconcat(tmpcmd, " ", data, NULL); + silc_parse_command_line(tmp, &argv, &argv_lens, + &argv_types, &argc, 3); + g_free(tmp); + + if (argc < 3) + cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); + + chanrec = silc_channel_find(server, argv[1]); + if (chanrec == NULL) + cmd_return_error(CMDERR_CHAN_NOT_FOUND); + + /* Send the action message */ + silc_client_send_channel_message(silc_client, server->conn, + chanrec->entry, NULL, + SILC_MESSAGE_FLAG_ACTION, + argv[2], argv_lens[2], TRUE); + + printformat_module("fe-common/silc", server, chanrec->entry->channel_name, + MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, + server->conn->local_entry->nickname, argv[2]); + + for (i = 0; i < argc; i++) + silc_free(argv[i]); + silc_free(argv_lens); + silc_free(argv_types); +} + +/* NOTICE local command. */ + +static void command_notice(const char *data, SILC_SERVER_REC *server, + WI_ITEM_REC *item) +{ + SILC_CHANNEL_REC *chanrec; + char *tmpcmd = "ME", *tmp; + uint32 argc = 0; + unsigned char **argv; + uint32 *argv_lens, *argv_types; + int i; + + if (!IS_SILC_SERVER(server) || !server->connected) + cmd_return_error(CMDERR_NOT_CONNECTED); + + if (!IS_SILC_CHANNEL(item)) + cmd_return_error(CMDERR_NOT_JOINED); + + /* Now parse all arguments */ + tmp = g_strconcat(tmpcmd, " ", data, NULL); + silc_parse_command_line(tmp, &argv, &argv_lens, + &argv_types, &argc, 2); + g_free(tmp); + + if (argc < 2) + cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS); + + chanrec = silc_channel_find(server, item->name); + if (chanrec == NULL) + cmd_return_error(CMDERR_CHAN_NOT_FOUND); + + /* Send the action message */ + silc_client_send_channel_message(silc_client, server->conn, + chanrec->entry, NULL, + SILC_MESSAGE_FLAG_NOTICE, + argv[1], argv_lens[1], TRUE); + + printformat_module("fe-common/silc", server, chanrec->entry->channel_name, + MSGLEVEL_NOTICES, SILCTXT_CHANNEL_OWNNOTICE, + server->conn->local_entry->nickname, argv[1]); + + for (i = 0; i < argc; i++) + silc_free(argv[i]); + silc_free(argv_lens); + silc_free(argv_types); +} + +/* AWAY local command. Sends UMODE command that sets the SILC_UMODE_GONE + flag. */ + +static void command_away(const char *data, SILC_SERVER_REC *server, + WI_ITEM_REC *item) +{ + bool set; + + if (!IS_SILC_SERVER(server) || !server->connected) + cmd_return_error(CMDERR_NOT_CONNECTED); + + if (*data == '\0') { + /* Remove any possible away message */ + silc_client_set_away_message(silc_client, server->conn, NULL); + set = FALSE; + + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_UNSET_AWAY); + } else { + /* Set the away message */ + silc_client_set_away_message(silc_client, server->conn, (char *)data); + set = TRUE; + + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_SET_AWAY, data); + } + + signal_emit("away mode changed", 1, server); + + silc_command_exec(server, "UMODE", set ? "+g" : "-g"); +} + +typedef struct { + int type; /* 1 = msg, 2 = channel */ + bool responder; + SILC_SERVER_REC *server; +} *KeyInternal; + +/* Key agreement callback that is called after the key agreement protocol + has been performed. This is called also if error occured during the + key agreement protocol. The `key' is the allocated key material and + the caller is responsible of freeing it. The `key' is NULL if error + has occured. The application can freely use the `key' to whatever + purpose it needs. See lib/silcske/silcske.h for the definition of + the SilcSKEKeyMaterial structure. */ + +static void keyagr_completion(SilcClient client, + SilcClientConnection conn, + SilcClientEntry client_entry, + SilcKeyAgreementStatus status, + SilcSKEKeyMaterial *key, + void *context) +{ + KeyInternal i = (KeyInternal)context; + + switch(status) { + case SILC_KEY_AGREEMENT_OK: + printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT_OK, client_entry->nickname); + + if (i->type == 1) { + /* Set the private key for this client */ + silc_client_del_private_message_key(client, conn, client_entry); + silc_client_add_private_message_key_ske(client, conn, client_entry, + NULL, key, i->responder); + printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT_PRIVMSG, + client_entry->nickname); + silc_ske_free_key_material(key); + } + + break; + + case SILC_KEY_AGREEMENT_ERROR: + printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT_ERROR, client_entry->nickname); + break; + + case SILC_KEY_AGREEMENT_FAILURE: + printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT_FAILURE, client_entry->nickname); + break; + + case SILC_KEY_AGREEMENT_TIMEOUT: + printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT_TIMEOUT, client_entry->nickname); + break; + + default: + break; + } + + if (i) + silc_free(i); +} + +/* Local command KEY. This command is used to set and unset private + keys for channels, set and unset private keys for private messages + with remote clients and to send key agreement requests and + negotiate the key agreement protocol with remote client. The + key agreement is supported only to negotiate private message keys, + it currently cannot be used to negotiate private keys for channels, + as it is not convenient for that purpose. */ + +typedef struct { + SILC_SERVER_REC *server; + char *data; + WI_ITEM_REC *item; +} *KeyGetClients; + +/* Callback to be called after client information is resolved from the + server. */ + +SILC_CLIENT_CMD_FUNC(key_get_clients) +{ + KeyGetClients internal = (KeyGetClients)context; + signal_emit("command key", 3, internal->data, internal->server, + internal->item); + silc_free(internal->data); + silc_free(internal); +} + +static void command_key(const char *data, SILC_SERVER_REC *server, + WI_ITEM_REC *item) +{ + SilcClientConnection conn = server->conn; + SilcClientEntry client_entry = NULL; + SilcChannelEntry channel_entry = NULL; + char *nickname = NULL, *tmp; + int command = 0, port = 0, type = 0; + char *hostname = NULL; + KeyInternal internal = NULL; + uint32 argc = 0; + unsigned char **argv; + uint32 *argv_lens, *argv_types; + + if (!IS_SILC_SERVER(server) || !server->connected) + cmd_return_error(CMDERR_NOT_CONNECTED); + + /* Now parse all arguments */ + tmp = g_strconcat("KEY", " ", data, NULL); + silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 7); + g_free(tmp); + + if (argc < 4) { + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KEY msg|channel " + "set|unset|agreement|negotiate []"); + return; + } + + /* Get type */ + if (!strcasecmp(argv[1], "msg")) + type = 1; + if (!strcasecmp(argv[1], "channel")) + type = 2; + + if (type == 0) { + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KEY msg|channel " + "set|unset|agreement|negotiate []"); + return; + } + + if (type == 1) { + if (argv[2][0] == '*') { + nickname = "*"; + } else { + /* Parse the typed nickname. */ + if (!silc_parse_userfqdn(argv[2], &nickname, NULL)) { + printformat_module("fe-common/silc", server, NULL, + MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]); + return; + } + + /* Find client entry */ + client_entry = silc_idlist_get_client(silc_client, conn, nickname, + argv[2], TRUE); + if (!client_entry) { + KeyGetClients inter = silc_calloc(1, sizeof(*inter)); + inter->server = server; + inter->data = strdup(data); + inter->item = item; + + /* Client entry not found, it was requested thus mark this to be + pending command. */ + silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, + conn->cmd_ident, + NULL, silc_client_command_key_get_clients, + inter); + goto out; + } + } + } + + if (type == 2) { + /* Get channel entry */ + char *name; + + if (argv[2][0] == '*') { + if (!conn->current_channel) { + silc_free(nickname); + cmd_return_error(CMDERR_NOT_JOINED); + } + name = conn->current_channel->channel_name; + } else { + name = argv[2]; + } + + channel_entry = silc_client_get_channel(silc_client, conn, name); + if (!channel_entry) { + silc_free(nickname); + cmd_return_error(CMDERR_NOT_JOINED); + } + } + + /* Set command */ + if (!strcasecmp(argv[3], "set")) { + command = 1; + + if (argc >= 5) { + if (type == 1 && client_entry) { + /* Set private message key */ + + silc_client_del_private_message_key(silc_client, conn, client_entry); + + if (argc >= 6) + silc_client_add_private_message_key(silc_client, conn, client_entry, + argv[5], argv[4], + argv_lens[4], + (argv[4][0] == '*' ? + TRUE : FALSE), FALSE); + else + silc_client_add_private_message_key(silc_client, conn, client_entry, + NULL, argv[4], + argv_lens[4], + (argv[4][0] == '*' ? + TRUE : FALSE), FALSE); + + /* Send the key to the remote client so that it starts using it + too. */ + silc_client_send_private_message_key(silc_client, conn, + client_entry, TRUE); + } else if (type == 2) { + /* Set private channel key */ + char *cipher = NULL, *hmac = NULL; + + if (!(channel_entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) { + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_CH_PRIVATE_KEY_NOMODE, + channel_entry->channel_name); + goto out; + } + + if (argc >= 6) + cipher = argv[5]; + if (argc >= 7) + hmac = argv[6]; + + if (!silc_client_add_channel_private_key(silc_client, conn, + channel_entry, + cipher, hmac, + argv[4], + argv_lens[4])) { + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_CH_PRIVATE_KEY_ERROR, + channel_entry->channel_name); + goto out; + } + + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_CH_PRIVATE_KEY_ADD, + channel_entry->channel_name); + } + } + + goto out; + } + + /* Unset command */ + if (!strcasecmp(argv[3], "unset")) { + command = 2; + + if (type == 1 && client_entry) { + /* Unset private message key */ + silc_client_del_private_message_key(silc_client, conn, client_entry); + } else if (type == 2) { + /* Unset channel key(s) */ + SilcChannelPrivateKey *keys; + uint32 keys_count; + int number; + + if (argc == 4) + silc_client_del_channel_private_keys(silc_client, conn, + channel_entry); + + if (argc > 4) { + number = atoi(argv[4]); + keys = silc_client_list_channel_private_keys(silc_client, conn, + channel_entry, + &keys_count); + if (!keys) + goto out; + + if (!number || number > keys_count) { + silc_client_free_channel_private_keys(keys, keys_count); + goto out; + } + + silc_client_del_channel_private_key(silc_client, conn, channel_entry, + keys[number - 1]); + silc_client_free_channel_private_keys(keys, keys_count); + } + + goto out; + } + } + + /* List command */ + if (!strcasecmp(argv[3], "list")) { + command = 3; + + if (type == 1) { + SilcPrivateMessageKeys keys; + uint32 keys_count; + int k, i, len; + char buf[1024]; + + keys = silc_client_list_private_message_keys(silc_client, conn, + &keys_count); + if (!keys) + goto out; + + /* list the private message key(s) */ + if (nickname[0] == '*') { + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_PRIVATE_KEY_LIST); + for (k = 0; k < keys_count; k++) { + memset(buf, 0, sizeof(buf)); + strncat(buf, " ", 2); + len = strlen(keys[k].client_entry->nickname); + strncat(buf, keys[k].client_entry->nickname, len > 30 ? 30 : len); + if (len < 30) + for (i = 0; i < 30 - len; i++) + strcat(buf, " "); + strcat(buf, " "); + + len = strlen(keys[k].cipher); + strncat(buf, keys[k].cipher, len > 14 ? 14 : len); + if (len < 14) + for (i = 0; i < 14 - len; i++) + strcat(buf, " "); + strcat(buf, " "); + + if (keys[k].key) + strcat(buf, ""); + else + strcat(buf, "*generated*"); + + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf); + } + } else { + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_PRIVATE_KEY_LIST_NICK, + client_entry->nickname); + for (k = 0; k < keys_count; k++) { + if (keys[k].client_entry != client_entry) + continue; + + memset(buf, 0, sizeof(buf)); + strncat(buf, " ", 2); + len = strlen(keys[k].client_entry->nickname); + strncat(buf, keys[k].client_entry->nickname, len > 30 ? 30 : len); + if (len < 30) + for (i = 0; i < 30 - len; i++) + strcat(buf, " "); + strcat(buf, " "); + + len = strlen(keys[k].cipher); + strncat(buf, keys[k].cipher, len > 14 ? 14 : len); + if (len < 14) + for (i = 0; i < 14 - len; i++) + strcat(buf, " "); + strcat(buf, " "); + + if (keys[k].key) + strcat(buf, ""); + else + strcat(buf, "*generated*"); + + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf); + } + } + + silc_client_free_private_message_keys(keys, keys_count); + } else if (type == 2) { + SilcChannelPrivateKey *keys; + uint32 keys_count; + int k, i, len; + char buf[1024]; + + keys = silc_client_list_channel_private_keys(silc_client, conn, + channel_entry, + &keys_count); + if (!keys) + goto out; + + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, + SILCTXT_CH_PRIVATE_KEY_LIST, + channel_entry->channel_name); + for (k = 0; k < keys_count; k++) { + memset(buf, 0, sizeof(buf)); + strncat(buf, " ", 2); + + len = strlen(keys[k]->cipher->cipher->name); + strncat(buf, keys[k]->cipher->cipher->name, len > 16 ? 16 : len); + if (len < 16) + for (i = 0; i < 16 - len; i++) + strcat(buf, " "); + strcat(buf, " "); + + len = strlen(keys[k]->hmac->hmac->name); + strncat(buf, keys[k]->hmac->hmac->name, len > 16 ? 16 : len); + if (len < 16) + for (i = 0; i < 16 - len; i++) + strcat(buf, " "); + strcat(buf, " "); + + strcat(buf, ""); + + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf); + } + + silc_client_free_channel_private_keys(keys, keys_count); + } + + goto out; + } + + /* Send command is used to send key agreement */ + if (!strcasecmp(argv[3], "agreement")) { + command = 4; + + if (argc >= 5) + hostname = argv[4]; + if (argc >= 6) + port = atoi(argv[5]); + + internal = silc_calloc(1, sizeof(*internal)); + internal->type = type; + internal->server = server; + } + + /* Start command is used to start key agreement (after receiving the + key_agreement client operation). */ + if (!strcasecmp(argv[3], "negotiate")) { + command = 5; + + if (argc >= 5) + hostname = argv[4]; + if (argc >= 6) + port = atoi(argv[5]); + + internal = silc_calloc(1, sizeof(*internal)); + internal->type = type; + internal->server = server; + } + + if (command == 0) { + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KEY msg|channel " + "set|unset|agreement|negotiate []"); + goto out; + } + + if (command == 4 && client_entry) { + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT, argv[2]); + internal->responder = TRUE; + silc_client_send_key_agreement(silc_client, conn, client_entry, hostname, + port, 120, keyagr_completion, internal); + if (!hostname) + silc_free(internal); + goto out; + } + + if (command == 5 && client_entry && hostname) { + printformat_module("fe-common/silc", server, NULL, MSGLEVEL_NOTICES, + SILCTXT_KEY_AGREEMENT_NEGOTIATE, argv[2]); + internal->responder = FALSE; + silc_client_perform_key_agreement(silc_client, conn, client_entry, + hostname, port, keyagr_completion, + internal); + goto out; + } + + out: + silc_free(nickname); +} + +/* Lists locally saved client and server public keys. */ + +static void command_listkeys(const char *data, SILC_SERVER_REC *server, + WI_ITEM_REC *item) +{ + +} + void silc_channels_init(void) { signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed); signal_add("server connected", (SIGNAL_FUNC) sig_connected); + signal_add("server quit", (SIGNAL_FUNC) sig_server_quit); signal_add("silc event join", (SIGNAL_FUNC) event_join); signal_add("silc event leave", (SIGNAL_FUNC) event_leave); @@ -439,10 +1193,15 @@ void silc_channels_init(void) signal_add("silc event server_signoff", (SIGNAL_FUNC) event_server_signoff); signal_add("silc event kick", (SIGNAL_FUNC) event_kick); signal_add("silc event kill", (SIGNAL_FUNC) event_kill); - signal_add("silc event ban", (SIGNAL_FUNC) event_ban); command_bind("part", MODULE_NAME, (SIGNAL_FUNC) command_part); - + command_bind("me", MODULE_NAME, (SIGNAL_FUNC) command_me); + command_bind("action", MODULE_NAME, (SIGNAL_FUNC) command_action); + command_bind("notice", MODULE_NAME, (SIGNAL_FUNC) command_notice); + command_bind("away", MODULE_NAME, (SIGNAL_FUNC) command_away); + command_bind("key", MODULE_NAME, (SIGNAL_FUNC) command_key); + command_bind("listkeys", MODULE_NAME, (SIGNAL_FUNC) command_listkeys); + silc_nicklist_init(); } @@ -450,6 +1209,7 @@ void silc_channels_deinit(void) { signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed); signal_remove("server connected", (SIGNAL_FUNC) sig_connected); + signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit); signal_remove("silc event join", (SIGNAL_FUNC) event_join); signal_remove("silc event leave", (SIGNAL_FUNC) event_leave); @@ -466,9 +1226,14 @@ void silc_channels_deinit(void) (SIGNAL_FUNC) event_server_signoff); signal_remove("silc event kick", (SIGNAL_FUNC) event_kick); signal_remove("silc event kill", (SIGNAL_FUNC) event_kill); - signal_remove("silc event ban", (SIGNAL_FUNC) event_ban); command_unbind("part", (SIGNAL_FUNC) command_part); - + command_unbind("me", (SIGNAL_FUNC) command_me); + command_unbind("action", (SIGNAL_FUNC) command_action); + command_unbind("notice", (SIGNAL_FUNC) command_notice); + command_unbind("away", (SIGNAL_FUNC) command_away); + command_unbind("key", (SIGNAL_FUNC) command_key); + command_unbind("listkeys", (SIGNAL_FUNC) command_listkeys); + silc_nicklist_deinit(); }