wai-session-tokyocabinet (empty) → 0.1
raw patch · 5 files changed
+96/−0 lines, 5 filesdep +basedep +bytestringdep +cerealsetup-changed
Dependencies added: base, bytestring, cereal, errors, tokyocabinet-haskell, transformers, wai-session
Files
- COPYING +13/−0
- Network/Wai/Session/TokyoCabinet.hs +38/−0
- README +3/−0
- Setup.hs +3/−0
- wai-session-tokyocabinet.cabal +39/−0
+ COPYING view
@@ -0,0 +1,13 @@+Copyright © 2012, Stephen Paul Weber <singpolyma.net>++Permission to use, copy, modify, and/or distribute this software for any+purpose with or without fee is hereby granted, provided that the above+copyright notice and this permission notice appear in all copies.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Network/Wai/Session/TokyoCabinet.hs view
@@ -0,0 +1,38 @@+module Network.Wai.Session.TokyoCabinet (tokyocabinetStore, tokyocabinetStore_) where++import Control.Monad+import Data.ByteString (ByteString)+import Control.Monad.IO.Class (liftIO, MonadIO)+import Network.Wai.Session (Session, SessionStore, genSessionId)+import Control.Error (hush)+import qualified Data.ByteString as BS++import Database.TokyoCabinet+import Data.Serialize (encode, decode, Serialize)++-- | Session store that keeps all content in TokyoCabinet+--+-- WARNING: This session is vulnerable to sidejacking,+-- use with TLS for security.+tokyocabinetStore :: (TCDB a, Serialize k, Serialize v, MonadIO m) =>+ IO ByteString+ -- ^ 'IO' action to generate unique session IDs+ -> a+ -- ^ TokyoCabinet handle+ -> SessionStore m k v+tokyocabinetStore _ db (Just sk) = backend db sk+tokyocabinetStore genNewKey db Nothing = genNewKey >>= backend db++-- | Store using simple session ID generator based on time and 'Data.Unique'+tokyocabinetStore_ :: (TCDB a, Serialize k, Serialize v, MonadIO m) => a -> SessionStore m k v+tokyocabinetStore_ = tokyocabinetStore genSessionId++backend :: (TCDB a, Serialize k, Serialize v, MonadIO m) => a -> ByteString -> IO (Session m k v, IO ByteString)+backend db sk =+ return ((+ liftTCM . liftM (join . liftM (hush . decode)) . get db . fullKey,+ (\k v -> liftTCM $ put db (fullKey k) (encode v) >> return ())+ ), return sk)+ where+ liftTCM = liftIO . runTCM+ fullKey k = sk `BS.append` encode k
+ README view
@@ -0,0 +1,3 @@+Provides a session store for use with wai-session.++See example/Main.hs in git for example usage.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ wai-session-tokyocabinet.cabal view
@@ -0,0 +1,39 @@+name: wai-session-tokyocabinet+version: 0.1+cabal-version: >= 1.8+license: OtherLicense+license-file: COPYING+category: Web+copyright: © 2012 Stephen Paul Weber+author: Stephen Paul Weber <singpolyma@singpolyma.net>+maintainer: Stephen Paul Weber <singpolyma@singpolyma.net>+stability: experimental+tested-with: GHC == 7.0.3+synopsis: Session store based on Tokyo Cabinet+homepage: https://github.com/singpolyma/wai-session-tokyocabinet+bug-reports: https://github.com/singpolyma/wai-session-tokyocabinet/issues+build-type: Simple+description:+ Provides a session store for use with wai-session.+ .+ See example/Main.hs in git for example usage.++extra-source-files:+ README++library+ exposed-modules:+ Network.Wai.Session.TokyoCabinet++ build-depends:+ base == 4.*,+ bytestring,+ transformers,+ cereal,+ tokyocabinet-haskell,+ errors,+ wai-session++source-repository head+ type: git+ location: git://github.com/singpolyma/wai-session-tokyocabinet.git