Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Admin API error handling
0003  *
0004  * @file tpadmerror.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 <errno.h>
0038 #include <regex.h>
0039 #include <utlist.h>
0040 #include <unistd.h>
0041 #include <signal.h>
0042 
0043 #include <ndebug.h>
0044 #include <atmi.h>
0045 #include <atmi_int.h>
0046 #include <typed_buf.h>
0047 #include <ndrstandard.h>
0048 #include <ubf.h>
0049 #include <Exfields.h>
0050 #include <Excompat.h>
0051 #include <ubfutil.h>
0052 
0053 #include "tpadmsv.h"
0054 #include <tpadm.h>
0055 /*---------------------------Externs------------------------------------*/
0056 /*---------------------------Macros-------------------------------------*/
0057 /*---------------------------Enums--------------------------------------*/
0058 /*---------------------------Typedefs-----------------------------------*/
0059 /*---------------------------Globals------------------------------------*/
0060 /*---------------------------Statics------------------------------------*/
0061 /*---------------------------Prototypes---------------------------------*/
0062 
0063 /**
0064  * Read TA_ERROR from UBF buffer.
0065  * If no error is set, then OK is returned.
0066  * @param p_ub UBF buffer
0067  * @return 
0068  */
0069 expublic long ndrx_adm_error_get(UBFH *p_ub)
0070 {
0071     long err = TAOK;
0072     
0073     if (Bpres(p_ub, TA_ERROR, 0))
0074     {
0075         Bget(p_ub, TA_ERROR, 0, (char *)&err, 0L);
0076     }
0077     
0078     return err;
0079 }
0080 
0081 /**
0082  * Set error for the current request
0083  * @param[out] p_ub UBF buffer with request data
0084  * @param[in] error_code error code (or OK status) to be set
0085  * @param[in] fldid Field id with has the error (if not BFLDID)
0086  * @param[in] fmt format string for the message
0087  * @return EXSUCCEED/EXFAIL
0088  */
0089 expublic int ndrx_adm_error_set(UBFH *p_ub, long error_code, 
0090         long fldid, const char *fmt, ...)
0091 {
0092     long curerr;
0093     int ret = EXSUCCEED;
0094     char msg[MAX_TP_ERROR_LEN+1] = {EXEOS};
0095     va_list ap;
0096 
0097     if (TAOK!=(curerr=ndrx_adm_error_get(p_ub)))
0098     {
0099         NDRX_LOG(log_info, "Error code %d already set -> no override to %d",
0100                 curerr, error_code);
0101         goto out;
0102     }
0103     
0104     va_start(ap, fmt);
0105     (void) vsnprintf(msg, sizeof(msg), fmt, ap);
0106     va_end(ap);
0107     
0108     if (error_code >= TAOK)
0109     {
0110         NDRX_LOG(log_info, "Setting MIB error to: %d:[%s] (%d)",
0111                 error_code, msg, fldid);
0112     }
0113     else
0114     {
0115         NDRX_LOG(log_error, "Setting MIB error to: %d:[%s] (%d)",
0116                 error_code, msg, fldid);
0117     }
0118     
0119     if (EXSUCCEED!=Bchg(p_ub, TA_ERROR, 0, (char *)&error_code, 0L))
0120     {
0121         NDRX_LOG(log_error, "Failed to set TA_ERROR: %s", Bstrerror(Berror));
0122         EXFAIL_OUT(ret);
0123     }
0124     
0125     if (EXEOS!=msg[0])
0126     {
0127         if (EXSUCCEED!=Bchg(p_ub, TA_STATUS, 0, (char *)msg, 0L))
0128         {
0129             NDRX_LOG(log_error, "Failed to set TA_STATUS: %s", Bstrerror(Berror));
0130             EXFAIL_OUT(ret);
0131         }
0132     }
0133     
0134     if (BBADFLDID!=fldid)
0135     {
0136         if (EXSUCCEED!=Bchg(p_ub, TA_BADFLD, 0, (char *)&fldid, 0L))
0137         {
0138             NDRX_LOG(log_error, "Failed to set TA_BADFLD: %s", Bstrerror(Berror));
0139             EXFAIL_OUT(ret);
0140         }
0141     }
0142     
0143 out:
0144     return ret;
0145 
0146 }
0147 
0148 /* vim: set ts=4 sw=4 et smartindent: */