📄 proxy_provider.c
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Frank Scheffler//// Modified By: Adrian Schuur (schuur@de.ibm.com)////%//////////////////////////////////////////////////////////////////////////////*! \file proxy_provider.c \brief Proxy Provider for CMPI to access remote providers. Remote providers are accessed by the MB through this proxy provider. The resolver is used to identify the remote peers either with a class-based object path or an instance-based one, depending on the provider call. Create() calls and cleanup() calls will not be relayed to remote locations, i.e. remote provider will be activated and cleaned up by their remote brokers automatically. Thus, these calls only gather necessary information, such as the broker handle. The results from the "real" MI calls will be either passed back directly, in case of an instance call with exactly one peer, or as a combined result, in case of enumerative calls. \author Frank Scheffler*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#if defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)#include <error.h>#endif#include "proxy.h"#include "resolver.h"#include "ticket.h"#include "debug.h"#include "indication_objects.h"CMPIBrokerExtFT *CMPI_BrokerExt_Ftab=NULL;int nativeSide=0;#ifdef __GNUC__MULTI__//! Contains the entities to be passed to an enumerative remote MI request.struct enum_thread { provider_comm *comm; provider_address *addr; CMPIContext *ctx;};static CMPI_THREAD_TYPE spawn_enumerate_thread(provider_comm * comm, provider_address * addr, CMPIBroker * broker, CMPIContext * ctx, CMPIStatus * (*__thread) (struct enum_thread *)){ CMPI_THREAD_TYPE t; struct enum_thread *et = (struct enum_thread *) malloc(sizeof(struct enum_thread)); TRACE_NORMAL(("Spawning enumerative thread for " "comm-layer \"%s\", address \"%s\"", comm->id, addr->dst_address)); et->comm = comm; et->addr = addr; et->ctx = CBPrepareAttachThread(broker, ctx); t=CMPI_BrokerExt_Ftab->newThread( (void *(*)(void *)) __thread, et,0); return t;}#endifvoid cleanup_if_last ( void ){ static int cleanup_count = 0; // If the counter has been called for all five cleanup // functions: Instance, Association, Indication, Property, // and Method.. if (++cleanup_count >= 5) { // then call all of underlaying cleanup functions. cleanup_ticket(); cleanup_count = 0; }}#ifdef CMPI_VER_100static CMPIStatus __InstanceMI_cleanup(CMPIInstanceMI * cThis, const CMPIContext * ctx, CMPIBoolean term)#elsestatic CMPIStatus __InstanceMI_cleanup(CMPIInstanceMI * cThis, CMPIContext * ctx)#endif{ RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; TRACE_NORMAL(("Cleaning up proxy provider handle for: %s", rcThis->provider)); unload_provider_comms(); if (revoke_ticket(&rcThis->ticket)) { TRACE_CRITICAL(("ticket could not be revoked.")); CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not revoke ticket"); }; cleanup_if_last(); free(rcThis->provider); free(rcThis); CMReturn(CMPI_RC_OK);};static CMPIStatus __InstanceMI_enumInstanceNames(CMPIInstanceMI * cThis, CONST CMPIContext * ctx, CONST CMPIResult * rslt, CONST CMPIObjectPath * cop){ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr, *tmp; TRACE_NORMAL(("Executing fan-out remote provider call " "for: %s.", rcThis->provider)); tmp = addr = resolve_class(rcThis->broker, ctx, cop, rcThis->provider, NULL); for (; addr != NULL; addr = addr->next) { provider_comm *comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_enumInstanceNames(addr, rcThis, ctx, rslt, cop); } else { tmp->destructor(tmp); CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "comm-layer not found"); } if (rc.rc != CMPI_RC_OK) { tmp->destructor(tmp); return rc; } } CMReturnDone(rslt); if (tmp) tmp->destructor(tmp); else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};static CMPIStatus __InstanceMI_enumInstances(CMPIInstanceMI * cThis, CONST CMPIContext * ctx, CONST CMPIResult * rslt, CONST CMPIObjectPath * cop, CONST char **props){ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr, *tmp; TRACE_NORMAL(("Executing fan-out remote provider call " "for: %s.", rcThis->provider)); tmp = addr = resolve_class(rcThis->broker, ctx, cop, rcThis->provider, NULL); for (; addr != NULL; addr = addr->next) { provider_comm *comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_enumInstances(addr, rcThis, ctx, rslt, cop, props); } else { tmp->destructor(tmp); CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "comm-layer not found"); } if (rc.rc != CMPI_RC_OK) { tmp->destructor(tmp); return rc; } } CMReturnDone(rslt); if (tmp) tmp->destructor(tmp); else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};static CMPIStatus __InstanceMI_getInstance(CMPIInstanceMI * cThis, CONST CMPIContext * ctx, CONST CMPIResult * rslt, CONST CMPIObjectPath * cop, CONST char **props){ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr; provider_comm *comm; TRACE_NORMAL(("Executing single-targeted remote provider " "call for: %s.", rcThis->provider)); if ((addr = resolve_instance(rcThis->broker, ctx, cop, rcThis->provider, NULL))) { comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_getInstance(addr, rcThis, ctx, rslt, cop, props); CMReturnDone(rslt); } addr->destructor(addr); } else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};static CMPIStatus __InstanceMI_createInstance(CMPIInstanceMI * cThis, CONST CMPIContext * ctx, CONST CMPIResult * rslt, CONST CMPIObjectPath * cop, CONST CMPIInstance * inst){ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr; provider_comm *comm; TRACE_NORMAL(("Executing single-targeted remote provider " "call for: %s.", rcThis->provider)); if ((addr = resolve_instance(rcThis->broker, ctx, cop, rcThis->provider, NULL))) { comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_createInstance(addr, rcThis, ctx, rslt, cop, inst); CMReturnDone(rslt); } addr->destructor(addr); } else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};#ifdef CMPI_VER_100/* This function prototype should be called 'modifyInstance' but since this proxy provider is not using the MI macro stub functions which use that, it is ok to leave it as is. */static CMPIStatus __InstanceMI_setInstance(CMPIInstanceMI * cThis, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * cop, const CMPIInstance * inst, const char **props)#elsestatic CMPIStatus __InstanceMI_setInstance(CMPIInstanceMI * cThis, CMPIContext * ctx, CMPIResult * rslt, CMPIObjectPath * cop, CMPIInstance * inst, char **props)#endif{ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr; provider_comm *comm; TRACE_NORMAL(("Executing single-targeted remote provider " "call for: %s.", rcThis->provider)); if ((addr = resolve_instance(rcThis->broker, ctx, cop, rcThis->provider, NULL))) { comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_setInstance(addr, rcThis, ctx, rslt, cop, inst, props); CMReturnDone(rslt); } addr->destructor(addr); } else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};static CMPIStatus __InstanceMI_deleteInstance(CMPIInstanceMI * cThis, CONST CMPIContext * ctx, CONST CMPIResult * rslt, CONST CMPIObjectPath * cop){ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr; provider_comm *comm; TRACE_NORMAL(("Executing single-targeted remote provider " "call for: %s.", rcThis->provider)); if ((addr = resolve_instance(rcThis->broker, ctx, cop, rcThis->provider, NULL))) { comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_deleteInstance(addr, rcThis, ctx, rslt, cop); CMReturnDone(rslt); } addr->destructor(addr); } else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};static CMPIStatus __InstanceMI_execQuery(CMPIInstanceMI * cThis, CONST CMPIContext * ctx, CONST CMPIResult * rslt, CONST CMPIObjectPath * cop, CONST char *lang, CONST char *query){ CMPIStatus rc = { CMPI_RC_ERR_FAILED, NULL }; RemoteCMPIInstanceMI *rcThis = (RemoteCMPIInstanceMI *) cThis; provider_address *addr, *tmp; TRACE_NORMAL(("Executing fan-out remote provider call " "for: %s.", rcThis->provider)); tmp = addr = resolve_class(rcThis->broker, ctx, cop, rcThis->provider, NULL); for (; addr != NULL; addr = addr->next) { provider_comm *comm = load_provider_comm(addr->comm_layer_id, rcThis->broker, ctx); if (comm != NULL) { rc = comm->InstanceMI_execQuery(addr, rcThis, ctx, rslt, cop, lang, query); } else { tmp->destructor(tmp); CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "comm-layer not found"); } if (rc.rc != CMPI_RC_OK) { tmp->destructor(tmp); return rc; } } CMReturnDone(rslt); if (tmp) tmp->destructor(tmp); else CMReturnWithChars(rcThis->broker, CMPI_RC_ERR_FAILED, "could not resolve location"); return rc;};#ifdef CMPI_VER_100CMPIInstanceMI *_Generic_Create_InstanceMI(const CMPIBroker * broker, const CMPIContext * context, const char *provider, CMPIStatus *rc)#elseCMPIInstanceMI *_Generic_Create_InstanceMI(CMPIBroker * broker, CMPIContext * context, const char *provider)#endif{ static CMPIInstanceMIFT miFT = { CMPICurrentVersion, CMPICurrentVersion, "Instance" "RemoteCMPI", __InstanceMI_cleanup, __InstanceMI_enumInstanceNames, __InstanceMI_enumInstances, __InstanceMI_getInstance, __InstanceMI_createInstance, __InstanceMI_setInstance, __InstanceMI_deleteInstance, __InstanceMI_execQuery }; RemoteCMPIInstanceMI *mi = (RemoteCMPIInstanceMI *) calloc(1, sizeof(RemoteCMPIInstanceMI)); TRACE_NORMAL(("Creating proxy provider handle for: %s", provider)); CMPI_BrokerExt_Ftab=broker->xft; mi->ref.ft = &miFT; mi->provider = strdup(provider); mi->broker = broker; mi->ticket = generate_ticket(broker); return (CMPIInstanceMI *) mi;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -