X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcclient%2Fcommand_reply.c;h=79acee69291f3865e8a859debadc8201eab32c59;hb=017dec75a98209fbef49eb496c2269b0c49e736d;hp=a264ec240597c0b4dc39b4a2e4b889b838e08f4d;hpb=a13a1924bf35d6f8d9422a2c60364329fd6511b3;p=silc.git diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index a264ec24..79acee69 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -82,8 +82,8 @@ const SilcCommandStatusMessage silc_command_status_messages[] = { { STAT(NO_SERVER_ID), "No Server ID given" }, { STAT(BAD_CLIENT_ID), "Bad Client ID" }, { STAT(BAD_CHANNEL_ID), "Bad Channel ID" }, - { STAT(NO_SUCH_CLIENT_ID), "There was no such client" }, - { STAT(NO_SUCH_CHANNEL_ID),"There was no such channel" }, + { STAT(NO_SUCH_CLIENT_ID), "There is no such client" }, + { STAT(NO_SUCH_CHANNEL_ID),"There is no such channel" }, { STAT(NICKNAME_IN_USE), "Nickname already exists" }, { STAT(NOT_ON_CHANNEL), "You are not on that channel" }, { STAT(USER_NOT_ON_CHANNEL),"They are not on the channel" }, @@ -257,43 +257,13 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd, silc_hash_client_id_compare, NULL, &id_cache)) { SILC_LOG_DEBUG(("Adding new client entry")); - - client_entry = silc_calloc(1, sizeof(*client_entry)); - client_entry->id = client_id; - silc_parse_nickname(nickname, &client_entry->nickname, - &client_entry->server, &client_entry->num); - client_entry->username = strdup(username); - if (realname) - client_entry->realname = strdup(realname); - client_entry->mode = mode; - - /* Add client to cache */ - silc_idcache_add(conn->client_cache, client_entry->nickname, - client_id, (void *)client_entry, FALSE); + client_entry = + silc_client_add_client(cmd->client, conn, nickname, username, realname, + client_id, mode); } else { client_entry = (SilcClientEntry)id_cache->context; - if (client_entry->nickname) - silc_free(client_entry->nickname); - if (client_entry->server) - silc_free(client_entry->server); - if (client_entry->username) - silc_free(client_entry->username); - if (client_entry->realname) - silc_free(client_entry->realname); - client_entry->mode = mode; - - SILC_LOG_DEBUG(("Updating client entry")); - - silc_parse_nickname(nickname, &client_entry->nickname, - &client_entry->server, &client_entry->num); - client_entry->username = strdup(username); - if (realname) - client_entry->realname = strdup(realname); - - /* Remove the old cache entry and create a new one */ - silc_idcache_del_by_context(conn->client_cache, client_entry); - silc_idcache_add(conn->client_cache, client_entry->nickname, - client_entry->id, client_entry, FALSE); + silc_client_update_client(cmd->client, conn, client_entry, + nickname, username, realname, mode); silc_free(client_id); } @@ -477,38 +447,13 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd, silc_hash_client_id_compare, NULL, &id_cache)) { SILC_LOG_DEBUG(("Adding new client entry")); - - client_entry = silc_calloc(1, sizeof(*client_entry)); - client_entry->id = silc_id_dup(client_id, id_type); - silc_parse_nickname(name, &client_entry->nickname, - &client_entry->server, &client_entry->num); - if (info) - client_entry->username = strdup(info); - - /* Add client to cache */ - silc_idcache_add(conn->client_cache, client_entry->nickname, - client_entry->id, (void *)client_entry, FALSE); + client_entry = + silc_client_add_client(cmd->client, conn, name, info, NULL, + silc_id_dup(client_id, id_type), 0); } else { client_entry = (SilcClientEntry)id_cache->context; - if (client_entry->nickname) - silc_free(client_entry->nickname); - if (client_entry->server) - silc_free(client_entry->server); - if (info && client_entry->username) - silc_free(client_entry->username); - - SILC_LOG_DEBUG(("Updating client entry")); - - silc_parse_nickname(name, &client_entry->nickname, - &client_entry->server, &client_entry->num); - - if (info) - client_entry->username = strdup(info); - - /* Remove the old cache entry and create a new one */ - silc_idcache_del_by_context(conn->client_cache, client_entry); - silc_idcache_add(conn->client_cache, client_entry->nickname, - client_entry->id, client_entry, FALSE); + silc_client_update_client(cmd->client, conn, client_entry, + name, info, NULL, 0); } /* Notify application */ @@ -527,7 +472,8 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd, server_entry = silc_calloc(1, sizeof(*server_entry)); server_entry->server_id = silc_id_dup(server_id, id_type); - server_entry->server_name = strdup(name); + if (name) + server_entry->server_name = strdup(name); if (info) server_entry->server_info = strdup(info); @@ -550,9 +496,12 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd, /* Check if we have this channel cached already. */ if (!silc_idcache_find_by_id_one(conn->channel_cache, (void *)channel_id, &id_cache)) { + if (!name) + break; + SILC_LOG_DEBUG(("Adding new channel entry")); channel_entry = silc_client_new_channel_id(client, conn->sock, - name, 0, idp); + strdup(name), 0, idp); } else { channel_entry = (SilcChannelEntry)id_cache->context; } @@ -1138,10 +1087,9 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) silc_hash_client_id_compare, NULL, &id_cache)) { /* No, we don't have it, add entry for it. */ - client_entry = silc_calloc(1, sizeof(*client_entry)); - client_entry->id = silc_id_dup(client_id, SILC_ID_CLIENT); - silc_idcache_add(conn->client_cache, NULL, client_entry->id, - (void *)client_entry, FALSE); + client_entry = + silc_client_add_client(cmd->client, conn, NULL, NULL, NULL, + silc_id_dup(client_id, SILC_ID_CLIENT), 0); } else { /* Yes, we have it already */ client_entry = (SilcClientEntry)id_cache->context; @@ -1935,21 +1883,19 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey) /* Get the public key payload */ tmp = silc_argument_get_arg_type(cmd->args, 3, &len); - if (!tmp) - goto out; - - /* Decode the public key */ - - SILC_GET16_MSB(pk_len, tmp); - SILC_GET16_MSB(type, tmp + 2); - pk = tmp + 4; - - if (type != SILC_SKE_PK_TYPE_SILC) - goto out; - - if (!silc_pkcs_public_key_decode(pk, pk_len, &public_key)) - goto out; - + if (tmp) { + /* Decode the public key */ + SILC_GET16_MSB(pk_len, tmp); + SILC_GET16_MSB(type, tmp + 2); + pk = tmp + 4; + + if (type != SILC_SKE_PK_TYPE_SILC) + goto out; + + if (!silc_pkcs_public_key_decode(pk, pk_len, &public_key)) + goto out; + } + id_type = silc_id_payload_get_type(idp); if (id_type == SILC_ID_CLIENT) { /* Received client's public key */