[asterisk-commits] mmichelson: branch mmichelson/pubsub_bodies r405858 - /team/mmichelson/pubsub...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 17 14:11:25 CST 2014


Author: mmichelson
Date: Fri Jan 17 14:11:18 2014
New Revision: 405858

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=405858
Log:
Add some error checking to places that use body generators.


Modified:
    team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
    team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c

Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c?view=diff&rev=405858&r1=405857&r2=405858
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_mwi.c Fri Jan 17 14:11:18 2014
@@ -409,7 +409,12 @@
 		pj_cstr(&reason_str, reason);
 		reason_str_ptr = &reason_str;
 	}
-	ast_sip_pubsub_generate_body_content(MWI_TYPE, MWI_SUBTYPE, &body, &counter);
+
+	if (ast_sip_pubsub_generate_body_content(MWI_TYPE, MWI_SUBTYPE, &body, &counter)) {
+		ast_log(LOG_WARNING, "Unable to generate SIP MWI NOTIFY body.\n");
+		return;
+	}
+
 	pj_cstr(&pj_body, ast_str_buffer(body));
 
 	ast_debug(5, "Sending  %s MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",

Modified: team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c?view=diff&rev=405858&r1=405857&r2=405858
==============================================================================
--- team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c (original)
+++ team/mmichelson/pubsub_bodies/res/res_pjsip_pidf.c Fri Jan 17 14:11:18 2014
@@ -293,7 +293,11 @@
 		goto end;
 	}
 
-	ast_sip_pubsub_generate_body_content("application", "pidf+xml", pres, &gen_data);
+	if (ast_sip_pubsub_generate_body_content("application", "pidf+xml", pres, &gen_data)) {
+		ast_log(LOG_WARNING, "Failed to generate PIDF NOTIFY body\n");
+		res = -1;
+		goto end;
+	}
 
 	if (!(size = pjpidf_print(pres, ast_str_buffer(*body_text),
 				  ast_str_size(*body_text)))) {
@@ -379,18 +383,20 @@
 	}
 
 	if (!(pres = pjxpidf_create(gen_data.pool, pj_cstr(&name, local)))) {
-		exten_state_body_generator_data_release(&gen_data);
 		ast_log(LOG_WARNING, "Unable to create XPIDF presence\n");
 		res = -1;
 		goto end;
 	}
 
-	ast_sip_pubsub_generate_body_content("application", "xpidf+xml", pres, &gen_data);
+	if (ast_sip_pubsub_generate_body_content("application", "xpidf+xml", pres, &gen_data)) {
+		ast_log(LOG_WARNING, "Unable to generate XPIDF NOTIFY body\n");
+		res = -1;
+		goto end;
+	}
 
 	if (!(size = pjxpidf_print(pres, ast_str_buffer(*body_text),
 				  ast_str_size(*body_text)))) {
 		ast_log(LOG_WARNING, "XPIDF body text too large\n");
-		exten_state_body_generator_data_release(&gen_data);
 		res = -1;
 		goto end;
 	}
@@ -433,35 +439,58 @@
 	.generate_body_content = xpidf_generate_body_content,
 };
 
+static void unregister_all(void)
+{
+	ast_sip_unregister_exten_state_provider(&cpim_pidf_xml_provider);
+	ast_sip_pubsub_unregister_body_generator(&cpim_pidf_body_generator);
+	ast_sip_unregister_exten_state_provider(&xpidf_xml_provider);
+	ast_sip_pubsub_unregister_body_generator(&xpidf_body_generator);
+	ast_sip_unregister_exten_state_provider(&pidf_xml_provider);
+	ast_sip_pubsub_unregister_body_generator(&pidf_body_generator);
+}
+
 static int load_module(void)
 {
 	if (ast_sip_register_exten_state_provider(&pidf_xml_provider)) {
 		ast_log(LOG_WARNING, "Unable to load provider event_name=%s, body_type=%s",
 			pidf_xml_provider.event_name, pidf_xml_provider.body_type);
-	}
-	ast_sip_pubsub_register_body_generator(&pidf_body_generator);
+		goto fail;
+	}
+	
+	if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
+		goto fail;
+	}
 
 	if (ast_sip_register_exten_state_provider(&xpidf_xml_provider)) {
 		ast_log(LOG_WARNING, "Unable to load provider event_name=%s, body_type=%s",
 			xpidf_xml_provider.event_name, xpidf_xml_provider.body_type);
-	}
-	ast_sip_pubsub_register_body_generator(&xpidf_body_generator);
+		goto fail;
+	}
+
+	if (ast_sip_pubsub_register_body_generator(&xpidf_body_generator)) {
+		goto fail;
+	}
 
 	if (ast_sip_register_exten_state_provider(&cpim_pidf_xml_provider)) {
 		ast_log(LOG_WARNING, "Unable to load provider event_name=%s, body_type=%s",
 			cpim_pidf_xml_provider.event_name, cpim_pidf_xml_provider.body_type);
-	}
-	ast_sip_pubsub_register_body_generator(&cpim_pidf_body_generator);
+		goto fail;
+	}
+
+	if (ast_sip_pubsub_register_body_generator(&cpim_pidf_body_generator)) {
+		goto fail;
+	}
 
 	return AST_MODULE_LOAD_SUCCESS;
+
+fail:
+	unregister_all();
+	return AST_MODULE_LOAD_DECLINE;
 }
 
 static int unload_module(void)
 {
-	ast_sip_unregister_exten_state_provider(&cpim_pidf_xml_provider);
-	ast_sip_unregister_exten_state_provider(&xpidf_xml_provider);
-	ast_sip_unregister_exten_state_provider(&pidf_xml_provider);
-
+	unregister_all();
 	return 0;
 }
 




More information about the asterisk-commits mailing list