Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Dump the message to stdout.
0003  *
0004  * @file cmd_mqdm.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039 #include <errno.h>
0040 
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043 #include <nstdutil.h>
0044 
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048 #include <utlist.h>
0049 #include <Exfields.h>
0050 
0051 #include "xa_cmn.h"
0052 #include <ndrx.h>
0053 #include <qcommon.h>
0054 #include <nclopt.h>
0055 /*---------------------------Externs------------------------------------*/
0056 /*---------------------------Macros-------------------------------------*/
0057 /*---------------------------Enums--------------------------------------*/
0058 /*---------------------------Typedefs-----------------------------------*/
0059 /*---------------------------Globals------------------------------------*/
0060 /*---------------------------Statics------------------------------------*/
0061 /*---------------------------Prototypes---------------------------------*/
0062 
0063 /**
0064  * Dump the messsage to stdout.
0065  * @param p_cmd_map
0066  * @param argc
0067  * @param argv
0068  * @return SUCCEED
0069  */
0070 expublic int cmd_mqdm(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0071 {
0072     int ret = EXSUCCEED;
0073     short srvid;
0074     short nodeid;
0075     char msgid_str[TMMSGIDLEN_STR+1];
0076     char msgid[TMMSGIDLEN+1];
0077     char *buf = NULL;
0078     UBFH *p_ub = NULL;
0079     UBFH *p_ub2 = NULL;
0080     TPQCTL qc;
0081     long len = 1;
0082     char typ[64];
0083     long blen; 
0084     ncloptmap_t clopt[] =
0085     {
0086         {'n', BFLD_SHORT, (char *)&nodeid, 0,
0087                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Q cluster node id"},
0088         {'i', BFLD_SHORT, (char *)&srvid, 0, 
0089                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Q Server Id"},
0090         {'m', BFLD_STRING, msgid_str, sizeof(msgid_str), 
0091                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Message id"},
0092         {0}
0093     };
0094     
0095     /* parse command line */
0096     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0097     {
0098         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0099         EXFAIL_OUT(ret);
0100     }
0101     
0102     /* Have a number in FB! */
0103     memset(&qc, 0, sizeof(qc));
0104 
0105     tmq_msgid_deserialize(msgid_str, msgid);
0106     
0107     qc.flags|= TPQPEEK;
0108     qc.flags|= TPQGETBYMSGID;
0109     
0110     memcpy(qc.msgid, msgid, TMMSGIDLEN);
0111     
0112     buf = tpalloc("STRING", "", 1);
0113     
0114     if (EXSUCCEED!=tpdequeueex(nodeid, srvid, "*N/A*", &qc, (char **)&buf, &len, 0))
0115     {
0116         fprintf(stderr, "failed %s diag: %ld:%s", 
0117                 tpstrerror(tperrno), qc.diagnostic, qc.diagmsg);
0118         EXFAIL_OUT(ret);
0119     }
0120     
0121     if (NULL==(p_ub = (UBFH *)tpalloc("UBF", "", 1024)))
0122     {
0123         NDRX_LOG(log_error, "Failed to alloc: %s", strerror(errno));
0124         EXFAIL_OUT(ret);
0125     }
0126     
0127     if (EXSUCCEED!=tmq_tpqctl_to_ubf_deqrsp(p_ub, &qc))
0128     {
0129         NDRX_LOG(log_error, "Failed to build tpqctl struct ubf");
0130         EXFAIL_OUT(ret);
0131     }
0132     
0133     printf("*************** TPQCTL ***************\n");
0134     
0135     Bprint(p_ub);
0136     
0137     printf("*************** MESSAGE **************\n");
0138     
0139     
0140     /* Check the buffer & do the actions */
0141     if (EXFAIL==(blen=tptypes(buf, typ, NULL)))
0142     {
0143         NDRX_LOG(log_error, "Failed to detect buffer type");
0144         EXFAIL_OUT(ret);
0145     }
0146     
0147     printf("* Buffer type = %s\n", typ);
0148     
0149     if (0==strcmp(typ, "UBF"))
0150     {
0151         Bprint((UBFH *)buf);
0152     }
0153     else
0154     {
0155         /* Do the hex dump */
0156         STDOUT_DUMP(log_info, "Binary message contents", buf, len);
0157     }
0158     
0159 out:
0160     if (NULL!=p_ub)
0161     {
0162         tpfree((char *)p_ub);
0163     }
0164 
0165     if (NULL!=buf)
0166     {
0167         tpfree(buf);
0168     }
0169 
0170     return ret;
0171 }
0172 
0173 /* vim: set ts=4 sw=4 et smartindent: */