Exemple #1
0
// call for each key after all persists added
func (ct *cTest) commit(p priority.List, prev int) error {
	if ct.buffer == nil {
		return nil
	}
	// don't set priorities if any of the persists are identical
	var dupes bool
	var err error
	for i, v := range ct.buffer {
		if i == len(ct.buffer)-1 {
			break
		}
		for _, v2 := range ct.buffer[i+1:] {
			if v.Equals(v2) {
				dupes = true
				break
			}
		}
	}
	if dupes {
		ct.bm, _, err = bytematcher.Add(ct.bm, bytematcher.SignatureSet(ct.buffer), nil)
		ct.bm.(*bytematcher.Matcher).SetLowMem()
		ct.buffer = nil
		return err
	}
	ct.bm, _, err = bytematcher.Add(ct.bm, bytematcher.SignatureSet(ct.buffer), nil)
	ct.bm.(*bytematcher.Matcher).SetLowMem()
	ct.buffer = nil
	return err
}
Exemple #2
0
func (b *Base) Add(m core.Matcher, t core.MatcherType) (core.Matcher, error) {
	var l int
	var err error
	switch t {
	default:
		return nil, fmt.Errorf("Identifier: unknown matcher type %d", t)
	case core.NameMatcher:
		var globs []string
		globs, b.gids.ids = b.p.Globs()
		m, l, err = namematcher.Add(m, namematcher.SignatureSet(globs), nil)
		if err != nil {
			return nil, err
		}
		b.gids.start = l - len(b.gids.ids)
	case core.ContainerMatcher:
		znames, zsigs, zids, err := b.p.Zips()
		if err != nil {
			return nil, err
		}
		m, _, err = containermatcher.Add(m, containermatcher.SignatureSet{containermatcher.Zip, znames, zsigs}, b.p.Priorities().List(zids))
		if err != nil {
			return nil, err
		}
		mnames, msigs, mids, err := b.p.MSCFBs()
		if err != nil {
			return nil, err
		}
		m, l, err = containermatcher.Add(m, containermatcher.SignatureSet{containermatcher.Mscfb, mnames, msigs}, b.p.Priorities().List(mids))
		if err != nil {
			return nil, err
		}
		b.cids.ids = append(zids, mids...)
		b.cids.start = l - len(b.cids.ids)
	case core.MIMEMatcher:
		var mimes []string
		mimes, b.mids.ids = b.p.MIMEs()
		m, l, err = mimematcher.Add(m, mimematcher.SignatureSet(mimes), nil)
		if err != nil {
			return nil, err
		}
		b.mids.start = l - len(b.mids.ids)
	case core.XMLMatcher:
		var xmls [][2]string
		xmls, b.xids.ids = b.p.XMLs()
		m, l, err = xmlmatcher.Add(m, xmlmatcher.SignatureSet(xmls), nil)
		if err != nil {
			return nil, err
		}
		b.xids.start = l - len(b.xids.ids)
	case core.ByteMatcher:
		var sigs []frames.Signature
		var err error
		sigs, b.bids.ids, err = b.p.Signatures()
		if err != nil {
			return nil, err
		}
		m, l, err = bytematcher.Add(m, bytematcher.SignatureSet(sigs), b.p.Priorities().List(b.bids.ids))
		if err != nil {
			return nil, err
		}
		b.bids.start = l - len(b.bids.ids)
	case core.RIFFMatcher:
		var riffs [][4]byte
		riffs, b.rids.ids = b.p.RIFFs()
		m, l, err = riffmatcher.Add(m, riffmatcher.SignatureSet(riffs), b.p.Priorities().List(b.rids.ids))
		if err != nil {
			return nil, err
		}
		b.rids.start = l - len(b.rids.ids)
	case core.TextMatcher:
		b.tids.ids = b.p.Texts()
		if len(b.tids.ids) > 0 {
			m, l, _ = textmatcher.Add(m, textmatcher.SignatureSet{}, nil)
			b.tids.start = l
		}
	}
	return m, nil
}