Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
/*! The name of the state. Used for debugging */
const char *state_name;
/*! Function used to enter a state */
int (*enter)(struct attended_transfer_properties *props);
/*!
* Function used to exit a state
* This is used both to determine what the next state
* to transition to will be and to perform any cleanup
* necessary before exiting the current state.
*/
enum attended_transfer_state (*exit)(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus);
/*! Flags associated with this state */
enum attended_transfer_state_flags flags;
};
static const struct attended_transfer_state_properties state_properties[] = {
[TRANSFER_CALLING_TARGET] = {
.state_name = "Calling Target",
.enter = calling_target_enter,
.exit = calling_target_exit,
.flags = TRANSFER_STATE_FLAG_ATXFER_NO_ANSWER | TRANSFER_STATE_FLAG_TIMER_RESET,
},
[TRANSFER_HESITANT] = {
.state_name = "Hesitant",
.enter = hesitant_enter,
.exit = hesitant_exit,
.flags = TRANSFER_STATE_FLAG_ATXFER_NO_ANSWER,
},
[TRANSFER_REBRIDGE] = {
.state_name = "Rebridge",
.enter = rebridge_enter,
.flags = TRANSFER_STATE_FLAG_TERMINAL,
},
[TRANSFER_RESUME] = {
.state_name = "Resume",
.enter = resume_enter,
.flags = TRANSFER_STATE_FLAG_TERMINAL,
},
[TRANSFER_THREEWAY] = {
.state_name = "Threeway",
.enter = threeway_enter,
.flags = TRANSFER_STATE_FLAG_TERMINAL,
},
[TRANSFER_CONSULTING] = {
.state_name = "Consulting",
.enter = consulting_enter,
.exit = consulting_exit,
},
[TRANSFER_DOUBLECHECKING] = {
.state_name = "Double Checking",
.enter = double_checking_enter,
.exit = double_checking_exit,
},
[TRANSFER_COMPLETE] = {
.state_name = "Complete",
.enter = complete_enter,
.flags = TRANSFER_STATE_FLAG_TERMINAL,
},
[TRANSFER_BLOND] = {
.state_name = "Blond",
.enter = blond_enter,
.flags = TRANSFER_STATE_FLAG_TERMINAL,
},
[TRANSFER_BLOND_NONFINAL] = {
.state_name = "Blond Non-Final",
.enter = blond_nonfinal_enter,
.exit = blond_nonfinal_exit,
.flags = TRANSFER_STATE_FLAG_ATXFER_NO_ANSWER,
},
[TRANSFER_RECALLING] = {
.state_name = "Recalling",
.enter = recalling_enter,
.exit = recalling_exit,
.flags = TRANSFER_STATE_FLAG_ATXFER_NO_ANSWER | TRANSFER_STATE_FLAG_TIMER_RESET,
},
[TRANSFER_WAIT_TO_RETRANSFER] = {
.state_name = "Wait to Retransfer",
.enter = wait_to_retransfer_enter,
.exit = wait_to_retransfer_exit,
.flags = TRANSFER_STATE_FLAG_TIMER_RESET | TRANSFER_STATE_FLAG_TIMER_LOOP_DELAY,
},
[TRANSFER_RETRANSFER] = {
.state_name = "Retransfer",
.enter = retransfer_enter,
.exit = retransfer_exit,
.flags = TRANSFER_STATE_FLAG_ATXFER_NO_ANSWER | TRANSFER_STATE_FLAG_TIMER_RESET,
},
[TRANSFER_WAIT_TO_RECALL] = {
.state_name = "Wait to Recall",
.enter = wait_to_recall_enter,
.exit = wait_to_recall_exit,
.flags = TRANSFER_STATE_FLAG_TIMER_RESET | TRANSFER_STATE_FLAG_TIMER_LOOP_DELAY,
},
[TRANSFER_FAIL] = {
.state_name = "Fail",
.enter = fail_enter,
.flags = TRANSFER_STATE_FLAG_TERMINAL,
},
};
static int calling_target_enter(struct attended_transfer_properties *props)
{
Richard Mudgett
committed
bridge_move(props->target_bridge, props->transferee_bridge, props->transferer, NULL);
return 0;
}
static enum attended_transfer_state calling_target_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
play_failsound(props->transferer);
publish_transfer_fail(props);
return TRANSFER_FAIL;
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_TRANSFERER_HANGUP:
bridge_unhold(props->transferee_bridge);
return props->atxferdropcall ? TRANSFER_BLOND : TRANSFER_BLOND_NONFINAL;
case STIMULUS_TRANSFER_TARGET_ANSWER:
return TRANSFER_CONSULTING;
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TIMEOUT:
case STIMULUS_DTMF_ATXFER_ABORT:
play_failsound(props->transferer);
return TRANSFER_REBRIDGE;
case STIMULUS_DTMF_ATXFER_THREEWAY:
bridge_unhold(props->transferee_bridge);
return TRANSFER_THREEWAY;
case STIMULUS_DTMF_ATXFER_SWAP:
return TRANSFER_HESITANT;
case STIMULUS_NONE:
case STIMULUS_RECALL_TARGET_ANSWER:
case STIMULUS_RECALL_TARGET_HANGUP:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int hesitant_enter(struct attended_transfer_properties *props)
{
Richard Mudgett
committed
bridge_move(props->transferee_bridge, props->target_bridge, props->transferer, NULL);
unhold(props->transferer);
return 0;
}
static enum attended_transfer_state hesitant_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
play_failsound(props->transferer);
publish_transfer_fail(props);
return TRANSFER_FAIL;
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_TRANSFERER_HANGUP:
return props->atxferdropcall ? TRANSFER_BLOND : TRANSFER_BLOND_NONFINAL;
case STIMULUS_TRANSFER_TARGET_ANSWER:
return TRANSFER_DOUBLECHECKING;
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TIMEOUT:
case STIMULUS_DTMF_ATXFER_ABORT:
play_failsound(props->transferer);
return TRANSFER_RESUME;
case STIMULUS_DTMF_ATXFER_THREEWAY:
return TRANSFER_THREEWAY;
case STIMULUS_DTMF_ATXFER_SWAP:
hold(props->transferer);
return TRANSFER_CALLING_TARGET;
case STIMULUS_NONE:
case STIMULUS_RECALL_TARGET_HANGUP:
case STIMULUS_RECALL_TARGET_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int rebridge_enter(struct attended_transfer_properties *props)
{
Richard Mudgett
committed
bridge_move(props->transferee_bridge, props->target_bridge, props->transferer, NULL);
unhold(props->transferer);
return 0;
}
static int resume_enter(struct attended_transfer_properties *props)
{
return 0;
}
static int threeway_enter(struct attended_transfer_properties *props)
{
struct ast_channel *transferee_channel;
struct ast_channel *target_channel;
get_transfer_parties(props->transferer, props->transferee_bridge, props->target_bridge,
&transferee_channel, &target_channel);
bridge_merge(props->transferee_bridge, props->target_bridge, NULL, 0);
play_sound(props->transfer_target, props->xfersound);
play_sound(props->transferer, props->xfersound);
publish_transfer_threeway(props, transferee_channel, target_channel);
ast_channel_cleanup(transferee_channel);
ast_channel_cleanup(target_channel);
return 0;
}
static int consulting_enter(struct attended_transfer_properties *props)
{
return 0;
}
static enum attended_transfer_state consulting_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
/* This is a one-of-a-kind event. The transferer and transfer target are talking in
* one bridge, and the transferee has hung up in a separate bridge. In this case, we
* will change the personality of the transfer target bridge back to normal, and play
* a sound to the transferer to indicate the transferee is gone.
*/
bridge_basic_change_personality(props->target_bridge, BRIDGE_BASIC_PERSONALITY_NORMAL, NULL);
play_failsound(props->transferer);
ast_bridge_merge_inhibit(props->target_bridge, -1);
/* These next two lines are here to ensure that our reference to the target bridge
* is cleaned up properly and that the target bridge is not destroyed when the
* monitor thread exits
*/
ao2_ref(props->target_bridge, -1);
props->target_bridge = NULL;
return TRANSFER_FAIL;
case STIMULUS_TRANSFERER_HANGUP:
case STIMULUS_DTMF_ATXFER_COMPLETE:
/* We know the transferer is in the target_bridge, so take the other bridge off hold */
bridge_unhold(props->transferee_bridge);
return TRANSFER_COMPLETE;
case STIMULUS_TRANSFER_TARGET_HANGUP:
Kevin Harwell
committed
return TRANSFER_REBRIDGE;
case STIMULUS_DTMF_ATXFER_ABORT:
play_failsound(props->transferer);
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
return TRANSFER_REBRIDGE;
case STIMULUS_DTMF_ATXFER_THREEWAY:
bridge_unhold(props->transferee_bridge);
return TRANSFER_THREEWAY;
case STIMULUS_DTMF_ATXFER_SWAP:
hold(props->transferer);
bridge_move(props->transferee_bridge, props->target_bridge, props->transferer, NULL);
unhold(props->transferer);
return TRANSFER_DOUBLECHECKING;
case STIMULUS_NONE:
case STIMULUS_TIMEOUT:
case STIMULUS_TRANSFER_TARGET_ANSWER:
case STIMULUS_RECALL_TARGET_HANGUP:
case STIMULUS_RECALL_TARGET_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int double_checking_enter(struct attended_transfer_properties *props)
{
return 0;
}
static enum attended_transfer_state double_checking_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
play_failsound(props->transferer);
publish_transfer_fail(props);
return TRANSFER_FAIL;
case STIMULUS_TRANSFERER_HANGUP:
case STIMULUS_DTMF_ATXFER_COMPLETE:
/* We know the transferer is in the transferee, so take the other bridge off hold */
bridge_unhold(props->target_bridge);
return TRANSFER_COMPLETE;
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_DTMF_ATXFER_ABORT:
play_failsound(props->transferer);
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
return TRANSFER_RESUME;
case STIMULUS_DTMF_ATXFER_THREEWAY:
bridge_unhold(props->target_bridge);
return TRANSFER_THREEWAY;
case STIMULUS_DTMF_ATXFER_SWAP:
hold(props->transferer);
bridge_move(props->target_bridge, props->transferee_bridge, props->transferer, NULL);
unhold(props->transferer);
return TRANSFER_CONSULTING;
case STIMULUS_NONE:
case STIMULUS_TIMEOUT:
case STIMULUS_TRANSFER_TARGET_ANSWER:
case STIMULUS_RECALL_TARGET_HANGUP:
case STIMULUS_RECALL_TARGET_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int complete_enter(struct attended_transfer_properties *props)
{
struct ast_channel *transferee_channel;
struct ast_channel *target_channel;
get_transfer_parties(props->transferer, props->transferee_bridge, props->target_bridge,
&transferee_channel, &target_channel);
bridge_merge(props->transferee_bridge, props->target_bridge, &props->transferer, 1);
play_sound(props->transfer_target, props->xfersound);
publish_transfer_success(props, transferee_channel, target_channel);
ast_channel_cleanup(transferee_channel);
ast_channel_cleanup(target_channel);
return 0;
}
static int blond_enter(struct attended_transfer_properties *props)
{
struct ast_channel *transferee_channel;
struct ast_channel *target_channel;
get_transfer_parties(props->transferer, props->transferee_bridge, props->target_bridge,
&transferee_channel, &target_channel);
bridge_merge(props->transferee_bridge, props->target_bridge, &props->transferer, 1);
ringing(props->transfer_target);
publish_transfer_success(props, transferee_channel, target_channel);
ast_channel_cleanup(transferee_channel);
ast_channel_cleanup(target_channel);
return 0;
}
static int blond_nonfinal_enter(struct attended_transfer_properties *props)
{
int res;
props->superstate = SUPERSTATE_RECALL;
/* move the transfer target to the recall target along with its reference */
props->recall_target = ast_channel_ref(props->transfer_target);
res = blond_enter(props);
props->transfer_target = ast_channel_unref(props->transfer_target);
return res;
}
static enum attended_transfer_state blond_nonfinal_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
return TRANSFER_FAIL;
case STIMULUS_RECALL_TARGET_ANSWER:
return TRANSFER_RESUME;
case STIMULUS_TIMEOUT:
ast_softhangup(props->recall_target, AST_SOFTHANGUP_EXPLICIT);
/* It is possible before we hung them up that they queued up a recall target answer
* so we remove it if present as it should not exist.
*/
remove_attended_transfer_stimulus(props, STIMULUS_RECALL_TARGET_ANSWER);
case STIMULUS_RECALL_TARGET_HANGUP:
props->recall_target = ast_channel_unref(props->recall_target);
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
return TRANSFER_RECALLING;
case STIMULUS_NONE:
case STIMULUS_DTMF_ATXFER_ABORT:
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_DTMF_ATXFER_THREEWAY:
case STIMULUS_DTMF_ATXFER_SWAP:
case STIMULUS_TRANSFERER_HANGUP:
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TRANSFER_TARGET_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
/*!
* \brief Dial callback when attempting to recall the original transferer channel
*
* This is how we can monitor if the recall target has answered or has hung up.
* If one of the two is detected, then an appropriate stimulus is sent to the
* attended transfer monitor thread.
*/
static void recall_callback(struct ast_dial *dial)
{
struct attended_transfer_properties *props = ast_dial_get_user_data(dial);
switch (ast_dial_state(dial)) {
default:
case AST_DIAL_RESULT_INVALID:
case AST_DIAL_RESULT_FAILED:
case AST_DIAL_RESULT_TIMEOUT:
case AST_DIAL_RESULT_HANGUP:
case AST_DIAL_RESULT_UNANSWERED:
/* Failure cases */
stimulate_attended_transfer(props, STIMULUS_RECALL_TARGET_HANGUP);
break;
case AST_DIAL_RESULT_RINGING:
case AST_DIAL_RESULT_PROGRESS:
case AST_DIAL_RESULT_PROCEEDING:
case AST_DIAL_RESULT_TRYING:
/* Don't care about these cases */
break;
case AST_DIAL_RESULT_ANSWERED:
/* We struck gold! */
props->recall_target = ast_dial_answered_steal(dial);
stimulate_attended_transfer(props, STIMULUS_RECALL_TARGET_ANSWER);
break;
}
}
Richard Mudgett
committed
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
/*!
* \internal
* \brief Setup common things to transferrer and transfer_target recall channels.
*
* \param recall Channel for recalling a party.
* \param transferer Channel supplying recall information.
*
* \details
* Setup callid, variables, datastores, accountcode, and peeraccount.
*
* \pre Both channels are locked on entry.
*
* \pre COLP and CLID on the recall channel are setup by the caller but not
* explicitly published yet.
*
* \return Nothing
*/
static void common_recall_channel_setup(struct ast_channel *recall, struct ast_channel *transferer)
{
struct ast_callid *callid;
callid = ast_read_threadstorage_callid();
if (callid) {
ast_channel_callid_set(recall, callid);
ast_callid_unref(callid);
}
ast_channel_inherit_variables(transferer, recall);
ast_channel_datastore_inherit(transferer, recall);
/*
* Stage a snapshot to ensure that a snapshot is always done
* on the recall channel so earler COLP and CLID setup will
* get published.
*/
ast_channel_stage_snapshot(recall);
ast_channel_req_accountcodes(recall, transferer, AST_CHANNEL_REQUESTOR_REPLACEMENT);
ast_channel_stage_snapshot_done(recall);
}
static int recalling_enter(struct attended_transfer_properties *props)
{
RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
Richard Mudgett
committed
struct ast_channel *recall;
if (!cap) {
return -1;
}
ast_format_cap_append(cap, ast_format_slin, 0);
/* When we dial the transfer target, since we are communicating
* with a local channel, we can place the local channel in a bridge
* and then call out to it. When recalling the transferer, though, we
* have to use the dialing API because the channel is not local.
*/
props->dial = ast_dial_create();
if (!props->dial) {
return -1;
}
if (ast_dial_append(props->dial, props->transferer_type, props->transferer_addr, NULL)) {
return -1;
}
if (ast_dial_prerun(props->dial, NULL, cap)) {
return -1;
}
Richard Mudgett
committed
/*
* Setup callid, variables, datastores, accountcode, peeraccount,
* COLP, and CLID on the recalled transferrer.
*/
recall = ast_dial_get_channel(props->dial, 0);
if (!recall) {
return -1;
}
ast_channel_lock_both(recall, props->transferer);
ast_party_caller_copy(ast_channel_caller(recall),
ast_channel_caller(props->transferer));
ast_party_connected_line_copy(ast_channel_connected(recall),
&props->original_transferer_colp);
common_recall_channel_setup(recall, props->transferer);
ast_channel_unlock(recall);
ast_channel_unlock(props->transferer);
ast_dial_set_state_callback(props->dial, recall_callback);
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
ao2_ref(props, +1);
ast_dial_set_user_data(props->dial, props);
if (ast_dial_run(props->dial, NULL, 1) == AST_DIAL_RESULT_FAILED) {
ao2_ref(props, -1);
return -1;
}
bridge_ringing(props->transferee_bridge);
return 0;
}
static enum attended_transfer_state recalling_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
/* No matter what the outcome was, we need to kill off the dial */
ast_dial_join(props->dial);
ast_dial_destroy(props->dial);
props->dial = NULL;
/* This reference is the one we incremented for the dial state callback (recall_callback) to use */
ao2_ref(props, -1);
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
return TRANSFER_FAIL;
case STIMULUS_TIMEOUT:
case STIMULUS_RECALL_TARGET_HANGUP:
++props->retry_attempts;
if (props->retry_attempts >= props->atxfercallbackretries) {
return TRANSFER_FAIL;
}
if (props->atxferloopdelay) {
return TRANSFER_WAIT_TO_RETRANSFER;
}
return TRANSFER_RETRANSFER;
case STIMULUS_RECALL_TARGET_ANSWER:
/* Setting this datastore up will allow the transferer to have all of his
* call features set up automatically when the bridge changes back to a
* normal personality
*/
ast_bridge_features_ds_set(props->recall_target, &props->transferer_features);
ast_channel_ref(props->recall_target);
if (ast_bridge_impart(props->transferee_bridge, props->recall_target, NULL, NULL,
AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
ast_hangup(props->recall_target);
ast_channel_unref(props->recall_target);
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
return TRANSFER_FAIL;
}
return TRANSFER_RESUME;
case STIMULUS_NONE:
case STIMULUS_DTMF_ATXFER_ABORT:
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_DTMF_ATXFER_THREEWAY:
case STIMULUS_DTMF_ATXFER_SWAP:
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TRANSFER_TARGET_ANSWER:
case STIMULUS_TRANSFERER_HANGUP:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int wait_to_retransfer_enter(struct attended_transfer_properties *props)
{
bridge_hold(props->transferee_bridge);
return 0;
}
static enum attended_transfer_state wait_to_retransfer_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
bridge_unhold(props->transferee_bridge);
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
return TRANSFER_FAIL;
case STIMULUS_TIMEOUT:
return TRANSFER_RETRANSFER;
case STIMULUS_NONE:
case STIMULUS_DTMF_ATXFER_ABORT:
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_DTMF_ATXFER_THREEWAY:
case STIMULUS_DTMF_ATXFER_SWAP:
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TRANSFER_TARGET_ANSWER:
case STIMULUS_TRANSFERER_HANGUP:
case STIMULUS_RECALL_TARGET_HANGUP:
case STIMULUS_RECALL_TARGET_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int attach_framehook(struct attended_transfer_properties *props, struct ast_channel *channel);
static int retransfer_enter(struct attended_transfer_properties *props)
{
RAII_VAR(struct ast_format_cap *, cap, ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
char destination[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];
int cause;
if (!cap) {
return -1;
}
snprintf(destination, sizeof(destination), "%s@%s", props->exten, props->context);
ast_format_cap_append(cap, ast_format_slin, 0);
/* Get a channel that is the destination we wish to call */
props->recall_target = ast_request("Local", cap, NULL, NULL, destination, &cause);
if (!props->recall_target) {
ast_log(LOG_ERROR, "Unable to request outbound channel for recall target\n");
return -1;
}
if (attach_framehook(props, props->recall_target)) {
ast_log(LOG_ERROR, "Unable to attach framehook to recall target\n");
ast_hangup(props->recall_target);
props->recall_target = NULL;
return -1;
}
Richard Mudgett
committed
/*
* Setup callid, variables, datastores, accountcode, peeraccount,
* and COLP on the recalled transfer target.
*/
ast_channel_lock_both(props->recall_target, props->transferer);
ast_party_connected_line_copy(ast_channel_connected(props->recall_target),
&props->original_transferer_colp);
ast_party_id_reset(&ast_channel_connected(props->recall_target)->priv);
common_recall_channel_setup(props->recall_target, props->recall_target);
ast_channel_unlock(props->recall_target);
ast_channel_unlock(props->transferer);
if (ast_call(props->recall_target, destination, 0)) {
ast_log(LOG_ERROR, "Unable to place outbound call to recall target\n");
ast_hangup(props->recall_target);
props->recall_target = NULL;
return -1;
}
ast_channel_ref(props->recall_target);
if (ast_bridge_impart(props->transferee_bridge, props->recall_target, NULL, NULL,
AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
ast_log(LOG_ERROR, "Unable to place recall target into bridge\n");
ast_hangup(props->recall_target);
ast_channel_unref(props->recall_target);
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
return -1;
}
return 0;
}
static enum attended_transfer_state retransfer_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
return TRANSFER_FAIL;
case STIMULUS_TIMEOUT:
ast_softhangup(props->recall_target, AST_SOFTHANGUP_EXPLICIT);
case STIMULUS_RECALL_TARGET_HANGUP:
props->recall_target = ast_channel_unref(props->recall_target);
if (props->atxferloopdelay) {
return TRANSFER_WAIT_TO_RECALL;
}
return TRANSFER_RECALLING;
case STIMULUS_RECALL_TARGET_ANSWER:
return TRANSFER_RESUME;
case STIMULUS_NONE:
case STIMULUS_DTMF_ATXFER_ABORT:
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_DTMF_ATXFER_THREEWAY:
case STIMULUS_DTMF_ATXFER_SWAP:
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TRANSFER_TARGET_ANSWER:
case STIMULUS_TRANSFERER_HANGUP:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int wait_to_recall_enter(struct attended_transfer_properties *props)
{
bridge_hold(props->transferee_bridge);
return 0;
}
static enum attended_transfer_state wait_to_recall_exit(struct attended_transfer_properties *props,
enum attended_transfer_stimulus stimulus)
{
bridge_unhold(props->transferee_bridge);
switch (stimulus) {
case STIMULUS_TRANSFEREE_HANGUP:
return TRANSFER_FAIL;
case STIMULUS_TIMEOUT:
return TRANSFER_RECALLING;
case STIMULUS_NONE:
case STIMULUS_DTMF_ATXFER_ABORT:
case STIMULUS_DTMF_ATXFER_COMPLETE:
case STIMULUS_DTMF_ATXFER_THREEWAY:
case STIMULUS_DTMF_ATXFER_SWAP:
case STIMULUS_TRANSFER_TARGET_HANGUP:
case STIMULUS_TRANSFER_TARGET_ANSWER:
case STIMULUS_TRANSFERER_HANGUP:
case STIMULUS_RECALL_TARGET_HANGUP:
case STIMULUS_RECALL_TARGET_ANSWER:
default:
ast_log(LOG_WARNING, "Unexpected stimulus '%s' received in attended transfer state '%s'\n",
stimulus_strs[stimulus], state_properties[props->state].state_name);
return props->state;
}
}
static int fail_enter(struct attended_transfer_properties *props)
{
if (props->transferee_bridge) {
Richard Mudgett
committed
ast_bridge_destroy(props->transferee_bridge, 0);
props->transferee_bridge = NULL;
}
return 0;
}
/*!
* \brief DTMF hook when transferer presses abort sequence.
*
* Sends a stimulus to the attended transfer monitor thread that the abort sequence has been pressed
*/
static int atxfer_abort(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
{
struct attended_transfer_properties *props = hook_pvt;
ast_debug(1, "Transferer on attended transfer %p pressed abort sequence\n", props);
stimulate_attended_transfer(props, STIMULUS_DTMF_ATXFER_ABORT);
return 0;
}
/*!
* \brief DTMF hook when transferer presses complete sequence.
*
* Sends a stimulus to the attended transfer monitor thread that the complete sequence has been pressed
*/
static int atxfer_complete(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
{
struct attended_transfer_properties *props = hook_pvt;
ast_debug(1, "Transferer on attended transfer %p pressed complete sequence\n", props);
stimulate_attended_transfer(props, STIMULUS_DTMF_ATXFER_COMPLETE);
return 0;
}
/*!
* \brief DTMF hook when transferer presses threeway sequence.
*
* Sends a stimulus to the attended transfer monitor thread that the threeway sequence has been pressed
*/
static int atxfer_threeway(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
{
struct attended_transfer_properties *props = hook_pvt;
ast_debug(1, "Transferer on attended transfer %p pressed threeway sequence\n", props);
stimulate_attended_transfer(props, STIMULUS_DTMF_ATXFER_THREEWAY);
return 0;
}
/*!
* \brief DTMF hook when transferer presses swap sequence.
*
* Sends a stimulus to the attended transfer monitor thread that the swap sequence has been pressed
*/
static int atxfer_swap(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
{
struct attended_transfer_properties *props = hook_pvt;
ast_debug(1, "Transferer on attended transfer %p pressed swap sequence\n", props);
stimulate_attended_transfer(props, STIMULUS_DTMF_ATXFER_SWAP);
return 0;
}
/*!
* \brief Hangup hook for transferer channel.
*
* Sends a stimulus to the attended transfer monitor thread that the transferer has hung up.
*/
static int atxfer_transferer_hangup(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
{
struct attended_transfer_properties *props = hook_pvt;
ast_debug(1, "Transferer on attended transfer %p hung up\n", props);
stimulate_attended_transfer(props, STIMULUS_TRANSFERER_HANGUP);
return 0;
}
/*!
* \brief Frame hook for transfer target channel
*
* This is used to determine if the transfer target or recall target has answered
* the outgoing call.
*
* When an answer is detected, a stimulus is sent to the attended transfer monitor
* thread to indicate that the transfer target or recall target has answered.
*
* \param chan The channel the framehook is attached to.
* \param frame The frame being read or written.
* \param event What is being done with the frame.
* \param data The attended transfer properties.
*/
static struct ast_frame *transfer_target_framehook_cb(struct ast_channel *chan,
struct ast_frame *frame, enum ast_framehook_event event, void *data)
{
struct attended_transfer_properties *props = data;
if (event == AST_FRAMEHOOK_EVENT_READ &&
frame && frame->frametype == AST_FRAME_CONTROL &&
frame->subclass.integer == AST_CONTROL_ANSWER &&
!ast_check_hangup(chan)) {
ast_debug(1, "Detected an answer for recall attempt on attended transfer %p\n", props);
if (props->superstate == SUPERSTATE_TRANSFER) {
stimulate_attended_transfer(props, STIMULUS_TRANSFER_TARGET_ANSWER);
} else {
stimulate_attended_transfer(props, STIMULUS_RECALL_TARGET_ANSWER);
}
ast_framehook_detach(chan, props->target_framehook_id);
props->target_framehook_id = -1;
}
return frame;
}
Joshua Colp
committed
/*! \brief Callback function which informs upstream if we are consuming a frame of a specific type */
static int transfer_target_framehook_consume(void *data, enum ast_frame_type type)
{
return (type == AST_FRAME_CONTROL ? 1 : 0);
}
static void transfer_target_framehook_destroy_cb(void *data)
{
struct attended_transfer_properties *props = data;
ao2_cleanup(props);
}
static int bridge_personality_atxfer_push(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
{
const char *abort_dtmf;
const char *complete_dtmf;
const char *threeway_dtmf;
const char *swap_dtmf;
struct bridge_basic_personality *personality = self->personality;
if (!ast_channel_has_role(bridge_channel->chan, AST_TRANSFERER_ROLE_NAME)) {
return 0;
}
abort_dtmf = ast_channel_get_role_option(bridge_channel->chan, AST_TRANSFERER_ROLE_NAME, "abort");
complete_dtmf = ast_channel_get_role_option(bridge_channel->chan, AST_TRANSFERER_ROLE_NAME, "complete");
threeway_dtmf = ast_channel_get_role_option(bridge_channel->chan, AST_TRANSFERER_ROLE_NAME, "threeway");
swap_dtmf = ast_channel_get_role_option(bridge_channel->chan, AST_TRANSFERER_ROLE_NAME, "swap");
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
if (!ast_strlen_zero(abort_dtmf) && ast_bridge_dtmf_hook(bridge_channel->features,
abort_dtmf, atxfer_abort, personality->details[personality->current].pvt, NULL,
AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE | AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
return -1;
}
if (!ast_strlen_zero(complete_dtmf) && ast_bridge_dtmf_hook(bridge_channel->features,
complete_dtmf, atxfer_complete, personality->details[personality->current].pvt, NULL,
AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE | AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
return -1;
}
if (!ast_strlen_zero(threeway_dtmf) && ast_bridge_dtmf_hook(bridge_channel->features,
threeway_dtmf, atxfer_threeway, personality->details[personality->current].pvt, NULL,
AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE | AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
return -1;
}
if (!ast_strlen_zero(swap_dtmf) && ast_bridge_dtmf_hook(bridge_channel->features,
swap_dtmf, atxfer_swap, personality->details[personality->current].pvt, NULL,
AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE | AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
return -1;
}
if (ast_bridge_hangup_hook(bridge_channel->features, atxfer_transferer_hangup,
personality->details[personality->current].pvt, NULL,
AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE | AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
return -1;
}
return 0;
}
static void transfer_pull(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct attended_transfer_properties *props)
{
if (self->num_channels > 1 || bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
return;
}
if (self->num_channels == 1) {
Richard Mudgett
committed
struct ast_bridge_channel *transferer_bridge_channel;
int not_transferer;
ast_channel_lock(props->transferer);
transferer_bridge_channel = ast_channel_get_bridge_channel(props->transferer);
ast_channel_unlock(props->transferer);
if (!transferer_bridge_channel) {
return;
}
Richard Mudgett
committed
not_transferer = AST_LIST_FIRST(&self->channels) != transferer_bridge_channel;
ao2_ref(transferer_bridge_channel, -1);
if (not_transferer) {
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
return;
}
}
/* Reaching this point means that either
* 1) The bridge has no channels in it
* 2) The bridge has one channel, and it's the transferer
* In either case, it indicates that the non-transferer parties
* are no longer in the bridge.
*/
if (self == props->transferee_bridge) {
stimulate_attended_transfer(props, STIMULUS_TRANSFEREE_HANGUP);
} else {
stimulate_attended_transfer(props, STIMULUS_TRANSFER_TARGET_HANGUP);
}
}
static void recall_pull(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel, struct attended_transfer_properties *props)
{
if (self == props->target_bridge) {
/* Once we're in the recall superstate, we no longer care about this bridge */
return;
}
if (bridge_channel->chan == props->recall_target) {
stimulate_attended_transfer(props, STIMULUS_RECALL_TARGET_HANGUP);
return;
}
if (self->num_channels == 0) {
/* Empty bridge means all transferees are gone for sure */
stimulate_attended_transfer(props, STIMULUS_TRANSFEREE_HANGUP);
return;
}
if (self->num_channels == 1) {
Richard Mudgett
committed
struct ast_bridge_channel *target_bridge_channel;
if (!props->recall_target) {
/* No recall target means that the pull happened on a transferee. If there's still
* a channel left in the bridge, we don't need to send a stimulus
*/
return;
}
ast_channel_lock(props->recall_target);
target_bridge_channel = ast_channel_get_bridge_channel(props->recall_target);
ast_channel_unlock(props->recall_target);
Richard Mudgett
committed
if (target_bridge_channel) {
if (AST_LIST_FIRST(&self->channels) == target_bridge_channel) {
stimulate_attended_transfer(props, STIMULUS_TRANSFEREE_HANGUP);
}
ao2_ref(target_bridge_channel, -1);
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
}
}
}
static void bridge_personality_atxfer_pull(struct ast_bridge *self, struct ast_bridge_channel *bridge_channel)
{
struct bridge_basic_personality *personality = self->personality;
struct attended_transfer_properties *props = personality->details[personality->current].pvt;
switch (props->superstate) {
case SUPERSTATE_TRANSFER:
transfer_pull(self, bridge_channel, props);
break;
case SUPERSTATE_RECALL:
recall_pull(self, bridge_channel, props);
break;
}
}
static enum attended_transfer_stimulus wait_for_stimulus(struct attended_transfer_properties *props)
{
Richard Mudgett
committed
enum attended_transfer_stimulus stimulus;