Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Remove message from Qspace
0003  *
0004  * @file cmd_mqrm.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  * Remove the message from Q
0065  * @param p_cmd_map
0066  * @param argc
0067  * @param argv
0068  * @return SUCCEED
0069  */
0070 expublic int cmd_mqrm(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     TPQCTL qc;
0079     long len = 1;
0080     ncloptmap_t clopt[] =
0081     {
0082         {'n', BFLD_SHORT, (char *)&nodeid, 0,
0083                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Q cluster node id"},
0084         {'i', BFLD_SHORT, (char *)&srvid, 0, 
0085                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Q Server Id"},
0086         {'m', BFLD_STRING, msgid_str, sizeof(msgid_str), 
0087                                 NCLOPT_MAND|NCLOPT_HAVE_VALUE, "Message id"},
0088         {0}
0089     };
0090     
0091     /* parse command line */
0092     if (nstd_parse_clopt(clopt, EXTRUE,  argc, argv, EXFALSE))
0093     {
0094         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0095         EXFAIL_OUT(ret);
0096     }
0097     
0098     /* Have a number in FB! */
0099     memset(&qc, 0, sizeof(qc));
0100 
0101     tmq_msgid_deserialize(msgid_str, msgid);
0102     
0103     qc.flags|= TPQGETBYMSGID;
0104     
0105     memcpy(qc.msgid, msgid, TMMSGIDLEN);
0106     
0107     buf = tpalloc("STRING", "", 1);
0108     
0109     if (EXSUCCEED!=tpdequeueex(nodeid, srvid, "*N/A*", &qc, (char **)&buf, &len, 0))
0110     {
0111         fprintf(stderr, "failed %s diag: %ld:%s", 
0112                 tpstrerror(tperrno), qc.diagnostic, qc.diagmsg);
0113         NDRX_LOG(log_error, "failed %s diag: %ld:%s", 
0114                 tpstrerror(tperrno), qc.diagnostic, qc.diagmsg);
0115         
0116         EXFAIL_OUT(ret);
0117     }
0118     
0119     
0120     printf("Succeed\n");
0121     
0122 out:
0123 
0124     if (NULL!=buf)
0125     {
0126         tpfree(buf);
0127     }
0128 
0129     return ret;
0130 }
0131 /* vim: set ts=4 sw=4 et smartindent: */