freeswitch php esl,FreeSWITCH的ESL消息接口

FreeSWITCH的ESL消息接口

tags:FreeSWITCH ESL SOCKET 创建时间:2015-11-22 20:48:25

```c

ESL_DECLARE(esl_status_t) esl_send(esl_handle_t handle, const charcmd)

{

const char *e = cmd + strlen(cmd) -1;

if (!handle || !handle->connected || handle->sock == ESL_SOCK_INVALID) {

return ESL_FAIL;

}

esl_log(ESL_LOG_DEBUG, "SEND\n%s\n", cmd);

if (send(handle->sock, cmd, strlen(cmd), 0) != (int)strlen(cmd)) {

handle->connected = 0;

if (!(strerror_r(handle->errnum, handle->err, sizeof(handle->err))))

*(handle->err)=0;

return ESL_FAIL;

}

if (!(*e == '\n' && *(e-1) == '\n')) {

if (send(handle->sock, "\n\n", 2, 0) != 2) {

handle->connected = 0;

if (!(strerror_r(handle->errnum, handle->err, sizeof(handle->err))))

*(handle->err)=0;

return ESL_FAIL;

}

}

return ESL_SUCCESS;

}

ESL_DECLARE(esl_status_t) esl_send_recv_timed(esl_handle_t handle, const charcmd, uint32_t ms)

{

const char *hval;

esl_status_t status;

if (!handle || !handle->connected || handle->sock == ESL_SOCK_INVALID) {

return ESL_FAIL;

}

esl_mutex_lock(handle->mutex);

if (!handle->connected || handle->sock == ESL_SOCK_INVALID) {

handle->connected = 0;

esl_mutex_unlock(handle->mutex);

return ESL_FAIL;

}

esl_event_safe_destroy(&handle->last_sr_event);

*handle->last_sr_reply = '\0';

if ((status = esl_send(handle, cmd))) {

esl_mutex_unlock(handle->mutex);

return status;

}

recv:

esl_event_safe_destroy(&handle->last_sr_event);

*handle->last_sr_reply = '\0';

status = esl_recv_event_timed(handle, ms, 0, &handle->last_sr_event);

if (handle->last_sr_event) {

char *ct = esl_event_get_header(handle->last_sr_event,"content-type");

if (strcasecmp(ct, "api/response") && strcasecmp(ct, "command/reply")) {

esl_event_t *ep;

for(ep = handle->race_event; ep && ep->next; ep = ep->next);

if (ep) {

ep->next = handle->last_sr_event;

} else {

handle->race_event = handle->last_sr_event;

}

handle->last_sr_event = NULL;

esl_mutex_unlock(handle->mutex);

esl_mutex_lock(handle->mutex);

if (!handle->connected || handle->sock == ESL_SOCK_INVALID) {

handle->connected = 0;

esl_mutex_unlock(handle->mutex);

return ESL_FAIL;

}

goto recv;

}

if (handle->last_sr_event) {

hval = esl_event_get_header(handle->last_sr_event, "reply-text");

if (!esl_strlen_zero(hval)) {

strncpy(handle->last_sr_reply, hval, sizeof(handle->last_sr_reply));

}

}

}

esl_mutex_unlock(handle->mutex);

return status;

}

```

上海老李,QQ:1354608370,FreeSWITCH QQ群:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值