bridge_after.h File Reference

After Bridge Execution API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* ast_bridge_after_cb )(struct ast_channel *chan, void *data)
 After bridge callback function.
typedef void(* ast_bridge_after_cb_failed )(enum ast_bridge_after_cb_reason reason, void *data)
 After bridge callback failed.

Enumerations

enum  ast_bridge_after_cb_reason {
  AST_BRIDGE_AFTER_CB_REASON_DESTROY, AST_BRIDGE_AFTER_CB_REASON_REPLACED, AST_BRIDGE_AFTER_CB_REASON_MASQUERADE, AST_BRIDGE_AFTER_CB_REASON_DEPART,
  AST_BRIDGE_AFTER_CB_REASON_REMOVED
}

Functions

const char * ast_bridge_after_cb_reason_string (enum ast_bridge_after_cb_reason reason)
 Get a string representation of an after bridge callback reason.
void ast_bridge_discard_after_callback (struct ast_channel *chan, enum ast_bridge_after_cb_reason reason)
 Run discarding any after bridge callbacks.
void ast_bridge_discard_after_goto (struct ast_channel *chan)
 Discard channel after bridge goto location.
void ast_bridge_read_after_goto (struct ast_channel *chan, char *buffer, size_t buf_size)
 Read after bridge goto if it exists.
void ast_bridge_run_after_callback (struct ast_channel *chan)
 Run any after bridge callback.
void ast_bridge_run_after_goto (struct ast_channel *chan)
 Run a PBX on any after bridge goto location.
int ast_bridge_set_after_callback (struct ast_channel *chan, ast_bridge_after_cb callback, ast_bridge_after_cb_failed failed, void *data)
 Setup an after bridge callback for when the channel leaves the bridging system.
void ast_bridge_set_after_go_on (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *parseable_goto)
 Set channel to go on in the dialplan after the bridge.
void ast_bridge_set_after_goto (struct ast_channel *chan, const char *context, const char *exten, int priority)
 Set channel to goto specific location after the bridge.
void ast_bridge_set_after_h (struct ast_channel *chan, const char *context)
 Set channel to run the h exten after the bridge.
int ast_bridge_setup_after_goto (struct ast_channel *chan)
 Setup any after bridge goto location to begin execution.


Detailed Description

After Bridge Execution API.

Author:
Richard Mudgett <rmudgett@digium.com>
See Also:

Definition in file bridge_after.h.


Typedef Documentation

typedef void(* ast_bridge_after_cb)(struct ast_channel *chan, void *data)

After bridge callback function.

Since:
12.0.0
Parameters:
chan Channel just leaving bridging system.
data Extra data what setup the callback wanted to pass.
Returns:
Nothing

Definition at line 209 of file bridge_after.h.

typedef void(* ast_bridge_after_cb_failed)(enum ast_bridge_after_cb_reason reason, void *data)

After bridge callback failed.

Since:
12.0.0
Parameters:
reason Reason callback is failing.
data Extra data what setup the callback wanted to pass.
Note:
Called when the channel leaves the bridging system or is destroyed.
Returns:
Nothing

Definition at line 198 of file bridge_after.h.


Enumeration Type Documentation

Reason the the after bridge callback will not be called.

Enumerator:
AST_BRIDGE_AFTER_CB_REASON_DESTROY  The datastore is being destroyed. Likely due to hangup. (Enum value must be zero.)
AST_BRIDGE_AFTER_CB_REASON_REPLACED  Something else replaced the callback with another.
AST_BRIDGE_AFTER_CB_REASON_MASQUERADE  The callback was removed because of a masquerade. (fixup)
AST_BRIDGE_AFTER_CB_REASON_DEPART  The channel was departed from the bridge.
AST_BRIDGE_AFTER_CB_REASON_REMOVED  Was explicitly removed by external code.

Definition at line 37 of file bridge_after.h.

00037                                 {
00038    /*! The datastore is being destroyed.  Likely due to hangup. (Enum value must be zero.) */
00039    AST_BRIDGE_AFTER_CB_REASON_DESTROY,
00040    /*! Something else replaced the callback with another. */
00041    AST_BRIDGE_AFTER_CB_REASON_REPLACED,
00042    /*! The callback was removed because of a masquerade. (fixup) */
00043    AST_BRIDGE_AFTER_CB_REASON_MASQUERADE,
00044    /*! The channel was departed from the bridge. */
00045    AST_BRIDGE_AFTER_CB_REASON_DEPART,
00046    /*! Was explicitly removed by external code. */
00047    AST_BRIDGE_AFTER_CB_REASON_REMOVED,
00048 };


Function Documentation

const char* ast_bridge_after_cb_reason_string ( enum ast_bridge_after_cb_reason  reason  ) 

Get a string representation of an after bridge callback reason.

Since:
12.0.0
Parameters:
reason The reason to interpret to a string
Return values:
NULL Unrecognized reason
non-NULL String representation of reason

Definition at line 306 of file bridge_after.c.

References AST_BRIDGE_AFTER_CB_REASON_DESTROY, and AST_BRIDGE_AFTER_CB_REASON_REMOVED.

Referenced by after_bridge_move_channel_fail(), agent_after_bridge_cb_failed(), and bridge_after_cb_failed().

00307 {
00308    if (reason < AST_BRIDGE_AFTER_CB_REASON_DESTROY
00309       || AST_BRIDGE_AFTER_CB_REASON_REMOVED < reason
00310       || !reason_strings[reason]) {
00311       return "Unknown";
00312    }
00313 
00314    return reason_strings[reason];
00315 }

void ast_bridge_discard_after_callback ( struct ast_channel chan,
enum ast_bridge_after_cb_reason  reason 
)

Run discarding any after bridge callbacks.

Since:
12.0.0
Parameters:
chan Channel to run after bridge callback.
Returns:
Nothing

Definition at line 249 of file bridge_after.c.

References after_bridge_cb_find(), and after_bridge_cb_run_discard().

Referenced by bridge_channel_depart_thread().

00250 {
00251    struct after_bridge_cb_ds *after_bridge;
00252 
00253    after_bridge = after_bridge_cb_find(chan);
00254    if (!after_bridge) {
00255       return;
00256    }
00257 
00258    after_bridge_cb_run_discard(after_bridge, reason);
00259 }

void ast_bridge_discard_after_goto ( struct ast_channel chan  ) 

Discard channel after bridge goto location.

Since:
12.0.0
Parameters:
chan Channel to discard after bridge goto location.
Note:
chan is locked by this function.
Returns:
Nothing

Definition at line 398 of file bridge_after.c.

References after_bridge_goto_remove(), and ast_datastore_free().

Referenced by __after_bridge_set_goto(), after_bridge_goto_fixup(), bridge_channel_depart_thread(), feature_blind_transfer(), and func_channel_write_real().

00399 {
00400    struct ast_datastore *datastore;
00401 
00402    datastore = after_bridge_goto_remove(chan);
00403    if (datastore) {
00404       ast_datastore_free(datastore);
00405    }
00406 }

void ast_bridge_read_after_goto ( struct ast_channel chan,
char *  buffer,
size_t  buf_size 
)

Read after bridge goto if it exists.

Since:
12.0.0
Parameters:
chan Channel to read the after bridge goto parseable goto string from
buffer Buffer to write the after bridge goto data to
buf_size size of the buffer being written to

Definition at line 408 of file bridge_after.c.

References ast_channel_datastore_find(), ast_strlen_zero, after_bridge_goto_ds::context, ast_datastore::data, after_bridge_goto_ds::exten, lock, NULL, after_bridge_goto_ds::parseable_goto, after_bridge_goto_ds::priority, after_bridge_goto_ds::run_h_exten, and SCOPED_CHANNELLOCK.

Referenced by func_channel_read().

00409 {
00410    struct ast_datastore *datastore;
00411    struct after_bridge_goto_ds *after_bridge;
00412    char *current_pos = buffer;
00413    size_t remaining_size = buf_size;
00414 
00415    SCOPED_CHANNELLOCK(lock, chan);
00416 
00417    datastore = ast_channel_datastore_find(chan, &after_bridge_goto_info, NULL);
00418    if (!datastore) {
00419       buffer[0] = '\0';
00420       return;
00421    }
00422 
00423    after_bridge = datastore->data;
00424 
00425    if (after_bridge->parseable_goto) {
00426       snprintf(buffer, buf_size, "%s", after_bridge->parseable_goto);
00427       return;
00428    }
00429 
00430    if (!ast_strlen_zero(after_bridge->context)) {
00431       snprintf(current_pos, remaining_size, "%s,", after_bridge->context);
00432       remaining_size = remaining_size - strlen(current_pos);
00433       current_pos += strlen(current_pos);
00434    }
00435 
00436    if (after_bridge->run_h_exten) {
00437       snprintf(current_pos, remaining_size, "h,");
00438       remaining_size = remaining_size - strlen(current_pos);
00439       current_pos += strlen(current_pos);
00440    } else if (!ast_strlen_zero(after_bridge->exten)) {
00441       snprintf(current_pos, remaining_size, "%s,", after_bridge->exten);
00442       remaining_size = remaining_size - strlen(current_pos);
00443       current_pos += strlen(current_pos);
00444    }
00445 
00446    snprintf(current_pos, remaining_size, "%d", after_bridge->priority);
00447 }

void ast_bridge_run_after_callback ( struct ast_channel chan  ) 

Run any after bridge callback.

Since:
12.0.0
Parameters:
chan Channel to run after bridge callback.
Returns:
Nothing

Definition at line 222 of file bridge_after.c.

References after_bridge_cb_failed(), after_bridge_cb_find(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, after_bridge_cb_node::callback, after_bridge_cb_ds::callbacks, after_bridge_cb_node::data, after_bridge_cb_node::failed, NULL, and after_bridge_cb_node::reason.

Referenced by ast_bridge_join(), and bridge_channel_ind_thread().

00223 {
00224    struct after_bridge_cb_ds *after_bridge;
00225    struct after_bridge_cb_node *node;
00226 
00227    after_bridge = after_bridge_cb_find(chan);
00228    if (!after_bridge) {
00229       return;
00230    }
00231 
00232    for (;;) {
00233       AST_LIST_LOCK(&after_bridge->callbacks);
00234       node = AST_LIST_REMOVE_HEAD(&after_bridge->callbacks, list);
00235       AST_LIST_UNLOCK(&after_bridge->callbacks);
00236       if (!node) {
00237          break;
00238       }
00239       if (node->reason) {
00240          after_bridge_cb_failed(node);
00241       } else {
00242          node->failed = NULL;
00243          node->callback(chan, node->data);
00244       }
00245       ast_free(node);
00246    }
00247 }

void ast_bridge_run_after_goto ( struct ast_channel chan  ) 

Run a PBX on any after bridge goto location.

Since:
12.0.0
Parameters:
chan Channel to execute after bridge goto location.
Note:
chan is locked by this function.
Pull off any after bridge goto location datastore and run a PBX at that location.

Note:
On return, the chan pointer is no longer valid because the channel has hung up.
Returns:
Nothing

Definition at line 539 of file bridge_after.c.

References ast_bridge_setup_after_goto(), ast_hangup(), and ast_pbx_run().

Referenced by bridge_channel_ind_thread().

00540 {
00541    int goto_failed;
00542 
00543    goto_failed = ast_bridge_setup_after_goto(chan);
00544    if (goto_failed || ast_pbx_run(chan)) {
00545       ast_hangup(chan);
00546    }
00547 }

int ast_bridge_set_after_callback ( struct ast_channel chan,
ast_bridge_after_cb  callback,
ast_bridge_after_cb_failed  failed,
void *  data 
)

Setup an after bridge callback for when the channel leaves the bridging system.

Since:
12.0.0
Parameters:
chan Channel to setup an after bridge callback on.
callback Function to call when the channel leaves the bridging system.
failed Function to call when it will not be calling the callback.
data Extra data to pass with the callback.
Note:
chan is locked by this function.

failed is called when the channel leaves the bridging system or is destroyed.

Return values:
0 on success.
-1 on error.

Definition at line 261 of file bridge_after.c.

References after_bridge_cb_setup(), ast_assert, AST_BRIDGE_AFTER_CB_REASON_REPLACED, ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_LAST, AST_LIST_LOCK, AST_LIST_UNLOCK, after_bridge_cb_node::callback, after_bridge_cb_ds::callbacks, after_bridge_cb_node::data, after_bridge_cb_node::failed, NULL, and after_bridge_cb_node::reason.

Referenced by bridge_agent_hold_push(), bridge_channel_attended_transfer(), bridge_moh_create(), bridge_stasis_push(), control_add_channel_to_bridge(), and stasis_app_bridge_playback_channel_add().

00262 {
00263    struct after_bridge_cb_ds *after_bridge;
00264    struct after_bridge_cb_node *new_node;
00265    struct after_bridge_cb_node *last_node;
00266 
00267    /* Sanity checks. */
00268    ast_assert(chan != NULL);
00269    if (!chan || !callback) {
00270       return -1;
00271    }
00272 
00273    after_bridge = after_bridge_cb_setup(chan);
00274    if (!after_bridge) {
00275       return -1;
00276    }
00277 
00278    /* Create a new callback node. */
00279    new_node = ast_calloc(1, sizeof(*new_node));
00280    if (!new_node) {
00281       return -1;
00282    }
00283    new_node->callback = callback;
00284    new_node->failed = failed;
00285    new_node->data = data;
00286 
00287    /* Put it in the container disabling any previously active one. */
00288    AST_LIST_LOCK(&after_bridge->callbacks);
00289    last_node = AST_LIST_LAST(&after_bridge->callbacks);
00290    if (last_node && !last_node->reason) {
00291       last_node->reason = AST_BRIDGE_AFTER_CB_REASON_REPLACED;
00292    }
00293    AST_LIST_INSERT_TAIL(&after_bridge->callbacks, new_node, list);
00294    AST_LIST_UNLOCK(&after_bridge->callbacks);
00295    return 0;
00296 }

void ast_bridge_set_after_go_on ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  parseable_goto 
)

Set channel to go on in the dialplan after the bridge.

Since:
12.0.0
Parameters:
chan Channel to setup after bridge goto location.
context Current context of the caller channel.
exten Current exten of the caller channel.
priority Current priority of the caller channel
parseable_goto User specified goto string from dialplan.
Note:
chan is locked by this function.
Add a channel datastore to setup the goto location when the channel leaves the bridge and run a PBX from there.

If parseable_goto then use the given context/exten/priority as the relative position for the parseable_goto. Else goto the given context/exten/priority+1.

Returns:
Nothing

Definition at line 638 of file bridge_after.c.

References __after_bridge_set_goto(), ast_replace_subargument_delimiter(), ast_strdupa, ast_strlen_zero, and NULL.

Referenced by action_bridge(), bridge_exec(), feature_blind_transfer(), func_channel_write_real(), and setup_peer_after_bridge_goto().

00639 {
00640    char *p_goto;
00641 
00642    if (!ast_strlen_zero(parseable_goto)) {
00643       p_goto = ast_strdupa(parseable_goto);
00644       ast_replace_subargument_delimiter(p_goto);
00645    } else {
00646       p_goto = NULL;
00647    }
00648    __after_bridge_set_goto(chan, 0, 0, context, exten, priority, p_goto);
00649 }

void ast_bridge_set_after_goto ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)

Set channel to goto specific location after the bridge.

Since:
12.0.0
Parameters:
chan Channel to setup after bridge goto location.
context Context to goto after bridge.
exten Exten to goto after bridge.
priority Priority to goto after bridge.
Note:
chan is locked by this function.
Add a channel datastore to setup the goto location when the channel leaves the bridge and run a PBX from there.

Returns:
Nothing

Definition at line 628 of file bridge_after.c.

References __after_bridge_set_goto(), and NULL.

00629 {
00630    __after_bridge_set_goto(chan, 0, 1, context, exten, priority, NULL);
00631 }

void ast_bridge_set_after_h ( struct ast_channel chan,
const char *  context 
)

Set channel to run the h exten after the bridge.

Since:
12.0.0
Parameters:
chan Channel to setup after bridge goto location.
context Context to goto after bridge.
Note:
chan is locked by this function.
Add a channel datastore to setup the goto location when the channel leaves the bridge and run a PBX from there.

Returns:
Nothing

Definition at line 633 of file bridge_after.c.

References __after_bridge_set_goto(), and NULL.

Referenced by setup_peer_after_bridge_goto().

00634 {
00635    __after_bridge_set_goto(chan, 1, 0, context, NULL, 1, NULL);
00636 }

int ast_bridge_setup_after_goto ( struct ast_channel chan  ) 

Setup any after bridge goto location to begin execution.

Since:
12.0.0
Parameters:
chan Channel to setup after bridge goto location.
Note:
chan is locked by this function.
Pull off any after bridge goto location datastore and setup for dialplan execution there.

Return values:
0 on success. The goto location is set for a PBX to run it.
non-zero on error or no goto location.
Note:
If the after bridge goto is set to run an h exten it is run here immediately.

Definition at line 449 of file bridge_after.c.

References after_bridge_goto_remove(), ast_channel_caller(), ast_channel_clear_softhangup(), ast_channel_context(), ast_channel_context_set(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_priority(), ast_channel_priority_set(), ast_channel_set_unbridged(), ast_channel_softhangup_internal_flag(), ast_check_hangup(), ast_clear_flag, ast_datastore_free(), ast_debug, ast_exists_extension(), ast_explicit_goto(), AST_FLAG_IN_AUTOLOOP, AST_FLAG_OUTGOING, ast_goto_if_exists(), ast_parseable_goto(), ast_pbx_h_exten_run(), AST_SOFTHANGUP_ASYNCGOTO, ast_strdupa, ast_strlen_zero, ast_test_flag, context, after_bridge_goto_ds::context, ast_datastore::data, exten, after_bridge_goto_ds::exten, NULL, after_bridge_goto_ds::parseable_goto, after_bridge_goto_ds::priority, after_bridge_goto_ds::run_h_exten, S_COR, and after_bridge_goto_ds::specific.

Referenced by ast_bridge_join(), ast_bridge_run_after_goto(), bridge_after_cb(), bridge_failed_peer_goto(), and dial_exec_full().

00450 {
00451    struct ast_datastore *datastore;
00452    struct after_bridge_goto_ds *after_bridge;
00453    int goto_failed = -1;
00454 
00455    /* We are going to be leaving the bridging system now;
00456     * clear any pending unbridge flags
00457     */
00458    ast_channel_set_unbridged(chan, 0);
00459 
00460    /* Determine if we are going to setup a dialplan location and where. */
00461    if (ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO) {
00462       /* An async goto has already setup a location. */
00463       ast_channel_clear_softhangup(chan, AST_SOFTHANGUP_ASYNCGOTO);
00464       if (!ast_check_hangup(chan)) {
00465          goto_failed = 0;
00466       }
00467       return goto_failed;
00468    }
00469 
00470    /* Get after bridge goto datastore. */
00471    datastore = after_bridge_goto_remove(chan);
00472    if (!datastore) {
00473       return goto_failed;
00474    }
00475 
00476    after_bridge = datastore->data;
00477    if (after_bridge->run_h_exten) {
00478       if (ast_exists_extension(chan, after_bridge->context, "h", 1,
00479          S_COR(ast_channel_caller(chan)->id.number.valid,
00480             ast_channel_caller(chan)->id.number.str, NULL))) {
00481          ast_debug(1, "Running after bridge goto h exten %s,h,1\n",
00482             ast_channel_context(chan));
00483          ast_pbx_h_exten_run(chan, after_bridge->context);
00484       }
00485    } else if (!ast_check_hangup(chan)) {
00486       /* Clear the outgoing flag */
00487       ast_clear_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
00488 
00489       if (after_bridge->specific) {
00490          goto_failed = ast_explicit_goto(chan, after_bridge->context,
00491             after_bridge->exten, after_bridge->priority);
00492       } else if (!ast_strlen_zero(after_bridge->parseable_goto)) {
00493          char *context;
00494          char *exten;
00495          int priority;
00496 
00497          /* Option F(x) for Bridge(), Dial(), and Queue() */
00498 
00499          /* Save current dialplan location in case of failure. */
00500          context = ast_strdupa(ast_channel_context(chan));
00501          exten = ast_strdupa(ast_channel_exten(chan));
00502          priority = ast_channel_priority(chan);
00503 
00504          /* Set current dialplan position to default dialplan position */
00505          ast_explicit_goto(chan, after_bridge->context, after_bridge->exten,
00506             after_bridge->priority);
00507 
00508          /* Then perform the goto */
00509          goto_failed = ast_parseable_goto(chan, after_bridge->parseable_goto);
00510          if (goto_failed) {
00511             /* Restore original dialplan location. */
00512             ast_channel_context_set(chan, context);
00513             ast_channel_exten_set(chan, exten);
00514             ast_channel_priority_set(chan, priority);
00515          }
00516       } else {
00517          /* Option F() for Bridge(), Dial(), and Queue() */
00518          goto_failed = ast_goto_if_exists(chan, after_bridge->context,
00519             after_bridge->exten, after_bridge->priority + 1);
00520       }
00521       if (!goto_failed) {
00522          if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP)) {
00523             ast_channel_priority_set(chan, ast_channel_priority(chan) + 1);
00524          }
00525 
00526          ast_debug(1, "Setup after bridge goto location to %s,%s,%d.\n",
00527             ast_channel_context(chan),
00528             ast_channel_exten(chan),
00529             ast_channel_priority(chan));
00530       }
00531    }
00532 
00533    /* Discard after bridge goto datastore. */
00534    ast_datastore_free(datastore);
00535 
00536    return goto_failed;
00537 }


Generated on Thu Apr 16 06:29:07 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6