diff options
Diffstat (limited to 'Presence')
-rw-r--r-- | Presence/XMPP.hs | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/Presence/XMPP.hs b/Presence/XMPP.hs index 36d9bf74..fd528037 100644 --- a/Presence/XMPP.hs +++ b/Presence/XMPP.hs | |||
@@ -323,7 +323,10 @@ lookupAttrib name attrs = | |||
323 | Just (_,[ContentEntity x]) -> Just x | 323 | Just (_,[ContentEntity x]) -> Just x |
324 | _ -> Nothing | 324 | _ -> Nothing |
325 | 325 | ||
326 | iqTypeSet = "set" | 326 | iqTypeSet = "set" |
327 | iqTypeGet = "get" | ||
328 | iqTypeResult = "result" | ||
329 | iqTypeError = "error" | ||
327 | 330 | ||
328 | isIQOf (EventBeginElement name attrs) testType | 331 | isIQOf (EventBeginElement name attrs) testType |
329 | | name=="{jabber:client}iq" | 332 | | name=="{jabber:client}iq" |
@@ -331,6 +334,37 @@ isIQOf (EventBeginElement name attrs) testType | |||
331 | = True | 334 | = True |
332 | isIQOf _ _ = False | 335 | isIQOf _ _ = False |
333 | 336 | ||
337 | iq_service_unavailable host iq_id mjid req = | ||
338 | [ EventBeginElement "{jabber:client}iq" | ||
339 | [("type",[ContentText "error"]) | ||
340 | ,("id",[ContentText iq_id]) | ||
341 | -- , TODO: set "from" if isJust mjid | ||
342 | ] | ||
343 | , EventBeginElement req [] | ||
344 | , EventEndElement req | ||
345 | , EventBeginElement "{jabber:client}error" [("type",[ContentText "cancel"])] | ||
346 | , EventBeginElement "{urn:ietf:params:xml:ns:xmpp-stanzas}service-unavailable" [] | ||
347 | , EventEndElement "{urn:ietf:params:xml:ns:xmpp-stanzas}service-unavailable" | ||
348 | , EventEndElement "{jabber:client}error" | ||
349 | , EventEndElement "{jabber:client}iq" | ||
350 | ] | ||
351 | |||
352 | handleIQGet session cmdChan tag = do | ||
353 | withJust (lookupAttrib "id" (tagAttrs tag)) $ \stanza_id -> do | ||
354 | whenJust nextElement $ \child -> do | ||
355 | host <- liftIO $ do | ||
356 | jid <- getJID session | ||
357 | names <- getNamesForPeer (peer jid) | ||
358 | return (S.decodeUtf8 . head $ names) | ||
359 | let unhandledGet req = do | ||
360 | liftIO $ putStrLn ("iq-get: "++show (stanza_id,child)) | ||
361 | liftIO . atomically . writeTChan cmdChan . Send $ iq_service_unavailable host stanza_id Nothing req | ||
362 | case tagName child of | ||
363 | -- "{http://jabber.org/protocol/disco#items}query" -> liftIO $ putStrLn "iq-get-query-items" | ||
364 | -- "{urn:xmpp:ping}ping" -> todo | ||
365 | req -> unhandledGet req | ||
366 | |||
367 | |||
334 | fromClient :: (MonadThrow m,MonadIO m, XMPPSession session) => | 368 | fromClient :: (MonadThrow m,MonadIO m, XMPPSession session) => |
335 | session -> TChan Commands -> Sink XML.Event m () | 369 | session -> TChan Commands -> Sink XML.Event m () |
336 | fromClient session cmdChan = doNestingXML $ do | 370 | fromClient session cmdChan = doNestingXML $ do |
@@ -358,6 +392,7 @@ fromClient session cmdChan = doNestingXML $ do | |||
358 | withJust mb $ \xs -> prettyPrint "C: " (toList xs) | 392 | withJust mb $ \xs -> prettyPrint "C: " (toList xs) |
359 | case () of | 393 | case () of |
360 | _ | stanza `isIQOf` iqTypeSet -> handleIQSet session cmdChan stanza | 394 | _ | stanza `isIQOf` iqTypeSet -> handleIQSet session cmdChan stanza |
395 | _ | stanza `isIQOf` iqTypeGet -> handleIQGet session cmdChan stanza | ||
361 | _ | otherwise -> unhandledStanza | 396 | _ | otherwise -> unhandledStanza |
362 | 397 | ||
363 | awaitCloser stanza_lvl | 398 | awaitCloser stanza_lvl |