|
|
|
|
@ -11,18 +11,19 @@ import Control.Monad.Trans.Resource
@@ -11,18 +11,19 @@ import Control.Monad.Trans.Resource
|
|
|
|
|
import Control.Monad.Trans.State |
|
|
|
|
|
|
|
|
|
import Data.ByteString as BS |
|
|
|
|
import Data.Default(def) |
|
|
|
|
import Data.Text(Text) |
|
|
|
|
|
|
|
|
|
import Data.Conduit |
|
|
|
|
import Data.Conduit.Binary as CB |
|
|
|
|
import Data.Conduit.Hexpat as CH |
|
|
|
|
-- import Data.Conduit.Hexpat as CH |
|
|
|
|
import Data.Conduit.List as CL |
|
|
|
|
import Data.Conduit.Text as CT |
|
|
|
|
import Data.Conduit.TLS |
|
|
|
|
|
|
|
|
|
import Data.XML.Pickle |
|
|
|
|
import Data.XML.Types |
|
|
|
|
--import Text.XML.Stream.Parse as XP |
|
|
|
|
import Text.XML.Stream.Parse as XP |
|
|
|
|
import Text.XML.Stream.Render as XR |
|
|
|
|
import Text.XML.Stream.Elements |
|
|
|
|
|
|
|
|
|
@ -49,14 +50,15 @@ pushOpen e = do
@@ -49,14 +50,15 @@ pushOpen e = do
|
|
|
|
|
lift . sink $ openElementToEvents e |
|
|
|
|
return () |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pulls :: Sink Event (ResourceT IO) a -> XMPPMonad a |
|
|
|
|
pulls snk = do |
|
|
|
|
source <- gets sConSrc |
|
|
|
|
lift $ source $$ snk |
|
|
|
|
(src', r) <- lift $ source $$+ snk |
|
|
|
|
modify $ (\s -> s {sConSrc = src'}) |
|
|
|
|
return r |
|
|
|
|
|
|
|
|
|
pullE :: XMPPMonad Element |
|
|
|
|
pullE = pulls elementFromEvents |
|
|
|
|
pullE = pulls elementFromEvents |
|
|
|
|
|
|
|
|
|
pullPickle :: Show b => PU [Node] b -> XMPPMonad b |
|
|
|
|
pullPickle p = unpickleElem p <$> pullE |
|
|
|
|
@ -70,13 +72,13 @@ xmppFromHandle
@@ -70,13 +72,13 @@ xmppFromHandle
|
|
|
|
|
-> IO (a, XMPPState) |
|
|
|
|
xmppFromHandle handle hostname username resource f = runResourceT $ do |
|
|
|
|
liftIO $ hSetBuffering handle NoBuffering |
|
|
|
|
raw <- bufferSource $ CB.sourceHandle handle |
|
|
|
|
src <- bufferSource $ raw $= CH.parseBS defaultParseOptions |
|
|
|
|
let raw = CB.sourceHandle handle $= conduitStdout |
|
|
|
|
let src = raw $= XP.parseBytes def |
|
|
|
|
let st = XMPPState |
|
|
|
|
src |
|
|
|
|
raw |
|
|
|
|
(raw) |
|
|
|
|
(\xs -> CL.sourceList xs |
|
|
|
|
$$ XR.renderBytes def =$ CB.sinkHandle handle) |
|
|
|
|
$$ XR.renderBytes def =$ conduitStdout =$ CB.sinkHandle handle) |
|
|
|
|
(BS.hPut handle) |
|
|
|
|
(Just handle) |
|
|
|
|
def |
|
|
|
|
@ -85,3 +87,20 @@ xmppFromHandle handle hostname username resource f = runResourceT $ do
@@ -85,3 +87,20 @@ xmppFromHandle handle hostname username resource f = runResourceT $ do
|
|
|
|
|
username |
|
|
|
|
resource |
|
|
|
|
runStateT f st |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xml = |
|
|
|
|
[ "<?xml version='1.0'?>" |
|
|
|
|
, "<stream:stream xmlns='jabber:client' " |
|
|
|
|
, "xmlns:stream='http://etherx.jabber.org/streams' id='1365401808' " |
|
|
|
|
, "from='examplehost.org' version='1.0' xml:lang='en'>" |
|
|
|
|
, "<stream:features>" |
|
|
|
|
, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>" |
|
|
|
|
, error "Booh!" |
|
|
|
|
] :: [BS.ByteString] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main :: IO () |
|
|
|
|
main = (runResourceT $ CL.sourceList xml $= XP.parseBytes def $$ CL.take 2 ) |
|
|
|
|
>>= print |
|
|
|
|
|
|
|
|
|
|