From 9cfdb81e913a8dd363ca4570b4eb4137de3b5837 Mon Sep 17 00:00:00 2001
From: Corey Farrell <git@cfware.com>
Date: Sun, 19 Nov 2017 17:30:49 -0500
Subject: [PATCH] loader: Add dependency fields to module structures.

* Declare 'requires' and 'enhances' text fields on module info structure.
* Rename 'nonoptreq' to 'optional_modules'.
* Update doxygen comments.

Still need to investigate dependencies among modules I cannot compile.

Change-Id: I3ad9547a0a6442409ff4e352a6d897bef2cc04bf
---
 apps/app_adsiprog.c                           |  2 +-
 apps/app_getcpeid.c                           |  2 +-
 apps/app_queue.c                              |  2 +-
 apps/app_speech_utils.c                       |  2 +-
 apps/app_stack.c                              |  2 +-
 apps/app_stasis.c                             |  2 +-
 apps/app_voicemail.c                          |  2 +-
 channels/chan_dahdi.c                         |  2 +-
 channels/chan_iax2.c                          |  2 +-
 channels/chan_mgcp.c                          |  2 +-
 channels/chan_motif.c                         |  1 +
 channels/chan_pjsip.c                         |  1 +
 channels/chan_rtp.c                           |  1 +
 channels/chan_sip.c                           |  2 +-
 funcs/func_aes.c                              |  2 +-
 funcs/func_pjsip_aor.c                        |  7 ++-
 funcs/func_pjsip_contact.c                    |  7 ++-
 funcs/func_pjsip_endpoint.c                   |  7 ++-
 include/asterisk/module.h                     | 60 +++++++++++++++----
 pbx/pbx_ael.c                                 |  1 +
 pbx/pbx_dundi.c                               |  2 +-
 res/res_agi.c                                 |  1 +
 res/res_ari.c                                 |  3 +-
 res/res_ari_applications.c                    |  2 +-
 res/res_ari_asterisk.c                        |  2 +-
 res/res_ari_bridges.c                         |  2 +-
 res/res_ari_channels.c                        |  2 +-
 res/res_ari_device_states.c                   |  2 +-
 res/res_ari_endpoints.c                       |  2 +-
 res/res_ari_events.c                          |  2 +-
 res/res_ari_mailboxes.c                       |  2 +-
 res/res_ari_playbacks.c                       |  2 +-
 res/res_ari_recordings.c                      |  2 +-
 res/res_ari_sounds.c                          |  2 +-
 res/res_chan_stats.c                          |  2 +-
 res/res_endpoint_stats.c                      |  2 +-
 res/res_fax_spandsp.c                         |  1 +
 res/res_hep_pjsip.c                           |  1 +
 res/res_hep_rtcp.c                            |  1 +
 res/res_mwi_external_ami.c                    |  2 +
 res/res_pjsip.c                               |  1 +
 res/res_pjsip_acl.c                           |  1 +
 res/res_pjsip_authenticator_digest.c          |  1 +
 res/res_pjsip_caller_id.c                     |  2 +-
 res/res_pjsip_dialog_info_body_generator.c    |  2 +-
 res/res_pjsip_diversion.c                     |  2 +-
 res/res_pjsip_dlg_options.c                   |  2 +-
 res/res_pjsip_dtmf_info.c                     |  2 +-
 res/res_pjsip_empty_info.c                    |  2 +-
 res/res_pjsip_endpoint_identifier_anonymous.c |  1 +
 res/res_pjsip_endpoint_identifier_ip.c        |  1 +
 res/res_pjsip_endpoint_identifier_user.c      |  1 +
 res/res_pjsip_exten_state.c                   |  1 +
 res/res_pjsip_header_funcs.c                  |  1 +
 res/res_pjsip_history.c                       |  1 +
 res/res_pjsip_logger.c                        |  1 +
 res/res_pjsip_messaging.c                     |  2 +-
 res/res_pjsip_mwi.c                           |  1 +
 res/res_pjsip_mwi_body_generator.c            |  1 +
 res/res_pjsip_nat.c                           |  1 +
 res/res_pjsip_notify.c                        |  1 +
 res/res_pjsip_one_touch_record_info.c         |  2 +-
 res/res_pjsip_outbound_authenticator_digest.c |  1 +
 res/res_pjsip_outbound_publish.c              |  1 +
 res/res_pjsip_outbound_registration.c         |  1 +
 res/res_pjsip_path.c                          |  1 +
 res/res_pjsip_phoneprov_provider.c            |  1 +
 res/res_pjsip_pidf_body_generator.c           |  1 +
 res/res_pjsip_pidf_digium_body_supplement.c   |  1 +
 res/res_pjsip_pidf_eyebeam_body_supplement.c  |  1 +
 res/res_pjsip_publish_asterisk.c              |  1 +
 res/res_pjsip_pubsub.c                        |  1 +
 res/res_pjsip_refer.c                         |  1 +
 res/res_pjsip_registrar.c                     |  1 +
 res/res_pjsip_registrar_expire.c              |  1 +
 res/res_pjsip_rfc3326.c                       |  2 +-
 res/res_pjsip_sdp_rtp.c                       |  1 +
 res/res_pjsip_send_to_voicemail.c             |  1 +
 res/res_pjsip_session.c                       |  1 +
 res/res_pjsip_sips_contact.c                  |  1 +
 res/res_pjsip_t38.c                           |  1 +
 res/res_pjsip_transport_management.c          |  1 +
 res/res_pjsip_transport_websocket.c           |  1 +
 res/res_pjsip_xpidf_body_generator.c          |  2 +-
 res/res_stasis_answer.c                       |  2 +-
 res/res_stasis_device_state.c                 |  2 +-
 res/res_stasis_mailbox.c                      |  2 +-
 res/res_stasis_playback.c                     |  2 +-
 res/res_stasis_recording.c                    |  2 +-
 res/res_stasis_snoop.c                        |  2 +-
 .../res_ari_resource.c.mustache               |  2 +-
 tests/test_ari.c                              |  2 +-
 tests/test_ari_model.c                        |  7 ++-
 tests/test_res_pjsip_scheduler.c              |  7 ++-
 tests/test_res_stasis.c                       |  2 +-
 tests/test_stasis_endpoints.c                 |  2 +-
 96 files changed, 170 insertions(+), 64 deletions(-)

diff --git a/apps/app_adsiprog.c b/apps/app_adsiprog.c
index 2dd226fbde..688168e522 100644
--- a/apps/app_adsiprog.c
+++ b/apps/app_adsiprog.c
@@ -1613,5 +1613,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk ADSI Programmin
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_adsi",
+	.requires = "res_adsi",
 );
diff --git a/apps/app_getcpeid.c b/apps/app_getcpeid.c
index e0b9f12393..868dc97c3b 100644
--- a/apps/app_getcpeid.c
+++ b/apps/app_getcpeid.c
@@ -140,5 +140,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get ADSI CPE ID",
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_adsi",
+	.requires = "res_adsi",
 );
diff --git a/apps/app_queue.c b/apps/app_queue.c
index c62828cfd8..e7779b7327 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -11345,5 +11345,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "True Call Queueing",
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
-	.nonoptreq = "res_monitor",
+	.optional_modules = "res_monitor",
 );
diff --git a/apps/app_speech_utils.c b/apps/app_speech_utils.c
index 339c3161f6..2ba297e330 100644
--- a/apps/app_speech_utils.c
+++ b/apps/app_speech_utils.c
@@ -1003,5 +1003,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Dialplan Speech Applicat
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_speech",
+	.requires = "res_speech",
 );
diff --git a/apps/app_stack.c b/apps/app_stack.c
index 459c06df24..1f98378c96 100644
--- a/apps/app_stack.c
+++ b/apps/app_stack.c
@@ -1320,5 +1320,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT | AST_MODFLAG_LOAD_ORDER,
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
-	.nonoptreq = "res_agi",
+	.optional_modules = "res_agi",
 );
diff --git a/apps/app_stasis.c b/apps/app_stasis.c
index 81c58e8b0c..8d09349b92 100644
--- a/apps/app_stasis.c
+++ b/apps/app_stasis.c
@@ -144,5 +144,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan applicat
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis",
+	.requires = "res_stasis",
 );
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 0bcfa4f3ae..4853a53f98 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -16488,5 +16488,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, tdesc,
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload,
-	.nonoptreq = "res_adsi,res_smdi",
+	.optional_modules = "res_adsi,res_smdi",
 );
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 4859d1a60c..de2c152790 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -19542,5 +19542,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, tdesc,
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
-	.nonoptreq = "res_smdi",
+	.optional_modules = "res_smdi",
 );
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 469fcda9eb..eade5d13cf 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -14902,5 +14902,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Inter Asterisk eXchan
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
-	.nonoptreq = "res_crypto",
+	.optional_modules = "res_crypto",
 );
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 547226c80e..2ac7690a6e 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -5025,5 +5025,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Media Gateway Control
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
-	.nonoptreq = "res_pktccops",
+	.optional_modules = "res_pktccops",
 );
diff --git a/channels/chan_motif.c b/channels/chan_motif.c
index df1eeb8cef..05184ca049 100644
--- a/channels/chan_motif.c
+++ b/channels/chan_motif.c
@@ -2821,4 +2821,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Motif Jingle Channel
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
+	.requires = "res_xmpp",
 );
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 4c30d335b2..68da4a1bba 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -3110,4 +3110,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Channel Driver"
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
+	.requires = "res_pjsip,res_pjsip_session",
 );
diff --git a/channels/chan_rtp.c b/channels/chan_rtp.c
index 0a59e330ed..7d9e26db89 100644
--- a/channels/chan_rtp.c
+++ b/channels/chan_rtp.c
@@ -432,4 +432,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "RTP Media Channel",
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
+	.requires = "res_rtp_multicast",
 );
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index e8cc591a30..fa98990272 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -35737,5 +35737,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Session Initiation Pr
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
-	.nonoptreq = "res_crypto,res_http_websocket",
+	.optional_modules = "res_crypto,res_http_websocket",
 );
diff --git a/funcs/func_aes.c b/funcs/func_aes.c
index 7208cd4c8b..af3f257e50 100644
--- a/funcs/func_aes.c
+++ b/funcs/func_aes.c
@@ -180,5 +180,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "AES dialplan functions",
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_crypto",
+	.requires = "res_crypto",
 );
diff --git a/funcs/func_pjsip_aor.c b/funcs/func_pjsip_aor.c
index 799e9e4ed5..589f667afd 100644
--- a/funcs/func_pjsip_aor.c
+++ b/funcs/func_pjsip_aor.c
@@ -181,4 +181,9 @@ static int load_module(void)
 	return ast_custom_function_register(&pjsip_aor_function);
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get information about a PJSIP AOR");
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get information about a PJSIP AOR",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.requires = "res_pjsip",
+);
diff --git a/funcs/func_pjsip_contact.c b/funcs/func_pjsip_contact.c
index c8403655ab..fac4cb68c4 100644
--- a/funcs/func_pjsip_contact.c
+++ b/funcs/func_pjsip_contact.c
@@ -198,4 +198,9 @@ static int load_module(void)
 	return ast_custom_function_register(&pjsip_contact_function);
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get information about a PJSIP contact");
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get information about a PJSIP contact",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.requires = "res_pjsip",
+);
diff --git a/funcs/func_pjsip_endpoint.c b/funcs/func_pjsip_endpoint.c
index a64d93b1ed..e4a6abab36 100644
--- a/funcs/func_pjsip_endpoint.c
+++ b/funcs/func_pjsip_endpoint.c
@@ -156,4 +156,9 @@ static int load_module(void)
 	return ast_custom_function_register(&pjsip_endpoint_function);
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Get information about a PJSIP endpoint");
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Get information about a PJSIP endpoint",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.requires = "res_pjsip",
+);
diff --git a/include/asterisk/module.h b/include/asterisk/module.h
index 103cd3053c..ebd41c06dd 100644
--- a/include/asterisk/module.h
+++ b/include/asterisk/module.h
@@ -304,26 +304,28 @@ enum ast_module_load_priority {
 };
 
 struct ast_module_info {
-
 	/*!
 	 * The 'self' pointer for a module; it will be set by the loader before
 	 * it calls the module's load_module() entrypoint, and used by various
 	 * other macros that need to identify the module.
 	 */
-
 	struct ast_module *self;
-	enum ast_module_load_result (*load)(void);	/*!< register stuff etc. Optional. */
-	int (*reload)(void);			/*!< config etc. Optional. */
-	int (*unload)(void);			/*!< unload. called with the module locked */
-	const char *name;			/*!< name of the module for loader reference and CLI commands */
-	const char *description;		/*!< user friendly description of the module. */
+	/*! Register stuff etc. Optional. */
+	enum ast_module_load_result (*load)(void);
+	/*! Config etc. Optional. */
+	int (*reload)(void);
+	/*! Unload. called with the module locked */
+	int (*unload)(void);
+	/*! Name of the module for loader reference and CLI commands */
+	const char *name;
+	/*! User friendly description of the module. */
+	const char *description;
 
 	/*!
 	 * This holds the ASTERISK_GPL_KEY, signifiying that you agree to the terms of
 	 * the Asterisk license as stated in the ASTERISK_GPL_KEY.  Your module will not
 	 * load if it does not return the EXACT key string.
 	 */
-
 	const char *key;
 	unsigned int flags;
 
@@ -337,10 +339,42 @@ struct ast_module_info {
 	 *  on load. */
 	unsigned char load_pri;
 
-	/*! Modules which should be loaded first, in comma-separated string format.
-	 * These are only required for loading, when the optional_api header file
-	 * detects that the compiler does not support the optional API featureset. */
-	const char *nonoptreq;
+	/*! Modules which must always be started first, in comma-separated string format. */
+	const char *requires;
+
+	/*!
+	 * \brief Comma-separated list of optionally required modules.
+	 *
+	 * The listed modules are optional, but load order is enforced.  For example
+	 * app_voicemail optionally requires res_adsi.  This means that app_voicemail
+	 * will happily load without res_adsi, but if both are being loaded the module
+	 * loader will force res_adsi to start first.
+	 */
+	const char *optional_modules;
+
+	/*!
+	 * \brief Modules that we provide enhanced functionality for.
+	 *
+	 * This is similar to a "requires" but specifies that we add functionality to
+	 * the other modules.  Any module that requires something we "enhances" will
+	 * also require us, but only if we are dlopen'ed.
+	 *
+	 * Example:
+	 * - res_fax_spandsp has .enhances = "res_fax".
+	 * - res_my_module has .requires = "res_fax" but has no direct knowledge
+	 *   of res_fax_spandsp.
+	 *
+	 * This forces the following startup order among the 3 modules:
+	 * 1) res_fax starts.
+	 * 2) res_fax_spandsp starts, holds a reference to res_fax.
+	 * 3) res_mymod starts, holds a reference to res_fax and res_fax_spandsp.
+	 *
+	 * If res_fax_spandsp were not being loaded res_mymod would load with
+	 * res_fax only.  If res_fax_spandsp were later loaded res_mymod would
+	 * get a reference to it.
+	 */
+	const char *enhances;
+
 	/*! The support level for the given module */
 	enum ast_module_support_level support_level;
 };
@@ -411,6 +445,8 @@ void __ast_module_unref(struct ast_module *mod, const char *file, int line, cons
 		AST_BUILDOPT_SUM,                                              \
 		load_pri,                                                      \
 		NULL,                                                          \
+		NULL,                                                          \
+		NULL,                                                          \
 		support_level,                                                 \
 	};                                                                 \
 	static void  __attribute__((constructor)) __reg_module(void)       \
diff --git a/pbx/pbx_ael.c b/pbx/pbx_ael.c
index 6517b3aeb2..d55f2d42af 100644
--- a/pbx/pbx_ael.c
+++ b/pbx/pbx_ael.c
@@ -292,6 +292,7 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk Extension Langu
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload,
+	.requires = "res_ael_share",
 );
 
 #ifdef AAL_ARGCHECK
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index e0aeb4903c..92e71981f1 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -5063,5 +5063,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Distributed Universal Nu
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload,
-	.nonoptreq = "res_crypto",
+	.optional_modules = "res_crypto",
 );
diff --git a/res/res_agi.c b/res/res_agi.c
index 393a503511..2d0dc27439 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -4717,4 +4717,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_speech",
 );
diff --git a/res/res_ari.c b/res/res_ari.c
index 9104eded3a..6ce25a5820 100644
--- a/res/res_ari.c
+++ b/res/res_ari.c
@@ -1197,6 +1197,7 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.load = load_module,
 	.unload = unload_module,
 	.reload = reload_module,
-	.nonoptreq = "res_http_websocket",
+	.optional_modules = "res_http_websocket",
+	.requires = "res_stasis",
 	.load_pri = AST_MODPRI_APP_DEPEND,
 );
diff --git a/res/res_ari_applications.c b/res/res_ari_applications.c
index cf700c464e..323bdb39a2 100644
--- a/res/res_ari_applications.c
+++ b/res/res_ari_applications.c
@@ -518,5 +518,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Sta
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_asterisk.c b/res/res_ari_asterisk.c
index eb0617b4c7..9f76f939bd 100644
--- a/res/res_ari_asterisk.c
+++ b/res/res_ari_asterisk.c
@@ -1239,5 +1239,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Ast
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c
index 35fd3bd7ff..34b9d898cc 100644
--- a/res/res_ari_bridges.c
+++ b/res/res_ari_bridges.c
@@ -1579,5 +1579,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Bri
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c
index f6befcc90d..7862c10069 100644
--- a/res/res_ari_channels.c
+++ b/res/res_ari_channels.c
@@ -2869,5 +2869,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Cha
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_device_states.c b/res/res_ari_device_states.c
index f393935626..ec8890b1e9 100644
--- a/res/res_ari_device_states.c
+++ b/res/res_ari_device_states.c
@@ -349,5 +349,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Dev
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_endpoints.c b/res/res_ari_endpoints.c
index d1242c0fbc..07197ca97c 100644
--- a/res/res_ari_endpoints.c
+++ b/res/res_ari_endpoints.c
@@ -473,5 +473,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - End
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_events.c b/res/res_ari_events.c
index f916d0e4ee..f750a5454d 100644
--- a/res/res_ari_events.c
+++ b/res/res_ari_events.c
@@ -473,5 +473,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Web
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_mailboxes.c b/res/res_ari_mailboxes.c
index 1f6d2cc81b..6469f936ee 100644
--- a/res/res_ari_mailboxes.c
+++ b/res/res_ari_mailboxes.c
@@ -355,5 +355,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Mai
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_playbacks.c b/res/res_ari_playbacks.c
index 40099cfb48..0148a74009 100644
--- a/res/res_ari_playbacks.c
+++ b/res/res_ari_playbacks.c
@@ -307,5 +307,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Pla
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_recordings.c b/res/res_ari_recordings.c
index fe3d343ee2..531ff6574d 100644
--- a/res/res_ari_recordings.c
+++ b/res/res_ari_recordings.c
@@ -891,5 +891,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Rec
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_ari_sounds.c b/res/res_ari_sounds.c
index 8d5928a504..5c27ebd922 100644
--- a/res/res_ari_sounds.c
+++ b/res/res_ari_sounds.c
@@ -237,5 +237,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Sou
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
diff --git a/res/res_chan_stats.c b/res/res_chan_stats.c
index 061d0867eb..dbc79f03ef 100644
--- a/res/res_chan_stats.c
+++ b/res/res_chan_stats.c
@@ -182,5 +182,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Example of how to use St
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_statsd"
+	.requires = "res_statsd"
 );
diff --git a/res/res_endpoint_stats.c b/res/res_endpoint_stats.c
index 1e3f104c21..7ce44f9585 100644
--- a/res/res_endpoint_stats.c
+++ b/res/res_endpoint_stats.c
@@ -151,5 +151,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Endpoint statistics",
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_statsd"
+	.requires = "res_statsd"
 	);
diff --git a/res/res_fax_spandsp.c b/res/res_fax_spandsp.c
index a3a82e463c..045dbc7080 100644
--- a/res/res_fax_spandsp.c
+++ b/res/res_fax_spandsp.c
@@ -1266,4 +1266,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Spandsp G.711 and T.38 F
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
+	.enhances = "res_fax",
 );
diff --git a/res/res_hep_pjsip.c b/res/res_hep_pjsip.c
index 6283efc763..ff0267501e 100644
--- a/res/res_hep_pjsip.c
+++ b/res/res_hep_pjsip.c
@@ -253,4 +253,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "PJSIP HEPv3 Logger",
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
+	.requires = "res_hep,res_pjsip",
 );
diff --git a/res/res_hep_rtcp.c b/res/res_hep_rtcp.c
index afad0c8455..199c8164da 100644
--- a/res/res_hep_rtcp.c
+++ b/res/res_hep_rtcp.c
@@ -184,4 +184,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RTCP HEPv3 Logger",
 	.support_level = AST_MODULE_SUPPORT_EXTENDED,
 	.load = load_module,
 	.unload = unload_module,
+	.requires = "res_hep",
 );
diff --git a/res/res_mwi_external_ami.c b/res/res_mwi_external_ami.c
index 8419f2fff1..8639fad402 100644
--- a/res/res_mwi_external_ami.c
+++ b/res/res_mwi_external_ami.c
@@ -370,4 +370,6 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "AMI support for external
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
+	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 5,
+	.requires = "res_mwi_external",
 );
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 0311dfd4b3..3f9574d2a6 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -5125,4 +5125,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.unload = unload_module,
 	.reload = reload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 5,
+	.requires = "res_pjproject",
 );
diff --git a/res/res_pjsip_acl.c b/res/res_pjsip_acl.c
index 5c10e5779b..9269864228 100644
--- a/res/res_pjsip_acl.c
+++ b/res/res_pjsip_acl.c
@@ -321,4 +321,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP ACL Resource",
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_authenticator_digest.c b/res/res_pjsip_authenticator_digest.c
index ef57e3754e..b6f2b74ff3 100644
--- a/res/res_pjsip_authenticator_digest.c
+++ b/res/res_pjsip_authenticator_digest.c
@@ -554,4 +554,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP authentication
 	.unload = unload_module,
 	.reload = reload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 5,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_caller_id.c b/res/res_pjsip_caller_id.c
index 64191a7509..16731479e4 100644
--- a/res/res_pjsip_caller_id.c
+++ b/res/res_pjsip_caller_id.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -764,4 +763,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Caller ID Suppo
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_dialog_info_body_generator.c b/res/res_pjsip_dialog_info_body_generator.c
index 7c386e3b2d..866ea9df80 100644
--- a/res/res_pjsip_dialog_info_body_generator.c
+++ b/res/res_pjsip_dialog_info_body_generator.c
@@ -20,7 +20,6 @@
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
 	<depend>res_pjsip_pubsub</depend>
-	<depend>res_pjsip_exten_state</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -219,4 +218,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_diversion.c b/res/res_pjsip_diversion.c
index efb5489f8e..84c42dca85 100644
--- a/res/res_pjsip_diversion.c
+++ b/res/res_pjsip_diversion.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -429,4 +428,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Add Diversion H
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_dlg_options.c b/res/res_pjsip_dlg_options.c
index de1ac97efa..565ad2afc4 100644
--- a/res/res_pjsip_dlg_options.c
+++ b/res/res_pjsip_dlg_options.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
 ***/
 
@@ -103,4 +102,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP OPTIONS in dialog
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_dtmf_info.c b/res/res_pjsip_dtmf_info.c
index e534f3e27e..68df61785d 100644
--- a/res/res_pjsip_dtmf_info.c
+++ b/res/res_pjsip_dtmf_info.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -178,4 +177,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP DTMF INFO Suppo
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_empty_info.c b/res/res_pjsip_empty_info.c
index 774f9de7e0..c67835ce02 100644
--- a/res/res_pjsip_empty_info.c
+++ b/res/res_pjsip_empty_info.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -84,4 +83,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Empty INFO Supp
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_endpoint_identifier_anonymous.c b/res/res_pjsip_endpoint_identifier_anonymous.c
index b47aefa94a..16662ebd50 100644
--- a/res/res_pjsip_endpoint_identifier_anonymous.c
+++ b/res/res_pjsip_endpoint_identifier_anonymous.c
@@ -132,4 +132,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "PJSIP Anonymous endpoint
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index a672b333a1..58e4624607 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -764,4 +764,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP IP endpoint ide
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 4,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_endpoint_identifier_user.c b/res/res_pjsip_endpoint_identifier_user.c
index ff97a62e4a..1b0c7d99a0 100644
--- a/res/res_pjsip_endpoint_identifier_user.c
+++ b/res/res_pjsip_endpoint_identifier_user.c
@@ -214,4 +214,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP username endpoi
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 4,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_exten_state.c b/res/res_pjsip_exten_state.c
index 3e756134c2..e70eba7cda 100644
--- a/res/res_pjsip_exten_state.c
+++ b/res/res_pjsip_exten_state.c
@@ -1015,4 +1015,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND + 5,
+	.requires = "res_pjsip,res_pjsip_pubsub,res_pjsip_outbound_publish",
 );
diff --git a/res/res_pjsip_header_funcs.c b/res/res_pjsip_header_funcs.c
index 648f1c8602..06fba0635e 100644
--- a/res/res_pjsip_header_funcs.c
+++ b/res/res_pjsip_header_funcs.c
@@ -629,4 +629,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Header Function
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip,res_pjsip_session",
 );
diff --git a/res/res_pjsip_history.c b/res/res_pjsip_history.c
index d6b3eebe9b..40d26d59dd 100644
--- a/res/res_pjsip_history.c
+++ b/res/res_pjsip_history.c
@@ -1403,4 +1403,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP History",
 		.load = load_module,
 		.unload = unload_module,
 		.load_pri = AST_MODPRI_APP_DEPEND,
+		.requires = "res_pjsip",
 	);
diff --git a/res/res_pjsip_logger.c b/res/res_pjsip_logger.c
index d29a6e2136..460b6a34fe 100644
--- a/res/res_pjsip_logger.c
+++ b/res/res_pjsip_logger.c
@@ -262,4 +262,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Packet Logger",
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index b6e7a64c36..3739bcf933 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -850,4 +849,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Messaging Suppo
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index 5423038e6e..92dc7dc65c 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -1397,4 +1397,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP MWI resource",
 	.unload = unload_module,
 	.reload = reload,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND + 5,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_mwi_body_generator.c b/res/res_pjsip_mwi_body_generator.c
index e8279101c8..65ac600673 100644
--- a/res/res_pjsip_mwi_body_generator.c
+++ b/res/res_pjsip_mwi_body_generator.c
@@ -116,4 +116,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP MWI resource",
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c
index e1d56e6af8..4231a1ec35 100644
--- a/res/res_pjsip_nat.c
+++ b/res/res_pjsip_nat.c
@@ -378,4 +378,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP NAT Support",
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c
index 59b7c6ea45..9767c56b5c 100644
--- a/res/res_pjsip_notify.c
+++ b/res/res_pjsip_notify.c
@@ -1032,4 +1032,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "CLI/AMI PJSIP NOTIFY
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_one_touch_record_info.c b/res/res_pjsip_one_touch_record_info.c
index ec5f9be3e7..ef59fca138 100644
--- a/res/res_pjsip_one_touch_record_info.c
+++ b/res/res_pjsip_one_touch_record_info.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	 <depend>pjproject</depend>
 	 <depend>res_pjsip</depend>
-	 <depend>res_pjsip_session</depend>
 	 <support_level>core</support_level>
 ***/
 
@@ -129,4 +128,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP INFO One Touch
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_outbound_authenticator_digest.c b/res/res_pjsip_outbound_authenticator_digest.c
index 7e2d711292..54bba08de2 100644
--- a/res/res_pjsip_outbound_authenticator_digest.c
+++ b/res/res_pjsip_outbound_authenticator_digest.c
@@ -224,4 +224,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP authentication
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c
index e5f12951fb..b4e3320f46 100644
--- a/res/res_pjsip_outbound_publish.c
+++ b/res/res_pjsip_outbound_publish.c
@@ -1702,4 +1702,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjproject,res_pjsip",
 );
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index d9afcd284b..79bea482bd 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -2289,4 +2289,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Outbound Regist
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_path.c b/res/res_pjsip_path.c
index e170a750d8..b245f159d2 100644
--- a/res/res_pjsip_path.c
+++ b/res/res_pjsip_path.c
@@ -264,4 +264,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Path Header Sup
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_phoneprov_provider.c b/res/res_pjsip_phoneprov_provider.c
index 7e082c4b55..11031c3c18 100644
--- a/res/res_pjsip_phoneprov_provider.c
+++ b/res/res_pjsip_phoneprov_provider.c
@@ -418,4 +418,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Phoneprov Provi
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip,res_phoneprov",
 );
diff --git a/res/res_pjsip_pidf_body_generator.c b/res/res_pjsip_pidf_body_generator.c
index 29c9e6be2f..6426dfa9dc 100644
--- a/res/res_pjsip_pidf_body_generator.c
+++ b/res/res_pjsip_pidf_body_generator.c
@@ -135,4 +135,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_pidf_digium_body_supplement.c b/res/res_pjsip_pidf_digium_body_supplement.c
index 93e4982e28..f855e2153f 100644
--- a/res/res_pjsip_pidf_digium_body_supplement.c
+++ b/res/res_pjsip_pidf_digium_body_supplement.c
@@ -114,4 +114,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Digium pre
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_pidf_eyebeam_body_supplement.c b/res/res_pjsip_pidf_eyebeam_body_supplement.c
index 40470840c0..6629aa3c1c 100644
--- a/res/res_pjsip_pidf_eyebeam_body_supplement.c
+++ b/res/res_pjsip_pidf_eyebeam_body_supplement.c
@@ -111,4 +111,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Eyebeam su
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_publish_asterisk.c b/res/res_pjsip_publish_asterisk.c
index 53ee60fe4a..13d7fd43bd 100644
--- a/res/res_pjsip_publish_asterisk.c
+++ b/res/res_pjsip_publish_asterisk.c
@@ -934,4 +934,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Asterisk Event
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND + 5,
+	.requires = "res_pjsip,res_pjsip_outbound_publish,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 1f24de050b..af696b849a 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -5518,4 +5518,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index 62f8b67de3..3100993def 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -1229,4 +1229,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Blind and Atten
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip,res_pjsip_session,res_pjsip_pubsub",
 );
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index f0da6dee2f..7277a5f4fc 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -1134,4 +1134,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Registrar Suppo
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 3,
+	.requires = "res_pjproject,res_pjsip",
 );
diff --git a/res/res_pjsip_registrar_expire.c b/res/res_pjsip_registrar_expire.c
index fe4a60da87..85e3fb859a 100644
--- a/res/res_pjsip_registrar_expire.c
+++ b/res/res_pjsip_registrar_expire.c
@@ -150,4 +150,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Contact Auto-Ex
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_rfc3326.c b/res/res_pjsip_rfc3326.c
index d49a170d33..8b8035efc0 100644
--- a/res/res_pjsip_rfc3326.c
+++ b/res/res_pjsip_rfc3326.c
@@ -19,7 +19,6 @@
 /*** MODULEINFO
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
-	<depend>res_pjsip_session</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -156,4 +155,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP RFC3326 Support
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 9e04119032..3cc97644a0 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -1970,4 +1970,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP SDP RTP/AVP str
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
+	.requires = "res_pjsip,res_pjsip_session",
 );
diff --git a/res/res_pjsip_send_to_voicemail.c b/res/res_pjsip_send_to_voicemail.c
index 1cd28ceac8..06c3edc034 100644
--- a/res/res_pjsip_send_to_voicemail.c
+++ b/res/res_pjsip_send_to_voicemail.c
@@ -236,4 +236,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP REFER Send to V
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip,res_pjsip_session",
 );
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 53f60cc3bc..8247fbaaa4 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -4202,4 +4202,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_sips_contact.c b/res/res_pjsip_sips_contact.c
index 7579be6f3d..41b26df7dc 100644
--- a/res/res_pjsip_sips_contact.c
+++ b/res/res_pjsip_sips_contact.c
@@ -104,4 +104,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "UAC SIPS Contact supp
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c
index 8f1905f6e2..7b7cd9910a 100644
--- a/res/res_pjsip_t38.c
+++ b/res/res_pjsip_t38.c
@@ -1053,4 +1053,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP T.38 UDPTL Supp
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DRIVER,
+	.requires = "res_pjsip,res_pjsip_session",
 );
diff --git a/res/res_pjsip_transport_management.c b/res/res_pjsip_transport_management.c
index eb92eb7a51..acffb86dca 100644
--- a/res/res_pjsip_transport_management.c
+++ b/res/res_pjsip_transport_management.c
@@ -397,4 +397,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Reliable Transp
 	.reload = reload_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND - 4,
+	.requires = "res_pjsip",
 );
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index 3ce90390cc..af1345f351 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -518,4 +518,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP WebSocket Trans
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_APP_DEPEND,
+	.requires = "res_pjsip,res_http_websocket",
 );
diff --git a/res/res_pjsip_xpidf_body_generator.c b/res/res_pjsip_xpidf_body_generator.c
index 41f6224d1a..f7c84db3dc 100644
--- a/res/res_pjsip_xpidf_body_generator.c
+++ b/res/res_pjsip_xpidf_body_generator.c
@@ -20,7 +20,6 @@
 	<depend>pjproject</depend>
 	<depend>res_pjsip</depend>
 	<depend>res_pjsip_pubsub</depend>
-	<depend>res_pjsip_exten_state</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -177,4 +176,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Extension State
 	.load = load_module,
 	.unload = unload_module,
 	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	.requires = "res_pjsip,res_pjsip_pubsub",
 );
diff --git a/res/res_stasis_answer.c b/res/res_stasis_answer.c
index 407a631354..6ec50c81bb 100644
--- a/res/res_stasis_answer.c
+++ b/res/res_stasis_answer.c
@@ -73,5 +73,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis applicatio
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis"
+	.requires = "res_stasis",
 );
diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c
index 6527af4a61..be09b15ad0 100644
--- a/res/res_stasis_device_state.c
+++ b/res/res_stasis_device_state.c
@@ -482,5 +482,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis applicatio
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis"
+	.requires = "res_stasis",
 );
diff --git a/res/res_stasis_mailbox.c b/res/res_stasis_mailbox.c
index 5ed061de2e..3d0e9db691 100644
--- a/res/res_stasis_mailbox.c
+++ b/res/res_stasis_mailbox.c
@@ -161,5 +161,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis applicatio
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis,res_mwi_external"
+	.requires = "res_stasis,res_mwi_external"
 );
diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index ca0446b89e..5b8256fc48 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -759,5 +759,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis applicatio
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis,res_stasis_recording"
+	.requires = "res_stasis,res_stasis_recording"
 );
diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c
index 56984cb401..17213aa245 100644
--- a/res/res_stasis_recording.c
+++ b/res/res_stasis_recording.c
@@ -655,6 +655,6 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis",
+	.requires = "res_stasis",
 	.load_pri = AST_MODPRI_APP_DEPEND
 );
diff --git a/res/res_stasis_snoop.c b/res/res_stasis_snoop.c
index f797a9b942..b234de1118 100644
--- a/res/res_stasis_snoop.c
+++ b/res/res_stasis_snoop.c
@@ -445,5 +445,5 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis applicatio
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis"
+	.requires = "res_stasis",
 );
diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache
index d4ccda9e8e..c1f680f21d 100644
--- a/rest-api-templates/res_ari_resource.c.mustache
+++ b/rest-api-templates/res_ari_resource.c.mustache
@@ -324,6 +324,6 @@ AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - {{{
 	.support_level = AST_MODULE_SUPPORT_CORE,
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari,res_stasis",
+	.requires = "res_ari,res_ari_model,res_stasis",
 );
 {{/api_declaration}}
diff --git a/tests/test_ari.c b/tests/test_ari.c
index bce5f95d64..a5db2284f2 100644
--- a/tests/test_ari.c
+++ b/tests/test_ari.c
@@ -573,5 +573,5 @@ static int load_module(void)
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ARI testing",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_ari",
+	.requires = "res_ari",
 );
diff --git a/tests/test_ari_model.c b/tests/test_ari_model.c
index caf4118789..e5a96cdd1b 100644
--- a/tests/test_ari_model.c
+++ b/tests/test_ari_model.c
@@ -452,4 +452,9 @@ static int load_module(void)
 	return AST_MODULE_LOAD_SUCCESS;
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Test");
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Skeleton (sample) Test",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.requires = "res_ari_model",
+);
diff --git a/tests/test_res_pjsip_scheduler.c b/tests/test_res_pjsip_scheduler.c
index da51d43be2..47a7034ffb 100644
--- a/tests/test_res_pjsip_scheduler.c
+++ b/tests/test_res_pjsip_scheduler.c
@@ -396,4 +396,9 @@ static int unload_module(void)
 	return 0;
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "res_pjsip scheduler test module");
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "res_pjsip scheduler test module",
+	.support_level = AST_MODULE_SUPPORT_CORE,
+	.load = load_module,
+	.unload = unload_module,
+	.requires = "res_pjsip",
+);
diff --git a/tests/test_res_stasis.c b/tests/test_res_stasis.c
index cb79fa6fea..077cc4c7a6 100644
--- a/tests/test_res_stasis.c
+++ b/tests/test_res_stasis.c
@@ -195,5 +195,5 @@ static int load_module(void)
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis Core testing",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis",
+	.requires = "res_stasis",
 );
diff --git a/tests/test_stasis_endpoints.c b/tests/test_stasis_endpoints.c
index 134738fee5..42c7532ebb 100644
--- a/tests/test_stasis_endpoints.c
+++ b/tests/test_stasis_endpoints.c
@@ -306,5 +306,5 @@ static int load_module(void)
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Endpoint stasis-related testing",
 	.load = load_module,
 	.unload = unload_module,
-	.nonoptreq = "res_stasis_test",
+	.requires = "res_stasis_test",
 );
-- 
GitLab