Back to home page

Enduro/X

 
 

    


0001 /**
0002  *
0003  * @file atmisv21.c
0004  */
0005 /* -----------------------------------------------------------------------------
0006  * Enduro/X Middleware Platform for Distributed Transaction Processing
0007  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0008  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0009  * This software is released under one of the following licenses:
0010  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0011  * See LICENSE file for full text.
0012  * -----------------------------------------------------------------------------
0013  * AGPL license:
0014  *
0015  * This program is free software; you can redistribute it and/or modify it under
0016  * the terms of the GNU Affero General Public License, version 3 as published
0017  * by the Free Software Foundation;
0018  *
0019  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0020  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0021  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0022  * for more details.
0023  *
0024  * You should have received a copy of the GNU Affero General Public License along 
0025  * with this program; if not, write to the Free Software Foundation, Inc.,
0026  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0027  *
0028  * -----------------------------------------------------------------------------
0029  * A commercial use license is available from Mavimax, Ltd
0030  * contact@mavimax.com
0031  * -----------------------------------------------------------------------------
0032  */
0033 
0034 #include <stdio.h>
0035 #include <stdlib.h>
0036 #include <ndebug.h>
0037 #include <atmi.h>
0038 #include <ndrstandard.h>
0039 #include <ubf.h>
0040 #include <test.fd.h>
0041 #include <string.h>
0042 #include <atmi_int.h>
0043 
0044 
0045 extern int __write_to_tx_file(char *buf);
0046 
0047 /**
0048  * Not related with XA transactions
0049  * used for CTLID testing...
0050  */
0051 void TESTCLTID(TPSVCINFO *p_svc)
0052 {
0053     char cnvstr[TPCONVMAXSTR]={EXEOS};
0054     char cnvbin[TPCONVMAXSTR]={EXEOS};
0055     int ret = EXSUCCEED;
0056     
0057     if (EXEOS==p_svc->cltid.clientdata[0])
0058     {
0059         NDRX_LOG(log_error, "TESTERROR: Received emtpy client ID!");
0060         EXFAIL_OUT(ret);
0061     }
0062     
0063     if (EXSUCCEED!=tpconvert(cnvstr, (char *)&p_svc->cltid, TPTOSTRING|TPCONVCLTID))
0064     {
0065         NDRX_LOG(log_error, "TESTERROR: Failed to convert cltid to string: %s", 
0066                 tpstrerror(tperrno));
0067         EXFAIL_OUT(ret);
0068     }
0069     
0070     if (EXSUCCEED!=tpconvert(cnvstr, cnvbin, TPCONVCLTID))
0071     {
0072         NDRX_LOG(log_error, "TESTERROR: Failed to convert cltid to string: %s", 
0073                 tpstrerror(tperrno));
0074         EXFAIL_OUT(ret);
0075     }
0076     
0077     if (0!=strcmp(cnvbin, (char *)&p_svc->cltid))
0078     {
0079         NDRX_LOG(log_error, "TESTERROR: Failed to convert cltid to string: %s", 
0080                 tpstrerror(tperrno));
0081         EXFAIL_OUT(ret);
0082     }
0083 out:
0084 
0085     tpreturn (ret==EXSUCCEED?TPSUCCESS:TPFAIL, 0L, NULL, 0L, 0L);
0086 }
0087 
0088 void NOTRANFAIL(TPSVCINFO *p_svc)
0089 {
0090     UBFH *p_ub = (UBFH *)p_svc->data;
0091 
0092     if (tpgetlev())
0093     {
0094         NDRX_LOG(log_error, "TESTERROR: SHOULD NOT BE IN TRNASACTION!");
0095     }
0096     
0097     tpreturn (TPFAIL, 0L, (char *)p_ub, 0L, 0L);
0098 }
0099 
0100 void RUNTXFAIL(TPSVCINFO *p_svc)
0101 {
0102     int first=1;
0103     UBFH *p_ub = (UBFH *)p_svc->data;
0104     char buf[1024];
0105 
0106     p_ub = (UBFH *)tprealloc ((char *)p_ub, Bsizeof (p_ub) + 4096);
0107 
0108     if (EXSUCCEED!=Bget(p_ub, T_STRING_FLD, 0, buf, 0))
0109     {
0110         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s",
0111                                           Bstrerror(Berror));
0112         tpreturn (TPFAIL, 0L, NULL, 0L, 0L);
0113     }
0114     
0115     if (EXSUCCEED!=__write_to_tx_file(buf))
0116     {
0117         NDRX_LOG(log_error, "TESTERROR: Failed to call __write_to_tx_file()");
0118         tpreturn (TPFAIL, 0L, NULL, 0L, 0L);
0119     }
0120     
0121     /* Return FAIL */
0122     tpreturn (TPFAIL, 0L, (char *)p_ub, 0L, 0L);
0123 }
0124 
0125 void RUNTX(TPSVCINFO *p_svc)
0126 {
0127     int first=1;
0128     UBFH *p_ub = (UBFH *)p_svc->data;
0129     char buf[1024];
0130 
0131     p_ub = (UBFH *)tprealloc ((char *)p_ub, Bsizeof (p_ub) + 4096);
0132 
0133     if (EXSUCCEED!=Bget(p_ub, T_STRING_FLD, 0, buf, 0))
0134     {
0135         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s",
0136                                           Bstrerror(Berror));
0137         tpreturn (TPFAIL, 0L, NULL, 0L, 0L);
0138     }
0139     
0140     if (EXSUCCEED!=__write_to_tx_file(buf))
0141     {
0142         NDRX_LOG(log_error, "TESTERROR: Failed to call __write_to_tx_file()");
0143         tpreturn (TPFAIL, 0L, NULL, 0L, 0L);
0144     }
0145     
0146     /* Return OK */
0147     tpreturn (TPSUCCESS, 0L, (char *)p_ub, 0L, 0L);
0148 }
0149 
0150 /**
0151  * Do initialization
0152  */
0153 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0154 {
0155     int ret = EXSUCCEED;
0156     NDRX_LOG(log_debug, "tpsvrinit called");
0157    
0158     if (EXSUCCEED!=tpopen())
0159     {
0160         NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
0161                                             tperrno, tpstrerror(tperrno));
0162         ret=EXFAIL;
0163         goto out;
0164     }
0165 
0166     if (EXSUCCEED!=tpadvertise("RUNTX", RUNTX))
0167     {
0168         NDRX_LOG(log_error, "Failed to initialize RUNTX!");
0169     }
0170     
0171     if (EXSUCCEED!=tpadvertise("RUNTXFAIL", RUNTXFAIL))
0172     {
0173         NDRX_LOG(log_error, "Failed to initialize RUNTXFAIL!");
0174     }
0175 
0176     if (EXSUCCEED!=tpadvertise("NOTRANFAIL", NOTRANFAIL))
0177     {
0178         NDRX_LOG(log_error, "Failed to initialize NOTRANFAIL!");
0179     }
0180     
0181     if (EXSUCCEED!=tpadvertise("TESTCLTID", TESTCLTID))
0182     {
0183         NDRX_LOG(log_error, "Failed to initialize TESTCLTID!");
0184     }
0185     
0186 out:
0187     return ret;
0188 }
0189 
0190 /**
0191  * Do de-initialization
0192  */
0193 void NDRX_INTEGRA(tpsvrdone)(void)
0194 {
0195     NDRX_LOG(log_debug, "tpsvrdone called");
0196     if (EXSUCCEED!=tpclose())
0197     {
0198         NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]", 
0199                                             tperrno, tpstrerror(tperrno));
0200     }
0201 }
0202 
0203 /* vim: set ts=4 sw=4 et smartindent: */