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;
}
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;
+}