net-mqtt 0.2.1.0 → 0.2.2.0
raw patch · 4 files changed
+44/−5 lines, 4 filesdep +network-uriPVP ok
version bump matches the API change (PVP)
Dependencies added: network-uri
API changes (from Hackage documentation)
+ Network.MQTT.Client: connectURI :: MQTTConfig -> URI -> IO MQTTClient
Files
- Changelog.md +5/−0
- README.md +1/−1
- net-mqtt.cabal +5/−2
- src/Network/MQTT/Client.hs +33/−2
Changelog.md view
@@ -1,5 +1,10 @@ # Changelog for net-mqtt +## 0.2.2.0++Added connectURI to make it easier to connect to mqtt or mqtts via+URI.+ ## 0.2.1.0 No externally visible changes, but a few bug fixes I found when
README.md view
@@ -23,7 +23,7 @@ print =<< waitForClient mc -- wait for the the client to disconnect where- msgReceived t m = print (t,m)+ msgReceived _ t m = print (t,m) ``` [mqtt]: http://mqtt.org/
net-mqtt.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: a06d7432239129c0c9e1c167ca977a97d9dae67c57e59c8a0a4a8c4985a53905+-- hash: 6ce49962b4292c81389d6a35017dccb8270e7ffafc1d99dac05ae0dc4565610c name: net-mqtt-version: 0.2.1.0+version: 0.2.2.0 synopsis: An MQTT Protocol Implementation. description: Please see the README on GitHub at <https://github.com/dustin/mqtt#readme> category: Network@@ -46,6 +46,7 @@ , conduit-extra >=1.3.0 && <1.4 , containers >=0.6.0 && <0.7 , network-conduit-tls >=1.3.2 && <1.4+ , network-uri >=2.6.1 && <2.7 , stm >=2.5.0 && <2.6 , text >=1.2.3 && <1.3 default-language: Haskell2010@@ -68,6 +69,7 @@ , containers >=0.6.0 && <0.7 , net-mqtt , network-conduit-tls >=1.3.2 && <1.4+ , network-uri >=2.6.1 && <2.7 , stm >=2.5.0 && <2.6 , text >=1.2.3 && <1.3 default-language: Haskell2010@@ -93,6 +95,7 @@ , containers >=0.6.0 && <0.7 , net-mqtt , network-conduit-tls >=1.3.2 && <1.4+ , network-uri >=2.6.1 && <2.7 , stm >=2.5.0 && <2.6 , tasty , tasty-hunit
src/Network/MQTT/Client.hs view
@@ -18,6 +18,7 @@ MQTTConfig(..), MQTTClient, QoS(..), Topic, mqttConfig, mkLWT, LastWill(..), -- * Running and waiting for the client. runClient, runClientTLS, waitForClient,+ connectURI, disconnect, -- * General client interactions. subscribe, unsubscribe, publish, publishq@@ -48,8 +49,11 @@ import Data.Text (Text) import qualified Data.Text.Encoding as TE import Data.Word (Word16)+import Network.URI (URI (..), unEscapeString, uriPort,+ uriRegName, uriUserInfo) + import Network.MQTT.Types as T -- | Topic is a type alias for topic values.@@ -99,6 +103,33 @@ _msgCB=Nothing} +-- | Connect to an MQTT server by URI. Currently only mqtt and mqtts+-- URLs are supported. The host, port, username, and password will be+-- derived from the URI and the values supplied in the config will be+-- ignored.+connectURI :: MQTTConfig -> URI -> IO MQTTClient+connectURI cfg uri = do+ let cf = case uriScheme uri of+ "mqtt:" -> runClient+ "mqtts:" -> runClientTLS+ us -> fail $ "invalid URI scheme: " <> us++ (Just a) = uriAuthority uri+ (u,p) = up (uriUserInfo a)++ cf cfg{_hostname=uriRegName a, _port=port (uriPort a) (uriScheme uri),+ Network.MQTT.Client._username=u, Network.MQTT.Client._password=p}++ where+ port "" "mqtt:" = 1883+ port "" "mqtts:" = 8883+ port x _ = read x++ up "" = (Nothing, Nothing)+ up x = let (u,r) = break (== ':') (init x) in+ (Just (unEscapeString u), if r == "" then Nothing else Just (unEscapeString $ tail r))++ -- | Set up and run a client from the given config. runClient :: MQTTConfig -> IO MQTTClient runClient cfg@MQTTConfig{..} = runClientAppData (runTCPClient (clientSettings _port (BCS.pack _hostname))) cfg@@ -305,8 +336,8 @@ where types = [DPubACK, DPubREC, DPubCOMP]- publishAndWait ch pid QoS0 = sendPacketIO c (pkt False pid)- publishAndWait ch pid _ = withAsync (pub False pid) (\p -> satisfyQoS p ch pid)+ publishAndWait _ pid QoS0 = sendPacketIO c (pkt False pid)+ publishAndWait ch pid _ = withAsync (pub False pid) (\p -> satisfyQoS p ch pid) pub dup pid = do sendPacketIO c (pkt dup pid)