X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcpacket.h;h=b2c9dd2790dc0b121ffc10c5f3919e452aa3dd01;hp=e3c4b6ea6174464585accc969666629a8608c47f;hb=382d15d447b7a95390decfa783836ae4fe255b3d;hpb=517c26a90223f5d5d7908c4285ab333d4ae09029 diff --git a/lib/silccore/silcpacket.h b/lib/silccore/silcpacket.h index e3c4b6ea..b2c9dd27 100644 --- a/lib/silccore/silcpacket.h +++ b/lib/silccore/silcpacket.h @@ -61,7 +61,7 @@ * * NAME * - * typedef unsigned char SilcPacketType; + * typedef SilcUInt8 SilcPacketType; * * DESCRIPTION * @@ -69,7 +69,7 @@ * * SOURCE */ -typedef unsigned char SilcPacketType; +typedef SilcUInt8 SilcPacketType; /* SILC Packet types. */ #define SILC_PACKET_NONE 0 /* NULL, never sent */ @@ -100,6 +100,7 @@ typedef unsigned char SilcPacketType; #define SILC_PACKET_KEY_AGREEMENT 25 /* Key Agreement request */ #define SILC_PACKET_RESUME_ROUTER 26 /* Backup router resume */ #define SILC_PACKET_FTP 27 /* File Transfer */ +#define SILC_PACKET_RESUME_CLIENT 28 /* Client resume */ #define SILC_PACKET_PRIVATE 200 /* Private range start */ #define SILC_PACKET_MAX 255 /* RESERVED */ @@ -109,20 +110,20 @@ typedef unsigned char SilcPacketType; * * NAME * - * typedef unsigned char SilcPacketVersion; + * typedef SilcUInt8 SilcPacketVersion; * * DESCRIPTION * * SILC packet version type definition. * ***/ -typedef unsigned char SilcPacketVersion; +typedef SilcUInt8 SilcPacketVersion; /****d* silccore/SilcPacketAPI/SilcPacketFlags * * NAME * - * typedef unsigned char SilcPacketFlags; + * typedef SilcUInt8 SilcPacketFlags; * * DESCRIPTION * @@ -130,17 +131,17 @@ typedef unsigned char SilcPacketVersion; * * SOURCE */ -typedef unsigned char SilcPacketFlags; +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 0x08 #define SILC_PACKET_FLAG_XXX 0x10 #define SILC_PACKET_FLAG_XXX 0x20 #define SILC_PACKET_FLAG_XXX 0x40 @@ -164,73 +165,81 @@ typedef unsigned char SilcPacketFlags; * * Short description of the fields following: * - * SilcBuffer buffer - * - * The data buffer. - * - * SilcPacketType type + * SilcUInt16 truelen * - * Type of the packet. Types are defined below. + * 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 - * unsigned char src_id_type + * 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; - * unsigned char src_id_type; + * 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. * - * SilcUInt16 truelen - * SilcUInt8 padlen - * - * The true lenght of the packet and the padded length of the packet. - * These may be set by the caller before calling any of the - * silc_packet_* routines. If not provided the library will calculate - * the values. + * 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. * - * int users; + * 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. + * 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 { - SilcBuffer buffer; - SilcUInt16 truelen; SilcPacketFlags flags; SilcPacketType type; - SilcUInt8 padlen; unsigned char *src_id; - SilcUInt8 src_id_len; - SilcUInt8 src_id_type; - unsigned char *dst_id; - SilcUInt8 dst_id_len; - SilcUInt8 dst_id_type; - - int users; - bool long_pad; /* Set to TRUE to use maximum padding - in packet (up to 256 bytes). */ + 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 @@ -323,10 +332,10 @@ typedef bool (*SilcPacketParserCallback)(SilcPacketParserContext * * SOURCE */ -#define SILC_PACKET_LENGTH(__packet, __ret_truelen, __ret_paddedlen) \ -do { \ - SILC_GET16_MSB((__ret_truelen), (__packet)->data); \ - (__ret_paddedlen) = (__ret_truelen) + (__packet)->data[4]; \ +#define SILC_PACKET_LENGTH(__packetdata, __ret_truelen, __ret_paddedlen) \ +do { \ + SILC_GET16_MSB((__ret_truelen), (__packetdata)); \ + (__ret_paddedlen) = (__ret_truelen) + (SilcUInt8)(__packetdata)[4]; \ } while(0) /***/ @@ -361,14 +370,18 @@ do { \ * * DESCRIPTION * - * Returns the length of the padding in the packet. This is used + * Calculates the length of the padding in the packet. This is used * by various library routines to determine needed padding length. * * SOURCE */ -#define SILC_PACKET_PADLEN(__packetlen, __blocklen) \ - SILC_PACKET_DEFAULT_PADLEN - (__packetlen) % \ - ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN) +#define SILC_PACKET_PADLEN(__packetlen, __blocklen, __padlen) \ +do { \ + __padlen = (SILC_PACKET_DEFAULT_PADLEN - (__packetlen) % \ + ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN)); \ + if (__padlen < 8) \ + __padlen += ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN); \ +} while(0) /***/ /****d* silccore/SilcPacketAPI/SILC_PACKET_PADLEN_MAX @@ -380,13 +393,16 @@ do { \ * DESCRIPTION * * Returns the length of the padding up to the maximum length, which - * is 128 butes. This is used by various library routines to determine + * is 128 bytes. This is used by various library routines to determine * needed padding length. * * SOURCE */ -#define SILC_PACKET_PADLEN_MAX(__packetlen) \ - SILC_PACKET_MAX_PADLEN - (__packetlen) % SILC_PACKET_MAX_PADLEN +#define SILC_PACKET_PADLEN_MAX(__packetlen, __blocklen, __padlen) \ +do { \ + __padlen = (SILC_PACKET_MAX_PADLEN - (__packetlen) % \ + ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN)); \ +} while(0) /***/ /* Prototypes */