From: Pekka Riikonen Date: Mon, 26 Nov 2001 19:05:58 +0000 (+0000) Subject: updates. X-Git-Tag: silc.toolkit.0.7~16 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=4e64dd02ccecc9c497b8db8ecb09d017b9cef9a4 updates. --- diff --git a/CHANGES b/CHANGES index 5bd1c49a..e88cd101 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,11 @@ Mon Nov 26 18:09:48 EET 2001 Pekka Riikonen ' SilcDList for requests, because it is faster. Affected file is lib/silcsftp/sftp_client.c. + * Moved the ID Payload routines from lib/silccore/silcpayload.[ch] + into lib/silccore/silcid.[ch]. + + Renamed silcpayload.[ch] into silcargument.[ch]. + Mon Nov 26 15:01:53 CET 2001 Pekka Riikonen * If client entry is deleted with active key agreement diff --git a/TODO b/TODO index 3e1c4787..eb752293 100644 --- a/TODO +++ b/TODO @@ -45,8 +45,6 @@ TODO/bugs In SILC Server the JOIN command. This will bypass invite-only mode as well for the client who got the founder mode during JOIN. - o Make the SILC_NOTIFY_TYPE_KICKED send the kicker's client ID as well. - o After backup resume protocol the TOPIC_SET was not handled correctly by all (unknown Channel ID). @@ -108,7 +106,7 @@ TODO/bugs In SILC Server o IP address fields in configuration file should accept mask format as well, IP/MASK, and not just plain IP. - o Connection classes should be actually implemented in + o Connection classes should be actually implemented in serverconfig.c. They can be defined but they are totally ignored currently. And they should be redefined also. @@ -116,24 +114,6 @@ TODO/bugs In SILC Server TODO/bugs In SILC Libraries =========================== - o Optimizations to lib/silcsftp - - o Do not allocate new req for every client request. Use - preallocated requests and recycle them. - - o Use SilcList instead of SilcDList for requests. It is faster. - - o Do not allocate new buffer for every packet. Use preallocated - buffer and reallocate only if necessary. - - o All payload parsing (decoding) functions should take unsigned char * - and uint32 as data and data length as arguments. Now some of the - routines do already that but most of the routines use SilcBuffer. - The SilcBuffer ones should be removed since buf->data and buf->len - is more convenient to use. These are currently only cosmetic changes - but at some point must be done to make the payload interfaces - consistent. - o Incomplete IPv6 support: o All network routines in lib/silcutil/silcnet.[ch] does not @@ -141,6 +121,9 @@ TODO/bugs In SILC Libraries o silc_id_render supports only IPv4 based ID's in the file lib/silcutil/silcutil.c. + o Add silc_net_gethostbyname, silc_net_gethostbyaddr, + silc_net_gethostbyname_async and silc_net_gethostbyaddr_async functions. + TODO/Bugs in native WIN32 support (libraries) ============================================= diff --git a/apps/irssi/src/fe-common/silc/module-formats.c b/apps/irssi/src/fe-common/silc/module-formats.c index 9b5b6514..4a8ec128 100644 --- a/apps/irssi/src/fe-common/silc/module-formats.c +++ b/apps/irssi/src/fe-common/silc/module-formats.c @@ -43,8 +43,8 @@ FORMAT_REC fecommon_silc_formats[] = { { "ban_list", "channel {channel $0} ban list: $1", 2, { 0, 0 } }, { "no_ban_list", "channel {channel $0} ban list not set", 1, { 0 } }, { "inviting", "Inviting {nick $0} to channel {channel $1}", 2, { 0, 0 } }, - { "kicked_you", "You have been kicked off channel {channel $0} ($1)", 2, { 0, 0 } }, - { "kicked", "{nick $0} has been kicked off channel {channel $1} ($2)", 3, { 0, 0, 0 } }, + { "kicked_you", "You have been kicked off channel {channel $0} by {nick $1} ($2)", 3, { 0, 0 } }, + { "kicked", "{nick $0} has been kicked off channel {channel $1} by {nick $2} ($3)", 4, { 0, 0, 0 } }, { "killed_you", "You have been killed from the SILC Network", 0 }, { "killed", "{nick $0} has been killed from the SILC Network ($1)", 2, { 0, 0 } }, @@ -79,6 +79,7 @@ FORMAT_REC fecommon_silc_formats[] = { { "key_agreement_error", "Error occurred during key agreement with {nick $0}", 1, { 0 } }, { "key_agreement_failure", "Key agreement failed with {nick $0}", 1, { 0 } }, { "key_agreement_timeout", "Timeout during key agreement. The key agreement was not performed with {nick $0}", 1, { 0 } }, + { "key_agreement_aborted", "Key agreement was aborted with {nick $0}", 1, { 0 } }, { "pubkey_received", "Received {hilight $0} public key", 1, { 0 } }, { "pubkey_fingerprint", "Fingerprint and babbleprint for the {hilight $0} key are %: $1", 2, { 0, 0 } }, { "pubkey_babbleprint", " $0", 1, { 0 } }, diff --git a/apps/irssi/src/fe-common/silc/module-formats.h b/apps/irssi/src/fe-common/silc/module-formats.h index ce4595c3..62b2db5a 100644 --- a/apps/irssi/src/fe-common/silc/module-formats.h +++ b/apps/irssi/src/fe-common/silc/module-formats.h @@ -74,6 +74,7 @@ enum { SILCTXT_KEY_AGREEMENT_ERROR, SILCTXT_KEY_AGREEMENT_FAILURE, SILCTXT_KEY_AGREEMENT_TIMEOUT, + SILCTXT_KEY_AGREEMENT_ABORTED, SILCTXT_PUBKEY_RECEIVED, SILCTXT_PUBKEY_FINGERPRINT, SILCTXT_PUBKEY_BABBLEPRINT, diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 89ef6c80..9d7d7d86 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -439,7 +439,8 @@ silc_command_reply(SilcClient client, SilcClientConnection conn, silc_free(nick); if (channels) { - SilcDList list = silc_channel_payload_parse_list(channels); + SilcDList list = silc_channel_payload_parse_list(channels->data, + channels->len); if (list) { SilcChannelPayload entry; memset(buf, 0, sizeof(buf)); diff --git a/apps/irssi/src/silc/core/silc-channels.c b/apps/irssi/src/silc/core/silc-channels.c index da14bcdd..25d6b6a4 100644 --- a/apps/irssi/src/silc/core/silc-channels.c +++ b/apps/irssi/src/silc/core/silc-channels.c @@ -475,13 +475,14 @@ 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; + SilcClientEntry client_entry, kicker; SilcChannelEntry channel_entry; char *tmp; SILC_CHANNEL_REC *chanrec; client_entry = va_arg(va, SilcClientEntry); tmp = va_arg(va, char *); + kicker = va_arg(va, SilcClientEntry); channel_entry = va_arg(va, SilcChannelEntry); chanrec = silc_channel_find_entry(server, channel_entry); @@ -489,6 +490,7 @@ static void event_kick(SILC_SERVER_REC *server, va_list va) if (client_entry == conn->local_entry) { printformat_module("fe-common/silc", server, channel_entry->channel_name, MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED_YOU, + kicker->nickname, channel_entry->channel_name, tmp ? tmp : ""); if (chanrec) { chanrec->kicked = TRUE; @@ -498,6 +500,7 @@ static void event_kick(SILC_SERVER_REC *server, va_list va) printformat_module("fe-common/silc", server, channel_entry->channel_name, MSGLEVEL_CRAP, SILCTXT_CHANNEL_KICKED, client_entry->nickname, + kicker->nickname, channel_entry->channel_name, tmp ? tmp : ""); if (chanrec) { @@ -805,6 +808,11 @@ static void keyagr_completion(SilcClient client, SILCTXT_KEY_AGREEMENT_TIMEOUT, client_entry->nickname); break; + case SILC_KEY_AGREEMENT_ABORTED: + printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_CRAP, + SILCTXT_KEY_AGREEMENT_ABORTED, client_entry->nickname); + break; + default: break; } diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 80e4ed36..25b642f4 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -181,7 +181,8 @@ void silc_server_command_process(SilcServer server, ctx->packet = silc_packet_context_dup(packet); /* Save original packet */ /* Parse the command payload in the packet */ - ctx->payload = silc_command_payload_parse(packet->buffer); + ctx->payload = silc_command_payload_parse(packet->buffer->data, + packet->buffer->len); if (!ctx->payload) { SILC_LOG_ERROR(("Bad command payload, packet dropped")); silc_buffer_free(packet->buffer); @@ -1117,23 +1118,15 @@ silc_server_command_whowas_send_reply(SilcServerCommandContext cmd, strcat(uh, "*private*"); } - if (entry->userinfo) - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_WHOWAS, - status, ident, 4, - 2, idp->data, idp->len, - 3, nh, strlen(nh), - 4, uh, strlen(uh), - 5, entry->userinfo, - strlen(entry->userinfo)); - else - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_WHOWAS, - status, ident, 3, - 2, idp->data, idp->len, - 3, nh, strlen(nh), - 4, uh, strlen(uh)); - + packet = + silc_command_reply_payload_encode_va(SILC_COMMAND_WHOWAS, + status, ident, 4, + 2, idp->data, idp->len, + 3, nh, strlen(nh), + 4, uh, strlen(uh), + 5, entry->userinfo, + entry->userinfo ? + strlen(entry->userinfo) : 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -1394,7 +1387,7 @@ silc_server_command_identify_parse(SilcServerCommandContext cmd, if (!tmp) continue; - idp = silc_id_payload_parse_data(tmp, len); + idp = silc_id_payload_parse(tmp, len); if (!idp) { silc_free(*clients); silc_free(*servers); @@ -1763,19 +1756,13 @@ silc_server_command_identify_send_reply(SilcServerCommandContext cmd, /* Send IDENTIFY reply */ idp = silc_id_payload_encode(entry->id, SILC_ID_SERVER); - if (entry->server_name) { - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, - status, ident, 2, - 2, idp->data, idp->len, - 3, entry->server_name, - strlen(entry->server_name)); - } else { - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, - status, ident, 1, - 2, idp->data, idp->len); - } - + packet = + silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, + status, ident, 2, + 2, idp->data, idp->len, + 3, entry->server_name, + entry->server_name ? + strlen(entry->server_name) : 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -1809,19 +1796,13 @@ silc_server_command_identify_send_reply(SilcServerCommandContext cmd, /* Send IDENTIFY reply */ idp = silc_id_payload_encode(entry->id, SILC_ID_CHANNEL); - if (entry->channel_name) { - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, - status, ident, 2, - 2, idp->data, idp->len, - 3, entry->channel_name, - strlen(entry->channel_name)); - } else { - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, - status, ident, 1, - 2, idp->data, idp->len); - } - + packet = + silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, + status, ident, 2, + 2, idp->data, idp->len, + 3, entry->channel_name, + entry->channel_name ? + strlen(entry->channel_name): 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -2075,14 +2056,12 @@ silc_server_command_list_send_reply(SilcServerCommandContext cmd, /* Local list */ for (i = 0; i < lch_count; i++) { entry = lch[i]; - if (!entry) continue; if (i >= 1) status = SILC_STATUS_LIST_ITEM; - - if (lch_count > 1 && i == lch_count - 1 && !gch_count) + if (i >= 1 && i == lch_count - 1 && !gch_count) status = SILC_STATUS_LIST_END; idp = silc_id_payload_encode(entry->id, SILC_ID_CHANNEL); @@ -2097,23 +2076,14 @@ silc_server_command_list_send_reply(SilcServerCommandContext cmd, } /* Send the reply */ - if (topic) - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_LIST, - status, ident, 4, - 2, idp->data, idp->len, - 3, entry->channel_name, - strlen(entry->channel_name), - 4, topic, strlen(topic), - 5, usercount, 4); - else - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_LIST, - status, ident, 3, - 2, idp->data, idp->len, - 3, entry->channel_name, - strlen(entry->channel_name), - 5, usercount, 4); + packet = + silc_command_reply_payload_encode_va(SILC_COMMAND_LIST, + status, ident, 4, + 2, idp->data, idp->len, + 3, entry->channel_name, + strlen(entry->channel_name), + 4, topic, topic ? strlen(topic) : 0, + 5, usercount, 4); silc_server_packet_send(cmd->server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -2121,19 +2091,15 @@ silc_server_command_list_send_reply(SilcServerCommandContext cmd, silc_buffer_free(idp); } - status = i ? SILC_STATUS_LIST_ITEM : SILC_STATUS_OK; - /* Global list */ for (i = 0; i < gch_count; i++) { entry = gch[i]; - if (!entry) continue; if (i >= 1) status = SILC_STATUS_LIST_ITEM; - - if (gch_count > 1 && i == lch_count - 1) + if (i >= 1 && i == gch_count - 1) status = SILC_STATUS_LIST_END; idp = silc_id_payload_encode(entry->id, SILC_ID_CHANNEL); @@ -2148,23 +2114,14 @@ silc_server_command_list_send_reply(SilcServerCommandContext cmd, } /* Send the reply */ - if (topic) - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_LIST, - status, ident, 4, - 2, idp->data, idp->len, - 3, entry->channel_name, - strlen(entry->channel_name), - 4, topic, strlen(topic), - 5, usercount, 4); - else - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_LIST, - status, ident, 3, - 2, idp->data, idp->len, - 3, entry->channel_name, - strlen(entry->channel_name), - 5, usercount, 4); + packet = + silc_command_reply_payload_encode_va(SILC_COMMAND_LIST, + status, ident, 4, + 2, idp->data, idp->len, + 3, entry->channel_name, + strlen(entry->channel_name), + 4, topic, topic ? strlen(topic) : 0, + 5, usercount, 4); silc_server_packet_send(cmd->server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -2342,16 +2299,12 @@ SILC_SERVER_CMD_FUNC(topic) /* Send the topic to client as reply packet */ idp = silc_id_payload_encode(channel_id, SILC_ID_CHANNEL); - if (channel->topic) - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_TOPIC, - SILC_STATUS_OK, ident, 2, - 2, idp->data, idp->len, - 3, channel->topic, - strlen(channel->topic)); - else - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_TOPIC, - SILC_STATUS_OK, ident, 1, - 2, idp->data, idp->len); + packet = silc_command_reply_payload_encode_va(SILC_COMMAND_TOPIC, + SILC_STATUS_OK, ident, 2, + 2, idp->data, idp->len, + 3, channel->topic, + channel->topic ? + strlen(channel->topic) : 0); silc_server_packet_send(cmd->server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -2908,20 +2861,14 @@ SILC_SERVER_CMD_FUNC(info) server_name = entry->server_name; /* Send the reply */ - if (server_info) - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_INFO, - SILC_STATUS_OK, ident, 3, - 2, idp->data, idp->len, - 3, server_name, - strlen(server_name), - 4, server_info, - strlen(server_info)); - else - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_INFO, - SILC_STATUS_OK, ident, 2, - 2, idp->data, idp->len, - 3, server_name, - strlen(server_name)); + packet = silc_command_reply_payload_encode_va(SILC_COMMAND_INFO, + SILC_STATUS_OK, ident, 3, + 2, idp->data, idp->len, + 3, server_name, + strlen(server_name), + 4, server_info, + server_info ? + strlen(server_info) : 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -3541,18 +3488,12 @@ SILC_SERVER_CMD_FUNC(motd) } idp = silc_id_payload_encode(server->id_entry->id, SILC_ID_SERVER); - - if (entry->motd) - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_MOTD, - SILC_STATUS_OK, ident, 2, - 2, idp, idp->len, - 3, entry->motd, - strlen(entry->motd)); - else - packet = silc_command_reply_payload_encode_va(SILC_COMMAND_MOTD, - SILC_STATUS_OK, ident, 1, - 2, idp, idp->len); - + packet = silc_command_reply_payload_encode_va(SILC_COMMAND_MOTD, + SILC_STATUS_OK, ident, 2, + 2, idp, idp->len, + 3, entry->motd, + entry->motd ? + strlen(entry->motd) : 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); silc_buffer_free(packet); @@ -4358,8 +4299,8 @@ SILC_SERVER_CMD_FUNC(kick) SilcChannelEntry channel; SilcChannelClientEntry chl; SilcBuffer idp; - uint32 tmp_len; - unsigned char *tmp, *comment; + uint32 tmp_len, target_idp_len; + unsigned char *tmp, *comment, *target_idp; SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_LEAVE, cmd, 1, 3); @@ -4406,13 +4347,13 @@ SILC_SERVER_CMD_FUNC(kick) } /* Get target Client ID */ - tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); - if (!tmp) { + target_idp = silc_argument_get_arg_type(cmd->args, 2, &target_idp_len); + if (!target_idp) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK, SILC_STATUS_ERR_NO_CLIENT_ID); goto out; } - client_id = silc_id_payload_parse_id(tmp, tmp_len); + client_id = silc_id_payload_parse_id(target_idp, target_idp_len); if (!client_id) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_KICK, SILC_STATUS_ERR_NO_CLIENT_ID); @@ -4454,12 +4395,12 @@ SILC_SERVER_CMD_FUNC(kick) SILC_STATUS_OK); /* Send KICKED notify to local clients on the channel */ - idp = silc_id_payload_encode(target_client->id, SILC_ID_CLIENT); + idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); silc_server_send_notify_to_channel(server, NULL, channel, FALSE, - SILC_NOTIFY_TYPE_KICKED, - comment ? 2 : 1, - idp->data, idp->len, - comment, comment ? strlen(comment) : 0); + SILC_NOTIFY_TYPE_KICKED, 3, + target_idp, target_idp_len, + comment, comment ? strlen(comment) : 0, + idp->data, idp->len); silc_buffer_free(idp); /* Remove the client from the channel. If the channel does not exist @@ -4806,19 +4747,13 @@ SILC_SERVER_CMD_FUNC(ban) TRUE : FALSE, channel, add, del); /* Send the reply back to the client */ - if (channel->ban_list) - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_BAN, - SILC_STATUS_OK, ident, 2, - 2, id, id_len, - 3, channel->ban_list, - strlen(channel->ban_list) - 1); - else - packet = - silc_command_reply_payload_encode_va(SILC_COMMAND_BAN, - SILC_STATUS_OK, ident, 1, - 2, id, id_len); - + packet = + silc_command_reply_payload_encode_va(SILC_COMMAND_BAN, + SILC_STATUS_OK, ident, 2, + 2, id, id_len, + 3, channel->ban_list, + channel->ban_list ? + strlen(channel->ban_list) - 1 : 0); silc_server_packet_send(server, cmd->sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, FALSE); @@ -5181,7 +5116,7 @@ SILC_SERVER_CMD_FUNC(getkey) SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } - idp = silc_id_payload_parse_data(tmp, tmp_len); + idp = silc_id_payload_parse(tmp, tmp_len); if (!idp) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_GETKEY, SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); diff --git a/apps/silcd/command_reply.c b/apps/silcd/command_reply.c index f83b9f95..2bd74472 100644 --- a/apps/silcd/command_reply.c +++ b/apps/silcd/command_reply.c @@ -77,7 +77,7 @@ void silc_server_command_reply_process(SilcServer server, SILC_LOG_DEBUG(("Start")); /* Get command reply payload from packet */ - payload = silc_command_payload_parse(buffer); + payload = silc_command_payload_parse(buffer->data, buffer->len); if (!payload) { /* Silently ignore bad reply packet */ SILC_LOG_DEBUG(("Bad command reply packet")); @@ -404,7 +404,7 @@ silc_server_command_reply_identify_save(SilcServerCommandReplyContext cmd) id_data = silc_argument_get_arg_type(cmd->args, 2, &id_len); if (!id_data) return FALSE; - idp = silc_id_payload_parse_data(id_data, id_len); + idp = silc_id_payload_parse(id_data, id_len); if (!idp) return FALSE; @@ -1019,7 +1019,7 @@ SILC_SERVER_CMD_REPLY_FUNC(getkey) tmp = silc_argument_get_arg_type(cmd->args, 2, &len); if (!tmp) goto out; - idp = silc_id_payload_parse_data(tmp, len); + idp = silc_id_payload_parse(tmp, len); if (!idp) goto out; diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index b3fd76db..3b11de0f 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -76,7 +76,8 @@ void silc_server_notify(SilcServer server, } /* Parse the Notify Payload */ - payload = silc_notify_payload_parse(packet->buffer); + payload = silc_notify_payload_parse(packet->buffer->data, + packet->buffer->len); if (!payload) return; @@ -1836,7 +1837,7 @@ static void silc_server_new_id_real(SilcServer server, packet->src_id_type != SILC_ID_SERVER) return; - idp = silc_id_payload_parse(buffer); + idp = silc_id_payload_parse(buffer->data, buffer->len); if (!idp) return; @@ -2113,7 +2114,8 @@ void silc_server_new_channel(SilcServer server, return; /* Parse the channel payload */ - payload = silc_channel_payload_parse(packet->buffer); + payload = silc_channel_payload_parse(packet->buffer->data, + packet->buffer->len); if (!payload) return; diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 773c3f3e..0956bdbd 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -1754,7 +1754,8 @@ void silc_server_send_command_reply(SilcServer server, va_start(ap, argc); - packet = silc_command_reply_payload_encode_vap(command, ident, argc, ap); + packet = silc_command_reply_payload_encode_vap(command, status, ident, + argc, ap); silc_server_packet_send(server, sock, SILC_PACKET_COMMAND_REPLY, 0, packet->data, packet->len, TRUE); silc_buffer_free(packet); diff --git a/apps/silcd/server.c b/apps/silcd/server.c index a9a9435b..4543cc28 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -2978,7 +2978,8 @@ SilcChannelEntry silc_server_save_channel_key(SilcServer server, SILC_LOG_DEBUG(("Start")); /* Decode channel key payload */ - payload = silc_channel_key_payload_parse(key_payload); + payload = silc_channel_key_payload_parse(key_payload->data, + key_payload->len); if (!payload) { SILC_LOG_ERROR(("Bad channel key payload, dropped")); channel = NULL; diff --git a/includes/silcincludes.h b/includes/silcincludes.h index 3520afd1..7ee3c0d0 100644 --- a/includes/silcincludes.h +++ b/includes/silcincludes.h @@ -249,7 +249,7 @@ typedef uint32 * void *; /* SILC core library includes */ #include "silcid.h" #include "silcidcache.h" -#include "silcpayload.h" +#include "silcargument.h" #include "silccommand.h" #include "silcchannel.h" #include "silcpacket.h" diff --git a/lib/LIBINDEX b/lib/LIBINDEX index 9c0073ab..e19fcbaf 100644 --- a/lib/LIBINDEX +++ b/lib/LIBINDEX @@ -6,10 +6,10 @@ SILC Toolkit Reference Manual
Copyright (C) GNU GPL 2001 The SILC Project
+Version: 0.6.3
Updated: @DATE@

Note that this document is still under work and does not -include yet all references for SILC Toolkit interfaces. Consider this to -be version 0.6 of the SILC Toolkit Reference Manual. +include yet all references for SILC Toolkit interfaces.

@BODY@ diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 7f1731dc..0440478d 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -1050,7 +1050,7 @@ void silc_client_packet_parse_type(SilcClient client, */ SilcIDPayload idp; - idp = silc_id_payload_parse(buffer); + idp = silc_id_payload_parse(buffer->data, buffer->len); if (!idp) break; if (silc_id_payload_get_type(idp) != SILC_ID_CLIENT) diff --git a/lib/silcclient/client_channel.c b/lib/silcclient/client_channel.c index aeb0ed85..fbe96863 100644 --- a/lib/silcclient/client_channel.c +++ b/lib/silcclient/client_channel.c @@ -236,7 +236,8 @@ void silc_client_channel_message(SilcClient client, all private keys and check what decrypts correctly. */ if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) { /* Parse the channel message payload. This also decrypts the payload */ - payload = silc_channel_message_payload_parse(buffer, channel->channel_key, + payload = silc_channel_message_payload_parse(buffer->data, buffer->len, + channel->channel_key, channel->hmac); /* If decryption failed and we have just performed channel key rekey @@ -246,7 +247,7 @@ void silc_client_channel_message(SilcClient client, if (!channel->old_channel_key) goto out; - payload = silc_channel_message_payload_parse(buffer, + payload = silc_channel_message_payload_parse(buffer->data, buffer->len, channel->old_channel_key, channel->old_hmac); if (!payload) @@ -258,7 +259,8 @@ void silc_client_channel_message(SilcClient client, silc_dlist_start(channel->private_keys); while ((entry = silc_dlist_get(channel->private_keys)) != SILC_LIST_END) { /* Parse the channel message payload. This also decrypts the payload */ - payload = silc_channel_message_payload_parse(buffer, entry->cipher, + payload = silc_channel_message_payload_parse(buffer->data, buffer->len, + entry->cipher, entry->hmac); if (payload) break; @@ -339,7 +341,8 @@ void silc_client_save_channel_key(SilcClientConnection conn, SilcIDCacheEntry id_cache = NULL; SilcChannelKeyPayload payload; - payload = silc_channel_key_payload_parse(key_payload); + payload = silc_channel_key_payload_parse(key_payload->data, + key_payload->len); if (!payload) return; diff --git a/lib/silcclient/client_ftp.c b/lib/silcclient/client_ftp.c index 7f85a8db..1c20d625 100644 --- a/lib/silcclient/client_ftp.c +++ b/lib/silcclient/client_ftp.c @@ -1013,7 +1013,8 @@ static void silc_client_ftp_resolve_cb(SilcClient client, } /* Parse the key agreement payload */ - payload = silc_key_agreement_payload_parse(packet->buffer); + payload = silc_key_agreement_payload_parse(packet->buffer->data, + packet->buffer->len); if (!payload) goto out; diff --git a/lib/silcclient/client_keyagr.c b/lib/silcclient/client_keyagr.c index b21a7dc7..37f98003 100644 --- a/lib/silcclient/client_keyagr.c +++ b/lib/silcclient/client_keyagr.c @@ -655,7 +655,8 @@ silc_client_key_agreement_resolve_cb(SilcClient client, goto out; /* Parse the key agreement payload */ - payload = silc_key_agreement_payload_parse(packet->buffer); + payload = silc_key_agreement_payload_parse(packet->buffer->data, + packet->buffer->len); if (!payload) goto out; diff --git a/lib/silcclient/client_notify.c b/lib/silcclient/client_notify.c index 1b7c3972..ddc70e7b 100644 --- a/lib/silcclient/client_notify.c +++ b/lib/silcclient/client_notify.c @@ -111,7 +111,9 @@ void silc_client_notify_by_server(SilcClient client, unsigned char *tmp; uint32 tmp_len, mode; - payload = silc_notify_payload_parse(buffer); + SILC_LOG_DEBUG(("Start")); + + payload = silc_notify_payload_parse(buffer->data, buffer->len); if (!payload) goto out; @@ -133,6 +135,8 @@ void silc_client_notify_by_server(SilcClient client, * for the application. */ + SILC_LOG_DEBUG(("Notify: INVITE")); + /* Get Channel ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -179,6 +183,8 @@ void silc_client_notify_by_server(SilcClient client, * cache them for later use. */ + SILC_LOG_DEBUG(("Notify: JOIN")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -244,6 +250,8 @@ void silc_client_notify_by_server(SilcClient client, * we'll keep it in the cache in case we'll need it later. */ + SILC_LOG_DEBUG(("Notify: LEAVE")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -291,6 +299,8 @@ void silc_client_notify_by_server(SilcClient client, * Someone left SILC. We'll remove it from all channels and from cache. */ + SILC_LOG_DEBUG(("Notify: SIGNOFF")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -329,6 +339,8 @@ void silc_client_notify_by_server(SilcClient client, * Someone set the topic on a channel. */ + SILC_LOG_DEBUG(("Notify: TOPIC_SET")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -374,6 +386,8 @@ void silc_client_notify_by_server(SilcClient client, * application. */ + SILC_LOG_DEBUG(("Notify: NICK_CHANGE")); + /* Get old Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -433,12 +447,14 @@ void silc_client_notify_by_server(SilcClient client, * Someone changed a channel mode */ + SILC_LOG_DEBUG(("Notify: CMODE_CHANGE")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) goto out; - idp = silc_id_payload_parse_data(tmp, tmp_len); + idp = silc_id_payload_parse(tmp, tmp_len); if (!idp) goto out; @@ -533,6 +549,8 @@ void silc_client_notify_by_server(SilcClient client, * Someone changed user's mode on a channel */ + SILC_LOG_DEBUG(("Notify: CUMODE_CHANGE")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -604,6 +622,8 @@ void silc_client_notify_by_server(SilcClient client, * Received Message of the day */ + SILC_LOG_DEBUG(("Notify: MOTD")); + /* Get motd */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -619,6 +639,8 @@ void silc_client_notify_by_server(SilcClient client, * ID to the one provided here. */ + SILC_LOG_DEBUG(("Notify: CHANNEL_CHANGE")); + /* Get the old ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -665,6 +687,8 @@ void silc_client_notify_by_server(SilcClient client, * A client (maybe me) was kicked from a channel */ + SILC_LOG_DEBUG(("Notify: KICKED")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -685,18 +709,38 @@ void silc_client_notify_by_server(SilcClient client, if (!channel_id) goto out; if (!silc_idcache_find_by_id_one(conn->channel_cache, (void *)channel_id, - &id_cache)) + &id_cache)) break; channel = (SilcChannelEntry)id_cache->context; + /* Get the kicker */ + tmp = silc_argument_get_arg_type(args, 3, &tmp_len); + if (!tmp) + goto out; + + client_id = silc_id_payload_parse_id(tmp, tmp_len); + if (!client_id) + goto out; + + /* Find kicker's client entry and if not found resolve it */ + client_entry2 = silc_client_get_client_by_id(client, conn, client_id); + if (!client_entry2) { + silc_client_notify_by_server_resolve(client, conn, packet, client_id); + goto out; + } else { + if (client_entry2 != conn->local_entry) + silc_client_nickname_format(client, conn, client_entry2); + } + /* Get comment */ tmp = silc_argument_get_arg_type(args, 2, &tmp_len); /* Notify application. The channel entry is sent last as this notify is for channel but application don't know it from the arguments sent by server. */ - client->ops->notify(client, conn, type, client_entry, tmp, channel); + client->ops->notify(client, conn, type, client_entry, tmp, + client_entry2, channel); /* If I was kicked from channel, remove the channel */ if (client_entry == conn->local_entry) { @@ -716,6 +760,8 @@ void silc_client_notify_by_server(SilcClient client, * A client (maybe me) was killed from the network. */ + SILC_LOG_DEBUG(("Notify: KILLED")); + /* Get Client ID */ tmp = silc_argument_get_arg_type(args, 1, &tmp_len); if (!tmp) @@ -754,6 +800,8 @@ void silc_client_notify_by_server(SilcClient client, uint32 clients_count = 0; int i; + SILC_LOG_DEBUG(("Notify: SIGNOFF")); + for (i = 1; i < silc_argument_get_arg_num(args); i++) { /* Get Client ID */ tmp = silc_argument_get_arg_type(args, i + 1, &tmp_len); diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index 5acc8610..331e1d69 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -186,7 +186,8 @@ void silc_client_private_message(SilcClient client, remote_client = (SilcClientEntry)id_cache->context; /* Parse the payload and decrypt it also if private message key is set */ - payload = silc_private_message_payload_parse(packet->buffer, + payload = silc_private_message_payload_parse(packet->buffer->data, + packet->buffer->len, remote_client->receive_key); if (!payload) { silc_free(remote_id); diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index f775d60c..5b5ef427 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -162,7 +162,7 @@ void silc_client_command_reply_process(SilcClient client, uint16 ident; /* Get command reply payload from packet */ - payload = silc_command_payload_parse(buffer); + payload = silc_command_payload_parse(buffer->data, buffer->len); if (!payload) { /* Silently ignore bad reply packet */ SILC_LOG_DEBUG(("Bad command reply packet")); @@ -433,7 +433,7 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd, COMMAND_REPLY_ERROR; return; } - idp = silc_id_payload_parse_data(id_data, len); + idp = silc_id_payload_parse(id_data, len); if (!idp) { COMMAND_REPLY_ERROR; return; @@ -590,7 +590,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) /* Take received Client ID */ tmp = silc_argument_get_arg_type(cmd->args, 2, &len); - idp = silc_id_payload_parse_data(tmp, len); + idp = silc_id_payload_parse(tmp, len); if (!idp) { COMMAND_REPLY_ERROR; goto out; @@ -932,8 +932,9 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL)); if (status != SILC_STATUS_OK) { - cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, - "%s", silc_client_command_status_message(status)); + if (status != SILC_STATUS_ERR_USER_ON_CHANNEL) + cmd->client->ops->say(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, + "%s", silc_client_command_status_message(status)); COMMAND_REPLY_ERROR; goto out; } @@ -965,7 +966,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) silc_free(channel_name); goto out; } - idp = silc_id_payload_parse_data(tmp, len); + idp = silc_id_payload_parse(tmp, len); if (!idp) { COMMAND_REPLY_ERROR; silc_free(channel_name); @@ -1844,7 +1845,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey) COMMAND_REPLY_ERROR; goto out; } - idp = silc_id_payload_parse_data(tmp, len); + idp = silc_id_payload_parse(tmp, len); if (!idp) { COMMAND_REPLY_ERROR; goto out; diff --git a/lib/silccore/DIRECTORY b/lib/silccore/DIRECTORY index 7da6935c..8cac11a9 100644 --- a/lib/silccore/DIRECTORY +++ b/lib/silccore/DIRECTORY @@ -9,7 +9,7 @@ @LINK=silcmode.html:SILC Modes @LINK=silcnotify.html:SILC Notify API @LINK=silcpacket.html:SILC Packet API -@LINK=silcpayload.html:SILC Payload API +@LINK=silcargument.html:SILC Argument API @LINK=silcprivate.html:SILC Private API --> diff --git a/lib/silccore/Makefile.am b/lib/silccore/Makefile.am index 04e898cd..bf01a0f1 100644 --- a/lib/silccore/Makefile.am +++ b/lib/silccore/Makefile.am @@ -26,7 +26,7 @@ libsilccore_a_SOURCES = \ silcchannel.c \ silccommand.c \ silcpacket.c \ - silcpayload.c \ + silcargument.c \ silcnotify.c \ silcauth.c \ silcprivate.c @@ -41,7 +41,7 @@ include_HEADERS = \ silcmode.h \ silcnotify.h \ silcpacket.h \ - silcpayload.h \ + silcargument.h \ silcprivate.h endif diff --git a/lib/silccore/silcpayload.c b/lib/silccore/silcargument.c similarity index 58% rename from lib/silccore/silcpayload.c rename to lib/silccore/silcargument.c index cc7071f1..471e92c7 100644 --- a/lib/silccore/silcpayload.c +++ b/lib/silccore/silcargument.c @@ -1,200 +1,26 @@ /* - silcpayload.c + silcargument.c - Author: Pekka Riikonen + Author: Pekka Riikonen - Copyright (C) 2000 Pekka Riikonen + Copyright (C) 2001 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -/* Implementation of generic payloads described in the protocol - specification drafts. */ +/* Implementation of Argument Payload routines */ /* $Id$ */ #include "silcincludes.h" -#include "silcpayload.h" - -/****************************************************************************** - - ID Payload - -******************************************************************************/ - -struct SilcIDPayloadStruct { - SilcIdType type; - uint16 len; - unsigned char *id; -}; - -/* Parses buffer and return ID payload into payload structure */ - -SilcIDPayload silc_id_payload_parse(const unsigned char *payload, - uint32 payload_len) -{ - SilcBufferStruct buffer; - SilcIDPayload new; - int ret; - - SILC_LOG_DEBUG(("Parsing ID payload")); - - silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); - new = silc_calloc(1, sizeof(*new)); - - ret = silc_buffer_unformat(&buffer, - SILC_STR_UI_SHORT(&new->type), - SILC_STR_UI_SHORT(&new->len), - SILC_STR_END); - if (ret == -1) - goto err; - - silc_buffer_pull(&buffer, 4); - - if (new->len > buffer.len) - goto err; - - ret = silc_buffer_unformat(&buffer, - SILC_STR_UI_XNSTRING_ALLOC(&new->id, new->len), - SILC_STR_END); - if (ret == -1) - goto err; - - silc_buffer_push(&buffer, 4); - - return new; - - err: - silc_free(new); - return NULL; -} - -/* Return the ID directly from the raw payload data. */ - -void *silc_id_payload_parse_id(const unsigned char *data, uint32 len) -{ - SilcBufferStruct buffer; - SilcIdType type; - uint16 idlen; - unsigned char *id_data = NULL; - int ret; - void *id; - - silc_buffer_set(&buffer, (unsigned char *)data, len); - ret = silc_buffer_unformat(&buffer, - SILC_STR_UI_SHORT(&type), - SILC_STR_UI_SHORT(&idlen), - SILC_STR_END); - if (ret == -1) - goto err; - - silc_buffer_pull(&buffer, 4); - - if (idlen > buffer.len) - goto err; - - ret = silc_buffer_unformat(&buffer, - SILC_STR_UI_XNSTRING_ALLOC(&id_data, idlen), - SILC_STR_END); - if (ret == -1) - goto err; - - id = silc_id_str2id(id_data, idlen, type); - silc_free(id_data); - return id; - - err: - return NULL; -} - -/* Encodes ID Payload */ - -SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type) -{ - SilcBuffer buffer; - unsigned char *id_data; - uint32 len; - - id_data = silc_id_id2str(id, type); - len = silc_id_get_len(id, type); - buffer = silc_id_payload_encode_data((const unsigned char *)id_data, - len, type); - silc_free(id_data); - return buffer; -} - -SilcBuffer silc_id_payload_encode_data(const unsigned char *id, - uint32 id_len, SilcIdType type) -{ - SilcBuffer buffer; - - SILC_LOG_DEBUG(("Encoding %s ID payload", - type == SILC_ID_CLIENT ? "Client" : - type == SILC_ID_SERVER ? "Server" : "Channel")); - - buffer = silc_buffer_alloc(4 + id_len); - silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer)); - silc_buffer_format(buffer, - SILC_STR_UI_SHORT(type), - SILC_STR_UI_SHORT(id_len), - SILC_STR_UI_XNSTRING(id, id_len), - SILC_STR_END); - return buffer; -} - -/* Free ID Payload */ - -void silc_id_payload_free(SilcIDPayload payload) -{ - if (payload) { - silc_free(payload->id); - silc_free(payload); - } -} - -/* Get ID type */ - -SilcIdType silc_id_payload_get_type(SilcIDPayload payload) -{ - return payload ? payload->type : 0; -} - -/* Get ID */ - -void *silc_id_payload_get_id(SilcIDPayload payload) -{ - return payload ? silc_id_str2id(payload->id, payload->len, - payload->type) : NULL; -} - -/* Get raw ID data. Data is duplicated. */ - -unsigned char *silc_id_payload_get_data(SilcIDPayload payload) -{ - unsigned char *ret; - - if (!payload) - return NULL; - - ret = silc_calloc(payload->len, sizeof(*ret)); - memcpy(ret, payload->id, payload->len); - return ret; -} - -/* Get length of ID */ - -uint32 silc_id_payload_get_len(SilcIDPayload payload) -{ - return payload ? payload->len : 0; -} +#include "silcargument.h" /****************************************************************************** diff --git a/lib/silccore/silcargument.h b/lib/silccore/silcargument.h new file mode 100644 index 00000000..f5de0d99 --- /dev/null +++ b/lib/silccore/silcargument.h @@ -0,0 +1,175 @@ +/* + + silcargument.h + + Author: Pekka Riikonen + + Copyright (C) 2001 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ + +/****h* silccore/SilcArgumentAPI + * + * DESCRIPTION + * + * Implementation of the Arugment Payload, that is used to include + * argument to other payload that needs arguments. + * + ***/ + +#ifndef SILCPAYLOAD_H +#define SILCPAYLOAD_H + +/****f* silccore/SilcArgumentAPI/silc_argument_payload_parse + * + * SYNOPSIS + * + * SilcArgumentPayload + * silc_argument_payload_parse(const unsigned char *payload, + * uint32 payload_len, + * uint32 argc); + * + * DESCRIPTION + * + * Parses arguments and returns them into Argument Payload structure. + * the `buffer' is raw Argument Payload data buffer. The `argc' is + * the number of arguments in the Argument Payload. The caller must + * know the number of the arguments. This is always known as the + * Argument payload is associated with other payloads which defines + * the number of the arguments. + * + ***/ +SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload, + uint32 payload_len, + uint32 argc); + +/****f* silccore/SilcArgumentAPI/silc_argument_payload_encode + * + * SYNOPSIS + * + * SilcBuffer silc_argument_payload_encode(uint32 argc, + * unsigned char **argv, + * uint32 *argv_lens, + * uint32 *argv_types); + * + * DESCRIPTION + * + * Encodes arguments in to Argument Paylods returning them to SilcBuffer. + * The `argv' is the array of the arguments, the `argv_lens' array of + * the length of the `argv' arguments and the `argv_types' array of + * the argument types of the `argv' arguments. The `argc' is the + * number of arguments. + * + ***/ +SilcBuffer silc_argument_payload_encode(uint32 argc, + unsigned char **argv, + uint32 *argv_lens, + uint32 *argv_types); + +/****f* silccore/SilcArgumentAPI/silc_argument_payload_encode_payload + * + * SYNOPSIS + * + * SilcBuffer + * silc_argument_payload_encode_payload(SilcArgumentPayload payload); + * + * DESCRIPTION + * + * Same as silc_argument_payload_encode but encodes the payload from + * already allocated SilcArgumentPayload structure instead of raw data. + * + ***/ +SilcBuffer silc_argument_payload_encode_payload(SilcArgumentPayload payload); + +/****f* silccore/SilcArgumentAPI/silc_argument_payload_free + * + * SYNOPSIS + * + * void silc_argument_payload_free(SilcArgumentPayload payload); + * + * DESCRIPTION + * + * Frees the Argument Payload and all data in it. + * + ***/ +void silc_argument_payload_free(SilcArgumentPayload payload); + +/****f* silccore/SilcArgumentAPI/silc_argument_get_arg_num + * + * SYNOPSIS + * + * uint32 silc_argument_get_arg_num(SilcArgumentPayload payload); + * + * DESCRIPTION + * + * Returns the number of argument in the Argument Payload. + * + ***/ +uint32 silc_argument_get_arg_num(SilcArgumentPayload payload); + +/****f* silccore/SilcArgumentAPI/silc_argument_get_first_arg + * + * SYNOPSIS + * + * unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload, + * uint32 *ret_len); + * + * DESCRIPTION + * + * Returns the first argument in the Argument Payload. The lenght + * of the argument is returned to `ret_len'. The caller must not + * free the returned argument. Returns NULL on error. + * + ***/ +unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload, + uint32 *ret_len); + +/****f* silccore/SilcArgumentAPI/silc_argument_get_next_arg + * + * SYNOPSIS + * + * unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload, + * uint32 *ret_len); + * + * DESCRIPTION + * + * Returns next argument from the Argument Payload. The length of + * the argument is returned to `ret_len'. The caller must not free + * the returned argument. This returns NULL when there are no more + * arguments in the payload. + * + ***/ +unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload, + uint32 *ret_len); + +/****f* silccore/SilcArgumentAPI/silc_argument_get_arg_type + * + * SYNOPSIS + * + * unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload, + * uint32 type, + * uint32 *ret_len); + * + * DESCRIPTION + * + * Returns argument by type. The returned argument has type `type' + * in the Argument Payload. Each argument has their own type (or zero + * if no specific type is set). The length of the argument is returned + * to the `ret_len'. The caller must not free the returned argument. + * Returns NULL on error. + * + ***/ +unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload, + uint32 type, + uint32 *ret_len); + +#endif diff --git a/lib/silccore/silcauth.c b/lib/silccore/silcauth.c index ef3512ec..36c51e93 100644 --- a/lib/silccore/silcauth.c +++ b/lib/silccore/silcauth.c @@ -40,7 +40,7 @@ struct SilcAuthPayloadStruct { /* Parses and returns Authentication Payload */ -SilcAuthPayload silc_auth_payload_parse(unsigned char *data, +SilcAuthPayload silc_auth_payload_parse(const unsigned char *data, uint32 data_len) { SilcBufferStruct buffer; @@ -49,8 +49,7 @@ SilcAuthPayload silc_auth_payload_parse(unsigned char *data, SILC_LOG_DEBUG(("Parsing Authentication Payload")); - silc_buffer_set(&buffer, data, data_len); - + silc_buffer_set(&buffer, (unsigned char *)data, data_len); new = silc_calloc(1, sizeof(*new)); /* Parse the payload */ @@ -84,9 +83,9 @@ SilcAuthPayload silc_auth_payload_parse(unsigned char *data, /* Encodes authentication payload into buffer and returns it */ SilcBuffer silc_auth_payload_encode(SilcAuthMethod method, - unsigned char *random_data, + const unsigned char *random_data, uint16 random_len, - unsigned char *auth_data, + const unsigned char *auth_data, uint16 auth_len) { SilcBuffer buffer; @@ -155,8 +154,8 @@ unsigned char *silc_auth_get_data(SilcAuthPayload payload, static unsigned char * silc_auth_public_key_encode_data(SilcPublicKey public_key, - unsigned char *random, - uint32 random_len, void *id, + const unsigned char *random, + uint32 random_len, const void *id, SilcIdType type, uint32 *ret_len) { SilcBuffer buf; @@ -202,7 +201,7 @@ silc_auth_public_key_encode_data(SilcPublicKey public_key, SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key, SilcPrivateKey private_key, SilcHash hash, - void *id, SilcIdType type) + const void *id, SilcIdType type) { unsigned char *random; unsigned char auth_data[1024]; @@ -262,9 +261,9 @@ SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key, /* Verifies the authentication data. Returns TRUE if authentication was successful. */ -int silc_auth_public_key_auth_verify(SilcAuthPayload payload, - SilcPublicKey public_key, SilcHash hash, - void *id, SilcIdType type) +bool silc_auth_public_key_auth_verify(SilcAuthPayload payload, + SilcPublicKey public_key, SilcHash hash, + const void *id, SilcIdType type) { unsigned char *tmp; uint32 tmp_len; @@ -311,15 +310,16 @@ int silc_auth_public_key_auth_verify(SilcAuthPayload payload, /* Same as above but the payload is not parsed yet. This will parse it. */ -int silc_auth_public_key_auth_verify_data(SilcBuffer payload, - SilcPublicKey public_key, - SilcHash hash, - void *id, SilcIdType type) +bool silc_auth_public_key_auth_verify_data(const unsigned char *payload, + uint32 payload_len, + SilcPublicKey public_key, + SilcHash hash, + const void *id, SilcIdType type) { SilcAuthPayload auth_payload; int ret; - auth_payload = silc_auth_payload_parse(payload->data, payload->len); + auth_payload = silc_auth_payload_parse(payload, payload_len); if (!auth_payload) { SILC_LOG_DEBUG(("Authentication failed")); return FALSE; @@ -340,9 +340,9 @@ int silc_auth_public_key_auth_verify_data(SilcBuffer payload, authentication then the `auth_data' is the SilcPublicKey and the `auth_data_len' is ignored. */ -int silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, - void *auth_data, uint32 auth_data_len, - SilcHash hash, void *id, SilcIdType type) +bool silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, + const void *auth_data, uint32 auth_data_len, + SilcHash hash, const void *id, SilcIdType type) { SILC_LOG_DEBUG(("Verifying authentication")); @@ -381,10 +381,10 @@ int silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, /* Same as above but parses the authentication payload before verify. */ -int silc_auth_verify_data(unsigned char *payload, uint32 payload_len, - SilcAuthMethod auth_method, void *auth_data, - uint32 auth_data_len, SilcHash hash, - void *id, SilcIdType type) +bool silc_auth_verify_data(const unsigned char *payload, uint32 payload_len, + SilcAuthMethod auth_method, const void *auth_data, + uint32 auth_data_len, SilcHash hash, + const void *id, SilcIdType type) { SilcAuthPayload auth_payload; int ret; @@ -416,17 +416,21 @@ struct SilcKeyAgreementPayloadStruct { /* Parses and returns an allocated Key Agreement payload. */ -SilcKeyAgreementPayload silc_key_agreement_payload_parse(SilcBuffer buffer) +SilcKeyAgreementPayload +silc_key_agreement_payload_parse(const unsigned char *payload, + uint32 payload_len) { + SilcBufferStruct buffer; SilcKeyAgreementPayload new; int ret; SILC_LOG_DEBUG(("Parsing Key Agreement Payload")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); new = silc_calloc(1, sizeof(*new)); /* Parse the payload */ - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI16_NSTRING_ALLOC(&new->hostname, &new->hostname_len), SILC_STR_UI_INT(&new->port), diff --git a/lib/silccore/silcauth.h b/lib/silccore/silcauth.h index a42c60fc..c280dab3 100644 --- a/lib/silccore/silcauth.h +++ b/lib/silccore/silcauth.h @@ -103,7 +103,7 @@ typedef uint16 SilcAuthMethod; * * SYNOPSIS * - * SilcAuthPayload silc_auth_payload_parse(unsigned char *data, + * SilcAuthPayload silc_auth_payload_parse(const unsigned char *data, * uint32 data_len); * * DESCRIPTION @@ -112,7 +112,7 @@ typedef uint16 SilcAuthMethod; * `data_len' are the raw payload buffer. * ***/ -SilcAuthPayload silc_auth_payload_parse(unsigned char *data, +SilcAuthPayload silc_auth_payload_parse(const unsigned char *data, uint32 data_len); /****f* silccore/SilcAuthAPI/silc_auth_payload_encode @@ -120,9 +120,9 @@ SilcAuthPayload silc_auth_payload_parse(unsigned char *data, * SYNOPSIS * * SilcBuffer silc_auth_payload_encode(SilcAuthMethod method, - * unsigned char *random_data, + * const unsigned char *random_data, * uint16 random_len, - * unsigned char *auth_data, + * const unsigned char *auth_data, * uint16 auth_len); * * DESCRIPTION @@ -133,9 +133,9 @@ SilcAuthPayload silc_auth_payload_parse(unsigned char *data, * ***/ SilcBuffer silc_auth_payload_encode(SilcAuthMethod method, - unsigned char *random_data, + const unsigned char *random_data, uint16 random_len, - unsigned char *auth_data, + const unsigned char *auth_data, uint16 auth_len); /****f* silccore/SilcAuthAPI/silc_auth_payload_free @@ -186,7 +186,8 @@ unsigned char *silc_auth_get_data(SilcAuthPayload payload, * SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key, * SilcPrivateKey private_key, * SilcHash hash, - * void *id, SilcIdType type); + * const void *id, + * SilcIdType type); * * DESCRIPTION * @@ -199,16 +200,16 @@ unsigned char *silc_auth_get_data(SilcAuthPayload payload, SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key, SilcPrivateKey private_key, SilcHash hash, - void *id, SilcIdType type); + const void *id, SilcIdType type); /****f* silccore/SilcAuthAPI/silc_auth_public_key_auth_verify * * SYNOPSIS * - * int silc_auth_public_key_auth_verify(SilcAuthPayload payload, - * SilcPublicKey public_key, - * SilcHash hash, - * void *id, SilcIdType type); + * bool silc_auth_public_key_auth_verify(SilcAuthPayload payload, + * SilcPublicKey public_key, + * SilcHash hash, + * const void *id, SilcIdType type); * * DESCRIPTION * @@ -216,18 +217,20 @@ SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key, * successful. * ***/ -int silc_auth_public_key_auth_verify(SilcAuthPayload payload, - SilcPublicKey public_key, SilcHash hash, - void *id, SilcIdType type); +bool silc_auth_public_key_auth_verify(SilcAuthPayload payload, + SilcPublicKey public_key, SilcHash hash, + const void *id, SilcIdType type); /****f* silccore/SilcAuthAPI/silc_auth_public_key_auth_verify_data * * SYNOPSIS * - * int silc_auth_public_key_auth_verify_data(SilcBuffer payload, - * SilcPublicKey public_key, - * SilcHash hash, - * void *id, SilcIdType type); + * bool silc_auth_public_key_auth_verify_data(const unsigned char *payload, + * uint32 payload_len, + * SilcPublicKey public_key, + * SilcHash hash, + * const void *id, + * SilcIdType type); * * DESCRIPTION * @@ -236,18 +239,20 @@ int silc_auth_public_key_auth_verify(SilcAuthPayload payload, * was successful. * ***/ -int silc_auth_public_key_auth_verify_data(SilcBuffer payload, - SilcPublicKey public_key, - SilcHash hash, - void *id, SilcIdType type); +bool silc_auth_public_key_auth_verify_data(const unsigned char *payload, + uint32 payload_len, + SilcPublicKey public_key, + SilcHash hash, + const void *id, SilcIdType type); /****f* silccore/SilcAuthAPI/silc_auth_verify * * SYNOPSIS * - * int silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, - * void *auth_data, uint32 auth_data_len, - * SilcHash hash, void *id, SilcIdType type); + * bool silc_auth_verify(SilcAuthPayload payload, + * SilcAuthMethod auth_method, + * const void *auth_data, uint32 auth_data_len, + * SilcHash hash, const void *id, SilcIdType type); * * DESCRIPTION * @@ -259,19 +264,21 @@ int silc_auth_public_key_auth_verify_data(SilcBuffer payload, * `auth_data_len' is ignored. * ***/ -int silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, - void *auth_data, uint32 auth_data_len, - SilcHash hash, void *id, SilcIdType type); +bool silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, + const void *auth_data, uint32 auth_data_len, + SilcHash hash, const void *id, SilcIdType type); /****f* silccore/SilcAuthAPI/silc_auth_verify_data * * SYNOPSIS * - * int silc_auth_verify_data(unsigned char *payload, uint32 payload_len, - * SilcAuthMethod auth_method, void *auth_data, - * uint32 auth_data_len, SilcHash hash, - * void *id, SilcIdType type); - * + * bool silc_auth_verify_data(const unsigned char *payload, + * uint32 payload_len, + * SilcAuthMethod auth_method, + * const void *auth_data, + * uint32 auth_data_len, SilcHash hash, + * const void *id, SilcIdType type); + * * DESCRIPTION * * Same as silc_auth_verify but the payload has not been parsed yet. @@ -283,24 +290,27 @@ int silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method, * `auth_data_len' is ignored. * ***/ -int silc_auth_verify_data(unsigned char *payload, uint32 payload_len, - SilcAuthMethod auth_method, void *auth_data, - uint32 auth_data_len, SilcHash hash, - void *id, SilcIdType type); +bool silc_auth_verify_data(const unsigned char *payload, uint32 payload_len, + SilcAuthMethod auth_method, const void *auth_data, + uint32 auth_data_len, SilcHash hash, + const void *id, SilcIdType type); /****f* silccore/SilcAuthAPI/silc_key_agreement_payload_parse * * SYNOPSIS * * SilcKeyAgreementPayload - * silc_key_agreement_payload_parse(SilcBuffer buffer); + * silc_key_agreement_payload_parse(const unsigned char *payload, + * uint32 payload_len); * * DESCRIPTION * * Parses and returns an allocated Key Agreement payload. * ***/ -SilcKeyAgreementPayload silc_key_agreement_payload_parse(SilcBuffer buffer); +SilcKeyAgreementPayload +silc_key_agreement_payload_parse(const unsigned char *payload, + uint32 payload_len); /****f* silccore/SilcAuthAPI/silc_key_agreement_payload_encode * diff --git a/lib/silccore/silcchannel.c b/lib/silccore/silcchannel.c index 0a3e2dc3..def0d53b 100644 --- a/lib/silccore/silcchannel.c +++ b/lib/silccore/silcchannel.c @@ -42,17 +42,20 @@ struct SilcChannelPayloadStruct { /* Parses channel payload returning new channel payload structure. */ -SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer) +SilcChannelPayload silc_channel_payload_parse(const unsigned char *payload, + uint32 payload_len) { + SilcBufferStruct buffer; SilcChannelPayload new; int ret; SILC_LOG_DEBUG(("Parsing channel payload")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); new = silc_calloc(1, sizeof(*new)); /* Parse the Channel Payload. Ignore the padding. */ - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI16_NSTRING_ALLOC(&new->channel_name, &new->name_len), SILC_STR_UI16_NSTRING_ALLOC(&new->channel_id, @@ -62,8 +65,8 @@ SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer) if (ret == -1) goto err; - if ((new->name_len < 1 || new->name_len > buffer->len) || - (new->id_len < 1 || new->id_len > buffer->len)) { + if ((new->name_len < 1 || new->name_len > buffer.len) || + (new->id_len < 1 || new->id_len > buffer.len)) { SILC_LOG_ERROR(("Incorrect channel payload in packet, packet dropped")); goto err; } @@ -77,19 +80,22 @@ SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer) /* Parses list of channel payloads returning list of payloads. */ -SilcDList silc_channel_payload_parse_list(SilcBuffer buffer) +SilcDList silc_channel_payload_parse_list(const unsigned char *payload, + uint32 payload_len) { + SilcBufferStruct buffer; SilcDList list; SilcChannelPayload new; int len, ret; SILC_LOG_DEBUG(("Parsing channel payload list")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); list = silc_dlist_init(); - while (buffer->len) { + while (buffer.len) { new = silc_calloc(1, sizeof(*new)); - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI16_NSTRING_ALLOC(&new->channel_name, &new->name_len), SILC_STR_UI16_NSTRING_ALLOC(&new->channel_id, @@ -99,16 +105,16 @@ SilcDList silc_channel_payload_parse_list(SilcBuffer buffer) if (ret == -1) goto err; - if ((new->name_len < 1 || new->name_len > buffer->len) || - (new->id_len < 1 || new->id_len > buffer->len)) { + if ((new->name_len < 1 || new->name_len > buffer.len) || + (new->id_len < 1 || new->id_len > buffer.len)) { SILC_LOG_ERROR(("Incorrect channel payload in packet, packet dropped")); goto err; } len = 2 + new->name_len + 2 + new->id_len + 4; - if (buffer->len < len) + if (buffer.len < len) break; - silc_buffer_pull(buffer, len); + silc_buffer_pull(&buffer, len); silc_dlist_add(list, new); } @@ -122,9 +128,9 @@ SilcDList silc_channel_payload_parse_list(SilcBuffer buffer) /* Encode new channel payload and returns it as buffer. */ -SilcBuffer silc_channel_payload_encode(unsigned char *channel_name, +SilcBuffer silc_channel_payload_encode(const unsigned char *channel_name, uint16 channel_name_len, - unsigned char *channel_id, + const unsigned char *channel_id, uint32 channel_id_len, uint32 mode) { @@ -275,18 +281,22 @@ int silc_channel_message_payload_decrypt(unsigned char *data, This also decrypts it and checks the MAC. */ SilcChannelMessagePayload -silc_channel_message_payload_parse(SilcBuffer buffer, +silc_channel_message_payload_parse(unsigned char *payload, + uint32 payload_len, SilcCipher cipher, SilcHmac hmac) { + SilcBufferStruct buffer; SilcChannelMessagePayload new; int ret; uint32 iv_len, mac_len; SILC_LOG_DEBUG(("Parsing channel message payload")); + silc_buffer_set(&buffer, payload, payload_len); + /* Decrypt the payload */ - ret = silc_channel_message_payload_decrypt(buffer->data, buffer->len, + ret = silc_channel_message_payload_decrypt(buffer.data, buffer.len, cipher, hmac); if (ret == FALSE) return NULL; @@ -297,7 +307,7 @@ silc_channel_message_payload_parse(SilcBuffer buffer, new = silc_calloc(1, sizeof(*new)); /* Parse the Channel Message Payload. Ignore the padding. */ - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI_SHORT(&new->flags), SILC_STR_UI16_NSTRING_ALLOC(&new->data, &new->data_len), @@ -308,7 +318,7 @@ silc_channel_message_payload_parse(SilcBuffer buffer, if (ret == -1) goto err; - if (new->data_len < 1 || new->data_len > buffer->len) { + if (new->data_len < 1 || new->data_len > buffer.len) { SILC_LOG_ERROR(("Incorrect channel message payload in packet, " "packet dropped")); goto err; @@ -328,7 +338,7 @@ silc_channel_message_payload_parse(SilcBuffer buffer, SilcBuffer silc_channel_message_payload_encode(uint16 flags, uint16 data_len, - unsigned char *data, + const unsigned char *data, uint16 iv_len, unsigned char *iv, SilcCipher cipher, @@ -450,18 +460,22 @@ struct SilcChannelKeyPayloadStruct { /* Parses channel key payload returning new channel key payload structure */ -SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer) +SilcChannelKeyPayload +silc_channel_key_payload_parse(const unsigned char *payload, + uint32 payload_len) { + SilcBufferStruct buffer; SilcChannelKeyPayload new; int ret; SILC_LOG_DEBUG(("Parsing channel key payload")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); new = silc_calloc(1, sizeof(*new)); /* Parse the Channel Key Payload */ ret = - silc_buffer_unformat(buffer, + silc_buffer_unformat(&buffer, SILC_STR_UI16_NSTRING_ALLOC(&new->id, &new->id_len), SILC_STR_UI16_NSTRING_ALLOC(&new->cipher, &new->cipher_len), @@ -492,11 +506,11 @@ SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer) to add channel key payload into a packet. */ SilcBuffer silc_channel_key_payload_encode(uint16 id_len, - unsigned char *id, + const unsigned char *id, uint16 cipher_len, - unsigned char *cipher, + const unsigned char *cipher, uint16 key_len, - unsigned char *key) + const unsigned char *key) { SilcBuffer buffer; uint32 len; diff --git a/lib/silccore/silcchannel.h b/lib/silccore/silcchannel.h index fdd8e663..5ad1f929 100644 --- a/lib/silccore/silcchannel.h +++ b/lib/silccore/silcchannel.h @@ -121,7 +121,9 @@ typedef uint16 SilcMessageFlags; * * SYNOPSIS * - * SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer); + * SilcChannelPayload + * silc_channel_payload_parse(const unsigned char *payload, + * uint32 payload_len); * * DESCRIPTION * @@ -129,13 +131,16 @@ typedef uint16 SilcMessageFlags; * `buffer' is the raw payload buffer. * ***/ -SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer); +SilcChannelPayload silc_channel_payload_parse(const unsigned char *payload, + uint32 payload_len); /****f* silccore/SilcChannelAPI/silc_channel_payload_parse_list * * SYNOPSIS * - * SilcDList silc_channel_payload_parse_list(SilcBuffer buffer); + * SilcDList + * silc_channel_payload_parse_list(const unsigned char *payload, + * uint32 payload_len); * * DESCRIPTION * @@ -144,15 +149,16 @@ SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer); * now includes multiple Channel Payloads one after the other. * ***/ -SilcDList silc_channel_payload_parse_list(SilcBuffer buffer); +SilcDList silc_channel_payload_parse_list(const unsigned char *payload, + uint32 payload_len); /****f* silccore/SilcChannelAPI/silc_channel_payload_encode * * SYNOPSIS * - * SilcBuffer silc_channel_payload_encode(unsigned char *channel_name, + * SilcBuffer silc_channel_payload_encode(const unsigned char *channel_name, * uint16 channel_name_len, - * unsigned char *channel_id, + * const unsigned char *channel_id, * uint32 channel_id_len, * uint32 mode); * @@ -161,9 +167,9 @@ SilcDList silc_channel_payload_parse_list(SilcBuffer buffer); * Encode new channel payload and returns it as buffer. * ***/ -SilcBuffer silc_channel_payload_encode(unsigned char *channel_name, +SilcBuffer silc_channel_payload_encode(const unsigned char *channel_name, uint16 channel_name_len, - unsigned char *channel_id, + const unsigned char *channel_id, uint32 channel_id_len, uint32 mode); @@ -289,7 +295,8 @@ int silc_channel_message_payload_decrypt(unsigned char *data, * SYNOPSIS * * SilcChannelMessagePayload - * silc_channel_message_payload_parse(SilcBuffer buffer, + * silc_channel_message_payload_parse(const unsigned char *payload, + * uint32 payload_len, * SilcCipher cipher, * SilcHmac hmac); * @@ -304,7 +311,8 @@ int silc_channel_message_payload_decrypt(unsigned char *data, * ***/ SilcChannelMessagePayload -silc_channel_message_payload_parse(SilcBuffer buffer, +silc_channel_message_payload_parse(unsigned char *payload, + uint32 payload_len, SilcCipher cipher, SilcHmac hmac); @@ -314,7 +322,7 @@ silc_channel_message_payload_parse(SilcBuffer buffer, * * SilcBuffer silc_channel_message_payload_encode(uint16 flags, * uint16 data_len, - * unsigned char *data, + * const unsigned char *data, * uint16 iv_len, * unsigned char *iv, * SilcCipher cipher, @@ -333,7 +341,7 @@ silc_channel_message_payload_parse(SilcBuffer buffer, ***/ SilcBuffer silc_channel_message_payload_encode(uint16 flags, uint16 data_len, - unsigned char *data, + const unsigned char *data, uint16 iv_len, unsigned char *iv, SilcCipher cipher, @@ -419,7 +427,9 @@ unsigned char *silc_channel_message_get_iv(SilcChannelMessagePayload payload); * * SYNOPSIS * - * SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer); + * SilcChannelKeyPayload + * silc_channel_key_payload_parse(const unsigned char *payload, + * uin32 payload_len); * * DESCRIPTION * @@ -427,18 +437,20 @@ unsigned char *silc_channel_message_get_iv(SilcChannelMessagePayload payload); * structure. * ***/ -SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer); +SilcChannelKeyPayload +silc_channel_key_payload_parse(const unsigned char *payload, + uint32 payload_len); /****f* silccore/SilcChannelAPI/silc_channel_key_payload_encode * * SYNOPSIS * * SilcBuffer silc_channel_key_payload_encode(uint16 id_len, - * unsigned char *id, + * const unsigned char *id, * uint16 cipher_len, - * unsigned char *cipher, + * const unsigned char *cipher, * uint16 key_len, - * unsigned char *key); + * const unsigned char *key); * * DESCRIPTION * @@ -447,11 +459,11 @@ SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer); * ***/ SilcBuffer silc_channel_key_payload_encode(uint16 id_len, - unsigned char *id, + const unsigned char *id, uint16 cipher_len, - unsigned char *cipher, + const unsigned char *cipher, uint16 key_len, - unsigned char *key); + const unsigned char *key); /****f* silccore/SilcChannelAPI/silc_channel_key_payload_free * diff --git a/lib/silccore/silccommand.c b/lib/silccore/silccommand.c index e85c7235..ba029871 100644 --- a/lib/silccore/silccommand.c +++ b/lib/silccore/silccommand.c @@ -41,20 +41,23 @@ struct SilcCommandPayloadStruct { /* Parses command payload returning new command payload structure */ -SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer) +SilcCommandPayload silc_command_payload_parse(const unsigned char *payload, + uint32 payload_len) { + SilcBufferStruct buffer; SilcCommandPayload new; unsigned char args_num; - uint16 payload_len; + uint16 p_len; int ret; SILC_LOG_DEBUG(("Parsing command payload")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); new = silc_calloc(1, sizeof(*new)); /* Parse the Command Payload */ - ret = silc_buffer_unformat(buffer, - SILC_STR_UI_SHORT(&payload_len), + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_SHORT(&p_len), SILC_STR_UI_CHAR(&new->cmd), SILC_STR_UI_CHAR(&args_num), SILC_STR_UI_SHORT(&new->ident), @@ -64,7 +67,7 @@ SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer) return NULL; } - if (payload_len != buffer->len) { + if (p_len != buffer.len) { SILC_LOG_ERROR(("Incorrect command payload in packet, packet dropped")); silc_free(new); return NULL; @@ -75,15 +78,15 @@ SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer) return NULL; } - silc_buffer_pull(buffer, SILC_COMMAND_PAYLOAD_LEN); + silc_buffer_pull(&buffer, SILC_COMMAND_PAYLOAD_LEN); if (args_num) { - new->args = silc_argument_payload_parse(buffer, args_num); + new->args = silc_argument_payload_parse(buffer.data, buffer.len, args_num); if (!new->args) { silc_free(new); return NULL; } } - silc_buffer_push(buffer, SILC_COMMAND_PAYLOAD_LEN); + silc_buffer_push(&buffer, SILC_COMMAND_PAYLOAD_LEN); return new; } diff --git a/lib/silccore/silccommand.h b/lib/silccore/silccommand.h index 3fdf80f1..65ed46a2 100644 --- a/lib/silccore/silccommand.h +++ b/lib/silccore/silccommand.h @@ -222,7 +222,9 @@ typedef uint16 SilcCommandStatus; * * SYNOPSIS * - * SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer); + * SilcCommandPayload + * silc_command_payload_parse(const unsigned char *payload, + * uint32 payload_len); * * DESCRIPTION * @@ -230,7 +232,8 @@ typedef uint16 SilcCommandStatus; * `buffer' is the raw payload. * ***/ -SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer); +SilcCommandPayload silc_command_payload_parse(const unsigned char *payload, + uint32 payload_len); /****f* silccore/SilcCommandAPI/silc_command_payload_encode * diff --git a/lib/silccore/silcid.c b/lib/silccore/silcid.c index bdd1353d..9a35723a 100644 --- a/lib/silccore/silcid.c +++ b/lib/silccore/silcid.c @@ -27,6 +27,178 @@ #define ID_CLIENT_LEN_PART CLIENTID_HASH_LEN + 1 #define ID_CHANNEL_LEN_PART 4 +/****************************************************************************** + + ID Payload + +******************************************************************************/ + +struct SilcIDPayloadStruct { + SilcIdType type; + uint16 len; + unsigned char *id; +}; + +/* Parses buffer and return ID payload into payload structure */ + +SilcIDPayload silc_id_payload_parse(const unsigned char *payload, + uint32 payload_len) +{ + SilcBufferStruct buffer; + SilcIDPayload new; + int ret; + + SILC_LOG_DEBUG(("Parsing ID payload")); + + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); + new = silc_calloc(1, sizeof(*new)); + + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_SHORT(&new->type), + SILC_STR_UI_SHORT(&new->len), + SILC_STR_END); + if (ret == -1) + goto err; + + silc_buffer_pull(&buffer, 4); + + if (new->len > buffer.len) + goto err; + + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_XNSTRING_ALLOC(&new->id, new->len), + SILC_STR_END); + if (ret == -1) + goto err; + + silc_buffer_push(&buffer, 4); + + return new; + + err: + silc_free(new); + return NULL; +} + +/* Return the ID directly from the raw payload data. */ + +void *silc_id_payload_parse_id(const unsigned char *data, uint32 len) +{ + SilcBufferStruct buffer; + SilcIdType type; + uint16 idlen; + unsigned char *id_data = NULL; + int ret; + void *id; + + silc_buffer_set(&buffer, (unsigned char *)data, len); + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_SHORT(&type), + SILC_STR_UI_SHORT(&idlen), + SILC_STR_END); + if (ret == -1) + goto err; + + silc_buffer_pull(&buffer, 4); + + if (idlen > buffer.len) + goto err; + + ret = silc_buffer_unformat(&buffer, + SILC_STR_UI_XNSTRING_ALLOC(&id_data, idlen), + SILC_STR_END); + if (ret == -1) + goto err; + + id = silc_id_str2id(id_data, idlen, type); + silc_free(id_data); + return id; + + err: + return NULL; +} + +/* Encodes ID Payload */ + +SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type) +{ + SilcBuffer buffer; + unsigned char *id_data; + uint32 len; + + id_data = silc_id_id2str(id, type); + len = silc_id_get_len(id, type); + buffer = silc_id_payload_encode_data((const unsigned char *)id_data, + len, type); + silc_free(id_data); + return buffer; +} + +SilcBuffer silc_id_payload_encode_data(const unsigned char *id, + uint32 id_len, SilcIdType type) +{ + SilcBuffer buffer; + + SILC_LOG_DEBUG(("Encoding %s ID payload", + type == SILC_ID_CLIENT ? "Client" : + type == SILC_ID_SERVER ? "Server" : "Channel")); + + buffer = silc_buffer_alloc(4 + id_len); + silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer)); + silc_buffer_format(buffer, + SILC_STR_UI_SHORT(type), + SILC_STR_UI_SHORT(id_len), + SILC_STR_UI_XNSTRING(id, id_len), + SILC_STR_END); + return buffer; +} + +/* Free ID Payload */ + +void silc_id_payload_free(SilcIDPayload payload) +{ + if (payload) { + silc_free(payload->id); + silc_free(payload); + } +} + +/* Get ID type */ + +SilcIdType silc_id_payload_get_type(SilcIDPayload payload) +{ + return payload ? payload->type : 0; +} + +/* Get ID */ + +void *silc_id_payload_get_id(SilcIDPayload payload) +{ + return payload ? silc_id_str2id(payload->id, payload->len, + payload->type) : NULL; +} + +/* Get raw ID data. Data is duplicated. */ + +unsigned char *silc_id_payload_get_data(SilcIDPayload payload) +{ + unsigned char *ret; + + if (!payload) + return NULL; + + ret = silc_calloc(payload->len, sizeof(*ret)); + memcpy(ret, payload->id, payload->len); + return ret; +} + +/* Get length of ID */ + +uint32 silc_id_payload_get_len(SilcIDPayload payload) +{ + return payload ? payload->len : 0; +} + /* Converts ID to string. */ unsigned char *silc_id_id2str(const void *id, SilcIdType type) diff --git a/lib/silccore/silcid.h b/lib/silccore/silcid.h index e28c412a..975d19d7 100644 --- a/lib/silccore/silcid.h +++ b/lib/silccore/silcid.h @@ -32,6 +32,9 @@ * way to distinguish the ID's from other ID's. The ID's supports both * IPv4 and IPv6. * + * This file also includes the implementation of the SILC ID Payload + * parsing and encoding. + * ***/ #ifndef SILCID_H @@ -66,6 +69,168 @@ typedef uint16 SilcIdType; #define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */ +/****s* silccore/SilcIDAPI/SilcIDPayload + * + * NAME + * + * typedef struct SilcIDPayloadStruct *SilcIDPayload; + * + * DESCRIPTION + * + * This context is the actual ID Payload and is allocated by + * silc_id_payload_parse and given as argument usually to all + * silc_id_payload_* functions. It is freed by the function + * silc_id_payload_free. + * + ***/ +typedef struct SilcIDPayloadStruct *SilcIDPayload; + +/****s* silccore/SilcIDAPI/SilcArgumentPayload + * + * NAME + * + * typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; + * + * DESCRIPTION + * + * This context is the actual Argument Payload and is allocated + * by silc_argument_payload_parse and given as argument usually to + * all silc_argument_payload_* functions. It is freed by the + * silc_argument_payload_free function. + * + ***/ +typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; + +/* Prototypes */ + +/****f* silccore/SilcIDAPI/silc_id_payload_parse + * + * SYNOPSIS + * + * SilcIDPayload silc_id_payload_parse(const unsigned char *payload, + * uint32 payload_len); + * + * DESCRIPTION + * + * Parses buffer and return ID payload into payload structure. The + * `buffer' is raw payload buffer. + * + ***/ +SilcIDPayload silc_id_payload_parse(const unsigned char *payload, + uint32 payload_len); + +/****f* silccore/SilcIDAPI/silc_id_payload_parse_id + * + * SYNOPSIS + * + * void *silc_id_payload_parse_id(const unsigned char *data, uint32 len); + * + * DESCRIPTION + * + * Return ID directly from the raw ID Payload data buffer. The + * caller must free the returned ID. + * + ***/ +void *silc_id_payload_parse_id(const unsigned char *data, uint32 len); + +/****f* silccore/SilcIDAPI/silc_id_payload_encode + * + * SYNOPSIS + * + * SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type); + * + * DESCRIPTION + * + * Encodes ID Payload. The `id' is the ID of the type `type' to put + * into the payload. Returns the encoded payload buffer. + * + ***/ +SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type); + +/****f* silccore/SilcIDAPI/silc_id_payload_encode_data + * + * SYNOPSIS + * + * SilcBuffer silc_id_payload_encode_data(const unsigned char *id, + * uin32 id_len, SilcIdType type); + * + * DESCRIPTION + * + * Encodes ID Payload. The `id' is raw ID data of the length of `id_len' + * of type of `type'. Returns the encoded payload buffer. + * + ***/ +SilcBuffer silc_id_payload_encode_data(const unsigned char *id, + uint32 id_len, SilcIdType type); + +/****f* silccore/SilcIDAPI/silc_id_payload_free + * + * SYNOPSIS + * + * void silc_id_payload_free(SilcIDPayload payload); + * + * DESCRIPTION + * + * Frees the ID Payload and all data in it. + * + ***/ +void silc_id_payload_free(SilcIDPayload payload); + +/****f* silccore/SilcIDAPI/silc_id_payload_get_type + * + * SYNOPSIS + * + * SilcIdType silc_id_payload_get_type(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the ID type from the ID Payload. The type tells the + * type of the ID in the payload. + * + ***/ +SilcIdType silc_id_payload_get_type(SilcIDPayload payload); + +/****f* silccore/SilcIDAPI/silc_id_payload_get_id + * + * SYNOPSIS + * + * void *silc_id_payload_get_id(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the ID in the ID Payload. The caller must free the + * returned ID. + * + ***/ +void *silc_id_payload_get_id(SilcIDPayload payload); + +/****f* silccore/SilcIDAPI/silc_id_payload_get_data + * + * SYNOPSIS + * + * unsigned char *silc_id_payload_get_data(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the raw ID data from the ID Payload. The data is duplicated + * and the caller must free it. + * + ***/ +unsigned char *silc_id_payload_get_data(SilcIDPayload payload); + +/****f* silccore/SilcIDAPI/silc_id_payload_get_len + * + * SYNOPSIS + * + * uint32 silc_id_payload_get_len(SilcIDPayload payload); + * + * DESCRIPTION + * + * Returns the length of the ID in the ID Payload. + * + ***/ +uint32 silc_id_payload_get_len(SilcIDPayload payload); + /****s* silccore/SilcIDAPI/SilcIDIP * * NAME diff --git a/lib/silccore/silcnotify.c b/lib/silccore/silcnotify.c index bee44cea..99f342cf 100644 --- a/lib/silccore/silcnotify.c +++ b/lib/silccore/silcnotify.c @@ -36,17 +36,20 @@ struct SilcNotifyPayloadStruct { /* Parse notify payload buffer and return data into payload structure */ -SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer) +SilcNotifyPayload silc_notify_payload_parse(const unsigned char *payload, + uint32 payload_len) { + SilcBufferStruct buffer; SilcNotifyPayload new; uint16 len; int ret; SILC_LOG_DEBUG(("Parsing Notify payload")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); new = silc_calloc(1, sizeof(*new)); - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI_SHORT(&new->type), SILC_STR_UI_SHORT(&len), SILC_STR_UI_CHAR(&new->argc), @@ -54,13 +57,14 @@ SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer) if (ret == -1) goto err; - if (len > buffer->len) + if (len > buffer.len) goto err; if (new->argc) { - silc_buffer_pull(buffer, 5); - new->args = silc_argument_payload_parse(buffer, new->argc); - silc_buffer_push(buffer, 5); + silc_buffer_pull(&buffer, 5); + new->args = silc_argument_payload_parse(buffer.data, buffer.len, + new->argc); + silc_buffer_push(&buffer, 5); } return new; diff --git a/lib/silccore/silcnotify.h b/lib/silccore/silcnotify.h index d173a51d..f00772b1 100644 --- a/lib/silccore/silcnotify.h +++ b/lib/silccore/silcnotify.h @@ -87,7 +87,9 @@ typedef uint16 SilcNotifyType; * * SYNOPSIS * - * SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer); + * SilcNotifyPayload + * silc_notify_payload_parse(const unsigned char *payload, + * uint32 payload_len); * * DESCRIPTION * @@ -95,7 +97,8 @@ typedef uint16 SilcNotifyType; * The `buffer' is the raw payload data. * ***/ -SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer); +SilcNotifyPayload silc_notify_payload_parse(const unsigned char *payload, + uint32 payload_len); /****f* silccore/SilcNotifyAPI/silc_notify_payload_encode * diff --git a/lib/silccore/silcpayload.h b/lib/silccore/silcpayload.h deleted file mode 100644 index e8a96f7e..00000000 --- a/lib/silccore/silcpayload.h +++ /dev/null @@ -1,340 +0,0 @@ -/* - - silcpayload.h - - Author: Pekka Riikonen - - Copyright (C) 2000 - 2001 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -*/ - -/****h* silccore/SilcGenericPayloadAPI - * - * DESCRIPTION - * - * Implementation of the generic payloads described in the protocol - * specification; ID Payload and Argument Payload. The ID Payload is - * used to represent an ID. The Argument Payload is used to include - * arguments to other payloads that needs arguments. - * - ***/ - -#ifndef SILCPAYLOAD_H -#define SILCPAYLOAD_H - -/****s* silccore/SilcGenericPayloadAPI/SilcIDPayload - * - * NAME - * - * typedef struct SilcIDPayloadStruct *SilcIDPayload; - * - * DESCRIPTION - * - * This context is the actual ID Payload and is allocated by - * silc_id_payload_parse and given as argument usually to all - * silc_id_payload_* functions. It is freed by the function - * silc_id_payload_free. - * - ***/ -typedef struct SilcIDPayloadStruct *SilcIDPayload; - -/****s* silccore/SilcGenericPayloadAPI/SilcArgumentPayload - * - * NAME - * - * typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; - * - * DESCRIPTION - * - * This context is the actual Argument Payload and is allocated - * by silc_argument_payload_parse and given as argument usually to - * all silc_argument_payload_* functions. It is freed by the - * silc_argument_payload_free function. - * - ***/ -typedef struct SilcArgumentPayloadStruct *SilcArgumentPayload; - -/* Prototypes */ - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_parse - * - * SYNOPSIS - * - * SilcIDPayload silc_id_payload_parse(const unsigned char *payload, - * uint32 payload_len); - * - * DESCRIPTION - * - * Parses buffer and return ID payload into payload structure. The - * `buffer' is raw payload buffer. - * - ***/ -SilcIDPayload silc_id_payload_parse(const unsigned char *payload, - uint32 payload_len); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_parse_id - * - * SYNOPSIS - * - * void *silc_id_payload_parse_id(const unsigned char *data, uint32 len); - * - * DESCRIPTION - * - * Return ID directly from the raw ID Payload data buffer. The - * caller must free the returned ID. - * - ***/ -void *silc_id_payload_parse_id(const unsigned char *data, uint32 len); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_encode - * - * SYNOPSIS - * - * SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type); - * - * DESCRIPTION - * - * Encodes ID Payload. The `id' is the ID of the type `type' to put - * into the payload. Returns the encoded payload buffer. - * - ***/ -SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_encode_data - * - * SYNOPSIS - * - * SilcBuffer silc_id_payload_encode_data(const unsigned char *id, - * uin32 id_len, SilcIdType type); - * - * DESCRIPTION - * - * Encodes ID Payload. The `id' is raw ID data of the length of `id_len' - * of type of `type'. Returns the encoded payload buffer. - * - ***/ -SilcBuffer silc_id_payload_encode_data(const unsigned char *id, - uint32 id_len, SilcIdType type); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_free - * - * SYNOPSIS - * - * void silc_id_payload_free(SilcIDPayload payload); - * - * DESCRIPTION - * - * Frees the ID Payload and all data in it. - * - ***/ -void silc_id_payload_free(SilcIDPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_type - * - * SYNOPSIS - * - * SilcIdType silc_id_payload_get_type(SilcIDPayload payload); - * - * DESCRIPTION - * - * Returns the ID type from the ID Payload. The type tells the - * type of the ID in the payload. - * - ***/ -SilcIdType silc_id_payload_get_type(SilcIDPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_id - * - * SYNOPSIS - * - * void *silc_id_payload_get_id(SilcIDPayload payload); - * - * DESCRIPTION - * - * Returns the ID in the ID Payload. The caller must free the - * returned ID. - * - ***/ -void *silc_id_payload_get_id(SilcIDPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_data - * - * SYNOPSIS - * - * unsigned char *silc_id_payload_get_data(SilcIDPayload payload); - * - * DESCRIPTION - * - * Returns the raw ID data from the ID Payload. The data is duplicated - * and the caller must free it. - * - ***/ -unsigned char *silc_id_payload_get_data(SilcIDPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_id_payload_get_len - * - * SYNOPSIS - * - * uint32 silc_id_payload_get_len(SilcIDPayload payload); - * - * DESCRIPTION - * - * Returns the length of the ID in the ID Payload. - * - ***/ -uint32 silc_id_payload_get_len(SilcIDPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_parse - * - * SYNOPSIS - * - * SilcArgumentPayload - * silc_argument_payload_parse(const unsigned char *payload, - * uint32 payload_len, - * uint32 argc); - * - * DESCRIPTION - * - * Parses arguments and returns them into Argument Payload structure. - * the `buffer' is raw Argument Payload data buffer. The `argc' is - * the number of arguments in the Argument Payload. The caller must - * know the number of the arguments. This is always known as the - * Argument payload is associated with other payloads which defines - * the number of the arguments. - * - ***/ -SilcArgumentPayload silc_argument_payload_parse(const unsigned char *payload, - uint32 payload_len, - uint32 argc); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_encode - * - * SYNOPSIS - * - * SilcBuffer silc_argument_payload_encode(uint32 argc, - * unsigned char **argv, - * uint32 *argv_lens, - * uint32 *argv_types); - * - * DESCRIPTION - * - * Encodes arguments in to Argument Paylods returning them to SilcBuffer. - * The `argv' is the array of the arguments, the `argv_lens' array of - * the length of the `argv' arguments and the `argv_types' array of - * the argument types of the `argv' arguments. The `argc' is the - * number of arguments. - * - ***/ -SilcBuffer silc_argument_payload_encode(uint32 argc, - unsigned char **argv, - uint32 *argv_lens, - uint32 *argv_types); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_encode_payload - * - * SYNOPSIS - * - * SilcBuffer - * silc_argument_payload_encode_payload(SilcArgumentPayload payload); - * - * DESCRIPTION - * - * Same as silc_argument_payload_encode but encodes the payload from - * already allocated SilcArgumentPayload structure instead of raw data. - * - ***/ -SilcBuffer silc_argument_payload_encode_payload(SilcArgumentPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_payload_free - * - * SYNOPSIS - * - * void silc_argument_payload_free(SilcArgumentPayload payload); - * - * DESCRIPTION - * - * Frees the Argument Payload and all data in it. - * - ***/ -void silc_argument_payload_free(SilcArgumentPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_arg_num - * - * SYNOPSIS - * - * uint32 silc_argument_get_arg_num(SilcArgumentPayload payload); - * - * DESCRIPTION - * - * Returns the number of argument in the Argument Payload. - * - ***/ -uint32 silc_argument_get_arg_num(SilcArgumentPayload payload); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_first_arg - * - * SYNOPSIS - * - * unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload, - * uint32 *ret_len); - * - * DESCRIPTION - * - * Returns the first argument in the Argument Payload. The lenght - * of the argument is returned to `ret_len'. The caller must not - * free the returned argument. Returns NULL on error. - * - ***/ -unsigned char *silc_argument_get_first_arg(SilcArgumentPayload payload, - uint32 *ret_len); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_next_arg - * - * SYNOPSIS - * - * unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload, - * uint32 *ret_len); - * - * DESCRIPTION - * - * Returns next argument from the Argument Payload. The length of - * the argument is returned to `ret_len'. The caller must not free - * the returned argument. This returns NULL when there are no more - * arguments in the payload. - * - ***/ -unsigned char *silc_argument_get_next_arg(SilcArgumentPayload payload, - uint32 *ret_len); - -/****f* silccore/SilcGenericPayloadAPI/silc_argument_get_arg_type - * - * SYNOPSIS - * - * unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload, - * uint32 type, - * uint32 *ret_len); - * - * DESCRIPTION - * - * Returns argument by type. The returned argument has type `type' - * in the Argument Payload. Each argument has their own type (or zero - * if no specific type is set). The length of the argument is returned - * to the `ret_len'. The caller must not free the returned argument. - * Returns NULL on error. - * - ***/ -unsigned char *silc_argument_get_arg_type(SilcArgumentPayload payload, - uint32 type, - uint32 *ret_len); - -#endif diff --git a/lib/silccore/silcprivate.c b/lib/silccore/silcprivate.c index 60534f6b..ac56c1d0 100644 --- a/lib/silccore/silcprivate.c +++ b/lib/silccore/silcprivate.c @@ -43,22 +43,27 @@ struct SilcPrivateMessagePayloadStruct { structure. This also decrypts the message if the `cipher' is provided. */ SilcPrivateMessagePayload -silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher) +silc_private_message_payload_parse(unsigned char *payload, + uint32 payload_len, + SilcCipher cipher) { + SilcBufferStruct buffer; SilcPrivateMessagePayload new; int ret; SILC_LOG_DEBUG(("Parsing private message payload")); + silc_buffer_set(&buffer, payload, payload_len); + /* Decrypt the payload */ if (cipher) - silc_cipher_decrypt(cipher, buffer->data, buffer->data, - buffer->len, cipher->iv); + silc_cipher_decrypt(cipher, buffer.data, buffer.data, + buffer.len, cipher->iv); new = silc_calloc(1, sizeof(*new)); /* Parse the Private Message Payload. Ignore the padding. */ - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI_SHORT(&new->flags), SILC_STR_UI16_NSTRING_ALLOC(&new->message, &new->message_len), @@ -68,7 +73,7 @@ silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher) goto err; } - if ((new->message_len < 1 || new->message_len > buffer->len)) { + if ((new->message_len < 1 || new->message_len > buffer.len)) { SILC_LOG_DEBUG(("Incorrect private message payload in packet, " "packet dropped")); goto err; @@ -87,7 +92,7 @@ silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher) SilcBuffer silc_private_message_payload_encode(uint16 flags, uint16 data_len, - unsigned char *data, + const unsigned char *data, SilcCipher cipher) { int i; diff --git a/lib/silccore/silcprivate.h b/lib/silccore/silcprivate.h index 80a2c683..f8beca27 100644 --- a/lib/silccore/silcprivate.h +++ b/lib/silccore/silcprivate.h @@ -55,7 +55,9 @@ typedef struct SilcPrivateMessagePayloadStruct *SilcPrivateMessagePayload; * SYNOPSIS * * SilcPrivateMessagePayload - * silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher); + * silc_private_message_payload_parse(unsigned char *payload, + * uint32 payload_len, + * SilcCipher cipher); * * DESCRIPTION * @@ -64,7 +66,9 @@ typedef struct SilcPrivateMessagePayloadStruct *SilcPrivateMessagePayload; * ***/ SilcPrivateMessagePayload -silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher); +silc_private_message_payload_parse(unsigned char *payload, + uint32 payload_len, + SilcCipher cipher); /****f* silccore/SilcPrivateAPI/silc_private_message_payload_encode * @@ -72,7 +76,7 @@ silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher); * * SilcBuffer silc_private_message_payload_encode(uint16 flags, * uint16 data_len, - * unsigned char *data, + * const unsigned char *data, * SilcCipher cipher); * * DESCRIPTION @@ -84,7 +88,7 @@ silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher); ***/ SilcBuffer silc_private_message_payload_encode(uint16 flags, uint16 data_len, - unsigned char *data, + const unsigned char *data, SilcCipher cipher); /****f* silccore/SilcPrivateAPI/silc_private_message_payload_free diff --git a/lib/silcsftp/sftp_client.c b/lib/silcsftp/sftp_client.c index 29ee2076..0aa1b91c 100644 --- a/lib/silcsftp/sftp_client.c +++ b/lib/silcsftp/sftp_client.c @@ -24,7 +24,7 @@ /* Request context. Every request will allocate this context and set the correct callback function according the `type' field. */ -typedef struct { +typedef struct SilcSFTPRequestStruct { uint32 id; SilcSFTPPacket type; SilcSFTPStatusCallback status; @@ -34,6 +34,7 @@ typedef struct { SilcSFTPAttrCallback attr; SilcSFTPExtendedCallback extended; void *context; + struct SilcSFTPRequestStruct *next; } *SilcSFTPRequest; /* SFTP client context */ @@ -44,7 +45,8 @@ typedef struct { SilcSFTPVersionCallback version; void *version_context; uint32 id; - SilcDList requests; + SilcList requests; + SilcBuffer packet; } *SilcSFTPClient; /* File handle */ @@ -93,22 +95,25 @@ static void silc_sftp_send_packet(SilcSFTPClient sftp, SilcSFTPPacket type, uint32 len, ...) { - SilcBuffer packet; + SilcBuffer tmp; va_list vp; va_start(vp, len); - packet = silc_sftp_packet_encode_vp(type, len, vp); + tmp = silc_sftp_packet_encode_vp(type, sftp->packet, len, vp); va_end(vp); - - if (!packet) + if (!tmp) return; + sftp->packet = tmp; - SILC_LOG_HEXDUMP(("SFTP packet to server"), packet->data, packet->len); + SILC_LOG_HEXDUMP(("SFTP packet to server"), sftp->packet->data, + sftp->packet->len); /* Send the packet */ - (*sftp->send_packet)(sftp->sock, packet, sftp->send_context); + (*sftp->send_packet)(sftp->sock, sftp->packet, sftp->send_context); - silc_buffer_free(packet); + /* Clear packet */ + sftp->packet->data = sftp->packet->tail = sftp->packet->head; + sftp->packet->len = 0; } /* Finds request by request ID. */ @@ -119,8 +124,8 @@ static SilcSFTPRequest silc_sftp_find_request(SilcSFTPClient sftp, uint32 id) SILC_LOG_DEBUG(("Finding request ID: %d", id)); - silc_dlist_start(sftp->requests); - while ((req = silc_dlist_get(sftp->requests)) != SILC_LIST_END) { + silc_list_start(sftp->requests); + while ((req = silc_list_get(sftp->requests)) != SILC_LIST_END) { if (req->id == id) return req; } @@ -280,7 +285,7 @@ static void silc_sftp_call_request(SilcSFTPClient sftp, } /* Remove this request */ - silc_dlist_del(sftp->requests, req); + silc_list_del(sftp->requests, req); silc_free(req); va_end(vp); @@ -310,7 +315,7 @@ SilcSFTP silc_sftp_client_start(SilcSocketConnection sock, sftp->send_context = send_context; sftp->version = callback; sftp->version_context = context; - sftp->requests = silc_dlist_init(); + silc_list_init(sftp->requests, struct SilcSFTPRequestStruct, next); /* Send the SFTP session initialization to the server */ silc_sftp_send_packet(sftp, SILC_SFTP_INIT, 4, @@ -328,7 +333,9 @@ void silc_sftp_client_shutdown(SilcSFTP context) { SilcSFTPClient sftp = (SilcSFTPClient)context; - silc_dlist_uninit(sftp->requests); + silc_list_uninit(sftp->requests); + if (sftp->packet) + silc_buffer_free(sftp->packet); silc_free(sftp); } @@ -583,7 +590,7 @@ void silc_sftp_open(SilcSFTP sftp, req->type = SILC_SFTP_OPEN; req->handle = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); attrs_buf = silc_sftp_attr_encode(attrs); len = 4 + 4 + strlen(filename) + 4 + attrs_buf->len; @@ -618,7 +625,7 @@ void silc_sftp_close(SilcSFTP sftp, req->type = SILC_SFTP_CLOSE; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); silc_sftp_handle_get(handle, &hdata, &hdata_len); len = 4 + 4 + hdata_len; @@ -650,7 +657,7 @@ void silc_sftp_read(SilcSFTP sftp, req->type = SILC_SFTP_READ; req->data = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); silc_sftp_handle_get(handle, &hdata, &hdata_len); len2 = 4 + 4 + hdata_len + 8 + 4; @@ -685,7 +692,7 @@ void silc_sftp_write(SilcSFTP sftp, req->type = SILC_SFTP_WRITE; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); silc_sftp_handle_get(handle, &hdata, &hdata_len); len = 4 + 4 + hdata_len + 8 + 4 + data_len; @@ -716,7 +723,7 @@ void silc_sftp_remove(SilcSFTP sftp, req->type = SILC_SFTP_REMOVE; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(filename); @@ -744,7 +751,7 @@ void silc_sftp_rename(SilcSFTP sftp, req->type = SILC_SFTP_RENAME; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(oldname) + 4 + strlen(newname); @@ -775,7 +782,7 @@ void silc_sftp_mkdir(SilcSFTP sftp, req->type = SILC_SFTP_MKDIR; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); attrs_buf = silc_sftp_attr_encode(attrs); len = 4 + 4 + strlen(path) + attrs_buf->len; @@ -807,7 +814,7 @@ void silc_sftp_rmdir(SilcSFTP sftp, req->type = SILC_SFTP_RMDIR; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(path); @@ -834,7 +841,7 @@ void silc_sftp_opendir(SilcSFTP sftp, req->type = SILC_SFTP_OPENDIR; req->handle = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(path); @@ -863,7 +870,7 @@ void silc_sftp_readdir(SilcSFTP sftp, req->type = SILC_SFTP_READDIR; req->name = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); silc_sftp_handle_get(handle, &hdata, &hdata_len); len = 4 + 4 + hdata_len; @@ -891,7 +898,7 @@ void silc_sftp_stat(SilcSFTP sftp, req->type = SILC_SFTP_STAT; req->attr = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(path); @@ -918,7 +925,7 @@ void silc_sftp_lstat(SilcSFTP sftp, req->type = SILC_SFTP_LSTAT; req->attr = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(path); @@ -947,7 +954,7 @@ void silc_sftp_fstat(SilcSFTP sftp, req->type = SILC_SFTP_FSTAT; req->attr = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); silc_sftp_handle_get(handle, &hdata, &hdata_len); len = 4 + 4 + hdata_len; @@ -977,7 +984,7 @@ void silc_sftp_setstat(SilcSFTP sftp, req->type = SILC_SFTP_SETSTAT; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); attrs_buf = silc_sftp_attr_encode(attrs); len = 4 + 4 + strlen(path) + attrs_buf->len; @@ -1013,7 +1020,7 @@ void silc_sftp_fsetstat(SilcSFTP sftp, req->type = SILC_SFTP_FSETSTAT; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); silc_sftp_handle_get(handle, &hdata, &hdata_len); attrs_buf = silc_sftp_attr_encode(attrs); @@ -1046,7 +1053,7 @@ void silc_sftp_readlink(SilcSFTP sftp, req->type = SILC_SFTP_READLINK; req->name = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(path); @@ -1074,7 +1081,7 @@ void silc_sftp_symlink(SilcSFTP sftp, req->type = SILC_SFTP_SYMLINK; req->status = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(linkpath) + 4 + strlen(targetpath); @@ -1103,7 +1110,7 @@ void silc_sftp_realpath(SilcSFTP sftp, req->type = SILC_SFTP_REALPATH; req->name = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(path); @@ -1132,7 +1139,7 @@ void silc_sftp_extended(SilcSFTP sftp, req->type = SILC_SFTP_WRITE; req->extended = callback; req->context = context; - silc_dlist_add(client->requests, req); + silc_list_add(client->requests, req); len = 4 + 4 + strlen(request) + data_len; diff --git a/lib/silcsftp/sftp_server.c b/lib/silcsftp/sftp_server.c index 119dbf1f..09f636cb 100644 --- a/lib/silcsftp/sftp_server.c +++ b/lib/silcsftp/sftp_server.c @@ -32,6 +32,7 @@ typedef struct { SilcSFTPMonitor monitor; void *monitor_context; SilcSFTPFilesystem fs; + SilcBuffer packet; } *SilcSFTPServer; /* General routine to send SFTP packet to the SFTP client. */ @@ -40,22 +41,25 @@ static void silc_sftp_send_packet(SilcSFTPServer sftp, SilcSFTPPacket type, uint32 len, ...) { - SilcBuffer packet; + SilcBuffer tmp; va_list vp; va_start(vp, len); - packet = silc_sftp_packet_encode_vp(type, len, vp); + tmp = silc_sftp_packet_encode_vp(type, sftp->packet, len, vp); va_end(vp); - - if (!packet) + if (!tmp) return; + sftp->packet = tmp; - SILC_LOG_HEXDUMP(("SFTP packet to client"), packet->data, packet->len); + SILC_LOG_HEXDUMP(("SFTP packet to client"), sftp->packet->data, + sftp->packet->len); /* Send the packet */ - (*sftp->send_packet)(sftp->sock, packet, sftp->send_context); + (*sftp->send_packet)(sftp->sock, sftp->packet, sftp->send_context); - silc_buffer_free(packet); + /* Clear packet */ + sftp->packet->data = sftp->packet->tail = sftp->packet->head; + sftp->packet->len = 0; } /* Sends error to the client */ @@ -285,6 +289,8 @@ void silc_sftp_server_shutdown(SilcSFTP sftp) SILC_LOG_DEBUG(("Stopping SFTP server %p", server)); + if (server->packet) + silc_buffer_free(server->packet); silc_free(server); } diff --git a/lib/silcsftp/sftp_util.c b/lib/silcsftp/sftp_util.c index 86cca1f9..5e3c526e 100644 --- a/lib/silcsftp/sftp_util.c +++ b/lib/silcsftp/sftp_util.c @@ -25,15 +25,18 @@ /* Encodes a SFTP packet of type `packet' of length `len'. The variable argument list is encoded as data payload to the buffer. Returns the encoded packet or NULL on error. The caller must free the returned - buffer. */ + buffer. If `packet_buf' is non-NULL then the new packet data is put + to that buffer instead of allocating new one. If the new data cannot + fit to `packet_buf' will be reallocated. */ -SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, uint32 len, ...) +SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, + SilcBuffer packet_buf, uint32 len, ...) { SilcBuffer buffer; va_list vp; va_start(vp, len); - buffer = silc_sftp_packet_encode_vp(packet, len, vp); + buffer = silc_sftp_packet_encode_vp(packet, packet_buf, len, vp); va_end(vp); return buffer; @@ -42,13 +45,25 @@ SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, uint32 len, ...) /* Same as silc_sftp_packet_encode but takes the variable argument list pointer as argument. */ -SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len, +SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, + SilcBuffer packet_buf, uint32 len, va_list vp) { SilcBuffer buffer; + bool dyn; int ret; - buffer = silc_buffer_alloc(4 + 1 + len); + if (packet_buf) { + if (packet_buf->truelen < 4 + 1 + len) + packet_buf = silc_buffer_realloc(packet_buf, 4 + 1 + len); + + buffer = packet_buf; + dyn = FALSE; + } else { + buffer = silc_buffer_alloc(4 + 1 + len); + dyn = TRUE; + } + silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer)); silc_buffer_format(buffer, SILC_STR_UI_INT(len), @@ -58,7 +73,8 @@ SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len, ret = silc_buffer_format_vp(buffer, vp); if (ret < 0) { - silc_buffer_free(buffer); + if (dyn) + silc_buffer_free(buffer); return NULL; } diff --git a/lib/silcsftp/sftp_util.h b/lib/silcsftp/sftp_util.h index ac43b06a..f8e9c305 100644 --- a/lib/silcsftp/sftp_util.h +++ b/lib/silcsftp/sftp_util.h @@ -61,12 +61,16 @@ typedef uint32 SilcSFTPPacket; /* Encodes a SFTP packet of type `packet' of length `len'. The variable argument list is encoded as data payload to the buffer. Returns the encoded packet or NULL on error. The caller must free the returned - buffer. */ -SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, uint32 len, ...); + buffer. If `packet_buf' is non-NULL then the new packet data is put + to that buffer instead of allocating new one. If the new data cannot + fit to `packet_buf' will be reallocated. */ +SilcBuffer silc_sftp_packet_encode(SilcSFTPPacket packet, + SilcBuffer packet_buf, uint32 len, ...); /* Same as silc_sftp_packet_encode but takes the variable argument list pointer as argument. */ -SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, uint32 len, +SilcBuffer silc_sftp_packet_encode_vp(SilcSFTPPacket packet, + SilcBuffer packet_buf, uint32 len, va_list vp); /* Decodes the SFTP packet data `data' and return the SFTP packet type. diff --git a/lib/silcsftp/tests/sftp_client.c b/lib/silcsftp/tests/sftp_client.c index 196b6768..9b2e796d 100644 --- a/lib/silcsftp/tests/sftp_client.c +++ b/lib/silcsftp/tests/sftp_client.c @@ -51,14 +51,14 @@ static void send_packet(SilcSocketConnection sock, memset(&packetdata, 0, sizeof(packetdata)); packetdata.type = SILC_PACKET_FTP; packetdata.truelen = packet->len + SILC_PACKET_HEADER_LEN; - packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen); + packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen, 0); silc_packet_send_prepare(sock, SILC_PACKET_HEADER_LEN, packetdata.padlen, packet->len); packetdata.buffer = sock->outbuf; silc_buffer_put(sock->outbuf, packet->data, packet->len); - silc_packet_assemble(&packetdata); + silc_packet_assemble(&packetdata, NULL); ret = silc_packet_send(sock, TRUE); if (ret != -2) return; @@ -68,17 +68,19 @@ static void send_packet(SilcSocketConnection sock, SILC_SET_OUTBUF_PENDING(sock); } -static void packet_parse(SilcPacketParserContext *parser) +static bool packet_parse(SilcPacketParserContext *parser, void *context) { Client client = (Client)parser->context; SilcSocketConnection sock = parser->sock; SilcPacketContext *packet = parser->packet; int ret; - ret = silc_packet_parse(packet); + ret = silc_packet_parse(packet, NULL); assert(packet->type == SILC_PACKET_FTP); silc_sftp_client_receive_process(client->sftp, sock, packet); + + return TRUE; } SILC_TASK_CALLBACK(packet_process) @@ -112,7 +114,8 @@ SILC_TASK_CALLBACK(packet_process) exit(0); } - silc_packet_receive_process(sock, NULL, NULL, packet_parse, client); + silc_packet_receive_process(sock, FALSE, NULL, NULL, 0, + packet_parse, client); } } @@ -237,8 +240,11 @@ int main(int argc, char **argv) gclient = client; - if (argc > 1 && !strcmp(argv[1], "-d")) + if (argc > 1 && !strcmp(argv[1], "-d")) { silc_debug = 1; + silc_debug_hexdump = 1; + silc_log_set_debug_string(""); + } client->schedule = silc_schedule_init(100); if (!client->schedule) diff --git a/lib/silcsftp/tests/sftp_server.c b/lib/silcsftp/tests/sftp_server.c index e2aa1aa6..bc5ac02e 100644 --- a/lib/silcsftp/tests/sftp_server.c +++ b/lib/silcsftp/tests/sftp_server.c @@ -38,14 +38,14 @@ static void send_packet(SilcSocketConnection sock, memset(&packetdata, 0, sizeof(packetdata)); packetdata.type = SILC_PACKET_FTP; packetdata.truelen = packet->len + SILC_PACKET_HEADER_LEN; - packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen); + packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen, 0); silc_packet_send_prepare(sock, SILC_PACKET_HEADER_LEN, packetdata.padlen, packet->len); packetdata.buffer = sock->outbuf; silc_buffer_put(sock->outbuf, packet->data, packet->len); - silc_packet_assemble(&packetdata); + silc_packet_assemble(&packetdata, NULL); ret = silc_packet_send(sock, TRUE); if (ret != -2) return; @@ -55,17 +55,19 @@ static void send_packet(SilcSocketConnection sock, SILC_SET_OUTBUF_PENDING(sock); } -static void packet_parse(SilcPacketParserContext *parser) +static bool packet_parse(SilcPacketParserContext *parser, void *context) { Server server = (Server)parser->context; SilcSocketConnection sock = parser->sock; SilcPacketContext *packet = parser->packet; int ret; - ret = silc_packet_parse(packet); + ret = silc_packet_parse(packet, NULL); assert(packet->type == SILC_PACKET_FTP); silc_sftp_server_receive_process(server->sftp[sock->sock], sock, packet); + + return TRUE; } SILC_TASK_CALLBACK(packet_process) @@ -104,7 +106,8 @@ SILC_TASK_CALLBACK(packet_process) return; } - silc_packet_receive_process(sock, NULL, NULL, packet_parse, server); + silc_packet_receive_process(sock, FALSE, NULL, NULL, 0, packet_parse, + server); } } diff --git a/lib/silcutil/silcbuffer.h b/lib/silcutil/silcbuffer.h index 9b35e922..9d6f2e2a 100644 --- a/lib/silcutil/silcbuffer.h +++ b/lib/silcutil/silcbuffer.h @@ -314,7 +314,7 @@ unsigned char *silc_buffer_push_tail(SilcBuffer sb, uint32 len) extern inline unsigned char *silc_buffer_put_head(SilcBuffer sb, - unsigned char *data, + const unsigned char *data, uint32 len) { #ifdef SILC_DEBUG @@ -336,7 +336,7 @@ unsigned char *silc_buffer_put_head(SilcBuffer sb, extern inline unsigned char *silc_buffer_put(SilcBuffer sb, - unsigned char *data, + const unsigned char *data, uint32 len) { #ifdef SILC_DEBUG @@ -358,7 +358,7 @@ unsigned char *silc_buffer_put(SilcBuffer sb, extern inline unsigned char *silc_buffer_put_tail(SilcBuffer sb, - unsigned char *data, + const unsigned char *data, uint32 len) { #ifdef SILC_DEBUG