X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilcclient%2Fcommand.c;h=2a388e96459215d6f69dc6448a17747e27ff65ca;hp=cf3fc46e4f34072ba8f34e0018929882d81a3586;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hpb=6394d86063413bc1c473723f3ef971840195bcd3 diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index cf3fc46e..2a388e96 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,8 @@ */ /* $Id$ */ -#include "clientlibincludes.h" +#include "silcincludes.h" +#include "silcclient.h" #include "client_internal.h" #define SILC_NOT_CONNECTED(x, c) \ @@ -34,12 +35,14 @@ #define COMMAND_ERROR cmd->client->internal->ops->command(cmd->client, \ cmd->conn, cmd, FALSE, cmd->command->cmd) +#define SAY cmd->client->internal->ops->say + /* Generic function to send any command. The arguments must be sent already encoded into correct form and in correct order. */ void silc_client_command_send(SilcClient client, SilcClientConnection conn, - SilcCommand command, uint16 ident, - uint32 argc, ...) + SilcCommand command, SilcUInt16 ident, + SilcUInt32 argc, ...) { SilcBuffer packet; va_list ap; @@ -90,8 +93,7 @@ void silc_client_command_call(SilcClientCommand command, void silc_client_command_pending(SilcClientConnection conn, SilcCommand reply_cmd, - uint16 ident, - SilcClientPendingDestructor destructor, + SilcUInt16 ident, SilcCommandCb callback, void *context) { @@ -102,7 +104,6 @@ void silc_client_command_pending(SilcClientConnection conn, reply->ident = ident; reply->context = context; reply->callback = callback; - reply->destructor = destructor; silc_dlist_add(conn->pending_commands, reply); } @@ -110,7 +111,7 @@ void silc_client_command_pending(SilcClientConnection conn, void silc_client_command_pending_del(SilcClientConnection conn, SilcCommand reply_cmd, - uint16 ident) + SilcUInt16 ident) { SilcClientCommandPending *r; @@ -129,7 +130,7 @@ void silc_client_command_pending_del(SilcClientConnection conn, int silc_client_command_pending_check(SilcClientConnection conn, SilcClientCommandReplyContext ctx, SilcCommand command, - uint16 ident) + SilcUInt16 ident) { SilcClientCommandPending *r; @@ -138,7 +139,6 @@ int silc_client_command_pending_check(SilcClientConnection conn, if (r->reply_cmd == command && r->ident == ident) { ctx->context = r->context; ctx->callback = r->callback; - ctx->destructor = r->destructor; ctx->ident = ident; return TRUE; } @@ -185,13 +185,6 @@ SilcClientCommandContext silc_client_command_dup(SilcClientCommandContext ctx) return ctx; } -/* Pending command destructor. */ - -static void silc_client_command_destructor(void *context) -{ - silc_client_command_free((SilcClientCommandContext)context); -} - /* Command WHOIS. This command is used to query information about specific user. */ @@ -252,8 +245,8 @@ SILC_CLIENT_CMD_FUNC(whowas) } if (cmd->argc < 2 || cmd->argc > 3) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /WHOWAS [@] []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /WHOWAS [@] []"); COMMAND_ERROR; goto out; } @@ -366,8 +359,8 @@ SILC_CLIENT_CMD_FUNC(nick) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /NICK "); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /NICK "); COMMAND_ERROR; goto out; } @@ -378,12 +371,12 @@ SILC_CLIENT_CMD_FUNC(nick) /* Show current nickname */ if (cmd->argc < 2) { if (cmd->conn) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Your nickname is %s on server %s", - conn->nickname, conn->remote_host); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Your nickname is %s on server %s", + conn->nickname, conn->remote_host); } else { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Your nickname is %s", conn->nickname); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Your nickname is %s", conn->nickname); } COMMAND; @@ -408,11 +401,9 @@ SILC_CLIENT_CMD_FUNC(nick) if there were no errors returned by the server. */ silc_client_command_pending(conn, SILC_COMMAND_NICK, cmd->conn->cmd_ident, - silc_client_command_destructor, silc_client_command_nick_change, silc_client_command_dup(cmd)); cmd->pending = TRUE; - return; out: silc_client_command_free(cmd); @@ -485,16 +476,16 @@ SILC_CLIENT_CMD_FUNC(topic) } if (cmd->argc < 2 || cmd->argc > 3) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /TOPIC []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /TOPIC []"); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -504,16 +495,16 @@ SILC_CLIENT_CMD_FUNC(topic) } if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } /* Get the Channel ID of the channel */ if (!silc_idcache_find_by_name_one(conn->channel_cache, name, &id_cache)) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } @@ -555,7 +546,7 @@ SILC_CLIENT_CMD_FUNC(invite) SilcClientEntry client_entry = NULL; SilcChannelEntry channel; SilcBuffer buffer, clidp, chidp; - uint32 type = 0; + SilcUInt32 type = 0; char *nickname = NULL, *name; char *invite = NULL; @@ -566,17 +557,17 @@ SILC_CLIENT_CMD_FUNC(invite) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /INVITE [[@server>]" - "[+|-[[@[![@hostname>]]]]]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /INVITE [[@server>]" + "[+|-[[@[![@hostname>]]]]]"); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -587,8 +578,8 @@ SILC_CLIENT_CMD_FUNC(invite) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -610,17 +601,15 @@ SILC_CLIENT_CMD_FUNC(invite) COMMAND_ERROR; goto out; } - silc_free(nickname); /* 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, - silc_client_command_destructor, silc_client_command_invite, silc_client_command_dup(cmd)); cmd->pending = 1; - return; + goto out; } } else { invite = cmd->argv[2]; @@ -744,10 +733,9 @@ SILC_TASK_CALLBACK(silc_client_command_kill_remove_later) /* Get the target client */ target = silc_idlist_get_client(cmd->client, conn, nickname, cmd->argv[1], FALSE); - if (target) { - silc_client_remove_from_channels(client, conn, target); + if (target) + /* Remove the client from all channels and free it */ silc_client_del_client(client, conn, target); - } silc_free(nickname); silc_client_command_free(cmd); @@ -794,8 +782,8 @@ SILC_CLIENT_CMD_FUNC(kill) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /KILL []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KILL []"); COMMAND_ERROR; goto out; } @@ -815,17 +803,14 @@ SILC_CLIENT_CMD_FUNC(kill) goto out; } - silc_free(nickname); - /* 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, - silc_client_command_destructor, silc_client_command_kill, silc_client_command_dup(cmd)); cmd->pending = 1; - return; + goto out; } /* Send the KILL command to the server */ @@ -851,7 +836,7 @@ SILC_CLIENT_CMD_FUNC(kill) /* Register a pending callback that will actually remove the killed client from our cache. */ silc_client_command_pending(conn, SILC_COMMAND_KILL, conn->cmd_ident, - NULL, silc_client_command_kill_remove, + silc_client_command_kill_remove, silc_client_command_dup(cmd)); out: @@ -963,7 +948,7 @@ SILC_CLIENT_CMD_FUNC(join) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; - SilcIDCacheEntry id_cache = NULL; + SilcChannelEntry channel; SilcBuffer buffer, idp, auth = NULL; char *name, *passphrase = NULL, *cipher = NULL, *hmac = NULL; int i; @@ -980,12 +965,9 @@ SILC_CLIENT_CMD_FUNC(join) } /* See if we have joined to the requested channel already */ - if (silc_idcache_find_by_name_one(conn->channel_cache, cmd->argv[1], - &id_cache)) { - SilcChannelEntry channel = (SilcChannelEntry)id_cache->context; - if (channel->on_channel) - goto out; - } + channel = silc_client_get_channel(cmd->client, conn, cmd->argv[1]); + if (channel && silc_client_on_channel(channel, conn->local_entry)) + goto out; idp = silc_id_payload_encode(conn->local_id, SILC_ID_CLIENT); @@ -995,13 +977,13 @@ SILC_CLIENT_CMD_FUNC(join) name = cmd->argv[1]; for (i = 2; i < cmd->argc; i++) { - if (!strcasecmp(cmd->argv[i], "-cipher") && cmd->argc >= i + 1) { + if (!strcasecmp(cmd->argv[i], "-cipher") && cmd->argc > i + 1) { cipher = cmd->argv[i + 1]; i++; - } else if (!strcasecmp(cmd->argv[i], "-hmac") && cmd->argc >= i + 1) { + } else if (!strcasecmp(cmd->argv[i], "-hmac") && cmd->argc > i + 1) { hmac = cmd->argv[i + 1]; i++; - } else if (!strcasecmp(cmd->argv[i], "-founder") && cmd->argc >= i + 1) { + } else if (!strcasecmp(cmd->argv[i], "-founder") && cmd->argc > i + 1) { if (!strcasecmp(cmd->argv[i + 1], "-pubkey")) { auth = silc_auth_public_key_auth_generate(cmd->client->public_key, cmd->client->private_key, @@ -1059,8 +1041,8 @@ SILC_CLIENT_CMD_FUNC(motd) } if (cmd->argc < 1 || cmd->argc > 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /MOTD []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /MOTD []"); COMMAND_ERROR; goto out; } @@ -1094,7 +1076,7 @@ SILC_CLIENT_CMD_FUNC(umode) SilcClientConnection conn = cmd->conn; SilcBuffer buffer, idp; unsigned char *cp, modebuf[4]; - uint32 mode, add, len; + SilcUInt32 mode, add, len; int i; if (!cmd->conn) { @@ -1104,8 +1086,8 @@ SILC_CLIENT_CMD_FUNC(umode) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /UMODE +|-"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /UMODE +|-"); COMMAND_ERROR; goto out; } @@ -1189,7 +1171,7 @@ SILC_CLIENT_CMD_FUNC(cmode) SilcChannelEntry channel; SilcBuffer buffer, chidp, auth = NULL; unsigned char *name, *cp, modebuf[4], tmp[4], *arg = NULL; - uint32 mode, add, type, len, arg_len = 0; + SilcUInt32 mode, add, type, len, arg_len = 0; int i; if (!cmd->conn) { @@ -1199,16 +1181,16 @@ SILC_CLIENT_CMD_FUNC(cmode) } if (cmd->argc < 3) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CMODE +|- [{ }]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1219,8 +1201,8 @@ SILC_CLIENT_CMD_FUNC(cmode) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -1278,8 +1260,8 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_ULIMIT; type = 3; if (cmd->argc < 4) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CMODE +|- [{ }]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; } @@ -1296,8 +1278,8 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_PASSPHRASE; type = 4; if (cmd->argc < 4) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CMODE +|- [{ }]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; } @@ -1312,8 +1294,8 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_CIPHER; type = 5; if (cmd->argc < 4) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CMODE +|- [{ }]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; } @@ -1328,8 +1310,8 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_HMAC; type = 6; if (cmd->argc < 4) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CMODE +|- [{ }]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; } @@ -1345,8 +1327,8 @@ SILC_CLIENT_CMD_FUNC(cmode) type = 7; if (cmd->argc < 4) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CMODE +|- [{ }]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; } @@ -1419,7 +1401,7 @@ SILC_CLIENT_CMD_FUNC(cumode) SilcClientEntry client_entry; SilcBuffer buffer, clidp, chidp, auth = NULL; unsigned char *name, *cp, modebuf[4]; - uint32 mode = 0, add, len; + SilcUInt32 mode = 0, add, len; char *nickname = NULL; int i; @@ -1430,16 +1412,16 @@ SILC_CLIENT_CMD_FUNC(cumode) } if (cmd->argc < 4) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CUMODE +|- [@]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CUMODE +|- [@]"); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1450,8 +1432,8 @@ SILC_CLIENT_CMD_FUNC(cumode) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -1472,27 +1454,20 @@ SILC_CLIENT_CMD_FUNC(cumode) goto out; } - silc_free(nickname); - /* 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, - silc_client_command_destructor, silc_client_command_cumode, silc_client_command_dup(cmd)); cmd->pending = 1; - return; + goto out; } /* Get the current mode */ - silc_list_start(channel->clients); - while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) { - if (chu->client == client_entry) { - mode = chu->mode; - break; - } - } + chu = silc_client_on_channel(channel, client_entry); + if (chu) + mode = chu->mode; /* Are we adding or removing mode */ if (cmd->argv[2][0] == '-') @@ -1596,16 +1571,16 @@ SILC_CLIENT_CMD_FUNC(kick) } if (cmd->argc < 3) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /KICK []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /KICK []"); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1615,16 +1590,16 @@ SILC_CLIENT_CMD_FUNC(kick) } if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } /* Get the Channel ID of the channel */ if (!silc_idcache_find_by_name_one(conn->channel_cache, name, &id_cache)) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } @@ -1641,9 +1616,8 @@ SILC_CLIENT_CMD_FUNC(kick) target = silc_idlist_get_client(cmd->client, conn, nickname, cmd->argv[2], FALSE); if (!target) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "No such client: %s", - cmd->argv[2]); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "No such client: %s", cmd->argv[2]); COMMAND_ERROR; goto out; } @@ -1676,7 +1650,7 @@ SILC_CLIENT_CMD_FUNC(kick) } static void silc_client_command_oper_send(unsigned char *data, - uint32 data_len, void *context) + SilcUInt32 data_len, void *context) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; @@ -1723,8 +1697,8 @@ SILC_CLIENT_CMD_FUNC(oper) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /OPER [-pubkey]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /OPER [-pubkey]"); COMMAND_ERROR; goto out; } @@ -1744,7 +1718,7 @@ SILC_CLIENT_CMD_FUNC(oper) } static void silc_client_command_silcoper_send(unsigned char *data, - uint32 data_len, void *context) + SilcUInt32 data_len, void *context) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; @@ -1791,8 +1765,8 @@ SILC_CLIENT_CMD_FUNC(silcoper) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /SILCOPER [-pubkey]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /SILCOPER [-pubkey]"); COMMAND_ERROR; goto out; } @@ -1819,7 +1793,7 @@ SILC_CLIENT_CMD_FUNC(connect) SilcClientConnection conn = cmd->conn; SilcBuffer buffer; unsigned char port[4]; - uint32 tmp; + SilcUInt32 tmp; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -1828,8 +1802,8 @@ SILC_CLIENT_CMD_FUNC(connect) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CONNECT []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CONNECT []"); COMMAND_ERROR; goto out; } @@ -1877,17 +1851,17 @@ SILC_CLIENT_CMD_FUNC(ban) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /BAN " - "[+|-[[@[![@hostname>]]]]]"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /BAN " + "[+|-[[@[![@hostname>]]]]]"); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1898,8 +1872,8 @@ SILC_CLIENT_CMD_FUNC(ban) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are on that channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -1946,7 +1920,7 @@ SILC_CLIENT_CMD_FUNC(close) SilcClientConnection conn = cmd->conn; SilcBuffer buffer; unsigned char port[4]; - uint32 tmp; + SilcUInt32 tmp; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -1955,8 +1929,8 @@ SILC_CLIENT_CMD_FUNC(close) } if (cmd->argc < 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /CLOSE []"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /CLOSE []"); COMMAND_ERROR; goto out; } @@ -2015,8 +1989,8 @@ SILC_CLIENT_CMD_FUNC(leave) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; - SilcIDCacheEntry id_cache = NULL; SilcChannelEntry channel; + SilcChannelUser chu; SilcBuffer buffer, idp; char *name; @@ -2027,16 +2001,16 @@ SILC_CLIENT_CMD_FUNC(leave) } if (cmd->argc != 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /LEAVE "); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /LEAVE "); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -2045,19 +2019,25 @@ SILC_CLIENT_CMD_FUNC(leave) name = cmd->argv[1]; } - /* Get the Channel ID of the channel */ - if (!silc_idcache_find_by_name_one(conn->channel_cache, name, &id_cache)) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on that channel"); + /* Get the channel entry */ + channel = silc_client_get_channel(cmd->client, conn, name); + if (!channel) { + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } - channel = (SilcChannelEntry)id_cache->context; - channel->on_channel = FALSE; + /* Remove us from channel */ + chu = silc_client_on_channel(channel, conn->local_entry); + if (chu) { + silc_hash_table_del(chu->client->channels, chu->channel); + silc_hash_table_del(chu->channel->user_list, chu->client); + silc_free(chu); + } /* Send LEAVE command to the server */ - idp = silc_id_payload_encode(id_cache->id, SILC_ID_CHANNEL); + idp = silc_id_payload_encode(channel->id, SILC_ID_CHANNEL); buffer = silc_command_payload_encode_va(SILC_COMMAND_LEAVE, 0, 1, 1, idp->data, idp->len); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, @@ -2094,16 +2074,16 @@ SILC_CLIENT_CMD_FUNC(users) } if (cmd->argc != 2) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "Usage: /USERS "); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /USERS "); COMMAND_ERROR; goto out; } if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, - "You are not on any channel"); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -2140,6 +2120,8 @@ SILC_CLIENT_CMD_FUNC(getkey) char *nickname = NULL; SilcBuffer idp, buffer; + SILC_LOG_DEBUG(("Start")); + if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); COMMAND_ERROR; @@ -2153,23 +2135,6 @@ SILC_CLIENT_CMD_FUNC(getkey) goto out; } - if (cmd->pending) { - SilcClientCommandReplyContext reply = - (SilcClientCommandReplyContext)context2; - SilcCommandStatus status; - unsigned char *tmp = silc_argument_get_arg_type(reply->args, 1, NULL); - SILC_GET16_MSB(status, tmp); - - if (status == SILC_STATUS_ERR_NO_SUCH_NICK || - status == SILC_STATUS_ERR_NO_SUCH_SERVER) { - cmd->client->internal->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, - "%s", - silc_client_command_status_message(status)); - COMMAND_ERROR; - goto out; - } - } - /* Parse the typed nickname. */ if (client->internal->params->nickname_parse) client->internal->params->nickname_parse(cmd->argv[1], &nickname); @@ -2184,38 +2149,57 @@ SILC_CLIENT_CMD_FUNC(getkey) server_entry = silc_client_get_server(client, conn, cmd->argv[1]); if (!server_entry) { - if (cmd->pending) { + /* No. what ever user wants we don't have it, so resolve it. We + will first try to resolve the client, and if that fails then + we'll try to resolve the server. */ + + if (!cmd->pending) { + /* This will send the IDENTIFY command for nickname */ + silc_idlist_get_client(client, conn, nickname, cmd->argv[1], TRUE); + silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, + conn->cmd_ident, + silc_client_command_getkey, + silc_client_command_dup(cmd)); + cmd->pending = 1; + goto out; + } else { + SilcClientCommandReplyContext reply = + (SilcClientCommandReplyContext)context2; + SilcCommandStatus status; + unsigned char *tmp = silc_argument_get_arg_type(reply->args, 1, NULL); + SILC_GET16_MSB(status, tmp); + + /* If nickname was not found, then resolve the server. */ + if (status == SILC_STATUS_ERR_NO_SUCH_NICK) { + /* This sends the IDENTIFY command to resolve the server. */ + silc_client_command_register(client, SILC_COMMAND_IDENTIFY, + NULL, NULL, + silc_client_command_reply_identify_i, 0, + ++conn->cmd_ident); + silc_client_command_send(client, conn, SILC_COMMAND_IDENTIFY, + conn->cmd_ident, 1, + 2, cmd->argv[1], cmd->argv_lens[1]); + silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, + conn->cmd_ident, + silc_client_command_getkey, + silc_client_command_dup(cmd)); + goto out; + } + + /* If server was not found, then we've resolved both nickname and + server and did not find anybody. */ + if (status == SILC_STATUS_ERR_NO_SUCH_SERVER) { + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", + silc_client_command_status_message(SILC_STATUS_ERR_NO_SUCH_NICK)); + SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", + silc_client_command_status_message(status)); + COMMAND_ERROR; + goto out; + } + COMMAND_ERROR; goto out; } - - /* No. what ever user wants we don't have it, so resolve it. We - will try to resolve both client and server, one of them is - bound to be wrong. */ - - /* This will send the IDENTIFY command */ - silc_idlist_get_client(client, conn, nickname, cmd->argv[1], TRUE); - silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, - silc_client_command_destructor, - silc_client_command_getkey, - silc_client_command_dup(cmd)); - - /* This sends the IDENTIFY command to resolve the server. */ - silc_client_command_register(client, SILC_COMMAND_IDENTIFY, NULL, NULL, - silc_client_command_reply_identify_i, 0, - ++conn->cmd_ident); - silc_client_command_send(client, conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, 1, - 2, cmd->argv[1], cmd->argv_lens[1]); - silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, - conn->cmd_ident, NULL, - silc_client_command_getkey, - silc_client_command_dup(cmd)); - - cmd->pending = 1; - silc_free(nickname); - return; } idp = silc_id_payload_encode(server_entry->server_id, SILC_ID_SERVER); @@ -2256,8 +2240,8 @@ bool silc_client_command_register(SilcClient client, const char *name, SilcCommandCb command_function, SilcCommandCb command_reply_function, - uint8 max_args, - uint16 ident) + SilcUInt8 max_args, + SilcUInt16 ident) { SilcClientCommand cmd; @@ -2282,7 +2266,7 @@ bool silc_client_command_unregister(SilcClient client, SilcCommand command, SilcCommandCb command_function, SilcCommandCb command_reply_function, - uint16 ident) + SilcUInt16 ident) { SilcClientCommand cmd; @@ -2320,7 +2304,7 @@ void silc_client_commands_register(SilcClient client) SILC_CLIENT_CMD(info, INFO, "INFO", 2); SILC_CLIENT_CMD(connect, CONNECT, "CONNECT", 3); SILC_CLIENT_CMD(ping, PING, "PING", 2); - SILC_CLIENT_CMD(oper, OPER, "OPER", 2); + SILC_CLIENT_CMD(oper, OPER, "OPER", 3); SILC_CLIENT_CMD(join, JOIN, "JOIN", 9); SILC_CLIENT_CMD(motd, MOTD, "MOTD", 2); SILC_CLIENT_CMD(umode, UMODE, "UMODE", 2); @@ -2366,6 +2350,4 @@ void silc_client_commands_unregister(SilcClient client) SILC_CLIENT_CMDU(leave, LEAVE, "LEAVE"); SILC_CLIENT_CMDU(users, USERS, "USERS"); SILC_CLIENT_CMDU(getkey, GETKEY, "GETKEY"); - - silc_list_uninit(client->internal->commands); }