From 99e0d5ed5639b1e1a37b51f0bf8bbaf87d1f6a28 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 2 Jan 2006 19:18:53 +0000 Subject: [PATCH] silc_buffer_format reallocates automatically now. --- TODO | 23 +++++++- lib/silccore/silcargument.c | 5 +- lib/silccore/silcattrs.c | 4 +- lib/silccore/silcmessage.c | 31 +++++----- lib/silcmath/mp_tfm.c | 6 +- lib/silcskr/silcskr.c | 2 +- lib/silcutil/silcbuffer.h | 44 +++++++++----- lib/silcutil/silcbuffmt.c | 114 +++++++++++++++++++++--------------- lib/silcutil/silcbuffmt.h | 72 ++++++++++++++++------- lib/silcutil/silcstack.h | 6 +- 10 files changed, 197 insertions(+), 110 deletions(-) diff --git a/TODO b/TODO index b455481c..3ff20880 100644 --- 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. diff --git a/lib/silccore/silcargument.c b/lib/silccore/silcargument.c index a5737049..aa6083e3 100644 --- a/lib/silccore/silcargument.c +++ b/lib/silccore/silcargument.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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)); diff --git a/lib/silccore/silcattrs.c b/lib/silccore/silcattrs.c index 27f25f73..3dd0b79b 100644 --- a/lib/silccore/silcattrs.c +++ b/lib/silccore/silcattrs.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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), diff --git a/lib/silccore/silcmessage.c b/lib/silccore/silcmessage.c index 990050c6..67be2e14 100644 --- a/lib/silccore/silcmessage.c +++ b/lib/silccore/silcmessage.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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; diff --git a/lib/silcmath/mp_tfm.c b/lib/silcmath/mp_tfm.c index 10b4f9e8..b3b1e73b 100644 --- a/lib/silcmath/mp_tfm.c +++ b/lib/silcmath/mp_tfm.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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) diff --git a/lib/silcskr/silcskr.c b/lib/silcskr/silcskr.c index 8efc9ca7..f2317c9e 100644 --- a/lib/silcskr/silcskr.c +++ b/lib/silcskr/silcskr.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 diff --git a/lib/silcutil/silcbuffer.h b/lib/silcutil/silcbuffer.h index 9d350470..c2c60b29 100644 --- a/lib/silcutil/silcbuffer.h +++ b/lib/silcutil/silcbuffer.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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. * ***/ diff --git a/lib/silcutil/silcbuffmt.c b/lib/silcutil/silcbuffmt.c index fb251a8f..3adc6547 100644 --- a/lib/silcutil/silcbuffmt.c +++ b/lib/silcutil/silcbuffmt.c @@ -20,28 +20,30 @@ #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, ...) diff --git a/lib/silcutil/silcbuffmt.h b/lib/silcutil/silcbuffmt.h index 44b9215d..4c3436a5 100644 --- a/lib/silcutil/silcbuffmt.h +++ b/lib/silcutil/silcbuffmt.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 @@ -42,11 +42,16 @@ * 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), @@ -59,6 +64,48 @@ ***/ 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 diff --git a/lib/silcutil/silcstack.h b/lib/silcutil/silcstack.h index 5fa4e093..c8ce3be5 100644 --- a/lib/silcutil/silcstack.h +++ b/lib/silcutil/silcstack.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 * ***/ -- 2.24.0