diff --git a/gemserv.cabal b/gemserv.cabal index 6a79dc5..5aae760 100644 --- a/gemserv.cabal +++ b/gemserv.cabal @@ -32,6 +32,7 @@ library build-depends: base >=4.7 && <5 , bytestring >=0.10.12.0 && <0.11 + , network , tcp-streams >=1.0.1.1 && <1.1 , text >=1.2.4.1 && <1.3 , tls @@ -53,6 +54,7 @@ test-suite gemserv-test , bytestring >=0.10.12.0 && <0.11 , gemserv , hspec >=2.7.10 && <2.8 + , network , tcp-streams >=1.0.1.1 && <1.1 , text >=1.2.4.1 && <1.3 , tls diff --git a/package.yaml b/package.yaml index 466c7a4..74e6137 100644 --- a/package.yaml +++ b/package.yaml @@ -27,6 +27,7 @@ dependencies: - bytestring >= 0.10.12.0 && < 0.11 - tcp-streams >= 1.0.1.1 && < 1.1 - text >= 1.2.4.1 && < 1.3 +- network - tls - x509 diff --git a/src/Network/GemServ.hs b/src/Network/GemServ.hs index 5dd2fd3..fb642a7 100644 --- a/src/Network/GemServ.hs +++ b/src/Network/GemServ.hs @@ -27,12 +27,14 @@ License along with this program. If not, see {-# LANGUAGE LambdaCase, OverloadedStrings, RecordWildCards #-} module Network.GemServ ( + runGemServer, encodeGemURL, decodeGemURL, escapeString, unescapeString ) where +import Control.Exception.Base (bracket) import qualified Data.ByteString as BS import Data.ByteString.Builder (charUtf8, stringUtf8, toLazyByteString) import qualified Data.ByteString.Lazy as BSL @@ -41,9 +43,26 @@ import Data.List (find, intercalate) import Data.Maybe (fromJust) import qualified Data.Text as T import Data.Text.Encoding (decodeUtf8') +import Network.Socket (close) +import System.IO.Streams.TCP (bindAndListen) import Network.GemServ.Types +-- | Builds and runs a Gemini server +runGemServer + :: GemServSettings + -- ^ The server settings + -> GemHandler + -- ^ The handler + -> IO () +runGemServer settings _ = bracket + ( bindAndListen + (servConnections settings) + (fromIntegral $ servPort settings) + ) + close + undefined + -- | Encodes a 'GemURL' into a 'String' encodeGemURL :: GemURL -> String encodeGemURL url =