Stability | experimental |
---|---|
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Network.Gopher.Util
Description
Helper utilities used within the library and the server which also could be useful for other application code.
Synopsis
- sanitizePath :: RawFilePath -> RawFilePath
- sanitizeIfNotUrl :: RawFilePath -> RawFilePath
- dropPrivileges :: String -> IO ()
- asciiOrd :: Char -> Word8
- asciiChr :: Word8 -> Char
- asciiToLower :: Word8 -> Word8
- uEncode :: String -> ByteString
- uDecode :: ByteString -> String
- stripNewline :: ByteString -> ByteString
- boolToMaybe :: Bool -> a -> Maybe a
Security
sanitizePath :: RawFilePath -> RawFilePathSource#
Normalise a path and prevent directory traversal attacks.
sanitizeIfNotUrl :: RawFilePath -> RawFilePathSource#
Use sanitizePath
except if the path starts with URL:
in which case the original string is returned.
dropPrivileges :: String -> IO () Source#
Call setGroupID
and setUserID
to switch to the given user and their primary group. Requires special privileges. Will raise an exception if either the user does not exist or the current user has no permission to change UID/GID.
String Encoding
uEncode :: String -> ByteStringSource#
Encode a String
to a UTF-8 ByteString
uDecode :: ByteString -> StringSource#
Decode a UTF-8 ByteString
to a String
Misc Helpers
stripNewline :: ByteString -> ByteStringSource#
Strip \r
and \n
from ByteString
s
boolToMaybe :: Bool -> a -> Maybe a Source#
boolToMaybe True x == Just x
boolToMaybe False x == Nothing