📄 osptransapi.c
字号:
intpart = 0; OSPTBOOL accumallowed = OSPC_FALSE; OSPTDELAY tmpstats; OSPM_MEMSET(&tmpstats, 0, sizeof(OSPTDELAY)); if((ospvNumberOfSamples == 0) || ((ospvNumberOfSamples == 1) && ((ospvMinimum != ospvMean) || (ospvVariance != 0)))) { errorcode = OSPC_ERR_TRAN_INVALID_ENTRY; OSPM_DBGERRORLOG(errorcode, "Invalid input for AccumulateOneWayDelay"); } if(errorcode == OSPC_ERR_NO_ERROR) { trans = OSPPTransactionGetContext(ospvTransaction, &errorcode); } if(errorcode == OSPC_ERR_NO_ERROR) { OSPPTransactionGetAccumAllowed(trans, &accumallowed); if(!accumallowed) { errorcode = OSPC_ERR_TRAN_ACCUMULATE_NOT_ALLOWED; OSPM_DBGERRORLOG(errorcode, "AccumulateRoundTrip not allowed in this transaction state."); } } if(errorcode == OSPC_ERR_NO_ERROR) { /* if no statistics structure, make one */ if(trans->TNStatistics == OSPC_OSNULL) { trans->TNStatistics = OSPPStatisticsNew(); if(trans->TNStatistics == OSPC_OSNULL) { errorcode = OSPC_ERR_TRAN_STATS_NEW_FAIL; OSPM_DBGERRORLOG(errorcode, "New failed for stats struct."); } } if(errorcode == OSPC_ERR_NO_ERROR) { /* make temporary copy so we don't corrupt our accumulator */ OSPM_MEMCPY(&tmpstats, &(trans->TNStatistics->ospmRoundTrip), sizeof(OSPTDELAY)); /* number of measurements */ currnumber = tmpstats.NumberOfSamples; tmpstats.NumberOfSamples += ospvNumberOfSamples; /* minimum measured value */ if(tmpstats.HasValue) { tmpstats.Minimum = osp_min(tmpstats.Minimum, ospvMinimum); } else { tmpstats.Minimum = ospvMinimum; } /* sample mean - have to cast NumberOfSamples to a float to get some precision * on the mean */ mean = ((tmpstats.Mean * currnumber) + (ospvMean * ospvNumberOfSamples)) / (float)tmpstats.NumberOfSamples; OSPM_ISNAN(tmpstats.Mean, tnisnan); if(tnisnan) { errorcode = OSPC_ERR_TRAN_INVALID_CALC; } else { /* if remainder is >= .5, round up, else round down */ if(OSPM_MODF(mean, &intpart) >= .5) { tmpstats.Mean = (unsigned)OSPM_CEIL(mean); } else { tmpstats.Mean = (unsigned)OSPM_FLOOR(mean); } /* sum of squares of samples */ OSPM_POW((double)ospvMean, 2, topower); if(topower != OSPC_ERR_POW) { tmpstats.SumOfSampSquares = tmpstats.SumOfSampSquares + ((ospvNumberOfSamples - 1) * (ospvVariance)) + ((ospvNumberOfSamples) * (float)topower); topower = 0; } else { errorcode = (int)topower; } } if(errorcode == OSPC_ERR_NO_ERROR) { /* variance */ OSPM_POW((double) tmpstats.Mean, 2, topower); if(topower != OSPC_ERR_POW) { tmpstats.Variance = (float)(tmpstats.SumOfSampSquares - (tmpstats.NumberOfSamples * topower)) / (tmpstats.NumberOfSamples - 1); topower = 0; } else { errorcode = (int)topower; } } /* Only set state if we have actually done something, otherwise no * change in state. */ if(errorcode == OSPC_ERR_NO_ERROR) { tmpstats.HasValue = OSPC_TRUE; trans->TNStatistics->ospmHasRoundTrip = OSPC_TRUE; /* now copy values back to permanent accumulator */ OSPM_MEMCPY(&(trans->TNStatistics->ospmRoundTrip), &(tmpstats), sizeof(OSPTDELAY)); OSPPTransactionSetState(trans, OSPC_ACCUMULATE_SUCCESS); } else { OSPPTransactionSetState(trans, OSPC_ACCUMULATE_FAIL); } } } return errorcode;}/* * OSPPTransactionDelete() * * Delete the transaction in the transaction collections associated with this * transaction handle. * * The OSPPTransactionDelete function destroys the ospvTransaction object and * releases the resources it consumes. Once this function is called, the * application is prohibited from subsequent interaction with the object. * (Attempts to do so are refused with an appropriate error code.) The library * may continue to use the transaction's resources, however, until it has * concluded communication regarding this transaction with the settlement * server. An application can ensure the release of all resources * only by specifying a time limit in a call to OSPPProviderDelete. * * returns OSPC_ERR_NO_ERROR if successful, or error code. */intOSPPTransactionDelete( OSPTTRANHANDLE ospvTransaction) /* In - Transaction handle. */{ int errorcode = OSPC_ERR_NO_ERROR; OSPTTRANS *trans = OSPC_OSNULL; OSPTBOOL deleteallowed = OSPC_FALSE; OSPTTRANCOLLECTION *trancoll = NULL; OSPTCOLLECTIONINDEX tranindex; trans = OSPPTransactionGetContext(ospvTransaction, &errorcode); if (errorcode == OSPC_ERR_NO_ERROR) { OSPPTransactionGetDeleteAllowed(trans, &deleteallowed); if (deleteallowed == OSPC_TRUE) { OSPPTransactionDeleteRequest(trans); OSPPTransactionDeleteResponse(trans); OSPPTransactionDeleteAuthInd(trans); OSPPTransactionDeleteAuthCnf(trans); OSPPTransactionDeleteUsageInd(trans); OSPPTransactionDeleteUsageCnf(trans); OSPPTransactionDeleteStatistics(trans); if (trans->DetailLog != (void *)NULL) { OSPM_FREE(trans->DetailLog); trans->DetailLog = NULL; } errorcode = OSPPProviderGetTransactionCollection(trans->Provider, &trancoll); if (errorcode == OSPC_ERR_NO_ERROR) { /* wbr ported from 2.5.1 */ /* 8/28/00 - add mutex around trancoll before removing a transaction*/ OSPM_MUTEX_LOCK(trancoll->TransactionMutex, errorcode); if (errorcode == OSPC_ERR_NO_ERROR) { tranindex.Index = OSPM_GET_TRANSACTION_INDEX(ospvTransaction); OSPPTransactionCollectionRemoveItem(trancoll, tranindex); OSPM_MUTEX_UNLOCK( trancoll->TransactionMutex, errorcode ); if(trans != (OSPTTRANS *)NULL) { OSPM_FREE(trans); trans = NULL; } } else { OSPM_DBGERRORLOG(tranindex, "unable to obtain mutex, trans not removed from trancoll"); } } /* if(trans != (OSPTTRANS *)NULL) { OSPM_FREE(trans); trans = NULL; } */ } else { errorcode = OSPC_ERR_TRAN_DELETE_NOT_ALLOWED; OSPM_DBGERRORLOG(errorcode, "delete not allowed in this trans state"); } } return errorcode;}/* * OSPPTransactionGetFirstDestination() * * The OSPPTransactionGetFirstDestination function returns the identity of the * first authorised destination for a call. The SDK library obtains this * information during the execution of the OSPPTransactionRequestAuthorisation * function. The parameters to this function consist of the following: * ospvTransaction: handle of the transaction object. * ospvSizeOfTimestamp: size of the character strings (including the * terminating '\0') in which the function should store validity times * for the destination. If this value is zero, then validity times are not * returned. If this size is non-zero but not large enough to store either * validity time, then an error is indicated and no destination is * returned. * ospvValidAfter: character string in which to store the earliest time for * which the call is authorised to the destination. The format for the * string is the same as indicated in the OSP protocol specification. * For example, 3:03 P.M. on May 2, 1997, Eastern Daylight Time in the * United States is represented as "1997-05-02T19:03:00Z". * ospvValidUntil: character string in which to store the latest time for * which the call is authorised to the destination. The format for the * string is the same as for the ospvValidAfter parameter. * ospvTimeLimit: pointer to a variable in which to place the number of * seconds for which the call is initially authorised. A value of zero * indicates that no limit exists. Note that the initial time limit may be * extended during the call by either party. * ospvSizeOfCallId: pointer to a variable which, on input, contains the size * of the memory buffer in which the function should place the H.323 call * identifier for the destination. If the value is not large enough to * accommodate the call identifier, then an error is indicated and no * destination is returned. On output this variable is updated to indicate * the actual size of the call identifier. * ospvCallId: memory location in which to store the H.323 call identifier * for the destination. The call identifier returned here is the same * format as the call identifier passed to the * OSPPTransactionRequestAuthorisation function. * ospvSizeOfCalledNumber: size of the character string (including the * terminating '\0') in which the function should store the called number. * If the value is not large enough to accommodate the called number, then * an error is indicated and no destination is returned. * ospvCalledNumber: character string in which to store the called number. In * general, the called number returned here will be the same as the called * number that the application passed to the * OSPPTransactionRequestAuthorisation function; however, the settlement * service provider may perform a number translation on the called number, * resulting in a new called number that should be signaled to the peer * gateway. * ospvSizeOfDestination: size of the character string (including the * terminating '\0') in which the function should store the destination * information. If the value is not large enough to accommodate the * destination, then an error is indicated and no destination is returned. * ospvDestination: character string in which to store the identity of the * destination. The value is expressed as either a DNS name or an IP * address enclosed in square brackets, followed by an optional colon and * TCP port number. Examples of valid destinations include * "gateway1.carrier.com" and "[172.16.1.2]:112".
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -