织梦CMS - 轻松建站从此开始!

罗索

Osip/eXosip Source Code Analysis

落鹤生 发布于 2011-05-13 09:25 点击:次 
It implements transaction layer which is defined by RFC3261.call osip_init to init the osip library. create transport layer to handle the outgoing and incoming messages.
TAG:

1.1 How to use osip

call osip_init to init the osip library

create transport layer to handle the outgoing and incoming messages.

1.2 osip internal

It implements transaction layer which is defined by RFC3261

osip structure

struct osip

  {

    /* list of transactions for ict, ist, nict, nist */

    osip_list_t *osip_ict_transactions;   /**< list of ict transactions */

    osip_list_t *osip_ist_transactions;   /**< list of ist transactions */

    osip_list_t *osip_nict_transactions;  /**< list of nict transactions */

    osip_list_t *osip_nist_transactions;  /**< list of nist transactions */

osip_list_t *ixt_retransmissions;    /**< list of ixt elements */

 

osip_message_cb_t msg_callbacks[OSIP_MESSAGE_CALLBACK_COUNT];

osip_kill_transaction_cb_t kill_callbacks[OSIP_KILL_CALLBACK_COUNT];

osip_transport_error_cb_t    

         tp_error_callbacks[OSIP_TRANSPORT_ERROR_CALLBACK_COUNT]; 

    int (*cb_send_message) (osip_transaction_t *, osip_message_t *, char *,

                            int, int);

  };

Transaction type:

    ICT, /**< Invite Client (outgoing) Transaction */

    IST, /**< Invite Server (incoming) Transaction */

    NICT,/**< Non-Invite Client (outgoing) Transaction */

    NIST /**< Non-Invite Server (incoming) Transaction */

Events:

    RCV_REQINVITE,    /**< Event is an incoming INVITE request */

    RCV_REQACK,       /**< Event is an incoming ACK request */

    RCV_REQUEST,      /**< Event is an incoming NON-INVITE and NON-ACK request */

    RCV_STATUS_1XX,   /**< Event is an incoming informational response */

    RCV_STATUS_2XX,   /**< Event is an incoming 2XX response */

    RCV_STATUS_3456XX,/**< Event is an incoming final response (not 2XX) */

 

    /* FOR OUTGOING MESSAGE */

    SND_REQINVITE,    /**< Event is an outgoing INVITE request */

    SND_REQACK,       /**< Event is an outgoing ACK request */

    SND_REQUEST,      /**< Event is an outgoing NON-INVITE and NON-ACK request */

    SND_STATUS_1XX,   /**< Event is an outgoing informational response */

    SND_STATUS_2XX,   /**< Event is an outgoing 2XX response */

    SND_STATUS_3456XX,/**< Event is an outgoing final response (not 2XX) */

 

KILL_TRANSACTION, /**< Event to 'kill' the transaction before termination */

/* other timer event not listed here*/

Callback:

There are four kinds of callbacks upper layer need to set for osip library:

osip_message_cb_t msg_callbacks[OSIP_MESSAGE_CALLBACK_COUNT];       

            Osip lib will call message callbacks to notify upper layer some information

osip_kill_transaction_cb_t kill_callbacks[OSIP_KILL_CALLBACK_COUNT];

            Osip lib will call these callbacks when a transaction is finished.

osip_transport_error_cb_t tp_error_callbacks[OSIP_TRANSPORT_ERROR_CALLBACK_COUNT]; 

            Osip lib will call these callbacks when the transport layer meet error.

int (*cb_send_message) (osip_transaction_t *, osip_message_t *, char *,

                            int, int);

            Osip lib will call this callback to do the real transportation of the message.

eXosip set these callbacks in eXosip_set_callbacks.

 

osip_init

init 4 types of transaction state machine:

set transition_t list:

typedef struct _transition_t

{

  state_t state;

  type_t type;

  void (*method) (void *, void *);

}

transition_t;

It set the process method for a type of event in a type of state

for example, in __ict_load_fsm ():

transition = (transition_t *) osip_malloc (sizeof (transition_t));

  transition->state = ICT_PRE_CALLING;

  transition->type = SND_REQINVITE;

  transition->method = (void (*)(void *, void *)) &ict_snd_invite;

  osip_list_add (ict_fsm->transitions, transition, -1);

 

How to process the SIP message

TU calls some functions to queue osip_event to the fifo of the transaction.

TU calls funtions, such as osip_ict_execute, which calls osip_transaction_execute to handle the osip_event in fifo:

            osip_transaction_execute first find the type of event, and then get that type of fsm, and then call fsm_callmethod

            fsm_callmethod will find the transition according to event type and transaction state, and the call transition->method

2 eXosip Overview

2.1 How to use eXosip lib

call eXosip and eXosip_listen_addr

poll the event periodly

2.2 eXosip lib internal:

It’s based on osip lib. It implements transport layer which is defined by RFC3261

The eXosip doesn’t wrapp the osip library. It just provides a transport layer for supporting message transfer.

 

eXosip_t structure

struct eXosip_t

  {

    struct eXosip_net net_interfaces[3];

     osip_list_t *j_transactions;

    osip_t *j_osip;

    int j_stop_ua;

    void *j_thread;

    jpipe_t *j_socketctl; // to notify an request from upper layer is queued to fifo of transaction

    jpipe_t *j_socketctl_event; //to notify event to upper layer

 

    osip_fifo_t *j_events; //save event which will be sent to upper layer

  };

 

eXosip_init:

init the struct eXosip

call osip_init to init the struct osip which is a member of eXosip(eXosip.j_osip

set osip lib callback: eXosip_set_callbacks (osip):

            cb_snd_message is most important callback

create two pipe(eXosip.j_socketctl and eXosip.j_socketctl_event)

init fifo: osip_fifo_init(eXosip.j_events)

j_stop_ua is used to indicate whether thread should be stopped (used in _eXosip_thread)

 

eXosip_listen_addr:

listen on a port for SIP message

call _eXosip_thread

 

_eXosip_thread:

            eXosip_read_message use select to wait for the message from upper layer or network

            call osip_timers_ict_execute, osip_timers_nict_execute  osip_timers_ist_execute and  osip_timers_nist_execute to handle transaction timeout

            call  osip_ict_execute ,osip_nict_execute, osip_ist_execute and osip_nist_execute to handle the event in transaction FIFO

 

eXosip_process_newrequest is used to init UAS transaction

(eXosip_call_send_initial_invite is used to init UAC transaction)

 

for outgoing message:

build SIP message, put to the transaction fifo by calling OSIP API

then write something to pipe to notify _eXosip_thread to handle transaction

 

for incoming message:

_eXosip_thread is listening to the incoming socket, if there is a incoming message,

the _eXosip_thread will be waken up to create a new transaction, and handle transaction.

 

3 The process to send an outgoing message (zblue78)

本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201105/11670.html]
本文出处:CSDN博客 作者:zblue78
顶一下
(1)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容