From: Pekka Riikonen Date: Mon, 9 Oct 2000 11:40:03 +0000 (+0000) Subject: Implemented new notify payload handling. Also changed notify X-Git-Tag: SILC.0.1~359 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=aaf475b988510db3cbce709e5bd2f06e6cf103da;p=silc.git Implemented new notify payload handling. Also changed notify client operation in ops.h Changed to use new generic payloads. Bugfixes. --- diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 99d8114e..8987f34e 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -963,8 +963,7 @@ void silc_client_packet_send_to_channel(SilcClient client, silc_hash_make(client->md5hash, channel->iv, 16, channel->iv); /* Encode the channel payload */ - payload = silc_channel_encode_payload(strlen(conn->nickname), conn->nickname, - data_len, data, 16, channel->iv, + payload = silc_channel_payload_encode(data_len, data, 16, channel->iv, client->rng); if (!payload) { client->ops->say(client, conn, @@ -1256,16 +1255,105 @@ void silc_client_notify_by_server(SilcClient client, SilcSocketConnection sock, SilcBuffer message) { - char *msg; + SilcClientConnection conn = (SilcClientConnection)sock->user_data; + SilcNotifyPayload payload; SilcNotifyType type; + SilcArgumentPayload args; - SILC_GET16_MSB(type, message->data); - silc_buffer_pull(message, 2); + payload = silc_notify_payload_parse(message); + type = silc_notify_get_type(payload); + args = silc_notify_get_args(payload); - msg = silc_calloc(message->len + 1, sizeof(char)); - memcpy(msg, message->data, message->len); - client->ops->notify(client, sock->user_data, type, msg); - silc_free(msg); + switch(type) { + case SILC_NOTIFY_TYPE_NONE: + break; + case SILC_NOTIFY_TYPE_INVITE: + break; + case SILC_NOTIFY_TYPE_JOIN: + { + SilcClientID *client_id; + SilcChannelID *channel_id; + SilcClientEntry new_client; + SilcChannelEntry channel; + SilcIDPayload idp; + SilcBuffer idp_buf; + SilcIDCacheEntry id_cache = NULL; + unsigned char *tmp; + unsigned int tmp_len; + + /* Get client ID (it's in ID payload) */ + tmp = silc_argument_get_arg_type(args, 1, &tmp_len); + idp_buf = silc_buffer_alloc(tmp_len); + silc_buffer_pull_tail(idp_buf, SILC_BUFFER_END(idp_buf)); + silc_buffer_put(idp_buf, tmp, tmp_len); + + /* Parse ID payload and get the ID */ + idp = silc_id_payload_parse(idp_buf); + client_id = silc_id_payload_get_id(idp); + + silc_id_payload_free(idp); + silc_buffer_free(idp_buf); + + /* If it's my ID, ignore */ + if (!SILC_ID_CLIENT_COMPARE(client_id, conn->local_id)) + break; + + /* Check if we have that ID already */ + if (silc_idcache_find_by_id_one(conn->client_cache, (void *)client_id, + SILC_ID_CLIENT, NULL)) + break; + + /* Add client to cache */ + new_client = silc_calloc(1, sizeof(*new_client)); + new_client->id = client_id; + new_client->nickname = + strdup(silc_argument_get_arg_type(args, 2, NULL)); + silc_idcache_add(conn->client_cache, new_client->nickname, + SILC_ID_CLIENT, client_id, (void *)new_client, TRUE); + + /* Get Channel ID (it's in ID payload) */ + tmp = silc_argument_get_arg_type(args, 5, &tmp_len); + idp_buf = silc_buffer_alloc(tmp_len); + silc_buffer_pull_tail(idp_buf, SILC_BUFFER_END(idp_buf)); + silc_buffer_put(idp_buf, tmp, tmp_len); + + /* Parse ID payload and get the ID */ + idp = silc_id_payload_parse(idp_buf); + channel_id = silc_id_payload_get_id(idp); + + silc_id_payload_free(idp); + silc_buffer_free(idp_buf); + + /* Find channel entry */ + if (!silc_idcache_find_by_id_one(conn->channel_cache, (void *)channel_id, + SILC_ID_CHANNEL, &id_cache)) + break; + + channel = (SilcChannelEntry)id_cache->context; + + /* Add client to channel */ + channel->clients = silc_realloc(channel->clients, + sizeof(*channel->clients) * + (channel->clients_count + 1)); + channel->clients[channel->clients_count] = new_client; + channel->clients_count++; + + /* XXX add support for multiple same nicks on same channel. Check + for them here */ + } + break; + case SILC_NOTIFY_TYPE_LEAVE: + break; + case SILC_NOTIFY_TYPE_SIGNOFF: + break; + case SILC_NOTIFY_TYPE_TOPIC_SET: + break; + default: + break; + } + + client->ops->notify(client, conn, payload); + silc_notify_payload_free(payload); } /* Processes the received new Client ID from server. Old Client ID is @@ -1347,13 +1435,13 @@ void silc_client_receive_channel_key(SilcClient client, SILC_LOG_DEBUG(("Received key for channel")); - payload = silc_channel_key_parse_payload(packet); + payload = silc_channel_key_payload_parse(packet); if (!payload) return; id_string = silc_channel_key_get_id(payload, NULL); if (!id_string) { - silc_channel_key_free_payload(payload); + silc_channel_key_payload_free(payload); return; } id = silc_id_str2id(id_string, SILC_ID_CHANNEL); @@ -1386,7 +1474,7 @@ void silc_client_receive_channel_key(SilcClient client, out: silc_free(id); - silc_channel_key_free_payload(payload); + silc_channel_key_payload_free(payload); } /* Process received message to a channel (or from a channel, really). This @@ -1430,14 +1518,12 @@ void silc_client_channel_message(SilcClient client, silc_buffer_pull_tail(buffer, 16); /* Parse the channel message payload */ - payload = silc_channel_parse_payload(buffer); + payload = silc_channel_payload_parse(buffer); if (!payload) goto out; - nickname = silc_channel_get_nickname(payload, NULL); - if (!nickname) - goto out; - + /* Find nickname */ + nickname = "[unknown]"; for (i = 0; i < channel->clients_count; i++) { if (channel->clients[i] && !SILC_ID_CLIENT_COMPARE(channel->clients[i]->id, client_id)) @@ -1461,7 +1547,7 @@ void silc_client_channel_message(SilcClient client, if (client_id) silc_free(client_id); if (payload) - silc_channel_free_payload(payload); + silc_channel_payload_free(payload); } /* Private message received. This processes the private message and diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 4797201a..30c4cba3 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -185,9 +185,10 @@ SILC_CLIENT_CMD_FUNC(whois) goto out; } - buffer = silc_command_encode_payload(SILC_COMMAND_WHOIS, + buffer = silc_command_payload_encode(SILC_COMMAND_WHOIS, cmd->argc - 1, ++cmd->argv, - ++cmd->argv_lens, ++cmd->argv_types); + ++cmd->argv_lens, ++cmd->argv_types, + 0); silc_client_packet_send(cmd->client, cmd->conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); @@ -229,9 +230,10 @@ SILC_CLIENT_CMD_FUNC(identify) goto out; } - buffer = silc_command_encode_payload(SILC_COMMAND_IDENTIFY, + buffer = silc_command_payload_encode(SILC_COMMAND_IDENTIFY, cmd->argc - 1, ++cmd->argv, - ++cmd->argv_lens, ++cmd->argv_types); + ++cmd->argv_lens, ++cmd->argv_types, + 0); silc_client_packet_send(cmd->client, cmd->conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); @@ -278,9 +280,10 @@ SILC_CLIENT_CMD_FUNC(nick) } /* Set new nickname */ - buffer = silc_command_encode_payload(SILC_COMMAND_NICK, + buffer = silc_command_payload_encode(SILC_COMMAND_NICK, cmd->argc - 1, ++cmd->argv, - ++cmd->argv_lens, ++cmd->argv_types); + ++cmd->argv_lens, ++cmd->argv_types, + 0); silc_client_packet_send(cmd->client, cmd->conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); @@ -357,13 +360,14 @@ SILC_CLIENT_CMD_FUNC(topic) /* Send TOPIC command to the server */ id_string = silc_id_id2str(id_cache->id, SILC_ID_CHANNEL); if (cmd->argc > 2) - buffer = silc_command_encode_payload_va(SILC_COMMAND_TOPIC, 2, + buffer = silc_command_payload_encode_va(SILC_COMMAND_TOPIC, 0, 2, 1, id_string, SILC_ID_CHANNEL_LEN, 2, cmd->argv[2], strlen(cmd->argv[2])); else - buffer = silc_command_encode_payload_va(SILC_COMMAND_TOPIC, 1, - 1, id_string, SILC_ID_CHANNEL_LEN); + buffer = silc_command_payload_encode_va(SILC_COMMAND_TOPIC, 1, + 1, id_string, SILC_ID_CHANNEL_LEN, + 0); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); silc_buffer_free(buffer); @@ -432,7 +436,7 @@ SILC_CLIENT_CMD_FUNC(invite) channel_id = silc_id_id2str(channel_entry->id, SILC_ID_CHANNEL); - buffer = silc_command_encode_payload_va(SILC_COMMAND_INVITE, 2, + buffer = silc_command_payload_encode_va(SILC_COMMAND_INVITE, 0, 2, 1, client_id, SILC_ID_CLIENT_LEN, 2, channel_id, SILC_ID_CHANNEL_LEN); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, @@ -463,9 +467,9 @@ SILC_CLIENT_CMD_FUNC(quit) goto out; } - buffer = silc_command_encode_payload(SILC_COMMAND_QUIT, cmd->argc - 1, + buffer = silc_command_payload_encode(SILC_COMMAND_QUIT, cmd->argc - 1, ++cmd->argv, ++cmd->argv_lens, - ++cmd->argv_types); + ++cmd->argv_types, 0); silc_client_packet_send(cmd->client, cmd->conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); @@ -511,7 +515,7 @@ SILC_CLIENT_CMD_FUNC(info) name = strdup(cmd->argv[1]); /* Send the command */ - buffer = silc_command_encode_payload_va(SILC_COMMAND_INFO, 1, + buffer = silc_command_payload_encode_va(SILC_COMMAND_INFO, 0, 1, 1, name, strlen(name)); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); @@ -552,7 +556,7 @@ SILC_CLIENT_CMD_FUNC(ping) id = silc_id_str2id(conn->remote_id_data, SILC_ID_SERVER); /* Send the command */ - buffer = silc_command_encode_payload_va(SILC_COMMAND_PING, 1, + buffer = silc_command_payload_encode_va(SILC_COMMAND_PING, 0, 1, 1, conn->remote_id_data, SILC_ID_SERVER_LEN); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, @@ -632,9 +636,9 @@ SILC_CLIENT_CMD_FUNC(join) } /* Send JOIN command to the server */ - buffer = silc_command_encode_payload(SILC_COMMAND_JOIN, + buffer = silc_command_payload_encode(SILC_COMMAND_JOIN, cmd->argc - 1, ++cmd->argv, - ++cmd->argv_lens, ++cmd->argv_types); + ++cmd->argv_lens, ++cmd->argv_types, 0); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); silc_buffer_free(buffer); @@ -669,7 +673,7 @@ SILC_CLIENT_CMD_FUNC(motd) } /* Send TOPIC command to the server */ - buffer = silc_command_encode_payload_va(SILC_COMMAND_MOTD, 1, + buffer = silc_command_payload_encode_va(SILC_COMMAND_MOTD, 0, 1, 2, conn->remote_host, strlen(conn->remote_host)); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, @@ -763,7 +767,7 @@ SILC_CLIENT_CMD_FUNC(leave) /* Send LEAVE command to the server */ id_string = silc_id_id2str(id_cache->id, SILC_ID_CHANNEL); - buffer = silc_command_encode_payload_va(SILC_COMMAND_LEAVE, 1, + buffer = silc_command_payload_encode_va(SILC_COMMAND_LEAVE, 0, 1, 1, id_string, SILC_ID_CHANNEL_LEN); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); @@ -829,7 +833,7 @@ SILC_CLIENT_CMD_FUNC(names) /* Send NAMES command to the server */ id_string = silc_id_id2str(id_cache->id, SILC_ID_CHANNEL); - buffer = silc_command_encode_payload_va(SILC_COMMAND_NAMES, 1, + buffer = silc_command_payload_encode_va(SILC_COMMAND_NAMES, 0, 1, 1, id_string, SILC_ID_CHANNEL_LEN); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 64fb1f6b..d0218009 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -126,7 +126,7 @@ void silc_client_command_reply_process(SilcClient client, SilcCommandPayload payload; /* Get command reply payload from packet */ - payload = silc_command_parse_payload(buffer); + payload = silc_command_payload_parse(buffer); if (!payload) { /* Silently ignore bad reply packet */ SILC_LOG_DEBUG(("Bad command reply packet")); @@ -139,6 +139,7 @@ void silc_client_command_reply_process(SilcClient client, ctx->client = client; ctx->sock = sock; ctx->payload = payload; + ctx->args = silc_command_get_args(ctx->payload); ctx->packet = packet; /* Check for pending commands and mark to be exeucted */ @@ -189,21 +190,21 @@ silc_client_command_reply_whois_print(SilcClientCommandReplyContext cmd, memset(buf, 0, sizeof(buf)); - argc = silc_command_get_arg_num(cmd->payload); - id_data = silc_command_get_arg_type(cmd->payload, 2, NULL); + argc = silc_argument_get_arg_num(cmd->args); + id_data = silc_argument_get_arg_type(cmd->args, 2, NULL); - nickname = silc_command_get_arg_type(cmd->payload, 3, &len); + nickname = silc_argument_get_arg_type(cmd->args, 3, &len); if (nickname) { strncat(buf, nickname, len); strncat(buf, " is ", 4); } - username = silc_command_get_arg_type(cmd->payload, 4, &len); + username = silc_argument_get_arg_type(cmd->args, 4, &len); if (username) { strncat(buf, username, len); } - realname = silc_command_get_arg_type(cmd->payload, 5, &len); + realname = silc_argument_get_arg_type(cmd->args, 5, &len); if (realname) { strncat(buf, " (", 2); strncat(buf, realname, len); @@ -229,7 +230,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(whois) SILC_LOG_DEBUG(("Start")); - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK && status != SILC_STATUS_LIST_START && @@ -237,7 +238,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(whois) status != SILC_STATUS_LIST_END) { if (status == SILC_STATUS_ERR_NO_SUCH_NICK) { /* Take nickname which may be provided */ - tmp = silc_command_get_arg_type(cmd->payload, 3, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 3, NULL); if (tmp) cmd->client->ops->say(cmd->client, conn, "%s: %s", tmp, silc_client_command_status_message(status)); @@ -296,12 +297,12 @@ SILC_CLIENT_CMD_REPLY_FUNC(identify) SILC_LOG_DEBUG(("Start")); - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { if (status == SILC_STATUS_ERR_NO_SUCH_NICK) { /* Take nickname which may be provided */ - tmp = silc_command_get_arg_type(cmd->payload, 3, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 3, NULL); if (tmp) cmd->client->ops->say(cmd->client, conn, "%s: %s", tmp, silc_client_command_status_message(status)); @@ -323,8 +324,8 @@ SILC_CLIENT_CMD_REPLY_FUNC(identify) unsigned char *id_data; char *nickname; - id_data = silc_command_get_arg_type(cmd->payload, 2, NULL); - nickname = silc_command_get_arg_type(cmd->payload, 3, NULL); + id_data = silc_argument_get_arg_type(cmd->args, 2, NULL); + nickname = silc_argument_get_arg_type(cmd->args, 3, NULL); /* Allocate client entry */ client_entry = silc_calloc(1, sizeof(*client_entry)); @@ -364,7 +365,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) SILC_LOG_DEBUG(("Start")); - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, "Cannot set nickname: %s", @@ -373,7 +374,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) goto out; } - argc = silc_command_get_arg_num(cmd->payload); + argc = silc_argument_get_arg_num(cmd->args); if (argc < 2 || argc > 2) { cmd->client->ops->say(cmd->client, conn, "Cannot set nickname: bad reply to command"); @@ -382,7 +383,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) } /* Take received Client ID */ - id_string = silc_command_get_arg_type(cmd->payload, 2, NULL); + id_string = silc_argument_get_arg_type(cmd->args, 2, NULL); silc_client_receive_new_id(cmd->client, cmd->sock, id_string); /* Notify application */ @@ -411,7 +412,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(topic) char *topic; int argc; - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -421,21 +422,21 @@ SILC_CLIENT_CMD_REPLY_FUNC(topic) return; } - argc = silc_command_get_arg_num(cmd->payload); + argc = silc_argument_get_arg_num(cmd->args); if (argc < 1 || argc > 3) { COMMAND_REPLY_ERROR; goto out; } /* Take Channel ID */ - id_string = silc_command_get_arg_type(cmd->payload, 2, NULL); + id_string = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!id_string) goto out; channel_id = silc_id_str2id(id_string, SILC_ID_CHANNEL); /* Take topic */ - topic = silc_command_get_arg_type(cmd->payload, 3, NULL); + topic = silc_argument_get_arg_type(cmd->args, 3, NULL); if (!topic) goto out; @@ -471,7 +472,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(invite) SilcCommandStatus status; unsigned char *tmp; - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -507,7 +508,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(info) SilcCommandStatus status; unsigned char *tmp; - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -518,14 +519,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(info) } /* Get server ID */ - tmp = silc_command_get_arg_type(cmd->payload, 2, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!tmp) goto out; /* XXX save server id */ /* Get server info */ - tmp = silc_command_get_arg_type(cmd->payload, 3, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 3, NULL); if (!tmp) goto out; @@ -555,7 +556,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping) int i; time_t diff, curtime; - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -609,7 +610,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) SILC_LOG_DEBUG(("Start")); - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -618,7 +619,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) goto out; } - argc = silc_command_get_arg_num(cmd->payload); + argc = silc_argument_get_arg_num(cmd->args); if (argc < 3 || argc > 5) { cmd->client->ops->say(cmd->client, conn, "Cannot join channel: Bad reply packet"); @@ -627,7 +628,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) } /* Get channel name */ - tmp = silc_command_get_arg_type(cmd->payload, 2, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!tmp) { cmd->client->ops->say(cmd->client, conn, "Cannot join channel: Bad reply packet"); @@ -637,7 +638,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) channel_name = strdup(tmp); /* Get Channel ID */ - id_string = silc_command_get_arg_type(cmd->payload, 3, NULL); + id_string = silc_argument_get_arg_type(cmd->args, 3, NULL); if (!id_string) { cmd->client->ops->say(cmd->client, conn, "Cannot join channel: Bad reply packet"); @@ -646,14 +647,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) } /* Get channel mode */ - tmp = silc_command_get_arg_type(cmd->payload, 4, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 4, NULL); if (tmp) SILC_GET32_MSB(mode, tmp); else mode = 0; /* Get topic */ - topic = silc_command_get_arg_type(cmd->payload, 5, NULL); + topic = silc_argument_get_arg_type(cmd->args, 5, NULL); /* Save received Channel ID */ silc_client_new_channel_id(cmd->client, cmd->sock, channel_name, @@ -682,7 +683,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(motd) unsigned char *tmp; char *motd = NULL, *cp, line[256]; - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -691,14 +692,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(motd) return; } - argc = silc_command_get_arg_num(cmd->payload); + argc = silc_argument_get_arg_num(cmd->args); if (argc > 2) { COMMAND_REPLY_ERROR; goto out; } if (argc == 2) { - motd = silc_command_get_arg_type(cmd->payload, 2, NULL); + motd = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!motd) { COMMAND_REPLY_ERROR; goto out; @@ -769,7 +770,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(leave) SilcCommandStatus status; unsigned char *tmp; - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -802,7 +803,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(names) SILC_LOG_DEBUG(("Start")); - tmp = silc_command_get_arg_type(cmd->payload, 1, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 1, NULL); SILC_GET16_MSB(status, tmp); if (status != SILC_STATUS_OK) { cmd->client->ops->say(cmd->client, conn, @@ -812,7 +813,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(names) } /* Get channel ID */ - tmp = silc_command_get_arg_type(cmd->payload, 2, NULL); + tmp = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!tmp) { cmd->client->ops->say(cmd->client, conn, "Cannot get user list: Bad reply packet"); @@ -822,7 +823,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(names) channel_id = silc_id_str2id(tmp, SILC_ID_CHANNEL); /* Get the name list of the channel */ - name_list = silc_command_get_arg_type(cmd->payload, 3, &len1); + name_list = silc_argument_get_arg_type(cmd->args, 3, &len1); if (!name_list) { cmd->client->ops->say(cmd->client, conn, "Cannot get user list: Bad reply packet"); @@ -831,7 +832,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(names) } /* Get Client ID list */ - tmp = silc_command_get_arg_type(cmd->payload, 4, &len2); + tmp = silc_argument_get_arg_type(cmd->args, 4, &len2); if (!tmp) { cmd->client->ops->say(cmd->client, conn, "Cannot get user list: Bad reply packet"); diff --git a/lib/silcclient/command_reply.h b/lib/silcclient/command_reply.h index 1a7e0578..12688670 100644 --- a/lib/silcclient/command_reply.h +++ b/lib/silcclient/command_reply.h @@ -35,6 +35,7 @@ typedef struct { SilcClient client; SilcSocketConnection sock; SilcCommandPayload payload; + SilcArgumentPayload args; SilcPacketContext *packet; /* If defined this executes the pending command. */ diff --git a/lib/silcclient/ops.h b/lib/silcclient/ops.h index 69da2416..ad63d197 100644 --- a/lib/silcclient/ops.h +++ b/lib/silcclient/ops.h @@ -38,7 +38,7 @@ typedef struct { void (*private_message)(SilcClient client, SilcClientConnection conn, char *sender, char *msg); void (*notify)(SilcClient client, SilcClientConnection conn, - SilcNotifyType type, char *msg); + SilcNotifyPayload notify_payload); void (*command)(SilcClient client, SilcClientConnection conn, SilcClientCommandContext cmd_context, int success, SilcCommand command); @@ -83,10 +83,14 @@ typedef struct { void (*notify)(SilcClient client, SilcClientConnection conn, - SilcNotifyType type, char *msg); - - Notify message to the client. The `type' is the notify type received - from server. The `msg' is a human readable message sent by the server. + SilcNotifyPayload notify_payload); + + Notify message to the client. The `notify_payload' is the Notify + Payload received from server. Client library may parse it to cache + some data received from the payload but it is the application's + responsiblity to retrieve the message and arguments from the payload. + The message in the payload sent by server is implementation specific + thus it is recommended that application will generate its own message. void (*command)(SilcClient client, SilcClientConnection conn, diff --git a/lib/silcclient/protocol.c b/lib/silcclient/protocol.c index 43fb6282..b1b9099a 100644 --- a/lib/silcclient/protocol.c +++ b/lib/silcclient/protocol.c @@ -147,6 +147,7 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) /* Allocate Key Exchange object */ ske = silc_ske_alloc(); ctx->ske = ske; + ske->rng = client->rng; if (ctx->responder == TRUE) { #if 0 @@ -164,7 +165,8 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange) SilcSKEStartPayload *start_payload; /* Assemble security properties. */ - silc_ske_assemble_security_properties(ske, silc_version_string, + silc_ske_assemble_security_properties(ske, SILC_SKE_SP_FLAG_NONE, + silc_version_string, &start_payload); /* Start the key exchange by sending our security properties