The Beautiful Nature 13 大自然 13 All photos from // Edited by 李常生 [email protected]@yahoo.com.tw.
Libosip2 / libexosip 李思銳 [email protected].
-
Upload
monica-hicks -
Category
Documents
-
view
312 -
download
3
Transcript of Libosip2 / libexosip 李思銳 [email protected].
![Page 2: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/2.jpg)
大綱 編譯 libosip2 Description Features src directory
![Page 3: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/3.jpg)
編譯 libosip2
# tar xvfz libosip2-2.2.1.tar.gz # cd libosip2-2.2.1 # ./configure # make # make install
![Page 4: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/4.jpg)
Description
The GNU oSIP library is an implementation of SIP - rfc3261
http://www.gnu.org/software/osip/osip.html
![Page 5: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/5.jpg)
Features
SIP parser1. SIP header parser2. SDP parser
SIP transaction state machines1. ICT : Invite Client Transaction2. NICT: Non Invite Client Transaction3. IST : Invite Server Transaction4. NIST: Non Invite Server Transaction
![Page 6: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/6.jpg)
src directory
src/osip2SIP transaction state machines
src/osipparser2SIP parser
src/testtest programs
![Page 7: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/7.jpg)
大綱 - 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
![Page 8: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/8.jpg)
Set a callback for each transaction operation related to network error
Set a callback for each transaction operation
![Page 9: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/9.jpg)
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;
![Page 10: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/10.jpg)
Register the callback used to send SIP message
osip_set_cb_send_message(osip, &cb_udp_snd_message);
![Page 11: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/11.jpg)
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);
![Page 12: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/12.jpg)
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);
![Page 13: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/13.jpg)
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);
![Page 14: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/14.jpg)
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);
![Page 15: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/15.jpg)
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);
![Page 16: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/16.jpg)
osip_set_message_callback(osip, OSIP_ICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_ICT_STATUS_4XX_RECEIVED, &cb_rcv3456xx);
![Page 17: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/17.jpg)
osip_set_message_callback(osip, OSIP_ICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_ICT_STATUS_6XX_RECEIVED, &cb_rcv3456xx);
![Page 18: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/18.jpg)
osip_set_message_callback(osip, OSIP_NICT_STATUS_1XX_RECEIVED, &cb_rcv1xx);
osip_set_message_callback(osip, OSIP_NICT_STATUS_2XX_RECEIVED, &cb_rcv2xx);
![Page 19: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/19.jpg)
osip_set_message_callback(osip, OSIP_NICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_NICT_STATUS_4XX_RECEIVED, &cb_rcv3456xx);
![Page 20: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/20.jpg)
osip_set_message_callback(osip, OSIP_NICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_NICT_STATUS_6XX_RECEIVED, &cb_rcv3456xx);
![Page 21: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/21.jpg)
osip_set_message_callback(osip, OSIP_IST_INVITE_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_IST_ACK_RECEIVED, &cb_rcvreq);
![Page 22: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/22.jpg)
osip_set_message_callback(osip, OSIP_NIST_REGISTER_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_NIST_BYE_RECEIVED, &cb_rcvreq);
![Page 23: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/23.jpg)
osip_set_message_callback(osip, OSIP_NIST_CANCEL_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_NIST_UNKNOWN_REQUEST_RECEIVED, &cb_rcvreq);
![Page 24: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/24.jpg)
大綱 - How-To parse URI
Allocate/Free/Parse a header element Get a string representation of a header
element Parse Via header, for example
![Page 25: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/25.jpg)
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);
![Page 26: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/26.jpg)
Get a string representation of a header element
osip_xxx_to_str(osip_xxx_t *header, char **dest);
![Page 27: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/27.jpg)
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);
![Page 28: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/28.jpg)
大綱 - How-To parse SIP message
Parse a given buffer containing a sip request or response
Convert the message into a printable string
![Page 29: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/29.jpg)
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);
![Page 30: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/30.jpg)
Convert the message into a printable string
char *dest; size_t length; osip_message_to_str(sip, &result,
&length); osip_free(dest);
![Page 31: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/31.jpg)
大綱 - How-To use the sdp negotiator
How-to initialize the SDP negotiator How-to add support for medias
![Page 32: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/32.jpg)
How-to initialize the SDP negotiator
struct osip_rfc3264 *cnf; osip_rfc3264_init(&cnf);
![Page 33: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/33.jpg)
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);
![Page 34: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/34.jpg)
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);
![Page 35: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/35.jpg)
大綱 編譯 libexosip Configure option Description Features
![Page 36: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/36.jpg)
編譯 libexosip
# tar xvfz libeXosip-0.9.0.tar.gz # cd libeXosip-0.9.0 # ./configure # make # make install
![Page 37: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/37.jpg)
Configure option
--disable-phapi --disable-miniua --disable-josua --disable-glib
![Page 38: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/38.jpg)
--disable-ms --disable-ortp --disable-gsm --disable-ilbc
![Page 39: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/39.jpg)
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
http://savannah.gnu.org/projects/exosip/
![Page 40: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/40.jpg)
Features
rfc3261: SIP rfcxxxx: MESSAGE request rfcxxxx: SIMPLE support
![Page 41: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/41.jpg)
大綱 - 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
![Page 42: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/42.jpg)
Initiate the eXtented oSIP library
int eXosip_init(FILE *input, FILE *output, int port);
eXosip_init(NULL, NULL, 5060);
![Page 43: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/43.jpg)
Force eXosip to use a specific local ip address in all its SIP message
int eXosip_force_localip(const char *localip);
eXosip_force_localip(“127.0.0.1”);
![Page 44: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/44.jpg)
Set the SIP User-Agent: header string
void eXosip_set_user_agent(const char *user_agent);
eXosip_set_user_agent(“mysip”);
![Page 45: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/45.jpg)
Release ressource used by the eXtented oSIP library
void eXosip_quit(void);
![Page 46: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/46.jpg)
大綱 – How to Process Event
Wait for an eXosip event Free ressource in an eXosip event eXosip event Management
![Page 47: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/47.jpg)
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);
![Page 48: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/48.jpg)
Free ressource in an eXosip event
void eXosip_event_free(eXosip_event_t *je);
eXosip_event_free(event);
![Page 49: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/49.jpg)
eXosip event Management
switch(event->type) Registration Info UAC events UAS events both UAS & UAC events
![Page 50: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/50.jpg)
Registration Info
EXOSIP_REGISTRATION_NEW EXOSIP_REGISTRATION_SUCCESS EXOSIP_REGISTRATION_FAILURE EXOSIP_REGISTRATION_REFRESHED EXOSIP_REGISTRATION_TERMINATED
![Page 51: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/51.jpg)
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
![Page 52: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/52.jpg)
UAS events
EXOSIP_CALL_NEW EXOSIP_CALL_ACK EXOSIP_CALL_CANCELLED EXOSIP_CALL_TIMEOUT EXOSIP_CALL_HOLD EXOSIP_CALL_OFFHOLD EXOSIP_CALL_CLOSED
![Page 53: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/53.jpg)
both UAS & UAC events
EXOSIP_CALL_STARTAUDIO EXOSIP_CALL_RELEASED
![Page 54: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/54.jpg)
大綱 – Sample Programs
sip_reg testing Modify sip_call Compile sip_call sip_call testing
![Page 55: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/55.jpg)
sip_reg testing
# sip_reg \-r sip:aaa.bbb.ccc.ddd \-u sip:[email protected] \-c sip:[email protected] \-p 5060 -U 1000 -P 1000 –d
![Page 56: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/56.jpg)
Modify sip_call
modify include header change getch() to be getchar()
![Page 57: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/57.jpg)
Include header
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <netdb.h> #include <syslog.h> #include <pthread.h>
![Page 58: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/58.jpg)
_getch() getchar()
//if ( _kbhit() ) //switch ( _getch() ) switch ( getchar() )
![Page 59: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/59.jpg)
Compile sip_call
# g++ \-losip2 -losipparser2 -leXosip \-o sip_call sip_call.cxx
Link error?
![Page 60: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/60.jpg)
sip_call testing
eXosip_build_initial_invite( osip_message_t **invite, char *to, char *from, char *route, char *subject);
![Page 61: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/61.jpg)
a - answering call h - hangup r - ringing c - call q - quit
![Page 62: Libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw.](https://reader036.fdocuments.net/reader036/viewer/2022081416/56649e255503460f94b13b09/html5/thumbnails/62.jpg)
作業 整合 sip_reg 和 sip_call 兩個 demo 程式 修正 sip_call 程式的 bug, 例如無法掛斷
的問題等