[asterisk-commits] markster: trunk r65731 - /trunk/channels/chan_sip.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed May 23 19:23:08 MST 2007


Author: markster
Date: Wed May 23 21:23:08 2007
New Revision: 65731

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65731
Log:
Add SendURL support

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=65731&r1=65730&r2=65731
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed May 23 21:23:08 2007
@@ -1037,6 +1037,8 @@
 	struct ast_rtp *rtp;			/*!< RTP Session */
 	struct ast_rtp *vrtp;			/*!< Video RTP session */
 	struct ast_rtp *trtp;			/*!< Text RTP session */
+	const char *url;				/*!< Temporary URI for next response */
+	int freeurl;					/*!< Whether URI should be free()'d */
 	struct sip_pkt *packets;		/*!< Packets scheduled for re-transmission */
 	struct sip_history_head *history;	/*!< History of this SIP dialog */
 	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
@@ -1264,6 +1266,7 @@
 static int sip_devicestate(void *data);
 static int sip_sendtext(struct ast_channel *ast, const char *text);
 static int sip_call(struct ast_channel *ast, char *dest, int timeout);
+static int sip_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen);
 static int sip_hangup(struct ast_channel *ast);
 static int sip_answer(struct ast_channel *ast);
 static struct ast_frame *sip_read(struct ast_channel *ast);
@@ -1597,6 +1600,7 @@
 	.requester = sip_request_call,
 	.devicestate = sip_devicestate,
 	.call = sip_call,
+	.send_html = sip_sendhtml,
 	.hangup = sip_hangup,
 	.answer = sip_answer,
 	.read = sip_read,
@@ -2536,6 +2540,44 @@
 		*options = uri ? uri : "";
 
 	return error;
+}
+
+/*! \brief Send message with Access-URL header, if this is an HTML URL only! */
+static int sip_sendhtml(struct ast_channel *chan, int subclass, const char *data, int datalen)
+{
+	struct sip_pvt *p = chan->tech_pvt;
+	char *tmp;
+	int debug = sip_debug_test_pvt(p);
+	if (subclass != AST_HTML_URL)
+		return -1;
+	tmp = alloca(strlen(data) + 20);
+	snprintf(tmp, strlen(data) + 20, "<%s>;mode=active", data);
+	p->url = tmp;
+	if (debug)
+		ast_verbose("Send URL %s, state = %d!\n", data, chan->_state);
+	switch(chan->_state) {
+	case AST_STATE_RING:
+		transmit_response(p, "100 Trying", &p->initreq);
+		break;
+	case AST_STATE_RINGING:
+		transmit_response(p, "180 Ringing", &p->initreq);
+		break;
+	case AST_STATE_UP:
+		if (!p->pendinginvite) {		/* We are up, and have no outstanding invite */
+			transmit_reinvite_with_sdp(p, FALSE);
+		} else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) {
+			/* We have a pending Invite. Send re-invite when we're done with the invite */
+			ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);	
+			p->url = strdup(p->url);
+			p->freeurl = 1;
+		}	
+		break;
+	default:
+		ast_log(LOG_WARNING, "Don't know how to send URI when state is %d!\n", chan->_state);
+	}
+	if (p->url && !p->freeurl)
+		ast_log(LOG_WARNING, "Whoa, didn't expect URI to hang around!\n");
+	return 0;
 }
 
 /*! \brief Send SIP MESSAGE text within a call
@@ -6104,6 +6146,12 @@
 	} else if (msg[0] != '4' && p->our_contact[0]) {
 		add_header(resp, "Contact", p->our_contact);
 	}
+	if (p->url) {
+		add_header(resp, "Access-URL", p->url);
+		if (p->freeurl)
+			free((char *)p->url);
+		p->url = NULL;
+	}
 	return 0;
 }
 
@@ -6208,7 +6256,12 @@
 
 	if (!ast_strlen_zero(p->rpid))
 		add_header(req, "Remote-Party-ID", p->rpid);
-
+	if (p->url) {
+		add_header(req, "Access-URL", p->url);
+		if (p->freeurl)
+			free((char *)p->url);
+		p->url = NULL;
+	}
 	return 0;
 }
 



More information about the asterisk-commits mailing list