From 6c9605462e4f9210558e97ed4929d8ab0d59f2d9 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 14 Oct 2002 14:11:52 +0000 Subject: [PATCH] Added implementation of VCard (RFC 2426). Added silc_buffer_strformat function. --- CHANGES | 10 ++++++++++ includes/silcincludes.h | 1 + lib/silcutil/Makefile.am | 4 +++- lib/silcutil/silcbuffmt.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/silcutil/silcbuffmt.h | 26 ++++++++++++++++++++++---- 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 76a8feab..ba624bb6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,13 @@ +Mon Oct 14 14:33:54 EEST 2002 Pekka Riikonen + + * 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 * Some strncat -> silc_strncat changes our the core and diff --git a/includes/silcincludes.h b/includes/silcincludes.h index aa53ee74..9933b084 100644 --- a/includes/silcincludes.h +++ b/includes/silcincludes.h @@ -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" diff --git a/lib/silcutil/Makefile.am b/lib/silcutil/Makefile.am index 93979c86..c9c6d702 100644 --- a/lib/silcutil/Makefile.am +++ b/lib/silcutil/Makefile.am @@ -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 diff --git a/lib/silcutil/silcbuffmt.c b/lib/silcutil/silcbuffmt.c index 577785a1..83d240ca 100644 --- a/lib/silcutil/silcbuffmt.c +++ b/lib/silcutil/silcbuffmt.c @@ -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; +} diff --git a/lib/silcutil/silcbuffmt.h b/lib/silcutil/silcbuffmt.h index 5401a217..c7621365 100644 --- a/lib/silcutil/silcbuffmt.h +++ b/lib/silcutil/silcbuffmt.h @@ -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 */ -- 2.24.0