Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > d661425f055462744853e295597df6f5 > files > 107

libeXosip2-devel-3.1.0-3.fc12.i686.rpm

\section{How-To send or update registrations.}
\label{group__howto2__registration}\index{How-To send or update registrations.@{How-To send or update registrations.}}
eXosip2 offers a flexible API to help you to register one or several identities.

\subsubsection*{Initiate a registration}

To start a registration, you need to build a default REGISTER request bby providing several mandatory headers

\small\begin{alltt}
  osip\_message\_t *reg = NULL;
  int id;
  int i;\end{alltt}
\normalsize 


\small\begin{alltt}  eXosip\_lock ();
  id = eXosip\_register\_build\_initial\_register (identity, registrar, NULL,
                                               1800, \&reg);
  if (id < 0)
    \{
      eXosip\_unlock ();
      return -1;
    \}\end{alltt}
\normalsize 


\small\begin{alltt}  osip\_message\_set\_supported (reg, "100rel");
  osip\_message\_set\_supported(reg, "path");\end{alltt}
\normalsize 


\small\begin{alltt}  i = eXosip\_register\_send\_register (id, reg);
  eXosip\_unlock ();
  return i;\end{alltt}
\normalsize 


\small\begin{alltt}\end{alltt}
\normalsize 


The returned element of eXosip\_\-register\_\-build\_\-initial\_\-register is the registration identifier that you can use to update your registration. In future events about this registration, you'll see that registration identifier when applicable.

\subsubsection*{Update a registration}

You just need to reuse the registration identifier:

\small\begin{alltt}
  int i;\end{alltt}
\normalsize 


\small\begin{alltt}  eXosip\_lock ();
  i = eXosip\_register\_build\_register (id, 1800, \&reg);
  if (i < 0)
    \{
      eXosip\_unlock ();
      return -1;
    \}\end{alltt}
\normalsize 


\small\begin{alltt}  eXosip\_register\_send\_register (id, reg);
  eXosip\_unlock ();
\end{alltt}
\normalsize 


{\bf Note}: The above code also shows that the stack is sometimes able to build and send a default SIP messages with only one API call

\subsubsection*{Closing the registration}

A softphone should delete its registration on the SIP server when terminating. To do so, you have to send a REGISTER request with the expires header set to value \char`\"{}0\char`\"{}.

The same code as for updating a registration is used with 0 instead of 1800 for the expiration delay.