[svn-commits] file: branch group/pimp_my_sip r380846 - in /team/group/pimp_my_sip/res: ./ r...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 5 11:21:19 CST 2013


Author: file
Date: Tue Feb  5 11:21:14 2013
New Revision: 380846

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380846
Log:
Add initial module refcounting and fix a crash when executing "core stop now".

If a module is loaded which uses either res_sip or res_sip_session the reference count of
either module will be increased to prevent unloading.

This also fixes a crash issue with the OPTIONS support. If res_sip were unloaded and then
"core stop now" executed an atexit function was still attempting to be called by the core
when it should not have been. The OPTIONS support now uses the SIP module start() and stop()
callbacks to set up and tear down resources.

Modified:
    team/group/pimp_my_sip/res/res_sip.c
    team/group/pimp_my_sip/res/res_sip/sip_options.c
    team/group/pimp_my_sip/res/res_sip_session.c

Modified: team/group/pimp_my_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip.c?view=diff&rev=380846&r1=380845&r2=380846
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Tue Feb  5 11:21:14 2013
@@ -57,11 +57,13 @@
 		return -1;
 	}
 	ast_debug(1, "Registered SIP service %.*s\n", (int) pj_strlen(&module->name), pj_strbuf(&module->name));
+	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
 void ast_sip_unregister_service(pjsip_module *module)
 {
+	ast_module_unref(ast_module_info->self);
 	if (!ast_pjsip_endpoint) {
 		return;
 	}
@@ -80,6 +82,7 @@
 	}
 	ao2_global_obj_replace_unref(registered_authenticator, auth);
 	ast_debug(1, "Registered SIP authenticator module %p\n", auth);
+	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
@@ -93,6 +96,7 @@
 	}
 	ao2_global_obj_release(registered_authenticator);
 	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)
@@ -181,6 +185,8 @@
 
 	AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
 	ast_debug(1, "Registered endpoint identifier %p\n", identifier);
+
+	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
@@ -193,6 +199,7 @@
 			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;
 		}
 	}
@@ -541,7 +548,7 @@
 		goto error;
 	}
 
-	if (ast_sip_register_service(&unhandled_module)) {
+	if (pjsip_endpt_register_module(ast_pjsip_endpoint, &unhandled_module)) {
 		ast_log(LOG_ERROR, "Failed to register unhandled request module. Aborting load\n");
 		goto error;
 	}

Modified: team/group/pimp_my_sip/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip/sip_options.c?view=diff&rev=380846&r1=380845&r2=380846
==============================================================================
--- team/group/pimp_my_sip/res/res_sip/sip_options.c (original)
+++ team/group/pimp_my_sip/res/res_sip/sip_options.c Tue Feb  5 11:21:14 2013
@@ -36,6 +36,8 @@
 	int scheduler_id;
 };
 
+static pj_bool_t options_module_start(void);
+static pj_bool_t options_module_stop(void);
 static pj_bool_t options_module_on_rx_request(pjsip_rx_data *rdata);
 static pj_bool_t options_module_on_rx_response(pjsip_rx_data *rdata);
 
@@ -43,9 +45,32 @@
 	.name = {"Options Module", 14},
 	.id = -1,
 	.priority = PJSIP_MOD_PRIORITY_APPLICATION,
+	.start = options_module_start,
+	.stop = options_module_stop,
 	.on_rx_request = options_module_on_rx_request,
 	.on_rx_response = options_module_on_rx_response,
 };
+
+static pj_bool_t options_module_start(void)
+{
+	if (!(sched = ast_sched_context_create()) ||
+	    ast_sched_start_thread(sched)) {
+		return -1;
+	}
+
+	return PJ_SUCCESS;
+}
+
+static pj_bool_t options_module_stop(void)
+{
+	ao2_t_ref(scheduled_qualifies, -1, "Remove scheduled qualifies on module stop");
+
+	if (sched) {
+		ast_sched_context_destroy(sched);
+	}
+
+	return PJ_SUCCESS;
+}
 
 static pj_status_t send_options_response(pjsip_rx_data *rdata, int code)
 {
@@ -278,17 +303,10 @@
 	ao2_iterator_destroy(&it_endpoints);
 }
 
-static void options_cleanup(void)
-{
-	ao2_t_ref(scheduled_qualifies, -1, "Remove scheduled qualifies on exit");
-	ast_sip_unregister_service(&options_module);
-	if (sched) {
-		ast_sched_context_destroy(sched);
-	}
-}
-
 int ast_res_sip_init_options_handling(int reload)
 {
+	const pj_str_t STR_OPTIONS = { "OPTIONS", 7 };
+
 	if (scheduled_qualifies) {
 		ao2_t_ref(scheduled_qualifies, -1, "Remove old scheduled qualifies");
 	}
@@ -297,37 +315,21 @@
 		return -1;
 	}
 
-	if (!reload) {
-		const pj_str_t STR_OPTIONS = { "OPTIONS", 7 };
-
-		if (ast_sip_register_service(&options_module)) {
-			ao2_t_ref(scheduled_qualifies, -1, "Remove scheduled qualifies on off nominal path");
-			return -1;
-		}
-
-		if (pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_ALLOW, NULL, 1, &STR_OPTIONS) != PJ_SUCCESS) {
-			ao2_t_ref(scheduled_qualifies, -1, "Remove scheduled qualifies on off nominal path");
-			ast_sip_unregister_service(&options_module);
-			return -1;
-		}
-
-		sched = ast_sched_context_create();
-		if (!sched) {
-			ao2_t_ref(scheduled_qualifies, -1, "Remove scheduled qualifies on off nominal path");
-			ast_sip_unregister_service(&options_module);
-			return -1;
-		}
-
-		if (ast_sched_start_thread(sched)) {
-			ao2_t_ref(scheduled_qualifies, -1, "Remove scheduled qualifies on off nominal path");
-			ast_sip_unregister_service(&options_module);
-			ast_sched_context_destroy(sched);
-			return -1;
-		}
-
-		schedule_qualifies();
-	}
-
-	ast_register_atexit(options_cleanup);
+	if (reload) {
+		return 0;
+	}
+
+	if (pjsip_endpt_register_module(ast_sip_get_pjsip_endpoint(), &options_module) != PJ_SUCCESS) {
+		options_module_stop();
+		return -1;
+	}
+
+	if (pjsip_endpt_add_capability(ast_sip_get_pjsip_endpoint(), NULL, PJSIP_H_ALLOW, NULL, 1, &STR_OPTIONS) != PJ_SUCCESS) {
+		pjsip_endpt_unregister_module(ast_sip_get_pjsip_endpoint(), &options_module);
+		return -1;
+	}
+
+	schedule_qualifies();
+
 	return 0;
 }

Modified: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=diff&rev=380846&r1=380845&r2=380846
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Tue Feb  5 11:21:14 2013
@@ -104,6 +104,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;
 	}
 
@@ -120,6 +121,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;
 }
 
@@ -134,6 +136,7 @@
 		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;
@@ -191,6 +194,7 @@
 {
 	SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
 	AST_RWLIST_INSERT_TAIL(&session_supplements, supplement, next);
+	ast_module_ref(ast_module_info->self);
 	return 0;
 }
 
@@ -201,6 +205,7 @@
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) {
 		if (supplement == iter) {
 			AST_RWLIST_REMOVE_CURRENT(next);
+			ast_module_unref(ast_module_info->self);
 			break;
 		}
 	}




More information about the svn-commits mailing list