-
Notifications
You must be signed in to change notification settings - Fork 62
/
mqiMQOD.go
217 lines (179 loc) · 6.66 KB
/
mqiMQOD.go
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
package ibmmq
/*
Copyright (c) IBM Corporation 2016
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
Mark Taylor - Initial Contribution
*/
/*
#include <stdlib.h>
#include <string.h>
#include <cmqc.h>
*/
import "C"
import (
"bytes"
"unsafe"
)
/*
MQOD is a structure containing the MQ Object Descriptor (MQOD)
*/
type MQOD struct {
Version int32
ObjectType int32
ObjectName string
ObjectQMgrName string
DynamicQName string
AlternateUserId string
// TODO: These fields are not currently mapped. The Dist List feature is not
// really supported here as Pub/Sub is the recommended approach.
//RecsPresent int32
//KnownDestCount int32
//UnknownDestCount int32
//InvalidDestCount int32
//ObjectRec []MQOR
//ResponseRec []MQOR
AlternateSecurityId []byte
ResolvedQName string
ResolvedQMgrName string
ObjectString string
SelectionString string
ResObjectString string
ResolvedType int32
}
/*
NewMQOD fills in default values for the MQOD structure
*/
func NewMQOD() *MQOD {
od := new(MQOD)
od.Version = 1
od.ObjectType = C.MQOT_Q
od.ObjectName = ""
od.ObjectQMgrName = ""
od.DynamicQName = "AMQ.*"
od.AlternateUserId = ""
od.AlternateSecurityId = bytes.Repeat([]byte{0}, C.MQ_SECURITY_ID_LENGTH)
od.ResolvedQName = ""
od.ResolvedQMgrName = ""
od.ObjectString = ""
od.SelectionString = ""
od.ResObjectString = ""
od.ResolvedType = C.MQOT_NONE
return od
}
func checkOD(good *MQOD, verb string) error {
mqrc := C.MQRC_NONE
if len(good.AlternateSecurityId) != C.MQ_SECURITY_ID_LENGTH {
mqrc = C.MQRC_OD_ERROR
}
if mqrc != C.MQRC_NONE {
mqreturn := MQReturn{MQCC: C.MQCC_FAILED,
MQRC: int32(mqrc),
verb: verb,
}
return &mqreturn
}
return nil
}
/*
* It is expected that copyXXtoC and copyXXfromC will be called as
* matching pairs. That means that we can handle the MQCHARV type
* by allocating storage in the toC function and freeing it in fromC.
* If the input string for an MQCHARV type is empty, then we allocate
* a fixed length buffer for any potential output.
*
* In the fromC function, that buffer is freed. Conveniently, we can
* free it always, because if we didn't explicitly call malloc(), it was
* allocated by C.CString and still needs to be freed.
*/
func copyODtoC(mqod *C.MQOD, good *MQOD) {
var i int
const vsbufsize = 10240
setMQIString((*C.char)(&mqod.StrucId[0]), "OD ", 4)
mqod.Version = C.MQLONG(good.Version)
mqod.ObjectType = C.MQLONG(good.ObjectType)
setMQIString((*C.char)(&mqod.ObjectName[0]), good.ObjectName, C.MQ_OBJECT_NAME_LENGTH)
setMQIString((*C.char)(&mqod.ObjectQMgrName[0]), good.ObjectQMgrName, C.MQ_OBJECT_NAME_LENGTH)
setMQIString((*C.char)(&mqod.DynamicQName[0]), good.DynamicQName, C.MQ_OBJECT_NAME_LENGTH)
setMQIString((*C.char)(&mqod.AlternateUserId[0]), good.AlternateUserId, C.MQ_USER_ID_LENGTH)
mqod.RecsPresent = 0
mqod.KnownDestCount = 0
mqod.UnknownDestCount = 0
mqod.InvalidDestCount = 0
mqod.ObjectRecOffset = 0
mqod.ResponseRecOffset = 0
mqod.ObjectRecPtr = nil
mqod.ResponseRecPtr = nil
for i = 0; i < C.MQ_SECURITY_ID_LENGTH; i++ {
mqod.AlternateSecurityId[i] = C.MQBYTE(good.AlternateSecurityId[i])
}
setMQIString((*C.char)(&mqod.ResolvedQName[0]), good.ResolvedQName, C.MQ_OBJECT_NAME_LENGTH)
setMQIString((*C.char)(&mqod.ResolvedQMgrName[0]), good.ResolvedQMgrName, C.MQ_OBJECT_NAME_LENGTH)
mqod.ObjectString.VSLength = (C.MQLONG)(len(good.ObjectString))
mqod.ObjectString.VSCCSID = C.MQCCSI_APPL
if mqod.ObjectString.VSLength == 0 {
mqod.ObjectString.VSPtr = C.MQPTR(C.malloc(vsbufsize))
mqod.ObjectString.VSBufSize = vsbufsize
} else {
mqod.ObjectString.VSPtr = (C.MQPTR)(C.CString(good.ObjectString))
}
mqod.SelectionString.VSLength = (C.MQLONG)(len(good.SelectionString))
mqod.SelectionString.VSCCSID = C.MQCCSI_APPL
if mqod.SelectionString.VSLength == 0 {
mqod.SelectionString.VSPtr = C.MQPTR(C.malloc(vsbufsize))
mqod.SelectionString.VSBufSize = vsbufsize
} else {
mqod.SelectionString.VSPtr = (C.MQPTR)(C.CString(good.SelectionString))
}
if mqod.SelectionString.VSLength > 0 || mqod.ObjectString.VSLength > 0 {
if mqod.Version < C.MQOD_VERSION_4 {
mqod.Version = C.MQOD_VERSION_4
}
}
mqod.ResObjectString.VSLength = (C.MQLONG)(len(good.ResObjectString))
mqod.ResObjectString.VSCCSID = C.MQCCSI_APPL
if mqod.ResObjectString.VSLength == 0 {
mqod.ResObjectString.VSPtr = C.MQPTR(C.malloc(vsbufsize))
mqod.ResObjectString.VSBufSize = vsbufsize
} else {
mqod.ResObjectString.VSPtr = (C.MQPTR)(C.CString(good.ResObjectString))
}
mqod.ResolvedType = C.MQLONG(good.ResolvedType)
return
}
func copyODfromC(mqod *C.MQOD, good *MQOD) {
var i int
good.Version = int32(mqod.Version)
good.ObjectType = int32(mqod.ObjectType)
good.ObjectName = trimStringN((*C.char)(&mqod.ObjectName[0]), C.MQ_OBJECT_NAME_LENGTH)
good.ObjectQMgrName = trimStringN((*C.char)(&mqod.ObjectQMgrName[0]), C.MQ_OBJECT_NAME_LENGTH)
good.DynamicQName = trimStringN((*C.char)(&mqod.DynamicQName[0]), C.MQ_OBJECT_NAME_LENGTH)
good.AlternateUserId = trimStringN((*C.char)(&mqod.AlternateUserId[0]), C.MQ_USER_ID_LENGTH)
//good.RecsPresent = int32(mqod.RecsPresent)
//good.KnownDestCount = int32(mqod.KnownDestCount)
//good.UnknownDestCount = int32(mqod.UnknownDestCount)
//good.InvalidDestCount = int32(mqod.InvalidDestCount)
//good.ObjectRecPtr = mqod.ObjectRecPtr
//good.ResponseRecPtr = mqod.ResponseRecPtr
for i = 0; i < C.MQ_SECURITY_ID_LENGTH; i++ {
good.AlternateSecurityId[i] = (byte)(mqod.AlternateSecurityId[i])
}
good.ResolvedQName = trimStringN((*C.char)(&mqod.ResolvedQName[0]), C.MQ_OBJECT_NAME_LENGTH)
good.ResolvedQMgrName = trimStringN((*C.char)(&mqod.ResolvedQMgrName[0]), C.MQ_OBJECT_NAME_LENGTH)
good.ObjectString = trimStringN((*C.char)(mqod.ObjectString.VSPtr), (C.int)(mqod.ObjectString.VSLength))
C.free(unsafe.Pointer(mqod.ObjectString.VSPtr))
good.SelectionString = trimStringN((*C.char)(mqod.SelectionString.VSPtr), (C.int)(mqod.SelectionString.VSLength))
C.free(unsafe.Pointer(mqod.SelectionString.VSPtr))
good.ResObjectString = trimStringN((*C.char)(mqod.ResObjectString.VSPtr), (C.int)(mqod.ResObjectString.VSLength))
C.free(unsafe.Pointer(mqod.ResObjectString.VSPtr))
good.ResolvedType = int32(mqod.ResolvedType)
return
}