Download presentation
Published byMonica Hicks Modified over 9 years ago
1
李思銳 voip_taiwan@yahoo.com.tw
libosip2 / libexosip 李思銳
2
大綱 編譯libosip2 Description Features src directory
3
編譯libosip2 # tar xvfz libosip2-2.2.1.tar.gz # cd libosip2-2.2.1
# ./configure # make # make install
4
Description The GNU oSIP library is an implementation of SIP - rfc3261
5
Features SIP parser 1. SIP header parser 2. SDP parser
SIP transaction state machines 1. ICT : Invite Client Transaction 2. NICT: Non Invite Client Transaction 3. IST : Invite Server Transaction 4. NIST: Non Invite Server Transaction
6
src directory src/osip2 SIP transaction state machines
src/osipparser2 SIP parser src/test test programs
7
大綱 - How-To initialize libosip2
Allocate an osip_t element Register the callback used to send SIP message Set a callback for transaction operation related to the end of transactions
8
Set a callback for each transaction operation related to network error
9
Allocate an osip_t element
#include <sys/time.h> #include <osip2/osip.h> int i; osip_t *osip; i=osip_init(&osip); if (i!=0) return -1;
10
Register the callback used to send SIP message
osip_set_cb_send_message(osip, &cb_udp_snd_message);
11
Set a callback for transaction operation related to the end of transactions
osip_set_kill_transaction_callback(osip, OSIP_ICT_KILL_TRANSACTION, &cb_ict_kill_transaction); osip_set_kill_transaction_callback(osip, OSIP_IST_KILL_TRANSACTION, &cb_ist_kill_transaction);
12
osip_set_kill_transaction_callback(osip, OSIP_NICT_KILL_TRANSACTION, &cb_nict_kill_transaction);
osip_set_kill_transaction_callback(osip, OSIP_NIST_KILL_TRANSACTION, &cb_nist_kill_transaction);
13
Set a callback for each transaction operation related to network error
osip_set_transport_error_callback(osip, OSIP_ICT_TRANSPORT_ERROR, &cb_transport_error); osip_set_transport_error_callback(osip, OSIP_IST_TRANSPORT_ERROR, &cb_transport_error);
14
osip_set_transport_error_callback(osip, OSIP_NICT_TRANSPORT_ERROR, &cb_transport_error);
osip_set_transport_error_callback(osip, OSIP_NIST_TRANSPORT_ERROR, &cb_transport_error);
15
Set a callback for each transaction operation
osip_set_message_callback(osip, OSIP_ICT_STATUS_1XX_RECEIVED, &cb_rcv1xx); osip_set_message_callback(osip, OSIP_ICT_STATUS_2XX_RECEIVED, &cb_rcv2xx);
16
osip_set_message_callback(osip, OSIP_ICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
17
osip_set_message_callback(osip, OSIP_ICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
18
osip_set_message_callback(osip, OSIP_NICT_STATUS_1XX_RECEIVED, &cb_rcv1xx);
19
osip_set_message_callback(osip, OSIP_NICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
20
osip_set_message_callback(osip, OSIP_NICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
21
osip_set_message_callback(osip, OSIP_IST_INVITE_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_IST_ACK_RECEIVED, &cb_rcvreq);
22
osip_set_message_callback(osip, OSIP_NIST_REGISTER_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_NIST_BYE_RECEIVED, &cb_rcvreq);
23
osip_set_message_callback(osip, OSIP_NIST_CANCEL_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_NIST_UNKNOWN_REQUEST_RECEIVED, &cb_rcvreq);
24
大綱 - How-To parse URI Allocate/Free/Parse a header element
Get a string representation of a header element Parse Via header, for example
25
Allocate/Free/Parse a header element
osip_xxx_init(osip_xxx_t **header); osip_xxx_free(osip_xxx_t *header); osip_xxx_parse(osip_xxx_t *header, char *buffer);
26
Get a string representation of a header element
osip_xxx_to_str(osip_xxx_t *header, char **dest);
27
Parse Via header, for example
osip_via_t *via; char *a_via; char *dest; osip_via_init(&via); osip_via_parse(via, a_via); osip_via_to_str(via, &dest); osip_via_free(via);
28
大綱 - How-To parse SIP message
Parse a given buffer containing a sip request or response Convert the message into a printable string
29
Parse a given buffer containing a sip request or response
osip_message_t *sip; osip_message_init(&sip); osip_message_parse(sip, msg, strlen(msg); osip_message_free(sip);
30
Convert the message into a printable string
char *dest; size_t length; osip_message_to_str(sip, &result, &length); osip_free(dest);
31
大綱 - How-To use the sdp negotiator
How-to initialize the SDP negotiator How-to add support for medias
32
How-to initialize the SDP negotiator
struct osip_rfc3264 *cnf; osip_rfc3264_init(&cnf);
33
How-to add support for medias
sdp_media_t *med; sdp_attribute_t *attr; sdp_media_init(&med); med->m_proto = strdup("RTP/AVP"); osip_list_add(med->m_payloads, tmp, -1);
34
sdp_attribute_init(&attr);
attr->a_att_field = strdup("rtpmap"); attr->a_att_value = strdup("0 PCMU/8000"); osip_list_add(med->a_attributes, attr, -1); osip_rfc3264_add_audio_media(cnf, med, -1);
35
大綱 編譯libexosip Configure option Description Features
36
編譯libexosip # tar xvfz libeXosip-0.9.0.tar.gz # cd libeXosip-0.9.0
# ./configure # make # make install
37
Configure option --disable-phapi --disable-miniua --disable-josua
--disable-glib
38
--disable-ms --disable-ortp --disable-gsm --disable-ilbc
39
Description eXosip is a GPL library that extend the capability of the oSIP library It aims to implement a simple high layer API to control the SIP for sessions establishements and common extensions
40
Features rfc3261: SIP rfcxxxx: MESSAGE request rfcxxxx: SIMPLE support
41
大綱 - How-To initialize libexosip
Initiate the eXtented oSIP library Force eXosip to use a specific local ip address in all its SIP message Set the SIP User-Agent: header string Release ressource used by the eXtented oSIP library
42
Initiate the eXtented oSIP library
int eXosip_init(FILE *input, FILE *output, int port); eXosip_init(NULL, NULL, 5060);
43
Force eXosip to use a specific local ip address in all its SIP message
int eXosip_force_localip(const char *localip); eXosip_force_localip(“ ”);
44
Set the SIP User-Agent: header string
void eXosip_set_user_agent(const char *user_agent); eXosip_set_user_agent(“mysip”);
45
Release ressource used by the eXtented oSIP library
void eXosip_quit(void);
46
大綱 – How to Process Event
Wait for an eXosip event Free ressource in an eXosip event eXosip event Management
47
Wait for an eXosip event
eXosip_event_t *eXosip_event_wait(int tv_s, int tv_ms); eXosip_event_t *event; event = eXosip_event_wait(0, 0);
48
Free ressource in an eXosip event
void eXosip_event_free(eXosip_event_t *je); eXosip_event_free(event);
49
eXosip event Management
switch(event->type) Registration Info UAC events UAS events both UAS & UAC events
50
Registration Info EXOSIP_REGISTRATION_NEW EXOSIP_REGISTRATION_SUCCESS
EXOSIP_REGISTRATION_FAILURE EXOSIP_REGISTRATION_REFRESHED EXOSIP_REGISTRATION_TERMINATED
51
UAC events EXOSIP_CALL_NOANSWER EXOSIP_CALL_PROCEEDING
EXOSIP_CALL_RINGING EXOSIP_CALL_ANSWERED EXOSIP_CALL_REDIRECTED EXOSIP_CALL_REQUESTFAILURE EXOSIP_CALL_SERVERFAILURE EXOSIP_CALL_GLOBALFAILURE
52
UAS events EXOSIP_CALL_NEW EXOSIP_CALL_ACK EXOSIP_CALL_CANCELLED
EXOSIP_CALL_TIMEOUT EXOSIP_CALL_HOLD EXOSIP_CALL_OFFHOLD EXOSIP_CALL_CLOSED
53
both UAS & UAC events EXOSIP_CALL_STARTAUDIO EXOSIP_CALL_RELEASED
54
大綱 – Sample Programs sip_reg testing Modify sip_call Compile sip_call
sip_call testing
55
sip_reg testing # sip_reg \ -r sip:aaa.bbb.ccc.ddd \ -u \ -c \ -p U P 1000 –d
56
Modify sip_call modify include header change getch() to be getchar()
57
Include header #include <stdio.h> #include <stdlib.h>
#include <unistd.h> #include <netdb.h> #include <syslog.h> #include <pthread.h>
58
_getch() getchar() //if ( _kbhit() ) //switch ( _getch() )
switch ( getchar() )
59
Compile sip_call # g++ \ -losip2 -losipparser2 -leXosip \ -o sip_call sip_call.cxx Link error?
60
sip_call testing eXosip_build_initial_invite( osip_message_t **invite, char *to, char *from, char *route, char *subject);
61
a - answering call h - hangup r - ringing c - call q - quit
62
作業 整合sip_reg和sip_call兩個demo程式 修正sip_call程式的bug, 例如無法掛斷的問題等
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.