李思銳 voip_taiwan@yahoo.com.tw libosip2 / libexosip 李思銳 voip_taiwan@yahoo.com.tw
大綱 編譯libosip2 Description Features src directory
編譯libosip2 # tar xvfz libosip2-2.2.1.tar.gz # cd libosip2-2.2.1 # ./configure # make # make install
Description The GNU oSIP library is an implementation of SIP - rfc3261 http://www.gnu.org/software/osip/osip.html
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
src directory src/osip2 SIP transaction state machines src/osipparser2 SIP parser src/test test programs
大綱 - 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
Set a callback for each transaction operation related to network error
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;
Register the callback used to send SIP message osip_set_cb_send_message(osip, &cb_udp_snd_message);
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);
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);
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);
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);
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);
osip_set_message_callback(osip, OSIP_ICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_ICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_NICT_STATUS_1XX_RECEIVED, &cb_rcv1xx);
osip_set_message_callback(osip, OSIP_NICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_NICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
osip_set_message_callback(osip, OSIP_IST_INVITE_RECEIVED, &cb_rcvreq); osip_set_message_callback(osip, OSIP_IST_ACK_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_NIST_REGISTER_RECEIVED, &cb_rcvreq); osip_set_message_callback(osip, OSIP_NIST_BYE_RECEIVED, &cb_rcvreq);
osip_set_message_callback(osip, OSIP_NIST_CANCEL_RECEIVED, &cb_rcvreq); osip_set_message_callback(osip, OSIP_NIST_UNKNOWN_REQUEST_RECEIVED, &cb_rcvreq);
大綱 - How-To parse URI Allocate/Free/Parse a header element Get a string representation of a header element Parse Via header, for example
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);
Get a string representation of a header element osip_xxx_to_str(osip_xxx_t *header, char **dest);
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);
大綱 - How-To parse SIP message Parse a given buffer containing a sip request or response Convert the message into a printable string
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);
Convert the message into a printable string char *dest; size_t length; osip_message_to_str(sip, &result, &length); osip_free(dest);
大綱 - How-To use the sdp negotiator How-to initialize the SDP negotiator How-to add support for medias
How-to initialize the SDP negotiator struct osip_rfc3264 *cnf; osip_rfc3264_init(&cnf);
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);
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);
大綱 編譯libexosip Configure option Description Features
編譯libexosip # tar xvfz libeXosip-0.9.0.tar.gz # cd libeXosip-0.9.0 # ./configure # make # make install
Configure option --disable-phapi --disable-miniua --disable-josua --disable-glib
--disable-ms --disable-ortp --disable-gsm --disable-ilbc
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/
Features rfc3261: SIP rfcxxxx: MESSAGE request rfcxxxx: SIMPLE support
大綱 - 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
Initiate the eXtented oSIP library int eXosip_init(FILE *input, FILE *output, int port); eXosip_init(NULL, NULL, 5060);
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”);
Set the SIP User-Agent: header string void eXosip_set_user_agent(const char *user_agent); eXosip_set_user_agent(“mysip”);
Release ressource used by the eXtented oSIP library void eXosip_quit(void);
大綱 – How to Process Event Wait for an eXosip event Free ressource in an eXosip event eXosip event Management
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);
Free ressource in an eXosip event void eXosip_event_free(eXosip_event_t *je); eXosip_event_free(event);
eXosip event Management switch(event->type) Registration Info UAC events UAS events both UAS & UAC events
Registration Info EXOSIP_REGISTRATION_NEW EXOSIP_REGISTRATION_SUCCESS EXOSIP_REGISTRATION_FAILURE EXOSIP_REGISTRATION_REFRESHED EXOSIP_REGISTRATION_TERMINATED
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
UAS events EXOSIP_CALL_NEW EXOSIP_CALL_ACK EXOSIP_CALL_CANCELLED EXOSIP_CALL_TIMEOUT EXOSIP_CALL_HOLD EXOSIP_CALL_OFFHOLD EXOSIP_CALL_CLOSED
both UAS & UAC events EXOSIP_CALL_STARTAUDIO EXOSIP_CALL_RELEASED
大綱 – Sample Programs sip_reg testing Modify sip_call Compile sip_call sip_call testing
sip_reg testing # sip_reg \ -r sip:aaa.bbb.ccc.ddd \ -u sip:1000@aaa.bbb.ccc.ddd \ -c sip:1000@aaa.bbb.ccc.ddd \ -p 5060 -U 1000 -P 1000 –d
Modify sip_call modify include header change getch() to be getchar()
Include header #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <netdb.h> #include <syslog.h> #include <pthread.h>
_getch() getchar() //if ( _kbhit() ) //switch ( _getch() ) switch ( getchar() )
Compile sip_call # g++ \ -losip2 -losipparser2 -leXosip \ -o sip_call sip_call.cxx Link error?
sip_call testing eXosip_build_initial_invite( osip_message_t **invite, char *to, char *from, char *route, char *subject);
a - answering call h - hangup r - ringing c - call q - quit
作業 整合sip_reg和sip_call兩個demo程式 修正sip_call程式的bug, 例如無法掛斷的問題等