~singpolyma/network-protocol-xmpp

78b5a2c0e9de788d4f6f10f4b52c4c5a9a632952 — John Millikin 14 years ago bb4dfca
Rename 'Event' to 'SaxEvent', in preparation for new "xml-types" package.
M Network/Protocol/XMPP/Component.hs => Network/Protocol/XMPP/Component.hs +1 -1
@@ 58,7 58,7 @@ beginStream jid = do
		Nothing -> throwError M.NoComponentStreamID
		Just x -> return x

parseStreamID :: X.Event -> Maybe T.Text
parseStreamID :: X.SaxEvent -> Maybe T.Text
parseStreamID (X.BeginElement _ attrs) = sid where
	sid = case idAttrs of
		(x:_) -> Just . X.attributeText $ x

M Network/Protocol/XMPP/Connections.hs => Network/Protocol/XMPP/Connections.hs +1 -1
@@ 48,7 48,7 @@ xmlHeader ns jid = encodeUtf8 header where
		, " xmlns:stream=\"http://etherx.jabber.org/streams\">"
		]

startOfStream :: Integer -> X.Event -> Bool
startOfStream :: Integer -> X.SaxEvent -> Bool
startOfStream depth event = case (depth, event) of
	(1, (X.BeginElement elemName _)) -> qnameStream == elemName
	_ -> False

M Network/Protocol/XMPP/Monad.hs => Network/Protocol/XMPP/Monad.hs +1 -1
@@ 154,7 154,7 @@ putElement = putBytes . encodeUtf8 . X.serialiseElement
putStanza :: S.Stanza a => a -> XMPP ()
putStanza = withLock sessionWriteLock . putElement . S.stanzaToElement

readEvents :: (Integer -> X.Event -> Bool) -> XMPP [X.Event]
readEvents :: (Integer -> X.SaxEvent -> Bool) -> XMPP [X.SaxEvent]
readEvents done = xmpp where
	xmpp = do
		Session h _ p _ _ <- getSession

M Network/Protocol/XMPP/XML.hs => Network/Protocol/XMPP/XML.hs +11 -11
@@ 33,7 33,7 @@ module Network.Protocol.XMPP.XML
	
	-- * libxml-sax-0.4 API imitation
	, Parser
	, Event (..)
	, SaxEvent (..)
	, newParser
	, parse
	, eventsToElement


@@ 111,7 111,7 @@ serialiseElement e = text where

-- quick-and-dirty imitation of libxml-sax-0.4 API; later, this should
-- probably be rewritten to use ST and discard the list parsing
data Parser = Parser (SAX.Parser IO) (IORef (Either T.Text [Event]))
data Parser = Parser (SAX.Parser IO) (IORef (Either T.Text [SaxEvent]))

newParser :: IO Parser
newParser = do


@@ 135,7 135,7 @@ newParser = do
	
	return $ Parser p ref

parse :: Parser -> B.ByteString -> Bool -> IO (Either T.Text [Event])
parse :: Parser -> B.ByteString -> Bool -> IO (Either T.Text [SaxEvent])
parse (Parser p ref) bytes finish = do
	writeIORef ref (Right [])
	SAX.parseLazyBytes p bytes


@@ 145,7 145,7 @@ parse (Parser p ref) bytes finish = do
		Left err -> Left err
		Right events -> Right $ reverse events

data Event
data SaxEvent
	= BeginElement Name [Attribute]
	| EndElement Name
	| Characters T.Text


@@ 153,9 153,9 @@ data Event
	| ProcessingInstruction Instruction

readEvents :: Monad m
           => (Integer -> Event -> Bool)
           -> m [Event]
           -> m [Event]
           => (Integer -> SaxEvent -> Bool)
           -> m [SaxEvent]
           -> m [SaxEvent]
readEvents done nextEvents = readEvents' 0 [] where
	readEvents' depth acc = do
		events <- nextEvents


@@ 177,18 177,18 @@ readEvents done nextEvents = readEvents' 0 [] where

-- | Convert a list of events to a single 'X.Element'. If the events do not
-- contain at least one valid element, 'Nothing' will be returned instead.
eventsToElement :: [Event] -> Maybe Element
eventsToElement :: [SaxEvent] -> Maybe Element
eventsToElement es = case eventsToNodes es >>= isElement of
	(e:_) -> Just e
	_ -> Nothing

eventsToNodes :: [Event] -> [Node]
eventsToNodes :: [SaxEvent] -> [Node]
eventsToNodes = concatMap blockToNodes . splitBlocks

-- Split event list into a sequence of "blocks", which are the events including
-- and between a pair of tags. <start><start2/></start> and <start/> are both
-- single blocks.
splitBlocks :: [Event] -> [[Event]]
splitBlocks :: [SaxEvent] -> [[SaxEvent]]
splitBlocks es = ret where
	(_, _, ret) = foldl splitBlocks' (0, [], []) es
	


@@ 203,7 203,7 @@ splitBlocks es = ret where
			(EndElement _) -> (- 1)
			_ -> 0

blockToNodes :: [Event] -> [Node]
blockToNodes :: [SaxEvent] -> [Node]
blockToNodes [] = []
blockToNodes (begin:rest) = nodes where
	end = last rest

M network-protocol-xmpp.cabal => network-protocol-xmpp.cabal +1 -1
@@ 1,5 1,5 @@
name: network-protocol-xmpp
version: 0.3.2
version: 0.3.2.1
synopsis: Client <-> Server communication over XMPP
license: GPL-3
license-file: License.txt