Fixed bug in route set calculation: prevent updating route set upon receiving failure response (e.g. 401/407 response), and remove the first_cseq check since this would not work when the first request is challenged

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1555 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsip/sip_dialog.c b/pjsip/src/pjsip/sip_dialog.c
index 595574a..09954c6 100644
--- a/pjsip/src/pjsip/sip_dialog.c
+++ b/pjsip/src/pjsip/sip_dialog.c
@@ -1560,9 +1560,12 @@
 	if (msg->type != PJSIP_RESPONSE_MSG)
 	    return;
 
-	/* Ignore subsequent responses with higher CSeq than initial CSeq */
-	if (msg_cseq != dlg->local.first_cseq)
-	    return;
+	/* Ignore subsequent responses with higher CSeq than initial CSeq.
+	 * Unfortunately this would be broken when the first request is 
+	 * challenged!
+	 */
+	//if (msg_cseq != dlg->local.first_cseq)
+	//    return;
 
     } else {
 
@@ -1577,6 +1580,10 @@
     /* Based on the checks above, we should only get response message here */
     pj_assert(msg->type == PJSIP_RESPONSE_MSG);
 
+    /* Ignore if this is not 1xx or 2xx response */
+    if (msg->line.status.code >= 300)
+	return;
+
     /* Reset route set */
     pj_list_init(&dlg->route_set);
 
@@ -1591,6 +1598,8 @@
 	}
     }
 
+    PJ_LOG(5,(dlg->obj_name, "Route-set updated"));
+
     /* Freeze the route set only when the route set comes in 2xx response. 
      * If it is in 1xx response, prepare to recompute the route set when 
      * the 2xx response comes in.
@@ -1599,9 +1608,15 @@
      * is established with reliable provisional response, but I think
      * it is safer to not freeze the route set (thus recompute the route set
      * upon receiving 2xx response). Also RFC 3261 says so in 13.2.2.4.
+     *
+     * The pjsip_method_creates_dialog() check protects from wrongly 
+     * freezing the route set upon receiving 200/OK response for PRACK.
      */
-    if (PJSIP_IS_STATUS_IN_CLASS(msg->line.status.code, 200)) {
+    if (pjsip_method_creates_dialog(&rdata->msg_info.cseq->method) &&
+	PJSIP_IS_STATUS_IN_CLASS(msg->line.status.code, 200)) 
+    {
 	dlg->route_set_frozen = PJ_TRUE;
+	PJ_LOG(5,(dlg->obj_name, "Route-set frozen"));
     }
 }