Fixed several bugs in PJSUA-API:
- in some condition, when outgoing call fails, call count
  incorrectly decremented to -1
- introduce account priority in pjsua_acc_config, and
  improve the account searching for incoming calls
- pjsua will hangup call after sending transfer/REFER request.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@737 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index 35eee94..bb2ccd1 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -237,6 +237,9 @@
 
     call = &pjsua_var.calls[call_id];
 
+    PJ_LOG(4,(THIS_FILE, "Making call with acc #%d to %.*s", acc_id,
+	      (int)dest_uri->slen, dest_uri->ptr));
+
     /* Mark call start time. */
     pj_gettimeofday(&call->start_time);
 
@@ -316,6 +319,9 @@
 
     pjsua_process_msg_data( tdata, msg_data);
 
+    /* Must increment call counter now */
+    ++pjsua_var.call_cnt;
+
     /* Send initial INVITE: */
 
     status = pjsip_inv_send_msg(inv, tdata);
@@ -333,8 +339,6 @@
 
     /* Done. */
 
-    ++pjsua_var.call_cnt;
-
     if (p_call_id)
 	*p_call_id = call_id;
 
@@ -462,7 +466,7 @@
      * call. We need the account to find which contact URI to put for
      * the call.
      */
-    acc_id = pjsua_acc_find_for_incoming(rdata);
+    acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata);
 
     /* Get suitable Contact header */
     status = pjsua_acc_create_uas_contact(rdata->tp_info.pool, &contact,