static void mycallback(esl_socket_t server_sock, esl_socket_t client_sock, struct sockaddr_in *addr, void *user_data) { esl_handle_t handle = {{0}}; int done = 0; esl_status_t status; time_t exp = 0; if (fork()) { return; } if (esl_attach_handle(&handle, client_sock, addr) != ESL_SUCCESS) { return; } esl_log(ESL_LOG_INFO, "Connected! %d\n", handle.sock); esl_filter(&handle, "unique-id", esl_event_get_header(handle.info_event, "caller-unique-id")); esl_events(&handle, ESL_EVENT_TYPE_PLAIN, "SESSION_HEARTBEAT CHANNEL_ANSWER CHANNEL_ORIGINATE CHANNEL_PROGRESS CHANNEL_HANGUP " "CHANNEL_BRIDGE CHANNEL_UNBRIDGE CHANNEL_OUTGOING CHANNEL_EXECUTE CHANNEL_EXECUTE_COMPLETE DTMF CUSTOM conference::maintenance"); esl_send_recv(&handle, "linger"); esl_execute(&handle, "answer", NULL, NULL); esl_execute(&handle, "conference", "3000@default", NULL); while((status = esl_recv_timed(&handle, 1000)) != ESL_FAIL) { if (done) { if (time(NULL) >= exp) { break; } } else if (status == ESL_SUCCESS) { const char *type = esl_event_get_header(handle.last_event, "content-type"); if (type && !strcasecmp(type, "text/disconnect-notice")) { const char *dispo = esl_event_get_header(handle.last_event, "content-disposition"); esl_log(ESL_LOG_INFO, "Got a disconnection notice dispostion: [%s]\n", dispo ? dispo : ""); if (dispo && !strcmp(dispo, "linger")) { done = 1; esl_log(ESL_LOG_INFO, "Waiting 5 seconds for any remaining events.\n"); exp = time(NULL) + 5; } } } } esl_log(ESL_LOG_INFO, "Disconnected! %d\n", handle.sock); esl_disconnect(&handle); }
int32_t fs_opr_t::bridge(const char* uuid, const char* called_disp, const char* dnis) { FUNC_BEGIN(); if (set_channel_attribute(uuid, "bridge_early_media=true") && set_channel_attribute(uuid, "hangup_after_bridge=false") && set_channel_attribute(uuid, "bypass_media=false") && set_channel_attribute(uuid, "playback_terminators=none") && set_channel_attribute(uuid, "continue_on_fail=true")) { set_channel_attribute(uuid, "export_vars=IMSDATA"); snprintf(szcmd, LEN_512, "effective_caller_id_name=%s", called_disp); set_channel_attribute(uuid, szcmd); snprintf(szcmd, LEN_512, "effective_caller_id_number=%s", called_disp); set_channel_attribute(uuid, szcmd); if (esl_execute(&_handle, "bridge", dnis, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; break; } else { WARNING_LOG("fs:bridge(%s,%s,%s);ret(%s)", uuid, called_disp, dnis, fs_resp); } } FUNC_END(); }
int32_t fs_opr_t::bridge_ex(const char* uuid, const char* called_disp, const char* dnis, bool isAsync, bool return_ring_ready) { FUNC_BEGIN(); if (set_channel_attribute(uuid, "bridge_early_media=true") && set_channel_attribute(uuid, "hangup_after_bridge=false") && set_channel_attribute(uuid, "bypass_media=false") && set_channel_attribute(uuid, "playback_terminators=none") && set_channel_attribute(uuid, "continue_on_fail=true")) { set_channel_attribute(uuid, "export_vars=IMSDATA"); snprintf(szcmd, LEN_512, "effective_caller_id_name=%s", called_disp); set_channel_attribute(uuid, szcmd); snprintf(szcmd, LEN_512, "effective_caller_id_number=%s", called_disp); set_channel_attribute(uuid, szcmd); //char param[LEN_512+1]={0}; //snprintf(param, LEN_512, "[return_ring_ready=%s]%s", return_ring_ready ? "true" : "false", dnis); esl_status_t esl_ret = ESL_GENERR; TRACE_LOG("before bridge %s", isAsync ? "async" : "sync"); if (isAsync) { int async = _handle.async_execute; _handle.async_execute = 1; esl_ret = esl_execute(&_handle, "bridge", dnis, uuid); _handle.async_execute = async; } else { esl_ret = esl_execute(&_handle, "bridge", dnis, uuid); } TRACE_LOG("after bridge %s", isAsync ? "async" : "sync"); if (esl_ret == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; break; } else { WARNING_LOG("fs:bridge(%s,%s,%s,%s);ret(%s)", uuid, called_disp, dnis, fs_resp, isAsync ? "async" : "sync"); } } FUNC_END(); }
int ESLconnection::executeAsync(const char *app, const char *arg, const char *uuid) { int async = handle.async_execute; int r; handle.async_execute = 1; r = esl_execute(&handle, app, arg, uuid); handle.async_execute = async; return r; }
/////////////////////////////////////媒体START///////////////////////////////////////////////// int32_t fs_opr_t::stop_media(const char* uuid) { FUNC_BEGIN(); (void)szcmd; if (esl_execute(&_handle, "break", NULL, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:stop_media(%s);ret(%s)", uuid, fs_resp); } FUNC_END(); }
int32_t fs_opr_t::conference(const char* uuid, const char* name) { FUNC_BEGIN(); (void)szcmd; if (esl_execute(&_handle, "conference", name, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:conference(%s,%s);ret(%s)", uuid, name, fs_resp); } FUNC_END(); }
int32_t fs_opr_t::play(const char* uuid, const char* file, uint32_t count) { FUNC_BEGIN(); (void)szcmd; if (set_channel_attribute(uuid, "playback_terminators=none") && esl_execute(&_handle, "playback", file, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; TRACE_LOG("fs:play(%s,%s,%u) success.", uuid, file, count); } else { WARNING_LOG("fs:play(%s,%s,%u);ret(%s)", uuid, file, count, fs_resp); } FUNC_END(); }
int32_t fs_opr_t::send_dtmf(const char* uuid, const char* keys) { FUNC_BEGIN(); (void)szcmd; //snprintf(szcmd,LEN_512,CMD_UUIDSENDDTMF_FMT,uuid,keys); //TRACE_LOG("send_dtmf(%s)",szcmd); //if(esl_send_recv(&_handle,szcmd)==ESL_SUCCESS){ if (esl_execute(&_handle, "send_dtmf", keys, uuid) == ESL_SUCCESS && is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) { ret = IMS_SUCCESS; } else { WARNING_LOG("fs:send_dtmf(%s,%s);ret(%s)", uuid, keys, fs_resp); } FUNC_END(); }
int ESLconnection::execute(const char *app, const char *arg, const char *uuid) { return esl_execute(&handle, app, arg, uuid); }
bool nway_playring(esl_handle_t * pHandle, const char * uuid, const char * ring_file) { esl_execute(pHandle, "playback", ring_file, uuid); }