Index: pjproject/trunk/pjlib-util/src/pjlib-util/cli_telnet.c
===================================================================
--- pjproject/trunk/pjlib-util/src/pjlib-util/cli_telnet.c	(revision 4537)
+++ pjproject/trunk/pjlib-util/src/pjlib-util/cli_telnet.c	(revision 4728)
@@ -37,5 +37,5 @@
     (defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0)
 
-#define EADDRINUSE WSAEADDRINUSE 
+#define EADDRINUSE WSAEADDRINUSE
 
 #endif
@@ -67,11 +67,11 @@
  * This specify the state for the telnet option negotiation.
  */
-enum cli_telnet_option_states 
-{    
+enum cli_telnet_option_states
+{
     OPT_DISABLE,		/* Option disable */
     OPT_ENABLE,			/* Option enable */
     OPT_EXPECT_DISABLE,		/* Already send disable req, expecting resp */
     OPT_EXPECT_ENABLE,		/* Already send enable req, expecting resp */
-    OPT_EXPECT_DISABLE_REV,	/* Already send disable req, expecting resp, 
+    OPT_EXPECT_DISABLE_REV,	/* Already send disable req, expecting resp,
 				 * need to send enable req */
     OPT_EXPECT_ENABLE_REV	/* Already send enable req, expecting resp,
@@ -199,5 +199,5 @@
 };
 
-enum terminal_cmd 
+enum terminal_cmd
 {
     TC_ESC		= 27,
@@ -207,5 +207,5 @@
     TC_LEFT		= 68,
     TC_END		= 70,
-    TC_HOME		= 72,    
+    TC_HOME		= 72,
     TC_CTRL_C		= 3,
     TC_CR		= 13,
@@ -229,6 +229,6 @@
 
 /**
- * This structure contains the command line shown to the user. 
- * The telnet also needs to maintain and manage command cursor position. 
+ * This structure contains the command line shown to the user.
+ * The telnet also needs to maintain and manage command cursor position.
  * Due to that reason, the insert/delete character process from buffer will
  * consider its current cursor position.
@@ -252,5 +252,5 @@
 
 /**
- * This structure contains the command history executed by user. 
+ * This structure contains the command history executed by user.
  * Besides storing the command history, it is necessary to be able
  * to browse it.
@@ -291,5 +291,5 @@
     pj_thread_t            *worker_thread;
     pj_bool_t               is_quitting;
-    pj_mutex_t             *mutex;    
+    pj_mutex_t             *mutex;
 } cli_telnet_fe;
 
@@ -305,5 +305,5 @@
 
 /**
- * Return the number of characters between the current cursor position 
+ * Return the number of characters between the current cursor position
  * to the end of line.
  */
@@ -314,12 +314,12 @@
 
 /**
- * Insert character to the receive buffer. 
- */
-static pj_bool_t recv_buf_insert(telnet_recv_buf *recv_buf, 
-				 unsigned char *data) 
-{    
+ * Insert character to the receive buffer.
+ */
+static pj_bool_t recv_buf_insert(telnet_recv_buf *recv_buf,
+				 unsigned char *data)
+{
     if (recv_buf->len+1 >= PJ_CLI_MAX_CMDBUF) {
 	return PJ_FALSE;
-    } else {	
+    } else {
 	if (*data == '\t' || *data == '?' || *data == '\r') {
 	    /* Always insert to the end of line */
@@ -328,11 +328,11 @@
 	    /* Insert based on the current cursor pos */
 	    unsigned cur_pos = recv_buf->cur_pos;
-	    unsigned rlen = recv_buf_right_len(recv_buf);	    
-	    if (rlen > 0) {		    
+	    unsigned rlen = recv_buf_right_len(recv_buf);
+	    if (rlen > 0) {
 		/* Shift right characters */
-		pj_memmove(&recv_buf->rbuf[cur_pos+1], 
-			   &recv_buf->rbuf[cur_pos], 
+		pj_memmove(&recv_buf->rbuf[cur_pos+1],
+			   &recv_buf->rbuf[cur_pos],
 			   rlen+1);
-	    } 
+	    }
 	    recv_buf->rbuf[cur_pos] = *data;
 	}
@@ -356,5 +356,5 @@
 	    unsigned cur_pos = recv_buf->cur_pos;
 	    /* Shift left characters */
-	    pj_memmove(&recv_buf->rbuf[cur_pos-1], &recv_buf->rbuf[cur_pos], 
+	    pj_memmove(&recv_buf->rbuf[cur_pos-1], &recv_buf->rbuf[cur_pos],
 		       rlen);
 	}
@@ -362,5 +362,5 @@
 	--recv_buf->len;
 	recv_buf->rbuf[recv_buf->len] = 0;
-    }    
+    }
     return PJ_TRUE;
 }
@@ -373,9 +373,9 @@
 
 /**
- * Insert the command to history. If the entered command is not on the list, 
- * a new entry will be created. All entered command will be moved to 
- * the first entry of the history. 
- */
-static pj_status_t insert_history(cli_telnet_sess *sess, 				 
+ * Insert the command to history. If the entered command is not on the list,
+ * a new entry will be created. All entered command will be moved to
+ * the first entry of the history.
+ */
+static pj_status_t insert_history(cli_telnet_sess *sess,
 				  char *cmd_val)
 {
@@ -393,9 +393,9 @@
     in_history = pj_list_search(sess->history, (void*)&cmd, compare_str);
     if (!in_history) {
-	if (pj_list_size(sess->history) < PJ_CLI_MAX_CMD_HISTORY) {	    
+	if (pj_list_size(sess->history) < PJ_CLI_MAX_CMD_HISTORY) {
 	    char *data_history;
 	    in_history = PJ_POOL_ZALLOC_T(sess->pool, cmd_history);
 	    pj_list_init(in_history);
-	    data_history = (char *)pj_pool_calloc(sess->pool, 
+	    data_history = (char *)pj_pool_calloc(sess->pool,
 			   sizeof(char), PJ_CLI_MAX_CMDBUF);
 	    in_history->command.ptr = data_history;
@@ -404,5 +404,5 @@
 	    /* Get the oldest history */
 	    in_history = sess->history->prev;
-	}	    
+	}
     } else {
 	pj_list_insert_nodes_after(in_history->prev, in_history->next);
@@ -416,5 +416,5 @@
 
 /**
- * Get the next or previous history of the shown/active history. 
+ * Get the next or previous history of the shown/active history.
  */
 static pj_str_t* get_prev_history(cli_telnet_sess *sess, pj_bool_t is_forward)
@@ -434,8 +434,8 @@
 	return NULL;
     } else {
-	if (is_forward) {	    
-	    node = (node->next==root)?node->next->next:node->next;	    
+	if (is_forward) {
+	    node = (node->next==root)?node->next->next:node->next;
 	} else {
-	    node = (node->prev==root)?node->prev->prev:node->prev;	    
+	    node = (node->prev==root)?node->prev->prev:node->prev;
 	}
 	retval = &node->command;
@@ -451,8 +451,8 @@
  * referenced - (RFC-854).
  */
-static pj_bool_t send_telnet_cmd(cli_telnet_sess *sess, 
-				 cli_telnet_command cmd, 
+static pj_bool_t send_telnet_cmd(cli_telnet_sess *sess,
+				 cli_telnet_command cmd,
 				 unsigned char option)
-{       
+{
     unsigned char buf[3];
     PJ_ASSERT_RETURN(sess, PJ_FALSE);
@@ -470,9 +470,9 @@
  * For local option: send WILL.
  * For remote option: send DO.
- * This method also handle the state transition of the ENABLE 
+ * This method also handle the state transition of the ENABLE
  * negotiation process.
  */
-static pj_bool_t send_enable_option(cli_telnet_sess *sess, 
-				    pj_bool_t is_local, 
+static pj_bool_t send_enable_option(cli_telnet_sess *sess,
+				    pj_bool_t is_local,
 				    unsigned char option)
 {
@@ -500,5 +500,5 @@
 	    *state = OPT_EXPECT_ENABLE;
 	    break;
-	case OPT_EXPECT_DISABLE_REV:	    
+	case OPT_EXPECT_DISABLE_REV:
 	    *state = OPT_DISABLE;
 	    break;
@@ -509,5 +509,5 @@
 }
 
-static pj_bool_t send_cmd_do(cli_telnet_sess *sess, 
+static pj_bool_t send_cmd_do(cli_telnet_sess *sess,
 			     unsigned char option)
 {
@@ -515,5 +515,5 @@
 }
 
-static pj_bool_t send_cmd_will(cli_telnet_sess *sess, 
+static pj_bool_t send_cmd_will(cli_telnet_sess *sess,
 			       unsigned char option)
 {
@@ -523,9 +523,9 @@
 /**
  * This method will handle receiving telnet's ENABLE option negotiation.
- * This method also handle the state transition of the ENABLE 
- * negotiation process. 
- */
-static pj_bool_t receive_enable_option(cli_telnet_sess *sess, 
-				       pj_bool_t is_local, 
+ * This method also handle the state transition of the ENABLE
+ * negotiation process.
+ */
+static pj_bool_t receive_enable_option(cli_telnet_sess *sess,
+				       pj_bool_t is_local,
 				       unsigned char option)
 {
@@ -550,13 +550,13 @@
 	    }
 	    break;
-	case OPT_EXPECT_ENABLE:	    
+	case OPT_EXPECT_ENABLE:
 	    *state = OPT_ENABLE;
 	    break;
-	case OPT_EXPECT_DISABLE:	    
+	case OPT_EXPECT_DISABLE:
 	    *state = OPT_DISABLE;
 	    break;
 	case OPT_EXPECT_ENABLE_REV:
 	    *state = OPT_EXPECT_DISABLE;
-	    send_telnet_cmd(sess, is_local?WONT:DONT, option);	    
+	    send_telnet_cmd(sess, is_local?WONT:DONT, option);
 	    break;
 	case OPT_EXPECT_DISABLE_REV:
@@ -566,14 +566,14 @@
 	    return PJ_FALSE;
     }
-    return PJ_TRUE;        
+    return PJ_TRUE;
 }
 
 /**
  * This method will handle receiving telnet's DISABLE option negotiation.
- * This method also handle the state transition of the DISABLE 
- * negotiation process. 
- */
-static pj_bool_t receive_disable_option(cli_telnet_sess *sess, 
-					pj_bool_t is_local, 
+ * This method also handle the state transition of the DISABLE
+ * negotiation process.
+ */
+static pj_bool_t receive_disable_option(cli_telnet_sess *sess,
+					pj_bool_t is_local,
 					unsigned char option)
 {
@@ -585,5 +585,5 @@
     sess_opt = &sess->telnet_option[option];
     state = is_local?(&sess_opt->local_state):(&sess_opt->peer_state);
-    
+
     switch (*state) {
 	case OPT_ENABLE:
@@ -595,5 +595,5 @@
 	    /* Ignore if already enabled */
 	    break;
-	case OPT_EXPECT_ENABLE:	    
+	case OPT_EXPECT_ENABLE:
 	case OPT_EXPECT_DISABLE:
 	    *state = OPT_DISABLE;
@@ -601,5 +601,5 @@
 	case OPT_EXPECT_ENABLE_REV:
 	    *state = OPT_DISABLE;
-	    send_telnet_cmd(sess, is_local?WONT:DONT, option);	    
+	    send_telnet_cmd(sess, is_local?WONT:DONT, option);
 	    break;
 	case OPT_EXPECT_DISABLE_REV:
@@ -610,5 +610,5 @@
 	    return PJ_FALSE;
     }
-    return PJ_TRUE;       
+    return PJ_TRUE;
 }
 
@@ -633,26 +633,26 @@
 }
 
-static void set_local_option(cli_telnet_sess *sess, 
-			     unsigned char option, 
-			     pj_bool_t enable) 
+static void set_local_option(cli_telnet_sess *sess,
+			     unsigned char option,
+			     pj_bool_t enable)
 {
     sess->telnet_option[option].local_is_enable = enable;
 }
 
-static void set_peer_option(cli_telnet_sess *sess, 
-			    unsigned char option, 
-			    pj_bool_t enable) 
+static void set_peer_option(cli_telnet_sess *sess,
+			    unsigned char option,
+			    pj_bool_t enable)
 {
     sess->telnet_option[option].peer_is_enable = enable;
 }
 
-static pj_bool_t is_local_option_state_ena(cli_telnet_sess *sess, 
+static pj_bool_t is_local_option_state_ena(cli_telnet_sess *sess,
 					   unsigned char option)
-{    
+{
     return (sess->telnet_option[option].local_state == OPT_ENABLE);
 }
 
-static void send_return_key(cli_telnet_sess *sess) 
-{    
+static void send_return_key(cli_telnet_sess *sess)
+{
     telnet_sess_send2(sess, (unsigned char*)"\r\n", 2);
 }
@@ -671,5 +671,5 @@
     send_data.ptr = data_str;
     send_data.slen = 0;
-    
+
     pj_strcat(&send_data, &fe->cfg.prompt_str);
 
@@ -681,6 +681,6 @@
  * the error position of the source command.
  */
-static void send_err_arg(cli_telnet_sess *sess, 
-			 const pj_cli_exec_info *info, 
+static void send_err_arg(cli_telnet_sess *sess,
+			 const pj_cli_exec_info *info,
 			 const pj_str_t *msg,
 			 pj_bool_t with_return,
@@ -715,5 +715,5 @@
 }
 
-static void send_inv_arg(cli_telnet_sess *sess, 
+static void send_inv_arg(cli_telnet_sess *sess,
 			 const pj_cli_exec_info *info,
 			 pj_bool_t with_return,
@@ -724,5 +724,5 @@
 }
 
-static void send_too_many_arg(cli_telnet_sess *sess, 
+static void send_too_many_arg(cli_telnet_sess *sess,
 			      const pj_cli_exec_info *info,
 			      pj_bool_t with_return,
@@ -733,6 +733,6 @@
 }
 
-static void send_hint_arg(cli_telnet_sess *sess, 
-			  pj_str_t *send_data, 
+static void send_hint_arg(cli_telnet_sess *sess,
+			  pj_str_t *send_data,
 			  const pj_str_t *desc,
 			  pj_ssize_t cmd_len,
@@ -756,5 +756,5 @@
  * is ambiguous. It will show the matching command as the hint information.
  */
-static void send_ambi_arg(cli_telnet_sess *sess, 
+static void send_ambi_arg(cli_telnet_sess *sess,
 			  const pj_cli_exec_info *info,
 			  pj_bool_t with_return,
@@ -770,10 +770,9 @@
     pj_ssize_t max_length = 0;
     pj_ssize_t cmd_length = 0;
-    const pj_str_t *cmd_desc = 0;
     static const pj_str_t sc_type = {"sc", 2};
     static const pj_str_t choice_type = {"choice", 6};
     send_data.ptr = data;
     send_data.slen = 0;
-    
+
     if (with_return)
 	pj_strcat2(&send_data, "\r\n");
@@ -787,15 +786,15 @@
     /* Get the max length of the command name */
     for (i=0;i<info->hint_cnt;++i) {
-	if ((&hint[i].type) && (hint[i].type.slen > 0)) {	    
-	    if (pj_stricmp(&hint[i].type, &sc_type) == 0) {		
+	if ((&hint[i].type) && (hint[i].type.slen > 0)) {
+	    if (pj_stricmp(&hint[i].type, &sc_type) == 0) {
 		if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) {
 		    cmd_length += (hint[i].name.slen + 3);
 		} else {
 		    cmd_length = hint[i].name.slen;
-		}		
+		}
 	    } else {
 		cmd_length = hint[i].name.slen;
 	    }
-	} else {	    	    
+	} else {
 	    cmd_length = hint[i].name.slen;
 	}
@@ -805,9 +804,9 @@
 	}
     }
-    
+
     cmd_length = 0;
     /* Build hint information */
-    for (i=0;i<info->hint_cnt;++i) {			
-	if ((&hint[i].type) && (hint[i].type.slen > 0)) {	    
+    for (i=0;i<info->hint_cnt;++i) {
+	if ((&hint[i].type) && (hint[i].type.slen > 0)) {
 	    if (pj_stricmp(&hint[i].type, &sc_type) == 0) {
 		parse_state = OP_SHORTCUT;
@@ -817,19 +816,19 @@
 		parse_state = OP_TYPE;
 	    }
-	} else {	    	    
+	} else {
 	    parse_state = OP_NORMAL;
 	}
-	
+
 	if (parse_state != OP_SHORTCUT) {
 	    pj_strcat2(&send_data, "\r\n  ");
 	    cmd_length = hint[i].name.slen;
-	}	    
-	
+	}
+
 	switch (parse_state) {
 	case OP_CHOICE:
-	    /* Format : "[Choice Value]  description" */	    
+	    /* Format : "[Choice Value]  description" */
 	    pj_strcat2(&send_data, "[");
 	    pj_strcat(&send_data, &hint[i].name);
-	    pj_strcat2(&send_data, "]");	
+	    pj_strcat2(&send_data, "]");
 	    break;
 	case OP_TYPE:
@@ -837,17 +836,17 @@
 	    pj_strcat2(&send_data, "<");
 	    pj_strcat(&send_data, &hint[i].name);
-	    pj_strcat2(&send_data, ">");	
+	    pj_strcat2(&send_data, ">");
 	    break;
 	case OP_SHORTCUT:
 	    /* Format : "Command | sc |  description" */
-	    {		
+	    {
 		cmd_length += hint[i].name.slen;
 		if ((i > 0) && (!pj_stricmp(&hint[i-1].desc, &hint[i].desc))) {
 		    pj_strcat2(&send_data, " | ");
-		    cmd_length += 3;		    
+		    cmd_length += 3;
 		} else {
 		    pj_strcat2(&send_data, "\r\n  ");
 		}
-		pj_strcat(&send_data, &hint[i].name);	
+		pj_strcat(&send_data, &hint[i].name);
 	    }
 	    break;
@@ -855,26 +854,25 @@
 	    /* Command */
 	    pj_strcat(&send_data, &hint[i].name);
-	    cmd_desc = &hint[i].desc;	    
-	    break;
-	}
-    	
-	if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) || 
+	    break;
+	}
+
+	if ((parse_state == OP_TYPE) || (parse_state == OP_CHOICE) ||
 	    ((i+1) >= info->hint_cnt) ||
-	    (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen))) 
+	    (pj_strncmp(&hint[i].desc, &hint[i+1].desc, hint[i].desc.slen)))
 	{
 	    /* Add description info */
-	    send_hint_arg(sess, &send_data, 
-			  &hint[i].desc, cmd_length, 
+	    send_hint_arg(sess, &send_data,
+			  &hint[i].desc, cmd_length,
 			  max_length);
 
 	    cmd_length = 0;
-	}	
-    }  
-    pj_strcat2(&send_data, "\r\n");       
+	}
+    }
+    pj_strcat2(&send_data, "\r\n");
     pj_strcat(&send_data, &fe->cfg.prompt_str);
     if (with_last_cmd)
 	pj_strcat2(&send_data, (char *)sess->rcmd->rbuf);
 
-    telnet_sess_send(sess, &send_data);    
+    telnet_sess_send(sess, &send_data);
 }
 
@@ -882,5 +880,5 @@
  * This method is to send command completion of the entered command.
  */
-static void send_comp_arg(cli_telnet_sess *sess, 
+static void send_comp_arg(cli_telnet_sess *sess,
 			  pj_cli_exec_info *info)
 {
@@ -893,5 +891,5 @@
     send_data.slen = 0;
 
-    pj_strcat(&send_data, &info->hint[0].name);        
+    pj_strcat(&send_data, &info->hint[0].name);
 
     telnet_sess_send(sess, &send_data);
@@ -902,8 +900,8 @@
  */
 static pj_bool_t handle_alfa_num(cli_telnet_sess *sess, unsigned char *data)
-{        
+{
     if (is_local_option_state_ena(sess, TERM_ECHO)) {
 	if (recv_buf_right_len(sess->rcmd) > 0) {
-	    /* Cursor is not at EOL, insert character */	    
+	    /* Cursor is not at EOL, insert character */
 	    unsigned char echo[5] = {0x1b, 0x5b, 0x31, 0x40, 0x00};
 	    echo[4] = *data;
@@ -914,5 +912,5 @@
 	}
 	return PJ_TRUE;
-    } 
+    }
     return PJ_FALSE;
 }
@@ -926,6 +924,6 @@
     if (recv_buf_backspace(sess->rcmd)) {
 	if (rlen) {
-	    /* 
-	     * Cursor is not at the end of line, move the characters 
+	    /*
+	     * Cursor is not at the end of line, move the characters
 	     * after the cursor to left
 	     */
@@ -934,5 +932,5 @@
 	    telnet_sess_send2(sess, echo, 5);
 	} else {
-	    const static unsigned char echo[3] = {0x08, 0x20, 0x08};	    
+	    const static unsigned char echo[3] = {0x08, 0x20, 0x08};
 	    telnet_sess_send2(sess, echo, 3);
 	}
@@ -942,6 +940,6 @@
 }
 
-/* 
- * Syntax error handler for parser. 
+/*
+ * Syntax error handler for parser.
  */
 static void on_syntax_error(pj_scanner *scanner)
@@ -958,5 +956,5 @@
     pj_scanner scanner;
     PJ_USE_EXCEPTION;
-    pj_scan_init(&scanner, cmd->ptr, cmd->slen, PJ_SCAN_AUTOSKIP_WS, 
+    pj_scan_init(&scanner, cmd->ptr, cmd->slen, PJ_SCAN_AUTOSKIP_WS,
 		 &on_syntax_error);
     PJ_TRY {
@@ -966,5 +964,5 @@
     }
     PJ_CATCH_ANY {
-	pj_scan_fini(&scanner);	
+	pj_scan_fini(&scanner);
 	return PJ_GET_EXCEPTION();
     }
@@ -981,5 +979,5 @@
     pj_bool_t retval = PJ_TRUE;
     unsigned len;
-    
+
     pj_pool_t *pool;
     pj_cli_cmd_val *cmd_val;
@@ -990,7 +988,7 @@
 
     cmd_val = PJ_POOL_ZALLOC_T(pool, pj_cli_cmd_val);
-    
-    status = pj_cli_sess_parse(&sess->base, (char *)&sess->rcmd->rbuf, cmd_val, 
-			       pool, &info);    
+
+    status = pj_cli_sess_parse(&sess->base, (char *)&sess->rcmd->rbuf, cmd_val,
+			       pool, &info);
 
     len = (unsigned)pj_ansi_strlen((char *)sess->rcmd->rbuf);
@@ -998,5 +996,5 @@
     switch (status) {
     case PJ_CLI_EINVARG:
-	send_inv_arg(sess, &info, PJ_TRUE, PJ_TRUE);		
+	send_inv_arg(sess, &info, PJ_TRUE, PJ_TRUE);
 	break;
     case PJ_CLI_ETOOMANYARGS:
@@ -1015,5 +1013,5 @@
 	    telnet_sess_send2(sess, data_sent, rlen);
 	}
-	if (info.hint_cnt > 0) {	
+	if (info.hint_cnt > 0) {
 	    /* Complete command */
 	    pj_str_t cmd = pj_str((char *)sess->rcmd->rbuf);
@@ -1026,15 +1024,15 @@
 		if (hint_info->slen >= last_token.slen) {
 		    hint_info->slen -= last_token.slen;
-		    pj_memmove(hint_info->ptr, 
-			       &hint_info->ptr[last_token.slen], 
-			       hint_info->slen);		    
-		} 
+		    pj_memmove(hint_info->ptr,
+			       &hint_info->ptr[last_token.slen],
+			       hint_info->slen);
+		}
 		send_comp_arg(sess, &info);
 
-		pj_memcpy(&sess->rcmd->rbuf[len], info.hint[0].name.ptr, 
+		pj_memcpy(&sess->rcmd->rbuf[len], info.hint[0].name.ptr,
 			  info.hint[0].name.slen);
 
 		len += (unsigned)info.hint[0].name.slen;
-		sess->rcmd->rbuf[len] = 0;		    
+		sess->rcmd->rbuf[len] = 0;
 	    }
 	} else {
@@ -1046,6 +1044,6 @@
     sess->rcmd->cur_pos = sess->rcmd->len;
 
-    pj_pool_release(pool);	
-    return retval; 
+    pj_pool_release(pool);
+    return retval;
 }
 
@@ -1057,8 +1055,8 @@
     pj_status_t status;
     pj_bool_t retval = PJ_TRUE;
-    
-    pj_pool_t *pool;    
-    pj_cli_exec_info info;    
-    
+
+    pj_pool_t *pool;
+    pj_cli_exec_info info;
+
     send_return_key(sess);
     insert_history(sess, (char *)&sess->rcmd->rbuf);
@@ -1066,12 +1064,12 @@
     pool = pj_pool_create(sess->pool->factory, "handle_return",
 			  PJ_CLI_TELNET_POOL_SIZE, PJ_CLI_TELNET_POOL_INC,
-			  NULL);    
-    
-    status = pj_cli_sess_exec(&sess->base, (char *)&sess->rcmd->rbuf, 
+			  NULL);
+
+    status = pj_cli_sess_exec(&sess->base, (char *)&sess->rcmd->rbuf,
 			      pool, &info);
 
     switch (status) {
     case PJ_CLI_EINVARG:
-	send_inv_arg(sess, &info, PJ_FALSE, PJ_FALSE);	
+	send_inv_arg(sess, &info, PJ_FALSE, PJ_FALSE);
 	break;
     case PJ_CLI_ETOOMANYARGS:
@@ -1088,5 +1086,5 @@
 	send_prompt_str(sess);
 	break;
-    }    
+    }
     if (retval) {
 	sess->rcmd->rbuf[0] = 0;
@@ -1095,6 +1093,6 @@
     }
 
-    pj_pool_release(pool);	
-    return retval; 
+    pj_pool_release(pool);
+    return retval;
 }
 
@@ -1106,5 +1104,5 @@
     if (recv_buf_right_len(sess->rcmd)) {
 	unsigned char *data = &sess->rcmd->rbuf[sess->rcmd->cur_pos++];
-	telnet_sess_send2(sess, data, 1);		
+	telnet_sess_send2(sess, data, 1);
 	return PJ_TRUE;
     }
@@ -1116,5 +1114,5 @@
  */
 static pj_bool_t handle_left_key(cli_telnet_sess *sess)
-{    
+{
     static const unsigned char move_cursor_left = 0x08;
     if (sess->rcmd->cur_pos) {
@@ -1151,5 +1149,5 @@
 	    send_data.slen = sess->rcmd->cur_pos;
 	}
-	
+
 	if (sess->rcmd->len > (unsigned)history->slen) {
 	    /* Clear the command currently shown*/
@@ -1159,8 +1157,8 @@
 
 	    /* Move cursor position to the beginning of line */
-	    pj_memset(&send_data.ptr[send_data.slen], MOVE_CURSOR_LEFT, 
+	    pj_memset(&send_data.ptr[send_data.slen], MOVE_CURSOR_LEFT,
 		      buf_len);
 	    send_data.slen += buf_len;
-	} 
+	}
 	/* Send data */
 	pj_strcat(&send_data, history);
@@ -1175,7 +1173,7 @@
 }
 
-static pj_status_t process_vt100_cmd(cli_telnet_sess *sess, 
+static pj_status_t process_vt100_cmd(cli_telnet_sess *sess,
 				     unsigned char *cmd)
-{    
+{
     pj_status_t status = PJ_TRUE;
     switch (*cmd) {
@@ -1225,6 +1223,6 @@
 }
 
-/* 
- * Send a message to a telnet session 
+/*
+ * Send a message to a telnet session
  */
 static pj_status_t telnet_sess_send(cli_telnet_sess *sess,
@@ -1241,10 +1239,10 @@
 
     if (sess->buf_len == 0)
-        status = pj_activesock_send(sess->asock, &sess->op_key, 
+        status = pj_activesock_send(sess->asock, &sess->op_key,
                                     str->ptr, &sz, 0);
-    /* If we cannot send now, append it at the end of the buffer 
+    /* If we cannot send now, append it at the end of the buffer
      * to be sent later.
      */
-    if (sess->buf_len > 0 || 
+    if (sess->buf_len > 0 ||
         (status != PJ_SUCCESS && status != PJ_EPENDING))
     {
@@ -1273,6 +1271,6 @@
 }
 
-/* 
- * Send a message to a telnet session with formatted text 
+/*
+ * Send a message to a telnet session with formatted text
  * (add single linefeed character with carriage return)
  */
@@ -1288,18 +1286,18 @@
     PJ_USE_EXCEPTION;
 
-    pj_scan_init(&scanner, str->ptr, str->slen, 
+    pj_scan_init(&scanner, str->ptr, str->slen,
 	         PJ_SCAN_AUTOSKIP_WS, &on_syntax_error);
-    
+
     str_begin = scanner.begin;
 
     PJ_TRY {
-	while (!pj_scan_is_eof(&scanner)) {	    	    
-	    pj_scan_get_until_ch(&scanner, '\n', &out_str);	    
+	while (!pj_scan_is_eof(&scanner)) {
+	    pj_scan_get_until_ch(&scanner, '\n', &out_str);
 	    str_len = (int)(scanner.curptr - str_begin);
-	    if (*scanner.curptr == '\n') {		
-		if ((str_len > 1) && (out_str.ptr[str_len-2] == '\r')) 
-		{	    		    
+	    if (*scanner.curptr == '\n') {
+		if ((str_len > 1) && (out_str.ptr[str_len-2] == '\r'))
+		{
 		    continue;
-		} else {		    
+		} else {
 		    int str_pos = (int)(str_begin - scanner.begin);
 
@@ -1314,5 +1312,5 @@
 			pj_scan_advance_n(&scanner, 1, PJ_TRUE);
 			str_begin = scanner.curptr;
-		    }		    
+		    }
 		}
 	    } else {
@@ -1355,5 +1353,5 @@
     pj_mutex_unlock(tsess->smutex);
     pj_activesock_close(tsess->asock);
-    pj_mutex_destroy(tsess->smutex);    
+    pj_mutex_destroy(tsess->smutex);
     pj_pool_release(tsess->pool);
 }
@@ -1363,5 +1361,5 @@
 {
     cli_telnet_fe *tfe = (cli_telnet_fe *)fe;
-    pj_cli_sess *sess;    
+    pj_cli_sess *sess;
 
     pj_mutex_lock(tfe->mutex);
@@ -1371,5 +1369,5 @@
         cli_telnet_sess *tsess = (cli_telnet_sess *)sess;
 
-        sess = sess->next;        
+        sess = sess->next;
 	if (tsess->base.log_level > level) {
 	    pj_str_t s;
@@ -1379,5 +1377,5 @@
 	}
     }
-    
+
     pj_mutex_unlock(tfe->mutex);
 }
@@ -1436,5 +1434,5 @@
 			    pj_activesock_get_user_data(asock);
 
-    PJ_UNUSED_ARG(op_key);    
+    PJ_UNUSED_ARG(op_key);
 
     if (sent <= 0) {
@@ -1471,5 +1469,5 @@
                             pj_activesock_get_user_data(asock);
     cli_telnet_fe *tfe = (cli_telnet_fe *)sess->base.fe;
-    unsigned char *cdata = (unsigned char*)data;    
+    unsigned char *cdata = (unsigned char*)data;
     pj_status_t is_valid = PJ_TRUE;
 
@@ -1483,5 +1481,5 @@
 	TRACE_((THIS_FILE, "Error on data read %d", status));
         return PJ_FALSE;
-    }    
+    }
 
     pj_mutex_lock(sess->smutex);
@@ -1490,10 +1488,10 @@
 	case ST_CR:
 	    sess->parse_state = ST_NORMAL;
-	    if (*cdata == 0 || *cdata == '\n')				
+	    if (*cdata == 0 || *cdata == '\n')
 		pj_mutex_unlock(sess->smutex);
 		is_valid = handle_return(sess);
-		if (!is_valid)		    
+		if (!is_valid)
 		    return PJ_FALSE;
-		pj_mutex_lock(sess->smutex);	
+		pj_mutex_lock(sess->smutex);
 		break;
 	case ST_NORMAL:
@@ -1502,7 +1500,7 @@
 	    } else if (*cdata == 127) {
 		is_valid = handle_backspace(sess, cdata);
-	    } else if (*cdata == 27) {		    
+	    } else if (*cdata == 27) {
 		sess->parse_state = ST_ESC;
-	    } else { 
+	    } else {
 		if (recv_buf_insert(sess->rcmd, cdata)) {
 		    if (*cdata == '\r') {
@@ -1519,5 +1517,5 @@
 	    break;
 	case ST_ESC:
-	    if (*cdata == 91) {		
+	    if (*cdata == 91) {
 		sess->parse_state = ST_VT100;
 	    } else {
@@ -1598,9 +1596,9 @@
     if (status != PJ_SUCCESS && status != PJ_EPENDING) {
 	TRACE_((THIS_FILE, "Error on data accept %d", status));
-	if (status == PJ_ESOCKETSTOP) 
-	    telnet_restart(fe);	    
-	
+	if (status == PJ_ESOCKETSTOP)
+	    telnet_restart(fe);
+
         return PJ_FALSE;
-    }    
+    }
 
     /* An incoming connection is accepted, create a new session */
@@ -1609,5 +1607,5 @@
                           NULL);
     if (!pool) {
-        TRACE_((THIS_FILE, 
+        TRACE_((THIS_FILE,
                 "Not enough memory to create a new telnet session"));
         return PJ_TRUE;
@@ -1632,5 +1630,5 @@
     if (sstatus != PJ_SUCCESS)
         goto on_exit;
-    
+
     sstatus = pj_activesock_create(pool, newsock, pj_SOCK_STREAM(),
                                    NULL, fe->cfg.ioqueue,
@@ -1657,5 +1655,5 @@
     send_cmd_do(sess, SUPPRESS_GA);
     send_cmd_will(sess, TERM_ECHO);
-    send_cmd_will(sess, STATUS);   
+    send_cmd_will(sess, STATUS);
     send_cmd_will(sess, SUPPRESS_GA);
 
@@ -1682,5 +1680,5 @@
     else
         pj_sock_close(newsock);
-    
+
     if (sess->smutex)
         pj_mutex_destroy(sess->smutex);
@@ -1697,5 +1695,5 @@
     cli_telnet_fe *fe;
     pj_pool_t *pool;
-    pj_status_t status;   
+    pj_status_t status;
 
     PJ_ASSERT_RETURN(cli, PJ_EINVAL);
@@ -1707,5 +1705,5 @@
     if (!fe)
         return PJ_ENOMEM;
-	
+
     fe->base.op = PJ_POOL_ZALLOC_T(pool, struct pj_cli_front_end_op);
 
@@ -1714,5 +1712,5 @@
     else
         pj_memcpy(&fe->cfg, param, sizeof(*param));
-	
+
     pj_list_init(&fe->sess_head);
     fe->base.cli = cli;
@@ -1722,5 +1720,5 @@
     fe->pool = pool;
 
-    if (!fe->cfg.ioqueue) {	
+    if (!fe->cfg.ioqueue) {
         /* Create own ioqueue if application doesn't supply one */
         status = pj_ioqueue_create(pool, 8, &fe->cfg.ioqueue);
@@ -1762,5 +1760,5 @@
     pj_activesock_cb asock_cb;
     pj_sockaddr_in addr;
-    pj_status_t status;   
+    pj_status_t status;
     int val;
     int restart_retry;
@@ -1794,18 +1792,18 @@
 	PJ_LOG(4,(THIS_FILE, "Address is still in use, retrying.."));
 	pj_thread_sleep(msec);
-    }    
-    
-    if (status == PJ_SUCCESS) {	
-	int addr_len = sizeof(addr);	
+    }
+
+    if (status == PJ_SUCCESS) {
+	int addr_len = sizeof(addr);
 
 	status = pj_sock_getsockname(sock, &addr, &addr_len);
 	if (status != PJ_SUCCESS)
 	    goto on_exit;
-	    
-        fe->cfg.port = pj_sockaddr_in_get_port(&addr);	
+
+        fe->cfg.port = pj_sockaddr_in_get_port(&addr);
 
 	if (fe->cfg.prompt_str.slen == 0) {
 	    pj_str_t prompt_sign = {"> ", 2};
-	    char *prompt_data = pj_pool_alloc(fe->pool, 
+	    char *prompt_data = pj_pool_alloc(fe->pool,
 					      pj_gethostname()->slen+2);
 	    fe->cfg.prompt_str.ptr = prompt_data;
@@ -1813,5 +1811,5 @@
 	    pj_strcpy(&fe->cfg.prompt_str, pj_gethostname());
 	    pj_strcat(&fe->cfg.prompt_str, &prompt_sign);
-	}	
+	}
     } else {
         PJ_LOG(3, (THIS_FILE, "Failed binding the socket"));
@@ -1869,8 +1867,8 @@
 {
     pj_status_t status;
-    pj_cli_sess *sess;      
+    pj_cli_sess *sess;
 
     fe->is_quitting = PJ_TRUE;
-    if (fe->worker_thread) {	
+    if (fe->worker_thread) {
 	pj_thread_join(fe->worker_thread);
     }
@@ -1911,12 +1909,12 @@
 }
 
-PJ_DEF(pj_status_t) pj_cli_telnet_get_info(pj_cli_front_end *fe, 
+PJ_DEF(pj_status_t) pj_cli_telnet_get_info(pj_cli_front_end *fe,
 					   pj_cli_telnet_info *info)
 {
     pj_sockaddr hostip;
     pj_status_t status;
-    cli_telnet_fe *tfe = (cli_telnet_fe*) fe; 
-
-    PJ_ASSERT_RETURN(fe && (fe->type == PJ_CLI_TELNET_FRONT_END) && info, 
+    cli_telnet_fe *tfe = (cli_telnet_fe*) fe;
+
+    PJ_ASSERT_RETURN(fe && (fe->type == PJ_CLI_TELNET_FRONT_END) && info,
 		     PJ_EINVAL);
 
