ferocia-rubywmq 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +8 -0
- data/LICENSE +13 -0
- data/Manifest.txt +20 -0
- data/README +73 -0
- data/examples/each_a.rb +32 -0
- data/examples/each_b.rb +41 -0
- data/examples/each_header.rb +38 -0
- data/examples/files_to_q.cfg +24 -0
- data/examples/files_to_q.rb +47 -0
- data/examples/get_a.rb +35 -0
- data/examples/get_client.rb +51 -0
- data/examples/put1_a.rb +25 -0
- data/examples/put1_b.rb +33 -0
- data/examples/put1_c.rb +32 -0
- data/examples/put_a.rb +35 -0
- data/examples/put_b.rb +43 -0
- data/examples/put_dlh.rb +41 -0
- data/examples/put_dynamic_q.rb +38 -0
- data/examples/put_group_a.rb +51 -0
- data/examples/put_group_b.rb +53 -0
- data/examples/put_rfh.rb +67 -0
- data/examples/put_rfh2_a.rb +43 -0
- data/examples/put_rfh2_b.rb +43 -0
- data/examples/put_xmit_q.rb +33 -0
- data/examples/q_to_files.cfg +17 -0
- data/examples/q_to_files.rb +48 -0
- data/examples/request.rb +60 -0
- data/examples/server.rb +97 -0
- data/ext/build.bat +3 -0
- data/ext/build.sh +6 -0
- data/ext/decode_rfh.c +348 -0
- data/ext/decode_rfh.h +45 -0
- data/ext/extconf.rb +44 -0
- data/ext/extconf_client.rb +40 -0
- data/ext/generate/generate_const.rb +167 -0
- data/ext/generate/generate_reason.rb +246 -0
- data/ext/generate/generate_structs.rb +97 -0
- data/ext/generate/wmq_structs.erb +371 -0
- data/ext/lib/wmq_temp.rb +197 -0
- data/ext/wmq.c +93 -0
- data/ext/wmq.h +367 -0
- data/ext/wmq_message.c +671 -0
- data/ext/wmq_mq_load.c +217 -0
- data/ext/wmq_queue.c +1411 -0
- data/ext/wmq_queue_manager.c +1587 -0
- data/lib/wmq.rb +25 -0
- data/rubywmq.binary.gemspec +32 -0
- data/rubywmq.gemspec +33 -0
- data/tests/test.rb +328 -0
- metadata +124 -0
data/ext/decode_rfh.c
ADDED
@@ -0,0 +1,348 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007 Edwin M. Fine, Fine Computer Consultants, Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
5
|
+
* (the "License"); you may not use this file except
|
6
|
+
* in compliance with the License. You may obtain a copy
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
* Unless required by applicable law or agreed to in writing,
|
9
|
+
* software distributed under the License is distributed on an
|
10
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
11
|
+
* either express or implied. See the License for the specific
|
12
|
+
* language governing permissions and limitations under the License.
|
13
|
+
*/
|
14
|
+
|
15
|
+
/*
|
16
|
+
* This function decodes an RFH NameValueString into separate
|
17
|
+
* name/value strings and invokes a callback function for each
|
18
|
+
* name/value pair. The callback function prototype is
|
19
|
+
*
|
20
|
+
* void cbfunc(const char *name, const char *value);
|
21
|
+
*
|
22
|
+
* Strings are expected to be null-terminated and not contain any
|
23
|
+
* null characters.
|
24
|
+
*
|
25
|
+
* This is the specification for NameValueString:
|
26
|
+
*
|
27
|
+
* NameValueString (MQCHARn)
|
28
|
+
*
|
29
|
+
* String containing name/value pairs.
|
30
|
+
*
|
31
|
+
* This is a variable-length character string containing name/value
|
32
|
+
* pairs in the form:
|
33
|
+
*
|
34
|
+
* name1 value1 name2 value2 name3 value3 ...
|
35
|
+
*
|
36
|
+
* Each name or value must be separated from the adjacent name
|
37
|
+
* or value by one or more blank characters; these blanks are
|
38
|
+
* not significant. A name or value can contain significant
|
39
|
+
* blanks by prefixing and suffixing the name or value with the
|
40
|
+
* double-quote character; all characters between the open
|
41
|
+
* double-quote and the matching close double-quote are treated
|
42
|
+
* as significant. In the following example, the name is
|
43
|
+
* FAMOUS_WORDS, and the value is Hello World:
|
44
|
+
*
|
45
|
+
* FAMOUS_WORDS "Hello World"
|
46
|
+
*
|
47
|
+
* A name or value can contain any characters other than the
|
48
|
+
* null character (which acts as a delimiter for
|
49
|
+
* NameValueString). However, to assist interoperability, an
|
50
|
+
* application might prefer to restrict names to the following
|
51
|
+
* characters:
|
52
|
+
*
|
53
|
+
* * First character: upper case or lower case alphabetic (A
|
54
|
+
* through Z, or a through z), or underscore.
|
55
|
+
*
|
56
|
+
* * Second character: upper case or lower case alphabetic,
|
57
|
+
* decimal digit (0 through 9), underscore, hyphen, or
|
58
|
+
* dot.
|
59
|
+
*
|
60
|
+
* If a name or value contains one or more double-quote
|
61
|
+
* characters, the name or value must be enclosed in double
|
62
|
+
* quotes, and each double quote within the string must be
|
63
|
+
* doubled, for example:
|
64
|
+
*
|
65
|
+
* Famous_Words "The program displayed ""Hello World"""
|
66
|
+
*
|
67
|
+
* Names and values are case sensitive, that is, lowercase
|
68
|
+
* letters are not considered to be the same as uppercase
|
69
|
+
* letters. For example, FAMOUS_WORDS and Famous_Words are two
|
70
|
+
* different names. / The length in bytes of NameValueString is
|
71
|
+
* equal to StrucLength minus MQRFH_STRUC_LENGTH_FIXED. To avoid
|
72
|
+
* problems with data conversion of the user data in some
|
73
|
+
* environments, make sure that this length is a multiple of
|
74
|
+
* four. NameValueString must be padded with blanks to this
|
75
|
+
* length, or terminated earlier by placing a null character
|
76
|
+
* following the last value in the string. The null and bytes
|
77
|
+
* following it, up to the specified length of NameValueString,
|
78
|
+
* are ignored.
|
79
|
+
*/
|
80
|
+
|
81
|
+
#include "decode_rfh.h"
|
82
|
+
#include <stdio.h>
|
83
|
+
|
84
|
+
#define MAX_TOK_LEN 1024 /* This is pretty generous */
|
85
|
+
#define EOS -1 /* End of input string */
|
86
|
+
#define QUOTE '"'
|
87
|
+
|
88
|
+
#define IS_SEPARATOR(ch) ((ch) == ' ' || (ch) == '\0')
|
89
|
+
#define IS_VALID_ID_CHAR(ch) (!IS_SEPARATOR(ch))
|
90
|
+
#define IS_UNQUOTED_ID_CHAR(ch) (!IS_SEPARATOR(ch) && ch != QUOTE)
|
91
|
+
#define GETCHAR(charp, endp) ((charp) < (endp) ? (int)*charp++ : EOS)
|
92
|
+
#define LOOKAHEAD(charp, endp) (charp < endp - 1 ? (int)*charp : EOS)
|
93
|
+
#define PUSHBACK(ch, charp) (*--charp = (char)ch)
|
94
|
+
|
95
|
+
#define SKIP_SEPARATORS(charp, endp) \
|
96
|
+
while (charp < endp && IS_SEPARATOR(*charp)) ++charp
|
97
|
+
|
98
|
+
typedef enum {
|
99
|
+
ST_INITIAL,
|
100
|
+
ST_IN_QUOTED_ID,
|
101
|
+
ST_IN_UNQUOTED_ID,
|
102
|
+
ST_END,
|
103
|
+
} state_t;
|
104
|
+
|
105
|
+
static int debug_mode = 0;
|
106
|
+
|
107
|
+
int rfh_in_debug_mode(void)
|
108
|
+
{
|
109
|
+
return debug_mode;
|
110
|
+
}
|
111
|
+
|
112
|
+
void rfh_set_debug_mode(int on_if_true)
|
113
|
+
{
|
114
|
+
debug_mode = on_if_true;
|
115
|
+
}
|
116
|
+
|
117
|
+
#define ENUM_TUPLE(enum_val) { enum_val, #enum_val }
|
118
|
+
#define NUM_ELEMS(arr) (sizeof(arr) / sizeof(*arr))
|
119
|
+
|
120
|
+
static const char *rfh_state_to_s(state_t state)
|
121
|
+
{
|
122
|
+
static struct
|
123
|
+
{
|
124
|
+
state_t state;
|
125
|
+
const char *str;
|
126
|
+
} state_map[] =
|
127
|
+
{
|
128
|
+
ENUM_TUPLE(ST_INITIAL),
|
129
|
+
ENUM_TUPLE(ST_IN_QUOTED_ID),
|
130
|
+
ENUM_TUPLE(ST_IN_UNQUOTED_ID),
|
131
|
+
ENUM_TUPLE(ST_END),
|
132
|
+
};
|
133
|
+
|
134
|
+
size_t i;
|
135
|
+
|
136
|
+
for (i = 0; i < NUM_ELEMS(state_map); ++i)
|
137
|
+
if (state_map[i].state == state)
|
138
|
+
return state_map[i].str;
|
139
|
+
|
140
|
+
return "";
|
141
|
+
}
|
142
|
+
|
143
|
+
const char *rfh_toktype_to_s(rfh_toktype_t toktype)
|
144
|
+
{
|
145
|
+
static struct
|
146
|
+
{
|
147
|
+
rfh_toktype_t toktype;
|
148
|
+
const char *str;
|
149
|
+
} toktype_map[] =
|
150
|
+
{
|
151
|
+
ENUM_TUPLE(TT_TOKEN),
|
152
|
+
ENUM_TUPLE(TT_UNESCAPED_QUOTE),
|
153
|
+
ENUM_TUPLE(TT_ILLEGAL_QUOTE),
|
154
|
+
ENUM_TUPLE(TT_UNEXPECTED_EOS),
|
155
|
+
ENUM_TUPLE(TT_TOKEN_TRUNCATED),
|
156
|
+
ENUM_TUPLE(TT_INTERNAL_ERROR),
|
157
|
+
ENUM_TUPLE(TT_ALLOC_FAILURE),
|
158
|
+
ENUM_TUPLE(TT_END),
|
159
|
+
};
|
160
|
+
|
161
|
+
size_t i;
|
162
|
+
|
163
|
+
for (i = 0; i < NUM_ELEMS(toktype_map); ++i)
|
164
|
+
if (toktype_map[i].toktype == toktype)
|
165
|
+
return toktype_map[i].str;
|
166
|
+
|
167
|
+
return "";
|
168
|
+
}
|
169
|
+
|
170
|
+
static rfh_toktype_t get_token(const char **charpp, const char *endp, char *token, char *end_token)
|
171
|
+
{
|
172
|
+
const char *charp = *charpp;
|
173
|
+
char *tokp = token;
|
174
|
+
int ch;
|
175
|
+
state_t state = ST_INITIAL;
|
176
|
+
rfh_toktype_t toktype = TT_TOKEN;
|
177
|
+
|
178
|
+
SKIP_SEPARATORS(charp, endp);
|
179
|
+
|
180
|
+
while (state != ST_END && tokp < end_token)
|
181
|
+
{
|
182
|
+
ch = GETCHAR(charp, endp);
|
183
|
+
|
184
|
+
if (debug_mode)
|
185
|
+
fprintf(stderr, "state = %s, char = %c [%d]\n", rfh_state_to_s(state), (char)ch, ch);
|
186
|
+
|
187
|
+
switch (state)
|
188
|
+
{
|
189
|
+
case ST_INITIAL:
|
190
|
+
if (ch == EOS)
|
191
|
+
{
|
192
|
+
*tokp = '\0';
|
193
|
+
toktype = TT_END;
|
194
|
+
state = ST_END;
|
195
|
+
if (debug_mode)
|
196
|
+
fprintf(stderr, "new state = %s, toktype = %s\n",
|
197
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype));
|
198
|
+
}
|
199
|
+
else if (IS_UNQUOTED_ID_CHAR(ch))
|
200
|
+
{
|
201
|
+
*tokp++ = (char)ch;
|
202
|
+
state = ST_IN_UNQUOTED_ID;
|
203
|
+
if (debug_mode)
|
204
|
+
fprintf(stderr, "new state = %s\n", rfh_state_to_s(state));
|
205
|
+
}
|
206
|
+
else if (ch == QUOTE)
|
207
|
+
{
|
208
|
+
state = ST_IN_QUOTED_ID;
|
209
|
+
if (debug_mode)
|
210
|
+
fprintf(stderr, "new state = %s\n", rfh_state_to_s(state));
|
211
|
+
}
|
212
|
+
break;
|
213
|
+
|
214
|
+
case ST_IN_UNQUOTED_ID:
|
215
|
+
if (IS_SEPARATOR(ch) || ch == EOS)
|
216
|
+
{
|
217
|
+
*tokp = '\0';
|
218
|
+
state = ST_END;
|
219
|
+
if (debug_mode)
|
220
|
+
fprintf(stderr, "new state = %s\n", rfh_state_to_s(state));
|
221
|
+
}
|
222
|
+
else if (ch == QUOTE) /* Not allowed in unquoted string */
|
223
|
+
{
|
224
|
+
toktype = TT_ILLEGAL_QUOTE;
|
225
|
+
state = ST_END;
|
226
|
+
if (debug_mode)
|
227
|
+
fprintf(stderr, "new state = %s, toktype = %s\n",
|
228
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype));
|
229
|
+
}
|
230
|
+
else
|
231
|
+
*tokp++ = (char)ch;
|
232
|
+
break;
|
233
|
+
|
234
|
+
case ST_IN_QUOTED_ID:
|
235
|
+
if (ch == QUOTE) /* Could be end of token, or first char of "" */
|
236
|
+
{
|
237
|
+
int lookahead_ch = LOOKAHEAD(charp, endp);
|
238
|
+
if (lookahead_ch == QUOTE) /* Found escaped quote */
|
239
|
+
{
|
240
|
+
*tokp++ = QUOTE;
|
241
|
+
++charp; /* Skip second quote */
|
242
|
+
}
|
243
|
+
else if (IS_SEPARATOR(lookahead_ch) || lookahead_ch == EOS) /* End of token */
|
244
|
+
{
|
245
|
+
*tokp = '\0';
|
246
|
+
state = ST_END;
|
247
|
+
if (debug_mode)
|
248
|
+
fprintf(stderr, "new state = %s\n", rfh_state_to_s(state));
|
249
|
+
}
|
250
|
+
else /* Error: Unescaped quote */
|
251
|
+
{
|
252
|
+
toktype = TT_UNESCAPED_QUOTE;
|
253
|
+
state = ST_END;
|
254
|
+
if (debug_mode)
|
255
|
+
fprintf(stderr, "new state = %s, toktype = %s\n",
|
256
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype));
|
257
|
+
}
|
258
|
+
}
|
259
|
+
else if (ch == EOS) /* Error */
|
260
|
+
{
|
261
|
+
toktype = TT_UNEXPECTED_EOS;
|
262
|
+
state = ST_END;
|
263
|
+
if (debug_mode)
|
264
|
+
fprintf(stderr, "new state = %s, toktype = %s\n",
|
265
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype));
|
266
|
+
}
|
267
|
+
else
|
268
|
+
*tokp++ = (char)ch;
|
269
|
+
break;
|
270
|
+
|
271
|
+
default:
|
272
|
+
toktype = TT_INTERNAL_ERROR;
|
273
|
+
state = ST_END;
|
274
|
+
if (debug_mode)
|
275
|
+
fprintf(stderr, "new state = %s, toktype = %s\n",
|
276
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype));
|
277
|
+
break;
|
278
|
+
} /* switch */
|
279
|
+
} /* while */
|
280
|
+
|
281
|
+
/* If state is not ST_END, an error may have occurred */
|
282
|
+
if (state != ST_END && toktype == TT_TOKEN)
|
283
|
+
{
|
284
|
+
if (tokp >= end_token)
|
285
|
+
toktype = TT_TOKEN_TRUNCATED;
|
286
|
+
else
|
287
|
+
toktype = TT_UNEXPECTED_EOS;
|
288
|
+
|
289
|
+
if (debug_mode)
|
290
|
+
fprintf(stderr, "end state = %s, toktype = %s\n",
|
291
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype));
|
292
|
+
}
|
293
|
+
|
294
|
+
*charpp = charp;
|
295
|
+
|
296
|
+
if (debug_mode)
|
297
|
+
fprintf(stderr, "-- leaving; end state = %s, returned toktype = %s, returned token = [%s]\n",
|
298
|
+
rfh_state_to_s(state), rfh_toktype_to_s(toktype), token);
|
299
|
+
|
300
|
+
return toktype;
|
301
|
+
}
|
302
|
+
|
303
|
+
rfh_toktype_t rfh_decode_name_val_str(const char *nvstr, size_t len, CALLBACK_FN callback, void *user_data)
|
304
|
+
{
|
305
|
+
#if defined(USE_FIXED_BUFFERS)
|
306
|
+
char name[MAX_TOK_LEN + 1];
|
307
|
+
char value[MAX_TOK_LEN + 1];
|
308
|
+
size_t name_len = sizeof(name);
|
309
|
+
size_t value_len = sizeof(value);
|
310
|
+
#else
|
311
|
+
size_t name_len = len + 1;
|
312
|
+
size_t value_len = len + 1;
|
313
|
+
char *buf = (char *)malloc(len * 2 * sizeof(char) + 2);
|
314
|
+
char *name = buf;
|
315
|
+
char *value = buf + len + 1;
|
316
|
+
#endif
|
317
|
+
|
318
|
+
const char *charp = nvstr, *endp = nvstr + len;
|
319
|
+
rfh_toktype_t toktype;
|
320
|
+
|
321
|
+
#if !defined(USE_FIXED_BUFFERS)
|
322
|
+
if (buf == NULL) /* Out of mem */
|
323
|
+
return TT_ALLOC_FAILURE;
|
324
|
+
#endif
|
325
|
+
|
326
|
+
for (;;)
|
327
|
+
{
|
328
|
+
if ((toktype = get_token(&charp, endp, name, name + name_len)) != TT_TOKEN)
|
329
|
+
{
|
330
|
+
break;
|
331
|
+
}
|
332
|
+
|
333
|
+
if ((toktype = get_token(&charp, endp, value, value + value_len)) != TT_TOKEN)
|
334
|
+
{
|
335
|
+
if (toktype == TT_END) /* Expected a value! */
|
336
|
+
toktype = TT_UNEXPECTED_EOS;
|
337
|
+
break;
|
338
|
+
}
|
339
|
+
|
340
|
+
callback(name, value, user_data);
|
341
|
+
}
|
342
|
+
|
343
|
+
#if !defined(USE_FIXED_BUFFERS)
|
344
|
+
free(buf);
|
345
|
+
#endif
|
346
|
+
|
347
|
+
return toktype;
|
348
|
+
}
|
data/ext/decode_rfh.h
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2007 Edwin M. Fine, Fine Computer Consultants, Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0
|
5
|
+
* (the "License"); you may not use this file except
|
6
|
+
* in compliance with the License. You may obtain a copy
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
* Unless required by applicable law or agreed to in writing,
|
9
|
+
* software distributed under the License is distributed on an
|
10
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
11
|
+
* either express or implied. See the License for the specific
|
12
|
+
* language governing permissions and limitations under the License.
|
13
|
+
*/
|
14
|
+
#if !defined(DECODE_RFH_INCLUDED)
|
15
|
+
#define DECODE_RFH_INCLUDED
|
16
|
+
|
17
|
+
#include <stdlib.h> /* For size_t */
|
18
|
+
|
19
|
+
typedef void (*CALLBACK_FN)(const char *name, const char *value, void *user_data);
|
20
|
+
|
21
|
+
typedef enum {
|
22
|
+
TT_TOKEN,
|
23
|
+
TT_UNESCAPED_QUOTE, /* '"' not followed by '"' in quoted string */
|
24
|
+
TT_ILLEGAL_QUOTE, /* '"' in unquoted string */
|
25
|
+
TT_UNEXPECTED_EOS,
|
26
|
+
TT_TOKEN_TRUNCATED, /* Token buffer too short to receive full token */
|
27
|
+
TT_INTERNAL_ERROR,
|
28
|
+
TT_ALLOC_FAILURE,
|
29
|
+
TT_END
|
30
|
+
} rfh_toktype_t;
|
31
|
+
|
32
|
+
/* Returns TT_END on success, other on error */
|
33
|
+
rfh_toktype_t
|
34
|
+
rfh_decode_name_val_str(const char *nvstr,
|
35
|
+
size_t len,
|
36
|
+
CALLBACK_FN callback,
|
37
|
+
void *user_data);
|
38
|
+
|
39
|
+
/* Translates toktype_t to string */
|
40
|
+
const char *rfh_toktype_to_s(rfh_toktype_t toktype);
|
41
|
+
|
42
|
+
int rfh_in_debug_mode(void);
|
43
|
+
void rfh_set_debug_mode(int on_if_true);
|
44
|
+
|
45
|
+
#endif
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
require 'mkmf'
|
18
|
+
require_relative 'generate/generate_reason'
|
19
|
+
require_relative 'generate/generate_const'
|
20
|
+
require_relative 'generate/generate_structs'
|
21
|
+
|
22
|
+
include_path = ''
|
23
|
+
if RUBY_PLATFORM =~ /mswin32/
|
24
|
+
include_path = 'C:\Program Files\IBM\WebSphere MQ\Tools\c\include'
|
25
|
+
dir_config('mqm', include_path, '.')
|
26
|
+
else
|
27
|
+
include_path = '/opt/mqm/inc'
|
28
|
+
#dir_config('mqm', include_path, '/opt/mqm/lib')
|
29
|
+
end
|
30
|
+
|
31
|
+
have_header('cmqc.h')
|
32
|
+
|
33
|
+
# Check for WebSphere MQ Server library
|
34
|
+
unless (RUBY_PLATFORM =~ /win/i) || (RUBY_PLATFORM =~ /solaris/i) || (RUBY_PLATFORM =~ /linux/i)
|
35
|
+
have_library('mqm')
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generate Source Files
|
39
|
+
GenerateReason.generate(include_path+'/')
|
40
|
+
GenerateConst.generate(include_path+'/', 'lib')
|
41
|
+
GenerateStructs.new(include_path+'/', 'generate').generate
|
42
|
+
|
43
|
+
# Generate Makefile
|
44
|
+
create_makefile('wmq/wmq')
|
@@ -0,0 +1,40 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
################################################################################
|
16
|
+
|
17
|
+
#
|
18
|
+
# NOTE: Do NOT use this file unless the platform being requested is not supported
|
19
|
+
# directly by Ruby WMQ. Ruby WMQ already supports automatic dynamic loading on
|
20
|
+
# Windows, Solaris and Linux
|
21
|
+
#
|
22
|
+
require 'mkmf'
|
23
|
+
require '../../generate/generate_reason'
|
24
|
+
require '../../generate/generate_const'
|
25
|
+
require '../../generate/generate_structs'
|
26
|
+
|
27
|
+
include_path = ''
|
28
|
+
unless (RUBY_PLATFORM =~ /win/i) || (RUBY_PLATFORM =~ /solaris/i) || (RUBY_PLATFORM =~ /linux/i)
|
29
|
+
include_path = '/opt/mqm/inc'
|
30
|
+
dir_config('mqm', include_path, '/opt/mqm/lib')
|
31
|
+
have_library('mqic')
|
32
|
+
|
33
|
+
# Generate Source Files # Could check if not already present
|
34
|
+
GenerateReason.generate(include_path+'/')
|
35
|
+
GenerateConst.generate(include_path+'/', '../../lib/wmq')
|
36
|
+
GenerateStructs.new(include_path+'/', '../../generate').generate
|
37
|
+
|
38
|
+
have_header('cmqc.h')
|
39
|
+
create_makefile('wmq_client')
|
40
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
class GenerateConst
|
2
|
+
|
3
|
+
#Extract Constants from Header files
|
4
|
+
def GenerateConst.extract_const(filename, const_prefix, start_exp=nil, end_exp=nil)
|
5
|
+
@constants = []
|
6
|
+
active = if start_exp then false else true end # Sure there is a better way
|
7
|
+
File.open(filename) do |file|
|
8
|
+
file.each do |line|
|
9
|
+
line.rstrip!
|
10
|
+
if line.length > 0 # Skip empty lines
|
11
|
+
if active
|
12
|
+
break if start_exp && line.match(end_exp)
|
13
|
+
# Skip Comment lines, then check for a match
|
14
|
+
if (line !~ /^\s*\/\*/) && (match = /\s*#define\s+(#{const_prefix}\w+)[\(\s]+([-\\\w\dx\'\"\s]+)/.match(line))
|
15
|
+
@constants << [match[1], match[2]]
|
16
|
+
end
|
17
|
+
else
|
18
|
+
next unless line.match(start_exp)
|
19
|
+
active = true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@constants
|
25
|
+
end
|
26
|
+
|
27
|
+
#Extract MQ Constants from Header files
|
28
|
+
def GenerateConst.rb_const(filename, const_prefix, exclude_exp=nil)
|
29
|
+
str = ''
|
30
|
+
GenerateConst.extract_const(filename, const_prefix).each do |item|
|
31
|
+
const, val = item
|
32
|
+
next if const.include?('_STRUC_ID')
|
33
|
+
next if exclude_exp && const.match(exclude_exp)
|
34
|
+
if val.include?('"') || val.include?("'")
|
35
|
+
if match = val.match(/(\w+)/)
|
36
|
+
val = "'#{match[0]}'"
|
37
|
+
else
|
38
|
+
val = "''"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
str << " %-30s = #{val}\n" % const
|
42
|
+
end
|
43
|
+
str
|
44
|
+
end
|
45
|
+
|
46
|
+
def GenerateConst.config(filename, prefix)
|
47
|
+
str = "# WMQ::QueueManager execute commands\n"
|
48
|
+
str << "execute_commands:\n"
|
49
|
+
GenerateConst.extract_const(filename,prefix).each do |item|
|
50
|
+
name = item[0].gsub(prefix,'').downcase
|
51
|
+
str << " :%-26s " % "#{name}:"
|
52
|
+
match = name.match(/\w+?_([\w_]+)/)
|
53
|
+
str << ":#{match[1]}" if match
|
54
|
+
str << "\n"
|
55
|
+
end
|
56
|
+
str
|
57
|
+
end
|
58
|
+
|
59
|
+
def GenerateConst.wmq_const(path)
|
60
|
+
str = <<END_OF_STRING
|
61
|
+
################################################################################
|
62
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
63
|
+
#
|
64
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
65
|
+
# you may not use this file except in compliance with the License.
|
66
|
+
# You may obtain a copy of the License at
|
67
|
+
#
|
68
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
69
|
+
#
|
70
|
+
# Unless required by applicable law or agreed to in writing, software
|
71
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
72
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
73
|
+
# See the License for the specific language governing permissions and
|
74
|
+
# limitations under the License.
|
75
|
+
################################################################################
|
76
|
+
#
|
77
|
+
# WARNING: DO NOT MODIFY THIS FILE
|
78
|
+
#
|
79
|
+
# This file was generated by generate_const.rb.
|
80
|
+
#
|
81
|
+
################################################################################
|
82
|
+
module WMQ
|
83
|
+
END_OF_STRING
|
84
|
+
[ ['Connect Options','cmqc.h','MQCNO_',/(VERSION)|(CONN_TAG)|(HANDLE_SHARE)/],
|
85
|
+
['Open Options', 'cmqc.h','MQOO_' ],
|
86
|
+
['Close Options', 'cmqc.h','MQCO_'],
|
87
|
+
['Match Options', 'cmqc.h','MQMO_'],
|
88
|
+
['Message Format Options', 'cmqc.h','MQFMT_',/(_ARRAY)/],
|
89
|
+
['Get Message Options', 'cmqc.h','MQGMO_',/(VERSION)/],
|
90
|
+
['Transport Types', 'cmqxc.h','MQXPT_'] ,
|
91
|
+
['Report Options', 'cmqc.h', 'MQRO_'],
|
92
|
+
['Message Types', 'cmqc.h', 'MQMT_'],
|
93
|
+
['Expiry', 'cmqc.h', 'MQEI_'],
|
94
|
+
['Feedback Values', 'cmqc.h', 'MQFB_'],
|
95
|
+
['Encoding Values', 'cmqc.h', 'MQENC_'],
|
96
|
+
['Coded Character Set Identifiers', 'cmqc.h', 'MQCCSI_'],
|
97
|
+
['Priority', 'cmqc.h', 'MQPRI_'],
|
98
|
+
['Persistence', 'cmqc.h', 'MQPER_'],
|
99
|
+
['Put Application Types', 'cmqc.h', 'MQAT_'],
|
100
|
+
['Message Flags', 'cmqc.h', 'MQMF_'],
|
101
|
+
['Original Length', 'cmqc.h', 'MQOL_'],
|
102
|
+
['Put Message Options', 'cmqc.h', 'MQPMO_',/(VERSION)|(LENGTH)/],
|
103
|
+
['Put Message Record Fields', 'cmqc.h', 'MQPMRF_',/(VERSION)|(LENGTH)/],
|
104
|
+
['Reason Codes', 'cmqc.h','MQRC_'],
|
105
|
+
].each do |item|
|
106
|
+
str << "\n# #{item[0]}\n"
|
107
|
+
str << GenerateConst.rb_const("#{path}/#{item[1]}", item[2], item[3])
|
108
|
+
end
|
109
|
+
str << "end\n"
|
110
|
+
end
|
111
|
+
|
112
|
+
def GenerateConst.admin_consts(path)
|
113
|
+
str = <<END_OF_STRING
|
114
|
+
################################################################################
|
115
|
+
# Copyright 2006 J. Reid Morrison. Dimension Solutions, Inc.
|
116
|
+
#
|
117
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
118
|
+
# you may not use this file except in compliance with the License.
|
119
|
+
# You may obtain a copy of the License at
|
120
|
+
#
|
121
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
122
|
+
#
|
123
|
+
# Unless required by applicable law or agreed to in writing, software
|
124
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
125
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
126
|
+
# See the License for the specific language governing permissions and
|
127
|
+
# limitations under the License.
|
128
|
+
################################################################################
|
129
|
+
#
|
130
|
+
# WARNING: DO NOT MODIFY THIS FILE
|
131
|
+
#
|
132
|
+
# This file was generated by generate_const.rb.
|
133
|
+
#
|
134
|
+
################################################################################
|
135
|
+
module WMQ
|
136
|
+
END_OF_STRING
|
137
|
+
str << "# Admin constants from cmqc.h\n"
|
138
|
+
[ ['Object Types', 'cmqc.h', 'MQOT_'],
|
139
|
+
['Security Identifier Types', 'cmqc.h', 'MQSIDT_'],
|
140
|
+
['Channel Types', 'cmqxc.h', 'MQCHT_'],
|
141
|
+
].each do |item|
|
142
|
+
str << "\n# #{item[0]}\n"
|
143
|
+
str << GenerateConst.rb_const("#{path}/#{item[1]}", item[2], item[3])
|
144
|
+
end
|
145
|
+
GenerateConst.extract_const(path+'cmqc.h', 'MQ', /Queue\sAttributes/, /typedef/).each do |item|
|
146
|
+
str << " %-30s = #{item[1]}\n" % item[0]
|
147
|
+
end
|
148
|
+
str << "# Admin constants from cmqcfc.h\n"
|
149
|
+
GenerateConst.extract_const(path+'cmqcfc.h', 'MQ', /Parameter\s+Values/, /typedef\s+struct/).each do |item|
|
150
|
+
str << " %-30s = #{item[1]}\n" % item[0]
|
151
|
+
end
|
152
|
+
str << "end\n"
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.generate(path, target_path='')
|
156
|
+
File.open(File.join(target_path,'wmq_const_admin.rb'), 'w') {|file| file.write(GenerateConst.admin_consts(path))}
|
157
|
+
puts 'Generated wmq_const_admin.rb'
|
158
|
+
File.open(File.join(target_path,'wmq_const.rb'), 'w') {|file| file.write(GenerateConst.wmq_const(path))}
|
159
|
+
puts 'Generated wmq_const.rb'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
if $0 == __FILE__
|
164
|
+
path = ARGV[0] || raise("Mandatory parameter: 'WebSphere MQ Include path' is missing")
|
165
|
+
path = path + '/'
|
166
|
+
GenerateConst.generate(path)
|
167
|
+
end
|