Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2316)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2370)
@@ -63,4 +63,5 @@
     pjsua_transport_config  udp_cfg;
     pjsua_transport_config  rtp_cfg;
+    pjsip_redirect_op	    redir_op;
 
     unsigned		    acc_cnt;
@@ -279,4 +280,6 @@
     puts  ("  --use-compact-form  Minimize SIP message size");
     puts  ("  --no-force-lr       Allow strict-route to be used (i.e. do not force lr)");
+    puts  ("  --accept-redirect=N Specify how to handle call redirect (3xx) response.");
+    puts  ("                      0: reject, 1: follow automatically (default), 2: ask");
 
     puts  ("");
@@ -304,4 +307,5 @@
     pjsua_transport_config_default(&cfg->rtp_cfg);
     cfg->rtp_cfg.port = 4000;
+    cfg->redir_op = PJSIP_REDIRECT_ACCEPT;
     cfg->duration = NO_LIMIT;
     cfg->wav_id = PJSUA_INVALID_ID;
@@ -473,5 +477,5 @@
 	   OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, 
 	   OPT_DURATION, OPT_NO_TCP, OPT_NO_UDP, OPT_THREAD_CNT,
-	   OPT_NOREFERSUB,
+	   OPT_NOREFERSUB, OPT_ACCEPT_REDIRECT,
 	   OPT_USE_TLS, OPT_TLS_CA_FILE, OPT_TLS_CERT_FILE, OPT_TLS_PRIV_FILE,
 	   OPT_TLS_PASSWORD, OPT_TLS_VERIFY_SERVER, OPT_TLS_VERIFY_CLIENT,
@@ -516,4 +520,5 @@
 	{ "auto-update-nat",	1, 0, OPT_AUTO_UPDATE_NAT},
         { "use-compact-form",	0, 0, OPT_USE_COMPACT_FORM},
+	{ "accept-redirect", 1, 0, OPT_ACCEPT_REDIRECT},
 	{ "no-force-lr",0, 0, OPT_NO_FORCE_LR},
 	{ "realm",	1, 0, OPT_REALM},
@@ -841,4 +846,13 @@
 	    break;
 
+	case OPT_ACCEPT_REDIRECT:
+	    cfg->redir_op = my_atoi(pj_optarg);
+	    if (cfg->redir_op<0 || cfg->redir_op>PJSIP_REDIRECT_STOP) {
+		PJ_LOG(1,(THIS_FILE, 
+			  "Error: accept-redirect value '%s' ", pj_optarg));
+		return PJ_EINVAL;
+	    }
+	    break;
+
 	case OPT_NO_FORCE_LR:
 	    cfg->cfg.force_lr = PJ_FALSE;
@@ -1786,4 +1800,11 @@
     }
 
+    /* accept-redirect */
+    if (config->redir_op != PJSIP_REDIRECT_ACCEPT) {
+	pj_ansi_sprintf(line, "--accept-redirect %d\n",
+			config->redir_op);
+	pj_strcat2(&cfg, line);
+    }
+
     /* Max calls. */
     pj_ansi_sprintf(line, "--max-calls %d\n",
@@ -1841,5 +1862,6 @@
  * as the logger can accept.
  */
-static void log_call_dump(int call_id) {
+static void log_call_dump(int call_id) 
+{
     unsigned call_dump_len;
     unsigned part_len;
@@ -2367,4 +2389,31 @@
 {
     PJ_LOG(3,(THIS_FILE, "Incoming DTMF on call %d: %c", call_id, dtmf));
+}
+
+/*
+ * Redirection handler.
+ */
+static void call_on_redirected(pjsua_call_id call_id, const pjsip_uri *target,
+			       pjsip_redirect_op *cmd, const pjsip_event *e)
+{
+    *cmd = app_config.redir_op;
+
+    PJ_UNUSED_ARG(e);
+
+    if (*cmd == PJSIP_REDIRECT_PENDING) {
+	char uristr[PJSIP_MAX_URL_SIZE];
+	int len;
+
+	len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, target, uristr, 
+			      sizeof(uristr));
+	if (len < 1) {
+	    pj_ansi_strcpy(uristr, "--URI too long--");
+	}
+
+	PJ_LOG(3,(THIS_FILE, "Call %d is being redirected to %.*s. "
+		  "Press 'Ra' to accept, 'Rr' to reject, or 'Rd' to "
+		  "disconnect.",
+		  call_id, len, uristr));
+    }
 }
 
@@ -3916,4 +3965,19 @@
 
 
+	case 'R':
+	    if (!pjsua_call_is_active(current_call)) {
+		PJ_LOG(1,(THIS_FILE, "Call %d has gone", current_call));
+	    } else if (menuin[1] == 'a') {
+		pjsua_call_process_redirect(current_call, 
+					    PJSIP_REDIRECT_ACCEPT);
+	    } else if (menuin[1] == 'r') {
+		pjsua_call_process_redirect(current_call,
+					    PJSIP_REDIRECT_REJECT);
+	    } else {
+		pjsua_call_process_redirect(current_call,
+					    PJSIP_REDIRECT_STOP);
+	    }
+	    break;
+
 	default:
 	    if (menuin[0] != '\n' && menuin[0] != '\r') {
@@ -3963,4 +4027,5 @@
     app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state;
     app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback;
+    app_config.cfg.cb.on_call_redirected = &call_on_redirected;
     app_config.cfg.cb.on_reg_state = &on_reg_state;
     app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe;
