updates.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 26 Nov 2001 19:05:58 +0000 (19:05 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 26 Nov 2001 19:05:58 +0000 (19:05 +0000)
44 files changed:
CHANGES
TODO
apps/irssi/src/fe-common/silc/module-formats.c
apps/irssi/src/fe-common/silc/module-formats.h
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/silc-channels.c
apps/silcd/command.c
apps/silcd/command_reply.c
apps/silcd/packet_receive.c
apps/silcd/packet_send.c
apps/silcd/server.c
includes/silcincludes.h
lib/LIBINDEX
lib/silcclient/client.c
lib/silcclient/client_channel.c
lib/silcclient/client_ftp.c
lib/silcclient/client_keyagr.c
lib/silcclient/client_notify.c
lib/silcclient/client_prvmsg.c
lib/silcclient/command_reply.c
lib/silccore/DIRECTORY
lib/silccore/Makefile.am
lib/silccore/silcargument.c [moved from lib/silccore/silcpayload.c with 58% similarity]
lib/silccore/silcargument.h [new file with mode: 0644]
lib/silccore/silcauth.c
lib/silccore/silcauth.h
lib/silccore/silcchannel.c
lib/silccore/silcchannel.h
lib/silccore/silccommand.c
lib/silccore/silccommand.h
lib/silccore/silcid.c
lib/silccore/silcid.h
lib/silccore/silcnotify.c
lib/silccore/silcnotify.h
lib/silccore/silcpayload.h [deleted file]
lib/silccore/silcprivate.c
lib/silccore/silcprivate.h
lib/silcsftp/sftp_client.c
lib/silcsftp/sftp_server.c
lib/silcsftp/sftp_util.c
lib/silcsftp/sftp_util.h
lib/silcsftp/tests/sftp_client.c
lib/silcsftp/tests/sftp_server.c
lib/silcutil/silcbuffer.h

diff --git a/CHANGES b/CHANGES
index 5bd1c49ad935b96b0961d58c11a226a6678d50e3..e88cd101215f446081dbb748a87b2d3ce5051f40 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -25,6 +25,11 @@ Mon Nov 26 18:09:48 EET 2001  Pekka Riikonen <priikone@silcnet.org>'
          SilcDList for requests, because it is faster.  Affected file
          is lib/silcsftp/sftp_client.c.
 
          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
 Mon Nov 26 15:01:53 CET 2001  Pekka Riikonen <priikone@silcnet.org>
 
        * If client entry is deleted with active key agreement
diff --git a/TODO b/TODO
index 3e1c4787920a03c9de466f843ded8299e3c801b7..eb752293cf5555005046081d1e4c7cbc817c4718 100644 (file)
--- 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.
 
    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 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 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.
 
          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
 ===========================
 
 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 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 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)
 =============================================
 
 TODO/Bugs in native WIN32 support (libraries)
 =============================================
index 9b5b6514a8ca4a86ecf28a85f581404683da7220..4a8ec1288b9e82ef9eb2093ebabd5db8f1b48954 100644 (file)
@@ -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 } },
        { "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 } },
 
        { "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_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 } },
        { "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 } },
index ce4595c3375fbac59b8867ddb7facf7edbc3b634..62b2db5a2c50f4fc5ac4f8f3e3e8a822cd091fd5 100644 (file)
@@ -74,6 +74,7 @@ enum {
   SILCTXT_KEY_AGREEMENT_ERROR,
   SILCTXT_KEY_AGREEMENT_FAILURE,
   SILCTXT_KEY_AGREEMENT_TIMEOUT,
   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,
   SILCTXT_PUBKEY_RECEIVED,
   SILCTXT_PUBKEY_FINGERPRINT,
   SILCTXT_PUBKEY_BABBLEPRINT,
index 89ef6c80c3ec93db88c1da90f88f52b6dc73920d..9d7d7d86828499030bb7d5826a2a91dc28a42464 100644 (file)
@@ -439,7 +439,8 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
       silc_free(nick);
 
       if (channels) {
       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));
        if (list) {
          SilcChannelPayload entry;
          memset(buf, 0, sizeof(buf));
index da14bcdd5e1aee79c7bca1a41845cfd56c6ff3ec..25d6b6a4e122e12375c9c3a312414d9a4a5831fc 100644 (file)
@@ -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;
 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 *);
   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);
   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, 
   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;
                       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,
     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) {
                       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;
     
                       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;
   } 
   default:
     break;
   } 
index 80e4ed3637990b488b26cca096e25e2190f2c852..25b642f4ec18016c9c4cfdbb0dfed33d87bf5105 100644 (file)
@@ -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->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);
   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*");
     }
       
       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);
     
     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;
       
       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);
       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);
       
       /* 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);
       
       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);
       
       /* 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);
       
       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];
   /* Local list */
   for (i = 0; i < lch_count; i++) {
     entry = lch[i];
-
     if (!entry)
       continue;
 
     if (i >= 1)
       status = SILC_STATUS_LIST_ITEM;
     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);
       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 */
     }
 
     /* 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_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);
   }
 
     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];
   /* Global list */
   for (i = 0; i < gch_count; i++) {
     entry = gch[i];
-
     if (!entry)
       continue;
 
     if (i >= 1)
       status = SILC_STATUS_LIST_ITEM;
     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);
       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 */
     }
 
     /* 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_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);
 
   /* 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);
 
   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 */
   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);
     
   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);
     }
 
     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);
     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;
   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);
 
 
   SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_LEAVE, cmd, 1, 3);
 
@@ -4406,13 +4347,13 @@ SILC_SERVER_CMD_FUNC(kick)
   }
   
   /* Get target Client ID */
   }
   
   /* 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;
   }
     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);
   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 */
                                        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_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
   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 */
                                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_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;
   }
                                          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);
   if (!idp) {
     silc_server_command_send_status_reply(cmd, SILC_COMMAND_GETKEY,
                                          SILC_STATUS_ERR_NOT_ENOUGH_PARAMS);
index f83b9f9563da2c05c74e27fe7a316f784f0a3e74..2bd74472bc4b324be775cf0a5dd6760b920c7c02 100644 (file)
@@ -77,7 +77,7 @@ void silc_server_command_reply_process(SilcServer server,
   SILC_LOG_DEBUG(("Start"));
 
   /* Get command reply payload from packet */
   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"));
   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;
   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;
 
   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;
   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;
 
   if (!idp)
     goto out;
 
index b3fd76db47c54e09b5f8f3f31e9057bab879f8cf..3b11de0f82800e4682eced94663caacefb25087f 100644 (file)
@@ -76,7 +76,8 @@ void silc_server_notify(SilcServer server,
   }
 
   /* Parse the Notify Payload */
   }
 
   /* 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;
 
   if (!payload)
     return;
 
@@ -1836,7 +1837,7 @@ static void silc_server_new_id_real(SilcServer server,
       packet->src_id_type != SILC_ID_SERVER)
     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;
 
   if (!idp)
     return;
 
@@ -2113,7 +2114,8 @@ void silc_server_new_channel(SilcServer server,
     return;
 
   /* Parse the channel payload */
     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;
     
   if (!payload)
     return;
     
index 773c3f3ef39620d842a67bea05953f75df8a5146..0956bdbdaa56a1e20e0f7a446cb3738f3361df4d 100644 (file)
@@ -1754,7 +1754,8 @@ void silc_server_send_command_reply(SilcServer server,
 
   va_start(ap, argc);
 
 
   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_server_packet_send(server, sock, SILC_PACKET_COMMAND_REPLY, 0,
                          packet->data, packet->len, TRUE);
   silc_buffer_free(packet);
index a9a9435b1087e6176370d513ac50510f352ab4d7..4543cc28cabe994c8d984903fed396cbfa01e4fa 100644 (file)
@@ -2978,7 +2978,8 @@ SilcChannelEntry silc_server_save_channel_key(SilcServer server,
   SILC_LOG_DEBUG(("Start"));
 
   /* Decode channel key payload */
   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;
   if (!payload) {
     SILC_LOG_ERROR(("Bad channel key payload, dropped"));
     channel = NULL;
index 3520afd1942b25da8988d39ff9d2fc9115f9ba05..7ee3c0d03cb8b67af3be2b981f403c8b59440f75 100644 (file)
@@ -249,7 +249,7 @@ typedef uint32 * void *;
 /* SILC core library includes */
 #include "silcid.h"
 #include "silcidcache.h"
 /* 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"
 #include "silccommand.h"
 #include "silcchannel.h"
 #include "silcpacket.h"
index 9c0073ab3522cb3a68769d844c011f18cf6d1d4c..e19fcbaf0df07e8bca8e925f421222e9f21559f1 100644 (file)
@@ -6,10 +6,10 @@
 <FONT SIZE="+3" COLOR="#000044"><B>SILC Toolkit Reference Manual</B></FONT>
 <BR>
 Copyright (C) GNU GPL 2001 The SILC Project<BR>
 <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
 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@
 <BR><BR>
 @BODY@
index 7f1731dc54ac7589c9490a7ebf31b7c684719d4d..0440478dc2230a3d4f40f3fdc1512fc09407007d 100644 (file)
@@ -1050,7 +1050,7 @@ void silc_client_packet_parse_type(SilcClient client,
        */
       SilcIDPayload idp;
 
        */
       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)
       if (!idp)
        break;
       if (silc_id_payload_get_type(idp) != SILC_ID_CLIENT)
index aeb0ed85756cf223076c4963b08b708b61cea3e3..fbe9686315a1d8291d5a62707ee13d9f86b66630 100644 (file)
@@ -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 */
      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
                                                 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;
 
       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)
                                                   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 */
     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;
                                                   entry->hmac);
       if (payload)
        break;
@@ -339,7 +341,8 @@ void silc_client_save_channel_key(SilcClientConnection conn,
   SilcIDCacheEntry id_cache = NULL;
   SilcChannelKeyPayload payload;
 
   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;
 
   if (!payload)
     return;
 
index 7f85a8db9e03b6176e6fe8f18c20bd6b3eec8e89..1c20d625adbf8bc66d417de91b807ba05fa38e4d 100644 (file)
@@ -1013,7 +1013,8 @@ static void silc_client_ftp_resolve_cb(SilcClient client,
   }
 
   /* Parse the key agreement payload */
   }
 
   /* 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;
 
   if (!payload)
     goto out;
 
index b21a7dc737af22d7f228d827d67adfd70f5226a1..37f980034999bb43e7600f318da11237260bc0f1 100644 (file)
@@ -655,7 +655,8 @@ silc_client_key_agreement_resolve_cb(SilcClient client,
     goto out;
 
   /* Parse the key agreement payload */
     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;
 
   if (!payload)
     goto out;
 
index 1b7c39720a131a265c51fe7ad21cbf14af694fa1..ddc70e7bdcbd5e87aebf251ab7645bd88a9c5788 100644 (file)
@@ -111,7 +111,9 @@ void silc_client_notify_by_server(SilcClient client,
   unsigned char *tmp;
   uint32 tmp_len, mode;
 
   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;
 
   if (!payload)
     goto out;
 
@@ -133,6 +135,8 @@ void silc_client_notify_by_server(SilcClient client,
      * for the application.
      */
     
      * for the application.
      */
     
+    SILC_LOG_DEBUG(("Notify: INVITE"));
+
     /* Get Channel ID */
     tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
     if (!tmp)
     /* 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.
      */
 
      * 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)
     /* 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.
      */
     
      * 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)
     /* 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.
      */
 
      * 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)
     /* 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.
      */
 
      * 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)
     /* 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.
      */
 
      * application.
      */
 
+    SILC_LOG_DEBUG(("Notify: NICK_CHANGE"));
+
     /* Get old Client ID */
     tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
     if (!tmp)
     /* 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
      */
 
      * 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;
 
     /* 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;
 
     if (!idp)
       goto out;
 
@@ -533,6 +549,8 @@ void silc_client_notify_by_server(SilcClient client,
      * Someone changed user's mode on a channel
      */
 
      * 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)
     /* 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
      */
 
      * Received Message of the day
      */
 
+    SILC_LOG_DEBUG(("Notify: MOTD"));
+
     /* Get motd */
     tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
     if (!tmp)
     /* 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.
      */
 
      * 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)
     /* 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
      */
 
      * 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)
     /* 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,
     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;
 
       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. */
     /* 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) {
 
     /* 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.
      */
 
      * 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)
     /* 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;
 
       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);
       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);
index 5acc8610abd2d3d4fa446ee3cca7980f319abd0a..331e1d6990cba16b376e7c500f3b4b8a5f187042 100644 (file)
@@ -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 */
   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);
                                               remote_client->receive_key);
   if (!payload) {
     silc_free(remote_id);
index f775d60c6fdbb82513df57edf38751e8b6298d4b..5b5ef427294c94cbff3a960512fce938a2ff9758 100644 (file)
@@ -162,7 +162,7 @@ void silc_client_command_reply_process(SilcClient client,
   uint16 ident;
 
   /* Get command reply payload from packet */
   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"));
   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;
   }
     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;
   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);
 
   /* 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;
   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) {
 
   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;
   }
     COMMAND_REPLY_ERROR;
     goto out;
   }
@@ -965,7 +966,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join)
     silc_free(channel_name);
     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);
   if (!idp) {
     COMMAND_REPLY_ERROR;
     silc_free(channel_name);
@@ -1844,7 +1845,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey)
     COMMAND_REPLY_ERROR;
     goto out;
   }
     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;
   if (!idp) {
     COMMAND_REPLY_ERROR;
     goto out;
index 7da6935cde6c666001a68977b8d368b785401365..8cac11a909bb755b7b2370a6702850bb7aba0e3c 100644 (file)
@@ -9,7 +9,7 @@
 @LINK=silcmode.html:SILC Modes
 @LINK=silcnotify.html:SILC Notify API
 @LINK=silcpacket.html:SILC Packet API
 @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
 -->
 
 @LINK=silcprivate.html:SILC Private API
 -->
 
index 04e898cd4da4800a965c9f327de913a1a6fb42e4..bf01a0f103df4ebdcc71d0a07aa6878736944687 100644 (file)
@@ -26,7 +26,7 @@ libsilccore_a_SOURCES = \
        silcchannel.c \
        silccommand.c \
        silcpacket.c \
        silcchannel.c \
        silccommand.c \
        silcpacket.c \
-       silcpayload.c \
+       silcargument.c \
        silcnotify.c \
        silcauth.c \
        silcprivate.c
        silcnotify.c \
        silcauth.c \
        silcprivate.c
@@ -41,7 +41,7 @@ include_HEADERS =     \
        silcmode.h      \
        silcnotify.h    \
        silcpacket.h    \
        silcmode.h      \
        silcnotify.h    \
        silcpacket.h    \
-       silcpayload.h   \
+       silcargument.h  \
        silcprivate.h
 endif
 
        silcprivate.h
 endif
 
similarity index 58%
rename from lib/silccore/silcpayload.c
rename to lib/silccore/silcargument.c
index cc7071f18a54496a48d9c67a609ecc623e5aa1a7..471e92c78fe18130da9bbbd89caac6ad4d7e8394 100644 (file)
 /*
 
 /*
 
-  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
 
   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.
 
 */
   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"
 /* $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 (file)
index 0000000..f5de0d9
--- /dev/null
@@ -0,0 +1,175 @@
+/*
+
+  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
index ef3512ecff1cb9e92fbac2deb5da58e93369990f..36c51e93dd3494eebb5a453c99cbc9fcdee50583 100644 (file)
@@ -40,7 +40,7 @@ struct SilcAuthPayloadStruct {
 
 /* Parses and returns Authentication Payload */
 
 
 /* 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;
                                        uint32 data_len)
 {
   SilcBufferStruct buffer;
@@ -49,8 +49,7 @@ SilcAuthPayload silc_auth_payload_parse(unsigned char *data,
 
   SILC_LOG_DEBUG(("Parsing Authentication Payload"));
 
 
   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 */
   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,
 /* 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,
                                    uint16 random_len,
-                                   unsigned char *auth_data,
+                                   const unsigned char *auth_data,
                                    uint16 auth_len)
 {
   SilcBuffer buffer;
                                    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, 
 
 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;
                                 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,
 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];
 {
   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. */
 
 /* 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;
 {
   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. */
 
 
 /* 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;
 
 {
   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;
   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. */
 
    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"));
 
 {
   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. */
 
 
 /* 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;
 {
   SilcAuthPayload auth_payload;
   int ret;
@@ -416,17 +416,21 @@ struct SilcKeyAgreementPayloadStruct {
 
 /* Parses and returns an allocated Key Agreement payload. */
 
 
 /* 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"));
 
   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 */
   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),
                             SILC_STR_UI16_NSTRING_ALLOC(&new->hostname,
                                                         &new->hostname_len),
                             SILC_STR_UI_INT(&new->port),
index a42c60fc902462dd8a391d6a4a2dbbe255b5a3b4..c280dab3536483c1ec4c62d22f40e0c89b702984 100644 (file)
@@ -103,7 +103,7 @@ typedef uint16 SilcAuthMethod;
  *
  * SYNOPSIS
  *
  *
  * SYNOPSIS
  *
- *    SilcAuthPayload silc_auth_payload_parse(unsigned char *data,
+ *    SilcAuthPayload silc_auth_payload_parse(const unsigned char *data,
  *                                            uint32 data_len);
  *
  * DESCRIPTION
  *                                            uint32 data_len);
  *
  * DESCRIPTION
@@ -112,7 +112,7 @@ typedef uint16 SilcAuthMethod;
  *    `data_len' are the raw payload buffer.
  *
  ***/
  *    `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
                                        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,
  * SYNOPSIS
  *
  *    SilcBuffer silc_auth_payload_encode(SilcAuthMethod method,
- *                                        unsigned char *random_data,
+ *                                        const unsigned char *random_data,
  *                                        uint16 random_len,
  *                                        uint16 random_len,
- *                                        unsigned char *auth_data,
+ *                                        const unsigned char *auth_data,
  *                                        uint16 auth_len);
  *
  * DESCRIPTION
  *                                        uint16 auth_len);
  *
  * DESCRIPTION
@@ -133,9 +133,9 @@ SilcAuthPayload silc_auth_payload_parse(unsigned char *data,
  *
  ***/
 SilcBuffer silc_auth_payload_encode(SilcAuthMethod method,
  *
  ***/
 SilcBuffer silc_auth_payload_encode(SilcAuthMethod method,
-                                   unsigned char *random_data,
+                                   const unsigned char *random_data,
                                    uint16 random_len,
                                    uint16 random_len,
-                                   unsigned char *auth_data,
+                                   const unsigned char *auth_data,
                                    uint16 auth_len);
 
 /****f* silccore/SilcAuthAPI/silc_auth_payload_free
                                    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,
  *    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
  *
  *
  * 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,
 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
  *
 
 /****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
  *
  *
  * DESCRIPTION
  *
@@ -216,18 +217,20 @@ SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key,
  *    successful.
  *
  ***/
  *    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
  *
 
 /****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
  *
  *
  * DESCRIPTION
  *
@@ -236,18 +239,20 @@ int silc_auth_public_key_auth_verify(SilcAuthPayload payload,
  *    was successful.
  *
  ***/
  *    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
  *
 
 /****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
  *
  *
  * DESCRIPTION
  *
@@ -259,19 +264,21 @@ int silc_auth_public_key_auth_verify_data(SilcBuffer payload,
  *    `auth_data_len' is ignored.
  *
  ***/
  *    `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
  *
 
 /****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.
  * 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.
  *
  ***/
  *    `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 
 
 /****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.
  *
  ***/
  *
  * 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
  *
 
 /****f* silccore/SilcAuthAPI/silc_key_agreement_payload_encode
  *
index 0a3e2dc30b927e50c4be887ba8d7bd7e3776a26c..def0d53bdb9eac2e7e5c24de32fd14246d1e6c69 100644 (file)
@@ -42,17 +42,20 @@ struct SilcChannelPayloadStruct {
 
 /* Parses channel payload returning new channel payload structure. */
 
 
 /* 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"));
 
   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. */
   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, 
                             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 (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;
   }
     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. */
 
 
 /* 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"));
 
   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();
 
   list = silc_dlist_init();
 
-  while (buffer->len) {
+  while (buffer.len) {
     new = silc_calloc(1, sizeof(*new));
     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, 
                               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 (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;
       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;
       break;
-    silc_buffer_pull(buffer, len);
+    silc_buffer_pull(&buffer, len);
 
     silc_dlist_add(list, new);
   }
 
     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. */
 
 
 /* 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,
                                       uint16 channel_name_len,
-                                      unsigned char *channel_id,
+                                      const unsigned char *channel_id,
                                       uint32 channel_id_len,
                                       uint32 mode)
 {
                                       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 
    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)
 {
                                   SilcCipher cipher,
                                   SilcHmac hmac)
 {
+  SilcBufferStruct buffer;
   SilcChannelMessagePayload new;
   int ret;
   uint32 iv_len, mac_len;
 
   SILC_LOG_DEBUG(("Parsing channel message payload"));
 
   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 */
   /* 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;
                                             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. */
   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),
                             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 (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;
     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,
 
 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,
                                               uint16 iv_len,
                                               unsigned char *iv,
                                               SilcCipher cipher,
@@ -450,18 +460,22 @@ struct SilcChannelKeyPayloadStruct {
 
 /* Parses channel key payload returning new channel key payload structure */
 
 
 /* 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"));
 
   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 =
   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),
                         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,
    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,
                                           uint16 cipher_len,
-                                          unsigned char *cipher,
+                                          const unsigned char *cipher,
                                           uint16 key_len,
                                           uint16 key_len,
-                                          unsigned char *key)
+                                          const unsigned char *key)
 {
   SilcBuffer buffer;
   uint32 len;
 {
   SilcBuffer buffer;
   uint32 len;
index fdd8e663850c5bb3838655e841cac4d9587d2bd5..5ad1f929309b8316cbac28c27a40eb80c4cd3eab 100644 (file)
@@ -121,7 +121,9 @@ typedef uint16 SilcMessageFlags;
  *
  * SYNOPSIS
  *
  *
  * SYNOPSIS
  *
- *    SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer);
+ *    SilcChannelPayload 
+ *    silc_channel_payload_parse(const unsigned char *payload,
+ *                               uint32 payload_len);
  *
  * DESCRIPTION
  *
  *
  * DESCRIPTION
  *
@@ -129,13 +131,16 @@ typedef uint16 SilcMessageFlags;
  *    `buffer' is the raw payload buffer.
  *
  ***/
  *    `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
  *
 
 /****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
  *
  *
  * DESCRIPTION
  *
@@ -144,15 +149,16 @@ SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer);
  *    now includes multiple Channel Payloads one after the other.
  *
  ***/
  *    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
  *
 
 /****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,
  *                                           uint16 channel_name_len,
- *                                           unsigned char *channel_id,
+ *                                           const unsigned char *channel_id,
  *                                           uint32 channel_id_len,
  *                                           uint32 mode);
  *
  *                                           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.
  *
  ***/
  *    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,
                                       uint16 channel_name_len,
-                                      unsigned char *channel_id,
+                                      const unsigned char *channel_id,
                                       uint32 channel_id_len,
                                       uint32 mode);
 
                                       uint32 channel_id_len,
                                       uint32 mode);
 
@@ -289,7 +295,8 @@ int silc_channel_message_payload_decrypt(unsigned char *data,
  * SYNOPSIS
  *
  *    SilcChannelMessagePayload 
  * 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);
  *
  *                                       SilcCipher cipher,
  *                                       SilcHmac hmac);
  *
@@ -304,7 +311,8 @@ int silc_channel_message_payload_decrypt(unsigned char *data,
  *
  ***/
 SilcChannelMessagePayload 
  *
  ***/
 SilcChannelMessagePayload 
-silc_channel_message_payload_parse(SilcBuffer buffer,
+silc_channel_message_payload_parse(unsigned char *payload,
+                                  uint32 payload_len,
                                   SilcCipher cipher,
                                   SilcHmac hmac);
 
                                   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,
  *
  *    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,
  *                                                   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,
  ***/
 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,
                                               uint16 iv_len,
                                               unsigned char *iv,
                                               SilcCipher cipher,
@@ -419,7 +427,9 @@ unsigned char *silc_channel_message_get_iv(SilcChannelMessagePayload payload);
  *
  * SYNOPSIS
  *
  *
  * SYNOPSIS
  *
- *    SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer);
+ *    SilcChannelKeyPayload 
+ *    silc_channel_key_payload_parse(const unsigned char *payload,
+ *                                   uin32 payload_len);
  *
  * DESCRIPTION
  *
  *
  * DESCRIPTION
  *
@@ -427,18 +437,20 @@ unsigned char *silc_channel_message_get_iv(SilcChannelMessagePayload payload);
  *     structure.
  *
  ***/
  *     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,
 
 /****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,
  *                                               uint16 cipher_len,
- *                                               unsigned char *cipher,
+ *                                               const unsigned char *cipher,
  *                                               uint16 key_len,
  *                                               uint16 key_len,
- *                                               unsigned char *key);
+ *                                               const unsigned char *key);
  *
  * DESCRIPTION
  *
  *
  * DESCRIPTION
  *
@@ -447,11 +459,11 @@ SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer);
  *
  ***/
 SilcBuffer silc_channel_key_payload_encode(uint16 id_len,
  *
  ***/
 SilcBuffer silc_channel_key_payload_encode(uint16 id_len,
-                                          unsigned char *id,
+                                          const unsigned char *id,
                                           uint16 cipher_len,
                                           uint16 cipher_len,
-                                          unsigned char *cipher,
+                                          const unsigned char *cipher,
                                           uint16 key_len,
                                           uint16 key_len,
-                                          unsigned char *key);
+                                          const unsigned char *key);
 
 /****f* silccore/SilcChannelAPI/silc_channel_key_payload_free
  *
 
 /****f* silccore/SilcChannelAPI/silc_channel_key_payload_free
  *
index e85c72350ff9246daf77e2dea59dafca93848a1c..ba029871df1814d1b8fdb8d040191fb647a4b347 100644 (file)
@@ -41,20 +41,23 @@ struct SilcCommandPayloadStruct {
 
 /* Parses command payload returning new command payload structure */
 
 
 /* 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;
   SilcCommandPayload new;
   unsigned char args_num;
-  uint16 payload_len;
+  uint16 p_len;
   int ret;
 
   SILC_LOG_DEBUG(("Parsing command payload"));
 
   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 */
   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),
                             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;
   }
 
     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;
     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;
   }
 
     return NULL;
   }
 
-  silc_buffer_pull(buffer, SILC_COMMAND_PAYLOAD_LEN);
+  silc_buffer_pull(&buffer, SILC_COMMAND_PAYLOAD_LEN);
   if (args_num) {
   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;
     }
   }
     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;
 }
 
   return new;
 }
index 3fdf80f110e2828f559e87c905f54597369f72df..65ed46a2f5b652de0bd14a45009de2e5aa71e1ea 100644 (file)
@@ -222,7 +222,9 @@ typedef uint16 SilcCommandStatus;
  *
  * SYNOPSIS
  *
  *
  * SYNOPSIS
  *
- *    SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer);
+ *    SilcCommandPayload 
+ *    silc_command_payload_parse(const unsigned char *payload,
+ *                               uint32 payload_len);
  *
  * DESCRIPTION
  *
  *
  * DESCRIPTION
  *
@@ -230,7 +232,8 @@ typedef uint16 SilcCommandStatus;
  *    `buffer' is the raw payload.
  *
  ***/
  *    `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
  *
 
 /****f* silccore/SilcCommandAPI/silc_command_payload_encode
  *
index bdd1353d60c69417ffb5ca5ee0fc825e5d5efaf0..9a35723a38832fc94ac599558dfe18edc07dc271 100644 (file)
 #define ID_CLIENT_LEN_PART      CLIENTID_HASH_LEN + 1
 #define ID_CHANNEL_LEN_PART     4
 
 #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)
 /* Converts ID to string. */
 
 unsigned char *silc_id_id2str(const void *id, SilcIdType type)
index e28c412a408ee061af49e7165cd9951a80614206..975d19d7ef2812a12dec8b38b6f686c272320ea0 100644 (file)
@@ -32,6 +32,9 @@
  * way to distinguish the ID's from other ID's. The ID's supports both
  * IPv4 and IPv6.
  *
  * 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
  ***/
 
 #ifndef SILCID_H
@@ -66,6 +69,168 @@ typedef uint16 SilcIdType;
 
 #define CLIENTID_HASH_LEN       (88 / 8) /* Client ID's 88 bit MD5 hash */
 
 
 #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
 /****s* silccore/SilcIDAPI/SilcIDIP
  *
  * NAME
index bee44cea970677473b0f72062f6ffb1bb983d0bb..99f342cff65493b06064b25e00afcfef6340dab5 100644 (file)
@@ -36,17 +36,20 @@ struct SilcNotifyPayloadStruct {
 
 /* Parse notify payload buffer and return data into payload structure */
 
 
 /* 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"));
 
   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));
 
   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),
                             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 (ret == -1)
     goto err;
 
-  if (len > buffer->len)
+  if (len > buffer.len)
     goto err;
 
   if (new->argc) {
     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;
   }
 
   return new;
index d173a51ddca9d0c69740d5428bb66c40023f4804..f00772b1b26f1cfe456ed8c9089bd1d1b3b25baf 100644 (file)
@@ -87,7 +87,9 @@ typedef uint16 SilcNotifyType;
  *
  * SYNOPSIS
  *
  *
  * SYNOPSIS
  *
- *    SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer);
+ *    SilcNotifyPayload 
+ *    silc_notify_payload_parse(const unsigned char *payload,
+ *                              uint32 payload_len);
  *
  * DESCRIPTION
  *
  *
  * DESCRIPTION
  *
@@ -95,7 +97,8 @@ typedef uint16 SilcNotifyType;
  *    The `buffer' is the raw payload data.
  *
  ***/
  *    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
  *
 
 /****f* silccore/SilcNotifyAPI/silc_notify_payload_encode
  *
diff --git a/lib/silccore/silcpayload.h b/lib/silccore/silcpayload.h
deleted file mode 100644 (file)
index e8a96f7..0000000
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
-
-  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
index 60534f6be8735c332d7ca31d4bb943be5914dd4b..ac56c1d03d864cbe7294231e2eebfb358797acc8 100644 (file)
@@ -43,22 +43,27 @@ struct SilcPrivateMessagePayloadStruct {
    structure. This also decrypts the message if the `cipher' is provided. */
 
 SilcPrivateMessagePayload 
    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"));
 
   SilcPrivateMessagePayload new;
   int ret;
 
   SILC_LOG_DEBUG(("Parsing private message payload"));
 
+  silc_buffer_set(&buffer, payload, payload_len);
+
   /* Decrypt the payload */
   if (cipher)
   /* 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. */
 
   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),
                             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;
   }
 
     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;
     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,
 
 SilcBuffer silc_private_message_payload_encode(uint16 flags,
                                               uint16 data_len,
-                                              unsigned char *data,
+                                              const unsigned char *data,
                                               SilcCipher cipher)
 {
   int i;
                                               SilcCipher cipher)
 {
   int i;
index 80a2c683751384543acbc4d0d051370601cdfab1..f8beca27e4c418f96b6e1486aa4311b9abb1df5f 100644 (file)
@@ -55,7 +55,9 @@ typedef struct SilcPrivateMessagePayloadStruct *SilcPrivateMessagePayload;
  * SYNOPSIS
  *
  *    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
  *
  *
  * DESCRIPTION
  *
@@ -64,7 +66,9 @@ typedef struct SilcPrivateMessagePayloadStruct *SilcPrivateMessagePayload;
  *
  ***/
 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
  *
 
 /****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,
  *
  *    SilcBuffer silc_private_message_payload_encode(uint16 flags,
  *                                                   uint16 data_len,
- *                                                   unsigned char *data,
+ *                                                   const unsigned char *data,
  *                                                   SilcCipher cipher);
  *
  * DESCRIPTION
  *                                                   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,
  ***/
 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
                                               SilcCipher cipher);
 
 /****f* silccore/SilcPrivateAPI/silc_private_message_payload_free
index 29ee2076ecd8972852c5e608bb25dce36e7ebf9b..0aa1b91cab7d1fafdccb0d43f01539c9e2a7c7c6 100644 (file)
@@ -24,7 +24,7 @@
 
 /* Request context. Every request will allocate this context and set
    the correct callback function according the `type' field. */
 
 /* 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;
   uint32 id;
   SilcSFTPPacket type;
   SilcSFTPStatusCallback status;
@@ -34,6 +34,7 @@ typedef struct {
   SilcSFTPAttrCallback attr;
   SilcSFTPExtendedCallback extended;
   void *context;
   SilcSFTPAttrCallback attr;
   SilcSFTPExtendedCallback extended;
   void *context;
+  struct SilcSFTPRequestStruct *next;
 } *SilcSFTPRequest;
 
 /* SFTP client context */
 } *SilcSFTPRequest;
 
 /* SFTP client context */
@@ -44,7 +45,8 @@ typedef struct {
   SilcSFTPVersionCallback version;
   void *version_context;
   uint32 id;
   SilcSFTPVersionCallback version;
   void *version_context;
   uint32 id;
-  SilcDList requests;
+  SilcList requests;
+  SilcBuffer packet;
 } *SilcSFTPClient;
 
 /* File handle */
 } *SilcSFTPClient;
 
 /* File handle */
@@ -93,22 +95,25 @@ static void silc_sftp_send_packet(SilcSFTPClient sftp,
                                  SilcSFTPPacket type, 
                                  uint32 len, ...)
 {
                                  SilcSFTPPacket type, 
                                  uint32 len, ...)
 {
-  SilcBuffer packet;
+  SilcBuffer tmp;
   va_list vp;
 
   va_start(vp, len);
   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);
   va_end(vp);
-
-  if (!packet)
+  if (!tmp)
     return;
     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 */
 
   /* 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. */
 }
 
 /* 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_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;
   }
     if (req->id == id)
       return req;
   }
@@ -280,7 +285,7 @@ static void silc_sftp_call_request(SilcSFTPClient sftp,
   }
 
   /* Remove this request */
   }
 
   /* Remove this request */
-  silc_dlist_del(sftp->requests, req);
+  silc_list_del(sftp->requests, req);
   silc_free(req);
 
   va_end(vp);
   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->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, 
 
   /* 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;
 
 {
   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);
 }
 
   silc_free(sftp);
 }
 
@@ -583,7 +590,7 @@ void silc_sftp_open(SilcSFTP sftp,
   req->type = SILC_SFTP_OPEN;
   req->handle = callback;
   req->context = context;
   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;
 
   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;
   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;
 
   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;
   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;
 
   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;
   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;
 
   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;
   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);
 
 
   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;
   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);
 
 
   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;
   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;
 
   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;
   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);
 
 
   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;
   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);
 
 
   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;
   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;
 
   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;
   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);
 
 
   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;
   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);
 
 
   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;
   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;
 
   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;
   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;
 
   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;
   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);
 
   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;
   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);
 
 
   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;
   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);
 
 
   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;
   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);
 
 
   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;
   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;
 
 
   len = 4 + 4 + strlen(request) + data_len;
 
index 119dbf1f36d7c58d5886087fb3e20d96d339d6c6..09f636cbb320e61d2c616dd1459ffa996db51faf 100644 (file)
@@ -32,6 +32,7 @@ typedef struct {
   SilcSFTPMonitor monitor;
   void *monitor_context;
   SilcSFTPFilesystem fs;
   SilcSFTPMonitor monitor;
   void *monitor_context;
   SilcSFTPFilesystem fs;
+  SilcBuffer packet;
 } *SilcSFTPServer;
 
 /* General routine to send SFTP packet to the SFTP client. */
 } *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, ...)
 {
                                  SilcSFTPPacket type, 
                                  uint32 len, ...)
 {
-  SilcBuffer packet;
+  SilcBuffer tmp;
   va_list vp;
 
   va_start(vp, len);
   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);
   va_end(vp);
-
-  if (!packet)
+  if (!tmp)
     return;
     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 */
 
   /* 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 */
 }
 
 /* Sends error to the client */
@@ -285,6 +289,8 @@ void silc_sftp_server_shutdown(SilcSFTP sftp)
 
   SILC_LOG_DEBUG(("Stopping SFTP server %p", server));
 
 
   SILC_LOG_DEBUG(("Stopping SFTP server %p", server));
 
+  if (server->packet)
+    silc_buffer_free(server->packet);
   silc_free(server);
 }
 
   silc_free(server);
 }
 
index 86cca1f975a37cb38446aea41428f63c2b4768ac..5e3c526e01a94f2a1e7af57d22d83f155c766520 100644 (file)
 /* 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
 /* 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);
 {
   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;
   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. */
 
 /* 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;
                                      va_list vp)
 {
   SilcBuffer buffer;
+  bool dyn;
   int ret;
 
   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),
   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) {
 
   ret = silc_buffer_format_vp(buffer, vp);
   if (ret < 0) {
-    silc_buffer_free(buffer);
+    if (dyn)
+      silc_buffer_free(buffer);
     return NULL;
   }
 
     return NULL;
   }
 
index ac43b06a9de8fdadce3e93963ccc18e4ad4f818b..f8e9c3054d81c719098689202d70e649298b6a44 100644 (file)
@@ -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
 /* 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. */
 
 /* 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.
                                      va_list vp);
 
 /* Decodes the SFTP packet data `data' and return the SFTP packet type.
index 196b67681065b2aff3c94298fc935c2cf9a662e9..9b2e796d28c66b74d1cacbf90aac21c4750b1fce 100644 (file)
@@ -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;
   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_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;
   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);
 }
 
   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;
   
 {
   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);
   assert(packet->type == SILC_PACKET_FTP);
 
   silc_sftp_client_receive_process(client->sftp, sock, packet);
+
+  return TRUE;
 }
 
 SILC_TASK_CALLBACK(packet_process)
 }
 
 SILC_TASK_CALLBACK(packet_process)
@@ -112,7 +114,8 @@ SILC_TASK_CALLBACK(packet_process)
       exit(0);
     }
 
       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;
 
 
   gclient = client;
 
-  if (argc > 1 && !strcmp(argv[1], "-d"))
+  if (argc > 1 && !strcmp(argv[1], "-d")) {
     silc_debug = 1;
     silc_debug = 1;
+    silc_debug_hexdump = 1;
+    silc_log_set_debug_string("");
+  }
 
   client->schedule = silc_schedule_init(100);
   if (!client->schedule)
 
   client->schedule = silc_schedule_init(100);
   if (!client->schedule)
index e2aa1aa63980a84a384406b921ec6b0c2547465d..bc5ac02e19d122408e936a5876763ceaee14e797 100644 (file)
@@ -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;
   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_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;
   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);
 }
 
   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;
   
 {
   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);
   assert(packet->type == SILC_PACKET_FTP);
 
   silc_sftp_server_receive_process(server->sftp[sock->sock], sock, packet);
+
+  return TRUE;
 }
 
 SILC_TASK_CALLBACK(packet_process)
 }
 
 SILC_TASK_CALLBACK(packet_process)
@@ -104,7 +106,8 @@ SILC_TASK_CALLBACK(packet_process)
       return;
     }
 
       return;
     }
 
-    silc_packet_receive_process(sock, NULL, NULL, packet_parse, server);
+    silc_packet_receive_process(sock, FALSE, NULL, NULL, 0, packet_parse, 
+                               server);
   }
 }
 
   }
 }
 
index 9b35e922cc05328b5d4e6efbf7db455cd5586280..9d6f2e2aa3bf3c134fc16d5a3c8ae48a229bc2fd 100644 (file)
@@ -314,7 +314,7 @@ unsigned char *silc_buffer_push_tail(SilcBuffer sb, uint32 len)
 
 extern inline
 unsigned char *silc_buffer_put_head(SilcBuffer sb, 
 
 extern inline
 unsigned char *silc_buffer_put_head(SilcBuffer sb, 
-                                   unsigned char *data,
+                                   const unsigned char *data,
                                    uint32 len)
 {
 #ifdef SILC_DEBUG
                                    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, 
 
 extern inline
 unsigned char *silc_buffer_put(SilcBuffer sb, 
-                              unsigned char *data,
+                              const unsigned char *data,
                               uint32 len)
 {
 #ifdef SILC_DEBUG
                               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, 
 
 extern inline
 unsigned char *silc_buffer_put_tail(SilcBuffer sb, 
-                                   unsigned char *data,
+                                   const unsigned char *data,
                                    uint32 len)
 {
 #ifdef SILC_DEBUG
                                    uint32 len)
 {
 #ifdef SILC_DEBUG