Added silc_packet_send_va[_ext].
authorPekka Riikonen <priikone@silcnet.org>
Mon, 20 Nov 2006 14:50:04 +0000 (14:50 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 20 Nov 2006 14:50:04 +0000 (14:50 +0000)
lib/silccore/silcpacket.c
lib/silccore/silcpacket.h

index 24b63134ef60c83d8cb8cd0e7a520c52ce4eb006..2a2b9af18345a2079f7403b83c25dc48cd5c1b05 100644 (file)
@@ -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 *****************************/
 
index 67cb82488224601602ef22a904584dc17d8ca393..d926bcb3ce5f99097c92baae40efb94139842c7d 100644 (file)
@@ -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