]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Resource.hs
improvements related to RSS feed
[Rakka.git] / Rakka / Resource.hs
index 8448ea11d137d53dae3866bdd4ea9f11994602ba..d0d9c4866d06665732ab91344ed96dc87dc2ac2a 100644 (file)
@@ -3,6 +3,8 @@ module Rakka.Resource
     , runXmlA
     , getEntityType
     , outputXmlPage
+    , outputXmlPage'
+    , getUserID
     )
     where
 
@@ -13,6 +15,7 @@ import           Control.Monad.Trans
 import           Network.HTTP.Lucu
 import           Network.HTTP.Lucu.Utils
 import           Network.URI hiding (path)
+import           Rakka.Authorization
 import           Rakka.Environment
 import           Rakka.Validation
 import           System.Log.Logger
@@ -125,18 +128,18 @@ getEntityType
     where
       extMap :: [(String, MIMEType)]
       extMap = [ ("html", read "application/xhtml+xml")
+               , ( "rdf", read "application/rss+xml"  )
                , ( "xml", read "text/xml"             )
                ]
 
 
-outputXmlPage :: XmlTree -> IOSArrow XmlTree XmlTree -> Resource ()
-outputXmlPage tree toXHTML
+outputXmlPage :: XmlTree -> [(MIMEType, IOSArrow XmlTree XmlTree)] -> Resource ()
+outputXmlPage tree formatters
     = do mType <- getEntityType
          setContentType mType
-         let formatter = case mType of
-                           MIMEType "application" "xhtml+xml" _ -> toXHTML
-                           MIMEType "text"        "xml"       _ -> this
-                           _                                    -> undefined
+         let formatter = case lookup mType formatters of
+                           Just f  -> f
+                           Nothing -> this
          [resultStr] <- liftIO $ runX ( setErrorMsgHandler False fail
                                         >>>
                                         constA tree
@@ -145,4 +148,22 @@ outputXmlPage tree toXHTML
                                         >>>
                                         writeDocumentToString [ (a_indent, v_1) ]
                                       )
-         output resultStr
\ No newline at end of file
+         output resultStr
+
+
+outputXmlPage' :: XmlTree -> IOSArrow XmlTree XmlTree -> Resource ()
+outputXmlPage' tree toXHTML
+    = outputXmlPage tree [(MIMEType "application" "xhtml+xml" [], toXHTML)]
+
+
+getUserID :: Environment -> Resource (Maybe String)
+getUserID env
+    = do auth <- getAuthorization
+         case auth of
+           Just (BasicAuthCredential userID password)
+               -> do valid <- isValidPair (envAuthDB env) userID password
+                     if valid then
+                         return (Just userID)
+                       else
+                         return Nothing
+           _   -> return Nothing