Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief TPNULL buffer type support
0003  *
0004  * @file typed_null.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 
0039 #include <ndrstandard.h>
0040 #include <typed_buf.h>
0041 #include <ndebug.h>
0042 #include <tperror.h>
0043 /*---------------------------Externs------------------------------------*/
0044 /*---------------------------Macros-------------------------------------*/
0045 /*---------------------------Enums--------------------------------------*/
0046 /*---------------------------Typedefs-----------------------------------*/
0047 /*---------------------------Globals------------------------------------*/
0048 /*---------------------------Statics------------------------------------*/
0049 /*---------------------------Prototypes---------------------------------*/
0050 
0051 /**
0052  * Basic init data structure allocator
0053  * @param subtype
0054  * @param len
0055  * @return
0056  */
0057 expublic char   * TPNULL_tpalloc (typed_buffer_descr_t *descr, 
0058         char *subtype, long *len)
0059 {
0060     char *ret=NULL;
0061     char fn[] = "TPNULL_tpalloc";
0062 
0063     /* Allocate UBF buffer, 1 byte, what so ever.. 
0064     ret=NDRX_MALLOC(1);
0065 
0066     if (NULL==ret)
0067     {
0068         NDRX_LOG(log_error, "%s: Failed to allocate TPNULL buffer!", fn);
0069         ndrx_TPset_error_fmt(TPEOS, "TPNULL failed to allocate: %d bytes", 
0070                 sizeof(TPINIT));
0071         goto out;
0072     }
0073     */
0074 
0075 out:
0076     return ret;
0077 }
0078 
0079 /**
0080  * Gracefully remove free up the buffer
0081  * @param descr
0082  * @param buf
0083  */
0084 expublic void TPNULL_tpfree(typed_buffer_descr_t *descr, char *buf)
0085 {
0086     /* NDRX_FREE(buf); - nothing to do on NULL! */
0087 }
0088 
0089 /**
0090  * Prepare outgoing message, just do nothing
0091  * @param descr buffer type descr
0092  * @param idata input data/null
0093  * @param ilen 0
0094  * @param obuf no data to install
0095  * @param olen olen is 0
0096  * @param flags ?
0097  * @return EXSUCCEED
0098  */
0099 expublic int TPNULL_prepare_outgoing (typed_buffer_descr_t *descr, char *idata, 
0100         long ilen, char *obuf, long *olen, long flags)
0101 {
0102     if (NULL!=olen)
0103     {
0104         *olen = 0;
0105     }
0106     
0107     return EXSUCCEED;
0108 }
0109 
0110 /**
0111  * Prepare incoming buffer, for NULL we just free any other previous buffer
0112  * pointed to.
0113  * @param descr description ptr
0114  * @param rcv_data received data
0115  * @param rcv_len data len received
0116  * @param odata original XATMI buffer to push data in
0117  * @param olen data buffer len
0118  * @param flags flags
0119  * @return EXSUCCEED/EXFAIL
0120  */
0121 expublic int TPNULL_prepare_incoming (typed_buffer_descr_t *descr, char *rcv_data, 
0122                         long rcv_len, char **odata, long *olen, long flags)
0123 {
0124     
0125     /* reject type switch if requested... */
0126     int ret=EXSUCCEED;
0127     buffer_obj_t *outbufobj=NULL;
0128 
0129     NDRX_LOG(log_debug, "Entering %s", __func__);
0130         
0131     /* Figure out the passed in buffer */
0132     if (NULL==(outbufobj=ndrx_find_buffer(*odata)))
0133     {
0134         ndrx_TPset_error_fmt(TPEINVAL, "Output buffer %p is not allocated "
0135                                         "with tpalloc()!", *odata);
0136         EXFAIL_OUT(ret);
0137     }
0138 
0139     /* Check the data types */
0140     if (NULL!=outbufobj)
0141     {
0142         /* If we cannot change the data type, then we trigger an error */
0143         if (flags & TPNOCHANGE && outbufobj->type_id!=BUF_TYPE_NULL)
0144         {
0145             /* Raise error! */
0146             ndrx_TPset_error_fmt(TPEOTYPE, "Receiver expects %s but got %s buffer",
0147                                         G_buf_descr[BUF_TYPE_NULL].type,
0148                                         G_buf_descr[outbufobj->type_id].type
0149                                         );
0150             EXFAIL_OUT(ret);
0151         }
0152     }
0153     
0154     if (NULL!=*odata)
0155     {
0156         tpfree(*odata);
0157         *odata = NULL;
0158     }
0159     
0160     if (NULL!=olen)
0161     {
0162         *olen = 0;
0163     }
0164     
0165 out:
0166     return ret;
0167 }
0168 
0169 /* vim: set ts=4 sw=4 et smartindent: */