Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief This simulates ATM configuration server
0003  *
0004  * @file atmisv005.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 <stdio.h>
0035 #include <stdlib.h>
0036 #include <string.h>
0037 #include <ndebug.h>
0038 #include <atmi.h>
0039 #include <ndrstandard.h>
0040 #include <ubf.h>
0041 #include <test.fd.h>
0042 
0043 
0044 /*---------------------------Externs------------------------------------*/
0045 /*---------------------------Macros-------------------------------------*/
0046 /*---------------------------Enums--------------------------------------*/
0047 /*---------------------------Typedefs-----------------------------------*/
0048 /*---------------------------Globals------------------------------------*/
0049 int M_cd=EXFAIL;
0050 UBFH *M_p_ub=NULL;
0051 /*---------------------------Statics------------------------------------*/
0052 /*---------------------------Prototypes---------------------------------*/
0053 
0054 /**
0055  * Open configuration download
0056  * @return
0057  */
0058 exprivate short cnf_openf(void)
0059 {
0060     short   ret = EXSUCCEED;
0061     long    len;
0062     long    revent;
0063     char    *p;
0064     char    termcode[64];
0065     /* expect SENDONLY to pass rply */
0066     if (EXFAIL == tprecv(M_cd, (char **)&M_p_ub, &len, 0L, &revent))
0067     {
0068         if (TPEEVENT == tperrno )
0069         {
0070             if (TPEV_SENDONLY != revent)
0071             {
0072                 if (TPEV_DISCONIMM == revent)
0073                 {
0074                     NDRX_LOG(log_warn,
0075                      "Partner aborted conversation");
0076                 }
0077                 else
0078                 {
0079                     NDRX_LOG(log_error,
0080                         "TESTERROR: Unexpected conv event %lx",
0081                          revent );
0082                 }
0083                 ret = EXFAIL;
0084                 goto out;
0085             }
0086         }
0087         else
0088         {
0089             NDRX_LOG(log_error, "Conv receive err %d", tperrno );
0090             ret=EXFAIL;
0091             goto out;
0092         }
0093     }
0094     
0095     /*
0096      * Get the key stuff
0097      */
0098     if (EXFAIL==Bget(M_p_ub, T_STRING_2_FLD, 0, termcode, NULL))
0099     {
0100         NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_2_FLD[0]");
0101         ret=EXFAIL;
0102     }
0103     else if (0!=strcmp(termcode, "TERMINAL_T"))
0104     {
0105         NDRX_LOG(log_error, "TESTERROR: Got invalid T_STRING_2_FLD=[%s]",
0106                                         termcode);
0107         ret=EXFAIL;
0108     }
0109 
0110 out:
0111     return ret;
0112 }
0113 
0114 /**
0115  * Send configuration data
0116  * @param fld
0117  * @param data
0118  * @return 
0119  */
0120 int send_config_data(BFLDID fld, char *data)
0121 {
0122     int ret=EXSUCCEED;
0123     long revent;
0124     tpfree((char *)M_p_ub);
0125 
0126     if ( !(M_p_ub = (UBFH *)tpalloc("UBF", NULL, 1024)) )
0127     {
0128         NDRX_LOG(log_error, "TESTERROR: FML alloc failed");
0129         ret=EXFAIL;
0130         goto out;
0131     }
0132     else if (EXSUCCEED == CBchg(M_p_ub, fld, 0,
0133                                             data,
0134                                             0L,
0135                                             BFLD_STRING) )
0136     {
0137             if (EXFAIL == tpsend(M_cd,
0138                                     (char *)M_p_ub,
0139                                     0L,
0140                                     TPNOTIME,       /* DIRTY HACK   */
0141                                     &revent))
0142             {
0143                     NDRX_LOG(log_error, "Send data failed %d %ld",
0144                                                     tperrno, revent);
0145             }
0146             else
0147             {
0148                     NDRX_LOG(log_debug,"sent");
0149             }
0150 
0151     }
0152     
0153 out:
0154     return ret;
0155 }
0156 
0157 /**
0158  * Main server entry
0159  * @param p_svc
0160  */
0161 void CONVSV (TPSVCINFO *p_svc)
0162 {
0163     int ret=EXSUCCEED;
0164     int i;
0165     M_p_ub = (UBFH *)p_svc->data;
0166     M_cd = p_svc->cd; /* Our call descriptor (server side) */
0167     char databuf[512] = {EXEOS};
0168 
0169     NDRX_LOG(log_debug, "CONVSV got call");
0170 
0171     if (EXFAIL==cnf_openf())
0172     {
0173         NDRX_LOG(log_error, "TESTERROR: Failed to open config!");
0174         ret=EXFAIL;
0175         goto out;
0176     }
0177 
0178     for (i=0; i<100; i++)
0179     {
0180         snprintf(databuf, sizeof(databuf), "svc send %d", i);
0181         if (EXFAIL==send_config_data(T_STRING_FLD, databuf))
0182         {
0183             NDRX_LOG(log_error, "TESTERROR: Failed to send config!");
0184             ret=EXFAIL;
0185             goto out;
0186         }
0187     }
0188     
0189 out:
0190     tpreturn(  ret==EXSUCCEED?TPSUCCESS:TPFAIL,
0191                 0L,
0192                 (char *)NULL,
0193                 0L,
0194                 0L);
0195 }
0196 
0197 /*
0198  * Do initialization
0199  */
0200 int NDRX_INTEGRA(tpsvrinit)(int argc, char **argv)
0201 {
0202     int ret = EXSUCCEED;
0203     NDRX_LOG(log_debug, "tpsvrinit called");
0204 
0205     if (EXSUCCEED!=tpadvertise("CONVSV", CONVSV))
0206     {
0207         NDRX_LOG(log_error, "Failed to initialize CONVSV!");
0208         ret=EXFAIL;
0209     }
0210     
0211     return ret;
0212 }
0213 
0214 /**
0215  * Do de-initialization
0216  */
0217 void NDRX_INTEGRA(tpsvrdone)(void)
0218 {
0219     NDRX_LOG(log_debug, "tpsvrdone called");
0220 }
0221 /* vim: set ts=4 sw=4 et smartindent: */