updates. New data types.
[silc.git] / lib / silccore / silcpacket.h
index d48035135b9302e90420f917de7085cfb50dc0d1..7bc8a8a9d9724baeb59cdd919fec094f6923fa3b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
 
-  Copyright (C) 1997 - 2000 Pekka Riikonen
+  Copyright (C) 1997 - 2001 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -59,7 +59,7 @@ typedef unsigned char SilcPacketFlags;
 /* All defined packet flags */
 #define SILC_PACKET_FLAG_NONE             0x00
 #define SILC_PACKET_FLAG_PRIVMSG_KEY      0x01
-#define SILC_PACKET_FLAG_FORWARDED        0x02
+#define SILC_PACKET_FLAG_LIST             0x02
 #define SILC_PACKET_FLAG_BROADCAST        0x04
 #define SILC_PACKET_FLAG_TUNNELED         0x08
 /* Rest of flags still available
@@ -94,12 +94,19 @@ typedef unsigned char SilcPacketFlags;
        Packet flags. Flags are defined above.
 
    unsigned char *src_id
-   unsigned int src_id_len
-   SilcIdType src_id_type
+   uint16 src_id_len
+   unsigned char 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;
+  uint16 dst_id_len;
+  unsigned char 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.
+
    SilcHash hash
 
        Pointer to allocated hash object. This must be MD5 hash object.
@@ -112,18 +119,23 @@ typedef struct {
   SilcPacketFlags flags;
 
   unsigned char *src_id;
-  unsigned int src_id_len;
-  SilcIdType src_id_type;
+  uint16 src_id_len;
+  unsigned char src_id_type;
 
   unsigned char *dst_id;
-  unsigned int dst_id_len;
-  SilcIdType dst_id_type;
+  uint16 dst_id_len;
+  unsigned char dst_id_type;
 
-  unsigned int truelen;
-  unsigned int padlen;
+  uint16 truelen;
+  uint16 padlen;
+
+  /* Back pointers */
+  void *context;
+  SilcSocketConnection sock;
 
-  /* For padding generation */
-  SilcRng rng;
+  /* Reference count for this context. The context is free'd only
+     after the reference count is zero. */
+  int users;
 } SilcPacketContext;
 
 /* 
@@ -174,6 +186,11 @@ typedef struct {
 typedef void (*SilcPacketParserCallback)(SilcPacketParserContext 
                                         *parse_context);
 
+/* The packet check callback in decryption phase */
+typedef int (*SilcPacketCheckDecrypt)(SilcPacketType packet_type,
+                                     SilcBuffer buffer,
+                                     SilcPacketContext *packet,
+                                     void *context);
 
 /* SILC Packet types. */
 #define SILC_PACKET_NONE                0       /* NULL, never sent */
@@ -195,19 +212,17 @@ typedef void (*SilcPacketParserCallback)(SilcPacketParserContext
 #define SILC_PACKET_CONNECTION_AUTH_REQUEST 16   /* Request of auth meth */
 #define SILC_PACKET_CONNECTION_AUTH      17      /* Connectinon auth */
 #define SILC_PACKET_NEW_ID               18      /* Sending new ID */
-#define SILC_PACKET_NEW_ID_LIST          19      /* Sending list of them */
-#define SILC_PACKET_NEW_CLIENT           20      /* Registering client */
-#define SILC_PACKET_NEW_SERVER           21      /* Registering server */
-#define SILC_PACKET_NEW_CHANNEL          22      /* Registering channel */
-#define SILC_PACKET_NEW_CHANNEL_USER     23      /*   "" user on channel */
-#define SILC_PACKET_NEW_CHANNEL_LIST     24      /* List of new channels */
-#define SILC_PACKET_NEW_CHANNEL_USER_LIST 25     /* List of users on "" */
-#define SILC_PACKET_REPLACE_ID           26      /* To replace old ID */
-#define SILC_PACKET_REMOVE_ID            27      /* To remove ID */
-#define SILC_PACKET_REMOVE_CHANNEL_USER  28      /* Remove user from channel */
-#define SILC_PACKET_REKEY                29
-#define SILC_PACKET_REKEY_DONE           30
-/* #define SILC_PACKET_MAX               255 */
+#define SILC_PACKET_NEW_CLIENT           19      /* Client registering */
+#define SILC_PACKET_NEW_SERVER           20      /* Server registering */
+#define SILC_PACKET_NEW_CHANNEL          21      /* Channel registering */
+#define SILC_PACKET_REKEY                22      /* Re-key start */
+#define SILC_PACKET_REKEY_DONE           23      /* Re-key done */
+#define SILC_PACKET_HEARTBEAT            24      /* Heartbeat */
+#define SILC_PACKET_KEY_AGREEMENT        25      /* Key Agreement request */
+#define SILC_PACKET_CELL_ROUTERS         26      /* Cell routers backup */
+
+#define SILC_PACKET_PRIVATE              200     /* Private range start  */
+#define SILC_PACKET_MAX                  255     /* RESERVED */
 
 /* Macros */
 
@@ -227,21 +242,26 @@ do {                                                                           \
 int silc_packet_write(int sock, SilcBuffer src);
 int silc_packet_send(SilcSocketConnection sock, int force_send);
 void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, 
-                        SilcBuffer buffer, unsigned int len);
+                        SilcBuffer buffer, uint32 len);
 void silc_packet_assemble(SilcPacketContext *ctx);
 void silc_packet_send_prepare(SilcSocketConnection sock,
-                             unsigned int header_len,
-                             unsigned int padlen,
-                             unsigned int data_len);
+                             uint32 header_len,
+                             uint32 padlen,
+                             uint32 data_len);
 int silc_packet_read(int sock, SilcBuffer dest);
 int silc_packet_receive(SilcSocketConnection sock);
 int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
-                       SilcBuffer buffer, SilcPacketContext *packet);
-int silc_packet_receive_process(SilcSocketConnection sock, 
-                               SilcCipher cipher, SilcHmac hmac,
-                               SilcPacketParserCallback parser, 
-                               void *context);
+                       SilcBuffer buffer, SilcPacketContext *packet,
+                       SilcPacketCheckDecrypt check_packet,
+                       void *context);
+void silc_packet_receive_process(SilcSocketConnection sock,
+                                SilcCipher cipher, SilcHmac hmac,
+                                SilcPacketParserCallback parser,
+                                void *context);
 SilcPacketType silc_packet_parse(SilcPacketContext *ctx);
 SilcPacketType silc_packet_parse_special(SilcPacketContext *ctx);
+SilcPacketContext *silc_packet_context_alloc();
+SilcPacketContext *silc_packet_context_dup(SilcPacketContext *ctx);
+void silc_packet_context_free(SilcPacketContext *ctx);
 
 #endif