Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Send buffer from stdin to specified service,
0003  *   i.e. using SRVCNM.
0004  *
0005  * @file ud.c
0006  */
0007 /* -----------------------------------------------------------------------------
0008  * Enduro/X Middleware Platform for Distributed Transaction Processing
0009  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011  * This software is released under one of the following licenses:
0012  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013  * See LICENSE file for full text.
0014  * -----------------------------------------------------------------------------
0015  * AGPL license:
0016  *
0017  * This program is free software; you can redistribute it and/or modify it under
0018  * the terms of the GNU Affero General Public License, version 3 as published
0019  * by the Free Software Foundation;
0020  *
0021  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024  * for more details.
0025  *
0026  * You should have received a copy of the GNU Affero General Public License along 
0027  * with this program; if not, write to the Free Software Foundation, Inc.,
0028  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029  *
0030  * -----------------------------------------------------------------------------
0031  * A commercial use license is available from Mavimax, Ltd
0032  * contact@mavimax.com
0033  * -----------------------------------------------------------------------------
0034  */
0035 #include <string.h>
0036 #include <stdio.h>
0037 #include <stdlib.h>
0038 #include <memory.h>
0039 
0040 #include <atmi.h>
0041 #include <atmi_int.h>
0042 #include <ndrstandard.h>
0043 #include <Exfields.h>
0044 #include <ubf.h>
0045 #include <ubf_int.h>
0046 #include <fdatatype.h>
0047 /*---------------------------Externs------------------------------------*/
0048 /*---------------------------Macros-------------------------------------*/    
0049 /*---------------------------Enums--------------------------------------*/
0050 /*---------------------------Typedefs-----------------------------------*/
0051 /*---------------------------Globals------------------------------------*/
0052 /*---------------------------Statics------------------------------------*/
0053 /*---------------------------Prototypes---------------------------------*/
0054 
0055 /**
0056  * Main entry point for `ud' utility
0057  */
0058 int main(int argc, char** argv)
0059 {
0060 
0061     int ret=EXSUCCEED;
0062     UBFH *p_ub;
0063     UBFH *p_ub_ret=NULL;
0064     char svc[XATMI_SERVICE_NAME_LENGTH+1];
0065     BFLDLEN  len=sizeof(svc);
0066     long rsp_len;
0067 
0068     /* Allocate memory, currenlty max that could be supported, but exclude some header
0069      stuff out... */
0070     if (NULL==(p_ub=(UBFH *)tpalloc("UBF", NULL, MAX_CALL_DATA_SIZE-sizeof(UBF_header_t))))
0071     {
0072         fprintf(stderr, "%s\n", tpstrerror(tperrno));
0073         ret=EXFAIL;
0074         goto out;
0075     }
0076 
0077     /* Read the buffer from external source */
0078     if (EXSUCCEED!=Bextread(p_ub, stdin))
0079     {
0080         fprintf(stderr, "%s\n", Bstrerror(Berror));
0081         ret=EXFAIL;
0082         goto out;
0083     }
0084 
0085     /* Get service name */
0086     if (EXSUCCEED!=Bget(p_ub, SRVCNM, 0, svc, &len))
0087     {
0088         fprintf(stderr, "Failed to get SRVCNM: %s\n", Bstrerror(Berror));
0089         ret=EXFAIL;
0090         goto out;
0091     }
0092 
0093     /* remove SRVCNM from buffer */
0094     Bdel(p_ub, SRVCNM, 0);
0095 
0096     /* call the service now! */
0097     if (EXSUCCEED!=tpcall(svc, (char *)p_ub, 0L, (char **)&p_ub_ret, &rsp_len, 0L))
0098     {
0099         ret=EXFAIL;
0100 
0101     /* print the result */
0102         fprintf(stderr, "%s\n", tpstrerror(tperrno));
0103 
0104         /* print the buffer - print the buffers anyway...!
0105         Bprint(p_ub);
0106         goto out;
0107     */
0108     }
0109     fprintf(stdout, "SENT pkt(1) is :\n");
0110     /* print the buffer */
0111     Bprint(p_ub);
0112     fprintf(stdout, "\n");
0113 
0114     /* print the buffer */
0115     fprintf(stdout, "RTN pkt(1) is :\n");
0116     Bprint(p_ub_ret);
0117     fprintf(stdout, "\n");
0118 
0119 out:
0120     /* un-initalize */
0121     tpterm();
0122     return ret;
0123 }
0124 
0125 /* vim: set ts=4 sw=4 et smartindent: */