Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief NDRXD active application configuration dynamic change
0003  *
0004  * @file cmd_appconfig.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 #include <sys/param.h>
0039 #include <unistd.h>
0040 
0041 #include <ndrstandard.h>
0042 #include <ndebug.h>
0043 
0044 #include <ndrx.h>
0045 #include <ndrxdcmn.h>
0046 #include <atmi_int.h>
0047 #include <gencall.h>
0048 #include <nclopt.h>
0049 /*---------------------------Externs------------------------------------*/
0050 /*---------------------------Macros-------------------------------------*/
0051 /*---------------------------Enums--------------------------------------*/
0052 /*---------------------------Typedefs-----------------------------------*/
0053 /*---------------------------Globals------------------------------------*/
0054 /*---------------------------Statics------------------------------------*/
0055 /*---------------------------Prototypes---------------------------------*/
0056 
0057 /**
0058  * Response for application config (value of current setting)
0059  * @param reply
0060  * @param reply_len
0061  * @return EXSUCCEED/error code
0062  */
0063 expublic int appconfig_rsp_process(command_reply_t *reply, size_t reply_len)
0064 {
0065     command_reply_appconfig_t * cfg = (command_reply_appconfig_t*)reply;
0066     
0067     if (cfg->rply.error_code)
0068     {
0069         fprintf(stderr, NDRX_XADMIN_ERR_FMT_PFX "%s\n", cfg->rply.error_msg);
0070         return cfg->rply.error_code;
0071     }
0072     else
0073     {
0074         fprintf(stdout, "%s\n", cfg->svalue);
0075         return EXSUCCEED;
0076     }
0077 }
0078 
0079 /**
0080  * Change ndrxd appconfig on the fly (dynamically without reloading ndrxconfig.xml)
0081  * @param p_cmd_map
0082  * @param argc
0083  * @param argv
0084  * @return SUCCEED
0085  */
0086 expublic int cmd_appconfig(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0087 {
0088     int ret=EXSUCCEED;
0089     command_appconfig_t call;
0090 
0091     /* check mandatory args ..., if missing ... print all args...  */
0092     memset(&call, 0, sizeof(call));
0093     
0094     if (argc<2)
0095     {
0096         fprintf(stderr, XADMIN_INVALID_OPTIONS_MSG);
0097         EXFAIL_OUT(ret);
0098     }
0099     
0100     NDRX_STRCPY_SAFE(call.setting, argv[1]);
0101     
0102     if (argc==3)
0103     {
0104         NDRX_STRCPY_SAFE(call.svalue, argv[2]);
0105     }
0106     else
0107     {
0108         call.svalue[0] = EXEOS;
0109     }
0110     
0111     if (EXSUCCEED!=cmd_generic_listcall(p_cmd_map->ndrxd_cmd, NDRXD_SRC_ADMIN,
0112                         NDRXD_CALL_TYPE_GENERIC,
0113                         (command_call_t *)&call, sizeof(call),
0114                         G_config.reply_queue_str,
0115                         G_config.reply_queue,
0116                         G_config.ndrxd_q,
0117                         G_config.ndrxd_q_str,
0118                         argc, argv,
0119                         p_have_next,
0120                         G_call_args,
0121                         EXFALSE,
0122                         G_config.listcall_flags))
0123     {
0124         EXFAIL_OUT(ret);
0125     }
0126             
0127 out:
0128     return ret;
0129 }
0130 
0131 /* vim: set ts=4 sw=4 et smartindent: */