From f0e8e2d4ebe27764fba489d8cf91253828d21186 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Wed, 13 Jun 2012 04:13:52 +0200 Subject: [PATCH 1/2] send xml declaration --- source/Network/Xmpp/Monad.hs | 9 +++++++++ source/Network/Xmpp/Stream.hs | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/Network/Xmpp/Monad.hs b/source/Network/Xmpp/Monad.hs index 075b3cb..f7062f9 100644 --- a/source/Network/Xmpp/Monad.hs +++ b/source/Network/Xmpp/Monad.hs @@ -40,6 +40,15 @@ pushElement x = do pushStanza :: Stanza -> XmppConMonad Bool pushStanza = pushElement . pickleElem xpStanza +-- XML documents and XMPP streams SHOULD be preceeded by an XML declaration. +-- UTF-8 is the only supported XMPP encoding. The standalone document +-- declaration (matching "SDDecl" in the XML standard) MUST NOT be included in +-- XMPP streams. RFC 6120 defines XMPP only in terms of XML 1.0. +pushXmlDecl :: XmppConMonad Bool +pushXmlDecl = do + sink <- gets sConPushBS + liftIO $ sink "" + pushOpenElement :: Element -> XmppConMonad Bool pushOpenElement e = do sink <- gets sConPushBS diff --git a/source/Network/Xmpp/Stream.hs b/source/Network/Xmpp/Stream.hs index 2fa3681..52fba97 100644 --- a/source/Network/Xmpp/Stream.hs +++ b/source/Network/Xmpp/Stream.hs @@ -61,8 +61,10 @@ xmppStartStream = runErrorT $ do hostname' <- gets sHostname case hostname' of Nothing -> throwError StreamConnectionError - Just hostname -> lift . pushOpenElement $ - pickleElem pickleStream ("1.0", Nothing, Just hostname) + Just hostname -> lift $ do + pushXmlDecl + pushOpenElement $ + pickleElem pickleStream ("1.0", Nothing, Just hostname) features <- ErrorT . pullToSink $ runErrorT xmppStream modify (\s -> s {sFeatures = features}) return () From 5bca5a16b990977bf9ff8b97fa38948033a94012 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Wed, 13 Jun 2012 04:16:25 +0200 Subject: [PATCH 2/2] minor EchoClient modifications; exported simpleAuth started to use simpleAuth in EchoClient stripped password from EchoClient --- examples/EchoClient.hs | 13 +++++++------ source/Network/Xmpp.hs | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/examples/EchoClient.hs b/examples/EchoClient.hs index 8fbb2be..0b1c14d 100644 --- a/examples/EchoClient.hs +++ b/examples/EchoClient.hs @@ -25,10 +25,11 @@ import Network.Xmpp.IM -- Server and authentication details. -hostName = "nejla.com" -portNumber = 5222 -userName = "jon" -password = "G2D9%b4S3" -- TODO +hostname = "nejla.com" +hostname_ = "xmpp.nejla.com" -- TODO +-- portNumber = 5222 -- TODO +userName = "" +password = "" -- TODO: Incomplete code, needs documentation, etc. @@ -36,9 +37,9 @@ main :: IO () main = do withNewSession $ do withConnection $ do - connect "xmpp.nejla.com" "nejla.com" + connect hostname_ hostname -- startTLS exampleParams - saslResponse <- auth userName password (Just "echo-client") + saslResponse <- simpleAuth userName password (Just "echo-client") case saslResponse of Right _ -> return () Left e -> error $ show e diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs index e651f32..8124d11 100644 --- a/source/Network/Xmpp.hs +++ b/source/Network/Xmpp.hs @@ -35,6 +35,7 @@ module Network.Xmpp , withConnection , connect , startTLS + , simpleAuth , auth , endSession , setSessionEndHandler