-----------------------------------------------------------------------------
-- |
-- Module      :  Network.XMPP.XEP.Version
-- Copyright   :  (c) pierre, 2007
-- License     :  BSD-style (see the file libraries/base/LICENSE)
-- 
-- Maintainer  :  Dmitry Astapov <dastapov@gmail.com>, pierre <k.pierre.k@gmail.com>
-- Stability   :  experimental
-- Portability :  portable
--
-- XEP-0092, version request
--
-----------------------------------------------------------------------------
module Network.XMPP.XEP.Version
    ( isVersionReq
    , versionAnswer 
    ) where

import Network.XMPP.Stanza
import Network.XMPP.Stream
import Network.XMPP.Types
import Network.XMPP.Print    
import Network.XMPP.JID
import Network.XMPP.Utils 

import Text.XML.HaXml
import Text.XML.HaXml.Posn    
    
-- | True, if stanza is a version request
isVersionReq :: Stanza -> Bool               
isVersionReq (IQ { iqBody = ext }) =
    isVal "jabber:iq:version" "/iq/query/@xmlns" ext
isVersionReq _ = False

-- | Replies to version request
versionAnswer :: String -> String -> String -> (Stanza -> [CFilter i])
versionAnswer name version os s@(IQ { }) =
    [ ptag "query"
               [ xmlns "jabber:iq:version" ]
               [ ptag "name" [] [literal name],
                 ptag "version" [] [literal version],
                 ptag "os" [] [literal os]
               ]
    ]