Exemplo n.º 1
0
func (self *KamailioSessionManager) getSuppliers(kev KamEvent) (string, error) {
	cd, err := kev.AsCallDescriptor()
	if err != nil {
		utils.Logger.Info(fmt.Sprintf("<SM-Kamailio> LCR_PREPROCESS_ERROR error: %s", err.Error()))
		return "", errors.New("LCR_PREPROCESS_ERROR")
	}
	var lcr engine.LCRCost
	if err = self.Rater().GetLCR(&engine.AttrGetLcr{CallDescriptor: cd}, &lcr); err != nil {
		utils.Logger.Info(fmt.Sprintf("<SM-Kamailio> LCR_API_ERROR error: %s", err.Error()))
		return "", errors.New("LCR_API_ERROR")
	}
	if lcr.HasErrors() {
		lcr.LogErrors()
		return "", errors.New("LCR_COMPUTE_ERROR")
	}
	return lcr.SuppliersString()
}
Exemplo n.º 2
0
// Computes the LCR for a specific request emulating a call, returns a comma separated list of suppliers
func (self *ApierV1) GetLcrSuppliers(lcrReq engine.LcrRequest, suppliers *string) (err error) {
	cd, err := lcrReq.AsCallDescriptor(self.Config.DefaultTimezone)
	if err != nil {
		return err
	}
	var lcrQried engine.LCRCost
	if err := self.Responder.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd, Paginator: lcrReq.Paginator}, &lcrQried); err != nil {
		return utils.NewErrServerError(err)
	}
	if lcrQried.HasErrors() {
		lcrQried.LogErrors()
		if !lcrReq.IgnoreErrors {
			return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_COMPUTE_ERRORS")
		}
	}
	if suppliersStr, err := lcrQried.SuppliersString(); err != nil {
		return utils.NewErrServerError(err)
	} else {
		*suppliers = suppliersStr
	}
	return nil
}