Skip to content

Commit

Permalink
Merge pull request #2 from projectdiscovery/feature-scan-support
Browse files Browse the repository at this point in the history
adding scan support
  • Loading branch information
Mzack9999 authored Oct 26, 2020
2 parents cebbd0e + 71aac0a commit db41b57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
10 changes: 10 additions & 0 deletions store/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Cache interface {
DeleteExpired()
OnEvicted(func(string, interface{}))
CloneItems() map[string]Item
Scan(func([]byte, []byte) error)
ItemCount() int
}

Expand Down Expand Up @@ -144,6 +145,15 @@ func (c *CacheMemory) OnEvicted(f func(string, interface{})) {
c.onEvicted = f
}

func (c *CacheMemory) Scan(f func([]byte, []byte) error) {
c.mu.Lock()
defer c.mu.Unlock()

for k, item := range c.Items {
f([]byte(k), item.Object.([]byte))
}
}

func (c *CacheMemory) CloneItems() map[string]Item {
c.mu.RLock()
defer c.mu.RUnlock()
Expand Down
2 changes: 1 addition & 1 deletion store/disk/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ type ScannerOptions struct {
FetchValues bool

// the handler that handles the incoming data
Handler func(k, v string) bool
Handler func(k []byte, v []byte) error
}
5 changes: 2 additions & 3 deletions store/disk/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -218,8 +217,8 @@ func (ldb *LevelDB) Scan(scannerOpt ScannerOptions) error {

for iter.Next() {
key := iter.Key()
val := strings.SplitN(string(iter.Value()), ";", 2)[1]
if !valid(key) || !scannerOpt.Handler(string(key), string(val)) {
val := bytes.SplitN(iter.Value(), []byte(";"), 2)[1]
if !valid(key) || scannerOpt.Handler(key, val) != nil {
break
}
}
Expand Down
12 changes: 12 additions & 0 deletions store/hybrid/hybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ func (hm *HybridMap) Del(key string) error {
return nil
}

func (hm *HybridMap) Scan(f func([]byte, []byte) error) {
switch hm.options.Type {
case Memory:
hm.memorymap.Scan(f)
case Hybrid:
hm.memorymap.Scan(f)
hm.diskmap.Scan(disk.ScannerOptions{Handler: f})
case Disk:
hm.diskmap.Scan(disk.ScannerOptions{Handler: f})
}
}

func (hm *HybridMap) Size() int64 {
return 0
}
Expand Down

0 comments on commit db41b57

Please sign in to comment.