2 * h225-persistentdata.c
3 * Source for lists and hash tables used in wireshark's h225 dissector
4 * for calculation of delays in h225-calls
6 * Copyright 2003 Lars Roland
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
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>
36 #include <epan/emem.h>
41 #include "h225-persistentdata.h"
43 /* Global Memory Chunks for lists and Global hash tables*/
45 static GHashTable *ras_calls[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
48 * Functions needed for Ras-Hash-Table
52 static gint h225ras_call_equal(gconstpointer k1, gconstpointer k2)
54 const h225ras_call_info_key* key1 = (const h225ras_call_info_key*) k1;
55 const h225ras_call_info_key* key2 = (const h225ras_call_info_key*) k2;
57 return (key1->reqSeqNum == key2->reqSeqNum &&
58 key1->conversation == key2->conversation);
61 /* calculate a hash key */
62 static guint h225ras_call_hash(gconstpointer k)
64 const h225ras_call_info_key* key = (const h225ras_call_info_key*) k;
66 return key->reqSeqNum + GPOINTER_TO_UINT(key->conversation);
70 h225ras_call_t * find_h225ras_call(h225ras_call_info_key *h225ras_call_key ,int category)
72 h225ras_call_t *h225ras_call = NULL;
73 h225ras_call = (h225ras_call_t *)g_hash_table_lookup(ras_calls[category], h225ras_call_key);
78 h225ras_call_t * new_h225ras_call(h225ras_call_info_key *h225ras_call_key, packet_info *pinfo, e_guid_t *guid, int category)
80 h225ras_call_info_key *new_h225ras_call_key;
81 h225ras_call_t *h225ras_call = NULL;
84 /* Prepare the value data.
85 "req_num" and "rsp_num" are frame numbers;
86 frame numbers are 1-origin, so we use 0
87 to mean "we don't yet know in which frame
88 the reply for this call appears". */
89 new_h225ras_call_key = se_alloc(sizeof(h225ras_call_info_key));
90 new_h225ras_call_key->reqSeqNum = h225ras_call_key->reqSeqNum;
91 new_h225ras_call_key->conversation = h225ras_call_key->conversation;
92 h225ras_call = se_alloc(sizeof(h225ras_call_t));
93 h225ras_call->req_num = pinfo->fd->num;
94 h225ras_call->rsp_num = 0;
95 h225ras_call->requestSeqNum = h225ras_call_key->reqSeqNum;
96 h225ras_call->responded = FALSE;
97 h225ras_call->next_call = NULL;
98 h225ras_call->req_time=pinfo->fd->abs_ts;
99 h225ras_call->guid=*guid;
101 g_hash_table_insert(ras_calls[category], new_h225ras_call_key, h225ras_call);
106 h225ras_call_t * append_h225ras_call(h225ras_call_t *prev_call, packet_info *pinfo, e_guid_t *guid, int category _U_)
108 h225ras_call_t *h225ras_call = NULL;
110 /* Prepare the value data.
111 "req_num" and "rsp_num" are frame numbers;
112 frame numbers are 1-origin, so we use 0
113 to mean "we don't yet know in which frame
114 the reply for this call appears". */
115 h225ras_call = se_alloc(sizeof(h225ras_call_t));
116 h225ras_call->req_num = pinfo->fd->num;
117 h225ras_call->rsp_num = 0;
118 h225ras_call->requestSeqNum = prev_call->requestSeqNum;
119 h225ras_call->responded = FALSE;
120 h225ras_call->next_call = NULL;
121 h225ras_call->req_time=pinfo->fd->abs_ts;
122 h225ras_call->guid=*guid;
124 prev_call->next_call = h225ras_call;
129 /* Init routine for hash tables and delay calculation
130 This routine will be called by Wireshark, before it
131 is (re-)dissecting a trace file from beginning.
132 We need to discard and init any state we've saved */
135 h225_init_routine(void)
139 /* free hash-tables for RAS SRT */
141 if (ras_calls[i] != NULL) {
142 g_hash_table_destroy(ras_calls[i]);
147 /* create new hash-tables for RAS SRT */
150 ras_calls[i] = g_hash_table_new(h225ras_call_hash, h225ras_call_equal);