summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2011-12-23 02:35:13 +0000
committerRichard Mudgett <rmudgett@digium.com>2011-12-23 02:35:13 +0000
commit32e35e5fcd353e8212e7e164d07da3c2be0221ac (patch)
tree9e9cf812ba5ec9072fbbe9e20da486eb21985073 /include
parent262ea697646f0194d8bc4f74b7f1767775debc7a (diff)
Fix extension state callback references in chan_sip.
Chan_sip gives a dialog reference to the extension state callback and assumes that when ast_extension_state_del() returns, the callback cannot happen anymore. Chan_sip then reduces the dialog reference count associated with the callback. Recent changes (ASTERISK-17760) have resulted in the potential for the callback to happen after ast_extension_state_del() has returned. For chan_sip, this could be very bad because the dialog pointer could have already been destroyed. * Added ast_extension_state_add_destroy() so chan_sip can account for the sip_pvt reference given to the extension state callback when the extension state callback is deleted. * Fix pbx.c awkward statecbs handling in ast_extension_state_add_destroy() and handle_statechange() now that the struct ast_state_cb has a destructor to call. * Ensure that ast_extension_state_add_destroy() will never return -1 or 0 for a successful registration. * Fixed pbx.c statecbs_cmp() to compare the correct information. The passed in value to compare is a change_cb function pointer not an object pointer. * Make pbx.c ast_merge_contexts_and_delete() not perform callbacks with AST_EXTENSION_REMOVED with locks held. Chan_sip is notorious for deadlocking when those locks are held during the callback. * Removed unused lock declaration for the pbx.c store_hints list. (closes issue ASTERISK-18844) Reported by: rmudgett Review: https://reviewboard.asterisk.org/r/1635/ ........ Merged revisions 348940 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 348952 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@348953 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/pbx.h40
1 files changed, 32 insertions, 8 deletions
diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h
index 36bc0724c..02b0654f7 100644
--- a/include/asterisk/pbx.h
+++ b/include/asterisk/pbx.h
@@ -78,6 +78,9 @@ struct ast_sw;
/*! \brief Typedef for devicestate and hint callbacks */
typedef int (*ast_state_cb_type)(const char *context, const char *exten, enum ast_extension_states state, void *data);
+/*! \brief Typedef for devicestate and hint callback removal indication callback */
+typedef void (*ast_state_cb_destroy_type)(int id, void *data);
+
/*! \brief Data structure associated with a custom dialplan function */
struct ast_custom_function {
const char *name; /*!< Name */
@@ -408,33 +411,54 @@ int ast_extension_state(struct ast_channel *c, const char *context, const char *
const char *ast_extension_state2str(int extension_state);
/*!
+ * \brief Registers a state change callback with destructor.
+ * \since 1.8.9
+ * \since 10.1.0
+ *
+ * \param context which context to look in
+ * \param exten which extension to get state
+ * \param change_cb callback to call if state changed
+ * \param destroy_cb callback to call when registration destroyed.
+ * \param data to pass to callback
+ *
+ * \note The change_cb is called if the state of an extension is changed.
+ *
+ * \note The destroy_cb is called when the registration is
+ * deleted so the registerer can release any associated
+ * resources.
+ *
+ * \retval -1 on failure
+ * \retval ID on success
+ */
+int ast_extension_state_add_destroy(const char *context, const char *exten,
+ ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data);
+
+/*!
* \brief Registers a state change callback
*
* \param context which context to look in
* \param exten which extension to get state
- * \param callback callback to call if state changed
+ * \param change_cb callback to call if state changed
* \param data to pass to callback
*
- * The callback is called if the state of an extension is changed.
+ * \note The change_cb is called if the state of an extension is changed.
*
* \retval -1 on failure
* \retval ID on success
*/
int ast_extension_state_add(const char *context, const char *exten,
- ast_state_cb_type callback, void *data);
+ ast_state_cb_type change_cb, void *data);
/*!
* \brief Deletes a registered state change callback by ID
*
- * \param id of the callback to delete
- * \param callback callback
- *
- * Removes the callback from list of callbacks
+ * \param id of the registered state callback to delete
+ * \param change_cb callback to call if state changed (Used if id == 0 (global))
*
* \retval 0 success
* \retval -1 failure
*/
-int ast_extension_state_del(int id, ast_state_cb_type callback);
+int ast_extension_state_del(int id, ast_state_cb_type change_cb);
/*!
* \brief If an extension hint exists, return non-zero