diff --git a/cmd/embed/main.go b/cmd/embed/main.go index 167a14f..0f6fdd6 100644 --- a/cmd/embed/main.go +++ b/cmd/embed/main.go @@ -6,10 +6,10 @@ import ( "flag" "os" - "github.com/sleepinggenius2/gosmi" + "github.com/min-oc/gosmi" ) -//go:embed FIZBIN-MIB.mib +//go:embed mibs var fs embed.FS func main() { @@ -18,7 +18,7 @@ func main() { gosmi.Init() - gosmi.SetFS(gosmi.NamedFS("Embed Example", fs)) + gosmi.SetFS(gosmi.NamedFS("mibs", fs)) m, err := gosmi.GetModule(*module) if err != nil { diff --git a/cmd/embed/FIZBIN-MIB.mib b/cmd/embed/mibs/FIZBIN-MIB.mib similarity index 100% rename from cmd/embed/FIZBIN-MIB.mib rename to cmd/embed/mibs/FIZBIN-MIB.mib diff --git a/cmd/parse/main.go b/cmd/parse/main.go index db24ce1..566cd60 100644 --- a/cmd/parse/main.go +++ b/cmd/parse/main.go @@ -5,7 +5,7 @@ import ( "os" "github.com/alecthomas/repr" - "github.com/sleepinggenius2/gosmi/parser" + "github.com/min-oc/gosmi/parser" ) func main() { diff --git a/cmd/smi/main.go b/cmd/smi/main.go index 93655c9..1c9f968 100644 --- a/cmd/smi/main.go +++ b/cmd/smi/main.go @@ -7,8 +7,8 @@ import ( "os" "strings" - "github.com/sleepinggenius2/gosmi" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi" + "github.com/min-oc/gosmi/types" ) type arrayStrings []string diff --git a/config.go b/config.go index 61957ff..4b8bce3 100644 --- a/config.go +++ b/config.go @@ -3,7 +3,7 @@ package gosmi import ( "os" - "github.com/sleepinggenius2/gosmi/smi" + "github.com/min-oc/gosmi/smi" ) func Init() { diff --git a/go.mod b/go.mod index 3ea1cc3..b72f0e9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/sleepinggenius2/gosmi +module github.com/min-oc/gosmi go 1.16 diff --git a/models/format.go b/models/format.go index b90970e..1a7fbb3 100644 --- a/models/format.go +++ b/models/format.go @@ -7,7 +7,7 @@ import ( "strconv" "time" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type Format byte diff --git a/models/module.go b/models/module.go index f6ced35..d977088 100644 --- a/models/module.go +++ b/models/module.go @@ -3,7 +3,7 @@ package models import ( "time" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type Import struct { diff --git a/models/node.go b/models/node.go index fa724a4..73daa40 100644 --- a/models/node.go +++ b/models/node.go @@ -1,7 +1,7 @@ package models import ( - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type Node struct { diff --git a/models/nodes.go b/models/nodes.go index bee49ba..87cd7c7 100644 --- a/models/nodes.go +++ b/models/nodes.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type BaseNode struct { diff --git a/models/type.go b/models/type.go index 951aaae..bd66f25 100644 --- a/models/type.go +++ b/models/type.go @@ -5,7 +5,7 @@ import ( "fmt" "sync" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type Enum struct { diff --git a/module.go b/module.go index 2cc0146..1afdb24 100644 --- a/module.go +++ b/module.go @@ -3,9 +3,9 @@ package gosmi import ( "fmt" - "github.com/sleepinggenius2/gosmi/models" - "github.com/sleepinggenius2/gosmi/smi" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/models" + "github.com/min-oc/gosmi/smi" + "github.com/min-oc/gosmi/types" ) type SmiModule struct { diff --git a/node.go b/node.go index 84cf46c..c95d004 100644 --- a/node.go +++ b/node.go @@ -3,9 +3,9 @@ package gosmi import ( "fmt" - "github.com/sleepinggenius2/gosmi/models" - "github.com/sleepinggenius2/gosmi/smi" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/models" + "github.com/min-oc/gosmi/smi" + "github.com/min-oc/gosmi/types" ) type SmiNode struct { diff --git a/notification.go b/notification.go index 45ecd7e..0a6d823 100644 --- a/notification.go +++ b/notification.go @@ -1,7 +1,7 @@ package gosmi import ( - "github.com/sleepinggenius2/gosmi/smi" + "github.com/min-oc/gosmi/smi" ) type Notification struct { diff --git a/parser/common.go b/parser/common.go index d08f421..d6da04b 100644 --- a/parser/common.go +++ b/parser/common.go @@ -6,7 +6,7 @@ import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type SubIdentifier struct { diff --git a/parser/compliance.go b/parser/compliance.go index deb428e..b56a755 100644 --- a/parser/compliance.go +++ b/parser/compliance.go @@ -3,7 +3,7 @@ package parser import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type AgentCapabilityVariation struct { diff --git a/parser/macro.go b/parser/macro.go index 0a16e46..39dd79a 100644 --- a/parser/macro.go +++ b/parser/macro.go @@ -5,7 +5,7 @@ import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type MacroBody struct { diff --git a/parser/module.go b/parser/module.go index 1879a36..5381db1 100644 --- a/parser/module.go +++ b/parser/module.go @@ -5,7 +5,7 @@ import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type Date string diff --git a/parser/notification.go b/parser/notification.go index f54bf68..c973c6f 100644 --- a/parser/notification.go +++ b/parser/notification.go @@ -3,7 +3,7 @@ package parser import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type NotificationGroup struct { diff --git a/parser/object.go b/parser/object.go index 6db959f..3b4392f 100644 --- a/parser/object.go +++ b/parser/object.go @@ -3,7 +3,7 @@ package parser import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type ObjectGroup struct { diff --git a/parser/type.go b/parser/type.go index 12fd5d3..1035d17 100644 --- a/parser/type.go +++ b/parser/type.go @@ -3,7 +3,7 @@ package parser import ( "github.com/alecthomas/participle/lexer" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type TextualConvention struct { diff --git a/smi/config.go b/smi/config.go index 412dba8..785ff4c 100644 --- a/smi/config.go +++ b/smi/config.go @@ -7,8 +7,8 @@ import ( "runtime" "strings" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) const ( @@ -29,7 +29,7 @@ var DefaultSmiPaths []string = []string{ type FS = internal.FS type NamedFS = internal.NamedFS -func NewNamedFS(name string, fs FS) NamedFS { return NamedFS{Name: "[" + name + "]", FS: fs} } +func NewNamedFS(name string, fs FS) NamedFS { return NamedFS{Name: name, FS: fs} } func checkInit() { if !internal.Initialized() { diff --git a/smi/internal/handle.go b/smi/internal/handle.go index 7fddc69..f7ff0b0 100644 --- a/smi/internal/handle.go +++ b/smi/internal/handle.go @@ -1,8 +1,8 @@ package internal import ( - "github.com/sleepinggenius2/gosmi/parser" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/parser" + "github.com/min-oc/gosmi/types" ) const WellKnownModuleName types.SmiIdentifier = "" diff --git a/smi/internal/import.go b/smi/internal/import.go index 045acd2..5b28f39 100644 --- a/smi/internal/import.go +++ b/smi/internal/import.go @@ -1,7 +1,7 @@ package internal import ( - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) var importConversions map[types.SmiImport]types.SmiImport = map[types.SmiImport]types.SmiImport{ diff --git a/smi/internal/macro.go b/smi/internal/macro.go index d1953ef..e250afc 100644 --- a/smi/internal/macro.go +++ b/smi/internal/macro.go @@ -1,7 +1,7 @@ package internal import ( - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type Macro struct { diff --git a/smi/internal/module.go b/smi/internal/module.go index 3d2cca9..f82b039 100644 --- a/smi/internal/module.go +++ b/smi/internal/module.go @@ -7,10 +7,11 @@ import ( "os" "path/filepath" "strings" + "sync" "time" - "github.com/sleepinggenius2/gosmi/parser" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/parser" + "github.com/min-oc/gosmi/types" ) type Module struct { @@ -173,6 +174,7 @@ func (x *Module) getTrapTypePlaceholder(enterprise types.SmiIdentifier, line int } type ModuleMap struct { + sync.RWMutex First *Module last *Module @@ -181,6 +183,8 @@ type ModuleMap struct { } func (x *ModuleMap) Add(m *Module) { + x.Lock() + defer x.Unlock() if m.IsWellKnown() { x.wellKnown = m } @@ -199,6 +203,8 @@ func (x *ModuleMap) Add(m *Module) { } func (x *ModuleMap) Get(name types.SmiIdentifier) *Module { + x.RLock() + defer x.RUnlock() if name == WellKnownModuleName { return x.wellKnown } @@ -303,7 +309,10 @@ func GetModuleFile(name string) (string, io.ReadCloser, error) { } for _, path := range smiHandle.Paths { - dirEntries, err := path.FS.ReadDir(".") + if filepath.IsAbs(path.Name) { + path.Name = "" + } + dirEntries, err := path.FS.ReadDir(path.Name) if err != nil { return path.Name, nil, fmt.Errorf("Read directory: %w", err) } @@ -321,8 +330,8 @@ func GetModuleFile(name string) (string, io.ReadCloser, error) { } switch ext { case "", "mib", "my", "mi2", "txt": - fullpath := filepath.Join(path.Name, dirEntry.Name()) - r, err := path.FS.Open(dirEntry.Name()) + fullpath := path.Name + "/" + dirEntry.Name() + r, err := path.FS.Open(fullpath) if err != nil { return fullpath, nil, fmt.Errorf("Open file: %w", err) } diff --git a/smi/internal/node.go b/smi/internal/node.go index 6329e85..c7d6ab7 100644 --- a/smi/internal/node.go +++ b/smi/internal/node.go @@ -1,7 +1,9 @@ package internal import ( - "github.com/sleepinggenius2/gosmi/types" + "sync" + + "github.com/min-oc/gosmi/types" ) type Node struct { @@ -33,6 +35,7 @@ func (x *Node) IsRoot() bool { } type NodeChildMap struct { + sync.RWMutex First *Node last *Node @@ -40,6 +43,7 @@ type NodeChildMap struct { } func (x *NodeChildMap) Add(n *Node) { + existing := x.Get(n.SubId) if existing != nil { for obj := n.FirstObject; obj != nil; obj = obj.NextSameNode { @@ -47,6 +51,8 @@ func (x *NodeChildMap) Add(n *Node) { } return } + x.Lock() + defer x.Unlock() if n.Parent != nil && n.Parent.Oid != nil { n.Oid = types.NewOid(n.Parent.Oid, n.SubId) n.OidLen = n.Parent.OidLen + 1 @@ -82,6 +88,8 @@ func (x *NodeChildMap) Add(n *Node) { } func (x *NodeChildMap) Get(id types.SmiSubId) *Node { + x.RLock() + defer x.RUnlock() if x.m == nil { return nil } diff --git a/smi/internal/object.go b/smi/internal/object.go index 465a053..51a07fc 100644 --- a/smi/internal/object.go +++ b/smi/internal/object.go @@ -1,8 +1,8 @@ package internal import ( - "github.com/sleepinggenius2/gosmi/parser" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/parser" + "github.com/min-oc/gosmi/types" ) type Option struct { diff --git a/smi/internal/type.go b/smi/internal/type.go index a057f0c..8d5af06 100644 --- a/smi/internal/type.go +++ b/smi/internal/type.go @@ -4,8 +4,8 @@ import ( "sort" "strconv" - "github.com/sleepinggenius2/gosmi/parser" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/parser" + "github.com/min-oc/gosmi/types" ) type Type struct { diff --git a/smi/internal/types.go b/smi/internal/types.go index 66ade0b..cea5bce 100644 --- a/smi/internal/types.go +++ b/smi/internal/types.go @@ -1,7 +1,7 @@ package internal import ( - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/types" ) type List struct { diff --git a/smi/macro.go b/smi/macro.go index 01a48ea..c2d933e 100644 --- a/smi/macro.go +++ b/smi/macro.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiMacro *smiGetMacro(SmiModule *smiModulePtr, char *macro) diff --git a/smi/module.go b/smi/module.go index 946305e..81476fd 100644 --- a/smi/module.go +++ b/smi/module.go @@ -4,8 +4,8 @@ import ( "fmt" "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // char *smiLoadModule(const char *module) diff --git a/smi/module_import.go b/smi/module_import.go index cce0a4b..b21d2fe 100644 --- a/smi/module_import.go +++ b/smi/module_import.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiImport *smiGetFirstImport(SmiModule *smiModulePtr) diff --git a/smi/module_revision.go b/smi/module_revision.go index b2676d1..7d52913 100644 --- a/smi/module_revision.go +++ b/smi/module_revision.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiRevision *smiGetFirstRevision(SmiModule *smiModulePtr) diff --git a/smi/node.go b/smi/node.go index af94665..93c39a0 100644 --- a/smi/node.go +++ b/smi/node.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiNode *smiGetNode(SmiModule *smiModulePtr, const char *name) diff --git a/smi/node_element.go b/smi/node_element.go index 00c894c..cca1aaa 100644 --- a/smi/node_element.go +++ b/smi/node_element.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiElement *smiGetFirstElement(SmiNode *smiNodePtr) diff --git a/smi/node_option.go b/smi/node_option.go index 8872f13..7484406 100644 --- a/smi/node_option.go +++ b/smi/node_option.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiOption *smiGetFirstOption(SmiNode *smiComplianceNodePtr) diff --git a/smi/node_refinement.go b/smi/node_refinement.go index 71dad3e..63b0c8d 100644 --- a/smi/node_refinement.go +++ b/smi/node_refinement.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiRefinement *smiGetFirstRefinement(SmiNode *smiComplianceNodePtr) diff --git a/smi/render.go b/smi/render.go index a730f19..3b13aa1 100644 --- a/smi/render.go +++ b/smi/render.go @@ -4,8 +4,8 @@ import ( "strconv" "strings" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) func RenderNode(smiNodePtr *types.SmiNode, flags types.Render) string { diff --git a/smi/type.go b/smi/type.go index 833ab5c..4970f46 100644 --- a/smi/type.go +++ b/smi/type.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiType *smiGetType(SmiModule *smiModulePtr, char *type) diff --git a/smi/type_named_number.go b/smi/type_named_number.go index 75eddb7..e8420e1 100644 --- a/smi/type_named_number.go +++ b/smi/type_named_number.go @@ -3,8 +3,8 @@ package smi import ( "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiNamedNumber *smiGetFirstNamedNumber(SmiType *smiTypePtr) diff --git a/smi/type_range.go b/smi/type_range.go index 0b65c35..0d22f7e 100644 --- a/smi/type_range.go +++ b/smi/type_range.go @@ -4,8 +4,8 @@ import ( "math" "unsafe" - "github.com/sleepinggenius2/gosmi/smi/internal" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi/internal" + "github.com/min-oc/gosmi/types" ) // SmiRange *smiGetFirstRange(SmiType *smiTypePtr) diff --git a/table.go b/table.go index 738da00..410731e 100644 --- a/table.go +++ b/table.go @@ -1,8 +1,8 @@ package gosmi import ( - "github.com/sleepinggenius2/gosmi/smi" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/smi" + "github.com/min-oc/gosmi/types" ) type Table struct { diff --git a/type.go b/type.go index b71edbe..976a27f 100644 --- a/type.go +++ b/type.go @@ -3,9 +3,9 @@ package gosmi import ( "fmt" - "github.com/sleepinggenius2/gosmi/models" - "github.com/sleepinggenius2/gosmi/smi" - "github.com/sleepinggenius2/gosmi/types" + "github.com/min-oc/gosmi/models" + "github.com/min-oc/gosmi/smi" + "github.com/min-oc/gosmi/types" ) type SmiType struct {