![]() |
|
|||
0001 /** 0002 * @brief Advertise related command back-end 0003 * Currently only for SRVADV comand i.e. server requests advertise. 0004 * 0005 * @file cmd_adv.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 #include <utlist.h> 0040 #include <errno.h> 0041 0042 #include <ndrstandard.h> 0043 0044 #include "ndebug.h" 0045 #include "userlog.h" 0046 #include <ndrxd.h> 0047 #include <ndrxdcmn.h> 0048 #include <atmi.h> 0049 #include <cmd_processor.h> 0050 #include <bridge_int.h> 0051 /*---------------------------Externs------------------------------------*/ 0052 /*---------------------------Macros-------------------------------------*/ 0053 /*---------------------------Enums--------------------------------------*/ 0054 /*---------------------------Typedefs-----------------------------------*/ 0055 /*---------------------------Globals------------------------------------*/ 0056 /*---------------------------Statics------------------------------------*/ 0057 /*---------------------------Prototypes---------------------------------*/ 0058 0059 /** 0060 * Advertise service, requested by server. 0061 * @param call 0062 * @param data 0063 * @param len 0064 * @param context 0065 * @return 0066 */ 0067 expublic int cmd_srvadv (command_call_t * call, char *data, size_t len, int context) 0068 { 0069 int ret=EXSUCCEED; 0070 command_dynadvertise_t * adv = (command_dynadvertise_t *)call; 0071 pm_node_t *p_pm = get_pm_from_srvid(adv->srvid); 0072 pm_node_svc_t *chk=NULL; 0073 pm_node_svc_t *new_svc=NULL; 0074 int found = EXFALSE; 0075 0076 if (NULL==p_pm) 0077 { 0078 NDRX_LOG(log_error, "No such server with id: %d", adv->srvid); 0079 } 0080 else 0081 { 0082 NDRX_LOG(log_error, "Server id=%d ok, binary: [%s], adding service: [%s], func: [%s]", 0083 adv->srvid, p_pm->binary_name, adv->svc_nm, adv->fn_nm); 0084 0085 /* Check the stuff it must not exist already for server! */ 0086 DL_FOREACH(p_pm->svcs,chk) 0087 { 0088 if (0==strcmp(chk->svc.svc_nm, adv->svc_nm)) 0089 { 0090 found=EXTRUE; 0091 break; 0092 } 0093 } 0094 0095 if (found) 0096 { 0097 NDRX_LOG(log_error, "Service already advertised! Svc: [%s] Func: [%s]", 0098 chk->svc.svc_nm, chk->svc.fn_nm); 0099 /* Keep ret SUCCEED, as not deadly stuff */ 0100 goto out; 0101 } 0102 0103 new_svc=NDRX_MALLOC(sizeof(pm_node_svc_t)); 0104 if (NULL==new_svc) 0105 { 0106 NDRX_LOG(log_always, "Failed to allocate memory for new " 0107 "service: %s", strerror(errno) ); 0108 ret=EXFAIL; 0109 goto out; 0110 } 0111 memset((char *)new_svc, 0, sizeof(new_svc)); 0112 0113 /* Fill up details */ 0114 NDRX_STRCPY_SAFE(new_svc->svc.svc_nm, adv->svc_nm); 0115 NDRX_STRCPY_SAFE(new_svc->svc.fn_nm, adv->fn_nm); 0116 0117 brd_begin_diff(); 0118 0119 /* Add to linked list & add to svc shm */ 0120 DL_APPEND(p_pm->svcs, new_svc); 0121 0122 /* add stuff to bridge service hash */ 0123 if (EXSUCCEED!=brd_add_svc_to_hash(new_svc->svc.svc_nm)) 0124 { 0125 ret=EXFAIL; 0126 goto out; 0127 } 0128 0129 brd_end_diff(); 0130 } 0131 0132 out: 0133 return ret; 0134 } 0135 /* vim: set ts=4 sw=4 et smartindent: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |