Added silc_buffer_strformat function.
+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
#include "silcconfig.h"
#include "silcprotocol.h"
#include "silcsockconn.h"
+#include "silcvcard.h"
/* SILC core library includes */
#include "silcstatus.h"
silcutil.c \
silchashtable.c \
silcsockconn.c \
- silcprotocol.c
+ silcprotocol.c \
+ silcvcard.c
if SILC_DIST_TOOLKIT
include_HEADERS = \
silcfileutil.h \
silcutil.h \
silcstrutil.h \
+ silcvcard.h \
silctypes.h
endif
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;
+}
*
* 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, ...);
*
* 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 */