From 3b64f480e22bc2ac0c50bad5ebe628fd9dbea8b3 Mon Sep 17 00:00:00 2001 From: Zach Date: Sun, 2 Sep 2018 18:41:53 -0400 Subject: [PATCH] Move generic functions from query to registry These functions no longer have TCP based dependencies on them, they belong to the registry itself instead --- whois/query.go | 35 ----------------------------------- whois/registry.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/whois/query.go b/whois/query.go index 6fc6483..6c9ab17 100644 --- a/whois/query.go +++ b/whois/query.go @@ -25,41 +25,6 @@ func (r *Registry) handleObject(conn *net.TCPConn, object Object, flags *Flags) return found } -func (r *Registry) findObjectPaths(object Object) []pathpair { - var paths []pathpair - for _, t := range r.whoisTypes { - if t.Kind == ROUTE || t.Kind == ROUTE6 { - if object[t.Kind] != nil { - p := r.getObjFromIP(t.Name, object[t.Kind].(net.IP)) - paths = append(paths, p...) - } - } else { - arg := object[t.Kind].(string) - if t.Pattern.MatchString(arg) { - paths = append(paths, pathpair{t.Name, arg}) - } - } - } - return paths -} - -func (r *Registry) getObjFromIP(objType string, ip net.IP) []pathpair { - var paths []pathpair - routePath := path.Join(r.DataPath, objType) - cidrs, err := readCidrs(routePath) - if err != nil { - return paths - } - - for _, c := range cidrs { - if c.Contains(ip) { - obj := strings.Replace(c.String(), "/", "_", -1) - paths = append(paths, pathpair{objType, obj}) - } - } - return paths -} - func (r *Registry) HandleQuery(conn *net.TCPConn) { fmt.Fprint(conn, "% " + r.Header + "\n\n") diff --git a/whois/registry.go b/whois/registry.go index f5c12d0..5623d61 100644 --- a/whois/registry.go +++ b/whois/registry.go @@ -76,6 +76,41 @@ func (r *Registry) retrieveObject(objType string, obj string) ([]byte, string, e return fall, file[len(r.DataPath)+1:], nil } +func (r *Registry) findObjectPaths(object Object) []pathpair { + var paths []pathpair + for _, t := range r.whoisTypes { + if t.Kind == ROUTE || t.Kind == ROUTE6 { + if object[t.Kind] != nil { + p := r.getObjFromIP(t.Name, object[t.Kind].(net.IP)) + paths = append(paths, p...) + } + } else { + arg := object[t.Kind].(string) + if t.Pattern.MatchString(arg) { + paths = append(paths, pathpair{t.Name, arg}) + } + } + } + return paths +} + +func (r *Registry) getObjFromIP(objType string, ip net.IP) []pathpair { + var paths []pathpair + routePath := path.Join(r.DataPath, objType) + cidrs, err := readCidrs(routePath) + if err != nil { + return paths + } + + for _, c := range cidrs { + if c.Contains(ip) { + obj := strings.Replace(c.String(), "/", "_", -1) + paths = append(paths, pathpair{objType, obj}) + } + } + return paths +} + func readCidrs(path string) ([]net.IPNet, error) { files, err := ioutil.ReadDir(path) if err != nil {