+/***/
+
+/****d* silccore/SilcPacketAPI/SilcPacketVersion
+ *
+ * NAME
+ *
+ * typedef SilcUInt8 SilcPacketVersion;
+ *
+ * DESCRIPTION
+ *
+ * SILC packet version type definition.
+ *
+ ***/
+typedef SilcUInt8 SilcPacketVersion;
+
+/****d* silccore/SilcPacketAPI/SilcPacketFlags
+ *
+ * NAME
+ *
+ * typedef SilcUInt8 SilcPacketFlags;
+ *
+ * DESCRIPTION
+ *
+ * SILC packet flags type definition and all the packet flags.
+ *
+ * SOURCE
+ */
+typedef SilcUInt8 SilcPacketFlags;
+
+/* All defined packet flags */
+#define SILC_PACKET_FLAG_NONE 0x00 /* No flags */
+#define SILC_PACKET_FLAG_PRIVMSG_KEY 0x01 /* Private message key */
+#define SILC_PACKET_FLAG_LIST 0x02 /* Packet is a list */
+#define SILC_PACKET_FLAG_BROADCAST 0x04 /* Packet is a broadcast */
+#define SILC_PACKET_FLAG_COMPRESSED 0x08 /* Payload is compressed */
+/***/
+
+/* Rest of flags still available
+#define SILC_PACKET_FLAG_XXX 0x10
+#define SILC_PACKET_FLAG_XXX 0x20
+#define SILC_PACKET_FLAG_XXX 0x40
+#define SILC_PACKET_FLAG_XXX 0x80
+*/
+
+/****s* silccore/SilcPacketAPI/SilcPacketContext
+ *
+ * NAME
+ *
+ * typedef struct { ... } SilcPacketContext;
+ *
+ * DESCRIPTION
+ *
+ * In packet sending this is filled and sent to silc_packet_assemble
+ * which then uses it to assemble new packet. In packet reception pointer
+ * to this context is sent to silc_packet_parse which parses the packet
+ * and returns the relevant information to this structure. On packet
+ * reception returned ID's are always the hash values of the ID's from
+ * the packet.
+ *
+ * Short description of the fields following:
+ *
+ * SilcUInt16 truelen
+ *
+ * True length of the packet. This may be set by the caller before
+ * calling any of the silc_packet_* routines. If not provided the
+ * library will calculate the values.
+ *
+ * SilcPacketFlags flags
+ *
+ * Packet flags. Flags are defined above.
+ *
+ * SilcPacketType type
+ *
+ * Type of the packet. Types are defined below.
+ *
+ * unsigned char *src_id
+ * SilcUInt8 src_id_len
+ * SilcUInt8 src_id_type
+ *
+ * Source ID, its length and type. On packet reception retuned ID's
+ * are always the hash values of the ID's from the packet.
+ *
+ * unsigned char *dst_id;
+ * SilcUInt8 dst_id_len;
+ * SilcUInt8 src_id_type;
+ *
+ * Destination ID, its length and type. On packet reception retuned
+ * ID's are always the hash values of the ID's from the packet.
+ *
+ * bool long_pad
+ *
+ * If set to TRUE the packet will include the maximum padding allowed
+ * in SILC packet, which is 128 bytes. If FALSE only the amount of
+ * padding needed will be applied.
+ *
+ * SilcUInt16 users;
+ *
+ * Reference counter for this context. The context is freed only
+ * after the reference counter hits zero. The counter is added
+ * calling silc_packet_context_dup and decreased by calling the
+ * silc_packet_context_free.
+ *
+ * SilcUInt8 padlen
+ *
+ * The padded length of the packet. This may be set by the caller
+ * before calling any of the silc_packet_* routines. If not provided
+ * the library will calculate the values.
+ *
+ * SilcUInt32 sequence;
+ *
+ * Packet sequence number. Set only when this context is a parsed
+ * packet.
+ *
+ * SilcBuffer buffer
+ *
+ * The actual packet data. Set only when this context is a parsed
+ * packet.
+ *
+ ***/
+typedef struct {
+ SilcUInt16 truelen;
+ SilcPacketFlags flags;
+ SilcPacketType type;
+
+ unsigned char *src_id;
+ unsigned char *dst_id;
+ unsigned int src_id_len : 5;
+ unsigned int src_id_type : 2;
+ unsigned int dst_id_len : 5;
+ unsigned int dst_id_type : 2;
+ unsigned int long_pad : 1; /* Set when maximum padding in packet */
+ unsigned int users : 9; /* Reference counter */
+ unsigned int padlen : 8;
+
+ SilcUInt32 sequence;
+ SilcBuffer buffer;
+} SilcPacketContext;
+
+/****s* silccore/SilcPacketAPI/SilcPacketParserContext
+ *
+ * NAME
+ *
+ * typedef struct { ... } SilcPacketParserContext;
+ *
+ * DESCRIPTION
+ *
+ * This context is used in packet reception when the function
+ * silc_packet_receive_process calls parser callback that performs
+ * the actual packet decryption and parsing. This context is sent as
+ * argument to the parser function. This context must be free'd by
+ * the parser callback function.
+ *
+ * Following description of the fields:
+ *
+ * SilcPacketContext *packet
+ *
+ * The actual packet received from the network. In this phase the
+ * context is not parsed, only the packet->buffer is allocated and
+ * it includes the raw packet data, which is encrypted.
+ *
+ * bool normal
+ *
+ * Indicates whether the received packet is normal or special packet.
+ * If special the parsing process is special also.
+ *
+ * SilcSocketConnection sock
+ *
+ * The associated connection.
+ *
+ * void *context
+ *
+ * User context that is sent to the silc_packet_receive_process
+ * function. This usually includes application and connection specific
+ * data.
+ *
+ ***/
+typedef struct {
+ SilcPacketContext *packet;
+ bool normal;
+ SilcSocketConnection sock;
+ void *context;
+} SilcPacketParserContext;
+
+/****f* silccore/SilcPacketAPI/SilcPacketParserCallback
+ *
+ * SYNOPSIS
+ *
+ * typedef bool (*SilcPacketParserCallback)(SilcPacketParserContext
+ * *parse_context);
+ *
+ * DESCRIPTION
+ *
+ * This callback is given to the silc_packet_receive_process function.
+ * The callback is called by the library every time a packet is
+ * received from the network. After the packet has been decrypted
+ * and at least partially parsed it is passed to the application
+ * for further parsing using this callback and the SilcPacketParserContext
+ * context. The application receiving the SilcPacketParserContext
+ * must free it.
+ *
+ * This returns TRUE if the library should continue packet processing
+ * (assuming there is more data to be processed), and FALSE if the
+ * upper layer does not want the library to continue but to leave the
+ * rest of the data is the packet queue untouched. Application may
+ * want to do this for example if the cipher is not ready before
+ * processing a certain packet. In this case the application wants
+ * to recall the processing function with the correct cipher.
+ *
+ ***/
+typedef bool (*SilcPacketParserCallback)(SilcPacketParserContext
+ *parse_context, void *context);