+/****f* silccore/SilcPacketAPI/silc_packet_send
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_packet_send(SilcPacketStream stream,
+ * SilcPacketType type, SilcPacketFlags flags,
+ * const unsigned char *data,
+ * SilcUInt32 data_len);
+ *
+ * DESCRIPTION
+ *
+ * Send `data' of length of `data_len' to the packet stream indicated by
+ * `stream'. If ciphers and HMACs were set using silc_packet_set_keys
+ * the packet will be encrypted and MAC will be computed for it. If
+ * silc_packet_set_ids was used to set source and destination ID for the
+ * packet stream those IDs are used in the packet. If IDs have not been
+ * set and they need to be provided then silc_packet_send_ext function
+ * should be used. Otherwise, the packet will not have IDs set at all.
+ * Returns FALSE if packet could not be sent.
+ *
+ ***/
+SilcBool silc_packet_send(SilcPacketStream stream,
+ SilcPacketType type, SilcPacketFlags flags,
+ const unsigned char *data, SilcUInt32 data_len);
+
+/****f* silccore/SilcPacketAPI/silc_packet_send_ext
+ *
+ * SYNOPSIS
+ *
+ * SilcBool
+ * silc_packet_send_ext(SilcPacketStream stream,
+ * SilcPacketType type, SilcPacketFlags flags,
+ * SilcIdType src_id_type, void *srd_id,
+ * SilcIdType dst_id_type, void *dst_id,
+ * const unsigned char *data, SilcUInt32 data_len,
+ * SilcCipher cipher, SilcHmac hmac);
+ *
+ * DESCRIPTION
+ *
+ * Same as silc_packet_send 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_ext(SilcPacketStream stream,
+ SilcPacketType type, SilcPacketFlags flags,
+ SilcIdType src_id_type, void *src_id,
+ SilcIdType dst_id_type, void *dst_id,
+ 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_init
+ *
+ * SYNOPSIS
+ *
+ * void *silc_packet_wait_init(SilcPacketStream stream,
+ * const SilcID *source_id, ...);
+ *
+ * DESCRIPTION
+ *
+ * Initializes a packet waiter for the packet stream `stream' and
+ * for the variable argument list of packet types. The function
+ * silc_packet_wait can be used to block the thread until a packet
+ * has been received.
+ *
+ * This function is used to initialize the waiting and to give the list
+ * of packet types that caller wish to receive. The variable argument
+ * list must end with -1. To receive all packets use SILC_PACKET_ANY.
+ * If the `source_id' is non-NULL then only packets of the specified
+ * type from the specified `source_id' are received. If it is NULL
+ * then the packet source is ignored.
+ *
+ * Returns a context that must be given to the silc_packet_wait function
+ * as argument. Returns NULL on error. To uninitialize the waiting
+ * call silc_packet_wait_uninit.
+ *
+ * NOTES
+ *
+ * Note that packets may be available immediately after calling this
+ * function and they will be buffered, until silc_packet_wait is called.
+ *
+ * EXAMPLE
+ *
+ * void *waiter;
+ *
+ * // Will wait for private message packets
+ * waiter = silc_packet_wait_init(stream, NULL,
+ * SILC_PACKET_PRIVATE_MESSAGE, -1);
+ *
+ ***/
+void *silc_packet_wait_init(SilcPacketStream stream,
+ const SilcID *source_id, ...);
+
+/****f* silccore/SilcPacketAPI/silc_packet_wait_uninit
+ *
+ * SYNOPSIS
+ *
+ * void silc_packet_wait_uninit(void *waiter, SilcPacketStream stream);
+ *
+ * DESCRIPTION
+ *
+ * Uninitializes the waiting context. This may be called also from
+ * another thread while other thread is waiting for packets. This will
+ * inform the waiting thread to stop waiting.
+ *
+ ***/
+void silc_packet_wait_uninit(void *waiter, SilcPacketStream stream);
+
+/****f* silccore/SilcPacketAPI/silc_packet_wait
+ *
+ * SYNOPSIS
+ *
+ * int silc_packet_wait(void *waiter, int timeout,
+ * SilcPacket *return_packet)
+ *
+ * DESCRIPTION
+ *
+ * A special function that can be used to wait for a packet to arrive.
+ * This function will block the calling process or thread until either
+ * a packet is received into the `return_packet' pointer or the specified
+ * timeout value `timeout', which is in milliseconds, will expire. If
+ * the timeout is 0, no timeout exist. Before calling this function the
+ * silc_packet_wait_init must be called. The caller is responsible for
+ * freeing the returned packet with silc_packet_free.
+ *
+ * This function can be used for example from a thread that wants to
+ * block until SILC packet has been received.
+ *
+ * Returns 1 when packet was received, 0 if timeout occurred and -1 if
+ * error occurred.
+ *
+ * EXAMPLE
+ *
+ * static int foo_read_data(FooContext c)
+ * {
+ * SilcPacket packet;
+ * void *waiter;
+ * ...
+ *
+ * // Will wait for private message packets
+ * if (c->initialized == FALSE) {
+ * waiter = silc_packet_wait_init(stream,
+ * SILC_PACKET_PRIVATE_MESSAGE, -1);
+ * c->initialized = TRUE;
+ * }
+ *
+ * ...
+ * // Wait here until private message packet is received
+ * if ((silc_packet_wait(waiter, 0, &packet)) < 0)
+ * return -1;
+ *
+ * ... process packet ...
+ *
+ * return 1;
+ * }
+ *
+ ***/
+int silc_packet_wait(void *waiter, int timeout, SilcPacket *return_packet);
+
+/****f* silccore/SilcPacketAPI/silc_packet_free
+ *
+ * SYNOPSIS
+ *
+ * void silc_packet_free(SilcPacket packet);
+ *
+ * DESCRIPTION
+ *
+ * This function is used to free the SilcPacket pointer that application
+ * receives in the SilcPacketReceive callback. Application must free
+ * the packet if it takes it in to processing.
+ *
+ ***/
+void silc_packet_free(SilcPacket packet);
+
+#endif /* SILCPACKET_H */