[asterisk-commits] russell: branch russell/messaging r297573 - in /team/russell/messaging: chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 3 15:49:28 CST 2010


Author: russell
Date: Fri Dec  3 15:49:23 2010
New Revision: 297573

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=297573
Log:
Add support for auth requests for outbound MESSAGE requests

Also, update MESSAGE auth test to also test authenticated outbound MESSAGE

Modified:
    team/russell/messaging/channels/chan_sip.c
    team/russell/messaging/channels/sip/include/sip.h
    team/russell/messaging/doc/asterisk-messaging.txt
    team/russell/messaging/testsuite-tests/message_auth/sipp/message_recv.xml

Modified: team/russell/messaging/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/channels/chan_sip.c?view=diff&rev=297573&r1=297572&r2=297573
==============================================================================
--- team/russell/messaging/channels/chan_sip.c (original)
+++ team/russell/messaging/channels/chan_sip.c Fri Dec  3 15:49:23 2010
@@ -1248,7 +1248,7 @@
 static int transmit_info_with_aoc(struct sip_pvt *p, struct ast_aoc_decoded *decoded);
 static int transmit_info_with_digit(struct sip_pvt *p, const char digit, unsigned int duration);
 static int transmit_info_with_vidupdate(struct sip_pvt *p);
-static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init);
+static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init, int auth);
 static int transmit_refer(struct sip_pvt *p, const char *dest);
 static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten);
 static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq, char *message, int terminate);
@@ -1539,6 +1539,7 @@
 static void handle_response_refer(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
 static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
 static int handle_response_register(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
+static void handle_response_message(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
 static void handle_response(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno);
 
 /*------ SRTP Support -------- */
@@ -4218,7 +4219,7 @@
 	}
 	if (debug)
 		ast_verbose("Sending text %s on %s\n", text, ast->name);
-	transmit_message_with_text(dialog, text, 0);
+	transmit_message_with_text(dialog, text, 0, 0);
 	return 0;	
 }
 
@@ -12610,17 +12611,23 @@
 }
 
 /*! \brief Transmit text with SIP MESSAGE method */
-static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init)
+static int transmit_message_with_text(struct sip_pvt *p, const char *text, int init, int auth)
 {
 	struct sip_request req;
 
 	if (init) {
 		initreqprep(&req, p, SIP_MESSAGE, NULL);
+		ast_string_field_set(p, msg_body, text);
+		initialize_initreq(p, &req);
 	} else {
 		reqprep(&req, p, SIP_MESSAGE, 0, 1);
 	}
-	add_text(&req, text);
-	return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
+	if (auth) {
+		return transmit_request_with_auth(p, SIP_MESSAGE, p->ocseq, XMIT_RELIABLE, 0);
+	} else {
+		add_text(&req, text);
+		return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
+	}
 }
 
 /*! \brief Allocate SIP refer structure */
@@ -12857,6 +12864,10 @@
 		add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->hangupcause));
 		snprintf(buf, sizeof(buf), "%d", p->hangupcause);
 		add_header(&resp, "X-Asterisk-HangupCauseCode", buf);
+	}
+
+	if (sipmethod == SIP_MESSAGE) {
+		add_text(&resp, p->msg_body);
 	}
 
 	return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq);	
@@ -20012,6 +20023,8 @@
 				res = handle_response_register(p, resp, rest, req, seqno);
 			else if (sipmethod == SIP_UPDATE) {
 				handle_response_update(p, resp, rest, req, seqno);
+			} else if (sipmethod == SIP_MESSAGE) {
+				handle_response_message(p, resp, rest, req, seqno);
 			} else if (sipmethod == SIP_BYE) {
 				if (p->options)
 					p->options->auth_type = resp;
@@ -20368,11 +20381,11 @@
 
 #ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE
 	if (!res) {
-		transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n", 0);
+		transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n", 0, 0);
 	} else {
 		/* Then tell the transferer what happened */
 		sprintf(buf, "Call parked on extension '%d'", ext);
-		transmit_message_with_text(transferer->tech_pvt, buf, 0);
+		transmit_message_with_text(transferer->tech_pvt, buf, 0, 0);
 	}
 #endif
 
@@ -22783,6 +22796,41 @@
 	return 1;
 }
 
+/*!
+ * \internal
+ * \brief Handle auth requests to a MESSAGE request
+ */
+static void handle_response_message(struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, int seqno)
+{
+	char *header, *respheader;
+	char digest[1024];
+
+	if (p->options) {
+		p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH);
+	}
+
+	if ((p->authtries == MAX_AUTHTRIES)) {
+		ast_log(LOG_NOTICE, "Failed to authenticate on MESSAGE to '%s'\n", get_header(&p->initreq, "From"));
+		pvt_set_needdestroy(p, "MESSAGE authentication failed");
+	}
+
+	p->authtries++;
+	auth_headers((resp == 401 ? WWW_AUTH : PROXY_AUTH), &header, &respheader);
+	memset(digest, 0, sizeof(digest));
+	if (reply_digest(p, req, header, SIP_MESSAGE, digest, sizeof(digest))) {
+		/* There's nothing to use for authentication */
+		ast_debug(1, "Nothing to use for MESSAGE authentication\n");
+		pvt_set_needdestroy(p, "MESSAGE authentication failed");
+		return;
+	}
+
+	if (p->do_history) {
+		append_history(p, "MessageAuth", "Try: %d", p->authtries);
+	}
+
+	transmit_message_with_text(p, p->msg_body, 0, 1);
+}
+
 /*! \brief Handle incoming MESSAGE request */
 static int handle_request_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 {
@@ -22836,7 +22884,7 @@
 
 	/* XXX Does pvt->expiry need to be set? */
 
-	res = transmit_message_with_text(pvt, ast_msg_get_body(msg), 1);
+	res = transmit_message_with_text(pvt, ast_msg_get_body(msg), 1, 0);
 
 	sip_pvt_unlock(pvt);
 	sip_scheddestroy(pvt, DEFAULT_TRANS_TIMEOUT);

Modified: team/russell/messaging/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/channels/sip/include/sip.h?view=diff&rev=297573&r1=297572&r2=297573
==============================================================================
--- team/russell/messaging/channels/sip/include/sip.h (original)
+++ team/russell/messaging/channels/sip/include/sip.h Fri Dec  3 15:49:23 2010
@@ -953,6 +953,7 @@
 		AST_STRING_FIELD(parkinglot);   /*!< Parkinglot */
 		AST_STRING_FIELD(engine);       /*!< RTP engine to use */
 		AST_STRING_FIELD(dialstring);   /*!< The dialstring used to call this SIP endpoint */
+		AST_STRING_FIELD(msg_body);     /*!< Text for a MESSAGE body */
 	);
 	char via[128];                          /*!< Via: header */
 	int maxforwards;                        /*!< SIP Loop prevention */

Modified: team/russell/messaging/doc/asterisk-messaging.txt
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/doc/asterisk-messaging.txt?view=diff&rev=297573&r1=297572&r2=297573
==============================================================================
--- team/russell/messaging/doc/asterisk-messaging.txt (original)
+++ team/russell/messaging/doc/asterisk-messaging.txt Fri Dec  3 15:49:23 2010
@@ -275,8 +275,6 @@
 
     -> Add automated tests for:
        - disabling out of call MESSAGE completely
-       - MESSAGE with and without authentication, making sure messages hit
-         the right context
 
 XMPP (res_jabber):
 

Modified: team/russell/messaging/testsuite-tests/message_auth/sipp/message_recv.xml
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/testsuite-tests/message_auth/sipp/message_recv.xml?view=diff&rev=297573&r1=297572&r2=297573
==============================================================================
--- team/russell/messaging/testsuite-tests/message_auth/sipp/message_recv.xml (original)
+++ team/russell/messaging/testsuite-tests/message_auth/sipp/message_recv.xml Fri Dec  3 15:49:23 2010
@@ -1,6 +1,22 @@
 <?xml version="1.0" encoding="ISO-8859-1" ?>
 
 <scenario name="Basic MESSAGE send and receive">
+  <recv request="MESSAGE" crlf="true">
+  </recv>
+
+  <send>
+    <![CDATA[
+      SIP/2.0 401 Unauthorized
+      [last_Via:]
+      [last_From:]
+      [last_To:];tag=[call_number]
+      [last_Call-ID:]
+      [last_CSeq:]
+      WWW-Authenticate: digest realm="test",stale=true
+
+    ]]>
+  </send>
+
   <recv request="MESSAGE" crlf="true">
   </recv>
 




More information about the asterisk-commits mailing list