/***************************************************************************/ /* */ /* (c) Copyright IBM Corp. 2004 All rights reserved. */ /* */ /* This sample program is owned by International Business Machines */ /* Corporation or one of its subsidiaries ("IBM") and is copyrighted */ /* and licensed, not sold. */ /* */ /* You may copy, modify, and distribute this sample program in any */ /* form without payment to IBM, for any purpose including developing, */ /* using, marketing or distributing programs that include or are */ /* derivative works of the sample program. */ /* */ /* The sample program is provided to you on an "AS IS" basis, without */ /* warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, */ /* EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Some jurisdictions do not allow for the exclusion or limitation of */ /* implied warranties, so the above limitations or exclusions may not */ /* apply to you. IBM shall not be liable for any damages you suffer as */ /* a result of using, modifying or distributing the sample program or */ /* its derivatives. */ /* */ /***************************************************************************/ /* */ /* Program name: namelist.c */ /* */ /* Description: Sample c program that uses MQINQ to open a namelist and */ /* then displays the results */ /* */ /***************************************************************************/ /* */ /* Function: */ /* */ /* This program opens a namelist object in inquire mode so that the */ /* queue names in the list can be retrieved. The queue names are gotten */ /* using the MQINQ API. The results are then displayed to the user. */ /* */ /* Note: This program will give errors if a namelist that contains more */ /* than 10 names is used. */ /* */ /* This program has been tested by compiling with MSVC++ 6.0 and running */ /* against WebSphere MQ v5.3 CSD7. */ /* */ /***************************************************************************/ /* */ /* namelist has 2 parameters: */ /* namelist name (required) */ /* queue manager name (optional) */ /* */ /***************************************************************************/ #include #include #include #include int main(int argc, char **argv) { /* Declare MQI structures needed */ MQOD od = {MQOD_DEFAULT}; char QMName[50]; MQHCONN Hcon; /* connection handle */ MQHOBJ Hinq; /* handle for MQINQ */ MQLONG O_options; /* MQOPEN options */ MQLONG C_options; /* MQCLOSE options */ MQLONG CompCode; /* completion code */ MQLONG Reason; /* reason code */ MQLONG CReason; /* reason code (MQCONN) */ MQLONG Select[2]; /* attribute selectors */ MQLONG IAV[1]; /* integer attribute values */ MQCHAR CAV[10*MQ_Q_NAME_LENGTH]; /* character attribute values */ MQCHAR *ptr; long i; printf("Sample namelist start\n"); if (argc < 2) { printf("Missing parameter: namelist \n"); exit(99); } /**************************************************************/ /* If a queue manager name was passed in on the command line, */ /* then set it up here and then connect to it. */ /**************************************************************/ QMName[0] = 0; if (argc > 2) { strcpy(QMName, argv[2]); } MQCONN(QMName, &Hcon, &CompCode, &CReason); /********************************************/ /* If connect failed, give reason and exit. */ /********************************************/ if (CompCode == MQCC_FAILED) { printf("MQCONN failed with CompCode: %ld, ReasonCode: %ld\n", CompCode, CReason); exit(CReason); } /********************************************/ /* Open the namelist for inquiry. */ /********************************************/ strncpy(od.ObjectName, argv[1], (size_t)MQ_NAMELIST_NAME_LENGTH); O_options = MQOO_INQUIRE + MQOO_FAIL_IF_QUIESCING; od.ObjectType = MQOT_NAMELIST; MQOPEN(Hcon, &od, O_options, &Hinq, &CompCode, &Reason); /*****************************************/ /* If open failed, give reason and exit. */ /*****************************************/ if (CompCode == MQCC_FAILED) { printf("MQOPEN failed with CompCode: %ld, ReasonCode: %ld\n", CompCode, Reason); if (CReason != MQRC_ALREADY_CONNECTED) { MQDISC(&Hcon, &CompCode, &Reason); /*****************************************/ /* If disconnect failed, give reason. */ /*****************************************/ if (Reason != MQRC_NONE) { printf("MQDISC failed with CompCode:%ld, ReasonCode: %ld\n", CompCode, Reason); } } exit(Reason); } /********************************************************/ /* Build a selector array that contains the information */ /* about the namelist that we are interested in: */ /* number of names in list and the actual names */ /********************************************************/ Select[0] = MQIA_NAME_COUNT; /* number of names in the list */ Select[1] = MQCA_NAMES; /* actual names in the list */ MQINQ(Hcon, /* connection handle */ Hinq, /* object handle */ 2L, /* Selector count */ Select, /* Selector array */ 1L, /* integer attribute count */ IAV, /* integer attribute array */ sizeof(CAV), /* character attribute count */ CAV, /* character attribute array */ &CompCode, /* completion code */ &Reason); /* reason code */ /********************************************************/ /* If inquire worked, display the namelist information. */ /* Otherwise, display why it failed. */ /********************************************************/ if (CompCode == MQCC_OK) { printf("Namelist %s contains %ld names:\n", argv[1], IAV[0]); ptr = &CAV[0]; for (i=0; i