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=57678937fe86bfbe5a4289b624fd0c9f36039476;hpb=fc93c69a223d6cd374c4cb808e156b6e19294305;p=silc.git diff --git a/apps/irssi/src/silc/core/silc-channels.c b/apps/irssi/src/silc/core/silc-channels.c index 57678937..459dedd6 100644 --- a/apps/irssi/src/silc/core/silc-channels.c +++ b/apps/irssi/src/silc/core/silc-channels.c @@ -76,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); } @@ -99,7 +107,7 @@ static void sig_connected(SILC_SERVER_REC *server) static void sig_server_quit(SILC_SERVER_REC *server, const char *msg) { - if (IS_SILC_SERVER(server)) + if (IS_SILC_SERVER(server) && server->conn && server->conn->sock) silc_command_exec(server, "QUIT", msg); } @@ -244,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); } /* @@ -278,18 +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) { @@ -298,10 +314,19 @@ static void event_cmode(SILC_SERVER_REC *server, va_list va) signal_emit("channel mode changed", 1, chanrec); } - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE, - channel->channel_name, mode ? mode : "removed all", - 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); } @@ -336,6 +361,7 @@ static void event_cumode(SILC_SERVER_REC *server, va_list va) 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); } } @@ -373,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 */ } /* @@ -382,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"); } /* @@ -391,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)); + } + } } /* @@ -400,16 +468,31 @@ 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. */ @@ -422,7 +505,7 @@ static void command_part(const char *data, SILC_SERVER_REC *server, if (!IS_SILC_SERVER(server) || !server->connected) 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; @@ -479,7 +562,56 @@ static void command_me(const char *data, SILC_SERVER_REC *server, argv[1], argv_lens[1], TRUE); printformat_module("fe-common/silc", server, chanrec->entry->channel_name, - MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, argv[1]); + 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]); @@ -525,7 +657,8 @@ static void command_notice(const char *data, SILC_SERVER_REC *server, argv[1], argv_lens[1], TRUE); printformat_module("fe-common/silc", server, chanrec->entry->channel_name, - MSGLEVEL_NOTICES, SILCTXT_CHANNEL_OWNNOTICE, argv[1]); + MSGLEVEL_NOTICES, SILCTXT_CHANNEL_OWNNOTICE, + server->conn->local_entry->nickname, argv[1]); for (i = 0; i < argc; i++) silc_free(argv[i]); @@ -539,19 +672,38 @@ static void command_notice(const char *data, SILC_SERVER_REC *server, 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); - /* XXX TODO */ + 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; -static SilcSKEKeyMaterial *curr_key = NULL; - /* 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 @@ -569,8 +721,6 @@ static void keyagr_completion(SilcClient client, { KeyInternal i = (KeyInternal)context; - curr_key = NULL; - switch(status) { case SILC_KEY_AGREEMENT_OK: printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, @@ -580,7 +730,7 @@ static void keyagr_completion(SilcClient client, /* 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); + NULL, key, i->responder); printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, SILCTXT_KEY_AGREEMENT_PRIVMSG, client_entry->nickname); @@ -644,8 +794,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server, SilcClientConnection conn = server->conn; SilcClientEntry client_entry = NULL; SilcChannelEntry channel_entry = NULL; - uint32 num = 0; - char *nickname = NULL, *serv = NULL, *tmp; + char *nickname = NULL, *tmp; int command = 0, port = 0, type = 0; char *hostname = NULL; KeyInternal internal = NULL; @@ -662,7 +811,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server, g_free(tmp); if (argc < 4) { - silc_say(silc_client, conn, "Usage: /KEY msg|channel " + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KEY msg|channel " "set|unset|agreement|negotiate []"); return; } @@ -674,7 +824,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server, type = 2; if (type == 0) { - silc_say(silc_client, conn, "Usage: /KEY msg|channel " + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KEY msg|channel " "set|unset|agreement|negotiate []"); return; } @@ -684,14 +835,15 @@ static void command_key(const char *data, SILC_SERVER_REC *server, nickname = "*"; } else { /* Parse the typed nickname. */ - if (!silc_parse_nickname(argv[2], &nickname, &serv, &num)) { - silc_say(silc_client, conn, "Bad 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, - serv, num, TRUE); + argv[2], TRUE); if (!client_entry) { KeyGetClients inter = silc_calloc(1, sizeof(*inter)); inter->server = server; @@ -715,10 +867,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server, if (argv[2][0] == '*') { if (!conn->current_channel) { - if (nickname) - silc_free(nickname); - if (serv) - silc_free(serv); + silc_free(nickname); cmd_return_error(CMDERR_NOT_JOINED); } name = conn->current_channel->channel_name; @@ -728,10 +877,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server, channel_entry = silc_client_get_channel(silc_client, conn, name); if (!channel_entry) { - if (nickname) - silc_free(nickname); - if (serv) - silc_free(serv); + silc_free(nickname); cmd_return_error(CMDERR_NOT_JOINED); } } @@ -740,15 +886,6 @@ static void command_key(const char *data, SILC_SERVER_REC *server, if (!strcasecmp(argv[3], "set")) { command = 1; - if (argc == 4) { - if (curr_key && type == 1 && client_entry) { - silc_client_del_private_message_key(silc_client, conn, client_entry); - silc_client_add_private_message_key_ske(silc_client, conn, - client_entry, NULL, curr_key); - goto out; - } - } - if (argc >= 5) { if (type == 1 && client_entry) { /* Set private message key */ @@ -760,13 +897,13 @@ static void command_key(const char *data, SILC_SERVER_REC *server, argv[5], argv[4], argv_lens[4], (argv[4][0] == '*' ? - TRUE : FALSE)); + 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)); + TRUE : FALSE), FALSE); /* Send the key to the remote client so that it starts using it too. */ @@ -888,7 +1025,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server, else strcat(buf, "*generated*"); - silc_say(silc_client, conn, "%s", buf); + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf); } } else { printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, @@ -919,7 +1056,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server, else strcat(buf, "*generated*"); - silc_say(silc_client, conn, "%s", buf); + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf); } } @@ -959,7 +1096,7 @@ static void command_key(const char *data, SILC_SERVER_REC *server, strcat(buf, ""); - silc_say(silc_client, conn, "%s", buf); + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, "%s", buf); } silc_client_free_channel_private_keys(keys, keys_count); @@ -998,7 +1135,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server, } if (command == 0) { - silc_say(silc_client, conn, "Usage: /KEY msg|channel " + silc_say(silc_client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KEY msg|channel " "set|unset|agreement|negotiate []"); goto out; } @@ -1006,14 +1144,18 @@ static void command_key(const char *data, SILC_SERVER_REC *server, 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); @@ -1021,10 +1163,15 @@ static void command_key(const char *data, SILC_SERVER_REC *server, } out: - if (nickname) - silc_free(nickname); - if (serv) - silc_free(serv); + 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) @@ -1046,13 +1193,14 @@ 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(); } @@ -1078,13 +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(); }