-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A library implementing SOCKS Protocol Version 5.
@package crypton-socks
@version 0.6.2


module Network.Socks5.Types

-- | Type representing SOCKS protocol versions.
data SocksVersion

-- | SOCKS Protocol Version 5. The only version implemented by the library.
SocksVer5 :: SocksVersion

-- | Type representing commands that can be sent or received under the
--   SOCKS protocol.
data SocksCommand

-- | The CONNECT request.
SocksCommandConnect :: SocksCommand

-- | The BIND request. Not implemented by the library.
SocksCommandBind :: SocksCommand

-- | The UDP ASSOCIATE request. Not implemented by the library.
SocksCommandUdpAssociate :: SocksCommand

-- | Other requests. None are specified by the SOCKS Protocol Version 5.
SocksCommandOther :: !Word8 -> SocksCommand

-- | Type representing authentication methods available under the SOCKS
--   protocol.
--   
--   Only <a>SocksMethodNone</a> is effectively implemented, but other
--   values are enumerated for completeness.
data SocksMethod

-- | NO AUTHENTICATION REQUIRED.
SocksMethodNone :: SocksMethod

-- | GSSAPI.
SocksMethodGSSAPI :: SocksMethod

-- | USERNAME/PASSWORD.
SocksMethodUsernamePassword :: SocksMethod

-- | IANA ASSIGNED or RESERVED FOR PRIVATE METHODS.
SocksMethodOther :: !Word8 -> SocksMethod

-- | NO ACCEPTABLE METHODS.
SocksMethodNotAcceptable :: SocksMethod

-- | Type representing host addresses under the SOCKS protocol.
data SocksHostAddress

-- | A version-4 IP address.
SocksAddrIPV4 :: !HostAddress -> SocksHostAddress

-- | A fully-qualified domain name (FQDN).
SocksAddrDomainName :: !SocksFQDN -> SocksHostAddress

-- | A version-6 IP address.
SocksAddrIPV6 :: !HostAddress6 -> SocksHostAddress

-- | Type representing socket addresses under the SOCKS protocol.
data SocksAddress
SocksAddress :: !SocksHostAddress -> !PortNumber -> SocksAddress

-- | Type representing replies under the SOCKS protocol.
data SocksReply

-- | The server reports that the request succeeded.
SocksReplySuccess :: SocksReply

-- | The server reports that the request did not succeed.
SocksReplyError :: SocksError -> SocksReply

-- | Type representing exceptions.
data SocksVersionNotSupported

-- | The SOCKS protocol version is not supported. This library only
--   implements SOCKS Protocol Version 5.
SocksVersionNotSupported :: SocksVersionNotSupported

-- | Type representing SOCKS errors that can be part of a SOCKS reply.
data SocksError

-- | General SOCKS server failure.
SocksErrorGeneralServerFailure :: SocksError

-- | Connection not allowed by ruleset.
SocksErrorConnectionNotAllowedByRule :: SocksError

-- | Network unreachable.
SocksErrorNetworkUnreachable :: SocksError

-- | Host unreachable.
SocksErrorHostUnreachable :: SocksError

-- | Connection refused.
SocksErrorConnectionRefused :: SocksError

-- | TTL expired.
SocksErrorTTLExpired :: SocksError

-- | Command not supported.
SocksErrorCommandNotSupported :: SocksError

-- | Address type not supported.
SocksErrorAddrTypeNotSupported :: SocksError

-- | Other error. Unassigned in SOCKS Protocol Version 5.
SocksErrorOther :: Word8 -> SocksError

-- | Type synonym representing fully-qualified domain names (FQDN). The
--   SOCKS Protocol Version 5 does not specify an encoding for a FQDN other
--   than there is no terminating <tt>NUL</tt> octet (byte).
--   
--   This library's API assumes that FQDN values comprise only ASCII
--   characters. Domain names that include other Unicode code points should
--   be Punycode encoded.
type SocksFQDN = ByteString
instance GHC.Internal.Data.Data.Data Network.Socks5.Types.SocksError
instance GHC.Internal.Data.Data.Data Network.Socks5.Types.SocksReply
instance GHC.Internal.Data.Data.Data Network.Socks5.Types.SocksVersionNotSupported
instance GHC.Internal.Enum.Enum Network.Socks5.Types.SocksCommand
instance GHC.Internal.Enum.Enum Network.Socks5.Types.SocksError
instance GHC.Internal.Enum.Enum Network.Socks5.Types.SocksMethod
instance GHC.Internal.Enum.Enum Network.Socks5.Types.SocksReply
instance GHC.Classes.Eq Network.Socks5.Types.SocksAddress
instance GHC.Classes.Eq Network.Socks5.Types.SocksCommand
instance GHC.Classes.Eq Network.Socks5.Types.SocksError
instance GHC.Classes.Eq Network.Socks5.Types.SocksHostAddress
instance GHC.Classes.Eq Network.Socks5.Types.SocksMethod
instance GHC.Classes.Eq Network.Socks5.Types.SocksReply
instance GHC.Classes.Eq Network.Socks5.Types.SocksVersion
instance GHC.Internal.Exception.Type.Exception Network.Socks5.Types.SocksError
instance GHC.Internal.Exception.Type.Exception Network.Socks5.Types.SocksVersionNotSupported
instance GHC.Classes.Ord Network.Socks5.Types.SocksAddress
instance GHC.Classes.Ord Network.Socks5.Types.SocksCommand
instance GHC.Classes.Ord Network.Socks5.Types.SocksError
instance GHC.Classes.Ord Network.Socks5.Types.SocksHostAddress
instance GHC.Classes.Ord Network.Socks5.Types.SocksMethod
instance GHC.Classes.Ord Network.Socks5.Types.SocksReply
instance GHC.Classes.Ord Network.Socks5.Types.SocksVersion
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksAddress
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksCommand
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksError
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksHostAddress
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksMethod
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksReply
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksVersion
instance GHC.Internal.Show.Show Network.Socks5.Types.SocksVersionNotSupported


-- | Low level types and functions for interacting with a SOCKS server.
module Network.Socks5.Lowlevel

-- | For the specified socket, wait for a SOCKS Hello, send a SOCKS Hello
--   response (specifying no authentification method), and wait for a SOCKS
--   request.
socksListen :: Socket -> IO SocksRequest

-- | Type representing initial messages sent by a client with the list of
--   authentification methods supported.
newtype SocksHello
SocksHello :: [SocksMethod] -> SocksHello
[getSocksHelloMethods] :: SocksHello -> [SocksMethod]

-- | Type representing initial messages sent by a server in response to
--   Hello, with the server's chosen method of authentication.
newtype SocksHelloResponse
SocksHelloResponse :: SocksMethod -> SocksHelloResponse
[getSocksHelloResponseMethod] :: SocksHelloResponse -> SocksMethod

-- | Type representing SOCKS requests.
data SocksRequest
SocksRequest :: SocksCommand -> SocksHostAddress -> PortNumber -> SocksRequest
[requestCommand] :: SocksRequest -> SocksCommand
[requestDstAddr] :: SocksRequest -> SocksHostAddress
[requestDstPort] :: SocksRequest -> PortNumber

-- | Type representing SOCKS responses.
data SocksResponse
SocksResponse :: SocksReply -> SocksHostAddress -> PortNumber -> SocksResponse
[responseReply] :: SocksResponse -> SocksReply
[responseBindAddr] :: SocksResponse -> SocksHostAddress
[responseBindPort] :: SocksResponse -> PortNumber

-- | Connect using a fully-qualified domain name (FQDN).
connectDomainName :: Socket -> String -> PortNumber -> IO (SocksHostAddress, PortNumber)

-- | Connect using IPv4.
connectIPV4 :: Socket -> HostAddress -> PortNumber -> IO (HostAddress, PortNumber)

-- | Connect using IPv6.
connectIPV6 :: Socket -> HostAddress6 -> PortNumber -> IO (HostAddress6, PortNumber)

-- | Establish a connection with a SOCKS server.
establish :: SocksVersion -> Socket -> [SocksMethod] -> IO SocksMethod

-- | Try to execute the specified command with the specified socket.
rpc :: Command a => Socket -> a -> IO (Either SocksError (SocksHostAddress, PortNumber))

-- | As for <a>rpc</a> but throws an exception if it does not succeed.
rpc_ :: Command a => Socket -> a -> IO (SocksHostAddress, PortNumber)

-- | Send data to the specified socket.
sendSerialized :: Serialize a => Socket -> a -> IO ()

-- | Wait for data from the specified socket.
waitSerialized :: Serialize a => Socket -> IO a

-- | A type class for types that can yield a SOCKS request or, optionally,
--   be obtained from a SOCKS request.
class Command a
toRequest :: Command a => a -> SocksRequest
fromRequest :: Command a => SocksRequest -> Maybe a

-- | Type representing connect commands.
newtype Connect
Connect :: SocksAddress -> Connect


-- | This is an implementation of the SOCKS Protocol Version 5 as defined
--   in <a>RFC 1928</a>.
--   
--   In Wikipedia's words:
--   
--   SOCKS is an Internet protocol that exchanges network packets between a
--   client and server through a proxy server. SOCKS5 optionally provides
--   authentication so only authorized users may access a server.
--   Practically, a SOCKS server proxies TCP connections to an arbitrary IP
--   address, and provides a means for UDP packets to be forwarded. A SOCKS
--   server accepts incoming client connection on TCP port 1080.
--   
--   BIND and UDP ASSOCIATE messages are not implemented. However the main
--   usage of SOCKS is implemented.
module Network.Socks5

-- | Type representing socket addresses under the SOCKS protocol.
data SocksAddress
SocksAddress :: !SocksHostAddress -> !PortNumber -> SocksAddress

-- | Type representing host addresses under the SOCKS protocol.
data SocksHostAddress

-- | A version-4 IP address.
SocksAddrIPV4 :: !HostAddress -> SocksHostAddress

-- | A fully-qualified domain name (FQDN).
SocksAddrDomainName :: !SocksFQDN -> SocksHostAddress

-- | A version-6 IP address.
SocksAddrIPV6 :: !HostAddress6 -> SocksHostAddress

-- | Type representing replies under the SOCKS protocol.
data SocksReply

-- | The server reports that the request succeeded.
SocksReplySuccess :: SocksReply

-- | The server reports that the request did not succeed.
SocksReplyError :: SocksError -> SocksReply

-- | Type representing SOCKS errors that can be part of a SOCKS reply.
data SocksError

-- | General SOCKS server failure.
SocksErrorGeneralServerFailure :: SocksError

-- | Connection not allowed by ruleset.
SocksErrorConnectionNotAllowedByRule :: SocksError

-- | Network unreachable.
SocksErrorNetworkUnreachable :: SocksError

-- | Host unreachable.
SocksErrorHostUnreachable :: SocksError

-- | Connection refused.
SocksErrorConnectionRefused :: SocksError

-- | TTL expired.
SocksErrorTTLExpired :: SocksError

-- | Command not supported.
SocksErrorCommandNotSupported :: SocksError

-- | Address type not supported.
SocksErrorAddrTypeNotSupported :: SocksError

-- | Other error. Unassigned in SOCKS Protocol Version 5.
SocksErrorOther :: Word8 -> SocksError

-- | Type representing SOCKS identification and configuration structures.
--   
--   The data constructors may be extended in the future to support
--   authentification. Use the smart constructor <a>defaultSocksConf</a>
--   and <a>socksHost</a>.
data SocksConf
SocksConf :: SockAddr -> SocksVersion -> SocksConf

-- | The address of the server.
[socksServer] :: SocksConf -> SockAddr

-- | The SOCKS protocol version to use.
[socksVersion] :: SocksConf -> SocksVersion

-- | Yield the socket address of the server from the specified
--   configuration.
socksHost :: SocksConf -> SockAddr

-- | Yield a configuration given the specified socket addresss.
defaultSocksConf :: SockAddr -> SocksConf

-- | Same as <a>defaultSocksConf</a>.

-- | <i>Deprecated: Will be removed from future package versions. Use
--   defaultSocksConf instead.</i>
defaultSocksConfFromSockAddr :: SockAddr -> SocksConf

-- | Connect a user-specified new socket on the SOCKS server to a
--   destination.
--   
--   The specified socket needs to be connected to the SOCKS server
--   already.
--   
--   
--   |socket|-----sockServer-----&gt;|server|----destAddr-----&gt;|destination|
socksConnectWithSocket :: Socket -> SocksConf -> SocksAddress -> IO (SocksHostAddress, PortNumber)

-- | Connect a new socket to a SOCKS server and connect the stream on the
--   server side to the specified SOCKS address.
socksConnect :: SocksConf -> SocksAddress -> IO (Socket, (SocksHostAddress, PortNumber))

-- | Connect a new socket to the SOCKS server, and connect the stream to a
--   fully-qualified domain name (FQDN) resolved on the server side.
socksConnectName :: Socket -> SocksConf -> String -> PortNumber -> IO ()
