/*! \brief Thread which dials and executes upon answer */ static void *ari_originate_dial(void *data) { struct ast_dial *dial = data; struct ari_origination *origination = ast_dial_get_user_data(dial); enum ast_dial_result res; res = ast_dial_run(dial, NULL, 0); if (res != AST_DIAL_RESULT_ANSWERED) { goto end; } if (!ast_strlen_zero(origination->appdata)) { struct ast_app *app = pbx_findapp("Stasis"); if (app) { ast_verb(4, "Launching Stasis(%s) on %s\n", origination->appdata, ast_channel_name(ast_dial_answered(dial))); pbx_exec(ast_dial_answered(dial), app, origination->appdata); } else { ast_log(LOG_WARNING, "No such application 'Stasis'\n"); } } else { struct ast_channel *answered = ast_dial_answered(dial); if (!ast_strlen_zero(origination->context)) { ast_channel_context_set(answered, origination->context); } if (!ast_strlen_zero(origination->exten)) { ast_channel_exten_set(answered, origination->exten); } if (origination->priority > 0) { ast_channel_priority_set(answered, origination->priority); } if (ast_pbx_run(answered)) { ast_log(LOG_ERROR, "Failed to start PBX on %s\n", ast_channel_name(answered)); } else { /* PBX will have taken care of hanging up, so we steal the answered channel so dial doesn't do it */ ast_dial_answered_steal(dial); } } end: ast_dial_destroy(dial); ast_free(origination); return NULL; }
static void *app_control_dial(struct stasis_app_control *control, struct ast_channel *chan, void *data) { RAII_VAR(struct ast_dial *, dial, ast_dial_create(), ast_dial_destroy); RAII_VAR(struct stasis_app_control_dial_data *, dial_data, data, ast_free); enum ast_dial_result res; char *tech, *resource; struct ast_channel *new_chan; struct ast_bridge *bridge; tech = dial_data->endpoint; if (!(resource = strchr(tech, '/'))) { return NULL; } *resource++ = '\0'; if (!dial) { ast_log(LOG_ERROR, "Failed to create dialing structure.\n"); return NULL; } if (ast_dial_append(dial, tech, resource) < 0) { ast_log(LOG_ERROR, "Failed to add %s/%s to dialing structure.\n", tech, resource); return NULL; } ast_dial_set_global_timeout(dial, dial_data->timeout); res = ast_dial_run(dial, NULL, 0); if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) { return NULL; } if (!(bridge = ast_bridge_basic_new())) { ast_log(LOG_ERROR, "Failed to create basic bridge.\n"); return NULL; } if (ast_bridge_impart(bridge, new_chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) { ast_hangup(new_chan); } else { stasis_app_control_add_channel_to_bridge(control, bridge); } return NULL; }