Moved pjsua to pjsip-apps

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@253 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index c468f85..775c96b 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -58,6 +58,10 @@
     pjsua.sip_port = 5060;
 
 
+    /* Default we start RTP at port 4000 */
+    pjsua.start_rtp_port = 4000;
+
+
     /* Default logging settings: */
     pjsua.log_level = 5;
     pjsua.app_log_level = 4;
@@ -138,8 +142,6 @@
 				pjmedia_sock_info *skinfo)
 {
     enum { 
-	RTP_START_PORT = 4000,
-	RTP_RANDOM_START = 2,
 	RTP_RETRY = 100
     };
     enum {
@@ -148,11 +150,14 @@
 	RTCP_SOCK,
     };
     int i;
-    static pj_uint16_t rtp_port = RTP_START_PORT;
+    static pj_uint16_t rtp_port;
     pj_sock_t sock[3];
     pj_sockaddr_in mapped_addr[3];
     pj_status_t status = PJ_SUCCESS;
 
+    if (rtp_port == 0)
+	rtp_port = (pj_uint16_t)pjsua.start_rtp_port;
+
     for (i=0; i<3; ++i)
 	sock[i] = PJ_INVALID_SOCKET;
 
diff --git a/pjsip/src/pjsua-lib/pjsua_opt.c b/pjsip/src/pjsua-lib/pjsua_opt.c
index bdd1a42..c8b0ada 100644
--- a/pjsip/src/pjsua-lib/pjsua_opt.c
+++ b/pjsip/src/pjsua-lib/pjsua_opt.c
@@ -82,6 +82,7 @@
     puts("  --auto-play         Automatically play the file (to incoming calls only)");
     puts("  --auto-loop         Automatically loop incoming RTP to outgoing RTP");
     puts("  --auto-conf         Automatically put incoming calls to conference");
+    puts("  --rtp-port=N	Base port to try for RTP");
     puts("");
     puts("Buddy List (can be more than one):");
     puts("  --add-buddy url     Add the specified URL to the buddy list.");
@@ -211,7 +212,7 @@
 	   OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE,
 	   OPT_AUTO_ANSWER, OPT_AUTO_HANGUP, OPT_AUTO_PLAY, OPT_AUTO_LOOP,
 	   OPT_AUTO_CONF,
-	   OPT_PLAY_FILE,
+	   OPT_PLAY_FILE, OPT_RTP_PORT,
 	   OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS,
     };
     struct option long_options[] = {
@@ -243,6 +244,7 @@
 	{ "auto-loop",  0, 0, OPT_AUTO_LOOP},
 	{ "auto-conf",  0, 0, OPT_AUTO_CONF},
 	{ "play-file",  1, 0, OPT_PLAY_FILE},
+	{ "rtp-port",	1, 0, OPT_RTP_PORT},
 	{ "next-account",0,0, OPT_NEXT_ACCOUNT},
 	{ "next-cred",	0, 0, OPT_NEXT_CRED},
 	{ "max-calls",	1, 0, OPT_MAX_CALLS},
@@ -462,10 +464,19 @@
 	    pjsua.wav_file = optarg;
 	    break;
 
+	case OPT_RTP_PORT:
+	    pjsua.start_rtp_port = my_atoi(optarg);
+	    if (pjsua.start_rtp_port < 1 || pjsua.start_rtp_port > 65535) {
+		PJ_LOG(1,(THIS_FILE,
+			  "Error: rtp-port argument value (expecting 1-65535"));
+		return -1;
+	    }
+
 	case OPT_AUTO_ANSWER:
 	    pjsua.auto_answer = my_atoi(optarg);
 	    if (pjsua.auto_answer < 100 || pjsua.auto_answer > 699) {
-		puts("Error: invalid code in --auto-answer (expecting 100-699");
+		PJ_LOG(1,(THIS_FILE,
+			  "Error: invalid code in --auto-answer (expecting 100-699"));
 		return -1;
 	    }
 	    break;
@@ -473,7 +484,7 @@
 	case OPT_MAX_CALLS:
 	    pjsua.max_calls = my_atoi(optarg);
 	    if (pjsua.max_calls < 1 || pjsua.max_calls > 255) {
-		puts("Too many calls for max-calls (1-255)");
+		PJ_LOG(1,(THIS_FILE,"Too many calls for max-calls (1-255)"));
 		return -1;
 	    }
 	    break;
@@ -577,8 +588,8 @@
 
     pjsip_endpt_dump(pjsua.endpt, 1);
     pjmedia_endpt_dump(pjsua.med_endpt);
-    pjsip_tsx_layer_dump();
-    pjsip_ua_dump();
+    pjsip_tsx_layer_dump(1);
+    pjsip_ua_dump(1);
 
 
     /* Dump all invite sessions: */
diff --git a/pjsip/src/pjsua-lib/pjsua_reg.c b/pjsip/src/pjsua-lib/pjsua_reg.c
index e18f7cc..1552acf 100644
--- a/pjsip/src/pjsua-lib/pjsua_reg.c
+++ b/pjsip/src/pjsua-lib/pjsua_reg.c
@@ -86,8 +86,8 @@
  */
 void pjsua_regc_update(int acc_index, pj_bool_t renew)
 {
-    pj_status_t status;
-    pjsip_tx_data *tdata;
+    pj_status_t status = 0;
+    pjsip_tx_data *tdata = 0;
 
     if (renew) {
 	if (pjsua.acc[acc_index].regc == NULL) {
@@ -98,7 +98,12 @@
 		return;
 	    }
 	}
-	status = pjsip_regc_register(pjsua.acc[acc_index].regc, 1, &tdata);
+	if (!pjsua.acc[acc_index].regc)
+	    return;
+
+	status = pjsip_regc_register(pjsua.acc[acc_index].regc, 1, 
+				     &tdata);
+
     } else {
 	if (pjsua.acc[acc_index].regc == NULL) {
 	    PJ_LOG(3,(THIS_FILE, "Currently not registered"));
@@ -126,42 +131,45 @@
 {
     pj_status_t status;
 
-    /* initialize SIP registration if registrar is configured */
-    if (pjsua.acc[acc_index].reg_uri.slen) {
-
-	status = pjsip_regc_create( pjsua.endpt, 
-				    &pjsua.acc[acc_index], 
-				    &regc_cb, 
-				    &pjsua.acc[acc_index].regc);
-
-	if (status != PJ_SUCCESS) {
-	    pjsua_perror(THIS_FILE, "Unable to create client registration", 
-			 status);
-	    return status;
-	}
-
-
-	status = pjsip_regc_init( pjsua.acc[acc_index].regc, 
-				  &pjsua.acc[acc_index].reg_uri, 
-				  &pjsua.acc[acc_index].local_uri, 
-				  &pjsua.acc[acc_index].local_uri,
-				  1, &pjsua.acc[acc_index].contact_uri, 
-				  pjsua.acc[acc_index].reg_timeout);
-	if (status != PJ_SUCCESS) {
-	    pjsua_perror(THIS_FILE, 
-			 "Client registration initialization error", 
-			 status);
-	    return status;
-	}
-
-	pjsip_regc_set_credentials( pjsua.acc[acc_index].regc, 
-				    pjsua.cred_count, 
-				    pjsua.cred_info );
-
-	pjsip_regc_set_route_set( pjsua.acc[acc_index].regc, 
-				  &pjsua.acc[acc_index].route_set );
+    if (pjsua.acc[acc_index].reg_uri.slen == 0) {
+	PJ_LOG(3,(THIS_FILE, "Registrar URI is not specified"));
+	return PJ_SUCCESS;
     }
 
+    /* initialize SIP registration if registrar is configured */
+
+    status = pjsip_regc_create( pjsua.endpt, 
+				&pjsua.acc[acc_index], 
+				&regc_cb, 
+				&pjsua.acc[acc_index].regc);
+
+    if (status != PJ_SUCCESS) {
+	pjsua_perror(THIS_FILE, "Unable to create client registration", 
+		     status);
+	return status;
+    }
+
+
+    status = pjsip_regc_init( pjsua.acc[acc_index].regc, 
+			      &pjsua.acc[acc_index].reg_uri, 
+			      &pjsua.acc[acc_index].local_uri, 
+			      &pjsua.acc[acc_index].local_uri,
+			      1, &pjsua.acc[acc_index].contact_uri, 
+			      pjsua.acc[acc_index].reg_timeout);
+    if (status != PJ_SUCCESS) {
+	pjsua_perror(THIS_FILE, 
+		     "Client registration initialization error", 
+		     status);
+	return status;
+    }
+
+    pjsip_regc_set_credentials( pjsua.acc[acc_index].regc, 
+				pjsua.cred_count, 
+				pjsua.cred_info );
+
+    pjsip_regc_set_route_set( pjsua.acc[acc_index].regc, 
+			      &pjsua.acc[acc_index].route_set );
+
     return PJ_SUCCESS;
 }