随笔 - 272  文章 - 0  评论 - 283  阅读 - 142万

扩展Asterisk1.8.7的Dialplan Applications

我前面有一篇文章介绍了怎么扩展Asterisk 1.8.7CLI接口(http://www.cnblogs.com/MikeZhang/archive/2012/06/05/asterisk187CLIAddOns.html ),这里说说添加Dialplan Applications的方法。具体如下:

一、准备工作

1、进入之前建立的addons_test目录,建立app_testApp20120607.capp_testApp20120607.exports文件;

2、仿照app_testApp.c文件进行app_testApp20120607.c的编码,仿照app_testApp2.exports文件进行app_testApp20120607.exports的编码;

二、编码关键点

1、定义app名称为testApp20120607

2、功能处理函数:

AST_DECLARE_APP_ARGS函数和 AST_STANDARD_APP_ARGS函数
需要引入如下头文件:#include "asterisk/app.h"

3、核心代码:

复制代码
View Code
static int testApp_exec(struct ast_channel *chan, const char *data)
{
        ast_verb(2,"testApp_exec : %s\r\n",data);

        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(par1);
                AST_APP_ARG(par2);
        );

        char *parse;
        if (ast_strlen_zero(data))
        {
                ast_log(LOG_WARNING, "testApp20120607 requires an argument (data)\n");
                return -1;
        }
        parse = ast_strdupa(data);
        AST_STANDARD_APP_ARGS(args, parse);

        ast_verb(2,"testApp_exec : par1 = %s\r\n",args.par1);
        ast_verb(2,"testApp_exec : par2 = %s\r\n",args.par2);

        return 0;
}
复制代码

 三、测试

1、在拨号方案中调用

vi /etc/asterisk/extensions.conf

在拨号方案中添加如下调用:

exten => _X.,1,testApp20120607(${EXTEN},"Just a test")

2、用呼叫进行触发

1003呼叫1100,会有如下效果:

说明:

这只是在CLI调用程序上增加了接口,我们通过CLI接口也可以使用: 

posted on   Mike_Zhang  阅读(1404)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
< 2012年6月 >
27 28 29 30 31 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
1 2 3 4 5 6 7

点击右上角即可分享
微信分享提示