2 * h225-persistentdata.c
3 * Source for lists and hash tables used in ethereal's h225 dissector
4 * for calculation of delays in h225-calls
6 * Copyright 2003 Lars Roland
8 * $Id: h225-persistentdata.c,v 1.1 2003/11/16 23:11:18 sahlberg Exp $
10 * Ethereal - Network traffic analyzer
11 * By Gerald Combs <gerald@ethereal.com>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
35 #include <epan/conversation.h>
40 #include "h225-persistentdata.h"
42 /* Global Memory Chunks for lists and Global hash tables*/
44 static GMemChunk *h225ras_call_info_key_chunk = NULL;
45 static GMemChunk *h225ras_call_info_value_chunk = NULL;
47 static GHashTable *ras_calls[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
50 * Functions needed for Ras-Hash-Table
54 static gint h225ras_call_equal(gconstpointer k1, gconstpointer k2)
56 const h225ras_call_info_key* key1 = (const h225ras_call_info_key*) k1;
57 const h225ras_call_info_key* key2 = (const h225ras_call_info_key*) k2;
59 return (key1->reqSeqNum == key2->reqSeqNum &&
60 key1->conversation == key2->conversation);
63 /* calculate a hash key */
64 static guint h225ras_call_hash(gconstpointer k)
66 const h225ras_call_info_key* key = (const h225ras_call_info_key*) k;
68 return key->reqSeqNum + (guint32)(key->conversation);
72 h225ras_call_t * find_h225ras_call(h225ras_call_info_key *h225ras_call_key ,int category)
74 h225ras_call_t *h225ras_call = NULL;
75 h225ras_call = (h225ras_call_t *)g_hash_table_lookup(ras_calls[category], h225ras_call_key);
80 h225ras_call_t * new_h225ras_call(h225ras_call_info_key *h225ras_call_key, packet_info *pinfo, guint8 *guid, int category)
82 h225ras_call_info_key *new_h225ras_call_key;
83 h225ras_call_t *h225ras_call = NULL;
86 /* Prepare the value data.
87 "req_num" and "rsp_num" are frame numbers;
88 frame numbers are 1-origin, so we use 0
89 to mean "we don't yet know in which frame
90 the reply for this call appears". */
91 new_h225ras_call_key = (h225ras_call_info_key *)g_mem_chunk_alloc(h225ras_call_info_key_chunk);
92 new_h225ras_call_key->reqSeqNum = h225ras_call_key->reqSeqNum;
93 new_h225ras_call_key->conversation = h225ras_call_key->conversation;
94 h225ras_call = (h225ras_call_t *)g_mem_chunk_alloc(h225ras_call_info_value_chunk);
95 h225ras_call->req_num = pinfo->fd->num;
96 h225ras_call->rsp_num = 0;
97 h225ras_call->requestSeqNum = h225ras_call_key->reqSeqNum;
98 h225ras_call->responded = FALSE;
99 h225ras_call->next_call = NULL;
100 h225ras_call->req_time.secs=pinfo->fd->abs_secs;
101 h225ras_call->req_time.nsecs=pinfo->fd->abs_usecs*1000;
102 memcpy(h225ras_call->guid, guid,16);
104 g_hash_table_insert(ras_calls[category], new_h225ras_call_key, h225ras_call);
109 h225ras_call_t * append_h225ras_call(h225ras_call_t *prev_call, packet_info *pinfo, guint8 *guid, int category _U_)
111 h225ras_call_t *h225ras_call = NULL;
113 /* Prepare the value data.
114 "req_num" and "rsp_num" are frame numbers;
115 frame numbers are 1-origin, so we use 0
116 to mean "we don't yet know in which frame
117 the reply for this call appears". */
118 h225ras_call = (h225ras_call_t *)g_mem_chunk_alloc(h225ras_call_info_value_chunk);
119 h225ras_call->req_num = pinfo->fd->num;
120 h225ras_call->rsp_num = 0;
121 h225ras_call->requestSeqNum = prev_call->requestSeqNum;
122 h225ras_call->responded = FALSE;
123 h225ras_call->next_call = NULL;
124 h225ras_call->req_time.secs=pinfo->fd->abs_secs;
125 h225ras_call->req_time.nsecs=pinfo->fd->abs_usecs*1000;
126 memcpy(h225ras_call->guid, guid,16);
128 prev_call->next_call = h225ras_call;
133 /* Init routine for hash tables and delay calculation
134 This routine will be called by Ethereal, before it
135 is (re-)dissecting a trace file from beginning.
136 We need to discard and init any state we've saved */
139 h225_init_routine(void)
143 /* free hash-tables and mem_chunks for RAS SRT */
145 if (ras_calls[i] != NULL) {
146 g_hash_table_destroy(ras_calls[i]);
151 if (h225ras_call_info_key_chunk != NULL) {
152 g_mem_chunk_destroy(h225ras_call_info_key_chunk);
153 h225ras_call_info_key_chunk = NULL;
155 if (h225ras_call_info_value_chunk != NULL) {
156 g_mem_chunk_destroy(h225ras_call_info_value_chunk);
157 h225ras_call_info_value_chunk = NULL;
160 /* create new hash-tables and mem_chunks for RAS SRT */
163 ras_calls[i] = g_hash_table_new(h225ras_call_hash, h225ras_call_equal);
166 h225ras_call_info_key_chunk = g_mem_chunk_new("call_info_key_chunk",
167 sizeof(h225ras_call_info_key),
168 400 * sizeof(h225ras_call_info_key),
170 h225ras_call_info_value_chunk = g_mem_chunk_new("call_info_value_chunk",
171 sizeof(h225ras_call_t),
172 400 * sizeof(h225ras_call_t),