| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | //go:build cgo && ibm_mq |
| 4 | |
| 5 | package pcf |
| 6 | |
| 7 | import ( |
| 8 | "fmt" |
| 9 | "strconv" |
| 10 | |
| 11 | "github.com/ibm-messaging/mq-golang/v5/ibmmq" |
| 12 | ) |
| 13 | |
| 14 | // mqcmdToString returns a human-readable name for MQCMD command constants |
| 15 | func mqcmdToString(command int32) string { |
| 16 | // Use the library's built-in function to get the string name |
| 17 | name := ibmmq.MQItoString("CMD", int(command)) |
| 18 | |
| 19 | // If the library returns a numeric string, it means the constant is unknown |
| 20 | if name == fmt.Sprintf("%d", command) { |
| 21 | return fmt.Sprintf("MQCMD_%d", command) |
| 22 | } |
| 23 | |
| 24 | // Return the full name with prefix for clarity |
| 25 | return name |
| 26 | } |
| 27 | |
| 28 | // mqReasonString returns a human-readable name for MQ reason codes |
| 29 | func mqReasonString(reason int32) string { |
| 30 | // First try RC (reason codes) |
| 31 | name := ibmmq.MQItoString("RC", int(reason)) |
| 32 | |
| 33 | // If RC didn't work, try RCCF (PCF reason codes) |
| 34 | if name == fmt.Sprintf("%d", reason) { |
| 35 | name = ibmmq.MQItoString("RCCF", int(reason)) |
| 36 | } |
| 37 | |
| 38 | // If still not found, return numeric format |
| 39 | if name == fmt.Sprintf("%d", reason) { |
| 40 | return fmt.Sprintf("MQRC_%d", reason) |
| 41 | } |
| 42 | |
| 43 | // Return the full name with prefix for clarity |
| 44 | return name |
| 45 | } |
| 46 | |
| 47 | func mqParameterToString(parameter int32) string { |
| 48 | paramStr := strconv.Itoa(int(parameter)) |
| 49 | |
| 50 | // Try integer attributes (includes MQIA_* and MQIACF_*) |
| 51 | name := ibmmq.MQItoString("IA", int(parameter)) |
| 52 | if name != "" && name != paramStr { |
| 53 | return name |
| 54 | } |
| 55 | |
| 56 | // Try character attributes (includes MQCA_* and MQCACF_*) |
| 57 | name = ibmmq.MQItoString("CA", int(parameter)) |
| 58 | if name != "" && name != paramStr { |
| 59 | return name |
| 60 | } |
| 61 | |
| 62 | // Try byte attributes |
| 63 | name = ibmmq.MQItoString("BACF", int(parameter)) |
| 64 | if name != "" && name != paramStr { |
| 65 | return name |
| 66 | } |
| 67 | |
| 68 | // Try group attributes |
| 69 | name = ibmmq.MQItoString("GACF", int(parameter)) |
| 70 | if name != "" && name != paramStr { |
| 71 | return name |
| 72 | } |
| 73 | |
| 74 | // Unknown parameter |
| 75 | return "PARAM_" + paramStr |
| 76 | } |
| 77 | |
| 78 | // mqOperatorToString returns a human-readable name for MQ filter operators |
| 79 | func mqOperatorToString(operator int32) string { |
| 80 | switch operator { |
| 81 | case ibmmq.MQCFOP_EQUAL: |
| 82 | return "EQ" |
| 83 | case ibmmq.MQCFOP_NOT_EQUAL: |
| 84 | return "NE" |
| 85 | case ibmmq.MQCFOP_LESS: |
| 86 | return "LT" |
| 87 | case ibmmq.MQCFOP_GREATER: |
| 88 | return "GT" |
| 89 | case ibmmq.MQCFOP_NOT_LESS: |
| 90 | return "GE" |
| 91 | case ibmmq.MQCFOP_NOT_GREATER: |
| 92 | return "LE" |
| 93 | case ibmmq.MQCFOP_LIKE: |
| 94 | return "LIKE" |
| 95 | case ibmmq.MQCFOP_NOT_LIKE: |
| 96 | return "NOT_LIKE" |
| 97 | case ibmmq.MQCFOP_CONTAINS: |
| 98 | return "CONTAINS" |
| 99 | case ibmmq.MQCFOP_EXCLUDES: |
| 100 | return "EXCLUDES" |
| 101 | default: |
| 102 | return fmt.Sprintf("OP_%d", operator) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // mqPCFTypeToString returns a human-readable name for PCF message types |
| 107 | func mqPCFTypeToString(msgType int32) string { |
| 108 | // Use the library's built-in function to get the string name |
| 109 | name := ibmmq.MQItoString("CFT", int(msgType)) |
| 110 | |
| 111 | // If the library returns a numeric string, it means the constant is unknown |
| 112 | if name == fmt.Sprintf("%d", msgType) { |
| 113 | return fmt.Sprintf("MQCFT_%d", msgType) |
| 114 | } |
| 115 | |
| 116 | // Return the full name with prefix for clarity |
| 117 | return name |
| 118 | } |
| 119 | |
| 120 | // mqPCFControlToString returns a human-readable name for PCF control options |
| 121 | func mqPCFControlToString(control int32) string { |
| 122 | // Use the library's built-in function to get the string name |
| 123 | name := ibmmq.MQItoString("CFC", int(control)) |
| 124 | |
| 125 | // If the library returns a numeric string, it means the constant is unknown |
| 126 | if name == fmt.Sprintf("%d", control) { |
| 127 | return fmt.Sprintf("MQCFC_%d", control) |
| 128 | } |
| 129 | |
| 130 | // Return the full name with prefix for clarity |
| 131 | return name |
| 132 | } |