[asterisk-commits] oej: branch group/pinana-publish-1.4 r296508 - /team/group/pinana-publish-1.4...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Nov 27 16:07:42 CST 2010


Author: oej
Date: Sat Nov 27 16:07:39 2010
New Revision: 296508

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=296508
Log:
Yes, marquis, sloppy xml parsing. You're exactly right in that judgement.
But hey, we're getting those NOTIFY's coming in :-)

Btw, we're not going to be handle hold states with this way of treating xml...

Modified:
    team/group/pinana-publish-1.4/channels/chan_sip.c

Modified: team/group/pinana-publish-1.4/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pinana-publish-1.4/channels/chan_sip.c?view=diff&rev=296508&r1=296507&r2=296508
==============================================================================
--- team/group/pinana-publish-1.4/channels/chan_sip.c (original)
+++ team/group/pinana-publish-1.4/channels/chan_sip.c Sat Nov 27 16:07:39 2010
@@ -15083,9 +15083,8 @@
 		
 		/* Confirm that we received this packet */
 		transmit_response(p, "200 OK", req);
-	} else if (!strcmp(event, "dialog-info")) {
+	} else if (!strcmp(event, "dialog")) {
 		res = sip_pres_notify_update(p, req);
-
 	} else {
 		/* We don't understand this event. */
 		/* Here's room to implement incoming voicemail notifications :-) */
@@ -19397,10 +19396,67 @@
 /*! \brief Parse the incoming NOTIFY update and update the device state provider system for this device */
 static int sip_pres_notify_update(struct sip_pvt *dialog, struct sip_request *req)
 {
+	char buf[SIPBUFSIZE * 8];
+	char *state;
+/* Example:
+		NOTIFY sip:olle at 192.168.40.12 SIP/2.0
+		Via: SIP/2.0/UDP 192.168.20.200:5060;branch=z9hG4bK4d19eadc;rport
+		From: <sip:3000 at jarl.webway.se>;tag=as714765a1
+		To: "asterisk" <sip:olle at 192.168.40.12>;tag=as0ffc65b2
+		Contact: <sip:rutger at 192.168.20.200>
+		Call-ID: 0ef08767032f0f1f37eeb8c770309de7 at 192.168.40.12
+		CSeq: 102 NOTIFY
+		User-Agent: Asterisk Grouch Edition
+		Max-Forwards: 70
+		Event: dialog
+		Content-Type: application/dialog-info+xml
+		Subscription-State: active
+		Content-Length: 207
+
+		<?xml version="1.0"?>
+		<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info" version="0" state="full" entity="sip:3000 at jarl.webway.se">
+		<dialog id="3000">
+		<state>terminated</state>
+		</dialog>
+		</dialog-info>
+*/
+	/* Check the content type */
+	if (strncasecmp(get_header(req, "Content-Type"), "application/dialog-info+xml", strlen("application/dialog-info+xml"))) {
+		/* We need a dialog-info at this point */
+		transmit_response(dialog, "400 Bad request", req);
+		sip_scheddestroy(dialog, DEFAULT_TRANS_TIMEOUT);
+		return -1;
+	}
 	/* Get the XML message body */
-	/* Find the good stuff in it */
+	if (get_msg_text(buf, sizeof(buf), req)) {
+		ast_log(LOG_WARNING, "Unable to retrieve attachment from NOTIFY %s\n", dialog->callid);
+		transmit_response(dialog, "400 Bad request", req);
+		sip_scheddestroy(dialog, DEFAULT_TRANS_TIMEOUT);
+		return -1;
+	}
+	
+	/* Find the good stuff in it - we need the state */
+	state = strcasestr(buf, "</state>");
+	if (!state) {
+		/* Houston, we've got a problem - bad XML */
+		transmit_response(dialog, "400 Bad request", req);
+		sip_scheddestroy(dialog, DEFAULT_TRANS_TIMEOUT);
+		return -1;
+	}
+	*state = '\0';
+	state = strcasestr(buf, "<state>");
+	if (!state) {
+		/* Houston, we've got a problem - bad XML */
+		transmit_response(dialog, "400 Bad request", req);
+		sip_scheddestroy(dialog, DEFAULT_TRANS_TIMEOUT);
+		return -1;
+	}
+	state += strlen("<state>");
+	ast_log(LOG_DEBUG, "---------- State: ->%s<- \n", state);
+
 	/* Notify the device state system if there's a change */
 	/* Live long and prosper */
+	transmit_response(dialog, "200 OK", req);
 	return 0;
 }
 




More information about the asterisk-commits mailing list