MyNixOS website logo
Description

An XMPP client library.

Pontarius XMPP is a work in progress implementation of RFC 6120 ("XMPP CORE"), RFC 6121 ("XMPP IM"), and RFC 6122 ("XMPP ADDR"). While in alpha, Pontarius XMPP works quite well and fulfills most requirements of the RFCs.

Pontarius XMPP

Pontarius XMPP is a Haskell XMPP client library that implements the capabilities of RFC 6120 ("XMPP CORE"), RFC 6121 ("XMPP IM"), and RFC 6122 ("XMPP ADDR"). Pontarius XMPP was part of the Pontarius project, an effort to produce free and open source, uncentralized, and privacy-aware software solutions.

While in alpha, Pontarius XMPP works quite well and fulfills most requirements of the RFCs.

Prerequisites

Pontarius XMPP requires GHC 7.0, or later.

You will need the ICU Unicode library and it's header files in order to be able to build Pontarius XMPP. On Debian, you will need to install the libicu-dev package. In Fedora, the package is called libicu-devel.

Note to users of GHC 7.0 and GHC 7.2: You will need cabal-install, version 0.14.0 or higher, or the build will fail with an "unrecognized option: --disable-benchmarks" error. The versions 1.16.0 and higher might not build on your system; if so, install 0.14.0 with "cabal install cabal-install-0.14.0".

Note to users of GHC 7.2.1: Due to a bug, recent versions of the binary package wont build without running "ghc-pkg trust base".

Note to users of GHC 7.0.1: You will want to configure your Cabal environment (including cabal-install) for version 0.9.2.1 of bytestring.

Getting started

The latest release of Pontarius XMPP, as well as its module API pages, can always be found at the Pontarius XMPP Hackage page.

Note: Pontarius XMPP is still in its Alpha phase. Pontarius XMPP is not yet feature-complete, it may contain bugs, and its API may change between versions.

The first thing to do is to import the modules that we are going to use. We are also using the OverloadedStrings LANGUAGE pragma in order to be able to type Text values like strings.

{-# LANGUAGE OverloadedStrings #-}

import Network.Xmpp

import Control.Monad
import Data.Default
import System.Log.Logger

Pontarius XMPP supports hslogger logging. Start by enabling console logging.

updateGlobalLogger "Pontarius.Xmpp" $ setLevel DEBUG

When this is done, a Session object can be acquired by calling session. This object will be used for interacting with the library.

result <- session
             "example.com"
              (Just (\_ -> ( [scramSha1 "username" Nothing "password"])
                           , Nothing))
              def

The three parameters above are the XMPP server realm, a SASL handler (for authentication), and the session configuration settings (set to the default settings). session will perform the necessary DNS queries to find the address of the realm, connect, establish the XMPP stream, attempt to secure the stream with TLS, authenticate, establish a concurrent interface for interacting with the stream, and return the Session object.

The return type of session is IO (Either XmppFailure Session). As XmppFailure is an Control.Monad.Error instance, you can utilize the ErrorT monad transformer for error handling. A more simple way of doing it could be doing something like this:

sess <- case result of
            Right s -> return s
            Left e -> error $ "XmppFailure: " ++ (show e)

Next, let us set our status to Online.

sendPresence def sess

Here, def refers to the default Presence value, which is the same as Presence Nothing Nothing Nothing Nothing Available [].

Now, let's say that we want to receive all message stanzas, and echo the stanzas back to the sender. This can be done like so:

forever $ do
    msg <- getMessage sess
    case answerMessage msg (messagePayload msg) of
        Just answer -> sendMessage answer sess
        Nothing -> putStrLn "Received message with no sender."

You don't need to worry about escaping your Text values - Pontarius XMPP (or rather, xml-picklers) will take care of that for you.

Additional XMPP threads can be created using dupSession and forkIO.

For a public domain example of a simple Pontarius XMPP (Cabal) project, refer to the examples/echoclient directory.

Metadata

Version

0.5.7.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows