Network.Protocol.XMPP

network-protocol-xmpp-0.4.8: Client library for the XMPP protocol.

Safe Haskell | None
Language | Haskell98

Network.Protocol.XMPP

Contents

- JIDs
- Stanzas
- The XMPP monad
  - Resuming sessions

Synopsis

- data JID = JID {
  - jidNode :: Maybe Node
  - jidDomain :: Domain
  - jidResource :: Maybe Resource
  }
- data Node
- data Domain
- data Resource
- strNode :: Node -> Text
- strDomain :: Domain -> Text
- strResource :: Resource -> Text
- parseJID :: Text -> Maybe JID
- formatJID :: JID -> Text
- class Stanza a where
  - stanzaTo :: a -> Maybe JID
  - stanzaFrom :: a -> Maybe JID
  - stanzaID :: a -> Maybe Text
  - stanzaLang :: a -> Maybe Text
  - stanzaPayloads :: a -> [Element]
- data ReceivedStanza
  - = ReceivedMessage Message
  - | ReceivedPresence Presence
  - | ReceivedIQ IQ
- data Message = Message {
  - messageType :: MessageType
  - messageTo :: Maybe JID
  - messageFrom :: Maybe JID
  - messageID :: Maybe Text
  - messageLang :: Maybe Text
  - messagePayloads :: [Element]
  }
- data Presence = Presence {
  - presenceType :: PresenceType
  - presenceTo :: Maybe JID
  - presenceFrom :: Maybe JID
  - presenceID :: Maybe Text
  - presenceLang :: Maybe Text
  - presencePayloads :: [Element]
  }
- data IQ = IQ {
  - iqType :: IQType
  - iqTo :: Maybe JID
  - iqFrom :: Maybe JID
  - iqID :: Maybe Text
  - iqLang :: Maybe Text
  - iqPayload :: Maybe Element
  }
- data MessageType
  - = MessageNormal
  - | MessageChat
  - | MessageGroupChat
  - | MessageHeadline
  - | MessageError
- data PresenceType
  - = PresenceAvailable
  - | PresenceUnavailable
  - | PresenceSubscribe
  - | PresenceSubscribed
  - | PresenceUnsubscribe
  - | PresenceUnsubscribed
  - | PresenceProbe
  - | PresenceError
- data IQType
  - = IQGet
  - | IQSet
  - | IQResult
  - | IQError
- emptyMessage :: MessageType -> Message
- emptyPresence :: PresenceType -> Presence
- emptyIQ :: IQType -> IQ
- data XMPP a
- data Server = Server {
  - serverJID :: JID
  - serverHostname :: HostName
  - serverPort :: PortID
  }
- data Error
  - = AuthenticationFailure Element
  - | AuthenticationError Text
  - | InvalidStanza Element
  - | InvalidBindResult ReceivedStanza
  - | TransportError Text
  - | NoComponentStreamID
- runClient :: Server -> JID -> Text -> Text -> XMPP a -> IO (Either Error a)
- runComponent :: Server -> Text -> XMPP a -> IO (Either Error a)
- putStanza :: Stanza a => a -> XMPP ()
- getStanza :: XMPP ReceivedStanza
- bindJID :: JID -> XMPP JID
- data Session
- getSession :: XMPP Session
- sessionIsSecure :: XMPP Bool
- runXMPP :: Session -> XMPP a -> IO (Either Error a)

# JIDs

data JID

Constructors

JID |
Fields jidNode :: Maybe Node jidDomain :: Domain jidResource :: Maybe Resource

Instances

Eq JID |
Show JID |
IsString JID |

data Node

Instances

Eq Node |
Show Node |

data Domain

Instances

Eq Domain |
Show Domain |

data Resource

Instances

Eq Resource |
Show Resource |

strNode :: Node -> Text

strDomain :: Domain -> Text

strResource :: Resource -> Text

parseJID :: Text -> Maybe JID

formatJID :: JID -> Text

# Stanzas

class Stanza a where

Minimal complete definition

stanzaTo, stanzaFrom, stanzaID, stanzaLang, stanzaPayloads, stanzaToElement

Methods

stanzaTo :: a -> Maybe JID

stanzaFrom :: a -> Maybe JID

stanzaID :: a -> Maybe Text

stanzaLang :: a -> Maybe Text

stanzaPayloads :: a -> [Element]

Instances

Stanza IQ |
Stanza Presence |
Stanza Message |

data ReceivedStanza

Constructors

ReceivedMessage Message |
ReceivedPresence Presence |
ReceivedIQ IQ |

Instances

Show ReceivedStanza |

data Message

Constructors

Message |
Fields messageType :: MessageType messageTo :: Maybe JID messageFrom :: Maybe JID messageID :: Maybe Text messageLang :: Maybe Text messagePayloads :: [Element]

Instances

Show Message |
Stanza Message |

data Presence

Constructors

Presence |
Fields presenceType :: PresenceType presenceTo :: Maybe JID presenceFrom :: Maybe JID presenceID :: Maybe Text presenceLang :: Maybe Text presencePayloads :: [Element]

Instances

Show Presence |
Stanza Presence |

data IQ

Constructors

IQ |
Fields iqType :: IQType iqTo :: Maybe JID iqFrom :: Maybe JID iqID :: Maybe Text iqLang :: Maybe Text iqPayload :: Maybe Element

Instances

Show IQ |
Stanza IQ |

data MessageType

Constructors

MessageNormal |
MessageChat |
MessageGroupChat |
MessageHeadline |
MessageError |

Instances

Eq MessageType |
Show MessageType |

data PresenceType

Constructors

PresenceAvailable |
PresenceUnavailable |
PresenceSubscribe |
PresenceSubscribed |
PresenceUnsubscribe |
PresenceUnsubscribed |
PresenceProbe |
PresenceError |

Instances

Eq PresenceType |
Show PresenceType |

data IQType

Constructors

IQGet |
IQSet |
IQResult |
IQError |

Instances

Eq IQType |
Show IQType |

emptyMessage :: MessageType -> Message

emptyPresence :: PresenceType -> Presence

emptyIQ :: IQType -> IQ

# The XMPP monad

data XMPP a

Instances

Monad XMPP |
Functor XMPP |
MonadFix XMPP |
Applicative XMPP |
MonadIO XMPP |
MonadError XMPP |
type ErrorType XMPP = Error |

data Server

Constructors

Server |
Fields serverJID :: JID serverHostname :: HostName serverPort :: PortID

data Error

Constructors

AuthenticationFailure Element | The remote host refused the specified authentication credentials. The included XML element is the error value that the server provided. It may contain additional information about why authentication failed.
AuthenticationError Text | There was an error while authenticating with the remote host.
InvalidStanza Element | An unrecognized or malformed `Stanza` was received from the remote host.
InvalidBindResult ReceivedStanza | The remote host sent an invalid reply to a resource bind request.
TransportError Text | There was an error with the underlying transport.
NoComponentStreamID | The remote host did not send a stream ID when accepting a component connection.

Instances

Show Error |

runClient

Arguments

:: Server |
-> JID | Client JID
-> Text | Username
-> Text | Password
-> XMPP a |
-> IO (Either Error a) |

runComponent

Arguments

:: Server |
-> Text | Server secret
-> XMPP a |
-> IO (Either Error a) |

putStanza :: Stanza a => a -> XMPP ()

getStanza :: XMPP ReceivedStanza

bindJID :: JID -> XMPP JID

Send a `<bind>` message for the given `JID`, returning the server's reply. In most cases the reply will be the same as the input. However, if the input has no `Resource`, the returned `JID` will contain a generated `Resource`.

Clients must bind a `JID` before sending any `Stanza`s.

## Resuming sessions

data Session

getSession :: XMPP Session

sessionIsSecure :: XMPP Bool

runXMPP :: Session -> XMPP a -> IO (Either Error a)