Freeswitch kernel-based SIP module

Source: Internet
Author: User
Tags freeswitch

 

I created a freeswitch kernel research and exchange group,45211986. welcome to join us. In addition, we accept the SIP-based communication server and client solutions. 

Freeswitch supports cross-platform, and the underlying library uses Apache Portable Runtime lib (APR). The author has been familiar with Apache in his previous work.
 
In swith_apr.c, all the tool library interface functions provided by APR are referenced by freeswitch for the purpose of unification.

 
When the communication layer uses the SIP protocol, the mod_sofia module is used. This module is the access portal for the Nokia Open-Source SIP protocol stack Sofia sip,
Mod_sofia is the driver entry after kernel startup.
The SIP module is in the mod_sofia.c file.
Switch_module_load_function (name) is the entry for each module that can be loaded. When the system starts, it dynamically loads the configured module according to the module. xml configuration.
Macros related to dynamic module loading are defined in switch_types.h. Each module defines the module loading, running, and removing the corresponding callback.

Switch_module_load_function
Switch_module_shutdown_function
Switch_module_definition

Therefore, the loading entry of the SIP module is in switch_module_load_function (mod_sofia_load)

Mod_sofia_globals structure to save the global configurations of the SIP runtime, first set some global configurations, and then enter
The config_sofia function parses the SIP configuration information.
First, parse the main configuration file of the SIP protocol stack, Sofia. conf.
<Configuration name = "Sofia. conf" Description = "Sofia endpoint">

<Global_settings>
<Param name = "log-level" value = "0"/>
<! -- <Param name = "auto-Restart" value = "false"/> -->
<Param name = "debug-presence" value = "0"/>
</Global_settings>

<! --
The rabbit hole goes deep. This includes des all
Profiles in the sip_profiles directory that is up
One level from this directory.
-->
<Profiles>
<X-PRE-PROCESS cmd = "include" Data = "../sip_profiles/*. xml"/> // use a preprocessing macro to include the configuration file
</Profiles>

</Configuration>
Sofia. conf consists of two parts:
1. Global configuration (global_settings)
2. SIP protocol stack profiles (Lan, Internet, Gateway configuration), all configuration files related to this are placed in the sip_profiles directory
UA = user agent = Sofia profile = sip profile in freeswitch
For security, freeswitch classifies UA by LAN (the client and server are in the same CIDR Block) and Internet.

After config_sofia parses the first part, start to parse the second part:
Parsing by the configuration files under the sip_profiles directory one by one:
Note that only the XML files under the sip_profiles directory will be parsed and will not be parsed recursively.
Each configuration file in this directory corresponds to a sofia_profile structure. Sofia_profile can be understood as a SIP UA
The files in this directory are divided into several fixed nodes:
1. settings node, which is the name value pair. Configure general attributes for this type of sip ua. Including settings of SIP and RTP attributes, such as whether to enable
SIP 100rel features, presence, etc. It is similar to the extension attribute concept in the Asterisk SIP. conf configuration file, but it is more detailed and flexible.

2. the gateways node, freeswitch, and SIP landing interface node. This node includes several configurations of the SIP landing gateway.
Call String Structure in dilplan:

Sofia/gateway/<gateway_name>/<dialstring>

A single gateway node contains the corresponding property configuration, such as the inbound gateway or outbound gateway, and the account registered with the gateway...
The parse_gateways function resolves the configuration of the gateway node. The sofia_reg_add_gateway function places this gateway in the freeswitch registration list (freeswitch acts
The client registers to the gateway ).

3. Domains node, which contains all extension nodes. Is the parent node of all extension nodes. the hierarchical structure is as follows:
Domains
Domain
Groups
Group
User

All users in the directory are parsed here.
 
4. aliases Node

After this type of SIP profile is parsed, launch_sofia_profile_thread starts a thread sofia_profile_thread_run to further set this profile.
The thread internally uses nua_create to create Sofia sip ua, and nua_create provides the API for Sofia SIP protocol stack. It is responsible for creating and starting a sip ua protocol stack,
Specify the Event Callback Function sofia_event_callback. The entry of all transport layer SIP messages is this function. All SIP protocol stack events are passed through sofia_event_callback
To mod_sofia.
Finally, start the worker thread sofia_profile_worker_thread_run to process the event queue of the sip ua.

For more in-depth analysis, go to nua_create to access the core of Sofia SIP protocol stack (create, initialize, and start ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.