Sophie

Sophie

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

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

\section{How-To initialize libeXosip2.}
\label{group__howto0__initialize}\index{How-To initialize libeXosip2.@{How-To initialize libeXosip2.}}
When using eXosip, your first task is to initialize both eXosip context and libosip library (parser and state machines). This must be done prior to any use of libeXosip2.

\small\begin{alltt}
	include <\doxyref{eXosip2/eXosip.h}{p.}{eXosip_8h}>\end{alltt}
\normalsize 


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


\small\begin{alltt}	TRACE\_INITIALIZE (6, stdout);\end{alltt}
\normalsize 


\small\begin{alltt}	i=eXosip\_init();
	if (i!=0)
	  return -1;\end{alltt}
\normalsize 


\small\begin{alltt}	i = eXosip\_listen\_addr (IPPROTO\_UDP, NULL, port, AF\_INET, 0);
	if (i!=0)
	  \{
	    \doxyref{eXosip\_quit()}{p.}{group__eXosip2__conf_g03f2a9d54e88cbc36341cd2fcb91b05b};
	    fprintf (stderr, "could not initialize transport layer\(\backslash\)n");
	    return -1;
	  \}\end{alltt}
\normalsize 


\small\begin{alltt}	... then you have to send messages and wait for eXosip events...
\end{alltt}
\normalsize 


In the previous code, you've learned how to: \begin{itemize}
\item Initialize the osip trace (compile this code with -DENABLE\_\-TRACE) \item Initialize eXosip (and osip) stack \item Open a socket for signalling (only UDP with initial eXosip2 version) \end{itemize}


Now you have to handle eXosip events. Here is some code to get \doxyref{eXosip\_\-event}{p.}{structeXosip__event} from the eXosip2 stack.

\small\begin{alltt}
  eXosip\_event\_t *je;
  for (;;)
    \{
      je = eXosip\_event\_wait (0, 50);
      \doxyref{eXosip\_lock()}{p.}{group__eXosip2__conf_g039d93925ac6d1fdf35c68d6c6c435f5};
      eXosip\_automatic\_action ();
      \doxyref{eXosip\_unlock()}{p.}{group__eXosip2__conf_gcb362e00f0e5fb68ae53f18d846cd891};
      if (je == NULL)
        break;
      if (je->type == EXOSIP\_CALL\_NEW)
        \{
        ....
        ....
        \}
      else if (je->type == EXOSIP\_CALL\_ACK)
        \{
        ....
        ....
        \}
      else if (je->type == EXOSIP\_CALL\_ANSWERED)
        \{
        ....
        ....
        \}
      else .....
      ....
      ....\end{alltt}
\normalsize 


\small\begin{alltt}      eXosip\_event\_free(je);
    \}
\end{alltt}
\normalsize 


You will receive one event for each SIP message sent. Each event contains the original request of the affected transaction and the last response that triggers the event when available.

You can access all headers from those messages and store them in your own context for other actions or graphic displays.

For example, when you receive a REFER request for a call transfer, you'll typically retreive the \char`\"{}refer-To\char`\"{} header:

\small\begin{alltt}
  osip\_header\_t *referto\_head = NULL;
  i = osip\_message\_header\_get\_byname (evt->sip, "refer-to", 0, \&referto\_head);
  if (referto\_head == NULL || referto\_head->hvalue == NULL)\end{alltt}
\normalsize 


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


The \doxyref{eXosip\_\-event}{p.}{structeXosip__event} also contains identifiers for calls, registrations, incoming subscriptions or outgoing subscriptions when applicable. Those identifiers are used in API to control calls, registrations, incoming or outgoing subscriptions. These API will build default messages with usual SIP headers (From, To, Call-ID, CSeq, Route, Record-Route, Max-Forward...) and send thoses messages for you.