Beispiel #1
0
// indexASession explores settings and builds smg.aSessionsIndex based on that
func (smg *SMGeneric) indexASession(uuid string, s *SMGSession) bool {
	smg.aSIMux.Lock()
	defer smg.aSIMux.Unlock()
	ev := s.EventStart
	for _, fieldName := range smg.cgrCfg.SmGenericConfig.SessionIndexes {
		fieldVal, err := utils.ReflectFieldAsString(ev, fieldName, "")
		if err != nil {
			if err == utils.ErrNotFound {
				fieldVal = utils.NOT_AVAILABLE
			} else {
				utils.Logger.Err(fmt.Sprintf("<SMGeneric> Error retrieving field: %s from event: %+v", fieldName, ev))
				continue
			}
		}
		if fieldVal == "" {
			fieldVal = utils.MetaEmpty
		}
		if _, hasFieldName := smg.aSessionsIndex[fieldName]; !hasFieldName { // Init it here so we can minimize
			smg.aSessionsIndex[fieldName] = make(map[string]utils.StringMap)
		}
		if _, hasFieldVal := smg.aSessionsIndex[fieldName][fieldVal]; !hasFieldVal {
			smg.aSessionsIndex[fieldName][fieldVal] = make(utils.StringMap)
		}
		smg.aSessionsIndex[fieldName][fieldVal][uuid] = true
	}
	return true
}
Beispiel #2
0
func (fltr *RequestFilter) passRSRFields(req interface{}, extraFieldsLabel string) (bool, error) {
	for _, rsrFld := range fltr.rsrFields {
		if strVal, err := utils.ReflectFieldAsString(req, rsrFld.Id, extraFieldsLabel); err != nil {
			return false, err
		} else if rsrFld.FilterPasses(strVal) {
			return true, nil
		}
	}
	return false, nil
}
Beispiel #3
0
func (fltr *RequestFilter) passStringPrefix(req interface{}, extraFieldsLabel string) (bool, error) {
	strVal, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
	if err != nil {
		return false, err
	}
	for _, prfx := range fltr.Values {
		if strings.HasPrefix(strVal, prfx) {
			return true, nil
		}
	}
	return false, nil
}
Beispiel #4
0
func (fltr *RequestFilter) passString(req interface{}, extraFieldsLabel string) (bool, error) {
	strVal, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
	if err != nil {
		if err == utils.ErrNotFound {
			return false, nil
		}
		return false, err
	}
	for _, val := range fltr.Values {
		if strVal == val {
			return true, nil
		}
	}
	return false, nil
}
Beispiel #5
0
func (fltr *RequestFilter) passDestinations(req interface{}, extraFieldsLabel string) (bool, error) {
	dst, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
	if err != nil {
		return false, err
	}
	for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) {
		if x, err := CacheGet(utils.DESTINATION_PREFIX + p); err == nil {
			destIds := x.(map[string]struct{})
			for dID := range destIds {
				for _, valDstID := range fltr.Values {
					if valDstID == dID {
						return true, nil
					}
				}
			}
		}
	}
	return false, nil
}
Beispiel #6
0
// indexSession explores settings and builds SessionsIndex
// uses different tables and mutex-es depending on active/passive session
func (smg *SMGeneric) indexSession(s *SMGSession, passiveSessions bool) {
	idxMux := &smg.aSIMux // pointer to original mux since we cannot copy it
	ssIndx := smg.aSessionsIndex
	ssRIdx := smg.aSessionsRIndex
	if passiveSessions {
		idxMux = &smg.pSIMux
		ssIndx = smg.pSessionsIndex
		ssRIdx = smg.pSessionsRIndex
	}
	idxMux.Lock()
	defer idxMux.Unlock()
	for fieldName := range smg.ssIdxCfg {
		fieldVal, err := utils.ReflectFieldAsString(s.EventStart, fieldName, "")
		if err != nil {
			if err == utils.ErrNotFound {
				fieldVal = utils.NOT_AVAILABLE
			} else {
				utils.Logger.Err(fmt.Sprintf("<SMGeneric> Error retrieving field: %s from event: %+v", fieldName, s.EventStart))
				continue
			}
		}
		if fieldVal == "" {
			fieldVal = utils.MetaEmpty
		}
		if _, hasFieldName := ssIndx[fieldName]; !hasFieldName { // Init it here
			ssIndx[fieldName] = make(map[string]map[string]utils.StringMap)
		}
		if _, hasFieldVal := ssIndx[fieldName][fieldVal]; !hasFieldVal {
			ssIndx[fieldName][fieldVal] = make(map[string]utils.StringMap)
		}
		if _, hasFieldVal := ssIndx[fieldName][fieldVal][s.RunID]; !hasFieldVal {
			ssIndx[fieldName][fieldVal][s.RunID] = make(utils.StringMap)
		}
		ssIndx[fieldName][fieldVal][s.RunID][s.CGRID] = true
		if _, hasIt := ssRIdx[s.CGRID]; !hasIt {
			ssRIdx[s.CGRID] = make([]*riFieldNameVal, 0)
		}
		ssRIdx[s.CGRID] = append(ssRIdx[s.CGRID], &riFieldNameVal{runID: s.RunID, fieldName: fieldName, fieldValue: fieldVal})
	}
	return
}
Beispiel #7
0
func (fltr *RequestFilter) passDestinations(req interface{}, extraFieldsLabel string) (bool, error) {
	dst, err := utils.ReflectFieldAsString(req, fltr.FieldName, extraFieldsLabel)
	if err != nil {
		if err == utils.ErrNotFound {
			return false, nil
		}
		return false, err
	}
	for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) {
		if destIDs, err := ratingStorage.GetReverseDestination(p, false, utils.NonTransactional); err == nil {
			for _, dID := range destIDs {
				for _, valDstID := range fltr.Values {
					if valDstID == dID {
						return true, nil
					}
				}
			}
		}
	}
	return false, nil
}