goto e_return;
}
+ ast_channel_lock(chn);
ast_channel_tech_set(chn, &mbl_tech);
ast_format_cap_add(ast_channel_nativeformats(chn), &prefformat);
ast_format_copy(ast_channel_rawreadformat(chn), &prefformat);
if (pvt->sco_socket != -1) {
ast_channel_set_fd(chn, 0, pvt->sco_socket);
}
+ ast_channel_unlock(chn);
return chn;
}
ast_queue_control(c, AST_CONTROL_ANSWER);
- ast_channel_unlock(p->owner);
ast_publish_channel_state(c);
+ ast_channel_unlock(p->owner);
}
ast_mutex_unlock(&p->lock);
ast_bridge_destroy(caller_bridge, AST_CAUSE_USER_BUSY);
}
+ ast_channel_lock(logged);
send_agent_logoff(logged, agent->username, time_logged_in);
+ ast_channel_unlock(logged);
ast_verb(2, "Agent '%s' logged out. Logged in for %ld seconds.\n",
agent->username, time_logged_in);
ast_channel_unref(logged);
ast_verb(2, "Agent '%s' logged in (format %s/%s)\n", agent->username,
ast_getformatname(ast_channel_readformat(chan)),
ast_getformatname(ast_channel_writeformat(chan)));
+ ast_channel_lock(chan);
send_agent_login(chan, agent->username);
+ ast_channel_unlock(chan);
agent_run(agent, chan);
return -1;
}
/* To make sure playback_chan has the same language of that profile */
+ ast_channel_lock(conference->playback_chan);
ast_channel_language_set(conference->playback_chan, conference->b_profile.language);
+ ast_channel_unlock(conference->playback_chan);
ast_debug(1, "Created announcer channel '%s' to conference bridge '%s'\n",
ast_channel_name(conference->playback_chan), conference->name);
struct ast_party_caller caller;
/* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
+ ast_channel_lock(chan);
ast_channel_stage_snapshot(chan);
pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
ast_channel_stage_snapshot_done(chan);
+ ast_channel_unlock(chan);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
continue;
}
+ ast_channel_lock(tc);
ast_channel_stage_snapshot(tc);
+ ast_channel_unlock(tc);
ast_channel_get_device_name(tc, device_name, sizeof(device_name));
if (!ignore_cc) {
ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
}
- pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
ast_channel_lock_both(tc, chan);
+ pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
/* Setup outgoing SDP to match incoming one */
if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
number = ast_strdupa(number);
}
ast_channel_unlock(peer);
+ ast_channel_lock(chan);
pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
ast_channel_stage_snapshot_done(chan);
+ ast_channel_unlock(chan);
if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
/* chan and peer are going into the PBX; as such neither are considered
* outgoing channels any longer */
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
- ast_channel_stage_snapshot(peer);
- ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
/* peer goes to the same context and extension as chan, so just copy info from chan*/
+ ast_channel_lock(peer);
+ ast_channel_stage_snapshot(peer);
+ ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
ast_channel_context_set(peer, ast_channel_context(chan));
ast_channel_exten_set(peer, ast_channel_exten(chan));
ast_channel_priority_set(peer, ast_channel_priority(chan) + 2);
ast_channel_stage_snapshot_done(peer);
+ ast_channel_unlock(peer);
if (ast_pbx_start(peer)) {
ast_autoservice_chan_hangup_peer(chan, peer);
}
if (!res) {
if (!ast_tvzero(calldurationlimit)) {
struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
+ ast_channel_lock(peer);
ast_channel_whentohangup_set(peer, &whentohangup);
+ ast_channel_unlock(peer);
}
if (!ast_strlen_zero(dtmfcalled)) {
ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
ast_set_callerid(chan, ourcidnum, ourcidname, ourcidnum);
}
- if (!ast_strlen_zero(acctcode))
+ if (!ast_strlen_zero(acctcode)) {
+ ast_channel_lock(chan);
ast_channel_accountcode_set(chan, acctcode);
+ ast_channel_unlock(chan);
+ }
if (special_noanswer) {
ast_clear_flag(&cdr_flags, AST_CDR_FLAG_DISABLE);
}
}
+ ast_channel_lock(chan);
msg = ast_channel_blob_create(chan, message_type, json_object);
+ ast_channel_unlock(chan);
if (!msg) {
return;
RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
RAII_VAR(struct ast_channel_snapshot *, agent_snapshot, NULL, ao2_cleanup);
+ ast_channel_lock(caller);
caller_snapshot = ast_channel_snapshot_create(caller);
+ ast_channel_unlock(caller);
+ ast_channel_lock(agent);
agent_snapshot = ast_channel_snapshot_create(agent);
+ ast_channel_unlock(agent);
if (!caller_snapshot || !agent_snapshot) {
return;
"Queue", q->name,
"Position", qe->pos,
"Count", q->count);
+ ast_channel_lock(qe->chan);
ast_channel_publish_blob(qe->chan, queue_caller_join_type(), blob);
+ ast_channel_unlock(qe->chan);
ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, ast_channel_name(qe->chan), qe->pos );
}
ao2_unlock(q);
"Queue", q->name,
"Position", qe->pos,
"Count", q->count);
+ ast_channel_lock(qe->chan);
ast_channel_publish_blob(qe->chan, queue_caller_leave_type(), blob);
+ ast_channel_unlock(qe->chan);
ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, ast_channel_name(qe->chan));
/* Take us out of the queue */
if (prev) {
"Position", qe->pos,
"OriginalPosition", qe->opos,
"HoldTime", (int)(time(NULL) - qe->start));
- ast_channel_publish_blob(qe->chan, queue_caller_abandon_type(), blob);
qe->parent->callsabandoned++;
ao2_unlock(qe->parent);
+
+ ast_channel_lock(qe->chan);
+ ast_channel_publish_blob(qe->chan, queue_caller_abandon_type(), blob);
+ ast_channel_unlock(qe->chan);
}
/*! \brief RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer. */
}
}
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, ast_channel_user_event_type(), blob);
+ ast_channel_unlock(chan);
return 0;
}
#endif
/* Set language from config to override channel language */
- if (!ast_strlen_zero(vmu->language))
+ if (!ast_strlen_zero(vmu->language)) {
+ ast_channel_lock(chan);
ast_channel_language_set(chan, vmu->language);
+ ast_channel_unlock(chan);
+ }
/* Retrieve urgent, old and new message counts */
ast_debug(1, "Before open_mailbox\n");
if (!(tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, linkedid, 0, "ALSA/%s", indevname)))
return NULL;
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
ast_channel_tech_set(tmp, &alsa_tech);
ast_jb_configure(tmp, &global_jbconf);
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
return NULL;
}
+ ast_channel_lock(chan);
ast_channel_stage_snapshot(chan);
ast_channel_tech_set(chan, &console_tech);
ast_jb_configure(chan, &global_jbconf);
ast_channel_stage_snapshot_done(chan);
+ ast_channel_unlock(chan);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(chan)) {
return;
}
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, dahdichannel_type(), blob);
+ ast_channel_unlock(chan);
}
/*!
return NULL;
}
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
if (callid) {
pbx_builtin_setvar_helper(tmp, v->name, v->value);
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
ast_module_ref(ast_module_info->self);
getforward = 0;
} else {
res = tone_zone_play_tone(p->subs[idx].dfd, -1);
+ ast_channel_lock(chan);
ast_channel_exten_set(chan, exten);
if (!ast_strlen_zero(p->cid_num)) {
if (!p->hidecallerid)
ast_set_callerid(chan, NULL, p->cid_name, NULL);
}
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
dahdi_ec_enable(p);
res = ast_pbx_run(chan);
if (res) {
my_handle_notify_message(chan, p, flags, -1);
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_RING);
ast_channel_rings_set(chan, 1);
+ ast_channel_unlock(chan);
p->ringt = p->ringt_base;
res = ast_pbx_run(chan);
if (res) {
return NULL;
}
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
ast_channel_tech_set(tmp, >alk_tech);
ast_jb_configure(tmp, &global_jbconf);
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
ast_format_cap_joint_copy(p->cap, p->peercap, p->jointcap);
ast_mutex_unlock(&p->lock);
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
if (ast_format_cap_is_empty(p->jointcap)) {
ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->cap),
ast_getformatname_multiple(s2, BUFSIZ, p->peercap),
ch = ast_channel_alloc(1, state, cid_num, cid_name, pvt->accountcode, pvt->exten, pvt->context, linkedid, pvt->amaflags, "H323/%s", host);
/* Update usage counter */
ast_module_ref(ast_module_info->self);
+ if (ch) {
+ ast_channel_lock(ch);
+ }
ast_mutex_lock(&pvt->lock);
if (ch) {
ast_channel_tech_set(ch, &oh323_tech);
}
if (pvt->cd.transfer_capability >= 0)
ast_channel_transfercapability_set(ch, pvt->cd.transfer_capability);
+ ast_channel_unlock(ch);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(ch)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(ch));
/* Don't hold call lock */
ast_mutex_unlock(&iaxsl[callno]);
tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, linkedid, i->amaflags, "IAX2/%s-%d", i->host, i->callno);
+ if (tmp) {
+ ast_channel_lock(tmp);
+ }
ast_mutex_lock(&iaxsl[callno]);
if (i != iaxs[callno]) {
if (tmp) {
/* unlock and relock iaxsl[callno] to preserve locking order */
ast_mutex_unlock(&iaxsl[callno]);
+ ast_channel_unlock(tmp);
tmp = ast_channel_release(tmp);
ast_mutex_lock(&iaxsl[callno]);
}
}
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
if (c) {
struct ast_format_cap *joint;
if (callid) {
+ ast_channel_lock(c);
ast_channel_callid_set(c, callid);
+ ast_channel_unlock(c);
}
/* Choose a format we can live with */
return NULL;
}
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
ast_channel_tech_set(tmp, &jingle_tech);
ast_jb_configure(tmp, &global_jbconf);
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
}
ast_mutex_unlock(&p->lock);
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
res = ast_pbx_start(chan);
switch (res) {
tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, linkedid, i->accountcode, i->exten, i->context, i->amaflags, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
if (tmp) {
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
ast_channel_tech_set(tmp, &mgcp_tech);
ast_format_cap_copy(ast_channel_nativeformats(tmp), i->cap);
}
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
} else {
/*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
ast_indicate(chan, -1);
+ ast_channel_lock(chan);
ast_channel_exten_set(chan, p->dtmf_buf);
ast_channel_dialed(chan)->number.str = ast_strdup(p->dtmf_buf);
memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
p->hidecallerid ? "" : p->cid_name,
ast_channel_caller(chan)->ani.number.valid ? NULL : p->cid_num);
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
if (p->dtmfmode & MGCP_DTMF_HYBRID) {
p->dtmfmode |= MGCP_DTMF_INBAND;
ast_indicate(chan, -1);
chan_misdn_log(1, port, "read_config: Getting Config\n");
misdn_cfg_get(port, MISDN_CFG_LANGUAGE, lang, sizeof(lang));
+ ast_channel_lock(ast);
ast_channel_language_set(ast, lang);
+ ast_channel_unlock(ast);
misdn_cfg_get(port, MISDN_CFG_MUSICCLASS, ch->mohinterpret, sizeof(ch->mohinterpret));
misdn_cfg_get(bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));
+ ast_channel_lock(ast);
ast_channel_context_set(ast, ch->context);
+ ast_channel_unlock(ast);
#ifdef MISDN_1_2
update_pipeline_config(bc);
misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
chan_misdn_log(5, port, " --> * CallGrp:%s PickupGrp:%s\n", ast_print_group(buf, sizeof(buf), cg), ast_print_group(buf2, sizeof(buf2), pg));
+ ast_channel_lock(ast);
ast_channel_pickupgroup_set(ast, pg);
ast_channel_callgroup_set(ast, cg);
+ ast_channel_unlock(ast);
misdn_cfg_get(port, MISDN_CFG_NAMEDPICKUPGROUP, &npg, sizeof(npg));
misdn_cfg_get(port, MISDN_CFG_NAMEDCALLGROUP, &ncg, sizeof(ncg));
ast_free(tmp_str);
}
+ ast_channel_lock(ast);
ast_channel_named_pickupgroups_set(ast, npg);
ast_channel_named_callgroups_set(ast, ncg);
+ ast_channel_unlock(ast);
if (ch->originator == ORG_AST) {
char callerid[BUFFERSIZE + 1];
/* Add configured prefix to dialed.number */
misdn_add_number_prefix(bc->port, bc->dialed.number_type, bc->dialed.number, sizeof(bc->dialed.number));
+ ast_channel_lock(ast);
ast_channel_exten_set(ast, bc->dialed.number);
+ ast_channel_unlock(ast);
misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));
ast_mutex_init(&ch->overlap_tv_lock);
export_ch(chan, bc, ch);
+ ast_channel_lock(ch->ast);
ast_channel_rings_set(ch->ast, 1);
ast_setstate(ch->ast, AST_STATE_RINGING);
+ ast_channel_unlock(ch->ast);
/* Update asterisk channel caller information */
chan_misdn_log(2, bc->port, " --> TON: %s(%d)\n", misdn_to_str_ton(bc->caller.number_type), bc->caller.number_type);
}
ast_queue_control(ch->ast, AST_CONTROL_RINGING);
+ ast_channel_lock(ch->ast);
ast_setstate(ch->ast, AST_STATE_RINGING);
+ ast_channel_unlock(ch->ast);
cb_log(7, bc->port, " --> Set State Ringing\n");
if (!(chan = ast_channel_alloc(1, state, S_OR(title, ""), S_OR(cid_name, ""), "", "", "", linkedid, 0, "Motif/%s-%04lx", str, ast_random() & 0xffff))) {
return NULL;
}
+ ast_channel_lock(chan);
ast_channel_stage_snapshot(chan);
ao2_unlock(endpoint);
ast_channel_stage_snapshot_done(chan);
+ ast_channel_unlock(chan);
return chan;
}
ao2_link(endpoint->state->sessions, session);
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
res = ast_pbx_start(chan);
switch (res) {
struct ast_channel *tmp;
tmp = ast_channel_alloc(1, state, 0, 0, "", "s", context, linkedid, 0, "NBS/%s", i->stream);
if (tmp) {
+ ast_channel_lock(tmp);
ast_channel_tech_set(tmp, &nbs_tech);
ast_channel_set_fd(tmp, 0, nbs_fd(i->nbs));
ast_channel_language_set(tmp, "");
i->owner = tmp;
i->u = ast_module_user_add(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, linkedid, 0, "Console/%s", o->device + 5);
if (c == NULL)
return NULL;
+ ast_channel_lock(c);
ast_channel_tech_set(c, &oss_tech);
if (o->sounddev < 0)
setformat(o, O_RDWR);
o->owner = c;
ast_module_ref(ast_module_info->self);
ast_jb_configure(c, &global_jbconf);
+ ast_channel_unlock(c);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(c)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(c));
struct ast_format tmpfmt;
tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "", i->ext, i->context, linkedid, 0, "Phone/%s", i->dev + 5);
if (tmp) {
+ ast_channel_lock(tmp);
ast_channel_tech_set(tmp, cur_tech);
ast_channel_set_fd(tmp, 0, i->fd);
/* XXX Switching formats silently causes kernel panics XXX */
ast_channel_caller(tmp)->ani.number.valid = 1;
ast_channel_caller(tmp)->ani.number.str = ast_strdup(i->cid_num);
}
+ ast_channel_unlock(tmp);
i->owner = tmp;
ast_module_ref(ast_module_info->self);
return NULL;
}
- ast_channel_stage_snapshot(chan);
-
/* If res_pjsip_session is ever updated to create/destroy ast_sip_session_media
* during a call such as if multiple same-type stream support is introduced,
* these will need to be recaptured as well */
pvt->media[SIP_MEDIA_AUDIO] = ao2_find(session->media, "audio", OBJ_KEY);
pvt->media[SIP_MEDIA_VIDEO] = ao2_find(session->media, "video", OBJ_KEY);
+
+ ast_channel_lock(chan);
+ ast_channel_stage_snapshot(chan);
+
ast_channel_tech_pvt_set(chan, channel);
if (pvt->media[SIP_MEDIA_AUDIO] && pvt->media[SIP_MEDIA_AUDIO]->rtp) {
ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_AUDIO]->rtp, ast_channel_uniqueid(chan));
ast_channel_zone_set(chan, zone);
}
- ast_endpoint_add_channel(session->endpoint->persistent, chan);
-
ast_channel_stage_snapshot_done(chan);
+ ast_channel_unlock(chan);
+
+ ast_endpoint_add_channel(session->endpoint->persistent, chan);
return chan;
}
switch (status.code) {
case 180:
ast_queue_control(session->channel, AST_CONTROL_RINGING);
+ ast_channel_lock(session->channel);
if (ast_channel_state(session->channel) != AST_STATE_UP) {
ast_setstate(session->channel, AST_STATE_RINGING);
}
+ ast_channel_unlock(session->channel);
break;
case 183:
ast_queue_control(session->channel, AST_CONTROL_PROGRESS);
}
}
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
/* If we sent in a callid, bind it to the channel. */
ast_channel_callid_set(tmp, callid);
}
- ast_channel_lock(tmp);
sip_pvt_lock(i);
ast_channel_cc_params_init(tmp, i->cc_params);
ast_channel_caller(tmp)->id.tag = ast_strdup(i->cid_tag);
struct skinny_device *d = l->device;
int res = 0;
+ ast_channel_lock(c);
ast_set_callerid(c,
l->hidecallerid ? "" : l->cid_num,
l->hidecallerid ? "" : l->cid_name,
ast_party_name_init(&ast_channel_connected(c)->id.name);
#endif
ast_setstate(c, AST_STATE_RING);
+ ast_channel_unlock(c);
if (!sub->rtp) {
start_rtp(sub);
}
AST_LIST_INSERT_HEAD(&l->sub, sub, list);
//l->activesub = sub;
}
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
ast_channel_tech_set(tmp, &skinny_tech);
ast_channel_tech_pvt_set(tmp, sub);
pbx_builtin_setvar_helper(tmp, v->name, v->value);
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
int res;
ast_verb(3, "Starting switch on '%s@%s-%d' to %s\n", l->name, l->parent->name, sub->softkey, s->device->phone_number);
+ ast_channel_lock(chan);
ast_channel_exten_set(chan, s->device->phone_number);
+ ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
ast_copy_string(s->device->redial_number, s->device->phone_number,
sizeof(s->device->redial_number));
- ast_setstate(chan, AST_STATE_RING);
res = ast_pbx_run(chan);
if (res) {
ast_log(LOG_WARNING, "PBX exited non-zero\n");
return NULL;
}
+ ast_channel_lock(tmp);
ast_channel_stage_snapshot(tmp);
ast_format_cap_copy(ast_channel_nativeformats(tmp), l->cap);
ast_channel_priority_set(tmp, 1);
ast_channel_stage_snapshot_done(tmp);
+ ast_channel_unlock(tmp);
if (state != AST_STATE_DOWN) {
if (unistimdebug) {
tmp = ast_channel_alloc(1, state, 0, 0, "", me->ext, me->context, linkedid, AST_AMA_NONE, "%s", me->dev);
if (tmp) {
+ ast_channel_lock(tmp);
if (use_ast_ind == 1){
ast_channel_tech_set(tmp, &vpb_tech_indicate);
} else {
ast_channel_exten_set(tmp, "s");
if (!ast_strlen_zero(me->language))
ast_channel_language_set(tmp, me->language);
+ ast_channel_unlock(tmp);
me->owner = tmp;
getforward = 0;
} else {
res = analog_play_tone(p, idx, -1);
+ ast_channel_lock(chan);
ast_channel_exten_set(chan, exten);
if (!ast_strlen_zero(p->cid_num)) {
if (!p->hidecallerid) {
}
}
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
analog_set_echocanceller(p, 1);
res = ast_pbx_run(chan);
if (res) {
analog_handle_notify_message(chan, p, flags, -1);
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_RING);
ast_channel_rings_set(chan, 1);
+ ast_channel_unlock(chan);
analog_set_ringtimeout(p, p->ringt_base);
res = ast_pbx_run(chan);
if (res) {
#endif /* defined(ISSUE_16789) */
sig_pri_set_echocanceller(p, 1);
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_RING);
+ ast_channel_unlock(chan);
res = ast_pbx_run(chan);
if (res) {
ast_log(LOG_WARNING, "PBX exited non-zero!\n");
switch (*data) {
case 'a':
case 'A':
+ ast_channel_lock(chan);
ast_channel_setwhentohangup_tv(chan, when);
+ ast_channel_unlock(chan);
if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
when = ast_tvadd(when, ast_tvnow());
ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",
*/
int ast_aoc_decoded2str(const struct ast_aoc_decoded *decoded, struct ast_str **msg);
-/*! \brief generate AOC manager event for an AOC-S, AOC-D, or AOC-E msg */
+/*!
+ * \brief generate AOC manager event for an AOC-S, AOC-D, or AOC-E msg
+ * \pre chan is locked
+ */
int ast_aoc_manager_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan);
/*! \brief get the message type, AOC-D, AOC-E, or AOC Request */
* \details
* This function sets the absolute time out on a channel (when to hang up).
*
- * \note This function does not require that the channel is locked before
- * calling it.
+ * \pre chan is locked
*
* \return Nothing
* \sa ast_channel_setwhentohangup_tv()
*
* This function sets the absolute time out on a channel (when to hang up).
*
- * \note This function does not require that the channel is locked before
- * calling it.
+ * \pre chan is locked
*
* \return Nothing
* \since 1.6.1
* \param chan the channel
* \param vars a linked list of variables
*
+ * \pre chan is locked
+ *
* \details
* Variable names can be for a regular channel variable or a dialplan function
* that has the ability to be written to.
void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) __attribute__((format(printf, 2, 0))); \
void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) __attribute__((format(printf, 2, 3)))
+/*!
+ * The following string fields result in channel snapshot creation and
+ * should have the channel locked when called:
+ *
+ * \li language
+ * \li accountcode
+ * \li peeracccount
+ * \li linkedid
+ */
DECLARE_STRINGFIELD_SETTERS_FOR(name);
DECLARE_STRINGFIELD_SETTERS_FOR(language);
DECLARE_STRINGFIELD_SETTERS_FOR(musicclass);
struct timeval ast_channel_sending_dtmf_tv(const struct ast_channel *chan);
void ast_channel_sending_dtmf_tv_set(struct ast_channel *chan, struct timeval value);
enum ama_flags ast_channel_amaflags(const struct ast_channel *chan);
+
+/*!
+ * \pre chan is locked
+ */
void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value);
int ast_channel_epfd(const struct ast_channel *chan);
void ast_channel_epfd_set(struct ast_channel *chan, int value);
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value);
enum ast_channel_state ast_channel_state(const struct ast_channel *chan);
struct ast_callid *ast_channel_callid(const struct ast_channel *chan);
+
+/*!
+ * \pre chan is locked
+ */
void ast_channel_callid_set(struct ast_channel *chan, struct ast_callid *value);
/* XXX Internal use only, make sure to move later */
void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value);
void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value);
void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value);
+
+/*!
+ * \pre chan is locked
+ */
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value);
void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value);
struct timeval ast_channel_creationtime(struct ast_channel *chan);
/* Typedef accessors */
ast_group_t ast_channel_callgroup(const struct ast_channel *chan);
+/*!
+ * \pre chan is locked
+ */
void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value);
ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan);
+/*!
+ * \pre chan is locked
+ */
void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value);
struct ast_namedgroups *ast_channel_named_callgroups(const struct ast_channel *chan);
void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value);
void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value);
struct ast_bridge *ast_channel_internal_bridge(const struct ast_channel *chan);
+/*!
+ * \pre chan is locked
+ */
void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value);
struct ast_bridge_channel *ast_channel_internal_bridge_channel(const struct ast_channel *chan);
AST_STATE_MUTE = (1 << 16), /*!< Do not transmit voice data */
};
-/*! \brief Change the state of a channel */
+/*!
+ * \brief Change the state of a channel
+ * \pre chan is locked
+ */
int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
#endif /* __AST_CHANNELSTATE_H__ */
* should also be treated as immutable and not modified after it is put into the
* message.
*
+ * \pre bridge is locked.
+ * \pre No channels are locked.
+ *
* \param bridge Channel blob is associated with, or NULL for global/all bridges.
* \param blob JSON object representing the data.
* \return \ref ast_bridge_blob message.
* \since 12
* \brief Publish a bridge channel enter event
*
+ * \pre bridge is locked.
+ * \pre No channels are locked.
+ *
* \param bridge The bridge a channel entered
* \param chan The channel that entered the bridge
* \param swap The channel being swapped out of the bridge
* \since 12
* \brief Publish a bridge channel leave event
*
+ * \pre bridge is locked.
+ * \pre No channels are locked.
+ *
* \param bridge The bridge a channel left
* \param chan The channel that left the bridge
*/
/*!
* \brief Publish a blind transfer event
*
+ * \pre No channels or bridges are locked
+ *
* \param is_external Whether the blind transfer was initiated externally (e.g. via AMI or native protocol)
* \param result The success or failure of the transfer
* \param to_transferee The bridge between the transferer and transferee plus the transferer channel
* Publish an \ref ast_attended_transfer_message with the dest_type set to
* \c AST_ATTENDED_TRANSFER_DEST_FAIL.
*
+ * \pre No channels or bridges are locked
+ *
* \param is_external Indicates if the transfer was initiated externally
* \param result The result of the transfer. Will always be a type of failure.
* \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
*
* In either case, two bridges enter, one leaves.
*
+ * \pre No channels or bridges are locked
+ *
* \param is_external Indicates if the transfer was initiated externally
* \param result The result of the transfer.
* \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
* this results from merging two bridges together. The difference is that a
* transferer channel survives the bridge merge
*
+ * \pre No channels or bridges are locked
+ *
* \param is_external Indicates if the transfer was initiated externally
* \param result The result of the transfer.
* \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
* \li A transferee channel leaving a bridge to run an app
* \li A bridge of transferees running an app (via a local channel)
*
+ * \pre No channels or bridges are locked
+ *
* \param is_external Indicates if the transfer was initiated externally
* \param result The result of the transfer.
* \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
* When this type of transfer occurs, the two bridges continue to exist after the
* transfer and a local channel is used to link the two bridges together.
*
+ * \pre No channels or bridges are locked
+ *
* \param is_external Indicates if the transfer was initiated externally
* \param result The result of the transfer.
* \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
* \brief Generate a snapshot of the channel state. This is an ao2 object, so
* ao2_cleanup() to deallocate.
*
+ * \pre chan is locked
+ *
* \param chan The channel from which to generate a snapshot
*
* \retval pointer on success (must be unreffed)
* The given \a blob should be treated as immutable and not modified after it is
* put into the message.
*
+ * \pre chan is locked
+ *
* \param chan Channel blob is associated with, or \c NULL for global/all channels.
* \param type Message type for this blob.
* \param blob JSON object representing the data, or \c NULL for no data. If
* \brief Publish a channel blob message.
* \since 12.0.0
*
+ * \pre chan is locked
+ *
* \param chan Channel publishing the blob.
* \param type Type of stasis message.
* \param blob The blob being published. (NULL if no blob)
* \since 12
* \brief Set flag to indicate channel snapshot is being staged.
*
+ * \pre chan is locked
+ *
* \param chan Channel being staged.
*/
void ast_channel_stage_snapshot(struct ast_channel *chan);
* \since 12
* \brief Clear flag to indicate channel snapshot is being staged, and publish snapshot.
*
+ * \pre chan is locked
+ *
* \param chan Channel being staged.
*/
void ast_channel_stage_snapshot_done(struct ast_channel *chan);
* \since 12
* \brief Publish a \ref ast_channel_snapshot for a channel.
*
+ * \pre chan is locked
+ *
* \param chan Channel to publish.
*/
void ast_channel_publish_snapshot(struct ast_channel *chan);
* \since 12
* \brief Publish a \ref ast_channel_varset for a channel.
*
+ * \pre chan is locked
+ *
* \param chan Channel to publish the event for, or \c NULL for 'none'.
* \param variable Name of the variable being set
* \param value Value.
* \brief Publish in the \ref ast_channel_topic a \ref ast_channel_snapshot
* message indicating a change in channel state
*
+ * \pre chan is locked
+ *
* \param chan The channel whose state has changed
*/
void ast_publish_channel_state(struct ast_channel *chan);
other = ast_bridge_channel_peer(src_bridge_channel);
if (other && other->state == BRIDGE_CHANNEL_STATE_WAIT) {
- unsigned int id = ast_atomic_fetchadd_int((int *) &optimization_id, +1);
+ unsigned int id;
+
+ if (ast_channel_trylock(other->chan)) {
+ return 1;
+ }
+
+ id = ast_atomic_fetchadd_int((int *) &optimization_id, +1);
ast_verb(3, "Move-swap optimizing %s <-- %s.\n",
ast_channel_name(dst_bridge_channel->chan),
if (pvt && pvt->callbacks && pvt->callbacks->optimization_finished) {
pvt->callbacks->optimization_finished(pvt, res == 1, id);
}
+ ast_channel_unlock(other);
}
return res;
}
return;
}
+ ast_channel_lock(bridge_channel->chan);
ast_channel_linkedid_set(bridge_channel->chan, oldest_linkedid);
+ ast_channel_unlock(bridge_channel->chan);
AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
if (other == swap) {
continue;
}
+ ast_channel_lock(other->chan);
ast_channel_linkedid_set(other->chan, oldest_linkedid);
+ ast_channel_unlock(other->chan);
}
}
if (other == swap) {
continue;
}
+ ast_channel_lock_both(bridge_channel->chan, other->chan);
if (!ast_strlen_zero(ast_channel_accountcode(bridge_channel->chan)) && ast_strlen_zero(ast_channel_peeraccount(other->chan))) {
ast_debug(1, "Setting peeraccount to %s for %s from data on channel %s\n",
ast_channel_peeraccount_set(bridge_channel->chan, ast_channel_accountcode(other->chan));
}
}
+ ast_channel_unlock(bridge_channel->chan);
+ ast_channel_unlock(other->chan);
}
}
datalen = 0;
}
+ ast_channel_lock(bridge_channel->chan);
ast_channel_publish_blob(bridge_channel->chan, ast_channel_hold_type(), blob);
+ ast_channel_unlock(bridge_channel->chan);
return ast_bridge_channel_write_control_data(bridge_channel, AST_CONTROL_HOLD,
moh_class, datalen);
}
int ast_bridge_channel_write_unhold(struct ast_bridge_channel *bridge_channel)
{
+ ast_channel_lock(bridge_channel->chan);
ast_channel_publish_blob(bridge_channel->chan, ast_channel_unhold_type(), NULL);
+ ast_channel_unlock(bridge_channel->chan);
return ast_bridge_channel_write_control_data(bridge_channel, AST_CONTROL_UNHOLD, NULL, 0);
}
"event_type", event_type,
"event_details", blob);
+ ast_channel_lock(chan);
message = ast_channel_blob_create(chan, cel_generic_type(), cel_blob);
+ ast_channel_unlock(chan);
if (message) {
stasis_publish(ast_cel_topic(), message);
}
static struct stasis_message *create_channel_snapshot_message(struct ast_channel *channel)
{
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ ast_channel_lock(channel);
snapshot = ast_channel_snapshot_create(channel);
+ ast_channel_unlock(channel);
if (!snapshot) {
return NULL;
}
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HOLD };
int res;
+ ast_channel_lock(chan);
if (!ast_strlen_zero(musicclass)) {
f.data.ptr = (void *) musicclass;
f.datalen = strlen(musicclass) + 1;
ast_channel_publish_blob(chan, ast_channel_hold_type(), blob);
res = ast_queue_frame(chan, &f);
+ ast_channel_unlock(chan);
return res;
}
struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_UNHOLD };
int res;
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, ast_channel_unhold_type(), NULL);
res = ast_queue_frame(chan, &f);
+ ast_channel_unlock(chan);
return res;
}
/* Things that may possibly raise Stasis messages shouldn't occur after this point */
ast_set_flag(ast_channel_flags(chan), AST_FLAG_DEAD);
+ ast_channel_lock(chan);
ast_channel_publish_snapshot(chan);
+ ast_channel_unlock(chan);
publish_cache_clear(chan);
ast_channel_lock(chan);
generator_write_format_change(chan);
}
+ ast_channel_lock(chan);
ast_channel_publish_snapshot(chan);
+ ast_channel_unlock(chan);
return 0;
}
generator_write_format_change(chan);
}
+ ast_channel_lock(chan);
ast_channel_publish_snapshot(chan);
+ ast_channel_unlock(chan);
return res;
}
/* Copy/inherit important information into new channel */
if (oh) {
if (oh->vars) {
+ ast_channel_lock(new_chan);
ast_set_variables(new_chan, oh->vars);
+ ast_channel_unlock(new_chan);
}
if (oh->parent_channel) {
call_forward_inherit(new_chan, oh->parent_channel, orig);
if (oh) {
if (oh->vars) {
+ ast_channel_lock(chan);
ast_set_variables(chan, oh->vars);
+ ast_channel_unlock(chan);
}
if (!ast_strlen_zero(oh->cid_num) && !ast_strlen_zero(oh->cid_name)) {
/*
if (requestor) {
struct ast_callid *callid = ast_channel_callid(requestor);
if (callid) {
+ ast_channel_lock(c);
ast_channel_callid_set(c, callid);
+ ast_channel_unlock(c);
callid = ast_callid_unref(callid);
}
}
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
RAII_VAR(struct ast_channel_snapshot *, one_snapshot, NULL, ao2_cleanup);
RAII_VAR(struct ast_channel_snapshot *, two_snapshot, NULL, ao2_cleanup);
- SCOPED_AO2LOCK(lock, p);
+ struct ast_channel *owner;
+ struct ast_channel *chan;
+
+ ast_unreal_lock_all(&p->base, &chan, &owner);
blob = ast_json_pack("{s: s, s: s, s: b}",
"context", p->context,
"exten", p->exten,
"can_optimize", !ast_test_flag(&p->base, AST_UNREAL_NO_OPTIMIZATION));
if (!blob) {
- return;
+ goto end;
}
multi_blob = ast_multi_channel_blob_create(blob);
if (!multi_blob) {
- return;
+ goto end;
}
- one_snapshot = ast_channel_snapshot_create(p->base.owner);
+ one_snapshot = ast_channel_snapshot_create(owner);
if (!one_snapshot) {
- return;
+ goto end;
}
- two_snapshot = ast_channel_snapshot_create(p->base.chan);
+ two_snapshot = ast_channel_snapshot_create(chan);
if (!two_snapshot) {
- return;
+ goto end;
}
ast_multi_channel_blob_add_channel(multi_blob, "1", one_snapshot);
msg = stasis_message_create(ast_local_bridge_type(), multi_blob);
if (!msg) {
- return;
+ goto end;
}
- stasis_publish(ast_channel_topic(p->base.owner), msg);
+ stasis_publish(ast_channel_topic(owner), msg);
+
+end:
+ ast_channel_unlock(owner);
+ ast_channel_unlock(chan);
+ ao2_unlock(p);
}
int ast_local_setup_bridge(struct ast_channel *ast, struct ast_bridge *bridge, struct ast_channel *swap, struct ast_bridge_features *features)
}
if (callid) {
+ ast_channel_lock(owner);
ast_channel_callid_set(owner, callid);
+ ast_channel_unlock(owner);
+ ast_channel_lock(chan);
ast_channel_callid_set(chan, callid);
+ ast_channel_unlock(chan);
}
ast_channel_tech_set(owner, tech);
cap_request = NULL;
cap_all_audio = ast_format_cap_destroy(cap_all_audio);
+ ast_channel_lock(channel->owner);
ast_channel_stage_snapshot(channel->owner);
ast_channel_appl_set(channel->owner, "AppDial2");
}
ast_channel_stage_snapshot_done(channel->owner);
+ ast_channel_unlock(channel->owner);
return 0;
}
ast_str_container_add(endpoint->channel_ids, ast_channel_uniqueid(chan));
ao2_unlock(endpoint);
+ ast_channel_lock(chan);
ast_publish_channel_state(chan);
+ ast_channel_unlock(chan);
endpoint_publish_snapshot(endpoint);
return 0;
saved_c_appl= ast_channel_appl(c);
saved_c_data= ast_channel_data(c);
+ ast_channel_lock(c);
ast_channel_appl_set(c, app->name);
ast_channel_data_set(c, data);
ast_channel_publish_snapshot(c);
+ ast_channel_unlock(c);
if (app->module)
u = __ast_module_user_add(app->module, c);
if (!callid) {
callid = ast_create_callid();
if (callid) {
+ ast_channel_lock(c);
ast_channel_callid_set(c, callid);
+ ast_channel_unlock(c);
}
}
ast_callid_threadassoc_add(callid);
return -1;
}
+ ast_channel_lock(dialed);
if (vars) {
ast_set_variables(dialed, vars);
}
ast_channel_accountcode_set(dialed, account);
}
ast_set_flag(ast_channel_flags(dialed), AST_FLAG_ORIGINATED);
+ ast_channel_unlock(dialed);
if (!ast_strlen_zero(cid_num) || !ast_strlen_zero(cid_name)) {
struct ast_party_connected_line connected;
if (failed) {
char failed_reason[4] = "";
+ ast_channel_lock(failed);
if (!ast_strlen_zero(context)) {
ast_channel_context_set(failed, context);
}
ast_set_variables(failed, vars);
snprintf(failed_reason, sizeof(failed_reason), "%d", ast_dial_reason(outgoing->dial, 0));
pbx_builtin_setvar_helper(failed, "REASON", failed_reason);
+ ast_channel_unlock(failed);
if (ast_pbx_run(failed)) {
ast_log(LOG_ERROR, "Unable to run PBX on '%s'\n", ast_channel_name(failed));
ast_indicate(chan, AST_CONTROL_BUSY);
/* Don't change state of an UP channel, just indicate
busy in audio */
+ ast_channel_lock(chan);
if (ast_channel_state(chan) != AST_STATE_UP) {
ast_channel_hangupcause_set(chan, AST_CAUSE_BUSY);
ast_setstate(chan, AST_STATE_BUSY);
}
+ ast_channel_unlock(chan);
wait_for_hangup(chan, data);
return -1;
}
ast_indicate(chan, AST_CONTROL_CONGESTION);
/* Don't change state of an UP channel, just indicate
congestion in audio */
+ ast_channel_lock(chan);
if (ast_channel_state(chan) != AST_STATE_UP) {
ast_channel_hangupcause_set(chan, AST_CAUSE_CONGESTION);
ast_setstate(chan, AST_STATE_BUSY);
}
+ ast_channel_unlock(chan);
wait_for_hangup(chan, data);
return -1;
}
/* setting the HANGUPCAUSE so the ringing channel knows this call was not a missed call */
ast_channel_hangupcause_set(chan, AST_CAUSE_ANSWERED_ELSEWHERE);
- if (!(chan_snapshot = ast_channel_snapshot_create(chan))) {
+ ast_channel_lock(chan);
+ chan_snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
+ if (!chan_snapshot) {
goto pickup_failed;
}
- if (!(target_snapshot = ast_channel_snapshot_create(target))) {
+ ast_channel_lock(target);
+ target_snapshot = ast_channel_snapshot_create(target);
+ ast_channel_unlock(target);
+ if (!target_snapshot) {
goto pickup_failed;
}
}
if (chan) {
+ ast_channel_lock(chan);
obj->channel = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
if (obj->channel == NULL) {
return NULL;
}
}
}
+ ast_channel_lock(pair->channel);
snapshot_pair->channel_snapshot = ast_channel_snapshot_create(pair->channel);
+ ast_channel_unlock(pair->channel);
if (!snapshot_pair->channel_snapshot) {
return -1;
}
transfer_msg->dest_type = AST_ATTENDED_TRANSFER_DEST_LINK;
for (i = 0; i < 2; ++i) {
+ ast_channel_lock(locals[i]);
transfer_msg->dest.links[i] = ast_channel_snapshot_create(locals[i]);
+ ast_channel_unlock(locals[i]);
if (!transfer_msg->dest.links[i]) {
return;
}
}
if (caller) {
+ ast_channel_lock(caller);
caller_snapshot = ast_channel_snapshot_create(caller);
+ ast_channel_unlock(caller);
if (!caller_snapshot) {
return;
}
ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
}
+ ast_channel_lock(peer);
peer_snapshot = ast_channel_snapshot_create(peer);
+ ast_channel_unlock(peer);
if (!peer_snapshot) {
return;
}
term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
+ ast_channel_lock(chan);
snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
if (snapshot) {
/* pbx_exec sets application name and data, but we don't want to log
* every exec. Just update the snapshot here instead.
/* Set parking timeout channel variables */
snprintf(parking_space, sizeof(parking_space), "%d", user->parking_space);
+ ast_channel_lock(chan);
ast_channel_stage_snapshot(chan);
pbx_builtin_setvar_helper(chan, "PARKING_SPACE", parking_space);
pbx_builtin_setvar_helper(chan, "PARKINGSLOT", parking_space); /* Deprecated version of PARKING_SPACE */
pbx_builtin_setvar_helper(chan, "PARKER_FLAT", dial_string_flat);
parking_timeout_set_caller_features(chan, user->lot->cfg);
ast_channel_stage_snapshot_done(chan);
+ ast_channel_unlock(chan);
/* Dialplan generation for park-dial extensions */
RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup);
RAII_VAR(struct ast_channel_snapshot *, parkee_snapshot, NULL, ao2_cleanup);
+ ast_channel_lock(chan);
parkee_snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
if (!parkee_snapshot) {
return NULL;
}
struct timeval now = ast_tvnow();
const char *lot_name = pu->lot->name;
+ ast_channel_lock(pu->chan);
parkee_snapshot = ast_channel_snapshot_create(pu->chan);
+ ast_channel_unlock(pu->chan);
if (!parkee_snapshot) {
return NULL;
to execute based on the setup info */
ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
startblob = ast_json_pack("{s: s}", "Env", ami_buffer);
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, agi_async_start_type(), startblob);
hungup = ast_check_hangup(chan);
+ ast_channel_unlock(chan);
for (;;) {
/*
* Process as many commands as we can. Commands are added via
if (execblob && !ast_strlen_zero(cmd->cmd_id)) {
ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id));
}
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, agi_async_exec_type(), execblob);
+ ast_channel_unlock(chan);
free_agi_cmd(cmd);
ast_speech_destroy(async_agi.speech);
}
/* notify manager users this channel cannot be controlled anymore by Async AGI */
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, agi_async_end_type(), NULL);
+ ast_channel_unlock(chan);
async_agi_abort:
/* close the pipe */
whentohangup.tv_sec = timeout;
whentohangup.tv_usec = (timeout - whentohangup.tv_sec) * 1000000.0;
}
+ ast_channel_lock(chan);
ast_channel_setwhentohangup_tv(chan, whentohangup);
+ ast_channel_unlock(chan);
ast_agi_send(agi->fd, chan, "200 result=0\n");
return RESULT_SUCCESS;
}
"Command", command,
"ResultCode", result_code,
"Result", result);
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, agi_exec_end_type(), blob);
+ ast_channel_unlock(chan);
}
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
startblob = ast_json_pack("{s: i, s: s}",
"CommandId", command_id,
"Command", ami_cmd);
+ ast_channel_lock(chan);
ast_channel_publish_blob(chan, agi_exec_start_type(), startblob);
+ ast_channel_unlock(chan);
parse_args(buf, &argc, argv);
c = find_command(argv, 0);
goto end;
}
+ ast_channel_lock(session->channel);
ast_setstate(session->channel, AST_STATE_RING);
+ ast_channel_unlock(session->channel);
ast_raw_answer(session->channel);
if (!invite.bridge) {
ast_assert(chan != NULL);
/* Set channel info */
+ ast_channel_lock(chan);
snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
if (!snapshot) {
return -1;
}
ast_assert(chan != NULL);
/* Set channel info */
+ ast_channel_lock(chan);
snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
if (snapshot == NULL) {
return -1;
}
if ((priority) > 0) { \
ast_channel_priority_set((channel), (priority)); \
} \
+ ast_channel_lock((channel)); \
ast_channel_appl_set((channel), (application)); \
ast_channel_data_set((channel), (data)); \
ast_channel_publish_snapshot((channel)); \
+ ast_channel_unlock((channel)); \
} while (0)
/*! \brief Hang up a test channel safely */
SWAP_CONFIG(config, debug_cdr_config);
CREATE_ALICE_CHANNEL(chan, &caller, &expected);
+ ast_channel_lock(chan);
EMULATE_APP_DATA(chan, 1, "Answer", "");
ast_setstate(chan, AST_STATE_UP);
EMULATE_APP_DATA(chan, 2, "VoiceMailMain", "1");
+ ast_channel_unlock(chan);
HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
SWAP_CONFIG(config, debug_cdr_config);
CREATE_ALICE_CHANNEL(chan, &caller, &expected);
+ ast_channel_lock(chan);
EMULATE_APP_DATA(chan, 1, "Answer", "");
ast_setstate(chan, AST_STATE_UP);
EMULATE_APP_DATA(chan, 2, "Bridge", "");
+ ast_channel_unlock(chan);
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
CREATE_ALICE_CHANNEL(chan, &caller, &expected_one);
COPY_IDS(chan, &expected_two);
+ ast_channel_lock(chan);
EMULATE_APP_DATA(chan, 1, "Answer", "");
ast_setstate(chan, AST_STATE_UP);
EMULATE_APP_DATA(chan, 2, "Bridge", "");
+ ast_channel_unlock(chan);
bridge_one = ast_bridge_basic_new();
ast_test_validate(test, bridge_one != NULL);
CREATE_BOB_CHANNEL(chan_bob, &caller_bob, &bob_expected);
ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(bob_expected.linkedid));
+ ast_channel_lock(chan_alice);
EMULATE_APP_DATA(chan_alice, 1, "Answer", "");
ast_setstate(chan_alice, AST_STATE_UP);
EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
+ ast_channel_unlock(chan_alice);
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+ ast_channel_lock(chan_bob);
EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
ast_setstate(chan_bob, AST_STATE_UP);
EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
+ ast_channel_unlock(chan_bob);
ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
CREATE_BOB_CHANNEL(chan_bob, &caller_bob, &bob_expected);
ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(bob_expected.linkedid));
+ ast_channel_unlock(chan_alice);
EMULATE_APP_DATA(chan_alice, 1, "Answer", "");
ast_setstate(chan_alice, AST_STATE_UP);
EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
+ ast_channel_unlock(chan_alice);
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
+ ast_channel_lock(chan_bob);
EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
ast_setstate(chan_bob, AST_STATE_UP);
EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
+ ast_channel_unlock(chan_bob);
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
CREATE_CHARLIE_CHANNEL(chan_charlie, &caller_charlie, &charlie_expected);
ast_copy_string(charlie_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(charlie_expected.linkedid));
+ ast_channel_lock(chan_alice);
EMULATE_APP_DATA(chan_alice, 1, "Answer", "");
ast_setstate(chan_alice, AST_STATE_UP);
EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
+ ast_channel_unlock(chan_alice);
bridge = ast_bridge_basic_new();
ast_test_validate(test, bridge != NULL);
ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+ ast_channel_lock(chan_bob);
EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
ast_setstate(chan_bob, AST_STATE_UP);
EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
+ ast_channel_unlock(chan_bob);
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+ ast_channel_lock(chan_charlie);
EMULATE_APP_DATA(chan_charlie, 1, "Answer", "");
ast_setstate(chan_charlie, AST_STATE_UP);
EMULATE_APP_DATA(chan_charlie, 2, "Bridge", "");
+ ast_channel_unlock(chan_charlie);
ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
CREATE_ALICE_CHANNEL(chan_alice, &alice_caller, &alice_expected);
CREATE_BOB_CHANNEL(chan_bob, &bob_caller, &bob_expected);
+ ast_channel_lock(chan_alice);
EMULATE_APP_DATA(chan_alice, 1, "Park", "700");
ast_setstate(chan_alice, AST_STATE_UP);
+ ast_channel_unlock(chan_alice);
+
+ ast_channel_lock(chan_bob);
EMULATE_APP_DATA(chan_bob, 1, "Park", "701");
ast_setstate(chan_bob, AST_STATE_UP);
+ ast_channel_unlock(chan_bob);
bridge = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_HOLDING,
AST_BRIDGE_FLAG_MERGE_INHIBIT_TO | AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
ast_copy_string(fork_expected_two.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_two.linkedid));
/* Channel enters Wait app */
+ ast_channel_lock(chan);
ast_channel_appl_set(chan, "Wait");
ast_channel_data_set(chan, "10");
ast_channel_priority_set(chan, 1);
/* Set properties on the channel that propagate to the CDR */
ast_channel_amaflags_set(chan, AST_AMA_OMIT);
ast_channel_accountcode_set(chan, "XXX");
+ ast_channel_unlock(chan);
/* Wait one second so we get a duration. */
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
/* Channel enters Answer app */
+ ast_channel_lock(chan);
ast_channel_appl_set(chan, "Answer");
ast_channel_data_set(chan, "");
ast_channel_priority_set(chan, 1);
/* Set properties on the last record */
ast_channel_accountcode_set(chan, "ZZZ");
+ ast_channel_unlock(chan);
ast_cdr_setuserfield(ast_channel_name(chan), "schmackity");
ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_2") == 0);
ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
/* Test keep variables; setting a new answer time */
+ ast_channel_lock(chan);
ast_setstate(chan, AST_STATE_UP);
+ ast_channel_unlock(chan);
while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_2") == 0);
ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", varbuffer, sizeof(varbuffer)) == 0);
CREATE_ALICE_CHANNEL(chan_alice, &alice_caller);
CREATE_BOB_CHANNEL(chan_bob, &bob_caller);
+ ast_channel_lock(chan_alice);
alice_snapshot = ast_channel_snapshot_create(chan_alice);
+ ast_channel_unlock(chan_alice);
ast_test_validate(test, alice_snapshot != NULL);
+ ast_channel_lock(chan_bob);
bob_snapshot = ast_channel_snapshot_create(chan_bob);
+ ast_channel_unlock(chan_bob);
ast_test_validate(test, bob_snapshot != NULL);
ast_multi_channel_blob_add_channel(mc_blob, "1", alice_snapshot);
const char *peer)
{
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ ast_channel_lock(chan);
snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
if (!snapshot) {
return -1;
}
"foo", "bar");
/* Off nominal creation */
+ ast_channel_lock(chan);
ast_test_validate(test, NULL == ast_channel_blob_create(chan, NULL, json));
/* Test for single channel */
msg = ast_channel_blob_create(chan, type, json);
+ ast_channel_unlock(chan);
ast_test_validate(test, NULL != msg);
blob = stasis_message_data(msg);
ast_test_validate(test, NULL != blob);
"foo", "bar");
/* Test for single channel */
+ ast_channel_lock(chan);
msg = ast_channel_blob_create(chan, type, NULL);
+ ast_channel_unlock(chan);
ast_test_validate(test, NULL != msg);
blob = stasis_message_data(msg);
ast_test_validate(test, NULL != blob);
chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Bob", "300", "300", "default", NULL, 0, "TEST/Charlie");
blob = ast_multi_channel_blob_create(json);
+ ast_channel_lock(chan_alice);
ast_multi_channel_blob_add_channel(blob, "Caller", ast_channel_snapshot_create(chan_alice));
+ ast_channel_unlock(chan_alice);
+ ast_channel_lock(chan_bob);
ast_multi_channel_blob_add_channel(blob, "Peer", ast_channel_snapshot_create(chan_bob));
+ ast_channel_unlock(chan_bob);
+ ast_channel_lock(chan_charlie);
ast_multi_channel_blob_add_channel(blob, "Peer", ast_channel_snapshot_create(chan_charlie));
+ ast_channel_unlock(chan_charlie);
/* Test for unknown role */
ast_test_validate(test, NULL == ast_multi_channel_blob_get_channel(blob, "Foobar"));
chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, 0, "TEST/name");
ast_test_validate(test, NULL != chan);
+ ast_channel_lock(chan);
snapshot = ast_channel_snapshot_create(chan);
+ ast_channel_unlock(chan);
ast_test_validate(test, NULL != snapshot);
actual = ast_channel_snapshot_to_json(snapshot, NULL);