[asterisk-commits] dvossel: branch dvossel/gtalk_fixup r291826 - /team/dvossel/gtalk_fixup/chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 14 15:42:30 CDT 2010


Author: dvossel
Date: Thu Oct 14 15:42:26 2010
New Revision: 291826

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=291826
Log:
More code cleanup.  Making xml parsing safer

Modified:
    team/dvossel/gtalk_fixup/channels/chan_gtalk.c

Modified: team/dvossel/gtalk_fixup/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/gtalk_fixup/channels/chan_gtalk.c?view=diff&rev=291826&r1=291825&r2=291826
==============================================================================
--- team/dvossel/gtalk_fixup/channels/chan_gtalk.c (original)
+++ team/dvossel/gtalk_fixup/channels/chan_gtalk.c Thu Oct 14 15:42:26 2010
@@ -542,8 +542,8 @@
 	if (response) {
 		iks_insert_attrib(response, "type", "result");
 		iks_insert_attrib(response, "from", from);
-		iks_insert_attrib(response, "to", iks_find_attrib(pak->x, "from"));
-		iks_insert_attrib(response, "id", iks_find_attrib(pak->x, "id"));
+		iks_insert_attrib(response, "to", S_OR(iks_find_attrib(pak->x, "from"), ""));
+		iks_insert_attrib(response, "id", S_OR(iks_find_attrib(pak->x, "id"), ""));
 		if (reasonstr) {
 			error = iks_new("error");
 			if (error) {
@@ -592,8 +592,24 @@
 	/* codec points to the first <payload-type/> tag */
 	codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
 	while (codec) {
-		ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp, atoi(iks_find_attrib(codec, "id")));
-		ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp, atoi(iks_find_attrib(codec, "id")), "audio", iks_find_attrib(codec, "name"), 0);
+		char *codec_id = iks_find_attrib(codec, "id");
+		char *codec_name = iks_find_attrib(codec, "name");
+		if (!codec_id || !codec_name) {
+			codec = iks_next_tag(codec);
+			continue;
+		}
+
+		ast_rtp_codecs_payloads_set_m_type(
+			ast_rtp_instance_get_codecs(tmp->rtp),
+			tmp->rtp,
+			atoi(codec_id));
+		ast_rtp_codecs_payloads_set_rtpmap_type(
+			ast_rtp_instance_get_codecs(tmp->rtp),
+			tmp->rtp,
+			atoi(codec_id),
+			"audio",
+			codec_name,
+			0);
 		codec = iks_next_tag(codec);
 	}
 
@@ -1252,12 +1268,30 @@
 			codec = iks_next_tag(codec);
 			continue;
 		}
-		if (!strcmp(iks_name(codec), "vid:payload-type") && p->vrtp) {
-			ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->vrtp), p->vrtp, atoi(codec_id));
-			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->vrtp), p->vrtp, atoi(codec_id), "video", codec_name, 0);
+		if (!strcmp(S_OR(iks_name(codec), ""), "vid:payload-type") && p->vrtp) {
+			ast_rtp_codecs_payloads_set_m_type(
+				ast_rtp_instance_get_codecs(p->vrtp),
+				p->vrtp,
+				atoi(codec_id));
+			ast_rtp_codecs_payloads_set_rtpmap_type(
+				ast_rtp_instance_get_codecs(p->vrtp),
+				p->vrtp,
+				atoi(codec_id),
+				"video",
+				codec_name,
+				0);
 		} else {
-			ast_rtp_codecs_payloads_set_m_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(codec_id));
-			ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, atoi(codec_id), "audio", codec_name, 0);
+			ast_rtp_codecs_payloads_set_m_type(
+				ast_rtp_instance_get_codecs(p->rtp),
+				p->rtp,
+				atoi(codec_id));
+			ast_rtp_codecs_payloads_set_rtpmap_type(
+				ast_rtp_instance_get_codecs(p->rtp),
+				p->rtp,
+				atoi(codec_id),
+				"audio",
+				codec_name,
+				0);
 		}
 		codec = iks_next_tag(codec);
 	}
@@ -1418,15 +1452,15 @@
 	}
 	traversenodes = pak->query;
 	while(traversenodes) {
-		if(!strcasecmp(iks_name(traversenodes), "session")) {
+		if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "session")) {
 			traversenodes = iks_first_tag(traversenodes);
 			continue;
 		}
-		if(!strcasecmp(iks_name(traversenodes), "ses:session")) {
+		if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "ses:session")) {
 			traversenodes = iks_child(traversenodes);
 			continue;
 		}
-		if(!strcasecmp(iks_name(traversenodes), "candidate") || !strcasecmp(iks_name(traversenodes), "ses:candidate")) {
+		if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "candidate") || !strcasecmp(S_OR(iks_name(traversenodes), ""), "ses:candidate")) {
 			newcandidate = ast_calloc(1, sizeof(*newcandidate));
 			if (!newcandidate)
 				return 0;
@@ -1596,7 +1630,7 @@
 		ast_moh_stop(ast);
 		break;
 	default:
-		ast_log(LOG_NOTICE, "Don't know how to indicate condition '%d'\n", condition);
+		ast_debug(3, "Don't know how to indicate condition '%d'\n", condition);
 		res = -1;
 	}
 
@@ -1720,24 +1754,6 @@
 	return -1;
 }
 
-/* Not in use right now.
-static int gtalk_auto_congest(void *nothing)
-{
-	struct gtalk_pvt *p = nothing;
-
-	ast_mutex_lock(&p->lock);
-	if (p->owner) {
-		if (!ast_channel_trylock(p->owner)) {
-			ast_log(LOG_NOTICE, "Auto-congesting %s\n", p->owner->name);
-			ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
-			ast_channel_unlock(p->owner);
-		}
-	}
-	ast_mutex_unlock(&p->lock);
-	return 0;
-}
-*/
-
 /*!\brief Initiate new call, part of PBX interface
  * dest is the dial string */
 static int gtalk_call(struct ast_channel *ast, char *dest, int timeout)
@@ -1754,8 +1770,9 @@
 		ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
 		p->ringrule = iks_filter_add_rule(p->parent->connection->f, gtalk_ringing_ack, p,
 							IKS_RULE_ID, p->ring, IKS_RULE_DONE);
-	} else
+	} else {
 		ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
+	}
 
 	gtalk_invite(p, p->them, p->us, p->sid, 1);
 	gtalk_create_candidates(p->parent, p, p->sid, p->them, p->us);
@@ -1796,8 +1813,9 @@
 		s = ast_strdupa(data);
 		if (s) {
 			sender = strsep(&s, "/");
-			if (sender && (sender[0] != '\0'))
+			if (sender && (sender[0] != '\0')) {
 				to = strsep(&s, "/");
+			}
 			if (!to) {
 				ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", (char*) data);
 				return NULL;
@@ -2220,4 +2238,4 @@
 		.unload = unload_module,
 		/* .reload = reload, */
 		.load_pri = AST_MODPRI_CHANNEL_DRIVER,
-	       );
+		);




More information about the asterisk-commits mailing list