Network.Anonymous.Tor.Protocol.Parser.Ast: exported symbols usage examples

Symbols

  • key See 5 Occurences [+] Collapse [-]
    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
      return (A.Token k (Just v))
    
    -- | Parses a key, which is anything until either a space has been reached, or
    --   an '=' is reached.
    key :: Atto.Parser A.Token
    key =
      let isKeyEnd '=' = True
          isKeyEnd c   = Atto8.isSpace c
    
      in flip A.Token Nothing <$> Atto8.takeWhile1 (not . isKeyEnd)
    
    -- | A Token is either a Key or a Key/Value combination.
    token :: Atto.Parser A.Token
    token =
      Atto.skipWhile Atto8.isHorizontalSpace *> (keyValue <|> key)
    
    -- | Parser that reads keys or key/values
    tokens :: Atto.Parser [A.Token]
    tokens =
      Atto.many' token
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
      quotedString <|> unquotedString
    
    -- | Parses key and value
    keyValue :: Atto.Parser A.Token
    keyValue = do
      A.Token k _ <- key
      _ <- Atto.word8 equals
      v <- value
    
      return (A.Token k (Just v))
    
    -- | Parses a key, which is anything until either a space has been reached, or
    --   an '=' is reached.
    key :: Atto.Parser A.Token
    key =
      let isKeyEnd '=' = True
          isKeyEnd c   = Atto8.isSpace c
    
      in flip A.Token Nothing <$> Atto8.takeWhile1 (not . isKeyEnd)
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
    value =
      quotedString <|> unquotedString
    
    -- | Parses key and value
    keyValue :: Atto.Parser A.Token
    keyValue = do
      A.Token k _ <- key
      _ <- Atto.word8 equals
      v <- value
    
      return (A.Token k (Just v))
    
    -- | Parses a key, which is anything until either a space has been reached, or
    --   an '=' is reached.
    key :: Atto.Parser A.Token
    key =
      let isKeyEnd '=' = True
          isKeyEnd c   = Atto8.isSpace c
    
      in flip A.Token Nothing <$> Atto8.takeWhile1 (not . isKeyEnd)
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
      return (replies ++ [lastReply])
    
      where
        replyLine :: Word8 -> Atto.Parser A.Line
        replyLine c = A.Line <$> Atto8.decimal <*> (Atto.word8 c *> tokens) <* Atto8.endOfLine
    
    -- | Parses either a quoted value or an unquoted value
    value :: Atto.Parser BS.ByteString
    value =
      quotedString <|> unquotedString
    
    -- | Parses key and value
    keyValue :: Atto.Parser A.Token
    keyValue = do
      A.Token k _ <- key
      _ <- Atto.word8 equals
      v <- value
    
      return (A.Token k (Just v))
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
    -- | Parser defintions
    --
    -- Defines parsers used by the Tor Control protocol
    --
    --   __Warning__: This function is used internally by 'Network.Anonymous.Tor'
    --                and using these functions directly is unsupported. The
    --                interface of these functions might change at any time without
    --                prior notice.
    --
    
    module Network.Anonymous.Tor.Protocol.Parser ( quotedString
                                                 , unquotedString
                                                 , reply
                                                 , key
                                                 , keyValue
                                                 , value
                                                 , token
                                                 , tokens ) where
    

    line See 6 Occurences [+] Collapse [-]
    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
             -> Bool                -- ^ Wether to detach the hidden service from the current session
             -> Maybe BS.ByteString -- ^ Optional private key to use to set up the hidden service
             -> m B32.Base32String  -- ^ The address/service id of the Onion without the .onion part
    mapOnion s rport lport detach pkey = do
      reply <- sendCommand s $ BS8.concat
                                [ "ADD_ONION "
                                , maybe "NEW:BEST" (\pk -> "RSA1024:" `BS.append` pk) pkey
                                , if detach then " Flags=Detach " else " "
                                , "Port="
                                , BS8.pack (show rport)
                                , ",127.0.0.1:"
                                , BS8.pack(show lport)
                                , "\n"]
    
      return . B32.b32String' . fromJust . Ast.tokenValue . head . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "ServiceID") reply
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    
        methods :: [Ast.Line] -> [T.AuthMethod]
        methods reply =
          map (read . BS8.unpack) . BS8.split ',' . fromJust . Ast.value "METHODS" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    
        cookieFile :: [Ast.Line] -> Maybe FilePath
        cookieFile reply =
          fmap BS8.unpack . Ast.value "COOKIEFILE" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    
    -- | Authenticates with the Tor control server, based on the authentication
    --   information returned by PROTOCOLINFO.
    authenticate :: MonadIO m
                 => Network.Socket
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
      return (T.ProtocolInfo (protocolVersion res) (torVersion res) (methods res) (cookieFile res))
    
      where
    
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    
        methods :: [Ast.Line] -> [T.AuthMethod]
        methods reply =
          map (read . BS8.unpack) . BS8.split ',' . fromJust . Ast.value "METHODS" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    
        cookieFile :: [Ast.Line] -> Maybe FilePath
        cookieFile reply =
          fmap BS8.unpack . Ast.value "COOKIEFILE" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
                 -> m T.ProtocolInfo
    protocolInfo s = do
      res <- sendCommand s (BS.concat ["PROTOCOLINFO", "\n"])
    
      return (T.ProtocolInfo (protocolVersion res) (torVersion res) (methods res) (cookieFile res))
    
      where
    
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    
        methods :: [Ast.Line] -> [T.AuthMethod]
        methods reply =
          map (read . BS8.unpack) . BS8.split ',' . fromJust . Ast.value "METHODS" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
    --   still unauthenticated and authentication methods can be derived from this
    --   information.
    protocolInfo :: MonadIO m
                 => Network.Socket
                 -> m T.ProtocolInfo
    protocolInfo s = do
      res <- sendCommand s (BS.concat ["PROTOCOLINFO", "\n"])
    
      return (T.ProtocolInfo (protocolVersion res) (torVersion res) (methods res) (cookieFile res))
    
      where
    
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
      takeMVar result
    
      where
        performTest port result =
          NST.connect "127.0.0.1" (show port) (\(sock, _) -> do
                                                    _ <- protocolInfo sock
                                                    putMVar result Available)
    -- | Returns the configured SOCKS proxy port
    socksPort :: MonadIO m
              => Network.Socket
              -> m Integer
    socksPort s = do
      reply <- sendCommand s (BS8.pack "GETCONF SOCKSPORT\n")
    
      return . fst . fromJust . BS8.readInteger . fromJust . Ast.tokenValue . head . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "SocksPort") reply
    
    -- | Connect through a remote using the Tor SOCKS proxy. The remote might me a
    --   a normal host/ip or a hidden service address. When you provide a FQDN to
    --   resolve, it will be resolved by the Tor service, and as such is secure.
    --
    

    statusCode No usage example found for this symbol :( Collapse [-]
    value See 7 Occurences [+] Collapse [-]
    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    
        methods :: [Ast.Line] -> [T.AuthMethod]
        methods reply =
          map (read . BS8.unpack) . BS8.split ',' . fromJust . Ast.value "METHODS" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    
        cookieFile :: [Ast.Line] -> Maybe FilePath
        cookieFile reply =
          fmap BS8.unpack . Ast.value "COOKIEFILE" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    
    -- | Authenticates with the Tor control server, based on the authentication
    --   information returned by PROTOCOLINFO.
    authenticate :: MonadIO m
                 => Network.Socket
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
      return (T.ProtocolInfo (protocolVersion res) (torVersion res) (methods res) (cookieFile res))
    
      where
    
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    
        methods :: [Ast.Line] -> [T.AuthMethod]
        methods reply =
          map (read . BS8.unpack) . BS8.split ',' . fromJust . Ast.value "METHODS" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    
        cookieFile :: [Ast.Line] -> Maybe FilePath
        cookieFile reply =
          fmap BS8.unpack . Ast.value "COOKIEFILE" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    

    Found in Network.Anonymous.Tor.Protocol from the package network-anonymous-tor
                 -> m T.ProtocolInfo
    protocolInfo s = do
      res <- sendCommand s (BS.concat ["PROTOCOLINFO", "\n"])
    
      return (T.ProtocolInfo (protocolVersion res) (torVersion res) (methods res) (cookieFile res))
    
      where
    
        protocolVersion :: [Ast.Line] -> Integer
        protocolVersion reply =
          fst . fromJust . BS8.readInteger . Ast.tokenKey . last . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "PROTOCOLINFO") reply
    
        torVersion :: [Ast.Line] -> [Integer]
        torVersion reply =
          map (fst . fromJust . BS8.readInteger) . BS8.split '.' . fromJust . Ast.value "Tor" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "VERSION") reply
    
        methods :: [Ast.Line] -> [T.AuthMethod]
        methods reply =
          map (read . BS8.unpack) . BS8.split ',' . fromJust . Ast.value "METHODS" . Ast.lineMessage . fromJust $ Ast.line (BS8.pack "AUTH") reply
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
      where
        replyLine :: Word8 -> Atto.Parser A.Line
        replyLine c = A.Line <$> Atto8.decimal <*> (Atto.word8 c *> tokens) <* Atto8.endOfLine
    
    -- | Parses either a quoted value or an unquoted value
    value :: Atto.Parser BS.ByteString
    value =
      quotedString <|> unquotedString
    
    -- | Parses key and value
    keyValue :: Atto.Parser A.Token
    keyValue = do
      A.Token k _ <- key
      _ <- Atto.word8 equals
      v <- value
    
      return (A.Token k (Just v))
    
    -- | Parses a key, which is anything until either a space has been reached, or
    --   an '=' is reached.
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
      -- followed by a line that uses a space like 250 Wombat.
      --
      -- Let's parse all these lines into a reply.
      replies   <- Atto.many' (replyLine minus <|> replyLine plus)
      lastReply <- replyLine space
    
      return (replies ++ [lastReply])
    
      where
        replyLine :: Word8 -> Atto.Parser A.Line
        replyLine c = A.Line <$> Atto8.decimal <*> (Atto.word8 c *> tokens) <* Atto8.endOfLine
    
    -- | Parses either a quoted value or an unquoted value
    value :: Atto.Parser BS.ByteString
    value =
      quotedString <|> unquotedString
    
    -- | Parses key and value
    keyValue :: Atto.Parser A.Token
    keyValue = do
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
      -- A reply is a series of lines that look like 250-Foo or 250+Bar and then
      -- followed by a line that uses a space like 250 Wombat.
      --
      -- Let's parse all these lines into a reply.
      replies   <- Atto.many' (replyLine minus <|> replyLine plus)
      lastReply <- replyLine space
    
      return (replies ++ [lastReply])
    
      where
        replyLine :: Word8 -> Atto.Parser A.Line
        replyLine c = A.Line <$> Atto8.decimal <*> (Atto.word8 c *> tokens) <* Atto8.endOfLine
    
    -- | Parses either a quoted value or an unquoted value
    value :: Atto.Parser BS.ByteString
    value =
      quotedString <|> unquotedString
    
    -- | Parses key and value
    keyValue :: Atto.Parser A.Token
    

    Found in Network.Anonymous.Tor.Protocol.Parser from the package network-anonymous-tor
    --
    -- Defines parsers used by the Tor Control protocol
    --
    --   __Warning__: This function is used internally by 'Network.Anonymous.Tor'
    --                and using these functions directly is unsupported. The
    --                interface of these functions might change at any time without
    --                prior notice.
    --
    
    module Network.Anonymous.Tor.Protocol.Parser ( quotedString
                                                 , unquotedString
                                                 , reply
                                                 , key
                                                 , keyValue
                                                 , value
                                                 , token
                                                 , tokens ) where
    
    import           Control.Applicative                         ((*>), (<$>), (<*), (<*>),
                                                                  (<|>))
    

    valueAs No usage example found for this symbol :( Collapse [-]
    Line No usage example found for this symbol :( Collapse [-]
    Token No usage example found for this symbol :( Collapse [-]