How-to: Write an Asterisk Module, Part 3

Greetings fellow developers!

This is part 3 of a series on implementing the basic interfaces to provide features to Asterisk.

Part 1 – Basic Module Structure
Part 2 – CDR Handling Interface

In this section, you will see how to implement an Asterisk CLI command. CLI commands are extremely useful for showing configuration, statistics, and other debugging purposes.

We are going to continue editing the module from part 2, res_helloworld2.c.

The first step is to include the header file which defines the CLI command interface.

#include "asterisk/cli.h"

Here is the code for a CLI command, “echo”. It simply prints back the first argument to the CLI command. The individual parts of this function will be described later.

static char *handle_cli_echo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
    switch (cmd) {
    case CLI_INIT:
        e->command = "echo";
        e->usage =
            "Usage: echo <stuff>\n"
            "       Print back the first argument.\n"
            "Examples:\n"
            "       echo foo\n"
            "       echo \"multiple words\"\n"
            "";
        return NULL;
    case CLI_GENERATE:
        return NULL;
    }

    if (a->argc == e->args) {
        ast_cli(a->fd, "You did not provide an argument to echo\n\n");
        return CLI_SHOWUSAGE;
    }

    ast_cli(a->fd, "%s\n", a->argv[1]);

    return CLI_SUCCESS;
}

The first line of this CLI handler matches the defined function prototype for CLI command handlers. The ast_cli_entry argument includes static information about the CLI command being executed. The cmd argument is set when the CLI command is being invoked for a reason other than normal execution from the CLI, which will be explained more later. The ast_cli_args argument contains information specific to this one time execution of the command, like the arguments to the command.

static char *handle_cli_echo(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

The switch statement at the beginning of the function handles when the cmd argument is set to indicate that the function is being called for a reason other than normal execution. There are two cases handled.

  • CLI_INIT. Every CLI command handler is called one time with a cmd of CLI_INIT. This asks the function to fill in the documentation on what the command is, as well as usage documentation.
  • CLI_GENERATE. This cmd is used for implementing tab completion. CLI commands that provide tab completion of arguments must add code here. Implementing tab completion may be explained in a later tutorial. For now, there are many examples throughout the code.

The next code snippet ensures that at least one argument has been provided to the function. It is worth noting here that the ast_cli_entry argument is used to retrieve how many arguments define the command itself and the ast_cli_args argument is used to retrieve how many arguments were actually specified at the CLI when executing this command. If they are equal, then simply “echo” was provided.

if (a->argc == e->args) {
ast_cli(a->fd, "You did not provide an argument to echo\n\n");
return CLI_SHOWUSAGE;
}

Finally, we print a single argument to the CLI, and return that the execution of the CLI command was successful.

ast_cli(a->fd, "%s\n", a->argv[1]);
return CLI_SUCCESS;

The next thing that we have to add is the table of CLI commands included in this module. We will use AST_CLI_DEFINE() to add a single entry to this table. AST_CLI_DEFINE includes the pointer to the CLI command handling function, as well as a brief summary of what the command does.

static struct ast_cli_entry cli_helloworld[] = {
AST_CLI_DEFINE(handle_cli_echo, "Echo to the CLI"),
};

Finally, as discussed in part 2, we have to modify load_module and unload_module to register and unregister the CLI command table with the Asterisk core.

In unload_module, we add this:

ast_cli_unregister_multiple(cli_helloworld, ARRAY_LEN(cli_helloworld));

In load_module, we add this:

ast_cli_register_multiple(cli_helloworld, ARRAY_LEN(cli_helloworld));

That’s it! Recompile and reinstall the module. Take a look at res_helloworld3.c, for the completed code.

You can then try it out.

*CLI> help echo
Usage: echo 
       Print back the first argument.
Examples:
       echo foo
       echo "multiple words"

*CLI> echo
You did not provide an argument to echo

Usage: echo 
       Print back the first argument.
Examples:
       echo foo
       echo "multiple words"

*CLI> echo foo
foo

*CLI> echo hello world
hello

*CLI> echo "hello world"
hello world
soapui_part1 SoapUI是一个开源测试工具,通过soap/http来检查、调用、实现Web Service的功能/负载/符合性测试。该工具既可作为一个单独的测试软件使用,也可利用插件集成到Eclipse,maven2.X,Netbeans 和intellij中使用 立即下载

相关推荐

基于单片机控制的开关电源设计

采用开关电源技术和MCU模块,凭借可靠性高、易于调适的特点,可以更高效地发挥出二者的优势,从而实现更好的组合。stm32的起动模式是通过Boot0和Boot1两个管脚的高低电平来决定的,当stm32被供电之后,这两个管脚的电平。在 VCC上,键盘的一头(列线)被连接到 VCC上,而在“0”的编程输出中,则用来进。,在开关管打开的情况下,由输入电力供给电流,感应装置存储   Buck变换器是一种非隔离式的电压转换器[10]整流电路对输入电压进行整流,再经过滤波电路,即Dc电压是直流/直流变换器的直流输入。

QQ1694456187的博客 2315

Cannot write part return. RPC/Literal parts cannot be null. (WS-I BP R2211)

这是问题是CXF客户端调用时,出现的错误: org.apache.cxf.interceptor.Fault: Cannot write part return. RPC/Literal parts cannot be null. (WS-I BP R2211) 这个不难看出,参数不

站在技术的边缘,遥望你 9583

协方差矩阵

对两个类内协方差矩阵进行对角化,可以将它们变换为对角矩阵。这个过程可以通过对每个协方差矩阵进行特征值分解来实现,从而得到它们的特征向量和特征值,进而得到它们的对角矩阵形式。这个过程的意义在于,它可以帮助我们找到一个新的坐标系,使得在这个坐标系下,每个特征之间都是独立的,从而简化了计算。具体来说,当我们使用对角协方差矩阵作为特征向量的坐标系时,它意味着每个特征之间都是相互独立的,从而方便了进一步的分析和处理。在实际应用中,对角化协方差矩阵可以用于降维、特征选择和分类等任务。

m0_55196097的博客 1万+

asterisk模块功能及主要配置文件的作用

sterisk的学习首先应该从整体的体系结构入手,当对其有着一定的宏观了解后,在分块细化进行系统地、细致地学习。本文主要从三个方面来介绍安装后asterisk的结构:文件目录、配置文件、模块。 1、文件目录      安装后的文件目录结构见下表, 目录路径 简介       /etc/asterisk 所有配置文件都在此目录下 /usr/sbi

月无影的专栏 4155

Delta-Sigma调制(DSM)技术

前言 数字信号处理和通信系统的性能很大程度上受到了模拟信号到数字信号转换接口——ADC的精度和分辨率的限制。而传统的线性脉冲编码调制(PCM)ADC受到了制造工艺的限制,无法达到很高的分辨率。但基于Delta-Sigma调制技术的ADC可以在现有工艺下实现高分辨率(大于16位),同时由于结构简单,所以易于实现。低成本高性能使得Delta-Sigma调制技术得到了广泛的应用。 Delta-Sigma型ADC的结构原理图如下图所示: 它最大的优势在于仅用1位ADC进行数据转换,同时其模拟电路部分结构简单不需要

阿星的博客 2万+

Fluent后台计算中Journal文件的自动化编写与优化实践

本文深入探讨了Fluent在Linux/Unix环境下进行后台计算时,Journal文件的自动化编写与优化实践。Journal文件作为Fluent后台计算的“灵魂”,是实现仿真流程自动化、保证计算可重复性与准确性的关键。文章从基础脚本骨架搭建、命令简写技巧,到进阶的参数化研究与批量计算实现,提供了详实的实战指南,帮助工程师大幅提升仿真效率。

postgres8guard的博客 760

关于SOAP协议通信异常导致的daas agent与TA设备通信异常

【背景】 在一次为桌面租户创建环境中映像时,模板虚拟机中agent注册TA设备报错:SOAP-ENV:server;Actor:;String:Cannot write part return.RPC/Literal parts cannot be null.(WS-I BP R2211) 【关于SOAP】 SOAP(Simple Object Accrss Protocol,简单对象访问协议)...

企业实战系列集 ●●● https://ximenjianxue.blog.youkuaiyun.com 853

YOLOv11改进 | 上采样篇 | YOLOv11引入CARAFE上采样

在本文中,我们提出了一个通用、轻量级、高效的特征重组算子CARAFE来实现这一目标.CARAFE有几个吸引人的特性:(1)大视场。(2)内容感知处理。到此本文的正式分享内容就结束了,在这里给大家推荐我的YOLOv11改进有效涨点专栏,本专栏目前为新开的,后期我会根据各种前沿顶会进行论文复现,也会对一些老的改进机制进行补充,如果大家觉得本文帮助到你了,订阅本专栏,关注后续更多的更新~大视场:不同于以往的方法(如双线性插值),CARAFE能够在更大的感受野内聚合上下文信息,从而捕获更丰富的语义信息。

tsg6698的博客 928

hackthebox靶场记录(Cap、Connected、Reactor、Facts、WingData、Orion)

HTB靶场:Cap、Connected、Reactor、Facts、WingData、Orion,待更新

qq_43292831的博客 710

Doris磁盘空间管理(生命周期管理、清理磁盘空间方法)

在进行数据仓库开发时,比较头疼的是历史数据不删除,磁盘空间不断增长,如果磁盘空间不足时,spark调度任务写入时就会报错。

大模型大数据攻城狮的专栏 1720

电机控制的智慧之眼:全面解析FOC状态观测器

摘要:本文深入探讨磁场定向控制(FOC)中的状态观测器技术,重点分析其在无传感器电机控制中的关键作用。文章详细介绍了滑模观测器(SMO)、扩展卡尔曼滤波(EKF)、龙贝格观测器和高频注入法等主流观测器的工作原理、技术特点及适用场景,其中SMO因结构简单、鲁棒性强成为当前主流方案。同时阐述了观测器与锁相环(PLL)结合的工程实践方案,并针对不同应用场景提供了观测器选型建议。文章还探讨了启动问题处理、参数敏感性等工程挑战的解决方案,以及混合观测器、AI应用等未来发展趋势。这些观测器技术使电机系统在无机械传感器情

汽车软件开发 276

CXF中could not find matching RPC/Literal part问题

异常如下: org.apache.cxf.interceptor.Fault: Found element {}but could not find matching RPC/Literal part at org.apache.cxf.binding.soap.interceptor.RPCInInterceptor.handleMessage(RPCInInterceptor.j...

20386053 988

uniapp - [微信小程序 | 安卓苹果app] 详细实现接入天地图完整流程,提供显示地图、IP 属地定位 / 用户定位的城市名称、用户定位的经纬度超多功能(复制运行示例代码,详细注释及常见问题)

uni-app,微信小程序,安卓app,苹果app,App端,支付宝小程序,nvue,天地图,国家天地图api,接入使用天地图,uniApp小程序端接入天地图,uniapp安卓苹果app端接入天地图,微信小程序平台如何引入天地图,天地图Api使用教程,如何在uniapp里集成天地图,使用天地图获取当前定位,天地图api教程,天地图官方文档,天地图详细使用教程,Uniapp项目如何使用天地图,项目引入天地图配置及使用教程,使用天地图获取用户定位,天地图获取用户当前位置信息(经纬度),如何通过天地图拿到用户定位

🏆 前端领域优质创作者 1万+

Linux 日常命令汇总

项目场景:批量kill pid进程 问题描述:kill awk输出的pid ps -aux | grep idea | awk '{print $2}' | xargs kill -9 原因分析: 提示:这里填写问题的分析: 例如:Handler 发送消息有两种方式,分别是 Handler.obtainMessage()和 Handler.sendMessage(),其中 obtainMessage 方式当数据量过大时,由于 MessageQuene 大小也有限,所以当 message 处理不及

ailian_f的博客 645

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

CXF中could not find matching RPC/Literal part问题处理

前段时间,项目中涉及到和别的系统之间交互,对方的系统使用的是.NET,我们是J2EE平台,使用的WebService中的CXF框架。主要是我们这边调用对方系统公开的WebService。我使用Myeclipse工具生成的客户端存根。程序非常简单,但是总是报以下的错误:         Interceptor for {http://这个部分是Webservice的地址部分,省去}ExpertCh

坐忘峰 1万+

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

The R Formula Method: The Bad Parts

R’s model formula infrastructure was discussed in my previous post. Despite the elegance and convenience of the formula method, there are some aspects that are limiting. Limitations to Extensibil

四纪启悟 · 数据科学 595

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Asterisk权威指南/第二章 Asterisk架构

Asterisk和其他传统的PBX完全不同,因为Asterisk的拨号计划以同样的方式处理所有的入局信道(incoming channels)。 传统的PBX在逻辑上区分工作站信道(连接电话机)和电话局信道(连接到外部世界)。这意味着,你不可能无缝地在一个工作站端口配置一个外部网关。同样,传统PBX也很难实现对离站(off-site,不在座位上或外出办事)资源的访问,比如前台如果外出办事就什么事

学习是为了探索这个世界的本质 4772

asterisk 自动加载模块

1、vim /etc/asterisk/modules.conf 添加以下内容,就可以自动加载该模块: load => test.so  注:把test.so文件放到正确的目录下 vim /etc/asterisk/asterisk.conf查看astmoddir该项,本项为asterisk加载动态库的路径, 如下: astmoddir => /usr/lib/asterisk

飞呀飞呀菲 1125

asterisk常用命令

转自 http://blog.sina.com.cn/s/blog_5e42f31a0100yekd.html 使用篇       经过前面的步骤,代码已经编译完了,可执行文件安装完毕同时默认的配置文件也安装了,那么我们就从使用上首先简单的做个介绍,给大家带来一个直观的认识。下文所举例子都会以sip为例,其他h323,iax,mgcp等等类似,不再赘述。       使用之前

小白的成长笔记 1万+

Java Socket

 所谓socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄。应用程序通常通过"套接字"向网络发出请求或者应答网络请求。   以J2SDK-1.3为例,Socket和ServerSocket类库位于java.net包中。ServerSocket用于服务器端,Socket是建立网络连接时使用的。在连接成功时,应用程序两端都会产生一个Socket实例,操作这个实例,完成所需的会话

站在技术的边缘,遥望你 597
上一篇: How-to: Write an Asterisk Module, Part 2
下一篇: MySQL Commands
whatsyourname
博客等级 码龄23年 13粉丝 326原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值