From 71b25eb0fa0f13045d1c8d801ee41231c7d1e4d2 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Sat, 17 Nov 2012 01:14:56 +0100 Subject: [PATCH 1/5] borrowed modifyTVar for GHC 7.0 compatibility --- source/Network/Xmpp/Concurrent/Monad.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/Network/Xmpp/Concurrent/Monad.hs b/source/Network/Xmpp/Concurrent/Monad.hs index 6a3de26..29c1019 100644 --- a/source/Network/Xmpp/Concurrent/Monad.hs +++ b/source/Network/Xmpp/Concurrent/Monad.hs @@ -6,6 +6,7 @@ import Network.Xmpp.Types import Control.Applicative((<$>)) import Control.Concurrent import Control.Concurrent.STM +import Control.Concurrent.STM.TVar (TVar, readTVar, writeTVar) import qualified Control.Exception.Lifted as Ex import Control.Monad.IO.Class import Control.Monad.Reader @@ -205,6 +206,14 @@ sendMessage m session = sendStanza (MessageS m) session -- | Executes a function to update the event handlers. modifyHandlers :: (EventHandlers -> EventHandlers) -> Session -> IO () modifyHandlers f session = atomically $ modifyTVar (eventHandlers session) f + where + -- Borrowing modifyTVar from + -- http://hackage.haskell.org/packages/archive/stm/2.4/doc/html/src/Control-Concurrent-STM-TVar.html + -- as it's not available in GHC 7.0. + modifyTVar :: TVar a -> (a -> a) -> STM () + modifyTVar var f = do + x <- readTVar var + writeTVar var (f x) -- | Sets the handler to be executed when the server connection is closed. setConnectionClosedHandler :: (StreamError -> Session -> IO ()) -> Session -> IO () From 8338cc6536aee7ad381ff5228f64c1efe45811a6 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Sat, 17 Nov 2012 01:24:07 +0100 Subject: [PATCH 2/5] fixed build errors for EchoClient --- examples/EchoClient.hs | 17 ++++++++--------- source/Network/Xmpp.hs | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/EchoClient.hs b/examples/EchoClient.hs index aeb6a22..ad45313 100644 --- a/examples/EchoClient.hs +++ b/examples/EchoClient.hs @@ -36,24 +36,23 @@ resource = Nothing -- TODO: Incomplete code, needs documentation, etc. main :: IO () main = do - withNewSession $ do - withConnection $ simpleConnect hostname username password resource - sendPresence presenceOnline - echo - return () + session <- newSession + withConnection (simpleConnect hostname username password resource) session + sendPresence presenceOnline session + echo session return () -- Pull message stanzas, verify that they originate from a `full' XMPP -- address, and, if so, `echo' the message back. -echo :: Xmpp () -echo = forever $ do - result <- pullMessage +echo :: Session -> IO () +echo session = forever $ do + result <- pullMessage session case result of Right message -> if (isJust $ messageFrom message) && (isFull $ fromJust $ messageFrom message) then do -- TODO: May not set from. - sendMessage $ Message Nothing (messageTo message) (messageFrom message) Nothing (messageType message) (messagePayload message) + sendMessage (Message Nothing (messageTo message) (messageFrom message) Nothing (messageType message) (messagePayload message)) session liftIO $ putStrLn "Message echoed!" else liftIO $ putStrLn "Message sender is not set or is bare!" Left exception -> liftIO $ putStrLn "Error: " \ No newline at end of file diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs index 5b23db8..37b819b 100644 --- a/source/Network/Xmpp.hs +++ b/source/Network/Xmpp.hs @@ -29,7 +29,8 @@ module Network.Xmpp ( -- * Session management - newSession + Session + , newSession , withConnection , connect , simpleConnect From 01847fc85a0442f87b8f572520ae60b6d54c337a Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Sat, 17 Nov 2012 23:41:10 +0100 Subject: [PATCH 3/5] added lower bounds for versions of dependencies --- pontarius-xmpp.cabal | 56 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/pontarius-xmpp.cabal b/pontarius-xmpp.cabal index eeedc69..5bd558c 100644 --- a/pontarius-xmpp.cabal +++ b/pontarius-xmpp.cabal @@ -14,7 +14,7 @@ Bug-Reports: mailto:info@jonkri.com Package-URL: http://hackage.haskell.org/packages/archive/pontarius-xmpp/0.1.0.0/pontarius-xmpp-0.1.0.0.tar.gz Synopsis: An incomplete implementation of RFC 6120 (XMPP: Core) Description: Pontarius is a work in progress implementation of - RFC 6120 (XMPP: Core). + RFC 6120 (XMPP: Core). Category: Network Tested-With: GHC ==7.0.4, GHC ==7.4.1 -- Data-Files: @@ -25,33 +25,33 @@ Tested-With: GHC ==7.0.4, GHC ==7.4.1 Library hs-source-dirs: source Exposed: True - Build-Depends: base >4 && <5 - , conduit >= 0.5 - , void -any - , resourcet -any - , containers -any - , random -any - , tls -any - , tls-extra -any - , pureMD5 -any - , base64-bytestring -any - , binary -any - , attoparsec -any - , crypto-api -any - , cryptohash -any - , text -any - , bytestring -any - , transformers -any - , mtl -any - , network -any - , lifted-base -any - , split -any - , stm -any - , xml-types -any - , xml-conduit >= 1.0 - , xml-picklers >= 0.2.2 - , data-default -any - , stringprep >= 0.1.5 + Build-Depends: base >4 && <5 + , conduit >=0.5 + , void >=0.5.5 + , resourcet >=0.3.0 + , containers >=0.4.0.0 + , random >=1.0.0.0 + , tls >=1.0.0 + , tls-extra >=0.5.0 + , pureMD5 >=2.1.2.1 + , base64-bytestring >=0.1.0.0 + , binary >=0.4.1 + , attoparsec >=0.10.0.3 + , crypto-api >=0.9 + , cryptohash >=0.6.1 + , text >=0.11.1.5 + , bytestring >=0.9.1.9 + , transformers >=0.2.2.0 + , mtl >=2.0.0.0 + , network >=2.3 + , lifted-base >=0.1.0.1 + , split >=0.1.2.3 + , stm >=2.1.2.1 + , xml-types >=0.3.1 + , xml-conduit >=1.0 + , xml-picklers >=0.2.2 + , data-default >=0.2 + , stringprep >=0.1.3 Exposed-modules: Network.Xmpp , Network.Xmpp.Bind , Network.Xmpp.Concurrent From 3b688e03804389169a09adefbe30ba43b8c13685 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Sat, 17 Nov 2012 23:41:35 +0100 Subject: [PATCH 4/5] minor documentation and formatting changes --- source/Network/Xmpp.hs | 19 ++++++++----------- source/Network/Xmpp/Concurrent/Monad.hs | 2 +- source/Network/Xmpp/Concurrent/Threads.hs | 2 +- source/Network/Xmpp/Jid.hs | 7 +++++-- source/Network/Xmpp/Stream.hs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/Network/Xmpp.hs b/source/Network/Xmpp.hs index 37b819b..8b6e9b2 100644 --- a/source/Network/Xmpp.hs +++ b/source/Network/Xmpp.hs @@ -4,7 +4,7 @@ -- Core). -- License: Apache License 2.0 -- --- Maintainer: jon.kristensen@nejla.com +-- Maintainer: info@jonkri.com -- Stability: unstable -- Portability: portable -- @@ -41,9 +41,6 @@ module Network.Xmpp , endSession , setConnectionClosedHandler -- * JID - -- | A JID (historically: Jabber ID) is XMPPs native format - -- for addressing entities in the network. It is somewhat similar to an e-mail - -- address but contains three parts instead of two: , Jid(..) , isBare , isFull @@ -86,11 +83,11 @@ module Network.Xmpp , Message(..) , MessageError(..) , MessageType(..) - -- *** creating + -- *** Creating , answerMessage - -- *** sending + -- *** Sending , sendMessage - -- *** receiving + -- *** Receiving , pullMessage , waitForMessage , waitForMessageError @@ -102,9 +99,9 @@ module Network.Xmpp -- communication primitive: the presence stanza. , Presence(..) , PresenceError(..) - -- *** creating + -- *** Creating , module Network.Xmpp.Presence - -- *** sending + -- *** Sending -- | Sends a presence stanza. In general, the presence stanza should have no -- 'to' attribute, in which case the server to which the client is connected -- will broadcast that stanza to all subscribed entities. However, a @@ -112,7 +109,7 @@ module Network.Xmpp -- which case the server will route or deliver that stanza to the intended -- recipient. , sendPresence - -- *** receiving + -- *** Receiving , pullPresence , waitForPresence -- ** IQ @@ -142,7 +139,7 @@ module Network.Xmpp , iqResultPayload -- * Threads , forkSession - -- * Misc + -- * Miscellaneous , LangTag(..) , exampleParams ) where diff --git a/source/Network/Xmpp/Concurrent/Monad.hs b/source/Network/Xmpp/Concurrent/Monad.hs index 29c1019..8c6980f 100644 --- a/source/Network/Xmpp/Concurrent/Monad.hs +++ b/source/Network/Xmpp/Concurrent/Monad.hs @@ -152,7 +152,7 @@ waitForPresence f session = do -- TODO: Wait for presence error? --- | Run an XmppMonad action in isolation. Reader and writer workers will be +-- | Run an XmppConMonad action in isolation. Reader and writer workers will be -- temporarily stopped and resumed with the new session details once the action -- returns. The action will run in the calling thread. Any uncaught exceptions -- will be interpreted as connection failure. diff --git a/source/Network/Xmpp/Concurrent/Threads.hs b/source/Network/Xmpp/Concurrent/Threads.hs index 8788996..c438bc6 100644 --- a/source/Network/Xmpp/Concurrent/Threads.hs +++ b/source/Network/Xmpp/Concurrent/Threads.hs @@ -199,7 +199,7 @@ startThreads = do { connectionClosedHandler = \_ -> return () } --- | Creates and initializes a new concurrent session. +-- | Initializes a new XMPP session. newSession :: IO Session newSession = do (mC, pC, sC, hand, outC, stopThreads', writeR, conS, rdr, eh) <- startThreads diff --git a/source/Network/Xmpp/Jid.hs b/source/Network/Xmpp/Jid.hs index df1b889..bb80884 100644 --- a/source/Network/Xmpp/Jid.hs +++ b/source/Network/Xmpp/Jid.hs @@ -23,6 +23,9 @@ import qualified Data.Text as Text import qualified Text.NamePrep as SP import qualified Text.StringPrep as SP +-- | A JID is XMPP\'s native format for addressing entities in the network. It +-- is somewhat similar to an e-mail address but contains three parts instead of +-- two. data Jid = Jid { -- | The @localpart@ of a JID is an optional identifier placed -- before the domainpart and separated from the latter by a -- \'\@\' character. Typically a localpart uniquely identifies @@ -105,12 +108,12 @@ fromStrings l d r = do validPartLength :: Text -> Bool validPartLength p = Text.length p > 0 && Text.length p < 1024 --- | Returns True if the JID is /bare/, and False otherwise. +-- | Returns 'True' if the JID is /bare/, and 'False' otherwise. isBare :: Jid -> Bool isBare j | resourcepart j == Nothing = True | otherwise = False --- | Returns True if the JID is 'full', and False otherwise. +-- | Returns 'True' if the JID is /full/, and 'False' otherwise. isFull :: Jid -> Bool isFull = not . isBare diff --git a/source/Network/Xmpp/Stream.hs b/source/Network/Xmpp/Stream.hs index 2ead3b6..6fb1dd6 100644 --- a/source/Network/Xmpp/Stream.hs +++ b/source/Network/Xmpp/Stream.hs @@ -15,7 +15,7 @@ import Data.Maybe (fromJust, isJust, isNothing) import Data.Text as Text import Data.XML.Pickle import Data.XML.Types -import Data.Void(Void) +import Data.Void (Void) import Network.Xmpp.Monad import Network.Xmpp.Pickle From 8ef30ac78b0cc7a6ceee079914c2a44148fc66e5 Mon Sep 17 00:00:00 2001 From: Jon Kristensen Date: Sun, 18 Nov 2012 00:11:07 +0100 Subject: [PATCH 5/5] set License: OtherLicense --- pontarius-xmpp.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pontarius-xmpp.cabal b/pontarius-xmpp.cabal index 5bd558c..8352050 100644 --- a/pontarius-xmpp.cabal +++ b/pontarius-xmpp.cabal @@ -2,7 +2,7 @@ Name: pontarius-xmpp Version: 0.1.0.0 Cabal-Version: >= 1.6 Build-Type: Simple --- License: +License: OtherLicense License-File: LICENSE Copyright: Dmitry Astapov, Pierre Kovalev, Mahdi Abdinejadi, Jon Kristensen, IETF Trust, Philipp Balzarek