static int _testCMPIEnumeration(const CMPIContext *ctx) { CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIEnumeration *enum_ptr = NULL; CMPIData data; unsigned int initCount = 0; CMPIObjectPath *objPath = NULL; CMPIArray *arr_ptr = NULL; CMPICount returnedArraySize; void *eptr; objPath = make_ObjectPath(_broker, _Namespace, _PersonClass); enum_ptr = CBEnumInstances(_broker, ctx, objPath, NULL, &rc); if (enum_ptr == NULL) { return 1; } arr_ptr = CMToArray(enum_ptr, &rc); if (arr_ptr == NULL) { return 1; } returnedArraySize = CMGetArrayCount(arr_ptr, &rc); while (CMHasNext(enum_ptr, &rc)) { data = CMGetNext(enum_ptr, &rc); if (data.type != CMPI_instance) { return 1; } initCount++; } eptr = enum_ptr->hdl; enum_ptr->hdl = NULL; CMToArray(enum_ptr, &rc); if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) { return 1; } CMGetNext(enum_ptr, &rc); if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) { return 1; } CMHasNext(enum_ptr, &rc); if (rc.rc != CMPI_RC_ERR_INVALID_HANDLE) { return 1; } enum_ptr->hdl = eptr; rc = CMRelease(enum_ptr); if (rc.rc != CMPI_RC_OK) { return 1; } return 0; }
int enum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb, CMPIType type, int xmlAs, unsigned int flags) { CMPIObjectPath *cop; CMPIInstance *ci; CMPIConstClass *cl; _SFCB_ENTER(TRACE_CIMXMLPROC, "enum2xml"); while (CMHasNext(enm, NULL)) { if (type == CMPI_ref) { cop = CMGetNext(enm, NULL).value.ref; if (xmlAs == XML_asClassName) className2xml(cop, sb); else if (xmlAs == XML_asObjectPath) { SFCB_APPENDCHARS_BLOCK(sb, "<OBJECTPATH>\n"); SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n"); nsPath2xml(cop, sb); instanceName2xml(cop, sb); SFCB_APPENDCHARS_BLOCK(sb, "</INSTANCEPATH>\n"); SFCB_APPENDCHARS_BLOCK(sb, "</OBJECTPATH>\n"); } else instanceName2xml(cop, sb); } else if (type == CMPI_class) { cl = (CMPIConstClass *) CMGetNext(enm, NULL).value.inst; cls2xml(cl, sb, flags); } else if (type == CMPI_instance) { ci = CMGetNext(enm, NULL).value.inst; cop = CMGetObjectPath(ci, NULL); if (xmlAs == XML_asObj) { SFCB_APPENDCHARS_BLOCK(sb, "<VALUE.OBJECTWITHPATH>\n"); SFCB_APPENDCHARS_BLOCK(sb, "<INSTANCEPATH>\n"); nsPath2xml(cop, sb); } else SFCB_APPENDCHARS_BLOCK(sb, "<VALUE.NAMEDINSTANCE>\n"); instanceName2xml(cop, sb); if (xmlAs == XML_asObj) SFCB_APPENDCHARS_BLOCK(sb, "</INSTANCEPATH>\n"); instance2xml(ci, sb, flags); if (xmlAs == XML_asObj) SFCB_APPENDCHARS_BLOCK(sb, "</VALUE.OBJECTWITHPATH>\n"); else SFCB_APPENDCHARS_BLOCK(sb, "</VALUE.NAMEDINSTANCE>\n"); cop->ft->release(cop); } } _SFCB_RETURN(0); }
CMPIStatus TestCMPIAssociationProviderAssociatorNames( CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, const CMPIObjectPath* ref, const char* _RefLeftClass, const char* _RefRightClass, const char* role, const char* resultRole) { CMPIObjectPath* op = NULL; CMPIObjectPath* rop = NULL; CMPIEnumeration* en = NULL; CMPIData data ; CMPIStatus rc = { CMPI_RC_OK, NULL }; PROV_LOG_OPEN (_ClassName, _ProviderLocation); PROV_LOG ("\n\n********************* %s CMPI AssociatorNames() called", _ClassName); /* get object path of the target class */ op = get_assoc_targetClass_ObjectPath( _broker, ref, _RefLeftClass, _RefRightClass, &rc); PROV_LOG (" New Object Path [%s]", CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL)); /* create new object path of association */ rop = CMNewObjectPath( _broker, CMGetCharsPtr(CMGetNameSpace(ref,&rc),NULL), _ClassName, &rc ); /* upcall to CIMOM; call enumInstanceNames() of the target class */ en = CBEnumInstanceNames( _broker, ctx, op, &rc); /* as long as object path entries are found in the enumeration */ while( CMHasNext( en, &rc) ) { /* get the object path */ data = CMGetNext(en, &rc); /* and return the target class object path as result of the * associatorNames() call */ CMReturnObjectPath( rslt, data.value.ref ); } PROV_LOG ("\n\n********************* %s CMPI AssociatorNames() exited", _ClassName); PROV_LOG_CLOSE (); return rc; }
CMPIStatus TestCMPIAssociationProviderAssociators( CMPIAssociationMI* mi, const CMPIContext* ctx, const CMPIResult* rslt, const CMPIObjectPath* ref, const char* _RefLeftClass, const char* _RefRightClass, const char* role, const char* resultRole, const char** properties) { CMPIObjectPath * op = NULL; CMPIEnumeration * en = NULL; CMPIData data ; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIString * sourceClass = NULL; PROV_LOG_OPEN (_ClassName, _ProviderLocation); PROV_LOG ("\n\n********************* %s CMPI Associators() called", _ClassName); sourceClass = CMGetClassName(ref,&rc); /* get object path of the target class */ op = get_assoc_targetClass_ObjectPath( _broker, ref, _RefLeftClass, _RefRightClass, &rc); sourceClass = CMGetClassName(op,&rc); PROV_LOG(" target class: %s ",CMGetCharsPtr(sourceClass,NULL)); PROV_LOG (" New Object Path [%s]", CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL)); /* Call to Associators */ /* upcall to CIMOM; call enumInstances() of the target class */ en = CBEnumInstances( _broker, ctx, op, NULL, &rc); /* as long as instance entries are found in the enumeration */ while( CMHasNext( en, &rc) ) { /* get the instance */ data = CMGetNext( en, &rc); /* and return the target class instance as result of the * associators() call */ CMReturnInstance( rslt, data.value.inst ); } PROV_LOG ("\n\n********************* %s CMPI Associators exited", _ClassName); PROV_LOG_CLOSE (); return rc; }
CMPIStatus TestAssociationProviderAssociators(CMPIAssociationMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char *_RefLeftClass, const char *_RefRightClass, const char *role, const char *resultRole, const char **properties) { CMPIObjectPath *op = NULL; CMPIEnumeration *en = NULL; CMPIData data; CMPIStatus rc = { CMPI_RC_OK, NULL }; CMPIString *sourceClass = NULL; sourceClass = CMGetClassName(ref, &rc); /* * get object path of the target class */ op = get_assoc_targetClass_ObjectPath(_broker, ref, _RefLeftClass, _RefRightClass, &rc); sourceClass = CMGetClassName(op, &rc); /* * Call to Associators */ /* * upcall to CIMOM; call enumInstances() of the target class */ en = CBEnumInstances(_broker, ctx, op, NULL, &rc); /* * as long as instance entries are found in the enumeration */ if (!rc.rc) while (CMHasNext(en, &rc)) { /* * get the instance */ data = CMGetNext(en, &rc); /* * and return the target class instance as result of the * associators() call */ CMReturnInstance(rslt, data.value.inst); } return rc; }
int qualiEnum2xml(CMPIEnumeration *enm, UtilStringBuffer * sb) { CMPIQualifierDecl *q; _SFCB_ENTER(TRACE_CIMXMLPROC, "qualiEnum2xml"); while (CMHasNext(enm, NULL)) { q = CMGetNext(enm, NULL).value.dataPtr.ptr; qualifierDeclaration2xml(q, sb); } _SFCB_RETURN(0); }
void ElementCapabilitiesInitInstances(const CMPIContext *ctx) { CMPIObjectPath *op = NULL, *opLeft = NULL, *opRight = NULL, *left = NULL, *right = NULL; CMPIValue val; CMPIEnumeration *enm = NULL; CMPIInstance *ci = NULL; CMPIContext *ctxLocal; ctxLocal = native_clone_CMPIContext(ctx); val.string = sfcb_native_new_CMPIString("$DefaultProvider$", NULL, 0); ctxLocal->ft->addEntry(ctxLocal, "rerouteToProvider", &val, CMPI_string); op = CMNewObjectPath(_broker, "root/interop", "SFCB_ElementCapabilities", NULL); ci = CMNewInstance(_broker, op, NULL); opLeft = CMNewObjectPath(_broker, "root/interop", "CIM_IndicationService", NULL); enm = CBEnumInstanceNames(_broker, ctx, opLeft, NULL); left = CMGetNext(enm, NULL).value.ref; opRight = CMNewObjectPath(_broker, "root/interop", "SFCB_IndicationServiceCapabilities", NULL); enm = CBEnumInstanceNames(_broker, ctx, opRight, NULL); right = CMGetNext(enm, NULL).value.ref; CMAddKey(op, "ManagedElement", &left, CMPI_ref); CMAddKey(op, "Capabilities", &right, CMPI_ref); CMSetProperty(ci, "ManagedElement", &left, CMPI_ref); CMSetProperty(ci, "Capabilities", &right, CMPI_ref); CBCreateInstance(_broker, ctxLocal, op, ci, NULL); CMRelease(ctxLocal); return; }
int refillRetryQ (const CMPIContext * ctx) { _SFCB_ENTER(TRACE_INDPROVIDER, "refillRetryQ"); int qfill=0; if (RQhead==NULL) { // The queue is empty, check if there are instances to be restored CMPIObjectPath * op=CMNewObjectPath(_broker,"root/interop","SFCB_IndicationElement",NULL); CMPIEnumeration * enm = _broker->bft->enumerateInstances(_broker, ctx, op, NULL, NULL); while(enm && enm->ft->hasNext(enm, NULL)) { // get the properties from the repo instance CMPIData inst=CMGetNext(enm,NULL); CMPIData indID=CMGetProperty(inst.value.inst,"indicationID",NULL); CMPIData rcount=CMGetProperty(inst.value.inst,"retryCount",NULL); CMPIData last=CMGetProperty(inst.value.inst,"lastDelivery",NULL); CMPIData ind=CMGetProperty(inst.value.inst,"ind",NULL); CMPIData sub=CMGetProperty(inst.value.inst,"sub",NULL); CMPIData ld=CMGetProperty(inst.value.inst,"ld",NULL); _SFCB_TRACE(1,("--- Requeueing indication id:%d",indID.value.Int)); // Rebuild the queue element RTElement *element; element = (RTElement *) malloc(sizeof(*element)); element->instanceID=indID.value.Int; element->lasttry=last.value.Int; element->count=rcount.value.Int; element->ind=ind.value.ref->ft->clone(ind.value.ref,NULL); element->ref=ld.value.ref->ft->clone(ld.value.ref,NULL); element->sub=sub.value.ref->ft->clone(sub.value.ref,NULL); CMPIObjectPath * indele=CMGetObjectPath(inst.value.inst,NULL); element->SFCBIndEle=indele->ft->clone(indele,NULL); // call enq enqRetry(element,ctx,0); qfill=1; } // spawn thread if we queued anything if ((qfill == 1 ) && (retryRunning == 0)) { retryRunning=1; _SFCB_TRACE(1,("--- Starting retryExport thread")); pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); CMPIContext * pctx = native_clone_CMPIContext(ctx); pthread_create(&t, &tattr,&retryExport,(void *) pctx); } } _SFCB_RETURN(0); }
CMPIStatus IndCIMXMLHandlerInvokeMethod(CMPIMethodMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char *methodName, const CMPIArgs * in, CMPIArgs * out) { _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerInvokeMethod"); CMPIStatus st = { CMPI_RC_OK, NULL }; CMPIStatus circ = { CMPI_RC_OK, NULL }; struct timeval tv; struct timezone tz; static unsigned int indID=1; if (interOpNameSpace(ref, &st) == 0) _SFCB_RETURN(st); if (strcasecmp(methodName, "_deliver") == 0) { // On the first indication, check if reliable indications are enabled. if (RIEnabled == -1) { CMPIObjectPath *op=CMNewObjectPath(_broker,"root/interop","CIM_IndicationService",NULL); CMPIEnumeration *isenm = _broker->bft->enumerateInstances(_broker, ctx, op, NULL, NULL); CMPIData isinst=CMGetNext(isenm,NULL); CMPIData mc=CMGetProperty(isinst.value.inst,"DeliveryRetryAttempts",NULL); RIEnabled=mc.value.uint16; } CMPIInstance *indo=CMGetArg(in,"indication",NULL).value.inst; CMPIInstance *ind=CMClone(indo,NULL); CMPIContext *ctxLocal=NULL; CMPIObjectPath *iop=NULL,*subop=NULL; CMPIInstance *sub=NULL; if (RIEnabled) { ctxLocal = prepareUpcall((CMPIContext *) ctx); // Set the indication sequence values iop=CMGetObjectPath(ind,NULL); CMAddKey(iop,"SFCB_IndicationID",&indID,CMPI_uint32); CMSetProperty(ind,"SFCB_IndicationID",&indID,CMPI_uint32); // Prevent this property from showing up in the indication filterFlagProperty(ind, "SFCB_IndicationID"); sub=CMGetArg(in,"subscription",NULL).value.inst; CMPIData handler=CMGetProperty(sub, "Handler", &st); CMPIObjectPath *hop=handler.value.ref; CMPIInstance *hdlr=CBGetInstance(_broker, ctxLocal, hop, NULL, &st); // Build the complete sequence context // Get the stub from the handler CMPIString *context = CMGetProperty(hdlr, "SequenceContext", &st).value.string; // and add the sfcb start time char *cstr=malloc( (strlen(context->ft->getCharPtr(context,NULL)) + strlen(sfcBrokerStart) + 1) * sizeof(char)); sprintf(cstr,"%s%s",context->ft->getCharPtr(context,NULL),sfcBrokerStart); context = sfcb_native_new_CMPIString(cstr, NULL, 0); // and put it in the indication CMSetProperty(ind, "SequenceContext", &context, CMPI_string); free(cstr); CMRelease(context); // Get the proper sequence number CMPIValue lastseq = CMGetProperty(hdlr, "LastSequenceNumber", &st).value; lastseq.sint64++; // Handle wrapping of the signed int if (lastseq.sint64 < 0) lastseq.sint64=0; // Update the last used number in the handler CMSetProperty(hdlr, "LastSequenceNumber", &lastseq.sint64, CMPI_sint64); CBModifyInstance(_broker, ctxLocal, hop, hdlr, NULL); // And the indication CMSetProperty(ind, "SequenceNumber", &lastseq, CMPI_sint64); } // Now send the indication st = deliverInd(ref, in, ind); if (st.rc != 0) { if (RIEnabled){ _SFCB_TRACE(1,("--- Indication delivery failed, adding to retry queue")); // Indication delivery failed, send to retry queue // build an element RTElement *element; element = (RTElement *) malloc(sizeof(*element)); element->ref=ref->ft->clone(ref,NULL); // Get the OP of the subscription and indication subop=CMGetObjectPath(sub,NULL); element->sub=subop->ft->clone(subop,NULL); element->ind=iop->ft->clone(iop,NULL); // Store other attrs element->instanceID=indID; element->count=0; gettimeofday(&tv, &tz); element->lasttry=tv.tv_sec; // Push the indication to the repo CBCreateInstance(_broker, ctxLocal, iop, ind, &circ); if (circ.rc != 0) { mlogf(M_ERROR,M_SHOW,"Pushing indication instance to repository failed, rc:%d\n",circ.rc); } indID++; // Add it to the retry queue enqRetry(element,ctx,1); // And launch the thread if it isn't already running pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); if (retryRunning == 0) { retryRunning = 1; _SFCB_TRACE(1,("--- Starting retryExport thread")); CMPIContext *pctx = native_clone_CMPIContext(ctx); pthread_create(&t, &tattr, &retryExport, (void *) pctx); } CMRelease(ctxLocal); } } CMRelease(ind); } else { printf("--- ClassProvider: Invalid request %s\n", methodName); st.rc = CMPI_RC_ERR_METHOD_NOT_FOUND; } _SFCB_RETURN(st); }
void * retryExport(void *lctx) { _SFCB_ENTER(TRACE_INDPROVIDER, "retryExport"); CMPIObjectPath *ref; CMPIArgs *in; CMPIInstance *sub; CMPIContext *ctx = (CMPIContext *) lctx; CMPIContext *ctxLocal; RTElement *cur, *purge; struct timeval tv; struct timezone tz; int rint, maxcount, ract, rtint; CMPIUint64 sfc = 0; CMPIObjectPath *op; CMPIEnumeration *isenm = NULL; //Setup signal handlers struct sigaction sa; sa.sa_handler = handle_sig_retry; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGUSR2, &sa, NULL); CMPIStatus st = { CMPI_RC_OK, NULL }; ctxLocal = prepareUpcall(ctx); // Get the retry params from IndService op = CMNewObjectPath(_broker, "root/interop", "CIM_IndicationService", NULL); isenm = _broker->bft->enumerateInstances(_broker, ctx, op, NULL, NULL); CMPIData isinst = CMGetNext(isenm, NULL); CMPIData mc = CMGetProperty(isinst.value.inst, "DeliveryRetryAttempts", NULL); CMPIData ri = CMGetProperty(isinst.value.inst, "DeliveryRetryInterval", NULL); CMPIData ra = CMGetProperty(isinst.value.inst, "SubscriptionRemovalAction", NULL); CMPIData rti = CMGetProperty(isinst.value.inst, "SubscriptionRemovalTimeInterval", NULL); maxcount = mc.value.uint16; // Number of times to retry delivery rint = ri.value.uint32; // Interval between retries rtint = rti.value.uint32; // Time to allow sub to keep failing until ract = ra.value.uint16; // ... this action is taken // Now, run the queue sleep(5); //Prevent deadlock on startup when localmode is used. pthread_mutex_lock(&RQlock); cur = RQhead; while (RQhead != NULL) { if(retryShutdown) break; // Provider shutdown ref = cur->ref; // Build the CMPIArgs that deliverInd needs CMPIInstance *iinst=internalProviderGetInstance(cur->ind,&st); if (st.rc != 0 ) { mlogf(M_ERROR,M_SHOW,"Failed to retrieve indication instance from repository, rc:%d\n",st.rc); purge=cur; cur=cur->next; dqRetry(ctx,purge); continue; } in=CMNewArgs(_broker,NULL); CMAddArg(in,"indication",&iinst,CMPI_instance); sub=internalProviderGetInstance(cur->sub,&st); if (st.rc == CMPI_RC_ERR_NOT_FOUND) { // sub got deleted, purge this indication and move on _SFCB_TRACE(1,("--- Subscription for indication gone, deleting indication.")); purge = cur; cur = cur->next; dqRetry(ctx,purge); } else { // Still valid, retry gettimeofday(&tv, &tz); if ((cur->lasttry + rint) > tv.tv_sec) { _SFCB_TRACE(1,("--- sleeping.")); // no retries are ready, release the lock // and sleep for an interval, then relock pthread_mutex_unlock(&RQlock); sleep(rint); if(retryShutdown) break; // Provider shutdown pthread_mutex_lock(&RQlock); } st = deliverInd(ref, in, iinst); if ((st.rc == 0) || (cur->count >= maxcount - 1)) { // either it worked, or we maxed out on retries // If it succeeded, clear the failtime if (st.rc == 0) { _SFCB_TRACE(1,("--- Indication succeeded.")); sfc = 0; CMSetProperty(sub, "DeliveryFailureTime", &sfc, CMPI_uint64); CBModifyInstance(_broker, ctxLocal, cur->sub, sub, NULL); } // remove from queue in either case _SFCB_TRACE(1,("--- Indication removed.")); purge = cur; cur = cur->next; dqRetry(ctx,purge); } else { // still failing, leave on queue _SFCB_TRACE(1,("--- Indication still failing.")); cur->count++; gettimeofday(&tv, &tz); cur->lasttry = tv.tv_sec; CMPIInstance * indele=internalProviderGetInstance(cur->SFCBIndEle,&st); CMSetProperty(indele,"LastDelivery",&cur->lasttry,CMPI_sint32); CMSetProperty(indele,"RetryCount",&cur->count,CMPI_uint32); CBModifyInstance(_broker, ctxLocal, cur->SFCBIndEle, indele, NULL); CMPIData sfcp = CMGetProperty(sub, "DeliveryFailureTime", NULL); sfc = sfcp.value.uint64; if (sfc == 0) { // if the time isn't set, this is the first failure sfc = tv.tv_sec; CMSetProperty(sub, "DeliveryFailureTime", &sfc, CMPI_uint64); CBModifyInstance(_broker, ctxLocal, cur->sub, sub, NULL); cur = cur->next; } else if (sfc + rtint < tv.tv_sec) { // Exceeded subscription removal threshold, if action is: // 2, delete the sub; 3, disable the sub; otherwise, nothing if (ract == 2) { _SFCB_TRACE(1,("--- Subscription threshold reached, deleting.")); CBDeleteInstance(_broker, ctx, cur->sub); purge = cur; cur = cur->next; dqRetry(ctx,purge); } else if (ract == 3) { // Set sub state to disable(4) _SFCB_TRACE(1,("--- Subscription threshold reached, disable.")); CMPIUint16 sst = 4; CMSetProperty(sub, "SubscriptionState", &sst, CMPI_uint16); CBModifyInstance(_broker, ctx, cur->sub, sub, NULL); purge = cur; cur = cur->next; dqRetry(ctx,purge); } } else { cur = cur->next; } } } } // Queue went dry, cleanup and exit _SFCB_TRACE(1,("--- Indication retry queue empty, thread exitting.")); pthread_mutex_unlock(&RQlock); retryRunning = 0; CMRelease(ctxLocal); CMRelease(ctx); _SFCB_RETURN(NULL); }
CMPIStatus IndCIMXMLHandlerCreateInstance(CMPIInstanceMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * cop, const CMPIInstance *ci) { CMPIStatus st = { CMPI_RC_OK, NULL }; CMPIArgs *in, *out = NULL; CMPIObjectPath *op; CMPIData rv; unsigned short persistenceType; _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerCreateInstance"); if (interOpNameSpace(cop, &st) == 0) _SFCB_RETURN(st); internalProviderGetInstance(cop, &st); if (st.rc == CMPI_RC_ERR_FAILED) _SFCB_RETURN(st); if (st.rc == CMPI_RC_OK) { setStatus(&st, CMPI_RC_ERR_ALREADY_EXISTS, NULL); _SFCB_RETURN(st); } CMPIInstance *ciLocal = CMClone(ci, NULL); memLinkInstance(ciLocal); CMPIObjectPath* copLocal = CMClone(cop, NULL); memLinkObjectPath(copLocal); setCCN(copLocal,ciLocal,"CIM_ComputerSystem"); CMPIString *sysname=ciLocal->ft->getProperty(ciLocal,"SystemName",&st).value.string; if (sysname == NULL || sysname->hdl == NULL) { char hostName[512]; hostName[0]=0; gethostname(hostName,511); /* should be the same as SystemName of IndicationService */ CMAddKey(copLocal, "SystemName", hostName, CMPI_chars); CMSetProperty(ciLocal,"SystemName",hostName,CMPI_chars); } CMPIString *dest = CMGetProperty(ciLocal, "destination", &st).value.string; if (dest == NULL || CMGetCharPtr(dest) == NULL) { setStatus(&st, CMPI_RC_ERR_FAILED, "Destination property not found; is required"); CMRelease(ciLocal); _SFCB_RETURN(st); } else { /* if no scheme is given, assume http (as * req. for param by mof) */ char *ds = CMGetCharPtr(dest); if (strstr(ds, "://") == NULL) { char *prefix = "http://"; int n = strlen(ds) + strlen(prefix) + 1; char *newdest = (char *) malloc(n * sizeof(char)); strcpy(newdest, prefix); strcat(newdest, ds); CMSetProperty(ciLocal, "destination", newdest, CMPI_chars); free(newdest); } } CMPIData persistence = CMGetProperty(ciLocal, "persistencetype", &st); if (persistence.state == CMPI_nullValue || persistence.state == CMPI_notFound) { persistenceType = 2; /* default is 2 = permanent */ } else if (persistence.value.uint16 < 1 || persistence.value.uint16 > 3) { setStatus(&st, CMPI_RC_ERR_FAILED, "PersistenceType property must be 1, 2, or 3"); CMRelease(ciLocal); _SFCB_RETURN(st); } else { persistenceType = persistence.value.uint16; } CMSetProperty(ciLocal, "persistencetype", &persistenceType, CMPI_uint16); if (CMClassPathIsA(_broker, copLocal, "cim_listenerdestination", NULL)) { //get the creation timestamp struct timeval tv; struct timezone tz; char context[100]; gettimeofday(&tv, &tz); struct tm cttm; char * gtime = (char *) malloc(15 * sizeof(char)); memset(gtime, 0, 15 * sizeof(char)); if (gmtime_r(&tv.tv_sec, &cttm) != NULL) { strftime(gtime, 15, "%Y%m%d%H%M%S", &cttm); } // Even though reliable indications may be disabled, we need to do this // in case it ever gets enabled. // Get the IndicationService name CMPIObjectPath * isop = CMNewObjectPath(_broker, "root/interop", "CIM_IndicationService", NULL); CMPIEnumeration * isenm = _broker->bft->enumerateInstances(_broker, ctx, isop, NULL, NULL); CMPIData isinst = CMGetNext(isenm, NULL); CMPIData mc = CMGetProperty(isinst.value.inst, "Name", NULL); // build the context string sprintf (context,"%s#%s#",mc.value.string->ft->getCharPtr(mc.value.string,NULL),gtime); CMPIValue scontext; scontext.string = sfcb_native_new_CMPIString(context, NULL, 0); free(gtime); // set the properties CMSetProperty(ciLocal, "SequenceContext", &scontext, CMPI_string); CMPIValue zarro = {.sint64 = -1 }; CMSetProperty(ciLocal, "LastSequenceNumber", &zarro, CMPI_sint64); } CMPIString *str = CDToString(_broker, copLocal, NULL); CMPIString *ns = CMGetNameSpace(copLocal, NULL); _SFCB_TRACE(1, ("--- handler %s %s", (char *) ns->hdl, (char *) str->hdl)); in = CMNewArgs(_broker, NULL); CMAddArg(in, "handler", &ciLocal, CMPI_instance); CMAddArg(in, "key", &copLocal, CMPI_ref); op = CMNewObjectPath(_broker, "root/interop", "cim_indicationsubscription", &st); rv = CBInvokeMethod(_broker, ctx, op, "_addHandler", in, out, &st); if (st.rc == CMPI_RC_OK) { st = InternalProviderCreateInstance(NULL, ctx, rslt, copLocal, ciLocal); } else { rv=CBInvokeMethod(_broker,ctx,op,"_removeHandler",in,out,NULL); } _SFCB_RETURN(st); } CMPIStatus IndCIMXMLHandlerModifyInstance(CMPIInstanceMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * cop, const CMPIInstance *ci, const char **properties) { CMPIStatus st = { CMPI_RC_ERR_NOT_SUPPORTED, NULL }; _SFCB_ENTER(TRACE_INDPROVIDER, "IndCIMXMLHandlerSetInstance"); _SFCB_RETURN(st); }
CMPIStatus KDefaultGetInstance( const CMPIBroker* mb, CMPIInstanceMI* mi, const CMPIContext* cc, const CMPIResult* cr, const CMPIObjectPath* cop, const char** properties) { #if defined(DIRECT_CALL) static CMPIResultFT _ft = { CMPICurrentVersion, _DefaultGI_release, _DefaultGI_clone, _DefaultGI_returnData, _DefaultGI_returnInstance, _DefaultGI_returnObjectPath, _DefaultGI_returnDone, _DefaultGI_returnError }; DefaultGI_Result result; DefaultGI_Handle handle; CMPIStatus st; handle.result = cr; handle.cop = cop; handle.found = 0; result.hdl = (void*)&handle; result.ft = &_ft; st = (*mi->ft->enumerateInstances)( mi, cc, (CMPIResult*)(void*)&result, cop, NULL); if (!st.rc) return st; if (!handle.found) { KReturn(ERR_NOT_FOUND); } KReturn(OK); #else /* defined(DIRECT_CALL) */ CMPIEnumeration* e; CMPIStatus st; CMPIObjectPath* ccop; /* Create an object path with just the class from cop */ ccop = CMNewObjectPath(mb, KNameSpace(cop), KClassName(cop), &st); if (!ccop) KReturn(ERR_FAILED); /* Enumerate all instances of this class */ if (!(e = mb->bft->enumerateInstances(mb, cc, ccop, properties, &st))) KReturn(ERR_FAILED); while (CMHasNext(e, &st)) { CMPIData cd; CMPIObjectPath* tcop; cd = CMGetNext(e, &st); if (st.rc || cd.type != CMPI_instance || (cd.state & CMPI_nullValue)) KReturn(ERR_FAILED); if (!(tcop = CMGetObjectPath(cd.value.inst, &st))) KReturn(ERR_FAILED); if (KMatch(tcop, cop)) { CMReturnInstance(cr, cd.value.inst); KReturn(OK); } } KReturn(ERR_NOT_FOUND); #endif /* !defined(DIRECT_CALL) */ }
CMPIStatus TestAssociationProviderReferenceNames(CMPIAssociationMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char *resultClass, const char *role) { CMPIInstance *ci = NULL; CMPIObjectPath *op = NULL; CMPIObjectPath *rop = NULL; CMPIObjectPath *cop = NULL; CMPIEnumeration *en = NULL; CMPIData data; const char *targetName = NULL; const char *_thisClassName; const char *_RefLeftClass = NULL; const char *_RefRightClass = NULL; CMPIStatus rc = { CMPI_RC_OK, NULL }; _thisClassName = _ClassName; /* * get object path of the target class */ op = get_assoc_targetClass_ObjectPath(_broker, ref, _RefLeftClass, _RefRightClass, &rc); /* * check for a failure in creating the object path */ if (rc.rc != CMPI_RC_OK) return rc; /* * the target class does not belong to us so just return CMPI_RC_OK */ if (!op) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_OK, NULL ); return rc; } /* * create new object path of association */ rop = CMNewObjectPath(_broker, CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL), _thisClassName, &rc); /* * upcall to CIMOM; call enumInstanceNames() of the target class */ en = CBEnumInstanceNames(_broker, ctx, op, &rc); /* * as long as object path entries are found in the enumeration */ if (!rc.rc) while (CMHasNext(en, &rc)) { /* * get the object path */ data = CMGetNext(en, &rc); /* * create new instance of the association */ ci = CMNewInstance(_broker, rop, &rc); /* * get name of the target class */ targetName = get_assoc_targetClass_Name(_broker, ref, _RefLeftClass, _RefRightClass, &rc); /* * set the properties of the association instance depending on the * constellation of the source class (parameter ref) and the target * class (see targetName) */ if (strcmp(targetName, "CMPI_TEST_Person") == 0) { CMSetProperty(ci, "model", (CMPIValue *) & (data.value.ref), CMPI_ref); CMSetProperty(ci, "driver", (CMPIValue *) & (ref), CMPI_ref); } else if (strcmp(targetName, "CMPI_TEST_Vehicle") == 0) { CMSetProperty(ci, "model", (CMPIValue *) & (data.value.ref), CMPI_ref); CMSetProperty(ci, "driver", (CMPIValue *) & (ref), CMPI_ref); } /* * get object path of association instance */ cop = CMGetObjectPath(ci, &rc); /* * set namespace in object path of association */ CMSetNameSpace(cop, CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL)); /* * and return the association object path as result of the * referenceNames() call */ CMReturnObjectPath(rslt, cop); } return rc; }
CMPIStatus TestAssociationProviderAssociatorNames(CMPIAssociationMI * mi, const CMPIContext *ctx, const CMPIResult *rslt, const CMPIObjectPath * ref, const char *_RefLeftClass, const char *_RefRightClass, const char *role, const char *resultRole) { CMPIObjectPath *op = NULL; CMPIObjectPath *rop = NULL; CMPIEnumeration *en = NULL; CMPIData data; CMPIStatus rc = { CMPI_RC_OK, NULL }; /* * get object path of the target class */ op = get_assoc_targetClass_ObjectPath(_broker, ref, _RefLeftClass, _RefRightClass, &rc); /* * check for a failure in creating the object path */ if (rc.rc != CMPI_RC_OK) return rc; /* * the target class does not belong to us so just return CMPI_RC_OK */ if (!op) { CMSetStatusWithChars( _broker, &rc, CMPI_RC_OK, NULL ); return rc; } /* * create new object path of association */ rop = CMNewObjectPath(_broker, CMGetCharsPtr(CMGetNameSpace(ref, &rc), NULL), _ClassName, &rc); /* * upcall to CIMOM; call enumInstanceNames() of the target class */ en = CBEnumInstanceNames(_broker, ctx, op, &rc); /* * as long as object path entries are found in the enumeration */ if (!rc.rc) while (CMHasNext(en, &rc)) { /* * get the object path */ data = CMGetNext(en, &rc); /* * and return the target class object path as result of the * associatorNames() call */ CMReturnObjectPath(rslt, data.value.ref); } return rc; }
CMPIStatus TestCMPIAssociationProviderReferences( CMPIAssociationMI * mi, const CMPIContext * ctx, const CMPIResult * rslt, const CMPIObjectPath * ref, const char *resultClass, const char *role , const char** properties) { CMPIInstance * ci = NULL; CMPIObjectPath * op = NULL; CMPIObjectPath * rop = NULL; CMPIEnumeration * en = NULL; CMPIData data ; const char * targetName = NULL; char * _thisClassName; char * _RefLeftClass = NULL; char * _RefRightClass = NULL; CMPIStatus rc = {CMPI_RC_OK, NULL}; _thisClassName=_ClassName; PROV_LOG_OPEN (_thisClassName, _ProviderLocation); PROV_LOG ("\n\n********************* %s CMPI References() called", _thisClassName); /* get object path of the target class */ op = get_assoc_targetClass_ObjectPath( _broker, ref, _RefLeftClass, _RefRightClass, &rc); PROV_LOG (" New Object Path [%s]", CMGetCharsPtr (CMGetNameSpace (ref, &rc),NULL)); /* create new object path of association */ rop = CMNewObjectPath( _broker, CMGetCharsPtr(CMGetNameSpace(ref,&rc),NULL), _thisClassName, &rc ); /* upcall to CIMOM; call enumInstanceNames() of the target class */ en = CBEnumInstanceNames( _broker, ctx, op, &rc); /* as long as object path entries are found in the enumeration */ while( CMHasNext( en, &rc) ) { /* get the object path */ data = CMGetNext( en, &rc); { /* create new instance of the association */ ci = CMNewInstance( _broker, rop, &rc); /* get name of the target class */ targetName = get_assoc_targetClass_Name( _broker, ref, _RefLeftClass, _RefRightClass, &rc); /* set the properties of the association instance depending on the * constellation of the source class (parameter ref) and the target * class (see targetName) */ if(strcmp (targetName, "CMPI_TEST_Person")== 0) { CMSetProperty( ci, "model", (CMPIValue*)&(data.value.ref), CMPI_ref ); CMSetProperty( ci, "driver", (CMPIValue*)&(ref), CMPI_ref ); } else if( strcmp( targetName,"CMPI_TEST_Vehicle") == 0 ) { CMSetProperty( ci, "model", (CMPIValue*)&(data.value.ref), CMPI_ref ); CMSetProperty( ci, "driver", (CMPIValue*)&(ref), CMPI_ref ); } CMReturnInstance( rslt, ci ); } } PROV_LOG ("\n\n********************* %s CMPI References() exited", _thisClassName); PROV_LOG_CLOSE (); return rc; }