@@ -13,6 +13,9 @@ import (
1313 "sync"
1414 "time"
1515 "unicode"
16+
17+ iradix "github.com/hashicorp/go-immutable-radix"
18+ "github.com/jedisct1/dlog"
1619)
1720
1821type CryptoConstruction uint16
@@ -281,3 +284,44 @@ func ParseIPRule(line string, lineNo int) (cleanLine string, trailingStar bool,
281284
282285 return strings .ToLower (cleanLine ), trailingStar , nil
283286}
287+
288+ // ProcessConfigLines processes configuration file lines, calling the processor function for each non-empty line
289+ func ProcessConfigLines (lines string , processor func (line string , lineNo int ) error ) error {
290+ for lineNo , line := range strings .Split (lines , "\n " ) {
291+ line = TrimAndStripInlineComments (line )
292+ if len (line ) == 0 {
293+ continue
294+ }
295+ if err := processor (line , lineNo ); err != nil {
296+ return err
297+ }
298+ }
299+ return nil
300+ }
301+
302+ // LoadIPRules loads IP rules from text lines into radix tree and map structures
303+ func LoadIPRules (lines string , prefixes * iradix.Tree , ips map [string ]interface {}) (* iradix.Tree , error ) {
304+ err := ProcessConfigLines (lines , func (line string , lineNo int ) error {
305+ cleanLine , trailingStar , lineErr := ParseIPRule (line , lineNo )
306+ if lineErr != nil {
307+ dlog .Error (lineErr )
308+ return nil // Continue processing (matching existing behavior)
309+ }
310+
311+ if trailingStar {
312+ prefixes , _ , _ = prefixes .Insert ([]byte (cleanLine ), 0 )
313+ } else {
314+ ips [cleanLine ] = true
315+ }
316+ return nil
317+ })
318+ return prefixes , err
319+ }
320+
321+ // InitializePluginLogger initializes a logger for a plugin if the log file is configured
322+ func InitializePluginLogger (logFile , format string , maxSize , maxAge , maxBackups int ) (io.Writer , string ) {
323+ if len (logFile ) > 0 {
324+ return Logger (maxSize , maxAge , maxBackups , logFile ), format
325+ }
326+ return nil , ""
327+ }
0 commit comments