~singpolyma/network-protocol-xmpp

99f5f44719ae374e5b46f55001334848a5fd81f2 — John Millikin 12 years ago 3666904
Transition most remaining text storage to lazy 'Text'.
M Network/Protocol/XMPP/Client.hs => Network/Protocol/XMPP/Client.hs +1 -1
@@ 27,7 27,7 @@ import qualified Text.XML.HXT.DOM.Interface as DOM
import qualified Text.XML.HXT.DOM.XmlNode as XN
import qualified System.IO as IO
import Data.ByteString (ByteString)
import qualified Data.Text as T
import qualified Data.Text.Lazy as T

import qualified Network.Protocol.XMPP.Client.Authentication as A
import qualified Network.Protocol.XMPP.Connections as C

M Network/Protocol/XMPP/Client/Authentication.hs => Network/Protocol/XMPP/Client/Authentication.hs +7 -6
@@ 26,6 26,7 @@ import qualified Control.Monad.Error as E
import qualified Data.ByteString.Char8 as B
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Text.Lazy as TL
import Data.Typeable (Typeable)

import Text.XML.HXT.Arrow ((>>>))


@@ 41,7 42,7 @@ import Network.Protocol.XMPP.XML (element, qname)
data Result = Success | Failure
	deriving (Show, Eq)

data AuthException = XmppError M.Error | SaslError T.Text
data AuthException = XmppError M.Error | SaslError TL.Text
	deriving (Typeable, Show)

instance Exc.Exception AuthException


@@ 49,14 50,14 @@ instance Exc.Exception AuthException
authenticate :: [B.ByteString] -- ^ Mechanisms
             -> JID -- ^ User JID
             -> JID -- ^ Server JID
             -> T.Text -- ^ Username
             -> T.Text -- ^ Password
             -> TL.Text -- ^ Username
             -> TL.Text -- ^ Password
             -> M.XMPP ()
authenticate xmppMechanisms userJID serverJID username password = xmpp where
	mechanisms = map SASL.Mechanism xmppMechanisms
	authz = formatJID $ userJID { jidResource = Nothing }
	hostname = formatJID serverJID
	utf8 = TE.encodeUtf8
	utf8 = TE.encodeUtf8 . T.concat . TL.toChunks
	
	xmpp = do
		ctx <- M.getContext


@@ 92,7 93,7 @@ authenticate xmppMechanisms userJID serverJID username password = xmpp where
			
		case sessionResult of
			Right x -> return x
			Left err -> saslError $ T.pack $ show err
			Left err -> saslError $ TL.pack $ show err

saslLoop :: M.Context -> SASL.Session Result
saslLoop ctx = do


@@ 134,5 135,5 @@ getTree ctx = do
		Left err -> Exc.throwIO $ XmppError err
		Right x -> return x

saslError :: MonadIO m => T.Text -> m a
saslError :: MonadIO m => TL.Text -> m a
saslError = liftIO . Exc.throwIO . SaslError

M Network/Protocol/XMPP/Component.hs => Network/Protocol/XMPP/Component.hs +6 -7
@@ 23,8 23,9 @@ import Control.Monad.Error (throwError)
import Data.Bits (shiftR, (.&.))
import Data.Char (intToDigit)
import qualified Data.ByteString as B
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.Encoding as TE
import Network (connectTo)
import Text.XML.HXT.Arrow ((>>>))
import qualified Text.XML.HXT.Arrow as A


@@ 87,11 88,9 @@ authenticate streamID password = do
		throwError M.ComponentHandshakeFailed

buildSecret :: T.Text -> T.Text -> B.ByteString
buildSecret sid password = bytes where
	bytes = TE.encodeUtf8 $ T.pack escaped
	escaped = DOM.attrEscapeXml $ sid' ++ password'
	sid' = T.unpack sid
	password' = T.unpack password
buildSecret sid password = B.concat . BL.toChunks $ bytes where
	escape = T.pack . DOM.attrEscapeXml . T.unpack
	bytes = TE.encodeUtf8 $ escape $ T.append sid password

showDigest :: B.ByteString -> String
showDigest = concatMap wordToHex . B.unpack where

M Network/Protocol/XMPP/Connections.hs => Network/Protocol/XMPP/Connections.hs +3 -3
@@ 22,8 22,8 @@ module Network.Protocol.XMPP.Connections
	) where
import Network (HostName, PortID)
import qualified Data.ByteString.Lazy as B
import qualified Data.Text as T
import Data.Text.Encoding (encodeUtf8)
import qualified Data.Text.Lazy as T
import Data.Text.Lazy.Encoding (encodeUtf8)
import qualified Text.XML.HXT.DOM.Interface as DOM
import qualified Text.XML.LibXML.SAX as SAX



@@ 40,7 40,7 @@ data Server = Server
-- serialization cannot be used. Be careful to escape any embedded
-- attributes.
xmlHeader :: T.Text -> JID -> B.ByteString
xmlHeader ns jid = B.fromChunks [encodeUtf8 header] where
xmlHeader ns jid = encodeUtf8 header where
	escape = T.pack . DOM.attrEscapeXml . T.unpack
	attr x = T.concat ["\"", escape x, "\""]
	header = T.concat

M Network/Protocol/XMPP/Handle.hs => Network/Protocol/XMPP/Handle.hs +1 -1
@@ 25,7 25,7 @@ import Control.Monad (when)
import qualified Control.Monad.Error as E
import Control.Monad.Trans (liftIO)
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.Text as T
import qualified Data.Text.Lazy as T
import qualified System.IO as IO
import qualified Network.Protocol.TLS.GNU as TLS
import Network.Protocol.XMPP.ErrorT

M Network/Protocol/XMPP/JID.hs => Network/Protocol/XMPP/JID.hs +1 -1
@@ 24,7 24,7 @@ module Network.Protocol.XMPP.JID
	, parseJID_
	, formatJID
	) where
import qualified Data.Text as T
import qualified Data.Text.Lazy as T
import qualified Data.Text.IDN.StringPrep as SP
import Data.String (IsString, fromString)


M Network/Protocol/XMPP/Monad.hs => Network/Protocol/XMPP/Monad.hs +1 -1
@@ 39,7 39,7 @@ import Control.Monad.Trans (MonadIO, liftIO)
import qualified Control.Monad.Error as E
import qualified Control.Monad.Reader as R
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Text (Text)
import Data.Text.Lazy (Text)

import Text.XML.HXT.Arrow ((>>>))
import qualified Text.XML.HXT.Arrow as A

M Network/Protocol/XMPP/Stanza.hs => Network/Protocol/XMPP/Stanza.hs +1 -1
@@ 31,7 31,7 @@ module Network.Protocol.XMPP.Stanza
	, treeToStanza
	) where

import qualified Data.Text as T
import qualified Data.Text.Lazy as T
import Text.XML.HXT.DOM.Interface (XmlTree)
import Text.XML.HXT.Arrow ((>>>))
import qualified Text.XML.HXT.Arrow as A