silc_buffer_format reallocates automatically now.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 2 Jan 2006 19:18:53 +0000 (19:18 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 2 Jan 2006 19:18:53 +0000 (19:18 +0000)
TODO
lib/silccore/silcargument.c
lib/silccore/silcattrs.c
lib/silccore/silcmessage.c
lib/silcmath/mp_tfm.c
lib/silcskr/silcskr.c
lib/silcutil/silcbuffer.h
lib/silcutil/silcbuffmt.c
lib/silcutil/silcbuffmt.h
lib/silcutil/silcstack.h

diff --git a/TODO b/TODO
index b455481c91a058acc5dd0fe211f196e7b2116c8b..3ff20880c57b0777dd62f60a0ffb0ec45ded6404 100644 (file)
--- a/TODO
+++ b/TODO
@@ -88,10 +88,12 @@ lib/silcutil/silcbuffer.h   ****DONE****
    totally 8 bytes of memory per buffer.
 
 
-lib/silcutil/silcbuffmt.[ch]   ****PARTY DONE****
+lib/silcutil/silcbuffmt.[ch]   ****PARTLY DONE****
 ============================
 
- o SILC_STR_APPEND, _APPEND_TAIL.
+ o SilcStack aware silc_buffer_unformat
+
+ o silc_buffer_format reallocates automatically
 
  o SILC_STR_OFFSET
 
@@ -199,6 +201,8 @@ lib/silcasn1                        ****PARTLY DONE****
 
  o Some string encodings missing (copy/paste matter).
 
+ o Negative integer encoding
+
 
 lib/silcpkix
 ============
@@ -227,6 +231,10 @@ lib/silcutil/silcnet*, lib/silcutil/*/silc*net*            ****PARTLY DONE****
 lib/silcserver
 ==============
 
+ o (Re)write commands/command replys.
+
+ o (Re)write notify handling.
+
  o The SERVER_SIGNOFF notify handing is not optimal, because it'll
    cause sending of multiple SIGNOFF notify's instead of the one
    SERVER_SIGNOFF notify that the server received.  This should be
@@ -274,3 +282,14 @@ lib/silcserver
    key ends up being used.
 
  o The CMODE cipher & hmac change problem (#101).
+
+
+lib/silcclient
+==============
+
+ o Some form of rewrite to make it more efficient.
+
+ o Clear up interfaces.
+
+ o Remove silc_client_run and silc_client_run_one from calling SilcSchedule.
+   Leave the scheduling entirely to application.
index a57370495565523b7b787728f8a365b0c59b4f0a..aa6083e3f084321684890d96a091cb7a207bce24 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2005 Pekka Riikonen
+  Copyright (C) 2001 - 2006 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
@@ -162,7 +162,8 @@ SilcBuffer silc_argument_payload_encode_one(SilcBuffer args,
 
   len = 3 + (SilcUInt16)arg_len;
   buffer = silc_buffer_realloc(buffer,
-                              (buffer ? silc_buffer_truelen(buffer) + len : len));
+                              (buffer ? silc_buffer_truelen(buffer) +
+                               len : len));
   if (!buffer)
     return NULL;
   silc_buffer_pull(buffer, silc_buffer_len(buffer));
index 27f25f7373ebea728ba10e1c984ce7d5e9bca532..3dd0b79b9731ceeead70e0d3f34bf804fb3e713b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2002 - 2005 Pekka Riikonen
+  Copyright (C) 2002 - 2006 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
@@ -76,6 +76,8 @@ silc_attribute_payload_encode_int(SilcAttribute attribute,
        len = strlen(service->address);
        len2 = strlen(service->signon);
        tmpbuf = silc_buffer_alloc_size(13 + len + len2);
+       if (!tmpbuf)
+         return NULL;
        silc_buffer_format(tmpbuf,
                           SILC_STR_UI_INT(service->port),
                           SILC_STR_UI_SHORT(len),
index 990050c6d7327c223271322f10f60b88e3789f7c..67be2e1476cc650c31a864085f36794d85bbcd58 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2006 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
@@ -335,10 +335,12 @@ SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
 
   /* Sign the message if wanted */
   if (flags & SILC_MESSAGE_FLAG_SIGNED && private_key && hash) {
-    sig = silc_message_signed_payload_encode(buffer->data, silc_buffer_len(buffer),
+    sig = silc_message_signed_payload_encode(buffer->data,
+                                            silc_buffer_len(buffer),
                                             public_key, private_key, hash);
     if (sig) {
-      buffer = silc_buffer_realloc(buffer, silc_buffer_truelen(buffer) + silc_buffer_len(sig));
+      buffer = silc_buffer_realloc(buffer, silc_buffer_truelen(buffer) +
+                                  silc_buffer_len(sig));
       if (buffer) {
        silc_buffer_pull(buffer, 6 + data_len + pad_len);
        silc_buffer_pull_tail(buffer, silc_buffer_len(sig));
@@ -349,14 +351,14 @@ SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
   }
 
   /* Put IV */
-  silc_buffer_pull(buffer, 6 + data_len + pad_len + (sig ? silc_buffer_len(sig) : 0));
+  silc_buffer_pull(buffer, 6 + data_len + pad_len +
+                  (sig ? silc_buffer_len(sig) : 0));
   silc_buffer_pull_tail(buffer, iv_len);
   silc_buffer_format(buffer,
                     SILC_STR_UI_XNSTRING(iv, iv_len),
                     SILC_STR_END);
-  silc_buffer_push(buffer, 6 + data_len + pad_len + (sig ? silc_buffer_len(sig) : 0));
-
-  SILC_LOG_HEXDUMP(("foo"), buffer->data, silc_buffer_len(buffer));
+  silc_buffer_push(buffer, 6 + data_len + pad_len +
+                  (sig ? silc_buffer_len(sig) : 0));
 
   /* Now encrypt the Message Payload and compute MAC */
   if (cipher) {
@@ -370,7 +372,8 @@ SilcBuffer silc_message_payload_encode(SilcMessageFlags flags,
       return NULL;
     }
   }
-  silc_buffer_pull_tail(buffer, silc_buffer_truelen(buffer) - silc_buffer_len(buffer));
+  silc_buffer_pull_tail(buffer, silc_buffer_truelen(buffer) -
+                       silc_buffer_len(buffer));
 
   silc_buffer_free(sig);
   return buffer;
@@ -640,25 +643,25 @@ int silc_message_signed_verify(SilcMessageSignedPayload sig,
 {
   int ret = SILC_AUTH_FAILED;
   SilcBuffer sign;
-  SilcBuffer tmp;
+  SilcBufferStruct tmp;
 
   if (!sig || !remote_public_key || !hash)
     return ret;
 
   /* Generate the signature verification data, the Message Payload */
-  tmp = silc_buffer_alloc_size(6 + message->data_len + message->pad_len);
-  silc_buffer_format(tmp,
+  memset(&tmp, 0, sizeof(tmp));
+  silc_buffer_format(&tmp,
                     SILC_STR_UI_SHORT(message->flags),
                     SILC_STR_UI_SHORT(message->data_len),
                     SILC_STR_UI_XNSTRING(message->data, message->data_len),
                     SILC_STR_UI_SHORT(message->pad_len),
                     SILC_STR_UI_XNSTRING(message->pad, message->pad_len),
                     SILC_STR_END);
-  sign = silc_message_signed_encode_data(tmp->data, silc_buffer_len(tmp),
+  sign = silc_message_signed_encode_data(tmp.data, silc_buffer_len(&tmp),
                                         sig->pk_data, sig->pk_len,
                                         sig->pk_type);
-  silc_buffer_clear(tmp);
-  silc_buffer_free(tmp);
+  silc_buffer_clear(&tmp);
+  silc_free(silc_buffer_steal(&tmp, NULL));
 
   if (!sign)
     return ret;
index 10b4f9e8f567065ca768048f0b8b54493feb81a9..b3b1e73beb89bc8bf6cb22b43bcded5575019ef1 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005 - 2006 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
@@ -67,8 +67,8 @@ void silc_mp_set_str(SilcMPInt *dst, const char *str, int base)
 
 SilcUInt32 silc_mp_get_ui(SilcMPInt *mp)
 {
-  SILC_NOT_IMPLEMENTED("silc_mp_get_ui");
-  assert(FALSE);
+  fp_int *tmp = mp;
+  return tmp->used > 0 ? tmp->dp[0] : 0;
 }
 
 char *silc_mp_get_str(char *str, SilcMPInt *mp, int base)
index 8efc9ca71845b066985076371bd3b2a72348c397..f2317c9e13d34db64ed88f0d95be13b05763b8e9 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2005 Pekka Riikonen
+  Copyright (C) 2005 - 2006 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
index 9d35047082e03741eb6d0816f8a960f650b7c49f..c2c60b29e51f514e022a18de4e6daaa652288e5e 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1998 - 2005 Pekka Riikonen
+  Copyright (C) 1998 - 2006 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
@@ -202,15 +202,17 @@ SilcBuffer silc_buffer_alloc(SilcUInt32 len)
   if (!sb)
     return NULL;
 
-  /* Allocate the actual data area */
-  sb->head = (unsigned char *)silc_calloc(len, sizeof(*sb->head));
-  if (!sb->head)
-    return NULL;
+  if (len) {
+    /* Allocate the actual data area */
+    sb->head = (unsigned char *)silc_calloc(len, sizeof(*sb->head));
+    if (!sb->head)
+      return NULL;
 
-  /* Set pointers to the new buffer */
-  sb->data = sb->head;
-  sb->tail = sb->head;
-  sb->end = sb->head + len;
+    /* Set pointers to the new buffer */
+    sb->data = sb->head;
+    sb->tail = sb->head;
+    sb->end = sb->head + len;
+  }
 
   return sb;
 }
@@ -800,7 +802,8 @@ SilcBuffer silc_buffer_realloc_size(SilcBuffer sb, SilcUInt32 newsize)
  *
  *    Allocates new SilcBuffer and returns it.
  *
- *    This routine use SilcStack are memory source.
+ *    This routine use SilcStack are memory source.  If `stack' is NULL
+ *    reverts back to normal allocating routine.
  *
  ***/
 
@@ -809,6 +812,9 @@ SilcBuffer silc_buffer_salloc(SilcStack stack, SilcUInt32 len)
 {
   SilcBuffer sb;
 
+  if (!stack)
+    return silc_buffer_alloc(len);
+
   /* Allocate new SilcBuffer */
   sb = (SilcBuffer)silc_scalloc(stack, 1, sizeof(*sb));
   if (!sb)
@@ -840,7 +846,8 @@ SilcBuffer silc_buffer_salloc(SilcStack stack, SilcUInt32 len)
  *    `len' bytes so that the buffer is ready to use without calling the
  *    silc_buffer_pull_tail.
  *
- *    This routine use SilcStack are memory source.
+ *    This routine use SilcStack are memory source.  If `stack' is NULL
+ *    reverts back to normal allocating routine.
  *
  ***/
 
@@ -868,7 +875,8 @@ SilcBuffer silc_buffer_salloc_size(SilcStack stack, SilcUInt32 len)
  *    is exact clone of the old one except that there is now more space
  *    at the end of buffer.
  *
- *    This routine use SilcStack are memory source.
+ *    This routine use SilcStack are memory source.  If `stack' is NULL
+ *    reverts back to normal allocating routine.
  *
  ***/
 
@@ -879,6 +887,9 @@ SilcBuffer silc_buffer_srealloc(SilcStack stack,
   SilcUInt32 hlen, dlen;
   unsigned char *h;
 
+  if (!stack)
+    return silc_buffer_realloc(sb, newsize);
+
   if (!sb)
     return silc_buffer_salloc(stack, newsize);
 
@@ -920,7 +931,8 @@ SilcBuffer silc_buffer_srealloc(SilcStack stack,
  *    automatically so that the buffer is ready to use without calling the
  *    silc_buffer_pull_tail.
  *
- *    This routine use SilcStack are memory source.
+ *    This routine use SilcStack are memory source.  If `stack' is NULL
+ *    reverts back to normal allocating routine.
  *
  ***/
 
@@ -948,7 +960,8 @@ SilcBuffer silc_buffer_srealloc_size(SilcStack stack,
  *    currently valid data area, nothing more. Use silc_buffer_clone to
  *    copy entire buffer.
  *
- *    This routine use SilcStack are memory source.
+ *    This routine use SilcStack are memory source.  If `stack' is NULL
+ *    reverts back to normal allocating routine.
  *
  ***/
 
@@ -978,7 +991,8 @@ SilcBuffer silc_buffer_scopy(SilcStack stack, SilcBuffer sb)
  *    everything from the source buffer. The result is exact clone of
  *    the original buffer.
  *
- *    This routine use SilcStack are memory source.
+ *    This routine use SilcStack are memory source.  If `stack' is NULL
+ *    reverts back to normal allocating routine.
  *
  ***/
 
index fb251a8f4e774212541caf594bf02252688682fd..3adc6547b32e0ae0447aec8be272501bfcd54fca 100644 (file)
 
 #include "silc.h"
 
-/* Macros to check whether there is enough free space to add the
-   required amount of data. For unformatting this means that there must
-   be the data that is to be extracted. */
-#define FORMAT_HAS_SPACE(__x__, __req__)       \
-  do {                                         \
-    if (__req__ > silc_buffer_len((__x__)))    \
-      goto fail;                               \
-  } while(0)
+/************************** Types and definitions ***************************/
+
+/* Check that buffer has enough room to format data in it, if not
+   allocate more. */
+#define FORMAT_HAS_SPACE(__s__, __x__, __req__)                                    \
+do {                                                                       \
+  if (__req__ > silc_buffer_len((__x__)))                                  \
+    if (!silc_buffer_srealloc_size((__s__), (__x__),                       \
+                                  silc_buffer_truelen((__x__)) + __req__)) \
+      goto fail;                                                           \
+  flen += __req__;                                                         \
+} while(0)
+
+/* Check that there is data to be unformatted */
 #define UNFORMAT_HAS_SPACE(__x__, __req__)     \
-  do {                                         \
-    if (__req__ > silc_buffer_len((__x__)))    \
-      goto fail;                               \
-    if ((__req__ + 1) <= 0)                    \
-      goto fail;                               \
-  } while(0)
-
-/* Formats the arguments sent and puts them into the buffer sent as
-   argument. The buffer must be initialized beforehand and it must have
-   enough free space to include the formatted data. If this function
-   fails caller should not trust the buffer anymore and should free it.
-   This function is used, for example, to create packets to send over
-   network. */
+do {                                           \
+  if (__req__ > silc_buffer_len((__x__)))      \
+    goto fail;                                 \
+  if ((__req__ + 1) <= 0)                      \
+    goto fail;                                 \
+} while(0)
+
+
+/******************************* Formatting *********************************/
 
 int silc_buffer_format(SilcBuffer dst, ...)
 {
@@ -49,17 +51,33 @@ int silc_buffer_format(SilcBuffer dst, ...)
   int ret;
 
   va_start(ap, dst);
-  ret = silc_buffer_format_vp(dst, ap);
+  ret = silc_buffer_sformat_vp(NULL, dst, ap);
   va_end(ap);
 
   return ret;
 }
 
 int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
+{
+  return silc_buffer_sformat_vp(NULL, dst, ap);
+}
+
+int silc_buffer_sformat(SilcStack stack, SilcBuffer dst, ...)
+{
+  va_list ap;
+  int ret;
+
+  va_start(ap, dst);
+  ret = silc_buffer_sformat_vp(stack, dst, ap);
+  va_end(ap);
+
+  return ret;
+}
+
+int silc_buffer_sformat_vp(SilcStack stack, SilcBuffer dst, va_list ap)
 {
   SilcBufferParamType fmt;
-  unsigned char *start_ptr = dst->data;
-  int len;
+  int flen = 0;
 
   /* Parse the arguments by formatting type. */
   while (1) {
@@ -72,17 +90,20 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
        if (!offst)
          break;
        if (offst > 1) {
-         FORMAT_HAS_SPACE(dst, offst);
+         if (offst > silc_buffer_len(dst))
+           goto fail;
          silc_buffer_pull(dst, offst);
+         len += offst;
        } else {
          silc_buffer_push(dst, -(offst));
+         len += -(offst);
        }
        break;
       }
     case SILC_BUFFER_PARAM_SI8_CHAR:
       {
        char x = (char)va_arg(ap, int);
-       FORMAT_HAS_SPACE(dst, 1);
+       FORMAT_HAS_SPACE(stack, dst, 1);
        silc_buffer_put(dst, &x, 1);
        silc_buffer_pull(dst, 1);
        break;
@@ -90,7 +111,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
     case SILC_BUFFER_PARAM_UI8_CHAR:
       {
        unsigned char x = (unsigned char)va_arg(ap, int);
-       FORMAT_HAS_SPACE(dst, 1);
+       FORMAT_HAS_SPACE(stack, dst, 1);
        silc_buffer_put(dst, &x, 1);
        silc_buffer_pull(dst, 1);
        break;
@@ -99,7 +120,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[2];
        SilcInt16 x = (SilcInt16)va_arg(ap, int);
-       FORMAT_HAS_SPACE(dst, 2);
+       FORMAT_HAS_SPACE(stack, dst, 2);
        SILC_PUT16_MSB(x, xf);
        silc_buffer_put(dst, xf, 2);
        silc_buffer_pull(dst, 2);
@@ -109,7 +130,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[2];
        SilcUInt16 x = (SilcUInt16)va_arg(ap, int);
-       FORMAT_HAS_SPACE(dst, 2);
+       FORMAT_HAS_SPACE(stack, dst, 2);
        SILC_PUT16_MSB(x, xf);
        silc_buffer_put(dst, xf, 2);
        silc_buffer_pull(dst, 2);
@@ -119,7 +140,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[4];
        SilcInt32 x = va_arg(ap, SilcInt32);
-       FORMAT_HAS_SPACE(dst, 4);
+       FORMAT_HAS_SPACE(stack, dst, 4);
        SILC_PUT32_MSB(x, xf);
        silc_buffer_put(dst, xf, 4);
        silc_buffer_pull(dst, 4);
@@ -129,7 +150,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[4];
        SilcUInt32 x = va_arg(ap, SilcUInt32);
-       FORMAT_HAS_SPACE(dst, 4);
+       FORMAT_HAS_SPACE(stack, dst, 4);
        SILC_PUT32_MSB(x, xf);
        silc_buffer_put(dst, xf, 4);
        silc_buffer_pull(dst, 4);
@@ -139,7 +160,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[8];
        SilcInt64 x = va_arg(ap, SilcInt64);
-       FORMAT_HAS_SPACE(dst, sizeof(SilcInt64));
+       FORMAT_HAS_SPACE(stack, dst, sizeof(SilcInt64));
        SILC_PUT64_MSB(x, xf);
        silc_buffer_put(dst, xf, sizeof(SilcInt64));
        silc_buffer_pull(dst, sizeof(SilcInt64));
@@ -149,7 +170,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char xf[8];
        SilcUInt64 x = va_arg(ap, SilcUInt64);
-       FORMAT_HAS_SPACE(dst, sizeof(SilcUInt64));
+       FORMAT_HAS_SPACE(stack, dst, sizeof(SilcUInt64));
        SILC_PUT64_MSB(x, xf);
        silc_buffer_put(dst, xf, sizeof(SilcUInt64));
        silc_buffer_pull(dst, sizeof(SilcUInt64));
@@ -164,7 +185,7 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
       {
        unsigned char *x = va_arg(ap, unsigned char *);
        SilcUInt32 tmp_len = strlen(x);
-       FORMAT_HAS_SPACE(dst, tmp_len);
+       FORMAT_HAS_SPACE(stack, dst, tmp_len);
        silc_buffer_put(dst, x, tmp_len);
        silc_buffer_pull(dst, tmp_len);
        break;
@@ -179,11 +200,11 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
     case SILC_BUFFER_PARAM_UI_XNSTRING_ALLOC:
       {
        unsigned char *x = va_arg(ap, unsigned char *);
-       SilcUInt32 len = va_arg(ap, SilcUInt32);
+       SilcUInt32 tmp_len = va_arg(ap, SilcUInt32);
        if (x && len) {
-         FORMAT_HAS_SPACE(dst, len);
-         silc_buffer_put(dst, x, len);
-         silc_buffer_pull(dst, len);
+         FORMAT_HAS_SPACE(stack, dst, tmp_len);
+         silc_buffer_put(dst, x, tmp_len);
+         silc_buffer_pull(dst, tmp_len);
        }
        break;
       }
@@ -200,21 +221,17 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap)
 
  fail:
   SILC_LOG_DEBUG(("Error occured while formatting data"));
-  len = dst->data - start_ptr;
-  silc_buffer_push(dst, len);
+  silc_buffer_push(dst, flen);
   return -1;
 
  ok:
   /* Push the buffer back to where it belongs. */
-  len = dst->data - start_ptr;
-  silc_buffer_push(dst, len);
-  return len;
+  silc_buffer_push(dst, flen);
+  return flen;
 }
 
-/* Unformats the buffer sent as argument. The unformatted data is returned
-   to the variable argument list of pointers. The buffer must point to the
-   start of the data area to be unformatted. Buffer maybe be safely free'd
-   after this returns succesfully. */
+
+/****************************** Unformatting ********************************/
 
 int silc_buffer_unformat(SilcBuffer src, ...)
 {
@@ -538,6 +555,9 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
   return len;
 }
 
+
+/**************************** Utility functions *****************************/
+
 /* Formats strings into a buffer */
 
 int silc_buffer_strformat(SilcBuffer dst, ...)
index 44b9215da416002a199d2b3b84c030cf2103f8a8..4c3436a52b9095f92fe9cbe621807ee74bf2d195 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2006 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
  * DESCRIPTION
  *
  *    Formats a buffer from a variable argument list.  Returns -1 on error
- *    and the length of the formatted buffer otherwise.
+ *    and the length of the formatted buffer otherwise.  The buffer is
+ *    enlarged automatically during formatting, if it doesn't already have
+ *    enough space.
  *
  * EXAMPLE
  *
- *    ret = silc_buffer_format(buffer,
+ *    SilcBufferStruct buffer;
+ *
+ *    memset(&buffer, 0, sizeof(buffer));
+ *    ret = silc_buffer_format(&buffer,
  *                             SILC_STR_INT(intval),
  *                             SILC_STR_CHAR(charval),
  *                             SILC_STR_INT(intval),
  ***/
 int silc_buffer_format(SilcBuffer dst, ...);
 
+/****f* silcutil/SilcBufferFormatAPI/silc_buffer_sformat
+ *
+ * SYNOPSIS
+ *
+ *    int silc_buffer_sformat(SilcStack stack, SilcBuffer dst, ...);
+ *
+ * DESCRIPTION
+ *
+ *    Same as silc_buffer_format but uses `stack' to allocate the memory.
+ *    if `stack' is NULL reverts back to silc_buffer_format call.
+ *
+ ***/
+int silc_buffer_sformat(SilcStack stack, SilcBuffer dst, ...);
+
+/****f* silcutil/SilcBufferFormatAPI/silc_buffer_format_vp
+ *
+ * SYNOPSIS
+ *
+ *    int silc_buffer_format_vp(SilcBuffer dst, va_list vp);
+ *
+ * DESCRIPTION
+ *
+ *    Formats a buffer from a variable argument list indicated by the `ap'.
+ *    Returns -1 on error and the length of the formatted buffer otherwise.
+ *
+ ***/
+int silc_buffer_format_vp(SilcBuffer dst, va_list ap);
+
+/****f* silcutil/SilcBufferFormatAPI/silc_buffer_format_vp
+ *
+ * SYNOPSIS
+ *
+ *    int silc_buffer_format_vp(SilcBuffer dst, va_list vp);
+ *
+ * DESCRIPTION
+ *
+ *    Same as silc_buffer_format_vp but uses `stack' to allocate the memory.
+ *    if `stack' is NULL reverts back to silc_buffer_format_vp call.
+ *
+ ***/
+int silc_buffer_sformat_vp(SilcStack stack, SilcBuffer dst, va_list ap);
+
 /****f* silcutil/SilcBufferFormatAPI/silc_buffer_unformat
  *
  * SYNOPSIS
@@ -84,20 +131,6 @@ int silc_buffer_format(SilcBuffer dst, ...);
  ***/
 int silc_buffer_unformat(SilcBuffer src, ...);
 
-/****f* silcutil/SilcBufferFormatAPI/silc_buffer_format_vp
- *
- * SYNOPSIS
- *
- *    int silc_buffer_format_vp(SilcBuffer dst, va_list vp);
- *
- * DESCRIPTION
- *
- *    Formats a buffer from a variable argument list indicated by the `ap'.
- *    Returns -1 on error and the length of the formatted buffer otherwise.
- *
- ***/
-int silc_buffer_format_vp(SilcBuffer dst, va_list ap);
-
 /****f* silcutil/SilcBufferFormatAPI/silc_buffer_unformat_vp
  *
  * SYNOPSIS
@@ -136,8 +169,6 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap);
  ***/
 int silc_buffer_strformat(SilcBuffer dst, ...);
 
-/* SilcStack aware versions */
-
 /****f* silcutil/SilcBufferFormatAPI/silc_buffer_sstrformat
  *
  * SYNOPSIS
@@ -446,9 +477,6 @@ typedef enum {
  ***/
 #define SILC_STR_OFFSET(x) SILC_BUFFER_PARAM_OFFSET, (x)
 
-#define SILC_STR_APPEND
-#define SILC_STR_APPEND_TAIL
-
 /****d* silcutil/SilcBufferFormatAPI/SILC_STR_END
  *
  * NAME
index 5fa4e0933974ee796a17c76bd4f652dd05f52dde..c8ce3be50adadecae5e67bd4fdce57fb88cc793b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 - 2005 Pekka Riikonen
+  Copyright (C) 2003 - 2006 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
@@ -43,8 +43,8 @@
  * silc_smalloc, silc_smalloc_ua, silc_scalloc, silc_srealloc, silc_smemdup,
  * silc_sstrdup, silc_buffer_salloc, silc_buffer_salloc_size,
  * silc_buffer_srealloc, silc_buffer_srealloc_size, silc_buffer_scopy,
- * silc_buffer_sclone, silc_buffer_sunformat, silc_buffer_sstrformat,
- * silc_mp_sinit
+ * silc_buffer_sclone, silc_buffer_sformat, silc_buffer_sformat_vp,
+ * silc_buffer_sstrformat, silc_mp_sinit
  *
  ***/