Beispiel #1
0
static void telnet_log_callback(void *priv, const char *file, unsigned line,
	const char *function, const char *string)
{
	struct connection *connection = priv;
	struct telnet_connection *t_con = connection->priv;
	int i;

	/* if there is no prompt, simply output the message */
	if (t_con->line_cursor < 0) {
		telnet_outputline(connection, string);
		return;
	}

	/* 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_log_callback(void *priv, const char *file, unsigned line,
	const char *function, const char *string)
{
	struct connection *connection = priv;
	struct telnet_connection *t_con = connection->priv;
	size_t i;
	size_t tmp;

	/* If the prompt is not visible, simply output the message. */
	if (!t_con->prompt_visible) {
		telnet_outputline(connection, string);
		return;
	}

	/* Clear the command line. */
	tmp = strlen(t_con->prompt) + t_con->line_size;

	for (i = 0; i < tmp; i += 16)
		telnet_write(connection, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",
			MIN(tmp - i, 16));

	for (i = 0; i < tmp; i += 16)
		telnet_write(connection, "                ", MIN(tmp - i, 16));

	for (i = 0; i < tmp; i += 16)
		telnet_write(connection, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",
			MIN(tmp - i, 16));

	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_cursor; i < t_con->line_size; i++)
		telnet_write(connection, "\b", 1);
}
Beispiel #3
0
static int telnet_output(struct command_context *cmd_ctx, const char *line)
{
	struct connection *connection = cmd_ctx->output_handler_priv;

	return telnet_outputline(connection, line);
}