-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathservices.c
310 lines (262 loc) · 11.1 KB
/
services.c
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/*===========================================================================*/
/* This supportpac is maintained by Jeff Lowrey */
/* Wayne M. Schutz is maintainer emeritus */
/* */
/* Chris Petty is the original author. */
/* */
/*(C)Copyright IBM Corporation 1995, 1997, 1998, 1999, 2000, */
/*(C)Copyright IBM Corporation 2002, 2003, 2004, 2005, 2006 */
/*(C)Copyright IBM Corporation 2007, 2008, 2009 */
/* */
/*===========================================================================*/
/* */
/* See the read.me file for change history */
/* */
/*===========================================================================*/
/* Module Name: listener.c */
/* DESCRIPTIVE NAME WebSphere MQ Save Queue Manager Object */
/* Definitions using PCFs (ms03 supportpac) */
/* */
/*===========================================================================*/
/* Include standard libraries */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* Include MQSeries headers */
#include <cmqc.h>
#include <cmqcfc.h>
#include <cmqxc.h>
/* Include Application headers */
#include "saveqmgr.h"
#include "mqutils.h"
/* If this isn't v6, don't bother compiling anything */
#if defined (zzMQV60)
/* ------------------------------------------------------------------------ */
/* ProcessServiceStringParm() */
/* ProcessServiceIntegerParm() */
/* */
/* These two processes are given a pointer to a block of storage that */
/* contains the definition of a single attribute relating to an individual */
/* Listener. The first handles string parameters, the second integer. */
/* The calling process has already decided which type of parameter this is */
/* and is responsible for managing the storage. These procedures decide */
/* which of the possible attributes this one is and extract the value. */
/* */
/* Follows is a list of all attributes possible for a process definition. */
/* */
/* The ProcDefn structure contains entries for each of the attributes. */
/* ------------------------------------------------------------------------ */
extern int noisy;
extern int header;
extern int oneLine; /* v601 -- whether to write the entire DEFINE on oneline */
extern char lineTerm[3]; /* v601 -- line terminator */
void ProcessServiceStringParm( MQCFST *pPCFString
, ServiceParms *ServiceDefn
, MQLONG *iCC
)
{
/* Initialise return codes */
*iCC = MQCC_OK;
switch ( pPCFString->Parameter ) {
case MQCA_SERVICE_NAME:
memset( ServiceDefn->ServiceName
, ' ', MQ_SERVICE_NAME_LENGTH );
memcpy( ServiceDefn->ServiceName
, pPCFString->String, pPCFString->StringLength );
break;
case MQCA_SERVICE_DESC:
memset( ServiceDefn->ServiceDesc
, ' ', MQ_SERVICE_DESC_LENGTH );
memcpy( ServiceDefn->ServiceDesc
, pPCFString->String, pPCFString->StringLength );
break;
case MQCA_ALTERATION_DATE:
memset( ServiceDefn->AlterationDate
, ' ', MQ_CREATION_DATE_LENGTH );
memcpy( ServiceDefn->AlterationDate
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_ALTERATION_TIME:
memset( ServiceDefn->AlterationTime
, ' ', MQ_CREATION_TIME_LENGTH );
memcpy( ServiceDefn->AlterationTime
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_SERVICE_START_COMMAND:
memset( ServiceDefn->StartCommand
, ' ', MQ_SERVICE_COMMAND_LENGTH );
memcpy( ServiceDefn->StartCommand
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_SERVICE_START_ARGS:
memset( ServiceDefn->StartArgs
, ' ', MQ_SERVICE_ARGS_LENGTH );
memcpy( ServiceDefn->StartArgs
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_SERVICE_STOP_COMMAND:
memset( ServiceDefn->StopCommand
, ' ', MQ_SERVICE_COMMAND_LENGTH );
memcpy( ServiceDefn->StopCommand
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_SERVICE_STOP_ARGS:
memset( ServiceDefn->StopArgs
, ' ', MQ_SERVICE_ARGS_LENGTH );
memcpy( ServiceDefn->StopArgs
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_STDOUT_DESTINATION:
memset( ServiceDefn->StdoutDestination
, ' ', sizeof(ServiceDefn->StdoutDestination) );
memcpy( ServiceDefn->StdoutDestination
, pPCFString->String, pPCFString->StringLength);
break;
case MQCA_STDERR_DESTINATION:
memset( ServiceDefn->StderrDestination
, ' ', sizeof(ServiceDefn->StderrDestination) );
memcpy( ServiceDefn->StderrDestination
, pPCFString->String, pPCFString->StringLength);
break;
default:
if(noisy) fprintf(stderr, "(services.c) Unknown PCF String Parameter: %ld\n",
pPCFString->Parameter);
*iCC = WARNING;
break;
} /* endswitch */
return;
}
/*************************************************************/
void ProcessServiceIntegerParm( MQCFIN *pPCFInteger
, ServiceParms *ServiceDefn
, MQLONG *iCC
)
{
/* Initialise return codes */
*iCC = MQCC_OK;
switch ( pPCFInteger->Parameter ) {
case MQIA_SERVICE_CONTROL:
ServiceDefn->Control = pPCFInteger->Value;
break;
case MQIA_SERVICE_TYPE:
ServiceDefn->ServiceType = pPCFInteger->Value;
break;
default:
if(noisy) fprintf(stderr, "(services.c) Unknown PCF Integer Parameter: %ld\n",
pPCFInteger->Parameter);
*iCC = WARNING;
break;
} /* endswitch */
return;
}
/* ------------------------------------------------------------------------ */
/* */
/* This process takes the attributes of a single process and adds them */
/* to the end of a file, SAVEQMGR.TST, which can be found in the current */
/* directory. */
/* */
/* The file is of a format suitable for subsequent input to RUNMQSC. */
/* */
/* ------------------------------------------------------------------------ */
void AddToFileSERVICE(
ServiceParms *pServiceDefn,
int UserVersion,
char * fileName, /* v32 Name of the output file */
FILE * fp, /* v51 */
int twolines,
MQLONG *iCC )
{
char * ParmBuffer; /* Temporary buffer to hold for output to file */
char work[256];
int options = 0;
/* Initialise return codes */
*iCC = MQCC_OK;
/* v601 setup options for oneLine operation */
options = MQSPRINTF_X_DOUBLE_QUOTES + MQSPRINTF_X_NO_TRAILING_BLANKS;
if (!oneLine) options += MQSPRINTF_X_LINE_BREAKS;
if ( !( ParmBuffer = (char *) malloc (PBSIZE) )) {
fprintf (stderr, "(services.c) Failed to allocate %d bytes \n", PBSIZE);
exit(2);
}
if (twolines) fputs("* ", fp);
MQsprintf_X( ParmBuffer
, "DEFINE SERVICE ('%s') "
, pServiceDefn->ServiceName
, MQ_SERVICE_NAME_LENGTH
, options
);
fputs( ParmBuffer, fp );
if (header && (!oneLine|| twolines)) {
MQsprintf_X( ParmBuffer, "* ALTDATE (%s) ",
pServiceDefn->AlterationDate,
MQ_CREATION_DATE_LENGTH, options);
fputs( ParmBuffer, fp);
MQsprintf_X( ParmBuffer, "* ALTTIME (%s) ",
pServiceDefn->AlterationTime,
MQ_CREATION_TIME_LENGTH, options);
fputs( ParmBuffer, fp);
}
MQsprintf_X( ParmBuffer
, " DESCR('%s') "
, pServiceDefn->ServiceDesc
, MQ_SERVICE_DESC_LENGTH
, options
);
fputs( ParmBuffer, fp );
MQsprintf_X( ParmBuffer
, " STARTCMD('%s') "
, pServiceDefn->StartCommand
, MQ_SERVICE_COMMAND_LENGTH
, options
);
fputs( ParmBuffer, fp );
MQsprintf_X( ParmBuffer
, " STARTARG('%s') "
, pServiceDefn->StartArgs
, MQ_SERVICE_ARGS_LENGTH
, options
);
fputs( ParmBuffer, fp );
MQsprintf_X( ParmBuffer
, " STOPCMD('%s') "
, pServiceDefn->StopCommand
, MQ_SERVICE_COMMAND_LENGTH
, options
);
fputs( ParmBuffer, fp );
MQsprintf_X( ParmBuffer
, " STOPARG('%s') "
, pServiceDefn->StopArgs
, MQ_SERVICE_ARGS_LENGTH
, options
);
fputs( ParmBuffer, fp );
MQsprintf_X( ParmBuffer
, " STDOUT('%s') "
, pServiceDefn->StdoutDestination
, MQ_SERVICE_PATH_LENGTH
, options
);
fputs( ParmBuffer, fp );
MQsprintf_X( ParmBuffer
, " STDERR('%s') "
, pServiceDefn->StderrDestination
, MQ_SERVICE_PATH_LENGTH
, options
);
fputs( ParmBuffer, fp );
toStrMQSVC((char*)&work , pServiceDefn->Control);
sprintf( ParmBuffer, " CONTROL(%s) %s", work, lineTerm);
fputs( ParmBuffer, fp );
sprintf( ParmBuffer, " SERVTYPE(%s) %s",
pServiceDefn->ServiceType==MQSVC_TYPE_COMMAND?"COMMAND":"SERVER", lineTerm);
fputs( ParmBuffer, fp );
fputs( " REPLACE\n", fp );
if (!oneLine) {
fputs("\n", fp);
}
free (ParmBuffer);
return;
}
/* end of don't compile anything */
#endif