|
|
|
@ -33,7 +33,7 @@ timeout = Just 3000000 -- 3 seconds |
|
|
|
|
|
|
|
|
|
|
|
-- | Push a roster item to the server. The values for approved and ask are |
|
|
|
-- | Push a roster item to the server. The values for approved and ask are |
|
|
|
-- ignored and all values for subsciption except "remove" are ignored |
|
|
|
-- ignored and all values for subsciption except "remove" are ignored |
|
|
|
rosterPush :: Item -> Session -> IO (Either IQSendError IQResponse) |
|
|
|
rosterPush :: Item -> Session -> IO (Either IQSendError (Annotated IQResponse)) |
|
|
|
rosterPush item session = do |
|
|
|
rosterPush item session = do |
|
|
|
let el = pickleElem xpQuery (Query Nothing [fromItem item]) |
|
|
|
let el = pickleElem xpQuery (Query Nothing [fromItem item]) |
|
|
|
sendIQ' timeout Nothing Set Nothing el session |
|
|
|
sendIQ' timeout Nothing Set Nothing el session |
|
|
|
@ -45,7 +45,7 @@ rosterAdd :: Jid -- ^ JID of the item |
|
|
|
-> Maybe Text -- ^ Name alias |
|
|
|
-> Maybe Text -- ^ Name alias |
|
|
|
-> [Text] -- ^ Groups (duplicates will be removed) |
|
|
|
-> [Text] -- ^ Groups (duplicates will be removed) |
|
|
|
-> Session |
|
|
|
-> Session |
|
|
|
-> IO (Either IQSendError IQResponse) |
|
|
|
-> IO (Either IQSendError (Annotated IQResponse)) |
|
|
|
rosterAdd j n gs session = do |
|
|
|
rosterAdd j n gs session = do |
|
|
|
let el = pickleElem xpQuery (Query Nothing |
|
|
|
let el = pickleElem xpQuery (Query Nothing |
|
|
|
[QueryItem { qiApproved = Nothing |
|
|
|
[QueryItem { qiApproved = Nothing |
|
|
|
@ -67,7 +67,7 @@ rosterRemove j sess = do |
|
|
|
Just _ -> do |
|
|
|
Just _ -> do |
|
|
|
res <- rosterPush (Item False False j Nothing Remove []) sess |
|
|
|
res <- rosterPush (Item False False j Nothing Remove []) sess |
|
|
|
case res of |
|
|
|
case res of |
|
|
|
Right (IQResponseResult IQResult{}) -> return True |
|
|
|
Right (IQResponseResult IQResult{}, _) -> return True |
|
|
|
_ -> return False |
|
|
|
_ -> return False |
|
|
|
|
|
|
|
|
|
|
|
-- | Retrieve the current Roster state |
|
|
|
-- | Retrieve the current Roster state |
|
|
|
@ -86,13 +86,13 @@ initRoster session = do |
|
|
|
Just roster -> atomically $ writeTVar (rosterRef session) roster |
|
|
|
Just roster -> atomically $ writeTVar (rosterRef session) roster |
|
|
|
|
|
|
|
|
|
|
|
handleRoster :: TVar Roster -> StanzaHandler |
|
|
|
handleRoster :: TVar Roster -> StanzaHandler |
|
|
|
handleRoster ref out sta = case sta of |
|
|
|
handleRoster ref out sta as = case sta of |
|
|
|
IQRequestS (iqr@IQRequest{iqRequestPayload = |
|
|
|
IQRequestS (iqr@IQRequest{iqRequestPayload = |
|
|
|
iqb@Element{elementName = en}}) |
|
|
|
iqb@Element{elementName = en}}) |
|
|
|
| nameNamespace en == Just "jabber:iq:roster" -> do |
|
|
|
| nameNamespace en == Just "jabber:iq:roster" -> do |
|
|
|
case iqRequestFrom iqr of |
|
|
|
case iqRequestFrom iqr of |
|
|
|
Just _from -> return [sta] -- Don't handle roster pushes from |
|
|
|
Just _from -> return [(sta, as)] -- Don't handle roster pushes |
|
|
|
-- unauthorized sources |
|
|
|
-- from unauthorized sources |
|
|
|
Nothing -> case unpickleElem xpQuery iqb of |
|
|
|
Nothing -> case unpickleElem xpQuery iqb of |
|
|
|
Right Query{ queryVer = v |
|
|
|
Right Query{ queryVer = v |
|
|
|
, queryItems = [update] |
|
|
|
, queryItems = [update] |
|
|
|
@ -104,7 +104,7 @@ handleRoster ref out sta = case sta of |
|
|
|
errorM "Pontarius.Xmpp" "Invalid roster query" |
|
|
|
errorM "Pontarius.Xmpp" "Invalid roster query" |
|
|
|
_ <- out $ badRequest iqr |
|
|
|
_ <- out $ badRequest iqr |
|
|
|
return [] |
|
|
|
return [] |
|
|
|
_ -> return [sta] |
|
|
|
_ -> return [(sta, as)] |
|
|
|
where |
|
|
|
where |
|
|
|
handleUpdate v' update = atomically $ modifyTVar ref $ \(Roster v is) -> |
|
|
|
handleUpdate v' update = atomically $ modifyTVar ref $ \(Roster v is) -> |
|
|
|
Roster (v' `mplus` v) $ case qiSubscription update of |
|
|
|
Roster (v' `mplus` v) $ case qiSubscription update of |
|
|
|
@ -132,16 +132,16 @@ retrieveRoster mbOldRoster sess = do |
|
|
|
Left e -> do |
|
|
|
Left e -> do |
|
|
|
errorM "Pontarius.Xmpp.Roster" $ "getRoster: " ++ show e |
|
|
|
errorM "Pontarius.Xmpp.Roster" $ "getRoster: " ++ show e |
|
|
|
return Nothing |
|
|
|
return Nothing |
|
|
|
Right (IQResponseResult (IQResult{iqResultPayload = Just ros})) |
|
|
|
Right (IQResponseResult (IQResult{iqResultPayload = Just ros}), _) |
|
|
|
-> case unpickleElem xpQuery ros of |
|
|
|
-> case unpickleElem xpQuery ros of |
|
|
|
Left _e -> do |
|
|
|
Left _e -> do |
|
|
|
errorM "Pontarius.Xmpp.Roster" "getRoster: invalid query element" |
|
|
|
errorM "Pontarius.Xmpp.Roster" "getRoster: invalid query element" |
|
|
|
return Nothing |
|
|
|
return Nothing |
|
|
|
Right ros' -> return . Just $ toRoster ros' |
|
|
|
Right ros' -> return . Just $ toRoster ros' |
|
|
|
Right (IQResponseResult (IQResult{iqResultPayload = Nothing})) -> do |
|
|
|
Right (IQResponseResult (IQResult{iqResultPayload = Nothing}), _) -> do |
|
|
|
return mbOldRoster |
|
|
|
return mbOldRoster |
|
|
|
-- sever indicated that no roster updates are necessary |
|
|
|
-- sever indicated that no roster updates are necessary |
|
|
|
Right (IQResponseError e) -> do |
|
|
|
Right (IQResponseError e, _) -> do |
|
|
|
errorM "Pontarius.Xmpp.Roster" $ "getRoster: server returned error" |
|
|
|
errorM "Pontarius.Xmpp.Roster" $ "getRoster: server returned error" |
|
|
|
++ show e |
|
|
|
++ show e |
|
|
|
return Nothing |
|
|
|
return Nothing |
|
|
|
|