iproute icon indicating copy to clipboard operation
iproute copied to clipboard

Add parse from ByteString

Open tonal opened this issue 8 years ago • 4 comments

Add parse from ByteString and Text

tonal avatar Jul 15 '16 11:07 tonal

Are you talking about IP?

kazu-yamamoto avatar Jul 19 '16 06:07 kazu-yamamoto

Yes. I parse very big apache log files and find each IP in RouteTable.

tonal avatar Jul 19 '16 11:07 tonal

OK. Could you implement it by yourself and give me a pull request?

kazu-yamamoto avatar Jul 20 '16 00:07 kazu-yamamoto

I work throuth 4Int list:

import Control.Applicative
import Data.Attoparsec.ByteString
import qualified Data.ByteString.Char8 as BC
import Data.ByteString.Internal (c2w)

ip2list :: BC.ByteString -> [Int]
ip2list ipstr =
  case parseOnly pIP2list ipstr of
    Left msg -> error msg
    Right ip -> ip

pIP2list :: Parser [Int]
pIP2list = toIP <$> dd <*> dd <*> dd <*> dig
  where
    toIP a b c d = [a, b, c, d]
    dig = AC.decimal
    dd = dig <* skip (== c2w '.')

And my ipFilter:

ipFiltr :: IPRTable IPv4 () -> LogLine -> Bool
ipFiltr bans
  = DM.isNothing . flip lookup bans
  . flip makeAddrRange 32 . toIPv4 . ip2list . getLogIP

tonal avatar Jul 20 '16 05:07 tonal