MAX_MCS_INDEX is a valid array index.
[metze/wireshark/wip.git] / epan / stream.c
index 1784c7d312c5760570be9dc028a8b26ca06b10e6..bb1bbc9c452040649f047f943e460d02404a115b 100644 (file)
@@ -4,8 +4,6 @@
  * which are handled as streams, and don't have lengths
  * and IDs such as are required for reassemble.h
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
@@ -35,7 +33,7 @@
 
 
 typedef struct {
-    fragment_data *fd_head;          /* the reassembled data, NULL
+    fragment_head *fd_head;          /* the reassembled data, NULL
                                       * until we add the last fragment */
     guint32 pdu_number;              /* Number of this PDU within the stream */
 
@@ -94,7 +92,7 @@ static guint stream_hash_func(gconstpointer k)
     const stream_key_t *key = (const stream_key_t *)k;
 
     /* is_circuit is redundant to the circuit/conversation pointer */
-    return ((guint)(unsigned long)key->circ.circuit) ^ key->p2p_dir;
+    return (GPOINTER_TO_UINT(key->circ.circuit)) ^ key->p2p_dir;
 }
 
 /* compare func */
@@ -156,7 +154,7 @@ static stream_t *new_stream( stream_key_t *key )
 {
     stream_t *val;
 
-    val = se_alloc(sizeof(stream_t));
+    val = wmem_new(wmem_file_scope(), stream_t);
     val -> key = key;
     val -> pdu_counter = 0;
     val -> current_pdu = NULL;
@@ -173,7 +171,7 @@ static stream_t *stream_hash_insert_circ( const struct circuit *circuit, int p2p
 {
     stream_key_t *key;
 
-    key = se_alloc(sizeof(stream_key_t));
+    key = wmem_new(wmem_file_scope(), stream_key_t);
     key->is_circuit = TRUE;
     key->circ.circuit = circuit;
     key->p2p_dir = p2p_dir;
@@ -185,7 +183,7 @@ static stream_t *stream_hash_insert_conv( const struct conversation *conv, int p
 {
     stream_key_t *key;
 
-    key = se_alloc(sizeof(stream_key_t));
+    key = wmem_new(wmem_file_scope(), stream_key_t);
     key->is_circuit = FALSE;
     key->circ.conv = conv;
     key->p2p_dir = p2p_dir;
@@ -216,7 +214,7 @@ static void stream_init_pdu_data(void)
 static stream_pdu_t *stream_new_pdu(stream_t *stream)
 {
     stream_pdu_t *pdu;
-    pdu = se_alloc(sizeof(stream_pdu_t));
+    pdu = wmem_new(wmem_file_scope(), stream_pdu_t);
     pdu -> fd_head = NULL;
     pdu -> pdu_number = stream -> pdu_counter++;
     pdu -> id = pdu_counter++;
@@ -240,7 +238,7 @@ typedef struct fragment_key {
 static guint fragment_hash_func(gconstpointer k)
 {
     const fragment_key_t *key = (const fragment_key_t *)k;
-    return ((guint)(unsigned long)key->stream) + ((guint)key -> framenum) + ((guint)key->offset);
+    return (GPOINTER_TO_UINT(key->stream)) + ((guint)key -> framenum) + ((guint)key->offset);
 }
 
 /* compare func */
@@ -283,7 +281,7 @@ static stream_pdu_fragment_t *fragment_hash_lookup( const stream_t *stream, guin
     key.stream = stream;
     key.framenum = framenum;
     key.offset = offset;
-    val = g_hash_table_lookup(fragment_hash, &key);
+    val = (stream_pdu_fragment_t *)g_hash_table_lookup(fragment_hash, &key);
 
     return val;
 }
@@ -296,12 +294,12 @@ static stream_pdu_fragment_t *fragment_hash_insert( const stream_t *stream, guin
     fragment_key_t *key;
     stream_pdu_fragment_t *val;
 
-    key = se_alloc(sizeof(fragment_key_t));
+    key = wmem_new(wmem_file_scope(), fragment_key_t);
     key->stream = stream;
     key->framenum = framenum;
     key->offset = offset;
 
-    val = se_alloc(sizeof(stream_pdu_fragment_t));
+    val = wmem_new(wmem_file_scope(), stream_pdu_fragment_t);
     val->len = length;
     val->pdu = NULL;
     val->final_fragment = FALSE;
@@ -312,9 +310,8 @@ static stream_pdu_fragment_t *fragment_hash_insert( const stream_t *stream, guin
 
 /*****************************************************************************/
 
-/* fragmentation hash tables */
-static GHashTable *stream_fragment_table = NULL;
-static GHashTable *stream_reassembled_table = NULL;
+/* reassembly table */
+static reassembly_table stream_reassembly_table;
 
 /* Initialise a new stream. Call this when you first identify a distinct
  * stream. */
@@ -361,8 +358,8 @@ stream_t *find_stream_conv ( const struct conversation *conv, int p2p_dir )
 
 /* cleanup the stream routines */
 /* Note: stream_cleanup must only be called when seasonal memory
- *       is also freed since the hash tables countain pointers to 
- *       se_alloc'd memory.
+ *       is also freed since the hash tables countain pointers to
+ *       wmem_file_scoped memory.
  */
 void stream_cleanup( void )
 {
@@ -378,8 +375,8 @@ void stream_init( void )
     init_fragment_hash();
     stream_init_pdu_data();
 
-    fragment_table_init(&stream_fragment_table);
-    reassembled_table_init(&stream_reassembled_table);
+    reassembly_table_init(&stream_reassembly_table,
+                          &addresses_reassembly_table_functions);
 }
 
 /*****************************************************************************/
@@ -392,7 +389,7 @@ stream_pdu_fragment_t *stream_find_frag( stream_t *stream, guint32 framenum, gui
 stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guint32 offset,
                                         tvbuff_t *tvb, packet_info *pinfo, gboolean more_frags )
 {
-    fragment_data *fd_head;
+    fragment_head *fd_head;
     stream_pdu_t *pdu;
     stream_pdu_fragment_t *frag_data;
 
@@ -410,8 +407,8 @@ stream_pdu_fragment_t *stream_add_frag( stream_t *stream, guint32 framenum, guin
     }
 
     /* add it to the reassembly tables */
-    fd_head = fragment_add_seq_next(tvb, 0, pinfo, pdu->id,
-                                    stream_fragment_table, stream_reassembled_table,
+    fd_head = fragment_add_seq_next(&stream_reassembly_table,
+                                    tvb, 0, pinfo, pdu->id, NULL,
                                     tvb_reported_length(tvb), more_frags);
     /* add it to our hash */
     frag_data = fragment_hash_insert( stream, framenum, offset, tvb_reported_length(tvb));
@@ -467,7 +464,7 @@ guint32 stream_get_frag_length( const stream_pdu_fragment_t *frag)
     return frag->len;
 }
 
-fragment_data *stream_get_frag_data( const stream_pdu_fragment_t *frag)
+fragment_head *stream_get_frag_data( const stream_pdu_fragment_t *frag)
 {
     DISSECTOR_ASSERT( frag );
     return frag->pdu->fd_head;
@@ -478,3 +475,16 @@ guint32 stream_get_pdu_no( const stream_pdu_fragment_t *frag)
     DISSECTOR_ASSERT( frag );
     return frag->pdu->pdu_number;
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */