File: gvcmz_netopen.c

package info (click to toggle)
fis-gtm 6.3-007-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 36,284 kB
  • sloc: ansic: 328,861; asm: 5,182; csh: 5,102; sh: 1,918; awk: 291; makefile: 69; sed: 13
file content (228 lines) | stat: -rwxr-xr-x 7,086 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/****************************************************************
 *								*
 * Copyright (c) 2001-2015 Fidelity National Information	*
 * Services, Inc. and/or its subsidiaries. All rights reserved.	*
 *								*
 *	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.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#ifdef VMS
#  include <descrip.h>
#  include <ssdef.h>
#endif

#include "gdsroot.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsfhead.h"
#include "filestruct.h"
#include "jnl.h"
#include "hashtab_mname.h"	/* needed for cmmdef.h */
#include "cmidef.h"
#include "cmmdef.h"
#include "stringpool.h"
#include "gtm_string.h"
#include "gvcmy_close.h"
#include "gvcmz.h"
#include "gt_timer.h"
#include "copy.h"
#include "iosp.h"
#include "gtcm_protocol.h"
#include "gtcm_is_query_queryget.h"
#include "gtcm_err_compat.h"
#include "error.h"

GBLREF boolean_t		gtcm_connection;
GBLREF jnl_process_vector	*prc_vec;
GBLREF spdesc			stringpool;
GBLREF struct NTD		*ntd_root;

error_def(CMERR_INVPROT);
error_def(ERR_BADSRVRNETMSG);
error_def(ERR_NETDBOPNERR);
error_def(ERR_TEXT);

static volatile boolean_t	second_attempt = FALSE;
static protocol_msg		myproto;
static struct CLB		*clb;

int		v010_jnl_process_vector_size(void);
void		v010_jnl_prc_vector(void *);

CONDITION_HANDLER(gvcmz_netopen_ch)
{
	/* This condition handler is established only for VMS. In VMS, we do not do CONTINUE for INFO/SUCCESS severity.
	 * FALSE input to START_CH achieves the same thing. */
	START_CH(FALSE);
	if (SIGNAL != CMERR_INVPROT || second_attempt)
	{
		second_attempt = FALSE;
		assert(clb);
		gvcmy_close(clb);
		NEXTCH;
	}
	second_attempt = TRUE;
	UNWIND(NULL, NULL);
}

void gvcmz_netopen_attempt(struct CLB *c)
{
	unsigned char	*ptr, *proto_str;
	int		prc_vec_size;
	int		status;
#ifdef BIGENDIAN
	jnl_process_vector	temp_vect;
#endif

	VMS_ONLY(
		ESTABLISH(gvcmz_netopen_ch); /* our old servers run only on VMS; no need for retry on other OSs */
		clb = c; /* need this assignment since we can't pass c to gvcmz_netopen_ch */
	)
	c->mbf = stringpool.free;
	c->mbl = CM_MINBUFSIZE;
	ptr = c->mbf;
	*ptr++ = CMMS_S_INITPROC;
	assertpro(!second_attempt);
	if (!second_attempt)
	{
		proto_str = (unsigned char *)&myproto;
		if (!prc_vec)
		{
			prc_vec = malloc(SIZEOF(*prc_vec));
			jnl_prc_vector(prc_vec);
		}
		prc_vec_size = SIZEOF(*prc_vec);
#ifdef BIGENDIAN
		memcpy((unsigned char *)&temp_vect, (unsigned char *)prc_vec, SIZEOF(jnl_process_vector));
		temp_vect.jpv_pid =  GTM_BYTESWAP_32(temp_vect.jpv_pid);
		temp_vect.jpv_image_count =  GTM_BYTESWAP_32(temp_vect.jpv_image_count);
		temp_vect.jpv_time =  GTM_BYTESWAP_64(temp_vect.jpv_time);
		temp_vect.jpv_login_time =  GTM_BYTESWAP_64(temp_vect.jpv_login_time);
		memcpy(ptr + S_PROTSIZE, (unsigned char *)&temp_vect, SIZEOF(jnl_process_vector));
#else
		memcpy(ptr + S_PROTSIZE, (unsigned char *)prc_vec, prc_vec_size);
#endif
	}
	memcpy(ptr, proto_str, S_PROTSIZE);
	c->cbl = S_HDRSIZE + S_PROTSIZE + prc_vec_size;
	status = cmi_write(c);	/* INITPROC */
	if (CMI_ERROR(status))
	{
		gvcmy_close(c);
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_NETDBOPNERR, 0, status);
	}
	status = cmi_read(c);	/* return message should be same size */
	if (CMI_ERROR(status))
	{
		gvcmy_close(c);
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_NETDBOPNERR, 0, status);
	}
	if (CMMS_T_INITPROC != *c->mbf)
	{
		if (CMMS_E_ERROR != *c->mbf)
		{
			gvcmy_close(c);
			rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_NETDBOPNERR, 0, ERR_BADSRVRNETMSG);
		}
		gvcmz_errmsg(c, FALSE);
	}
	VMS_ONLY(
		REVERT;
		clb = NULL; /* defensive programming */
		second_attempt = FALSE; /* we succesfully connected; no need for one more try */
	)
}

struct CLB *gvcmz_netopen(struct CLB *c, cmi_descriptor *node, cmi_descriptor *task)
{
	static readonly int4	wait[2] = {-100000, -1};
	static readonly int4	reptim[2] = {-10000, -1};
	unsigned char		*ptr;
	link_info		*li;
	int			len, i;
	uint4			status;
	protocol_msg		*server_proto;

	c = UNIX_ONLY(cmi_alloc_clb())VMS_ONLY(cmu_makclb());
	c->usr = malloc(SIZEOF(link_info));
	li = c->usr;
	memset(li, 0, SIZEOF(*li));
	c->err = gvcmz_neterr_set;
#ifdef VMS
	c->nod.dsc$b_dtype = c->tnd.dsc$b_dtype = DSC$K_DTYPE_T;
	c->nod.dsc$b_class = c->tnd.dsc$b_class = DSC$K_CLASS_S;
	c->nod.dsc$w_length = node->dsc$w_length;
	c->nod.dsc$a_pointer = malloc(c->nod.dsc$w_length);
	memcpy(c->nod.dsc$a_pointer, node->dsc$a_pointer, node->dsc$w_length);
	c->tnd.dsc$w_length = task->dsc$w_length;
	c->tnd.dsc$a_pointer = malloc(c->tnd.dsc$w_length);
	memcpy(c->tnd.dsc$a_pointer, task->dsc$a_pointer, task->dsc$w_length);
	for (i = 0; i < 2; i++) /* This retry should really be pushed down into cmi_open */
	{
		status = cmi_open(c);
		if (!CMI_ERROR(status))
			break;
		hiber_start_wait_any(10);
	}
#elif defined(UNIX)
	c->nod.addr = malloc(node->len);
	c->nod.len = node->len;
	memcpy(c->nod.addr, node->addr, node->len);
	c->tnd.len = task->len;
	c->tnd.addr = malloc(c->tnd.len);
	memcpy(c->tnd.addr, task->addr, task->len);
	status = cmi_open(c);
#else
#error Unsupported platform
#endif
	if (CMI_ERROR(status))
	{
		free(c->usr);
		free(VMS_ONLY(c->nod.dsc$a_pointer) UNIX_ONLY(c->nod.addr));
		free(VMS_ONLY(c->tnd.dsc$a_pointer) UNIX_ONLY(c->tnd.addr));
		VMS_ONLY(lib$free_vm(&SIZEOF(*c), &c, 0);)
		UNIX_ONLY(cmi_free_clb(c));
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_NETDBOPNERR, 0, status);
	}
	if (0 == ntd_root)
		ntd_root = cmu_ntdroot();
	gtcm_protocol(&myproto);
	li->lnk_active = TRUE;
	ENSURE_STP_FREE_SPACE(CM_MINBUFSIZE);
	do
	{
		gvcmz_netopen_attempt(c);
	} while (second_attempt);
	if (S_HDRSIZE + S_PROTSIZE + 2 != c->cbl)
	{
		gvcmy_close(c);
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_NETDBOPNERR, 0, ERR_BADSRVRNETMSG);
	}
	server_proto = (protocol_msg *)(c->mbf + 1);
	if (!gtcm_protocol_match(server_proto, &myproto))
	{
		gvcmy_close(c);
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_NETDBOPNERR, 0, CMERR_INVPROT);
	}
	li->convert_byteorder = (gtcm_is_big_endian(&myproto) != gtcm_is_big_endian(server_proto));
	li->query_is_queryget = gtcm_is_query_queryget(server_proto, &myproto);
	li->server_supports_dollar_incr = (0 <= memcmp(server_proto->msg + CM_LEVEL_OFFSET, CMM_INCREMENT_MIN_LEVEL, 3));
	li->server_supports_std_null_coll = (0 <= memcmp(server_proto->msg + CM_LEVEL_OFFSET, CMM_STDNULLCOLL_MIN_LEVEL, 3));
	li->server_supports_long_names = (0 <= memcmp(server_proto->msg + CM_LEVEL_OFFSET, CMM_LONGNAMES_MIN_LEVEL, 3));
	if (!(li->err_compat = gtcm_err_compat((protocol_msg *)(c->mbf + 1), &myproto)))
	{
		gvcmy_close(c);
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(6) ERR_NETDBOPNERR, 0, ERR_TEXT, 2,
				LEN_AND_LIT("GTCM functionality not implemented between UNIX and VMS yet"));
	}
	gtcm_connection = TRUE;
	CM_GET_USHORT(li->procnum, (c->mbf + S_HDRSIZE + S_PROTSIZE), li->convert_byteorder);
	return c;
}