| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | //go:build cgo && ibm_mq |
| 4 | |
| 5 | package pcf |
| 6 | |
| 7 | import ( |
| 8 | "strings" |
| 9 | |
| 10 | "github.com/ibm-messaging/mq-golang/v5/ibmmq" |
| 11 | ) |
| 12 | |
| 13 | // ChannelListResult contains the results of parsing channel list response |
| 14 | type ChannelListResult struct { |
| 15 | Channels []string // Successfully retrieved channel names |
| 16 | ErrorCounts map[int32]int // MQ error code -> count |
| 17 | ErrorChannels map[int32][]string // MQ error code -> channel names that failed |
| 18 | InternalErrors int // Count of parsing/internal errors |
| 19 | } |
| 20 | |
| 21 | // QueueListResult contains the results of parsing queue list response |
| 22 | type QueueListResult struct { |
| 23 | Queues []string // Successfully retrieved queue names |
| 24 | ErrorCounts map[int32]int // MQ error code -> count |
| 25 | ErrorQueues map[int32][]string // MQ error code -> queue names that failed |
| 26 | InternalErrors int // Count of parsing/internal errors |
| 27 | } |
| 28 | |
| 29 | // parseQueueListResponseFromParams parses PCF parameters into QueueListResult |
| 30 | func (c *Client) parseQueueListResponseFromParams(params []*ibmmq.PCFParameter) *QueueListResult { |
| 31 | result := &QueueListResult{ |
| 32 | Queues: []string{}, |
| 33 | ErrorCounts: make(map[int32]int), |
| 34 | ErrorQueues: make(map[int32][]string), |
| 35 | InternalErrors: 0, |
| 36 | } |
| 37 | |
| 38 | // Convert each parameter set (assuming it's a multi-object response) |
| 39 | for _, param := range params { |
| 40 | if param.Type == ibmmq.MQCFT_STRING && param.Parameter == ibmmq.MQCA_Q_NAME { |
| 41 | if len(param.String) > 0 { |
| 42 | queueName := strings.TrimSpace(param.String[0]) |
| 43 | if queueName != "" { |
| 44 | result.Queues = append(result.Queues, queueName) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return result |
| 51 | } |
| 52 | |
| 53 | // QueueListWithTypeResult contains the results of parsing queue list response with type information |
| 54 | type QueueListWithTypeResult struct { |
| 55 | Queues []QueueInfo // Successfully retrieved queues with type info |
| 56 | ErrorCounts map[int32]int // MQ error code -> count |
| 57 | ErrorQueues map[int32][]string // MQ error code -> queue names that failed |
| 58 | InternalErrors int // Count of parsing/internal errors |
| 59 | } |
| 60 | |
| 61 | // parseQueueListResponseWithTypeFromParams parses PCF parameters into QueueListWithTypeResult |
| 62 | func (c *Client) parseQueueListResponseWithTypeFromParams(params []*ibmmq.PCFParameter) *QueueListWithTypeResult { |
| 63 | result := &QueueListWithTypeResult{ |
| 64 | Queues: []QueueInfo{}, |
| 65 | ErrorCounts: make(map[int32]int), |
| 66 | ErrorQueues: make(map[int32][]string), |
| 67 | InternalErrors: 0, |
| 68 | } |
| 69 | |
| 70 | // Convert IBM PCFParameter array to attrs format for existing smart function |
| 71 | attrs := convertPCFParametersToAttrs(params) |
| 72 | |
| 73 | // Process queue attributes using existing logic |
| 74 | for _, param := range params { |
| 75 | if param.Type == ibmmq.MQCFT_STRING && param.Parameter == ibmmq.MQCA_Q_NAME { |
| 76 | if len(param.String) > 0 { |
| 77 | queueName := strings.TrimSpace(param.String[0]) |
| 78 | if queueName != "" { |
| 79 | // Create QueueInfo from attributes |
| 80 | queueInfo := QueueInfo{ |
| 81 | Name: queueName, |
| 82 | } |
| 83 | |
| 84 | // Extract type and configuration attributes |
| 85 | if qtype, ok := attrs[ibmmq.MQIA_Q_TYPE]; ok { |
| 86 | if qtypeInt, ok := qtype.(int32); ok { |
| 87 | queueInfo.Type = qtypeInt |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Set configuration attributes with NotCollected as default |
| 92 | queueInfo.InhibitGet = NotCollected |
| 93 | queueInfo.InhibitPut = NotCollected |
| 94 | queueInfo.BackoutThreshold = NotCollected |
| 95 | queueInfo.TriggerDepth = NotCollected |
| 96 | queueInfo.TriggerType = NotCollected |
| 97 | queueInfo.MaxMsgLength = NotCollected |
| 98 | queueInfo.DefPriority = NotCollected |
| 99 | |
| 100 | // Override with actual values if available |
| 101 | if val, ok := attrs[ibmmq.MQIA_INHIBIT_GET].(int32); ok { |
| 102 | queueInfo.InhibitGet = AttributeValue(val) |
| 103 | } |
| 104 | if val, ok := attrs[ibmmq.MQIA_INHIBIT_PUT].(int32); ok { |
| 105 | queueInfo.InhibitPut = AttributeValue(val) |
| 106 | } |
| 107 | if val, ok := attrs[ibmmq.MQIA_BACKOUT_THRESHOLD].(int32); ok { |
| 108 | queueInfo.BackoutThreshold = AttributeValue(val) |
| 109 | } |
| 110 | if val, ok := attrs[ibmmq.MQIA_TRIGGER_DEPTH].(int32); ok { |
| 111 | queueInfo.TriggerDepth = AttributeValue(val) |
| 112 | } |
| 113 | if val, ok := attrs[ibmmq.MQIA_TRIGGER_TYPE].(int32); ok { |
| 114 | queueInfo.TriggerType = AttributeValue(val) |
| 115 | } |
| 116 | if val, ok := attrs[ibmmq.MQIA_MAX_MSG_LENGTH].(int32); ok { |
| 117 | queueInfo.MaxMsgLength = AttributeValue(val) |
| 118 | } |
| 119 | if val, ok := attrs[ibmmq.MQIA_DEF_PRIORITY].(int32); ok { |
| 120 | queueInfo.DefPriority = AttributeValue(val) |
| 121 | } |
| 122 | |
| 123 | result.Queues = append(result.Queues, queueInfo) |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return result |
| 130 | } |
| 131 | |
| 132 | // TopicListResult contains the results of parsing topic list response |
| 133 | type TopicListResult struct { |
| 134 | Topics []string // Successfully retrieved topic names |
| 135 | ErrorCounts map[int32]int // MQ error code -> count |
| 136 | ErrorTopics map[int32][]string // MQ error code -> topic names that failed |
| 137 | InternalErrors int // Count of parsing/internal errors |
| 138 | } |
| 139 | |
| 140 | // parseTopicListResponseFromParams parses PCF parameters into TopicListResult |
| 141 | func (c *Client) parseTopicListResponseFromParams(params []*ibmmq.PCFParameter) *TopicListResult { |
| 142 | result := &TopicListResult{ |
| 143 | Topics: []string{}, |
| 144 | ErrorCounts: make(map[int32]int), |
| 145 | ErrorTopics: make(map[int32][]string), |
| 146 | InternalErrors: 0, |
| 147 | } |
| 148 | |
| 149 | // Process each parameter to extract topic names |
| 150 | for _, param := range params { |
| 151 | if param.Type == ibmmq.MQCFT_STRING && param.Parameter == ibmmq.MQCA_TOPIC_NAME { |
| 152 | if len(param.String) > 0 { |
| 153 | topicName := strings.TrimSpace(param.String[0]) |
| 154 | if topicName != "" { |
| 155 | result.Topics = append(result.Topics, topicName) |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return result |
| 162 | } |