[asterisk-commits] mmichelson: branch mmichelson/res_sip r378708 - /team/mmichelson/res_sip/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 09:13:42 CST 2013


Author: mmichelson
Date: Wed Jan  9 09:13:38 2013
New Revision: 378708

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378708
Log:
Use ao2 global obj for registered authenticator.


Modified:
    team/mmichelson/res_sip/res/res_sip.c

Modified: team/mmichelson/res_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/res_sip/res/res_sip.c?view=diff&rev=378708&r1=378707&r2=378708
==============================================================================
--- team/mmichelson/res_sip/res/res_sip.c (original)
+++ team/mmichelson/res_sip/res/res_sip.c Wed Jan  9 09:13:38 2013
@@ -45,60 +45,64 @@
 	pjsip_endpt_unregister_module(ast_pjsip_endpoint, module);
 }
 
-static struct ast_sip_authenticator *registered_authenticator;
+AO2_GLOBAL_OBJ_STATIC(registered_authenticator);
 
 int ast_sip_register_authenticator(struct ast_sip_authenticator *auth)
 {
-	if (registered_authenticator) {
-		ast_log(LOG_WARNING, "Authenticator %p is already registered. Cannot register a new one\n",
-				registered_authenticator);
+	RAII_VAR(struct ast_sip_authenticator *, reg, ao2_global_obj_ref(registered_authenticator), ao2_cleanup);
+	if (reg) {
+		ast_log(LOG_WARNING, "Authenticator %p is already registered. Cannot register a new one\n", reg);
 		return -1;
 	}
-	registered_authenticator = auth;
+	ao2_global_obj_replace_unref(registered_authenticator, auth);
 	ast_debug(1, "Registered SIP authenticator module %p\n", auth);
 	return 0;
 }
 
 void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth)
 {
-	if (auth != registered_authenticator) {
+	RAII_VAR(struct ast_sip_authenticator *, reg, ao2_global_obj_ref(registered_authenticator), ao2_cleanup);
+	if (auth != reg) {
 		ast_log(LOG_WARNING, "Trying to unregister authenticator %p but authenticator %p registered\n",
-				auth, registered_authenticator);
+				auth, reg);
 		return;
 	}
-	registered_authenticator = NULL;
+	ao2_global_obj_release(registered_authenticator);
 	ast_debug(1, "Unregistered SIP authenticator %p\n", auth);
 }
 
 int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata)
 {
-	if (!registered_authenticator) {
+	RAII_VAR(struct ast_sip_authenticator *, reg, ao2_global_obj_ref(registered_authenticator), ao2_cleanup);
+	if (!reg) {
 		ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming authentication is not required\n");
 		return 0;
 	}
 
-	return registered_authenticator->requires_authentication(endpoint, rdata);
+	return reg->requires_authentication(endpoint, rdata);
 }
 
 int ast_sip_authenticate_request(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata)
 {
-	if (!registered_authenticator) {
+	RAII_VAR(struct ast_sip_authenticator *, reg, ao2_global_obj_ref(registered_authenticator), ao2_cleanup);
+	if (!reg) {
 		ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming request authenticated properly\n");
 		return 0;
 	}
 
-	return registered_authenticator->authenticate_request(endpoint, rdata);
+	return reg->authenticate_request(endpoint, rdata);
 }
 
 int ast_sip_get_authentication_credentials(struct ast_sip_endpoint *endpoint,
 		struct sip_digest_challenge_data *challenge)
 {
-	if (!registered_authenticator) {
+	RAII_VAR(struct ast_sip_authenticator *, reg, ao2_global_obj_ref(registered_authenticator), ao2_cleanup);
+	if (!reg) {
 		ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming no authentication credentials\n");
 		return -1;
 	}
 
-	return registered_authenticator->authenticate_request(endpoint, rdata);
+	return reg->authenticate_request(endpoint, rdata);
 }
 
 struct endpoint_identifier_list {




More information about the asterisk-commits mailing list