SIP-XMPP integration using BOSH
Overview
SIP and XMPP integration using BOSH. I did this some years ago as a proof of concept. Implemented in Perl.
Author
Sebastian Schumann (seb.schumann@gmail.com)
Last modified: 25.09.2009
Documentation
States
Overview
The script requires the following states:
- online
- still-online
- onthephone
- still-onthephone
- offline
State model
The script has the following state model:
online
|------> still-online ------|
| ^ ^ ^ |
| |-------| | | |
| | | ---------|
| | | |
|-|-----> onthephone <------|
| | | |
| | v |
| |-- still-onthephone |
| |
|------> offline <----------|
The meaning of the states and events for transition will be described in the following.
Description
The state 'online' is reached after a SIP user is successfully registered to its proxy. A dedicated XMPP resource (SIP-phone) will publish its state, using the user's XMPP account information. If multiple phone states are planned to be integrated, the resource name should contain a unique identification.
The phone will be in the state 'online' only after SIP sign-on (i.e. after the first presence update towards XMPP after previous termination). After the SIP resource re-REGISTERs (i.e., re-PUBLISHes), the state will change to 'still-online'. The resource will be in this state most of the time.
If a SIP user is in a call, his state will change to 'onthephone'. The state can be reached from 'online' (i.e. call after first registration) or from 'still-online' (i.e. user phone is registered and no call is performed). If the call is long, there will be session keep-alives on the SIP side. Those keep-alives (with Expires < max_inactivity) will trigger the 'still-onthephone' state. During a longer call, the resource will be in this state.
If a call ends, the resource will get back to the state 'still-online'.
If a SIP user deregisters, he will reach the state 'offline'. His resource will be offline.
Arguments
The following parameters are required by the program
- XMPP username (to calculate PLAIN password)
- XMPP password (to calculate PLAIN password)
- State
- RID/SID for all states besides online (to create subsequent request)
- Presence ID for all states besides online (to create subsequent request)
The following parameters must be stored:
- username (as ID)
- RID
- SID
- presenceId
CSV file
The CSV file has the following layout:
SIP URI , XMPP username , XMPP password, RID , [SID] , [presenceId]
SID and presenceId will be only available after the session has been established at least once.
RID will have a default start value: 123456
Example:
0123456789@@domain.example.com,username,password,123456
Start-up
The main functions are exportet now. Before, the script was called with 2 mandatory command-line parameters: SIP username and state.
Example:
perl bosh_connect.pl 0123456789@@domain.example.com online
Now, the program has been extended with a daemon. The daemon reads the input parameter each second from database. OpenSIPS writes those parameters to the database.
The parameters remain: 'uri' and 'state'.
The daemon is integrated with other programs through database (e.g. OpenSIPS).