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 <priikone@silcnet.org>
* If client entry is deleted with active key agreement
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).
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.
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
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)
=============================================
{ "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 } },
{ "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 } },
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,
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));
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);
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;
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) {
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;
}
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);
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);
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);
/* 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);
/* 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);
/* 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);
}
/* 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);
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);
}
/* 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);
/* 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);
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);
}
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);
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);
}
/* 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);
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
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);
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);
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"));
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;
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;
}
/* 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;
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;
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;
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);
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;
/* 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"
<FONT SIZE="+3" COLOR="#000044"><B>SILC Toolkit Reference Manual</B></FONT>
<BR>
Copyright (C) GNU GPL 2001 The SILC Project<BR>
+Version: 0.6.3<BR>
Updated: @DATE@
<BR><BR>
<B><FONT SIZE="2">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.</FONT></B>
+include yet all references for SILC Toolkit interfaces. </FONT></B>
<BR><BR>
@BODY@
*/
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)
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
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)
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;
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;
}
/* 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;
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;
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;
* for the application.
*/
+ SILC_LOG_DEBUG(("Notify: INVITE"));
+
/* Get Channel ID */
tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
if (!tmp)
* 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)
* 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)
* 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)
* 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)
* application.
*/
+ SILC_LOG_DEBUG(("Notify: NICK_CHANGE"));
+
/* Get old Client ID */
tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
if (!tmp)
* 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;
* 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)
* Received Message of the day
*/
+ SILC_LOG_DEBUG(("Notify: MOTD"));
+
/* Get motd */
tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
if (!tmp)
* 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)
* 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)
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) {
* 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)
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);
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);
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"));
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;
/* 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;
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;
}
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);
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;
@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
-->
silcchannel.c \
silccommand.c \
silcpacket.c \
- silcpayload.c \
+ silcargument.c \
silcnotify.c \
silcauth.c \
silcprivate.c
silcmode.h \
silcnotify.h \
silcpacket.h \
- silcpayload.h \
+ silcargument.h \
silcprivate.h
endif
/*
- silcpayload.c
+ silcargument.c
- Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+ Author: Pekka Riikonen <priikone@silcnet.org>
- 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"
/******************************************************************************
--- /dev/null
+/*
+
+ silcargument.h
+
+ Author: Pekka Riikonen <priikone@silcnet.org>
+
+ 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
/* 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;
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 */
/* 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;
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;
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];
/* 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;
/* 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;
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"));
/* 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;
/* 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),
*
* SYNOPSIS
*
- * SilcAuthPayload silc_auth_payload_parse(unsigned char *data,
+ * SilcAuthPayload silc_auth_payload_parse(const unsigned char *data,
* uint32 data_len);
*
* DESCRIPTION
* `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
* 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
*
***/
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
* 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
*
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
*
* 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
*
* 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
*
* `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.
* `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
*
/* 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,
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;
}
/* 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,
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);
}
/* 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)
{
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;
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),
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;
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,
/* 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),
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;
*
* SYNOPSIS
*
- * SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer);
+ * SilcChannelPayload
+ * silc_channel_payload_parse(const unsigned char *payload,
+ * uint32 payload_len);
*
* DESCRIPTION
*
* `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
*
* 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);
*
* 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);
* 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);
*
*
***/
SilcChannelMessagePayload
-silc_channel_message_payload_parse(SilcBuffer buffer,
+silc_channel_message_payload_parse(unsigned char *payload,
+ uint32 payload_len,
SilcCipher cipher,
SilcHmac hmac);
*
* 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,
***/
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,
*
* SYNOPSIS
*
- * SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer);
+ * SilcChannelKeyPayload
+ * silc_channel_key_payload_parse(const unsigned char *payload,
+ * uin32 payload_len);
*
* DESCRIPTION
*
* 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
*
*
***/
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
*
/* 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),
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;
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;
}
*
* SYNOPSIS
*
- * SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer);
+ * SilcCommandPayload
+ * silc_command_payload_parse(const unsigned char *payload,
+ * uint32 payload_len);
*
* DESCRIPTION
*
* `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
*
#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)
* 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
#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
/* 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),
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;
*
* SYNOPSIS
*
- * SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer);
+ * SilcNotifyPayload
+ * silc_notify_payload_parse(const unsigned char *payload,
+ * uint32 payload_len);
*
* DESCRIPTION
*
* 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
*
+++ /dev/null
-/*
-
- silcpayload.h
-
- Author: Pekka Riikonen <priikone@silcnet.org>
-
- 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
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),
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;
SilcBuffer silc_private_message_payload_encode(uint16 flags,
uint16 data_len,
- unsigned char *data,
+ const unsigned char *data,
SilcCipher cipher)
{
int i;
* 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
*
*
***/
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
*
*
* SilcBuffer silc_private_message_payload_encode(uint16 flags,
* uint16 data_len,
- * unsigned char *data,
+ * const unsigned char *data,
* SilcCipher cipher);
*
* DESCRIPTION
***/
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
/* 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;
SilcSFTPAttrCallback attr;
SilcSFTPExtendedCallback extended;
void *context;
+ struct SilcSFTPRequestStruct *next;
} *SilcSFTPRequest;
/* SFTP client context */
SilcSFTPVersionCallback version;
void *version_context;
uint32 id;
- SilcDList requests;
+ SilcList requests;
+ SilcBuffer packet;
} *SilcSFTPClient;
/* File handle */
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. */
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;
}
}
/* Remove this request */
- silc_dlist_del(sftp->requests, req);
+ silc_list_del(sftp->requests, req);
silc_free(req);
va_end(vp);
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,
{
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);
}
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;
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;
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;
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;
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);
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);
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;
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);
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);
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;
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);
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);
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;
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;
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);
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);
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);
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);
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;
SilcSFTPMonitor monitor;
void *monitor_context;
SilcSFTPFilesystem fs;
+ SilcBuffer packet;
} *SilcSFTPServer;
/* General routine to send SFTP packet to the SFTP client. */
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 */
SILC_LOG_DEBUG(("Stopping SFTP server %p", server));
+ if (server->packet)
+ silc_buffer_free(server->packet);
silc_free(server);
}
/* 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;
/* 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),
ret = silc_buffer_format_vp(buffer, vp);
if (ret < 0) {
- silc_buffer_free(buffer);
+ if (dyn)
+ silc_buffer_free(buffer);
return NULL;
}
/* 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.
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;
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)
exit(0);
}
- silc_packet_receive_process(sock, NULL, NULL, packet_parse, client);
+ silc_packet_receive_process(sock, FALSE, NULL, NULL, 0,
+ packet_parse, client);
}
}
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)
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;
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)
return;
}
- silc_packet_receive_process(sock, NULL, NULL, packet_parse, server);
+ silc_packet_receive_process(sock, FALSE, NULL, NULL, 0, packet_parse,
+ server);
}
}
extern inline
unsigned char *silc_buffer_put_head(SilcBuffer sb,
- unsigned char *data,
+ const unsigned char *data,
uint32 len)
{
#ifdef SILC_DEBUG
extern inline
unsigned char *silc_buffer_put(SilcBuffer sb,
- unsigned char *data,
+ const unsigned char *data,
uint32 len)
{
#ifdef SILC_DEBUG
extern inline
unsigned char *silc_buffer_put_tail(SilcBuffer sb,
- unsigned char *data,
+ const unsigned char *data,
uint32 len)
{
#ifdef SILC_DEBUG