diff options
Diffstat (limited to 'Presence/EventUtil.hs')
-rw-r--r-- | Presence/EventUtil.hs | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/Presence/EventUtil.hs b/Presence/EventUtil.hs deleted file mode 100644 index 908e09e0..00000000 --- a/Presence/EventUtil.hs +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | {-# LANGUAGE OverloadedStrings #-} | ||
2 | module EventUtil where | ||
3 | |||
4 | import Control.Monad | ||
5 | import Data.XML.Types as XML | ||
6 | import qualified Data.List as List | ||
7 | import Data.Text (Text) | ||
8 | |||
9 | -- getStreamName (EventBeginElement name _) = name | ||
10 | |||
11 | isEventBeginElement :: Event -> Bool | ||
12 | isEventBeginElement (EventBeginElement {}) = True | ||
13 | isEventBeginElement _ = False | ||
14 | |||
15 | isEventEndElement :: Event -> Bool | ||
16 | isEventEndElement (EventEndElement {}) = True | ||
17 | isEventEndElement _ = False | ||
18 | |||
19 | -- Note: This function ignores name space qualification | ||
20 | elementAttrs :: | ||
21 | MonadPlus m => | ||
22 | Text -> Event -> m [(Name, [Content])] | ||
23 | elementAttrs expected (EventBeginElement name attrs) | ||
24 | | nameLocalName name==expected | ||
25 | = return attrs | ||
26 | elementAttrs _ _ = mzero | ||
27 | |||
28 | streamP :: Text -> Name | ||
29 | streamP name = Name name (Just "http://etherx.jabber.org/streams") (Just "stream") | ||
30 | |||
31 | attr :: Name -> Text -> (Name,[Content]) | ||
32 | attr name value = (name,[ContentText value]) | ||
33 | |||
34 | isServerIQOf :: Event -> Text -> Bool | ||
35 | isServerIQOf (EventBeginElement name attrs) testType | ||
36 | | name=="{jabber:server}iq" | ||
37 | && matchAttrib "type" testType attrs | ||
38 | = True | ||
39 | isServerIQOf _ _ = False | ||
40 | |||
41 | isClientIQOf :: Event -> Text -> Bool | ||
42 | isClientIQOf (EventBeginElement name attrs) testType | ||
43 | | name=="{jabber:client}iq" | ||
44 | && matchAttrib "type" testType attrs | ||
45 | = True | ||
46 | isClientIQOf _ _ = False | ||
47 | |||
48 | matchAttrib :: Name -> Text -> [(Name, [Content])] -> Bool | ||
49 | matchAttrib name value attrs = | ||
50 | case List.find ( (==name) . fst) attrs of | ||
51 | Just (_,[ContentText x]) | x==value -> True | ||
52 | Just (_,[ContentEntity x]) | x==value -> True | ||
53 | _ -> False | ||
54 | |||
55 | lookupAttrib :: Name -> [(Name, [Content])] -> Maybe Text | ||
56 | lookupAttrib name attrs = | ||
57 | case List.find ( (==name) . fst) attrs of | ||
58 | Just (_,[ContentText x]) -> Just x | ||
59 | Just (_,[ContentEntity x]) -> Just x | ||
60 | _ -> Nothing | ||
61 | |||
62 | tagAttrs :: Event -> [(Name, [Content])] | ||
63 | tagAttrs (EventBeginElement _ xs) = xs | ||
64 | tagAttrs _ = [] | ||
65 | |||
66 | |||
67 | {- | ||
68 | iqTypeSet = "set" | ||
69 | iqTypeGet = "get" | ||
70 | iqTypeResult = "result" | ||
71 | iqTypeError = "error" | ||
72 | -} | ||
73 | |||
74 | |||
75 | tagName :: Event -> Name | ||
76 | tagName (EventBeginElement n _) = n | ||
77 | tagName _ = "" | ||
78 | |||
79 | closerFor :: Event -> Event | ||
80 | closerFor (EventBeginElement n _) = EventEndElement n | ||
81 | closerFor _ = error "closerFor: unsupported event" | ||
82 | |||
83 | |||