Added implementation of VCard (RFC 2426).
authorPekka Riikonen <priikone@silcnet.org>
Mon, 14 Oct 2002 14:11:52 +0000 (14:11 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 14 Oct 2002 14:11:52 +0000 (14:11 +0000)
Added silc_buffer_strformat function.

CHANGES
includes/silcincludes.h
lib/silcutil/Makefile.am
lib/silcutil/silcbuffmt.c
lib/silcutil/silcbuffmt.h

diff --git a/CHANGES b/CHANGES
index 76a8feabb88e5975f39cf4196d37591b28f3c23f..ba624bb6cca99af9a7f4204d80f378b171a756cf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,13 @@
+Mon Oct 14 14:33:54 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added silc_buffer_strformat which can be used to format
+         strings into a buffer which size is automatically increased.
+         Affected file lib/silcutil/silcbuffmt.[ch].
+
+       * Added implementation of VCard (RFC 2426) which can be used
+         as part of Requested Attributes in WHOIS command.  Affected
+         file lib/silcutil/silcvcard.[ch].
+
 Fri Oct 11 23:52:17 EEST 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Some strncat -> silc_strncat changes our the core and
index aa53ee7423ea225264f0e0d890654c29cec91219..9933b084e09130f0360ab8f8569fd77193452b60 100644 (file)
@@ -251,6 +251,7 @@ extern "C" {
 #include "silcconfig.h"
 #include "silcprotocol.h"
 #include "silcsockconn.h"
+#include "silcvcard.h"
 
 /* SILC core library includes */
 #include "silcstatus.h"
index 93979c86d113930d90d8883165d79237eef299f8..c9c6d702c4d88419ab8938bec90f4a3e5163cbc1 100644 (file)
@@ -58,7 +58,8 @@ libsilcutil_a_SOURCES = \
        silcutil.c \
        silchashtable.c \
        silcsockconn.c  \
-       silcprotocol.c
+       silcprotocol.c  \
+       silcvcard.c
 
 if SILC_DIST_TOOLKIT
 include_HEADERS =      \
@@ -80,6 +81,7 @@ include_HEADERS =     \
        silcfileutil.h  \
        silcutil.h      \
        silcstrutil.h   \
+       silcvcard.h     \
        silctypes.h
 endif
 
index 577785a165fa06a8611dab6450ca601dd28370cc..83d240ca32d5d6882dffb66826b6066c0e106407 100644 (file)
@@ -499,3 +499,41 @@ int silc_buffer_unformat_vp(SilcBuffer src, va_list ap)
   silc_buffer_push(src, len);
   return len;
 }
+
+/* Formats strings into a buffer */
+
+int silc_buffer_strformat(SilcBuffer dst, ...)
+{
+  int len = dst->truelen;
+  va_list va;
+
+  va_start(va, dst);
+
+  /* Parse the arguments by formatting type. */
+  while(1) {
+    char *string = va_arg(va, char *);
+
+    if (!string)
+      continue;
+    if (string == (char *)SILC_BUFFER_PARAM_END)
+      goto ok;
+
+    dst->head = silc_realloc(dst->head, sizeof(*dst->head) *
+                            (strlen(string) + len));
+    memcpy(dst->head + len, string, strlen(string));
+    len += strlen(string);
+  }
+
+  SILC_LOG_DEBUG(("Error occured while formatting buffer"));
+  va_end(va);
+  return -1;
+
+ ok:
+  dst->end = dst->head + len;
+  dst->tail = dst->data = dst->end;
+  dst->len = 0;
+  dst->truelen = len;
+
+  va_end(va);
+  return len;
+}
index 5401a217170a2e9ce5236fec0bb2da3a61923f10..c76213657d202345933e5f3f3c74e4368fbcaf1d 100644 (file)
@@ -249,8 +249,8 @@ int silc_buffer_format(SilcBuffer dst, ...);
  *
  * DESCRIPTION
  *
- *    Formats a buffer from a variable argument list.  Returns -1 on error
- *    and the length of the formatted buffer otherwise.
+ *    Unformats a buffer from a variable argument list.  Returns -1 on error
+ *    and the length of the unformatted buffer otherwise.
  *
  ***/
 int silc_buffer_unformat(SilcBuffer src, ...);
@@ -277,10 +277,28 @@ int silc_buffer_format_vp(SilcBuffer dst, va_list ap);
  *
  * 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.
+ *    Unformats a buffer from a variable argument list indicated by the `ap'.
+ *    Returns -1 on error and the length of the unformatted buffer otherwise.
  *
  ***/
 int silc_buffer_unformat_vp(SilcBuffer src, va_list ap);
 
+/****f* silcutil/SilcBufferFormatAPI/silc_buffer_strformat
+ *
+ * SYNOPSIS
+ *
+ *   int silc_buffer_strformat(SilcBuffer dst, ...);
+ *
+ * DESCRIPTION
+ *
+ *   Formats a buffer from variable argument list of strings.  Eachs
+ *   string must be NULL-terminated and the variable argument list must
+ *   be end with SILC_STR_END argument.  This allows that a string in
+ *   the list can be NULL, in which case it is skipped.  This automatically
+ *   allocates the space for the buffer data but `dst' must be already
+ *   allocated by the caller.
+ *
+ ***/
+int silc_buffer_strformat(SilcBuffer dst, ...);
+
 #endif /* !SILCBUFFMT_H */