File: gtcm_hist.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (182 lines) | stat: -rw-r--r-- 4,600 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/****************************************************************
 *								*
 *	Copyright 2001, 2013 Fidelity Information Services, Inc	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

/* gtcm_hist.c - routines to save a history of recently received and
 *  transmitted packets.
 */

#define GTCM_HIST_C

#include "mdef.h"

#include "gtm_string.h"
#include "gtm_stdio.h"		/* for SPRINTF() atleast */
#include "gtm_time.h"
#include "have_crit.h"
#include <signal.h>

#include "gtcm.h"

GBLREF omi_conn *curr_conn;

/* init_omi_hist - Set up the next OMI history record */
void init_hist(void)
{
	int	i;

	omi_hist = malloc(SIZEOF(omi_hist_rec) * HISTORY);
	rc_hist = malloc(SIZEOF(rc_hist_rec) * HISTORY);

	for(i = 0; i < HISTORY; i++)
	{
		omi_hist[i].timestamp  = rc_hist[i].timestamp  = 0;
		omi_hist[i].toobigflag = rc_hist[i].toobigflag = 0;
		omi_hist[i].req_len    = rc_hist[i].req_len    = 0;
		omi_hist[i].rsp_len    = rc_hist[i].rsp_len    = 0;
	}
	omi_hist_num = rc_hist_num = -1;
}

void init_omi_hist(int conn)
{
	omi_hist_num = (omi_hist_num + 1) % HISTORY;

	omi_hist[omi_hist_num].timestamp = time(0);
	omi_hist[omi_hist_num].conn = conn;
	omi_hist[omi_hist_num].req_len = omi_hist[omi_hist_num].rsp_len = 0;
	omi_hist[omi_hist_num].toobigflag = 0;
}

void save_omi_req(char *buff, int len)
{
	omi_hist[omi_hist_num].req_len = len;
	if (len >= 0 && len <= OMI_HIST_BUFSIZ)
		memcpy(omi_hist[omi_hist_num].req, buff, len);
	else
	{
		omi_hist[omi_hist_num].toobigflag = 1;
		memcpy(omi_hist[omi_hist_num].req, buff, OMI_HIST_BUFSIZ);
	}
}

void save_omi_rsp(char *buff, int len)
{
	omi_hist[omi_hist_num].rsp_len = len;
	if (len >= 0 && len <= OMI_HIST_BUFSIZ)
		memcpy(omi_hist[omi_hist_num].rsp, buff, len);
	else
	{
		omi_hist[omi_hist_num].toobigflag = 1;
		memcpy(omi_hist[omi_hist_num].rsp, buff, OMI_HIST_BUFSIZ);
	}
}

/* init_rc_hist - Set up the next RC history record */
void init_rc_hist(int conn)
{
	rc_hist_num = (rc_hist_num + 1) % HISTORY;
	rc_hist[rc_hist_num].timestamp = time(0);
	rc_hist[rc_hist_num].conn = conn;
	rc_hist[rc_hist_num].req_len = rc_hist[rc_hist_num].rsp_len = 0;
	rc_hist[rc_hist_num].toobigflag = 0;
}

void save_rc_req(char *buff, int len)
{
	rc_hist[rc_hist_num].req_len = len;
	if (len >= 0 && len <= RC_HIST_BUFSIZ)
		memcpy(rc_hist[rc_hist_num].req, buff, len);
	else
	{
		rc_hist[rc_hist_num].toobigflag = 1;
		memcpy(rc_hist[rc_hist_num].req, buff, RC_HIST_BUFSIZ);
	}
}

void save_rc_rsp(char *buff, int len)
{
	rc_hist[rc_hist_num].rsp_len = len;
	if (len >= 0 && len <= RC_HIST_BUFSIZ)
		memcpy(rc_hist[rc_hist_num].rsp, buff, len);
	else
	{
		rc_hist[rc_hist_num].toobigflag = 1;
		memcpy(rc_hist[rc_hist_num].rsp, buff, RC_HIST_BUFSIZ);
	}
}

void dump_omi_rq(void)
{
    char	msg[256];
    char	*then;
    omi_conn	*temp;

    GTM_CTIME(then, &omi_hist[omi_hist_num].timestamp);
    then[24] = '\0';
    if (omi_hist_num < 0)   /* no history? */
	return;
    SPRINTF(msg,
	    "OMI Rq dump: %ld / %s Lg size %d conn %d",
	    omi_hist[omi_hist_num].timestamp, then,
	    omi_hist[omi_hist_num].req_len, omi_hist[omi_hist_num].conn);
    gtcm_pktdmp(omi_hist[omi_hist_num].req, 0, msg);

}

void dump_rc_hist(void)
{
	int	i;
	char	msg[256];
	char	*then;

	if (rc_hist_num < 0)	/* no history? */
		return;
	i = rc_hist_num;
	do
	{
		i = (i + 1) % HISTORY;
		if (rc_hist[i].timestamp)
		{
			GTM_CTIME(then, &rc_hist[i].timestamp);
			then[24] = '\0'; /* eliminate newline */
			if (rc_hist[i].toobigflag)
			{
				SPRINTF(msg,
				"RC Rq history: %ld / %s Lg size %d conn %d",
					rc_hist[i].timestamp, then,
					rc_hist[i].req_len, rc_hist[i].conn);
				gtcm_pktdmp(rc_hist[i].req, 0, msg);
				SPRINTF(msg,
				"RC Aq history: %ld / %s Lg size %d conn %d",
					rc_hist[i].timestamp, then,
					rc_hist[i].rsp_len, rc_hist[i].conn);
				gtcm_pktdmp(rc_hist[i].rsp, 0, msg);
			}
			else
			{
				SPRINTF(msg,
				"RC Rq history: %ld / %s size %d conn %d",
					rc_hist[i].timestamp, then,
					rc_hist[i].req_len, rc_hist[i].conn);
				gtcm_pktdmp(rc_hist[i].req,
					    rc_hist[i].req_len,
					    msg);
				SPRINTF(msg,
				"RC Aq history: %ld / %s size %d conn %d",
					rc_hist[i].timestamp, then,
					rc_hist[i].rsp_len, rc_hist[i].conn);
				gtcm_pktdmp(rc_hist[i].rsp,
					    rc_hist[i].rsp_len,
					    msg);
			}
		}
	} while (i != rc_hist_num);
}