[asterisk-commits] rizzo: branch rizzo/astobj2 r57977 - /team/rizzo/astobj2/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 6 01:21:54 MST 2007


Author: rizzo
Date: Tue Mar  6 02:21:53 2007
New Revision: 57977

URL: http://svn.digium.com/view/asterisk?view=rev&rev=57977
Log:
merge from trunk svn 54838, also fixing some previous errors.
Now we have up to svn54372 plus 54838



Modified:
    team/rizzo/astobj2/channels/chan_sip.c

Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=57977&r1=57976&r2=57977
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Tue Mar  6 02:21:53 2007
@@ -1689,7 +1689,7 @@
 static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active);
 static enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
 static enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-tatic enum ast_rtp_get_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
+static enum ast_rtp_get_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
 static int sip_get_codec(struct ast_channel *chan);
 static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p, int *faxdetect);
 
@@ -4854,11 +4854,11 @@
 		/* If the global videosupport flag is on, we always create a RTP interface for video */
 		if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT))
 			p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
-		f (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT))
+		if (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT))
 			p->trtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
 		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
 			p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
-		f (!p->rtp|| (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)
+		if (!p->rtp|| (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)
 			|| (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) && !p->trtp)) {
 			ast_log(LOG_WARNING, "Unable to create RTP audio %s%ssession: %s\n",
 				ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video " : "",
@@ -6696,55 +6696,56 @@
 
 	if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size))
 		*min_packet_size = fmt.cur_ms;
-
-/*! \brief Add video codec offer to SDP offer/answer body in INVITE or 200 OK */
-  	 /* This is different to the audio one now so we can add more caps later */
-  	 static void add_vcodec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
-  	                              char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
-  	                              int debug, int *min_packet_size)
-  	 {
-  	         int rtp_code;
-  	 
-  	         if (!p->vrtp)
-  	                 return;
-  	 
-  	         if (debug)
-  	                 ast_verbose("Adding video codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
-  	 
-  	         if ((rtp_code = ast_rtp_lookup_code(p->vrtp, 1, codec)) == -1)
-  	                 return;
-  	 
-  	         ast_build_string(m_buf, m_size, " %d", rtp_code);
-  	         ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
-  	                          ast_rtp_lookup_mime_subtype(1, codec, 0), sample_rate);
-  	         /* Add fmtp code here */
-  	 }
-  	 
-  	 /*! \brief Add text codec offer to SDP offer/answer body in INVITE or 200 OK */
-  	 static void add_tcodec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
-  	                              char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
-  	                              int debug, int *min_packet_size)
-  	 {
- int rtp_code;
-  	 
-  	         if (!p->trtp)
-  	                 return;
-  	 
-  	         if (debug)
-  	                 ast_verbose("Adding text codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
-  	 
-  	         if ((rtp_code = ast_rtp_lookup_code(p->trtp, 1, codec)) == -1)
-  	                 return;
-  	 
-  	         ast_build_string(m_buf, m_size, " %d", rtp_code);
-  	         ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
-  	                          ast_rtp_lookup_mime_subtype(1, codec, 0), sample_rate);
-  	         /* Add fmtp code here */
-  	 }
 	/* Our first codec packetization processed cannot be zero */
 	if ((*min_packet_size)==0 && fmt.cur_ms)
 		*min_packet_size = fmt.cur_ms;
 }
+
+/*! \brief Add video codec offer to SDP offer/answer body in INVITE or 200 OK */
+ /* This is different to the audio one now so we can add more caps later */
+static void add_vcodec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
+	struct ast_str **m_buf, struct ast_str **a_buf,
+	int debug, int *min_packet_size)
+{
+	int rtp_code;
+
+	if (!p->vrtp)
+		return;
+
+	if (debug)
+		ast_verbose("Adding video codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
+
+	if ((rtp_code = ast_rtp_lookup_code(p->vrtp, 1, codec)) == -1)
+		return;
+
+	ast_str_append(m_buf, 0, " %d", rtp_code);
+	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
+		ast_rtp_lookup_mime_subtype(1, codec, 0), sample_rate);
+	/* Add fmtp code here */
+}
+  	 
+/*! \brief Add text codec offer to SDP offer/answer body in INVITE or 200 OK */
+static void add_tcodec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
+	struct ast_str **m_buf, struct ast_str **a_buf,
+	int debug, int *min_packet_size)
+{
+	int rtp_code;
+
+	if (!p->trtp)
+		return;
+
+	if (debug)
+		ast_verbose("Adding text codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
+
+	if ((rtp_code = ast_rtp_lookup_code(p->trtp, 1, codec)) == -1)
+		return;
+
+	ast_str_append(m_buf, 0, " %d", rtp_code);
+	ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code,
+		ast_rtp_lookup_mime_subtype(1, codec, 0), sample_rate);
+	/* Add fmtp code here */
+}
+
 
 /*! \brief Get Max T.38 Transmission rate from T38 capabilities */
 static int t38_get_rate(int t38cap)
@@ -6946,15 +6947,19 @@
 	char *hold;
 	struct ast_str *m_audio = ast_str_alloca(256);	/* Media declaration line for audio */
 	struct ast_str *m_video = ast_str_alloca(256);	/* Media declaration line for video */
+	struct ast_str *m_text = ast_str_alloca(256);	/* Media declaration line for text */
 	struct ast_str *a_audio = ast_str_alloca(1024);	/* Attributes for audio */
 	struct ast_str *a_video = ast_str_alloca(1024);	/* Attributes for video */
+	struct ast_str *a_text = ast_str_alloca(1024);	/* Attributes for text */
 
 	int x;
 	int capability;
 	int needvideo = FALSE;
+	int needtext = FALSE;
 	int debug = sip_debug_test_pvt(p);
 	int min_audio_packet_size = 0;
 	int min_video_packet_size = 0;
+	int min_text_packet_size = 0;
 
 	if (!p->rtp) {
 		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
@@ -6974,7 +6979,8 @@
 
 	if (option_debug > 1) {
 		char codecbuf[BUFSIZ];
-		ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False");
+		ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s Text flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability),
+			ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False", ast_test_flag(&p->flags[1], SIP_PAGE2_NOTEXT) ? "True" : "False");
 		ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
 	}
 	
@@ -6996,7 +7002,10 @@
 	}
 
 	/* Get our media addresses */
-	get_our_media_address(p, needvideo, &sin, &vsin, &dest, &vdest);
+	get_our_media_address(p, needvideo, &sin, &vsin, &tsin, &dest, &vdest);
+
+	if (debug)
+		ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(sin.sin_port));
 		
 	/* Ok, we need video. Let's add what we need for video and set codecs.
 	   Video is handled differently than audio since we can not transcode. */
@@ -7009,9 +7018,38 @@
 		if (debug) 
 			ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(vsin.sin_port));	
 	}
-
-	if (debug) 
-		ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(sin.sin_port));	
+        /* Check if we need text in this call */
+	if((capability & AST_FORMAT_TEXT_MASK) && !ast_test_flag(&p->flags[1], SIP_PAGE2_NOTEXT)) {
+		if (sipdebug_text)
+			ast_verbose("We think we can do text\n");
+		if (p->trtp) {
+			if (sipdebug_text)
+				ast_verbose("And we have a text rtp object\n");
+			needtext = TRUE;
+			if (option_debug > 1)
+				ast_log(LOG_DEBUG, "This call needs text offers! \n");
+		} else if (option_debug > 1)
+			ast_log(LOG_DEBUG, "This call needs text offers, but there's no text support enabled ! \n");
+	}
+
+	/* Ok, we need text. Let's add what we need for text and set codecs.
+	Text is handled differently than audio since we can not transcode. */
+	if (needtext) {
+		if (sipdebug_text)
+			ast_verbose("Lets set up the text sdp\n");
+		/* Determine text destination */
+		if (p->tredirip.sin_addr.s_addr) {
+			tdest.sin_addr = p->tredirip.sin_addr;
+			tdest.sin_port = p->tredirip.sin_port;
+		} else {
+			tdest.sin_addr = p->ourip;
+			tdest.sin_port = tsin.sin_port;
+		}
+		ast_str_append(&m_text, 0, "m=text %d RTP/AVP", ntohs(tdest.sin_port));
+
+		if (debug) 
+			ast_verbose("Text is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(tsin.sin_port));
+	}
 
 	/* Start building generic SDP headers */
 
@@ -7067,7 +7105,7 @@
 	}
 
 	/* Now send any other common audio and video codecs, and non-codec formats: */
-	for (x = 1; x <= (needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) {
+	for (x = 1; x <= (needtext ? AST_FORMAT_MAX_TEXT : (needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO)); x <<= 1) {
 		if (!(capability & x))	/* Codec not requested */
 			continue;
 
@@ -7077,9 +7115,12 @@
 		if (x <= AST_FORMAT_MAX_AUDIO)
 			add_codec_to_sdp(p, x, SDP_SAMPLE_RATE(x),
 				 &m_audio,  &a_audio, debug, &min_audio_packet_size);
-		else 
-			add_codec_to_sdp(p, x, 90000,
+		else if (x <= AST_FORMAT_MAX_VIDEO)
+			add_vcodec_to_sdp(p, x, 90000,
 				&m_video, &a_video, debug, &min_video_packet_size);
+		else if (x <= AST_FORMAT_MAX_TEXT)
+			add_tcodec_to_sdp(p, x, 1000,
+				&m_text, &a_text, debug, &min_text_packet_size);
 	}
 
 	/* Now add DTMF RFC2833 telephony-event as a codec */
@@ -7098,21 +7139,31 @@
 
 	if (min_audio_packet_size)
 		ast_str_append(&a_audio, 0, "a=ptime:%d\r\n", min_audio_packet_size);
+
+	/* XXX don't think you can have ptime for video */
 	if (min_video_packet_size)
 		ast_str_append(&a_video, 0, "a=ptime:%d\r\n", min_video_packet_size);
 
+	/* XXX don't think you can have ptime for text */
+	if (min_text_packet_size)
+		ast_str_append(&a_text, 0, "a=ptime:%d\r\n", min_text_packet_size);
 	if (m_audio->len - m_audio->used < 2 || m_video->len - m_video->used < 2 ||
+		m_text->len - m_text->used < 2 || a_text->len - a_text->used < 2 ||
 		a_audio->len - a_audio->used < 2 || a_video->len - a_video->used < 2)
 		ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
 
 	ast_str_append(&m_audio, 0, "\r\n");
 	if (needvideo)
 		ast_str_append(&m_video, 0, "\r\n");
+	if (needtext)
+		ast_str_append(&m_text, 0, "\r\n");
 
 	len = strlen(version) + strlen(subject) + strlen(owner) +
 		strlen(connection) + strlen(stime) + m_audio->used + a_audio->used + strlen(hold);
 	if (needvideo) /* only if video response is appropriate */
 		len += m_video->used + a_video->used + strlen(bandwidth) + strlen(hold);
+	if (needtext) /* only if text response is appropriate */
+		len += m_text->used + a_text->used + strlen(hold);
 
 	add_header(resp, "Content-Type", "application/sdp");
 	add_header_contentLength(resp, len);
@@ -7130,6 +7181,11 @@
 		add_line(resp, m_video->str);
 		add_line(resp, a_video->str);
 		add_line(resp, hold);	/* Repeat hold for the video stream */
+	}
+	if (needtext) {
+		add_line(resp, m_text->str);
+		add_line(resp, a_text->str);
+		add_line(resp, hold);	/* Repeat hold for the text stream */
 	}
 
 	/* Update lastrtprx when we send our SDP */
@@ -9922,6 +9978,11 @@
 			ast_rtp_destroy(p->vrtp);
 			p->vrtp = NULL;
 		}
+		/* If we do not support text, remove text from call structure */
+		if (!ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) && p->trtp) {
+			ast_rtp_destroy(p->trtp);
+			p->trtp = NULL;
+		}
 	}
 	unref_user(user);
 	return res;
@@ -10041,6 +10102,10 @@
 			ast_rtp_destroy(p->vrtp);
 			p->vrtp = NULL;
 		}
+		if ((!ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) || !(p->capability & AST_FORMAT_TEXT_MASK)) && p->trtp) {
+			ast_rtp_destroy(p->trtp);
+			p->trtp = NULL;
+		}
 		if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
 		    (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
 			p->noncodeccapability |= AST_RTP_DTMF;
@@ -10527,6 +10592,7 @@
 			"Dynamic: %s\r\n"
 			"Natsupport: %s\r\n"
 			"VideoSupport: %s\r\n"
+			"TextSupport: %s\r\n"
 			"ACL: %s\r\n"
 			"Status: %s\r\n"
 			"RegisterFrom: %s\r\n"
@@ -10538,6 +10604,7 @@
 			ast_test_flag(&iterator->flags[1], SIP_PAGE2_DYNAMIC) ? "yes" : "no", 	/* Dynamic or not? */
 			ast_test_flag(&iterator->flags[0], SIP_NAT_ROUTE) ? "yes" : "no",	/* NAT=yes? */
 			ast_test_flag(&iterator->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no",	/* VIDEOSUPPORT=yes? */
+			ast_test_flag(&iterator->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "yes" : "no",       /* TEXTSUPPORT=yes? */
 			iterator->ha ? "yes" : "no",       /* permit/deny */
 			status,
 			iterator->register_from_hdr,
@@ -10976,6 +11043,7 @@
 		ast_cli(fd, "  PromiscRedir : %s\n", ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)?"Yes":"No");
 		ast_cli(fd, "  User=Phone   : %s\n", ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)?"Yes":"No");
 		ast_cli(fd, "  Video Support: %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)?"Yes":"No");
+		ast_cli(fd, "  Text Support : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT)?"Yes":"No");
 		ast_cli(fd, "  Trust RPID   : %s\n", ast_test_flag(&peer->flags[0], SIP_TRUSTRPID) ? "Yes" : "No");
 		ast_cli(fd, "  Send RPID    : %s\n", ast_test_flag(&peer->flags[0], SIP_SENDRPID) ? "Yes" : "No");
 		ast_cli(fd, "  Subscriptions: %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE) ? "Yes" : "No");
@@ -11065,6 +11133,7 @@
 		astman_append(s, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)?"Y":"N"));
 		astman_append(s, "SIP-UserPhone: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)?"Y":"N"));
 		astman_append(s, "SIP-VideoSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)?"Y":"N"));
+		astman_append(s, "SIP-TextSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT)?"Y":"N"));
 
 		/* - is enumerated */
 		astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF)));
@@ -11214,6 +11283,7 @@
 	ast_cli(fd, "  SIP Port:               %d\n", ntohs(bindaddr.sin_port));
 	ast_cli(fd, "  Bindaddress:            %s\n", ast_inet_ntoa(bindaddr.sin_addr));
 	ast_cli(fd, "  Videosupport:           %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "Yes" : "No");
+	ast_cli(fd, "  Textsupport:            %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT) ? "Yes" : "No");
 	ast_cli(fd, "  AutoCreatePeer:         %s\n", autocreatepeer ? "Yes" : "No");
 	ast_cli(fd, "  MatchAuthUsername:      %s\n", global_match_auth_username ? "Yes" : "No");
 	ast_cli(fd, "  Allow unknown access:   %s\n", global_allowguest ? "Yes" : "No");
@@ -11238,6 +11308,7 @@
 	ast_cli(fd, "  IP ToS SIP:             %s\n", ast_tos2str(global_tos_sip));
 	ast_cli(fd, "  IP ToS RTP audio:       %s\n", ast_tos2str(global_tos_audio));
 	ast_cli(fd, "  IP ToS RTP video:       %s\n", ast_tos2str(global_tos_video));
+	ast_cli(fd, "  IP ToS RTP text:        %s\n", ast_tos2str(global_tos_text));
 	ast_cli(fd, "  T38 fax pt UDPTL:       %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_UDPTL) ? "Yes" : "No");
 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
 	ast_cli(fd, "  T38 fax pt RTP:         %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_RTP) ? "Yes" : "No");
@@ -11909,11 +11980,13 @@
 	if (a->argc == e->args) {	/* on/off */
 		if (!strcasecmp(what, "on")) {
 			ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
+			ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_TEXT);   /*! \note this can be a special debug command - "sip debug text" or something */
 			memset(&debugaddr, 0, sizeof(debugaddr));
 			ast_cli(a->fd, "SIP Debugging %senabled\n", oldsipdebug ? "re-" : "");
 			return CLI_SUCCESS;
 		} else if (!strcasecmp(what, "off")) {
 			ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE);
+			ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_TEXT);
 			ast_cli(a->fd, "SIP Debugging Disabled\n");
 			return CLI_SUCCESS;
 		}
@@ -13161,6 +13234,8 @@
 		ast_rtp_stop(p->rtp);
 	if (p->vrtp)
 		ast_rtp_stop(p->vrtp);
+	if (p->trtp)
+		ast_rtp_stop(p->trtp);
 	if (p->udptl)
 		ast_udptl_stop(p->udptl);
 }
@@ -15174,7 +15249,7 @@
 
 	/* Get RTCP quality before end of call */
 	if (record_history(p) || p->owner) {
-		char *audioqos, *videoqos;
+		char *audioqos, *videoqos, *textqos;
 		if (p->rtp) {
 			audioqos = ast_rtp_get_quality(p->rtp);
 			append_history(p, "RTCPaudio", "Quality:%s", audioqos);
@@ -15186,6 +15261,12 @@
 			append_history(p, "RTCPvideo", "Quality:%s", videoqos);
 			if (p->owner)
 				pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos);
+		}
+		if (p->trtp) {
+			textqos = ast_rtp_get_quality(p->trtp);
+			append_history(p, "RTCPtext", "Quality:%s", textqos);
+			if (p->owner)
+				pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", textqos);
 		}
 	}
 
@@ -16474,6 +16555,7 @@
 	printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host);
 #endif
 	p->prefcodec = oldformat;				/* Format for this call */
+	p->jointcapability = oldformat;
 	sip_pvt_lock(p);
 	tmpc = sip_new(p, AST_STATE_DOWN, host);	/* Place the call */
 	/* XXX who keeps the reference ? */
@@ -16658,6 +16740,8 @@
 		CO_SF(0, SIP_PROMISCREDIR);
 	} else if (!strcasecmp(v->name, "videosupport")) {
 		CO_SF(1, SIP_PAGE2_VIDEOSUPPORT);
+	} else if (!strcasecmp(v->name, "textsupport")) {
+		CO_SF(1, SIP_PAGE2_TEXTSUPPORT);
 	} else if (!strcasecmp(v->name, "allowoverlap")) {
 		CO_SF(1, SIP_PAGE2_ALLOWOVERLAP);
 	} else if (!strcasecmp(v->name, "allowsubscribe")) {
@@ -17078,10 +17162,9 @@
 		M_STR("fromdomain", peer->fromdomain)
 		M_F("usereqphone", ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE);)
 		M_STR("fromuser", peer->fromuser)
-#if 0 /* XXX fixme */
+		/* XXX do not use commas in the macro, cpp can get confused */
 		M_F("outboundproxy", {
-			char *port, *next, *force, *proxyname;
-			int forceopt = FALSE;
+			char *port; char *next; char *force; char *proxyname; int forceopt = FALSE;
 			/* Set peer channel variable */
 			/* XXX use strsep here... */
 			next = proxyname = ast_strdupa(v->value);
@@ -17096,7 +17179,7 @@
 			/* Allocate proxy object */
 			peer->outboundproxy = proxy_allocate(proxyname, port, forceopt);
 		} )
-		M_F("host", {{
+		M_F("host",
 			if (!strcasecmp(v->value, "dynamic")) {
 				/* They'll register with us */
 				ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
@@ -17124,8 +17207,8 @@
 				ast_copy_string(peer->tohost, v->value, sizeof(peer->tohost));
 				if (!peer->addr.sin_port)
 					peer->addr.sin_port = htons(STANDARD_SIP_PORT);
-			}} )
-#endif
+			}
+		)
 		M_F("defaultip", {
 			if (ast_get_ip(&peer->defaddr, v->value)) {
 				unref_peer(peer);
@@ -17265,6 +17348,7 @@
 	global_tos_sip = DEFAULT_TOS_SIP;
 	global_tos_audio = DEFAULT_TOS_AUDIO;
 	global_tos_video = DEFAULT_TOS_VIDEO;
+	global_tos_text = DEFAULT_TOS_TEXT;
 	externhost[0] = '\0';			/* External host name (for behind NAT DynDNS support) */
 	externexpire = 0;			/* Expiration for DNS re-issuing */
 	externrefresh = 10;
@@ -17329,6 +17413,7 @@
 	memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
 
 	ast_clear_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT);
+	ast_clear_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT);
 
 	/* Read the [general] config section of sip.conf (or from realtime config) */
 	for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
@@ -17475,6 +17560,9 @@
 		M_F("tos_video", {
 			if (ast_str2tos(v->value, &global_tos_video))
 				ast_log(LOG_WARNING, "Invalid tos_video value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno); } )
+		M_F("tos_text", {
+			if (ast_str2tos(v->value, &global_tos_text))
+				ast_log(LOG_WARNING, "Invalid tos_text value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno); } )
 		M_F("bindport", {
 			if (sscanf(v->value, "%d", &ourport) == 1) {
 				bindaddr.sin_port = htons(ourport);
@@ -17874,6 +17962,31 @@
 	return res;
 }
 
+/* XXX this is almost the same as for vrtp. */
+/*! \brief Returns null if we can't reinvite text (part of RTP interface) */
+static enum ast_rtp_get_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp **rtp)
+{
+	struct sip_pvt *p = NULL;
+	enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL;
+
+	if (!(p = chan->tech_pvt))
+		return AST_RTP_GET_FAILED;
+
+	sip_pvt_lock(p);
+	if (!(p->trtp)) {
+		sip_pvt_unlock(p);
+		return AST_RTP_GET_FAILED;
+	}
+
+	*rtp = p->trtp;
+
+	if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE))
+		res = AST_RTP_TRY_NATIVE;
+
+	sip_pvt_unlock(p);
+
+	return res;
+}
 /*! \brief Set the RTP peer for this call */
 static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active)
 {



More information about the asterisk-commits mailing list