X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcclient%2Fcommand.c;h=b449b1150ed9da09d1d1eccd113d1f948bf63754;hb=017dec75a98209fbef49eb496c2269b0c49e736d;hp=b73d7f268aedcb140a42bca3fc885a46cc059e0c;hpb=8bedd95be03038c219f8a5ee9c7d0d02540c575c;p=silc.git diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index b73d7f26..b449b115 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -63,7 +63,7 @@ SilcClientCommand silc_command_list[] = }; #define SILC_NOT_CONNECTED(x, c) \ - x->ops->say((x), (c), \ + x->ops->say((x), (c), SILC_CLIENT_MESSAGE_ERROR, \ "You are not connected to a server, use /SERVER to connect"); /* Command operation that is called at the end of all commands. @@ -219,16 +219,6 @@ static void silc_client_command_destructor(void *context) silc_client_command_free((SilcClientCommandContext)context); } -/* silc_client_get_client completion callback */ -void silc_client_command_completion(SilcClient client, - SilcClientConnection conn, - SilcClientEntry clients, - uint32 clients_count, - void *context) -{ - -} - /* Command WHOIS. This command is used to query information about specific user. */ @@ -244,10 +234,13 @@ SILC_CLIENT_CMD_FUNC(whois) goto out; } - if (cmd->argc < 2 || cmd->argc > 3) { - cmd->client->ops->say(cmd->client, conn, - "Usage: /WHOIS [@] []"); - COMMAND_ERROR; + /* Given without arguments fetches client's own information */ + if (cmd->argc < 2) { + buffer = silc_id_payload_encode(cmd->conn->local_id, SILC_ID_CLIENT); + silc_client_send_command(cmd->client, cmd->conn, SILC_COMMAND_WHOIS, + ++conn->cmd_ident, + 1, 3, buffer->data, buffer->len); + silc_buffer_free(buffer); goto out; } @@ -286,7 +279,7 @@ SILC_CLIENT_CMD_FUNC(whowas) } if (cmd->argc < 2 || cmd->argc > 3) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /WHOWAS [@] []"); COMMAND_ERROR; goto out; @@ -327,23 +320,27 @@ SILC_CLIENT_CMD_FUNC(identify) } if (cmd->argc < 2 || cmd->argc > 3) { - cmd->client->ops->say(cmd->client, conn, - "Usage: /IDENTIFY [@] []"); COMMAND_ERROR; goto out; } - buffer = silc_command_payload_encode(SILC_COMMAND_IDENTIFY, - cmd->argc - 1, ++cmd->argv, - ++cmd->argv_lens, ++cmd->argv_types, - ++conn->cmd_ident); + if (cmd->argc == 2) + buffer = silc_command_payload_encode_va(SILC_COMMAND_IDENTIFY, + ++conn->cmd_ident, 1, + 1, cmd->argv[1], + cmd->argv_lens[1]); + else + buffer = silc_command_payload_encode_va(SILC_COMMAND_IDENTIFY, + ++conn->cmd_ident, 2, + 1, cmd->argv[1], + cmd->argv_lens[1], + 4, cmd->argv[2], + cmd->argv_lens[2]); + silc_client_packet_send(cmd->client, cmd->conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); silc_buffer_free(buffer); - cmd->argv--; - cmd->argv_lens--; - cmd->argv_types--; /* Notify application */ COMMAND; @@ -368,7 +365,8 @@ SILC_CLIENT_CMD_FUNC(nick) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, "Usage: /NICK "); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /NICK "); COMMAND_ERROR; goto out; } @@ -379,15 +377,14 @@ SILC_CLIENT_CMD_FUNC(nick) /* Show current nickname */ if (cmd->argc < 2) { if (cmd->conn) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Your nickname is %s on server %s", conn->nickname, conn->remote_host); } else { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Your nickname is %s", conn->nickname); } - /* XXX Notify application */ COMMAND; goto out; } @@ -482,7 +479,7 @@ SILC_CLIENT_CMD_FUNC(topic) } if (cmd->argc < 2 || cmd->argc > 3) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /TOPIC []"); COMMAND_ERROR; goto out; @@ -490,7 +487,8 @@ SILC_CLIENT_CMD_FUNC(topic) if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -500,14 +498,16 @@ SILC_CLIENT_CMD_FUNC(topic) } if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on that channel"); + cmd->client->ops->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->ops->say(cmd->client, conn, "You are not on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } @@ -549,8 +549,8 @@ SILC_CLIENT_CMD_FUNC(invite) SilcClientEntry client_entry = NULL; SilcChannelEntry channel; SilcBuffer buffer, clidp, chidp; - uint32 num = 0, type = 0; - char *nickname = NULL, *server = NULL, *name; + uint32 type = 0; + char *nickname = NULL, *name; char *invite = NULL; if (!cmd->conn) { @@ -560,7 +560,7 @@ SILC_CLIENT_CMD_FUNC(invite) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /INVITE [[@server>]" "[+|-[[@[![@hostname>]]]]]"); COMMAND_ERROR; @@ -569,7 +569,8 @@ SILC_CLIENT_CMD_FUNC(invite) if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -580,7 +581,8 @@ SILC_CLIENT_CMD_FUNC(invite) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->ops->say(cmd->client, conn, "You are on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -589,20 +591,16 @@ SILC_CLIENT_CMD_FUNC(invite) /* Parse the typed nickname. */ if (cmd->argc == 3) { if (cmd->argv[2][0] != '+' && cmd->argv[2][0] != '-') { - if (!silc_parse_nickname(cmd->argv[2], &nickname, &server, &num)) { - cmd->client->ops->say(cmd->client, conn, "Bad nickname"); - COMMAND_ERROR; - goto out; - } - + if (client->params->nickname_parse) + client->params->nickname_parse(cmd->argv[2], &nickname); + else + nickname = strdup(cmd->argv[2]); + /* Find client entry */ client_entry = silc_idlist_get_client(client, conn, nickname, - server, num, TRUE); + cmd->argv[2], TRUE); if (!client_entry) { - if (nickname) - silc_free(nickname); - if (server) - silc_free(server); + silc_free(nickname); if (cmd->pending) { COMMAND_ERROR; @@ -657,10 +655,7 @@ SILC_CLIENT_CMD_FUNC(invite) COMMAND; out: - if (nickname) - silc_free(nickname); - if (server) - silc_free(server); + silc_free(nickname); silc_client_command_free(cmd); } @@ -711,9 +706,9 @@ SILC_CLIENT_CMD_FUNC(quit) q->conn = cmd->conn; /* We quit the connection with little timeout */ - silc_task_register(cmd->client->timeout_queue, cmd->conn->sock->sock, - silc_client_command_quit_cb, (void *)q, - 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); + silc_schedule_task_add(cmd->client->schedule, cmd->conn->sock->sock, + silc_client_command_quit_cb, (void *)q, + 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); /* Notify application */ COMMAND; @@ -728,11 +723,11 @@ SILC_CLIENT_CMD_FUNC(quit) SILC_CLIENT_CMD_FUNC(kill) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; + SilcClient client = cmd->client; SilcClientConnection conn = cmd->conn; SilcBuffer buffer, idp; SilcClientEntry target; - uint32 num = 0; - char *nickname = NULL, *server = NULL; + char *nickname = NULL; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -741,26 +736,23 @@ SILC_CLIENT_CMD_FUNC(kill) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /KILL []"); COMMAND_ERROR; goto out; } /* Parse the typed nickname. */ - if (!silc_parse_nickname(cmd->argv[1], &nickname, &server, &num)) { - cmd->client->ops->say(cmd->client, conn, "Bad nickname"); - COMMAND_ERROR; - goto out; - } + if (client->params->nickname_parse) + client->params->nickname_parse(cmd->argv[1], &nickname); + else + nickname = strdup(cmd->argv[1]); /* Get the target client */ target = silc_idlist_get_client(cmd->client, conn, nickname, - server, num, TRUE); + cmd->argv[1], TRUE); if (!target) { silc_free(nickname); - if (server) - silc_free(server); if (cmd->pending) { COMMAND_ERROR; @@ -797,10 +789,7 @@ SILC_CLIENT_CMD_FUNC(kill) COMMAND; out: - if (nickname) - silc_free(nickname); - if (server) - silc_free(server); + silc_free(nickname); silc_client_command_free(cmd); } @@ -853,7 +842,6 @@ SILC_CLIENT_CMD_FUNC(ping) SilcBuffer buffer; void *id; int i; - char *name = NULL; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -861,9 +849,6 @@ SILC_CLIENT_CMD_FUNC(ping) goto out; } - if (cmd->argc == 1 || !strcmp(cmd->argv[1], conn->remote_host)) - name = strdup(conn->remote_host); - /* Send the command */ buffer = silc_command_payload_encode_va(SILC_COMMAND_PING, 0, 1, 1, conn->remote_id_data, @@ -886,7 +871,7 @@ SILC_CLIENT_CMD_FUNC(ping) if (conn->ping[i].dest_id == NULL) { conn->ping[i].start_time = time(NULL); conn->ping[i].dest_id = id; - conn->ping[i].dest_name = name; + conn->ping[i].dest_name = strdup(conn->remote_host); conn->ping_count++; break; } @@ -896,7 +881,7 @@ SILC_CLIENT_CMD_FUNC(ping) conn->ping = silc_realloc(conn->ping, sizeof(*conn->ping) * (i + 1)); conn->ping[i].start_time = time(NULL); conn->ping[i].dest_id = id; - conn->ping[i].dest_name = name; + conn->ping[i].dest_name = strdup(conn->remote_host); conn->ping_count++; } @@ -907,10 +892,6 @@ SILC_CLIENT_CMD_FUNC(ping) silc_client_command_free(cmd); } -SILC_CLIENT_CMD_FUNC(notice) -{ -} - /* Command JOIN. Joins to a channel. */ SILC_CLIENT_CMD_FUNC(join) @@ -926,24 +907,10 @@ SILC_CLIENT_CMD_FUNC(join) goto out; } - if (cmd->argc < 2) { - /* Show channels currently joined to */ - - goto out; - } - /* 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)) { -#if 0 - cmd->client->ops->say(cmd->client, conn, - "You are talking to channel %s", cmd->argv[1]); - conn->current_channel = (SilcChannelEntry)id_cache->context; - cmd->client->screen->bottom_line->channel = cmd->argv[1]; - silc_screen_print_bottom_line(cmd->client->screen, 0); -#endif + &id_cache)) goto out; - } idp = silc_id_payload_encode(conn->local_id, SILC_ID_CLIENT); @@ -995,7 +962,7 @@ SILC_CLIENT_CMD_FUNC(motd) } if (cmd->argc < 1 || cmd->argc > 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /MOTD []"); COMMAND_ERROR; goto out; @@ -1040,7 +1007,7 @@ SILC_CLIENT_CMD_FUNC(umode) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /UMODE +|-"); COMMAND_ERROR; goto out; @@ -1135,7 +1102,7 @@ SILC_CLIENT_CMD_FUNC(cmode) } if (cmd->argc < 3) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; @@ -1143,7 +1110,8 @@ SILC_CLIENT_CMD_FUNC(cmode) if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1154,7 +1122,8 @@ SILC_CLIENT_CMD_FUNC(cmode) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->ops->say(cmd->client, conn, "You are on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -1212,7 +1181,7 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_ULIMIT; type = 3; if (cmd->argc < 4) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; @@ -1230,7 +1199,7 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_PASSPHRASE; type = 4; if (cmd->argc < 4) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; @@ -1246,7 +1215,7 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_CIPHER; type = 5; if (cmd->argc < 4) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; @@ -1262,7 +1231,7 @@ SILC_CLIENT_CMD_FUNC(cmode) mode |= SILC_CHANNEL_MODE_HMAC; type = 6; if (cmd->argc < 4) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; @@ -1279,7 +1248,7 @@ SILC_CLIENT_CMD_FUNC(cmode) type = 7; if (cmd->argc < 4) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CMODE +|- [{ }]"); COMMAND_ERROR; goto out; @@ -1346,6 +1315,7 @@ SILC_CLIENT_CMD_FUNC(cmode) SILC_CLIENT_CMD_FUNC(cumode) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; + SilcClient client = cmd->client; SilcClientConnection conn = cmd->conn; SilcChannelEntry channel; SilcChannelUser chu; @@ -1353,8 +1323,7 @@ SILC_CLIENT_CMD_FUNC(cumode) SilcBuffer buffer, clidp, chidp, auth = NULL; unsigned char *name, *cp, modebuf[4]; uint32 mode = 0, add, len; - char *nickname = NULL, *server = NULL; - uint32 num = 0; + char *nickname = NULL; int i; if (!cmd->conn) { @@ -1364,7 +1333,7 @@ SILC_CLIENT_CMD_FUNC(cumode) } if (cmd->argc < 4) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CUMODE +|- [@]"); COMMAND_ERROR; goto out; @@ -1372,7 +1341,8 @@ SILC_CLIENT_CMD_FUNC(cumode) if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1383,23 +1353,25 @@ SILC_CLIENT_CMD_FUNC(cumode) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->ops->say(cmd->client, conn, "You are on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } } /* Parse the typed nickname. */ - if (!silc_parse_nickname(cmd->argv[3], &nickname, &server, &num)) { - cmd->client->ops->say(cmd->client, conn, "Bad nickname"); - COMMAND_ERROR; - goto out; - } + if (client->params->nickname_parse) + client->params->nickname_parse(cmd->argv[3], &nickname); + else + nickname = strdup(cmd->argv[3]); /* Find client entry */ - client_entry = silc_idlist_get_client(cmd->client, conn, - nickname, server, num, TRUE); + client_entry = silc_idlist_get_client(cmd->client, conn, nickname, + cmd->argv[3], TRUE); if (!client_entry) { + silc_free(nickname); + if (cmd->pending) { COMMAND_ERROR; goto out; @@ -1416,9 +1388,10 @@ SILC_CLIENT_CMD_FUNC(cumode) return; } + /* Get the current mode */ while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) { if (chu->client == client_entry) { - chu->mode = mode; + mode = chu->mode; break; } } @@ -1499,10 +1472,7 @@ SILC_CLIENT_CMD_FUNC(cumode) COMMAND; out: - if (nickname) - silc_free(nickname); - if (server) - silc_free(server); + silc_free(nickname); silc_client_command_free(cmd); } @@ -1511,14 +1481,14 @@ SILC_CLIENT_CMD_FUNC(cumode) SILC_CLIENT_CMD_FUNC(kick) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; + SilcClient client = cmd->client; SilcClientConnection conn = cmd->conn; SilcIDCacheEntry id_cache = NULL; SilcChannelEntry channel; SilcBuffer buffer, idp, idp2; SilcClientEntry target; char *name; - uint32 num = 0; - char *nickname = NULL, *server = NULL; + char *nickname = NULL; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -1527,7 +1497,7 @@ SILC_CLIENT_CMD_FUNC(kick) } if (cmd->argc < 3) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /KICK []"); COMMAND_ERROR; goto out; @@ -1535,7 +1505,8 @@ SILC_CLIENT_CMD_FUNC(kick) if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1545,14 +1516,16 @@ SILC_CLIENT_CMD_FUNC(kick) } if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on that channel"); + cmd->client->ops->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->ops->say(cmd->client, conn, "You are not on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } @@ -1560,17 +1533,17 @@ SILC_CLIENT_CMD_FUNC(kick) channel = (SilcChannelEntry)id_cache->context; /* Parse the typed nickname. */ - if (!silc_parse_nickname(cmd->argv[2], &nickname, &server, &num)) { - cmd->client->ops->say(cmd->client, conn, "Bad nickname"); - COMMAND_ERROR; - goto out; - } + if (client->params->nickname_parse) + client->params->nickname_parse(cmd->argv[2], &nickname); + else + nickname = strdup(cmd->argv[2]); /* Get the target client */ target = silc_idlist_get_client(cmd->client, conn, nickname, - server, num, FALSE); + cmd->argv[2], FALSE); if (!target) { - cmd->client->ops->say(cmd->client, conn, "No such client: %s", + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "No such client: %s", cmd->argv[2]); COMMAND_ERROR; goto out; @@ -1599,10 +1572,7 @@ SILC_CLIENT_CMD_FUNC(kick) COMMAND; out: - if (nickname) - silc_free(nickname); - if (server) - silc_free(server); + silc_free(nickname); silc_client_command_free(cmd); } @@ -1613,11 +1583,15 @@ static void silc_client_command_oper_send(unsigned char *data, SilcClientConnection conn = cmd->conn; SilcBuffer buffer, auth; - if (cmd->argc == 3) { - /* Pulic key auth XXX TODO */ - auth = NULL; + if (cmd->argc >= 3) { + /* Encode the public key authentication payload */ + auth = silc_auth_public_key_auth_generate(cmd->client->public_key, + cmd->client->private_key, + conn->hash, + conn->local_id, + SILC_ID_CLIENT); } else { - /* Encode the authentication payload */ + /* Encode the password authentication payload */ auth = silc_auth_payload_encode(SILC_AUTH_PASSWORD, NULL, 0, data, data_len); } @@ -1642,8 +1616,6 @@ SILC_CLIENT_CMD_FUNC(oper) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; - unsigned char *auth_data; - uint32 auth_data_len = 0; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -1652,18 +1624,13 @@ SILC_CLIENT_CMD_FUNC(oper) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, - "Usage: /OPER []"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /OPER [-pubkey]"); COMMAND_ERROR; goto out; } - if (cmd->argc == 3) { - /* XXX Get public key */ - auth_data = NULL; - COMMAND_ERROR; - goto out; - } else { + if (cmd->argc < 3) { /* Get passphrase */ cmd->client->ops->ask_passphrase(cmd->client, conn, silc_client_command_oper_send, @@ -1671,13 +1638,7 @@ SILC_CLIENT_CMD_FUNC(oper) return; } - silc_client_command_oper_send(auth_data, auth_data_len, context); - - memset(auth_data, 0, auth_data_len); - silc_free(auth_data); - - /* Notify application */ - COMMAND; + silc_client_command_oper_send(NULL, 0, context); out: silc_client_command_free(cmd); @@ -1690,11 +1651,15 @@ static void silc_client_command_silcoper_send(unsigned char *data, SilcClientConnection conn = cmd->conn; SilcBuffer buffer, auth; - if (cmd->argc == 3) { - /* Pulic key auth XXX TODO */ - auth = NULL; + if (cmd->argc >= 3) { + /* Encode the public key authentication payload */ + auth = silc_auth_public_key_auth_generate(cmd->client->public_key, + cmd->client->private_key, + conn->hash, + conn->local_id, + SILC_ID_CLIENT); } else { - /* Encode the authentication payload */ + /* Encode the password authentication payload */ auth = silc_auth_payload_encode(SILC_AUTH_PASSWORD, NULL, 0, data, data_len); } @@ -1719,8 +1684,6 @@ SILC_CLIENT_CMD_FUNC(silcoper) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; - unsigned char *auth_data; - uint32 auth_data_len = 0; if (!cmd->conn) { SILC_NOT_CONNECTED(cmd->client, cmd->conn); @@ -1729,18 +1692,13 @@ SILC_CLIENT_CMD_FUNC(silcoper) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, - "Usage: /SILCOPER []"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /SILCOPER [-pubkey]"); COMMAND_ERROR; goto out; } - if (cmd->argc == 3) { - /* XXX Get public key */ - auth_data = NULL; - COMMAND_ERROR; - goto out; - } else { + if (cmd->argc < 3) { /* Get passphrase */ cmd->client->ops->ask_passphrase(cmd->client, conn, silc_client_command_silcoper_send, @@ -1748,13 +1706,7 @@ SILC_CLIENT_CMD_FUNC(silcoper) return; } - silc_client_command_silcoper_send(auth_data, auth_data_len, context); - - memset(auth_data, 0, auth_data_len); - silc_free(auth_data); - - /* Notify application */ - COMMAND; + silc_client_command_silcoper_send(NULL, 0, context); out: silc_client_command_free(cmd); @@ -1777,7 +1729,7 @@ SILC_CLIENT_CMD_FUNC(connect) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CONNECT []"); COMMAND_ERROR; goto out; @@ -1826,7 +1778,7 @@ SILC_CLIENT_CMD_FUNC(ban) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /BAN " "[+|-[[@[![@hostname>]]]]]"); COMMAND_ERROR; @@ -1835,7 +1787,8 @@ SILC_CLIENT_CMD_FUNC(ban) if (cmd->argv[1][0] == '*') { if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1846,7 +1799,8 @@ SILC_CLIENT_CMD_FUNC(ban) channel = silc_client_get_channel(cmd->client, conn, name); if (!channel) { - cmd->client->ops->say(cmd->client, conn, "You are on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are on that channel"); COMMAND_ERROR; goto out; } @@ -1902,7 +1856,7 @@ SILC_CLIENT_CMD_FUNC(close) } if (cmd->argc < 2) { - cmd->client->ops->say(cmd->client, conn, + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, "Usage: /CLOSE []"); COMMAND_ERROR; goto out; @@ -1974,14 +1928,16 @@ SILC_CLIENT_CMD_FUNC(leave) } if (cmd->argc != 2) { - cmd->client->ops->say(cmd->client, conn, "Usage: /LEAVE "); + cmd->client->ops->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->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -1992,7 +1948,8 @@ SILC_CLIENT_CMD_FUNC(leave) /* Get the Channel ID of the channel */ if (!silc_idcache_find_by_name_one(conn->channel_cache, name, &id_cache)) { - cmd->client->ops->say(cmd->client, conn, "You are not on that channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on that channel"); COMMAND_ERROR; goto out; } @@ -2014,12 +1971,7 @@ SILC_CLIENT_CMD_FUNC(leave) if (conn->current_channel == channel) conn->current_channel = NULL; - silc_idcache_del_by_id(conn->channel_cache, channel->id); - silc_free(channel->channel_name); - silc_free(channel->id); - silc_free(channel->key); - silc_cipher_free(channel->channel_key); - silc_free(channel); + silc_client_del_channel(cmd->client, cmd->conn, channel); out: silc_client_command_free(cmd); @@ -2032,9 +1984,7 @@ SILC_CLIENT_CMD_FUNC(users) { SilcClientCommandContext cmd = (SilcClientCommandContext)context; SilcClientConnection conn = cmd->conn; - SilcIDCacheEntry id_cache = NULL; - SilcChannelEntry channel; - SilcBuffer buffer, idp; + SilcBuffer buffer; char *name; if (!cmd->conn) { @@ -2044,14 +1994,16 @@ SILC_CLIENT_CMD_FUNC(users) } if (cmd->argc != 2) { - cmd->client->ops->say(cmd->client, conn, "Usage: /USERS "); + cmd->client->ops->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->ops->say(cmd->client, conn, "You are not on any channel"); + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_INFO, + "You are not on any channel"); COMMAND_ERROR; goto out; } @@ -2060,45 +2012,14 @@ SILC_CLIENT_CMD_FUNC(users) name = cmd->argv[1]; } - if (!conn->current_channel) { - cmd->client->ops->say(cmd->client, conn, "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)) { - /* XXX should resolve the channel ID; LIST command */ - cmd->client->ops->say(cmd->client, conn, - "You are not on that channel", name); - COMMAND_ERROR; - goto out; - } - - channel = (SilcChannelEntry)id_cache->context; - - if (!cmd->pending) { - /* Send USERS command to the server */ - idp = silc_id_payload_encode(id_cache->id, SILC_ID_CHANNEL); - buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS, - ++conn->cmd_ident, 1, - 1, idp->data, idp->len); - silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, - NULL, 0, NULL, NULL, buffer->data, - buffer->len, TRUE); - silc_buffer_free(buffer); - silc_buffer_free(idp); - - /* Register pending callback which will recall this command callback with - same context and reprocesses the command. When reprocessing we actually - display the information on the screen. */ - silc_client_command_pending(conn, SILC_COMMAND_USERS, conn->cmd_ident, - silc_client_command_destructor, - silc_client_command_users, - silc_client_command_dup(cmd)); - cmd->pending = TRUE; - return; - } + /* Send USERS command to the server */ + buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS, + ++conn->cmd_ident, 1, + 2, name, strlen(name)); + silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, + NULL, 0, NULL, NULL, buffer->data, + buffer->len, TRUE); + silc_buffer_free(buffer); /* Notify application */ COMMAND; @@ -2115,8 +2036,8 @@ SILC_CLIENT_CMD_FUNC(getkey) SilcClientConnection conn = cmd->conn; SilcClient client = cmd->client; SilcClientEntry client_entry = NULL; - uint32 num = 0; - char *nickname = NULL, *server = NULL; + SilcServerEntry server_entry = NULL; + char *nickname = NULL; SilcBuffer idp, buffer; if (!cmd->conn) { @@ -2126,34 +2047,58 @@ SILC_CLIENT_CMD_FUNC(getkey) } if (cmd->argc < 2) { - client->ops->say(client, conn, "Usage: /GETKEY "); + client->ops->say(client, conn, SILC_CLIENT_MESSAGE_INFO, + "Usage: /GETKEY "); COMMAND_ERROR; goto out; } /* Parse the typed nickname. */ - if (!silc_parse_nickname(cmd->argv[1], &nickname, &server, &num)) { - client->ops->say(client, conn, "Bad nickname"); - COMMAND_ERROR; - goto out; - } + if (client->params->nickname_parse) + client->params->nickname_parse(cmd->argv[1], &nickname); + else + nickname = strdup(cmd->argv[1]); /* Find client entry */ - client_entry = silc_idlist_get_client(client, conn, nickname, server, num, - TRUE); + client_entry = silc_idlist_get_client(client, conn, nickname, cmd->argv[1], + FALSE); if (!client_entry) { - /* 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_getkey, - silc_client_command_dup(cmd)); - cmd->pending = 1; - return; + /* Check whether user requested server actually */ + server_entry = silc_client_get_server(client, conn, cmd->argv[1]); + + if (!server_entry) { + /* 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 INFO command to resolve the server. */ + silc_client_send_command(client, conn, SILC_COMMAND_INFO, + ++conn->cmd_ident, 1, + 1, cmd->argv[1], cmd->argv_lens[1]); + silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY, + conn->cmd_ident, + silc_client_command_destructor, + 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); + } else { + idp = silc_id_payload_encode(client_entry->id, SILC_ID_CLIENT); } - idp = silc_id_payload_encode(client_entry->id, SILC_ID_CLIENT); buffer = silc_command_payload_encode_va(SILC_COMMAND_GETKEY, 0, 1, 1, idp->data, idp->len); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, @@ -2165,5 +2110,6 @@ SILC_CLIENT_CMD_FUNC(getkey) COMMAND; out: + silc_free(nickname); silc_client_command_free(cmd); }