1How-To initialize libeXosip2.(3)  libeXosip2  How-To initialize libeXosip2.(3)
2
3
4

NAME

6       How-To initialize libeXosip2. - When using eXosip, your first task is
7       to initialize both eXosip context and libosip library (parser and state
8       machines). This must be done prior to any use of libeXosip2.
9
10            include <eXosip2/eXosip.h>
11
12            int i;
13
14            TRACE_INITIALIZE (6, stdout);
15
16            i=eXosip_init();
17            if (i!=0)
18              return -1;
19
20            i = eXosip_listen_addr (IPPROTO_UDP, NULL, port, AF_INET, 0);
21            if (i!=0)
22              {
23                eXosip_quit();
24                fprintf (stderr, 'could not initialize transport layer\n');
25                return -1;
26              }
27
28            ... then you have to send messages and wait for eXosip events...
29
30       In the previous code, you've learned how to:
31
32       · Initialize the osip trace (compile this code with -DENABLE_TRACE)
33       · Initialize eXosip (and osip) stack
34       · Open a socket for signalling (only UDP with initial eXosip2 version)
35       Now you have to handle eXosip events. Here is some code to get
36       eXosip_event from the eXosip2 stack.
37         eXosip_event_t *je;
38         for (;;)
39           {
40             je = eXosip_event_wait (0, 50);
41             eXosip_lock();
42             eXosip_automatic_action ();
43             eXosip_unlock();
44             if (je == NULL)
45               break;
46             if (je->type == EXOSIP_CALL_NEW)
47               {
48               ....
49               ....
50               }
51             else if (je->type == EXOSIP_CALL_ACK)
52               {
53               ....
54               ....
55               }
56             else if (je->type == EXOSIP_CALL_ANSWERED)
57               {
58               ....
59               ....
60               }
61             else .....
62             ....
63             ....
64             eXosip_event_free(je);
65           }
66       You will receive one event for each SIP message sent. Each event
67       contains the original request of the affected transaction and the last
68       response that triggers the event when available.
69       You can access all headers from those messages and store them in your
70       own context for other actions or graphic displays.
71       For example, when you receive a REFER request for a call transfer,
72       you'll typically retreive the 'refer-To' header:
73         osip_header_t *referto_head = NULL;
74         i = osip_message_header_get_byname (evt->sip, 'refer-to', 0, &referto_head);
75         if (referto_head == NULL || referto_head->hvalue == NULL)
76       The eXosip_event also contains identifiers for calls, registrations,
77       incoming subscriptions or outgoing subscriptions when applicable. Those
78       identifiers are used in API to control calls, registrations, incoming
79       or outgoing subscriptions. These API will build default messages with
80       usual SIP headers (From, To, Call-ID, CSeq, Route, Record-Route, Max-
81       Forward...) and send thoses messages for you.
82
83
84
85Version 3.0.1                     30 Aug 2007 How-To initialize libeXosip2.(3)
Impressum