转自:http://blog.csdn.net/southflow/article/details/5939006
Asterisk manager interface的应用及Asterisk中目前所拥有的AMI接口可以参考:http://www.voip-info.org/wiki/view/Asterisk+manager+API
那么我们如何为自己添加一个AMI命令呢?
添加AMI的接口如下:
int ast_manager_register2(const char *action, int auth, int (*func)(struct mansession *s, const struct message *m), const char *synopsis, const char
*description)
{
struct manager_action *cur = NULL;
if (!(cur = ast_calloc(1, sizeof(*cur))))
return -1;
cur->action = action; //命令名称
cur->authority = auth; //命令的执行权限,所有的AMI命令分为很多类
cur->func = func; //命令执行函数
cur->synopsis = synopsis; //命令摘要描述
cur->description = description; // 命令具体使用描述,在命令行查看帮组时将看到
if (ast_manager_register_struct(cur)) {
ast_free(cur);
return -1;
}
return 0;
}
添加AMI命令使用该接口如下:
ast_manager_register2("MeetmeList", EVENT_FLAG_REPORTING,
action_meetmelist, "List participants in a conference", mandescr_meetmelist);
动作函数的编写方法:
static int action_meetmelist(struct mansession *s, const struct message *m){
....
....
}
AMI协议以键值协议传递,那么在AMI会话中通过键拿到值的接口:
const char *astman_get_header(const struct message *m, char *var);
对于命令的回复使用到下面接口:
static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag);
对于执行AMI命令的结果产生的事件使用到下面的接口:
int __manager_event(int category, const char *event, const char *file, int line, const char *func, const char *fmt, ...);