From: Pekka Riikonen Date: Mon, 20 Nov 2006 14:50:04 +0000 (+0000) Subject: Added silc_packet_send_va[_ext]. X-Git-Tag: silc.client.1.1.beta1~185 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=bdf4e2fbdc2a9b769c524ee7d63a490035c93e06 Added silc_packet_send_va[_ext]. --- diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 24b63134..2a2b9af1 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -1108,6 +1108,61 @@ SilcBool silc_packet_send_ext(SilcPacketStream stream, hmac ? hmac : stream->send_hmac[0]); } +/* Sends packet after formatting the arguments to buffer */ + +SilcBool silc_packet_send_va(SilcPacketStream stream, + SilcPacketType type, SilcPacketFlags flags, ...) +{ + SilcBufferStruct buf; + SilcBool ret; + va_list va; + + va_start(va, flags); + + memset(&buf, 0, sizeof(buf)); + if (silc_buffer_format_vp(&buf, va) < 0) { + va_end(va); + return FALSE; + } + + ret = silc_packet_send(stream, type, flags, silc_buffer_data(&buf), + silc_buffer_len(&buf)); + + silc_buffer_purge(&buf); + va_end(va); + + return ret; +} + +/* Sends packet after formatting the arguments to buffer, extended routine */ + +SilcBool silc_packet_send_va_ext(SilcPacketStream stream, + SilcPacketType type, SilcPacketFlags flags, + SilcIdType src_id_type, void *src_id, + SilcIdType dst_id_type, void *dst_id, + SilcCipher cipher, SilcHmac hmac, ...) +{ + SilcBufferStruct buf; + SilcBool ret; + va_list va; + + va_start(va, hmac); + + memset(&buf, 0, sizeof(buf)); + if (silc_buffer_format_vp(&buf, va) < 0) { + va_end(va); + return FALSE; + } + + ret = silc_packet_send_ext(stream, type, flags, src_id_type, src_id, + dst_id_type, dst_id, silc_buffer_data(&buf), + silc_buffer_len(&buf), cipher, hmac); + + silc_buffer_purge(&buf); + va_end(va); + + return TRUE; +} /***************************** Packet Receiving *****************************/ diff --git a/lib/silccore/silcpacket.h b/lib/silccore/silcpacket.h index 67cb8248..d926bcb3 100644 --- a/lib/silccore/silcpacket.h +++ b/lib/silccore/silcpacket.h @@ -160,6 +160,9 @@ typedef struct SilcPacketStreamStruct *SilcPacketStream; * IDs are available. The application must free the packet with the * silc_packet_free function if it takes it in for processing. * + * The `buffer' field contains the parsed packet payload and the start + * of the data area will point to the start of the packet payload. + * * The list pointer `next' can be used by the application to put the * packet context in a list during processing, if needed. * @@ -799,6 +802,61 @@ SilcBool silc_packet_send_ext(SilcPacketStream stream, const unsigned char *data, SilcUInt32 data_len, SilcCipher cipher, SilcHmac hmac); +/****f* silccore/SilcPacketAPI/silc_packet_send_va + * + * SYNOPSIS + * + * SilcBool silc_packet_send_va(SilcPacketStream stream, + * SilcPacketType type, + * SilcPacketFlags flags, ...); + * + * DESCRIPTION + * + * Same as silc_packet_send but takes the data in as variable argument + * formatted buffer (see silcbuffmt.h). The arguments must be ended + * with SILC_STR_END. Returns FALSE if packet could not be sent or + * the buffer could not be formatted. + * + * EXAMPLE + * + * // Send NEW_CLIENT packet + * silc_packet_send_va(stream, SILC_PACKET_NEW_CLIENT, 0, + * SILC_STR_UI_SHORT(username_len), + * SILC_STR_DATA(username, username_len), + * SILC_STR_UI_SHORT(realname_len), + * SILC_STR_DATA(realname, realname_len), + * SILC_STR_END); + * + ***/ +SilcBool silc_packet_send_va(SilcPacketStream stream, + SilcPacketType type, SilcPacketFlags flags, ...); + +/****f* silccore/SilcPacketAPI/silc_packet_send_va_ext + * + * SYNOPSIS + * + * SilcBool + * silc_packet_send_va_ext(SilcPacketStream stream, + * SilcPacketType type, SilcPacketFlags flags, + * SilcIdType src_id_type, void *srd_id, + * SilcIdType dst_id_type, void *dst_id, + * SilcCipher cipher, SilcHmac hmac, ...); + * + * DESCRIPTION + * + * Same as silc_packet_send_va but with this function different sending + * parameters can be sent as argument. This function can be used to + * set specific IDs, cipher and HMAC to be used in packet sending, + * instead of the ones saved in the `stream'. If any of the extra + * pointers are NULL, default values set to the stream will apply. + * + ***/ +SilcBool silc_packet_send_va_ext(SilcPacketStream stream, + SilcPacketType type, SilcPacketFlags flags, + SilcIdType src_id_type, void *src_id, + SilcIdType dst_id_type, void *dst_id, + SilcCipher cipher, SilcHmac hmac, ...); + /****f* silccore/SilcPacketAPI/silc_packet_wait * * SYNOPSIS