HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / h225-persistentdata.c
blob4cb813763a941716a4dabd30fd51dd6d328ef02d
1 /*
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
8 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <glib.h>
32 #include <epan/packet.h>
33 #include <epan/emem.h>
35 #include <stdio.h>
36 #include <string.h>
38 #include "h225-persistentdata.h"
40 /* Global Memory Chunks for lists and Global hash tables*/
42 static GHashTable *ras_calls[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
45 * Functions needed for Ras-Hash-Table
48 /* compare 2 keys */
49 static gint h225ras_call_equal(gconstpointer k1, gconstpointer k2)
51 const h225ras_call_info_key* key1 = (const h225ras_call_info_key*) k1;
52 const h225ras_call_info_key* key2 = (const h225ras_call_info_key*) k2;
54 return (key1->reqSeqNum == key2->reqSeqNum &&
55 key1->conversation == key2->conversation);
58 /* calculate a hash key */
59 static guint h225ras_call_hash(gconstpointer k)
61 const h225ras_call_info_key* key = (const h225ras_call_info_key*) k;
63 return key->reqSeqNum + GPOINTER_TO_UINT(key->conversation);
67 h225ras_call_t * find_h225ras_call(h225ras_call_info_key *h225ras_call_key ,int category)
69 h225ras_call_t *h225ras_call = NULL;
70 h225ras_call = (h225ras_call_t *)g_hash_table_lookup(ras_calls[category], h225ras_call_key);
72 return h225ras_call;
75 h225ras_call_t * new_h225ras_call(h225ras_call_info_key *h225ras_call_key, packet_info *pinfo, e_guid_t *guid, int category)
77 h225ras_call_info_key *new_h225ras_call_key;
78 h225ras_call_t *h225ras_call = NULL;
81 /* Prepare the value data.
82 "req_num" and "rsp_num" are frame numbers;
83 frame numbers are 1-origin, so we use 0
84 to mean "we don't yet know in which frame
85 the reply for this call appears". */
86 new_h225ras_call_key = se_new(h225ras_call_info_key);
87 new_h225ras_call_key->reqSeqNum = h225ras_call_key->reqSeqNum;
88 new_h225ras_call_key->conversation = h225ras_call_key->conversation;
89 h225ras_call = se_new(h225ras_call_t);
90 h225ras_call->req_num = pinfo->fd->num;
91 h225ras_call->rsp_num = 0;
92 h225ras_call->requestSeqNum = h225ras_call_key->reqSeqNum;
93 h225ras_call->responded = FALSE;
94 h225ras_call->next_call = NULL;
95 h225ras_call->req_time=pinfo->fd->abs_ts;
96 h225ras_call->guid=*guid;
97 /* store it */
98 g_hash_table_insert(ras_calls[category], new_h225ras_call_key, h225ras_call);
100 return h225ras_call;
103 h225ras_call_t * append_h225ras_call(h225ras_call_t *prev_call, packet_info *pinfo, e_guid_t *guid, int category _U_)
105 h225ras_call_t *h225ras_call = NULL;
107 /* Prepare the value data.
108 "req_num" and "rsp_num" are frame numbers;
109 frame numbers are 1-origin, so we use 0
110 to mean "we don't yet know in which frame
111 the reply for this call appears". */
112 h225ras_call = se_new(h225ras_call_t);
113 h225ras_call->req_num = pinfo->fd->num;
114 h225ras_call->rsp_num = 0;
115 h225ras_call->requestSeqNum = prev_call->requestSeqNum;
116 h225ras_call->responded = FALSE;
117 h225ras_call->next_call = NULL;
118 h225ras_call->req_time=pinfo->fd->abs_ts;
119 h225ras_call->guid=*guid;
121 prev_call->next_call = h225ras_call;
122 return h225ras_call;
126 /* Init routine for hash tables and delay calculation
127 This routine will be called by Wireshark, before it
128 is (re-)dissecting a trace file from beginning.
129 We need to discard and init any state we've saved */
131 void
132 h225_init_routine(void)
134 int i;
136 /* free hash-tables for RAS SRT */
137 for(i=0;i<7;i++) {
138 if (ras_calls[i] != NULL) {
139 g_hash_table_destroy(ras_calls[i]);
140 ras_calls[i] = NULL;
144 /* create new hash-tables for RAS SRT */
146 for(i=0;i<7;i++) {
147 ras_calls[i] = g_hash_table_new(h225ras_call_hash, h225ras_call_equal);