• OpenSIPS配置脚本结构-》opensips.cfg


    OpenSIPs 的配置文件一般命名为opensips.cfg,它是一个自定义的类C风格的脚本。逻辑上,一般把脚本划分为三个部分:

    全局变量
    模块描述
    路由逻辑

    下面是一个简单的实例:

    #######	Global	Parameters	#########	
    debug=3	
    log_stderror=no	
    fork=yes	
    children=4	
    listen=udp:127.0.0.1:5060
     
     
    #######	Modules	Section	########	
    mpath="/usr/local/lib/opensips/modules/"	
    loadmodule	"signaling.so"	
    loadmodule	"sl.so"	
    loadmodule	"tm.so"	
    loadmodule	"rr.so"
    loadmodule	"uri.so"
    loadmodule	"sipmsgops.so"
    modparam("rr",	"append_fromtag",	0)	
     
     
    #######	Routing	Logic	########	
    route{	
    		if	(	has_totag()	)	{	
    				loose_route();					route(relay);	
    		}	
    		if	(	from_uri!=myself	&&	uri!=myself	)	{	
    				send_reply("403","Rely	forbidden");	
    				exit;	
    		}	
    		record_route();	
    		route(relay);	
    }	
    route[relay]	{	
    		if	(is_method("INVITE"))	
    				t_on_failure("missed_call");	
    		t_relay();	
    		exit;	
    }	
    failure_route[missed_call]	{	
    		if	(t_check_status("486"))	{	
    				$rd	=	"127.0.0.10";	
    				t_relay();	
    		}	
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    全局变量

    配置脚本的第一部分,通常是定义一些全局变量。这些变量配置OpenSIPS内核参数,也可能影响到一些潜在的模块。

    通常,这部分内容要配置监听端口,传输协议,工作进程数,日志等级等等。

    #######	Global	Parameters	#########	
    debug=3	
    log_stderror=no	
    fork=yes	
    children=4	
    listen=udp:127.0.0.1:5060
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    模块描述

    对于OpenSIPS来说,缺省是不加载外围模块的。用到具体模块时,需要在脚本里调用loadmodule加载。加载的模块通过模块名指定,可以加上路径描述。如果没有指定路径(只指定模块名),那么会到缺省路径(如果编译时没有指定,那么默认路径是/usr/lib/opensips/modules )中去查找。要配置新的路径,可以直接在模块名字前加路径,也可以配置全局变量mpath 。

    加载模块时,可以用modparam 来配置模块的参数。模块的具体可配置参数可以查询模块的文档。

    #######	Modules	Section	########	
    mpath="/usr/local/lib/opensips/modules/"	
    loadmodule	"signaling.so"	
    loadmodule	"sl.so"	
    loadmodule	"tm.so"	
    loadmodule	"rr.so"
    loadmodule	"uri.so"
    loadmodule	"sipmsgops.so"
    modparam("rr",	"append_fromtag",	0)	
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    路由逻辑

    路由逻辑实际上就是一些控制路由的脚本。OpenSIPS与SIP流量相关的所有行为都通过路由逻辑脚本来控制。

    路由分为两种类型:

    1、top routes顶层路由 - 由OpenSIPs 直接触发的路由(比如说收到SIP请求、应答,或者事务处理失败)

    2、sub-routes子路由 - 由顶层路由脚本触发的路由集

    OpenSIPS定义了几种不同的顶层路由 ,它们各有自己的触发点,允许的操作集也不同。子路由通过脚本中定义的名字调用。

    #######	Routing	Logic	########	
    route{	
    		if	(	has_totag()	)	{	
    				loose_route();					route(relay);	
    		}	
    		if	(	from_uri!=myself	&&	uri!=myself	)	{	
    				send_reply("403","Rely	forbidden");	
    				exit;	
    		}	
    		record_route();	
    		route(relay);	
    }	
    route[relay]	{	
    		if	(is_method("INVITE"))	
    				t_on_failure("missed_call");	
    		t_relay();	
    		exit;	
    }	
    failure_route[missed_call]	{	
    		if	(t_check_status("486"))	{	
    				$rd	=	"127.0.0.10";	
    				t_relay();	
    		}	
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
  • 相关阅读:
    Primer笔记——显式转换、返回数组指针的函数、const形参函数重载
    Ollama--本地大语言模型LLM运行专家
    AI生成PPT:如何轻松制作专业的答辩PPT?
    使用 Fody 实现 .NET 的静态织入
    闲活章始:初创纪元
    PostgreSQL 和 MySQL 在用途、好处、特性和特点上的异同
    qlib自动化quant
    C++ 数据类型学习资料
    Python Selenium Headless:以 Headless 模式打开 Chrome 浏览器
    线程和线程池
  • 原文地址:https://blog.csdn.net/nb_zsy/article/details/132737631