rfc1413-types (empty) → 0.0.0.0
raw patch · 5 files changed
+140/−0 lines, 5 filesdep +basedep +bytestringsetup-changed
Dependencies added: base, bytestring
Files
- LICENSE +30/−0
- README.md +1/−0
- Setup.hs +2/−0
- rfc1413-types.cabal +25/−0
- src/Data/Ident.hs +82/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,1 @@+# rfc1413-parser
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ rfc1413-types.cabal view
@@ -0,0 +1,25 @@+name: rfc1413-types+version: 0.0.0.0+synopsis: An rfc1413 parser and response renderer+description: Types and low level operations for rfc1413+homepage: https://github.com/cotrone/rfc1413-types#readme+license: BSD3+license-file: LICENSE+author: Kevin Cotrone+maintainer: kevincotrone@gmail.com+copyright: 2017 Kevin Cotrone+category: Web+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Data.Ident+ default-language: Haskell2010+ build-depends: base >= 4.7 && < 5+ , bytestring++source-repository head+ type: git+ location: https://github.com/cotrone/rfc1413-types
+ src/Data/Ident.hs view
@@ -0,0 +1,82 @@+module Data.Ident where++import Data.ByteString as BS+import qualified Data.ByteString.Lazy as BSL+import Data.ByteString.Char8 as BSC+import Data.ByteString.Builder+import Data.Monoid+++data PortPair = PortPair Int Int++data Reply = ReplyError PortPair ErrorType+ | ReplyIdent PortPair OpsysField UserID++data ErrorType = InvalidPort+ | NoUser+ | HiddenUser+ | UnknownError+ | ErrorToken String++data OpsysField = OpsysField Opsys (Maybe Charset)++data Opsys = Other+ | Unix+ | Token String++data Charset = USAscii++data UserID = UserID String++-- | Parse a port pair request+parsePortPair :: BS.ByteString -> Maybe PortPair+parsePortPair req =+ case (fmap fst . BSC.readInt) <$> (BSC.split ',' req) of+ [p1,p2] -> PortPair <$> p1 <*> p2+ _ -> Nothing++-- | Render a reply for a given request+renderReply :: Reply -> ByteString+renderReply (ReplyError portPair errType) =+ BSL.toStrict . toLazyByteString $+ renderPortPair portPair+ <> string7 " : ERROR : "+ <> renderErrorType errType+renderReply (ReplyIdent portPair opsysField userID) =+ BSL.toStrict . toLazyByteString $+ renderPortPair portPair + <> string7 " : USERID : "+ <> renderOpsysField opsysField+ <> string7 " : "+ <> renderUserId userID++renderPortPair :: PortPair -> Builder+renderPortPair (PortPair i j) =+ intDec i+ <> string7 ", "+ <> intDec j++renderErrorType :: ErrorType -> Builder+renderErrorType InvalidPort = string7 "INVALID-PORT"+renderErrorType NoUser = string7 "NO-USER"+renderErrorType HiddenUser = string7 "HIDDEN-USER"+renderErrorType UnknownError = string7 "UNKNOWN-ERROR"+renderErrorType (ErrorToken err) =+ string7 err++renderOpsysField :: OpsysField -> Builder+renderOpsysField (OpsysField opsys charset) =+ renderOpsys opsys+ <> renderCharset charset++renderUserId :: UserID -> Builder+renderUserId (UserID userID) = string7 userID++renderOpsys :: Opsys -> Builder+renderOpsys Other = string7 "OTHER"+renderOpsys Unix = string7 "UNIX"+renderOpsys (Token tok) = string7 tok++renderCharset :: Maybe Charset -> Builder+renderCharset Nothing = mempty+renderCharset _ = error "Charset not supported"