More #937 (presence):
 - added protection to not resubscribe immediately if initial SUBSCRIBE is responded with 481 for some reason


git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2960 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c
index 1c8fc61..e786637 100644
--- a/pjsip/src/pjsua-lib/pjsua_pres.c
+++ b/pjsip/src/pjsua-lib/pjsua_pres.c
@@ -1467,7 +1467,14 @@
 			/* 481: we refreshed too late? resubscribe
 			 * immediately.
 			 */
-			resub_delay = 500;
+			/* But this must only happen when the 481 is received
+			 * on subscription refresh request. We MUST NOT try to
+			 * resubscribe automatically if the 481 is received
+			 * on the initial SUBSCRIBE (if server returns this
+			 * response for some reason).
+			 */
+			if (buddy->dlg->remote.contact)
+			    resub_delay = 500;
 			break;
 		    }
 		} else if (pjsip_method_cmp(&tsx->method,
@@ -1530,8 +1537,9 @@
 	    }
 
 	    buddy_resubscribe(buddy, PJ_TRUE, resub_delay);
-				  
+
 	} else {
+	    /* This will clear the last termination code/reason */
 	    buddy->term_code = 0;
 	    buddy->term_reason.slen = 0;
 	}