[Asterisk-code-review] Remove redundant module references. (asterisk[master])

Corey Farrell asteriskteam at digium.com
Wed Jan 17 00:44:17 CST 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7989


Change subject: Remove redundant module references.
......................................................................

Remove redundant module references.

This removes references that are no longer needed due to automatic
references created by module dependencies.

Change-Id: I332a6e8383d4c72c8e89d988a184ab8320c4872e
---
M apps/app_stasis.c
M channels/chan_pjsip.c
M funcs/func_periodic_hook.c
M include/asterisk/res_mwi_external.h
M include/asterisk/res_pjproject.h
M include/asterisk/res_pjsip.h
M include/asterisk/res_pjsip_session.h
M include/asterisk/stasis_app.h
M res/res_agi.c
M res/res_ari.c
M res/res_ari_applications.c
M res/res_ari_asterisk.c
M res/res_ari_bridges.c
M res/res_ari_channels.c
M res/res_ari_device_states.c
M res/res_ari_endpoints.c
M res/res_ari_events.c
M res/res_ari_mailboxes.c
M res/res_ari_playbacks.c
M res/res_ari_recordings.c
M res/res_ari_sounds.c
M res/res_crypto.c
M res/res_fax.c
M res/res_http_websocket.c
M res/res_monitor.c
M res/res_mwi_external.c
M res/res_mwi_external_ami.c
M res/res_pjproject.c
M res/res_pjsip.c
M res/res_pjsip/config_auth.c
M res/res_pjsip/config_transport.c
M res/res_pjsip/include/res_pjsip_private.h
M res/res_pjsip/location.c
M res/res_pjsip/pjsip_distributor.c
M res/res_pjsip/pjsip_global_headers.c
M res/res_pjsip/pjsip_message_filter.c
M res/res_pjsip/pjsip_options.c
M res/res_pjsip/pjsip_session.c
M res/res_pjsip_config_wizard.c
M res/res_pjsip_dlg_options.c
M res/res_pjsip_nat.c
M res/res_pjsip_one_touch_record_info.c
M res/res_pjsip_outbound_publish.c
M res/res_pjsip_path.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_send_to_voicemail.c
M res/res_pjsip_session.c
M res/res_pjsip_t38.c
M res/res_pjsip_transport_websocket.c
M res/res_pktccops.c
M res/res_smdi.c
M res/res_stasis.c
M res/res_stasis_mailbox.c
M res/res_statsd.c
M res/stasis/app.c
M rest-api-templates/res_ari_resource.c.mustache
M tests/test_res_stasis.c
57 files changed, 81 insertions(+), 487 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/89/7989/1

diff --git a/apps/app_stasis.c b/apps/app_stasis.c
index 8d09349..b98c2b4 100644
--- a/apps/app_stasis.c
+++ b/apps/app_stasis.c
@@ -125,19 +125,12 @@
 
 static int load_module(void)
 {
-	int r = 0;
-
-	stasis_app_ref();
-	r |= ast_register_application_xml(stasis, app_exec);
-	return r;
+	return ast_register_application_xml(stasis, app_exec);
 }
 
 static int unload_module(void)
 {
-	int r = 0;
-	r |= ast_unregister_application(stasis);
-	stasis_app_unref();
-	return r;
+	return ast_unregister_application(stasis);
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application",
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 68da4a1..20d1f82 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -3016,10 +3016,7 @@
 		goto end;
 	}
 
-	if (ast_sip_session_register_supplement(&chan_pjsip_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register PJSIP supplement\n");
-		goto end;
-	}
+	ast_sip_session_register_supplement(&chan_pjsip_supplement);
 
 	if (!(pjsip_uids_onhold = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK,
 			AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, 37, uid_hold_hash_fn,
@@ -3028,26 +3025,9 @@
 		goto end;
 	}
 
-	if (ast_sip_session_register_supplement(&call_pickup_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register PJSIP call pickup supplement\n");
-		ast_sip_session_unregister_supplement(&chan_pjsip_supplement);
-		goto end;
-	}
-
-	if (ast_sip_session_register_supplement(&pbx_start_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register PJSIP pbx start supplement\n");
-		ast_sip_session_unregister_supplement(&chan_pjsip_supplement);
-		ast_sip_session_unregister_supplement(&call_pickup_supplement);
-		goto end;
-	}
-
-	if (ast_sip_session_register_supplement(&chan_pjsip_ack_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register PJSIP ACK supplement\n");
-		ast_sip_session_unregister_supplement(&pbx_start_supplement);
-		ast_sip_session_unregister_supplement(&chan_pjsip_supplement);
-		ast_sip_session_unregister_supplement(&call_pickup_supplement);
-		goto end;
-	}
+	ast_sip_session_register_supplement(&call_pickup_supplement);
+	ast_sip_session_register_supplement(&pbx_start_supplement);
+	ast_sip_session_register_supplement(&chan_pjsip_ack_supplement);
 
 	if (pjsip_channel_cli_register()) {
 		ast_log(LOG_ERROR, "Unable to register PJSIP Channel CLI\n");
diff --git a/funcs/func_periodic_hook.c b/funcs/func_periodic_hook.c
index 958da97..1f66747 100644
--- a/funcs/func_periodic_hook.c
+++ b/funcs/func_periodic_hook.c
@@ -486,11 +486,6 @@
 
 	res = ast_custom_function_register_escalating(&hook_function, AST_CFE_BOTH);
 
-	if (!res) {
-		/* For Optional API. */
-		ast_module_shutdown_ref(AST_MODULE_SELF);
-	}
-
 	return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 }
 
diff --git a/include/asterisk/res_mwi_external.h b/include/asterisk/res_mwi_external.h
index 7698a1b..25de700 100644
--- a/include/asterisk/res_mwi_external.h
+++ b/include/asterisk/res_mwi_external.h
@@ -36,22 +36,6 @@
 
 /* ------------------------------------------------------------------- */
 
-/*!
- * \brief Increase the external MWI resource module reference count.
- * \since 12.1.0
- *
- * \return Nothing
- */
-void ast_mwi_external_ref(void);
-
-/*!
- * \brief Decrease the external MWI resource module reference count.
- * \since 12.1.0
- *
- * \return Nothing
- */
-void ast_mwi_external_unref(void);
-
 struct ast_mwi_mailbox_object;
 
 /*! \brief Convienience unref function for mailbox object. */
diff --git a/include/asterisk/res_pjproject.h b/include/asterisk/res_pjproject.h
index 8828b34..f62862b 100644
--- a/include/asterisk/res_pjproject.h
+++ b/include/asterisk/res_pjproject.h
@@ -79,18 +79,4 @@
  */
 void ast_pjproject_log_intercept_end(void);
 
-/*!
- * \brief Increment the res_pjproject reference count.
- *
- * This ensures graceful shutdown happens in the proper order.
- */
-void ast_pjproject_ref(void);
-
-/*!
- * \brief Decrement the res_pjproject reference count.
- *
- * This ensures graceful shutdown happens in the proper order.
- */
-void ast_pjproject_unref(void);
-
 #endif /* _RES_PJPROJECT_H */
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 6c48d2e..34fa69a 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -931,9 +931,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-#define ast_sip_register_service(module) \
-	__ast_sip_register_service(module, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-int __ast_sip_register_service(pjsip_module *module, const char *file, int line, const char *func);
+int ast_sip_register_service(pjsip_module *module);
 
 /*!
  * This is the opposite of ast_sip_register_service().  Unregistering a
@@ -942,9 +940,7 @@
  *
  * \param module The PJSIP module to unregister
  */
-#define ast_sip_unregister_service(module) \
-	__ast_sip_unregister_service(module, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-void __ast_sip_unregister_service(pjsip_module *module, const char *file, int line, const char *func);
+void ast_sip_unregister_service(pjsip_module *module);
 
 /*!
  * \brief Register a SIP authenticator
@@ -2446,10 +2442,8 @@
  * \brief Register an endpoint formatter.
  *
  * \param obj the formatter to register
- * \retval 0 Success
- * \retval -1 Failure
  */
-int ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
+void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
 
 /*!
  * \brief Unregister an endpoint formatter.
@@ -2625,20 +2619,14 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-#define ast_sip_register_supplement(supplement) \
-	__ast_sip_register_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-int __ast_sip_register_supplement(struct ast_sip_supplement *supplement,
-	const char *file, int line, const char *func);
+void ast_sip_register_supplement(struct ast_sip_supplement *supplement);
 
 /*!
  * \brief Unregister a an supplement to SIP out of dialog processing
  *
  * \param supplement The supplement to unregister
  */
-#define ast_sip_unregister_supplement(supplement) \
-	__ast_sip_unregister_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-void __ast_sip_unregister_supplement(struct ast_sip_supplement *supplement,
-	const char *file, int line, const char *func);
+void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
 
 /*!
  * \brief Retrieve the global MWI taskprocessor high water alert trigger level.
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index 65d4638..e0d1682 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -579,23 +579,15 @@
  * a module could reject an incoming request if desired.
  *
  * \param supplement The supplement to register
- * \retval 0 Success
- * \retval -1 Failure
  */
-#define ast_sip_session_register_supplement(supplement) \
-	__ast_sip_session_register_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-int __ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement,
-	const char *file, int line, const char *func);
+void ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement);
 
 /*!
  * \brief Unregister a an supplement to SIP session processing
  *
  * \param supplement The supplement to unregister
  */
-#define ast_sip_session_unregister_supplement(supplement) \
-	__ast_sip_session_unregister_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
-void __ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement,
-	const char *file, int line, const char *func);
+void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
 
 /*!
  * \brief Add supplements to a SIP session
diff --git a/include/asterisk/stasis_app.h b/include/asterisk/stasis_app.h
index 8ef2bda..b0829ab 100644
--- a/include/asterisk/stasis_app.h
+++ b/include/asterisk/stasis_app.h
@@ -46,8 +46,8 @@
  * functions.
  *
  * Since module unload order is based on reference counting, any module that
- * uses the API defined in this file must call stasis_app_ref() when loaded,
- * and stasis_app_unref() when unloaded.
+ * uses the API defined in this file must list "res_stasis" in the requires
+ * field.
  */
 
 #include "asterisk/channel.h"
@@ -227,18 +227,6 @@
  * \brief Register core event sources.
  */
 void stasis_app_register_event_sources(void);
-
-/*!
- * \brief Checks to see if the given object is a core event source
- *
- * \note core event sources are currently only endpoint, bridge, and channel.
- *
- * \param obj event source object to check
- *
- * \return non-zero if core event source, otherwise 0 (false)
-
- */
-int stasis_app_is_core_event_source(struct stasis_app_event_source *obj);
 
 /*!
  * \brief Unregister an application event source.
@@ -848,20 +836,6 @@
  * \retval zero on success
  */
 void stasis_app_bridge_destroy(const char *bridge_id);
-
-/*!
- * \brief Increment the res_stasis reference count.
- *
- * This ensures graceful shutdown happens in the proper order.
- */
-void stasis_app_ref(void);
-
-/*!
- * \brief Decrement the res_stasis reference count.
- *
- * This ensures graceful shutdown happens in the proper order.
- */
-void stasis_app_unref(void);
 
 /*!
  * \brief Get the Stasis message sanitizer for app_stasis applications
diff --git a/res/res_agi.c b/res/res_agi.c
index 2d0dc27..34ace7a 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -3815,8 +3815,6 @@
 		AST_RWLIST_WRLOCK(&agi_commands);
 		AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
 		AST_RWLIST_UNLOCK(&agi_commands);
-		if (mod != ast_module_info->self)
-			ast_module_ref(ast_module_info->self);
 		ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
 		return 1;
 	} else {
@@ -3837,8 +3835,6 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
 		if (cmd == e) {
 			AST_RWLIST_REMOVE_CURRENT(list);
-			if (mod != ast_module_info->self)
-				ast_module_unref(ast_module_info->self);
 #ifdef AST_XML_DOCS
 			if (e->docsrc == AST_XML_DOC) {
 				ast_free((char *) e->summary);
@@ -4642,7 +4638,7 @@
 		break;
 	}
 
-	if (ast_agi_register(ast_module_info->self, &noop_command) == 0) {
+	if (ast_agi_register(NULL, &noop_command) == 0) {
 		ast_test_status_update(test, "Unable to register testnoop command, because res_agi is not loaded.\n");
 		return AST_TEST_NOT_RUN;
 	}
@@ -4659,7 +4655,7 @@
 	}
 #endif
 
-	ast_agi_unregister(ast_module_info->self, &noop_command);
+	ast_agi_unregister(NULL, &noop_command);
 	return res;
 }
 #endif
@@ -4673,7 +4669,7 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(agi_async_end_type);
 
 	ast_cli_unregister_multiple(cli_agi, ARRAY_LEN(cli_agi));
-	ast_agi_unregister_multiple(ast_module_info->self, commands, ARRAY_LEN(commands));
+	ast_agi_unregister_multiple(NULL, commands, ARRAY_LEN(commands));
 	ast_unregister_application(eapp);
 	ast_unregister_application(deadapp);
 	ast_manager_unregister("AGI");
@@ -4693,7 +4689,7 @@
 	err |= STASIS_MESSAGE_TYPE_INIT(agi_async_end_type);
 
 	err |= ast_cli_register_multiple(cli_agi, ARRAY_LEN(cli_agi));
-	err |= ast_agi_register_multiple(ast_module_info->self, commands, ARRAY_LEN(commands));
+	err |= ast_agi_register_multiple(NULL, commands, ARRAY_LEN(commands));
 	err |= ast_register_application_xml(deadapp, deadagi_exec);
 	err |= ast_register_application_xml(eapp, eagi_exec);
 	err |= ast_manager_register_xml("AGI", EVENT_FLAG_AGI, action_add_agi_cmd);
@@ -4705,9 +4701,6 @@
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
-
-	/* For Optional API. */
-	ast_module_shutdown_ref(AST_MODULE_SELF);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }
diff --git a/res/res_ari.c b/res/res_ari.c
index 6ce25a5..5ffb583 100644
--- a/res/res_ari.c
+++ b/res/res_ari.c
@@ -196,7 +196,6 @@
 	ao2_cleanup(root_handler);
 	ao2_ref(new_handler, +1);
 	root_handler = new_handler;
-	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
@@ -222,7 +221,6 @@
 	memcpy(new_handler, root_handler, sizeof(*new_handler));
 	for (i = 0, j = 0; i < root_handler->num_children; ++i) {
 		if (root_handler->children[i] == handler) {
-			ast_module_unref(ast_module_info->self);
 			continue;
 		}
 		new_handler->children[j++] = root_handler->children[i];
diff --git a/res/res_ari_applications.c b/res/res_ari_applications.c
index 323bdb3..aeb43e4 100644
--- a/res/res_ari_applications.c
+++ b/res/res_ari_applications.c
@@ -493,7 +493,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&applications);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -504,7 +503,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&applications);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_asterisk.c b/res/res_ari_asterisk.c
index 9f76f93..840c832 100644
--- a/res/res_ari_asterisk.c
+++ b/res/res_ari_asterisk.c
@@ -1214,7 +1214,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&asterisk);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -1225,7 +1224,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&asterisk);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c
index 34b9d89..90c48f9 100644
--- a/res/res_ari_bridges.c
+++ b/res/res_ari_bridges.c
@@ -1554,7 +1554,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&bridges);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -1565,7 +1564,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&bridges);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c
index 7862c10..02144da 100644
--- a/res/res_ari_channels.c
+++ b/res/res_ari_channels.c
@@ -2844,7 +2844,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&channels);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -2855,7 +2854,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&channels);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_device_states.c b/res/res_ari_device_states.c
index ec8890b..1cce031 100644
--- a/res/res_ari_device_states.c
+++ b/res/res_ari_device_states.c
@@ -324,7 +324,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&deviceStates);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -335,7 +334,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&deviceStates);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_endpoints.c b/res/res_ari_endpoints.c
index 07197ca..3021741 100644
--- a/res/res_ari_endpoints.c
+++ b/res/res_ari_endpoints.c
@@ -448,7 +448,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&endpoints);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -459,7 +458,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&endpoints);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_events.c b/res/res_ari_events.c
index f750a54..c9eea80 100644
--- a/res/res_ari_events.c
+++ b/res/res_ari_events.c
@@ -423,7 +423,6 @@
 	ao2_cleanup(events.ws_server);
 	events.ws_server = NULL;
 	ast_ari_websocket_events_event_websocket_dtor();
-	stasis_app_unref();
 	return 0;
 }
 
@@ -459,7 +458,6 @@
 		res |= ast_websocket_server_add_protocol2(events.ws_server, protocol);
 	}
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&events);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_mailboxes.c b/res/res_ari_mailboxes.c
index 6469f93..ff19bf7 100644
--- a/res/res_ari_mailboxes.c
+++ b/res/res_ari_mailboxes.c
@@ -330,7 +330,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&mailboxes);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -341,7 +340,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&mailboxes);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_playbacks.c b/res/res_ari_playbacks.c
index 0148a74..1c4b182 100644
--- a/res/res_ari_playbacks.c
+++ b/res/res_ari_playbacks.c
@@ -282,7 +282,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&playbacks);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -293,7 +292,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&playbacks);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_recordings.c b/res/res_ari_recordings.c
index 531ff65..3b8ee20 100644
--- a/res/res_ari_recordings.c
+++ b/res/res_ari_recordings.c
@@ -866,7 +866,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&recordings);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -877,7 +876,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&recordings);
 	if (res) {
 		unload_module();
diff --git a/res/res_ari_sounds.c b/res/res_ari_sounds.c
index 5c27ebd..d77ce1b 100644
--- a/res/res_ari_sounds.c
+++ b/res/res_ari_sounds.c
@@ -212,7 +212,6 @@
 static int unload_module(void)
 {
 	ast_ari_remove_handler(&sounds);
-	stasis_app_unref();
 	return 0;
 }
 
@@ -223,7 +222,6 @@
 	CHECK_ARI_MODULE_LOADED();
 
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&sounds);
 	if (res) {
 		unload_module();
diff --git a/res/res_crypto.c b/res/res_crypto.c
index 8f97ce9..4f8f2cb 100644
--- a/res/res_crypto.c
+++ b/res/res_crypto.c
@@ -651,8 +651,6 @@
 		crypto_load(-1, -1);
 	}
 
-	/* This prevents dlclose from ever running, but allows CLI cleanup at shutdown. */
-	ast_module_shutdown_ref(ast_module_info->self);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
@@ -663,7 +661,6 @@
 	return 0;
 }
 
-/* needs usecount semantics defined */
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Cryptographic Digital Signatures",
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
diff --git a/res/res_fax.c b/res/res_fax.c
index 4be5aee..315f000 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -978,7 +978,6 @@
 	AST_RWLIST_WRLOCK(&faxmodules);
 	AST_RWLIST_INSERT_TAIL(&faxmodules, fax, list);
 	AST_RWLIST_UNLOCK(&faxmodules);
-	ast_module_ref(ast_module_info->self);
 
 	ast_verb(3, "Registered handler for '%s' (%s)\n", fax->tech->type, fax->tech->description);
 
@@ -998,7 +997,6 @@
 			continue;
 		}
 		AST_RWLIST_REMOVE_CURRENT(list);
-		ast_module_unref(ast_module_info->self);
 		ast_free(fax);
 		ast_verb(4, "Unregistered FAX module type '%s'\n", tech->type);
 		break;
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 86a1547..bcad1c3 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -131,24 +131,18 @@
 	struct ao2_container *protocols; /*!< Container for registered protocols */
 };
 
-static void websocket_server_internal_dtor(void *obj)
+static void websocket_server_dtor(void *obj)
 {
 	struct ast_websocket_server *server = obj;
 	ao2_cleanup(server->protocols);
 	server->protocols = NULL;
 }
 
-static void websocket_server_dtor(void *obj)
-{
-	websocket_server_internal_dtor(obj);
-	ast_module_unref(ast_module_info->self);
-}
-
-static struct ast_websocket_server *websocket_server_create_impl(void (*dtor)(void *))
+static struct ast_websocket_server *websocket_server_create_impl(void)
 {
 	RAII_VAR(struct ast_websocket_server *, server, NULL, ao2_cleanup);
 
-	server = ao2_alloc(sizeof(*server), dtor);
+	server = ao2_alloc(sizeof(*server), websocket_server_dtor);
 	if (!server) {
 		return NULL;
 	}
@@ -164,13 +158,12 @@
 
 static struct ast_websocket_server *websocket_server_internal_create(void)
 {
-	return websocket_server_create_impl(websocket_server_internal_dtor);
+	return websocket_server_create_impl();
 }
 
 struct ast_websocket_server *AST_OPTIONAL_API_NAME(ast_websocket_server_create)(void)
 {
-	ast_module_ref(ast_module_info->self);
-	return websocket_server_create_impl(websocket_server_dtor);
+	return websocket_server_create_impl();
 }
 
 /*! \brief Destructor function for sessions */
@@ -997,11 +990,7 @@
 
 int AST_OPTIONAL_API_NAME(ast_websocket_add_protocol)(const char *name, ast_websocket_callback callback)
 {
-	int res = websocket_add_protocol_internal(name, callback);
-	if (res == 0) {
-		ast_module_ref(ast_module_info->self);
-	}
-	return res;
+	return websocket_add_protocol_internal(name, callback);
 }
 
 int AST_OPTIONAL_API_NAME(ast_websocket_add_protocol2)(struct ast_websocket_protocol *protocol)
@@ -1016,7 +1005,6 @@
 		return -1;
 	}
 
-	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
@@ -1031,11 +1019,7 @@
 
 int AST_OPTIONAL_API_NAME(ast_websocket_remove_protocol)(const char *name, ast_websocket_callback callback)
 {
-	int res = websocket_remove_protocol_internal(name, callback);
-	if (res == 0) {
-		ast_module_unref(ast_module_info->self);
-	}
-	return res;
+	return websocket_remove_protocol_internal(name, callback);
 }
 
 /*! \brief Parse the given uri into a path and remote address.
@@ -1456,9 +1440,6 @@
 	}
 	ast_http_uri_link(&websocketuri);
 	websocket_add_protocol_internal("echo", websocket_echo_callback);
-
-	/* For Optional API. */
-	ast_module_shutdown_ref(AST_MODULE_SELF);
 
 	return 0;
 }
diff --git a/res/res_monitor.c b/res/res_monitor.c
index 9dcbdbe..c67b37e 100644
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -985,9 +985,6 @@
 	ast_manager_register_xml("PauseMonitor", EVENT_FLAG_CALL, pause_monitor_action);
 	ast_manager_register_xml("UnpauseMonitor", EVENT_FLAG_CALL, unpause_monitor_action);
 
-	/* For Optional API. */
-	ast_module_shutdown_ref(AST_MODULE_SELF);
-
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
diff --git a/res/res_mwi_external.c b/res/res_mwi_external.c
index d797991..82c74b9 100644
--- a/res/res_mwi_external.c
+++ b/res/res_mwi_external.c
@@ -81,16 +81,6 @@
 
 static struct ast_sorcery *mwi_sorcery;
 
-void ast_mwi_external_ref(void)
-{
-	ast_module_ref(ast_module_info->self);
-}
-
-void ast_mwi_external_unref(void)
-{
-	ast_module_unref(ast_module_info->self);
-}
-
 /*!
  * \internal
  * \brief Post an update event to the MWI counts.
diff --git a/res/res_mwi_external_ami.c b/res/res_mwi_external_ami.c
index 8639fad..e4d5054 100644
--- a/res/res_mwi_external_ami.c
+++ b/res/res_mwi_external_ami.c
@@ -342,17 +342,12 @@
 	ast_manager_unregister("MWIDelete");
 	ast_manager_unregister("MWIUpdate");
 
-	/* Must be done last */
-	ast_mwi_external_unref();
 	return 0;
 }
 
 static int load_module(void)
 {
 	int res;
-
-	/* Must be done first */
-	ast_mwi_external_ref();
 
 	res = 0;
 	res |= ast_manager_register_xml("MWIGet", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, mwi_mailbox_get);
diff --git a/res/res_pjproject.c b/res/res_pjproject.c
index 6137898..f506a62 100644
--- a/res/res_pjproject.c
+++ b/res/res_pjproject.c
@@ -280,16 +280,6 @@
 	ast_mutex_unlock(&pjproject_log_intercept_lock);
 }
 
-void ast_pjproject_ref(void)
-{
-	ast_module_ref(ast_module_info->self);
-}
-
-void ast_pjproject_unref(void)
-{
-	ast_module_unref(ast_module_info->self);
-}
-
 static char *handle_pjproject_show_buildopts(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	int i;
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 3f9574d..ad601cc 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2604,7 +2604,7 @@
 /*! Local host address for IPv6 (string form) */
 static char host_ip_ipv6_string[PJ_INET6_ADDRSTRLEN];
 
-static int register_service_noref(void *data)
+static int register_service(void *data)
 {
 	pjsip_module **module = data;
 	if (!ast_pjsip_endpoint) {
@@ -2619,23 +2619,12 @@
 	return 0;
 }
 
-int internal_sip_register_service(pjsip_module *module)
+int ast_sip_register_service(pjsip_module *module)
 {
-	return ast_sip_push_task_synchronous(NULL, register_service_noref, &module);
+	return ast_sip_push_task_synchronous(NULL, register_service, &module);
 }
 
-int __ast_sip_register_service(pjsip_module *module, const char *file, int line, const char *func)
-{
-	int res;
-
-	if (!(res = ast_sip_push_task_synchronous(NULL, register_service_noref, &module))) {
-		__ast_module_ref(ast_module_info->self, file, line, func);
-	}
-
-	return res;
-}
-
-static int unregister_service_noref(void *data)
+static int unregister_service(void *data)
 {
 	pjsip_module **module = data;
 	if (!ast_pjsip_endpoint) {
@@ -2646,16 +2635,9 @@
 	return 0;
 }
 
-int internal_sip_unregister_service(pjsip_module *module)
+void ast_sip_unregister_service(pjsip_module *module)
 {
-	return ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module);
-}
-
-void __ast_sip_unregister_service(pjsip_module *module, const char *file, int line, const char *func)
-{
-	if (!ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module)) {
-		__ast_module_unref(ast_module_info->self, file, line, func);
-	}
+	ast_sip_push_task_synchronous(NULL, unregister_service, &module);
 }
 
 static struct ast_sip_authenticator *registered_authenticator;
@@ -2668,7 +2650,7 @@
 	}
 	registered_authenticator = auth;
 	ast_debug(1, "Registered SIP authenticator module %p\n", auth);
-	ast_module_ref(ast_module_info->self);
+
 	return 0;
 }
 
@@ -2681,7 +2663,6 @@
 	}
 	registered_authenticator = NULL;
 	ast_debug(1, "Unregistered SIP authenticator %p\n", auth);
-	ast_module_unref(ast_module_info->self);
 }
 
 int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
@@ -2714,7 +2695,7 @@
 	}
 	registered_outbound_authenticator = auth;
 	ast_debug(1, "Registered SIP outbound authenticator module %p\n", auth);
-	ast_module_ref(ast_module_info->self);
+
 	return 0;
 }
 
@@ -2727,7 +2708,6 @@
 	}
 	registered_outbound_authenticator = NULL;
 	ast_debug(1, "Unregistered SIP outbound authenticator %p\n", auth);
-	ast_module_unref(ast_module_info->self);
 }
 
 int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
@@ -2769,7 +2749,6 @@
 	if (ast_strlen_zero(name)) {
 		/* if an identifier has no name then place in front */
 		AST_RWLIST_INSERT_HEAD(&endpoint_identifiers, id_list_item, list);
-		ast_module_ref(ast_module_info->self);
 		return 0;
 	}
 
@@ -2779,8 +2758,6 @@
 	if (ast_strlen_zero(identifier_order)) {
 		id_list_item->priority = UINT_MAX;
 		AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
-		ast_module_ref(ast_module_info->self);
-		ast_free(identifier_order);
 		return 0;
 	}
 
@@ -2807,7 +2784,6 @@
 		/* if not in the endpoint_identifier_order list then consider it less in
 		   priority and add it to the end */
 		AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
-		ast_module_ref(ast_module_info->self);
 		ast_free(identifier_order);
 		return 0;
 	}
@@ -2825,7 +2801,6 @@
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 
-	ast_module_ref(ast_module_info->self);
 	ast_free(identifier_order);
 	return 0;
 }
@@ -2844,7 +2819,6 @@
 			AST_RWLIST_REMOVE_CURRENT(list);
 			ast_free(iter);
 			ast_debug(1, "Unregistered endpoint identifier %p\n", identifier);
-			ast_module_unref(ast_module_info->self);
 			break;
 		}
 	}
@@ -2987,23 +2961,17 @@
 
 AST_RWLIST_HEAD_STATIC(endpoint_formatters, ast_sip_endpoint_formatter);
 
-void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
+void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
 {
 	SCOPED_LOCK(lock, &endpoint_formatters, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
 	AST_RWLIST_INSERT_TAIL(&endpoint_formatters, obj, next);
 }
 
-int ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
-{
-	internal_sip_register_endpoint_formatter(obj);
-	ast_module_ref(ast_module_info->self);
-	return 0;
-}
-
-int internal_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
+void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
 {
 	struct ast_sip_endpoint_formatter *i;
 	SCOPED_LOCK(lock, &endpoint_formatters, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&endpoint_formatters, i, next) {
 		if (i == obj) {
 			AST_RWLIST_REMOVE_CURRENT(next);
@@ -3011,14 +2979,6 @@
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
-	return i == obj ? 0 : -1;
-}
-
-void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
-{
-	if (!internal_sip_unregister_endpoint_formatter(obj)) {
-		ast_module_unref(ast_module_info->self);
-	}
 }
 
 int ast_sip_format_endpoint_ami(struct ast_sip_endpoint *endpoint,
@@ -3705,7 +3665,7 @@
 
 AST_RWLIST_HEAD_STATIC(supplements, ast_sip_supplement);
 
-void internal_sip_register_supplement(struct ast_sip_supplement *supplement)
+void ast_sip_register_supplement(struct ast_sip_supplement *supplement)
 {
 	struct ast_sip_supplement *iter;
 	int inserted = 0;
@@ -3725,39 +3685,18 @@
 	}
 }
 
-int __ast_sip_register_supplement(struct ast_sip_supplement *supplement,
-	const char *file, int line, const char *func)
-{
-	internal_sip_register_supplement(supplement);
-	__ast_module_ref(ast_module_info->self, file, line, func);
-
-	return 0;
-}
-
-int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement)
+void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement)
 {
 	struct ast_sip_supplement *iter;
 	SCOPED_LOCK(lock, &supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
-	int res = -1;
 
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&supplements, iter, next) {
 		if (supplement == iter) {
 			AST_RWLIST_REMOVE_CURRENT(next);
-			res = 0;
 			break;
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
-
-	return res;
-}
-
-void __ast_sip_unregister_supplement(struct ast_sip_supplement *supplement,
-	const char *file, int line, const char *func)
-{
-	if (!internal_sip_unregister_supplement(supplement)) {
-		__ast_module_unref(ast_module_info->self, file, line, func);
-	}
 }
 
 static int send_in_dialog_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg)
@@ -4887,7 +4826,7 @@
 		ast_res_pjsip_destroy_configuration();
 		ast_sip_destroy_system();
 		ast_sip_destroy_global_headers();
-		internal_sip_unregister_service(&supplement_module);
+		ast_sip_unregister_service(&supplement_module);
 		ast_sip_destroy_transport_events();
 	}
 
@@ -5054,7 +4993,7 @@
 		goto error;
 	}
 
-	if (internal_sip_register_service(&supplement_module)) {
+	if (ast_sip_register_service(&supplement_module)) {
 		ast_log(LOG_ERROR, "Failed to initialize supplement hooks. Aborting load\n");
 		goto error;
 	}
@@ -5070,8 +5009,6 @@
 
 	AST_TEST_REGISTER(xml_sanitization_end_null);
 	AST_TEST_REGISTER(xml_sanitization_exceeds_buffer);
-
-	ast_pjproject_ref();
 
 	return AST_MODULE_LOAD_SUCCESS;
 
@@ -5113,8 +5050,6 @@
 	ast_sip_destroy_scheduler();
 	serializer_pool_shutdown();
 	ast_threadpool_shutdown(sip_threadpool);
-
-	ast_pjproject_unref();
 
 	return 0;
 }
diff --git a/res/res_pjsip/config_auth.c b/res/res_pjsip/config_auth.c
index 4732681..b1bf9c4 100644
--- a/res/res_pjsip/config_auth.c
+++ b/res/res_pjsip/config_auth.c
@@ -374,7 +374,7 @@
 	ast_sorcery_object_field_register_custom(sorcery, SIP_SORCERY_AUTH_TYPE, "auth_type",
 			"userpass", auth_type_handler, auth_type_to_str, NULL, 0, 0);
 
-	internal_sip_register_endpoint_formatter(&endpoint_auth_formatter);
+	ast_sip_register_endpoint_formatter(&endpoint_auth_formatter);
 
 	cli_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL);
 	if (!cli_formatter) {
@@ -403,7 +403,7 @@
 {
 	ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
 	ast_sip_unregister_cli_formatter(cli_formatter);
-	internal_sip_unregister_endpoint_formatter(&endpoint_auth_formatter);
+	ast_sip_unregister_endpoint_formatter(&endpoint_auth_formatter);
 
 	ast_manager_unregister("PJSIPShowAuths");
 
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 63bf118..d08b33b 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -1435,7 +1435,7 @@
 	ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
 	ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
 
-	internal_sip_register_endpoint_formatter(&endpoint_transport_formatter);
+	ast_sip_register_endpoint_formatter(&endpoint_transport_formatter);
 
 	cli_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL);
 	if (!cli_formatter) {
@@ -1465,7 +1465,7 @@
 	ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
 	ast_sip_unregister_cli_formatter(cli_formatter);
 
-	internal_sip_unregister_endpoint_formatter(&endpoint_transport_formatter);
+	ast_sip_unregister_endpoint_formatter(&endpoint_transport_formatter);
 
 	ao2_ref(transport_states, -1);
 	transport_states = NULL;
diff --git a/res/res_pjsip/include/res_pjsip_private.h b/res/res_pjsip/include/res_pjsip_private.h
index 5ce3c6f..7fafd80 100644
--- a/res/res_pjsip/include/res_pjsip_private.h
+++ b/res/res_pjsip/include/res_pjsip_private.h
@@ -314,55 +314,7 @@
  */
 int sip_cli_print_system(struct ast_sip_cli_context *context);
 
-/*!
- * \internal
- * \brief Used by res_pjsip.so to register a service without adding a self reference
- */
-int internal_sip_register_service(pjsip_module *module);
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to unregister a service without removing a self reference
- */
-int internal_sip_unregister_service(pjsip_module *module);
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to register a supplement without adding a self reference
- */
-void internal_sip_register_supplement(struct ast_sip_supplement *supplement);
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to unregister a supplement without removing a self reference
- */
-int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement);
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to register an endpoint formatter without adding a self reference
- */
-void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to unregister a endpoint formatter without removing a self reference
- */
-int internal_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
-
 struct ast_sip_session_supplement;
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to register a session supplement without adding a self reference
- */
-void internal_sip_session_register_supplement(struct ast_sip_session_supplement *supplement);
-
-/*!
- * \internal
- * \brief Used by res_pjsip.so to unregister a session supplement without removing a self reference
- */
-int internal_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
 
 /*!
  * \internal
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index eb9e588..84f73c7 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -1346,7 +1346,7 @@
 	ast_sorcery_object_field_register(sorcery, "aor", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, outbound_proxy));
 	ast_sorcery_object_field_register(sorcery, "aor", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, support_path));
 
-	internal_sip_register_endpoint_formatter(&endpoint_aor_formatter);
+	ast_sip_register_endpoint_formatter(&endpoint_aor_formatter);
 
 	contact_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL);
 	if (!contact_formatter) {
@@ -1402,7 +1402,7 @@
 	ast_sip_unregister_cli_formatter(aor_formatter);
 	ast_manager_unregister("PJSIPShowAors");
 
-	internal_sip_unregister_endpoint_formatter(&endpoint_aor_formatter);
+	ast_sip_unregister_endpoint_formatter(&endpoint_aor_formatter);
 
 	return 0;
 }
diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c
index b4828d8..c239c1a 100644
--- a/res/res_pjsip/pjsip_distributor.c
+++ b/res/res_pjsip/pjsip_distributor.c
@@ -1243,15 +1243,15 @@
 		return -1;
 	}
 
-	if (internal_sip_register_service(&distributor_mod)) {
+	if (ast_sip_register_service(&distributor_mod)) {
 		ast_sip_destroy_distributor();
 		return -1;
 	}
-	if (internal_sip_register_service(&endpoint_mod)) {
+	if (ast_sip_register_service(&endpoint_mod)) {
 		ast_sip_destroy_distributor();
 		return -1;
 	}
-	if (internal_sip_register_service(&auth_mod)) {
+	if (ast_sip_register_service(&auth_mod)) {
 		ast_sip_destroy_distributor();
 		return -1;
 	}
@@ -1282,9 +1282,9 @@
 	ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
 	ast_sip_unregister_cli_formatter(unid_formatter);
 
-	internal_sip_unregister_service(&auth_mod);
-	internal_sip_unregister_service(&endpoint_mod);
-	internal_sip_unregister_service(&distributor_mod);
+	ast_sip_unregister_service(&auth_mod);
+	ast_sip_unregister_service(&endpoint_mod);
+	ast_sip_unregister_service(&distributor_mod);
 
 	ao2_global_obj_release(artificial_auth);
 	ao2_cleanup(artificial_endpoint);
diff --git a/res/res_pjsip/pjsip_global_headers.c b/res/res_pjsip/pjsip_global_headers.c
index 4de28b5..52075ae 100644
--- a/res/res_pjsip/pjsip_global_headers.c
+++ b/res/res_pjsip/pjsip_global_headers.c
@@ -165,7 +165,7 @@
 	AST_RWLIST_HEAD_INIT(&request_headers);
 	AST_RWLIST_HEAD_INIT(&response_headers);
 
-	internal_sip_register_service(&global_header_mod);
+	ast_sip_register_service(&global_header_mod);
 }
 
 static void destroy_headers(struct header_list *headers)
@@ -183,5 +183,5 @@
 	destroy_headers(&request_headers);
 	destroy_headers(&response_headers);
 
-	internal_sip_unregister_service(&global_header_mod);
+	ast_sip_unregister_service(&global_header_mod);
 }
diff --git a/res/res_pjsip/pjsip_message_filter.c b/res/res_pjsip/pjsip_message_filter.c
index 427aec7..f948c44 100644
--- a/res/res_pjsip/pjsip_message_filter.c
+++ b/res/res_pjsip/pjsip_message_filter.c
@@ -517,24 +517,24 @@
 
 void ast_res_pjsip_cleanup_message_filter(void)
 {
-	internal_sip_unregister_service(&filter_module_tsx);
-	internal_sip_unregister_service(&filter_module_transport);
-	internal_sip_unregister_supplement(&filter_supplement);
-	internal_sip_session_unregister_supplement(&filter_session_supplement);
+	ast_sip_unregister_service(&filter_module_tsx);
+	ast_sip_unregister_service(&filter_module_transport);
+	ast_sip_unregister_supplement(&filter_supplement);
+	ast_sip_session_unregister_supplement(&filter_session_supplement);
 }
 
 int ast_res_pjsip_init_message_filter(void)
 {
-	internal_sip_session_register_supplement(&filter_session_supplement);
-	internal_sip_register_supplement(&filter_supplement);
+	ast_sip_session_register_supplement(&filter_session_supplement);
+	ast_sip_register_supplement(&filter_supplement);
 
-	if (internal_sip_register_service(&filter_module_transport)) {
+	if (ast_sip_register_service(&filter_module_transport)) {
 		ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
 		ast_res_pjsip_cleanup_message_filter();
 		return -1;
 	}
 
-	if (internal_sip_register_service(&filter_module_tsx)) {
+	if (ast_sip_register_service(&filter_module_tsx)) {
 		ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
 		ast_res_pjsip_cleanup_message_filter();
 		return -1;
diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c
index 9d7402b..5d3f234 100644
--- a/res/res_pjsip/pjsip_options.c
+++ b/res/res_pjsip/pjsip_options.c
@@ -1477,7 +1477,7 @@
 		return -1;
 	}
 
-	internal_sip_register_endpoint_formatter(&contact_status_formatter);
+	ast_sip_register_endpoint_formatter(&contact_status_formatter);
 	ast_manager_register_xml("PJSIPQualify", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, ami_sip_qualify);
 	ast_cli_register_multiple(cli_options, ARRAY_LEN(cli_options));
 
@@ -1491,7 +1491,7 @@
 {
 	ast_cli_unregister_multiple(cli_options, ARRAY_LEN(cli_options));
 	ast_manager_unregister("PJSIPQualify");
-	internal_sip_unregister_endpoint_formatter(&contact_status_formatter);
+	ast_sip_unregister_endpoint_formatter(&contact_status_formatter);
 
 	ast_sorcery_observer_remove(ast_sip_get_sorcery(), "aor", &observer_callbacks_options);
 	pjsip_endpt_unregister_module(ast_sip_get_pjsip_endpoint(), &options_module);
diff --git a/res/res_pjsip/pjsip_session.c b/res/res_pjsip/pjsip_session.c
index 153561c..f3f3a4d 100644
--- a/res/res_pjsip/pjsip_session.c
+++ b/res/res_pjsip/pjsip_session.c
@@ -32,7 +32,7 @@
 
 AST_RWLIST_HEAD_STATIC(session_supplements, ast_sip_session_supplement);
 
-void internal_sip_session_register_supplement(struct ast_sip_session_supplement *supplement)
+void ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement)
 {
 	struct ast_sip_session_supplement *iter;
 	int inserted = 0;
@@ -56,39 +56,18 @@
 	}
 }
 
-int __ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement,
-	const char *file, int line, const char *func)
-{
-	internal_sip_session_register_supplement(supplement);
-	__ast_module_ref(AST_MODULE_SELF, file, line, func);
-
-	return 0;
-}
-
-int internal_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
+void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
 {
 	struct ast_sip_session_supplement *iter;
-	int res = -1;
 	SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
 
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) {
 		if (supplement == iter) {
 			AST_RWLIST_REMOVE_CURRENT(next);
-			res = 0;
 			break;
 		}
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
-
-	return res;
-}
-
-void __ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement,
-	const char *file, int line, const char *func)
-{
-	if (!internal_sip_session_unregister_supplement(supplement)) {
-		__ast_module_unref(AST_MODULE_SELF, file, line, func);
-	}
 }
 
 static struct ast_sip_session_supplement *supplement_dup(const struct ast_sip_session_supplement *src)
diff --git a/res/res_pjsip_config_wizard.c b/res/res_pjsip_config_wizard.c
index 3a761a7..04555da 100644
--- a/res/res_pjsip_config_wizard.c
+++ b/res/res_pjsip_config_wizard.c
@@ -1199,21 +1199,18 @@
 	}
 }
 
-/*! \brief When the res_pjsip instance is created, add an observer to it and initialize the wizard vector.
- * Also, bump the module's ref count so it can't be unloaded before the sorcery instance is
- * destroyed.
+/*! \brief When the res_pjsip instance is created, add an observer to it and
+ * initialize the wizard vector.
  */
 static void instance_created_observer(const char *name, struct ast_sorcery *sorcery)
 {
 	if (strcmp(name, "res_pjsip")) {
 		return;
 	}
-	ast_module_ref(ast_module_info->self);
 	ast_sorcery_instance_observer_add(sorcery, &observer);
 }
 
-/*! \brief When the res_pjsip instance is destroyed, remove the observer
- * and unref the module.  This should then allow this module to unload cleanly.
+/*! \brief When the res_pjsip instance is destroyed, remove the observer.
  */
 static void instance_destroying_observer(const char *name, struct ast_sorcery *sorcery)
 {
@@ -1222,7 +1219,6 @@
 	}
 
 	ast_sorcery_instance_observer_remove(sorcery, &observer);
-	ast_module_unref(ast_module_info->self);
 }
 
 static char *handle_export_primitives(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
diff --git a/res/res_pjsip_dlg_options.c b/res/res_pjsip_dlg_options.c
index 565ad2a..924df06 100644
--- a/res/res_pjsip_dlg_options.c
+++ b/res/res_pjsip_dlg_options.c
@@ -85,9 +85,8 @@
 {
 	CHECK_PJSIP_MODULE_LOADED();
 
-	if (ast_sip_session_register_supplement(&dlg_options_supplement)) {
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	ast_sip_session_register_supplement(&dlg_options_supplement);
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c
index 4231a1e..406e1fe 100644
--- a/res/res_pjsip_nat.c
+++ b/res/res_pjsip_nat.c
@@ -364,11 +364,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	if (ast_sip_session_register_supplement(&nat_supplement)) {
-		ast_log(LOG_ERROR, "Could not register NAT session supplement for incoming and outgoing INVITE requests\n");
-		unload_module();
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	ast_sip_session_register_supplement(&nat_supplement);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }
diff --git a/res/res_pjsip_one_touch_record_info.c b/res/res_pjsip_one_touch_record_info.c
index ef59fca..dda8d85 100644
--- a/res/res_pjsip_one_touch_record_info.c
+++ b/res/res_pjsip_one_touch_record_info.c
@@ -109,10 +109,7 @@
 {
 	CHECK_PJSIP_SESSION_MODULE_LOADED();
 
-	if (ast_sip_session_register_supplement(&info_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register One Touch Recording supplement\n");
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	ast_sip_session_register_supplement(&info_supplement);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }
diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c
index b4e3320..692a104 100644
--- a/res/res_pjsip_outbound_publish.c
+++ b/res/res_pjsip_outbound_publish.c
@@ -345,7 +345,6 @@
 static void sub_add_handler(struct ast_sip_event_publisher_handler *handler)
 {
 	AST_RWLIST_INSERT_TAIL(&publisher_handlers, handler, next);
-	ast_module_ref(ast_module_info->self);
 }
 
 static struct ast_sip_event_publisher_handler *find_publisher_handler_for_event_name(const char *event_name)
@@ -643,7 +642,6 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&publisher_handlers, iter, next) {
 		if (handler == iter) {
 			AST_RWLIST_REMOVE_CURRENT(next);
-			ast_module_unref(ast_module_info->self);
 			break;
 		}
 	}
diff --git a/res/res_pjsip_path.c b/res/res_pjsip_path.c
index b245f15..80937c2 100644
--- a/res/res_pjsip_path.c
+++ b/res/res_pjsip_path.c
@@ -240,14 +240,8 @@
 {
 	CHECK_PJSIP_SESSION_MODULE_LOADED();
 
-	if (ast_sip_register_supplement(&path_supplement)) {
-		return AST_MODULE_LOAD_DECLINE;
-	}
-
-	if (ast_sip_session_register_supplement(&path_session_supplement)) {
-		ast_sip_unregister_supplement(&path_supplement);
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	ast_sip_register_supplement(&path_supplement);
+	ast_sip_session_register_supplement(&path_session_supplement);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index af696b8..5e0d2e5 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -2583,8 +2583,6 @@
 
 	publish_add_handler(handler);
 
-	ast_module_ref(ast_module_info->self);
-
 	return 0;
 }
 
@@ -2597,7 +2595,6 @@
 		if (handler == iter) {
 			AST_RWLIST_REMOVE_CURRENT(next);
 			ao2_cleanup(handler->publications);
-			ast_module_unref(ast_module_info->self);
 			break;
 		}
 	}
@@ -2611,7 +2608,6 @@
 {
 	AST_RWLIST_WRLOCK(&subscription_handlers);
 	AST_RWLIST_INSERT_TAIL(&subscription_handlers, handler, next);
-	ast_module_ref(ast_module_info->self);
 	AST_RWLIST_UNLOCK(&subscription_handlers);
 }
 
@@ -2670,7 +2666,6 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&subscription_handlers, iter, next) {
 		if (handler == iter) {
 			AST_RWLIST_REMOVE_CURRENT(next);
-			ast_module_unref(ast_module_info->self);
 			break;
 		}
 	}
diff --git a/res/res_pjsip_send_to_voicemail.c b/res/res_pjsip_send_to_voicemail.c
index 06c3edc..a5beed4 100644
--- a/res/res_pjsip_send_to_voicemail.c
+++ b/res/res_pjsip_send_to_voicemail.c
@@ -217,10 +217,7 @@
 {
 	CHECK_PJSIP_SESSION_MODULE_LOADED();
 
-	if (ast_sip_session_register_supplement(&refer_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register Send to Voicemail supplement\n");
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	ast_sip_session_register_supplement(&refer_supplement);
 
 	return AST_MODULE_LOAD_SUCCESS;
 }
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 8247fba..d649332 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -124,7 +124,7 @@
 		}
 		AST_LIST_INSERT_TAIL(&handler_list->list, handler, next);
 		ast_debug(1, "Registered SDP stream handler '%s' for stream type '%s'\n", handler->id, stream_type);
-		ast_module_ref(ast_module_info->self);
+
 		return 0;
 	}
 
@@ -141,7 +141,7 @@
 		return -1;
 	}
 	ast_debug(1, "Registered SDP stream handler '%s' for stream type '%s'\n", handler->id, stream_type);
-	ast_module_ref(ast_module_info->self);
+
 	return 0;
 }
 
@@ -156,7 +156,6 @@
 		if (!strcmp(iter->id, handler->id)) {
 			AST_LIST_REMOVE_CURRENT(next);
 			ast_debug(1, "Unregistered SDP stream handler '%s' for stream type '%s'\n", handler->id, stream_type);
-			ast_module_unref(ast_module_info->self);
 		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c
index 7b7cd99..9b61c5d 100644
--- a/res/res_pjsip_t38.c
+++ b/res/res_pjsip_t38.c
@@ -1031,10 +1031,7 @@
 		ast_sockaddr_parse(&address, "0.0.0.0", 0);
 	}
 
-	if (ast_sip_session_register_supplement(&t38_supplement)) {
-		ast_log(LOG_ERROR, "Unable to register T.38 session supplement\n");
-		goto end;
-	}
+	ast_sip_session_register_supplement(&t38_supplement);
 
 	if (ast_sip_session_register_sdp_handler(&image_sdp_handler, "image")) {
 		ast_log(LOG_ERROR, "Unable to register SDP handler for image stream type\n");
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index af1345f..bc6068b 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -490,10 +490,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	if (ast_sip_session_register_supplement(&websocket_supplement)) {
-		ast_sip_unregister_service(&websocket_module);
-		return AST_MODULE_LOAD_DECLINE;
-	}
+	ast_sip_session_register_supplement(&websocket_supplement);
 
 	if (ast_websocket_add_protocol("sip", websocket_cb)) {
 		ast_sip_session_unregister_supplement(&websocket_supplement);
diff --git a/res/res_pktccops.c b/res/res_pktccops.c
index 3a12285..9beabfb 100644
--- a/res/res_pktccops.c
+++ b/res/res_pktccops.c
@@ -1472,9 +1472,6 @@
 	ast_cli_register_multiple(cli_pktccops, sizeof(cli_pktccops) / sizeof(struct ast_cli_entry));
 	restart_pktc_thread();
 
-	/* For Optional API. */
-	ast_module_shutdown_ref(AST_MODULE_SELF);
-
 	return 0;
 }
 
diff --git a/res/res_smdi.c b/res/res_smdi.c
index 76e70c2..1d4826a 100644
--- a/res/res_smdi.c
+++ b/res/res_smdi.c
@@ -1405,9 +1405,6 @@
 	ast_custom_function_register(&smdi_msg_retrieve_function);
 	ast_custom_function_register(&smdi_msg_function);
 
-	/* For Optional API. */
-	ast_module_shutdown_ref(AST_MODULE_SELF);
-
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
diff --git a/res/res_stasis.c b/res/res_stasis.c
index a60ec5f..dcd7414 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -1302,8 +1302,6 @@
 int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc,
 		    char *argv[])
 {
-	SCOPED_MODULE_USE(ast_module_info->self);
-
 	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
 	struct ast_bridge *bridge = NULL;
@@ -1654,11 +1652,6 @@
 {
 	AST_RWLIST_WRLOCK(&event_sources);
 	AST_LIST_INSERT_TAIL(&event_sources, obj, next);
-	/* only need to bump the module ref on non-core sources because the
-	   core ones are [un]registered by this module. */
-	if (!stasis_app_is_core_event_source(obj)) {
-		ast_module_ref(ast_module_info->self);
-	}
 	AST_RWLIST_UNLOCK(&event_sources);
 }
 
@@ -1670,9 +1663,6 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&event_sources, source, next) {
 		if (source == obj) {
 			AST_RWLIST_REMOVE_CURRENT(next);
-			if (!stasis_app_is_core_event_source(obj)) {
-				ast_module_unref(ast_module_info->self);
-			}
 			break;
 		}
 	}
@@ -2034,16 +2024,6 @@
 	ao2_ref(message, -1);
 
 	return STASIS_APP_USER_OK;
-}
-
-void stasis_app_ref(void)
-{
-	ast_module_ref(ast_module_info->self);
-}
-
-void stasis_app_unref(void)
-{
-	ast_module_unref(ast_module_info->self);
 }
 
 static int unload_module(void)
diff --git a/res/res_stasis_mailbox.c b/res/res_stasis_mailbox.c
index 3d0e9db..3f6bede 100644
--- a/res/res_stasis_mailbox.c
+++ b/res/res_stasis_mailbox.c
@@ -143,17 +143,11 @@
 
 static int load_module(void)
 {
-	/* Must be done first */
-	ast_mwi_external_ref();
-
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)
 {
-	/* Must be done last */
-	ast_mwi_external_unref();
-
 	return 0;
 }
 
diff --git a/res/res_statsd.c b/res/res_statsd.c
index 221b359..8e647bc 100644
--- a/res/res_statsd.c
+++ b/res/res_statsd.c
@@ -353,9 +353,6 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	/* For Optional API. */
-	ast_module_shutdown_ref(AST_MODULE_SELF);
-
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
diff --git a/res/stasis/app.c b/res/stasis/app.c
index 854e799..18ac7d6 100644
--- a/res/stasis/app.c
+++ b/res/stasis/app.c
@@ -1600,13 +1600,6 @@
 	stasis_app_register_event_source(&endpoint_event_source);
 }
 
-int stasis_app_is_core_event_source(struct stasis_app_event_source *obj)
-{
-	return obj == &endpoint_event_source ||
-		obj == &bridge_event_source ||
-		obj == &channel_event_source;
-}
-
 void stasis_app_unregister_event_sources(void)
 {
 	stasis_app_unregister_event_source(&endpoint_event_source);
diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache
index c1f680f..b70c251 100644
--- a/rest-api-templates/res_ari_resource.c.mustache
+++ b/rest-api-templates/res_ari_resource.c.mustache
@@ -266,7 +266,6 @@
 	ast_ari_websocket_events_event_websocket_dtor();
 {{/has_websocket}}
 {{/apis}}
-	stasis_app_unref();
 	return 0;
 }
 
@@ -310,7 +309,6 @@
 {{/operations}}
 {{/apis}}
 
-	stasis_app_ref();
 	res |= ast_ari_add_handler(&{{root_full_name}});
 	if (res) {
 		unload_module();
diff --git a/tests/test_res_stasis.c b/tests/test_res_stasis.c
index 077cc4c..2c7906a 100644
--- a/tests/test_res_stasis.c
+++ b/tests/test_res_stasis.c
@@ -179,13 +179,11 @@
 	AST_TEST_UNREGISTER(app_invoke_dne);
 	AST_TEST_UNREGISTER(app_invoke_one);
 	AST_TEST_UNREGISTER(app_replaced);
-	stasis_app_unref();
 	return 0;
 }
 
 static int load_module(void)
 {
-	stasis_app_ref();
 	AST_TEST_REGISTER(app_replaced);
 	AST_TEST_REGISTER(app_invoke_one);
 	AST_TEST_REGISTER(app_invoke_dne);

-- 
To view, visit https://gerrit.asterisk.org/7989
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I332a6e8383d4c72c8e89d988a184ab8320c4872e
Gerrit-Change-Number: 7989
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180117/dfd9b0ac/attachment-0001.html>


More information about the asterisk-code-review mailing list