Ticket #870: Changed the mapping of host resolution failure to SIP status code 502 from 503 (thanks Robert Cichielo for the report)
 - also fixed client registration to use the reason phrase of the transaction rather than to retrieve the default reason phrase for the status code



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2732 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsip-ua/sip_reg.c b/pjsip/src/pjsip-ua/sip_reg.c
index d08427d..5278ae4 100644
--- a/pjsip/src/pjsip-ua/sip_reg.c
+++ b/pjsip/src/pjsip-ua/sip_reg.c
@@ -1056,7 +1056,7 @@
 	pj_lock_release(regc->lock);
 	call_callback(regc, PJ_SUCCESS, tsx->status_code, 
 		      (rdata ? &rdata->msg_info.msg->line.status.reason 
-			: pjsip_get_status_text(tsx->status_code)),
+			: &tsx->status_text),
 		      rdata, expiration, 
 		      contact_cnt, contact);
 	pj_lock_acquire(regc->lock);
diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c
index d10906d..f205ff5 100644
--- a/pjsip/src/pjsip/sip_transaction.c
+++ b/pjsip/src/pjsip/sip_transaction.c
@@ -23,6 +23,7 @@
 #include <pjsip/sip_endpoint.h>
 #include <pjsip/sip_errno.h>
 #include <pjsip/sip_event.h>
+#include <pjlib-util/errno.h>
 #include <pj/hash.h>
 #include <pj/pool.h>
 #include <pj/os.h>
@@ -1691,6 +1692,7 @@
 
 	if (!*cont) {
 	    char errmsg[PJ_ERR_MSG_SIZE];
+	    pjsip_status_code sc;
 	    pj_str_t err;
 
 	    tsx->transport_err = -sent;
@@ -1708,8 +1710,17 @@
 	    /* Mark that we have resolved the addresses. */
 	    tsx->transport_flag |= TSX_HAS_RESOLVED_SERVER;
 
+	    /* Server resolution error is now mapped to 502 instead of 503,
+	     * since with 503 normally client should try again.
+	     * See http://trac.pjsip.org/repos/ticket/870
+	     */
+	    if (-sent==PJ_ERESOLVE || -sent==PJLIB_UTIL_EDNS_NXDOMAIN)
+		sc = PJSIP_SC_BAD_GATEWAY;
+	    else
+		sc = PJSIP_SC_TSX_TRANSPORT_ERROR;
+
 	    /* Terminate transaction, if it's not already terminated. */
-	    tsx_set_status_code(tsx, PJSIP_SC_TSX_TRANSPORT_ERROR, &err);
+	    tsx_set_status_code(tsx, sc, &err);
 	    if (tsx->state != PJSIP_TSX_STATE_TERMINATED &&
 		tsx->state != PJSIP_TSX_STATE_DESTROYED)
 	    {