Rename crypt-xxx to xxx
[obnox/wireshark/wip.git] / epan / conversation.c
index 5a2e435277b29a8615696066e1ce22424f2b957e..d40ee7677d51fa4249fdf88324b054c16112c9ab 100644 (file)
@@ -408,22 +408,49 @@ conversation_match_no_addr2_or_port2(gconstpointer v, gconstpointer w)
        return 0;
 }
 
+/*
+ * Free the proto_data.  The conversation itself is se_allocated.
+ */
+void
+free_data_list(gpointer key _U_, gpointer value, gpointer user_data _U_)
+{
+       conversation_t *conv = value;
+
+       /* TODO: se_slist? */
+       g_slist_free(conv->data_list);
+
+       /* Not really necessary, but... */
+       conv->data_list = NULL;
+
+}
+
 /*
  * Destroy all existing conversations
  */
 void
 conversation_cleanup(void)
 {
-       /* The conversation keys are se_ allocated so they are already gone */
+       /*  Clean up the hash tables, but only after freeing any proto_data
+        *  that may be hanging off the conversations.
+        *  The conversation keys are se_ allocated so we don't have to clean them up.
+        */
        conversation_keys = NULL;
-       if (conversation_hashtable_exact != NULL)
+       if (conversation_hashtable_exact != NULL) {
+               g_hash_table_foreach(conversation_hashtable_exact, free_data_list, NULL);
                g_hash_table_destroy(conversation_hashtable_exact);
-       if (conversation_hashtable_no_addr2 != NULL)
+       }
+       if (conversation_hashtable_no_addr2 != NULL) {
+               g_hash_table_foreach(conversation_hashtable_no_addr2, free_data_list, NULL);
                g_hash_table_destroy(conversation_hashtable_no_addr2);
-       if (conversation_hashtable_no_port2 != NULL)
+       }
+       if (conversation_hashtable_no_port2 != NULL) {
+               g_hash_table_foreach(conversation_hashtable_no_port2, free_data_list, NULL);
                g_hash_table_destroy(conversation_hashtable_no_port2);
-       if (conversation_hashtable_no_addr2_or_port2 != NULL)
+       }
+       if (conversation_hashtable_no_addr2_or_port2 != NULL) {
+               g_hash_table_foreach(conversation_hashtable_no_addr2_or_port2, free_data_list, NULL);
                g_hash_table_destroy(conversation_hashtable_no_addr2_or_port2);
+       }
 
        conversation_hashtable_exact = NULL;
        conversation_hashtable_no_addr2 = NULL;
@@ -1108,3 +1135,27 @@ try_conversation_dissector(const address *addr_a, const address *addr_b, const p
        }
        return FALSE;
 }
+
+/*  A helper function that calls find_conversation() and, if a conversation is
+ *  not found, calls conversation_new().
+ *  The frame number and addresses are taken from pinfo.
+ *  No options are used, though we could extend this API to include an options
+ *  parameter.
+ */
+conversation_t *
+find_or_create_conversation(packet_info *pinfo)
+{
+       conversation_t *conv=NULL;
+
+       /* Have we seen this conversation before? */
+       if((conv = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst,
+                                    pinfo->ptype, pinfo->srcport,
+                                    pinfo->destport, 0)) == NULL) {
+               /* No, this is a new conversation. */
+               conv = conversation_new(pinfo->fd->num, &pinfo->src,
+                                       &pinfo->dst, pinfo->ptype,
+                                       pinfo->srcport, pinfo->destport, 0);
+       }
+
+       return conv;
+}