+ /* clear the command line */
+ for (i = strlen(t_con->prompt) + t_con->line_size; i > 0; i -= 16)
+ telnet_write(connection, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i > 16 ? 16 : i);
+ for (i = strlen(t_con->prompt) + t_con->line_size; i > 0; i -= 16)
+ telnet_write(connection, " ", i > 16 ? 16 : i);
+ for (i = strlen(t_con->prompt) + t_con->line_size; i > 0; i -= 16)
+ telnet_write(connection, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i > 16 ? 16 : i);
+
+ /* output the message */
+ telnet_outputline(connection, string);
+
+ /* put the command line to its previous state */
+ telnet_prompt(connection);
+ telnet_write(connection, t_con->line, t_con->line_size);
+ for (i = t_con->line_size; i > t_con->line_cursor; i--)
+ telnet_write(connection, "\b", 1);
+}
+
+static void telnet_load_history(struct telnet_connection *t_con)
+{
+ FILE *histfp;
+ char buffer[TELNET_BUFFER_SIZE];
+ int i = 0;
+
+ char *history = get_home_dir(TELNET_HISTORY);
+
+ if (history == NULL) {
+ LOG_INFO("unable to get user home directory, telnet history will be disabled");
+ return;
+ }
+
+ histfp = fopen(history, "rb");
+
+ if (histfp) {
+
+ while (fgets(buffer, sizeof(buffer), histfp) != NULL) {
+
+ char *p = strchr(buffer, '\n');
+ if (p)
+ *p = '\0';
+ if (buffer[0] && i < TELNET_LINE_HISTORY_SIZE)
+ t_con->history[i++] = strdup(buffer);
+ }
+
+ t_con->next_history = i;
+ t_con->next_history %= TELNET_LINE_HISTORY_SIZE;
+ /* try to set to last entry - 1, that way we skip over any exit/shutdown cmds */
+ t_con->current_history = t_con->next_history > 0 ? i - 1 : 0;
+ fclose(histfp);
+ }
+
+ free(history);