Fix prompt() handling of backspace/enter. Format name based on username and hostname. Add port parameter (not yet used). Determine parameter indices based on enum.
This commit is contained in:
parent
cf8ec8dbc2
commit
6d33be152c
@ -56,11 +56,20 @@
|
|||||||
/* Client plugin arguments */
|
/* Client plugin arguments */
|
||||||
const char* GUAC_CLIENT_ARGS[] = {
|
const char* GUAC_CLIENT_ARGS[] = {
|
||||||
"hostname",
|
"hostname",
|
||||||
|
"port",
|
||||||
"username",
|
"username",
|
||||||
"password",
|
"password",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum __SSH_ARGS_IDX {
|
||||||
|
IDX_HOSTNAME,
|
||||||
|
IDX_PORT,
|
||||||
|
IDX_USERNAME,
|
||||||
|
IDX_PASSWORD,
|
||||||
|
SSH_ARGS_COUNT
|
||||||
|
};
|
||||||
|
|
||||||
int guac_client_init(guac_client* client, int argc, char** argv) {
|
int guac_client_init(guac_client* client, int argc, char** argv) {
|
||||||
|
|
||||||
guac_socket* socket = client->socket;
|
guac_socket* socket = client->socket;
|
||||||
@ -77,15 +86,15 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
|||||||
client_data->clipboard_data = NULL;
|
client_data->clipboard_data = NULL;
|
||||||
client_data->term_channel = NULL;
|
client_data->term_channel = NULL;
|
||||||
|
|
||||||
if (argc != 3) {
|
if (argc != SSH_ARGS_COUNT) {
|
||||||
guac_client_log_error(client, "Wrong number of arguments");
|
guac_client_log_error(client, "Wrong number of arguments");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read parameters */
|
/* Read parameters */
|
||||||
strcpy(client_data->hostname, argv[0]);
|
strcpy(client_data->hostname, argv[IDX_HOSTNAME]);
|
||||||
strcpy(client_data->username, argv[1]);
|
strcpy(client_data->username, argv[IDX_USERNAME]);
|
||||||
strcpy(client_data->password, argv[2]);
|
strcpy(client_data->password, argv[IDX_PASSWORD]);
|
||||||
|
|
||||||
/* Set up I-bar pointer */
|
/* Set up I-bar pointer */
|
||||||
client_data->ibar_cursor = guac_ssh_create_ibar(client);
|
client_data->ibar_cursor = guac_ssh_create_ibar(client);
|
||||||
@ -93,8 +102,8 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
|
|||||||
/* Set up blank pointer */
|
/* Set up blank pointer */
|
||||||
client_data->blank_cursor = guac_ssh_create_blank(client);
|
client_data->blank_cursor = guac_ssh_create_blank(client);
|
||||||
|
|
||||||
/* Send name and dimensions */
|
/* Send initial name */
|
||||||
guac_protocol_send_name(socket, "Terminal");
|
guac_protocol_send_name(socket, client_data->hostname);
|
||||||
|
|
||||||
/* Initialize pointer */
|
/* Initialize pointer */
|
||||||
client_data->current_cursor = client_data->blank_cursor;
|
client_data->current_cursor = client_data->blank_cursor;
|
||||||
|
@ -74,7 +74,7 @@ static char* prompt(guac_client* client, const char* title, char* str, int size,
|
|||||||
while (pos < size && read(stdin_fd, &in_byte, 1) == 1) {
|
while (pos < size && read(stdin_fd, &in_byte, 1) == 1) {
|
||||||
|
|
||||||
/* Backspace */
|
/* Backspace */
|
||||||
if (in_byte == 0x08) {
|
if (in_byte == 0x7F) {
|
||||||
|
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
guac_terminal_write_all(stdout_fd, "\b \b", 3);
|
guac_terminal_write_all(stdout_fd, "\b \b", 3);
|
||||||
@ -82,8 +82,8 @@ static char* prompt(guac_client* client, const char* title, char* str, int size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Newline (end of input */
|
/* CR (end of input */
|
||||||
else if (in_byte == 0x0A) {
|
else if (in_byte == 0x0D) {
|
||||||
guac_terminal_write_all(stdout_fd, "\r\n", 2);
|
guac_terminal_write_all(stdout_fd, "\r\n", 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -131,6 +131,8 @@ void* ssh_client_thread(void* data) {
|
|||||||
guac_client* client = (guac_client*) data;
|
guac_client* client = (guac_client*) data;
|
||||||
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
ssh_guac_client_data* client_data = (ssh_guac_client_data*) client->data;
|
||||||
|
|
||||||
|
char name[1024];
|
||||||
|
|
||||||
guac_socket* socket = client->socket;
|
guac_socket* socket = client->socket;
|
||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
int bytes_read = -1234;
|
int bytes_read = -1234;
|
||||||
@ -144,11 +146,16 @@ void* ssh_client_thread(void* data) {
|
|||||||
prompt(client, "Login as: ", client_data->username, sizeof(client_data->username), true) == NULL)
|
prompt(client, "Login as: ", client_data->username, sizeof(client_data->username), true) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
/* Send new name */
|
||||||
|
snprintf(name, sizeof(name)-1, "%s@%s", client_data->username, client_data->hostname);
|
||||||
|
guac_protocol_send_name(socket, name);
|
||||||
|
|
||||||
/* Get password */
|
/* Get password */
|
||||||
if (client_data->password[0] == 0 &&
|
if (client_data->password[0] == 0 &&
|
||||||
prompt(client, "Password: ", client_data->password, sizeof(client_data->password), false) == NULL)
|
prompt(client, "Password: ", client_data->password, sizeof(client_data->password), false) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Clear screen */
|
/* Clear screen */
|
||||||
guac_terminal_write_all(stdout_fd, "\x1B[H\x1B[J", 6);
|
guac_terminal_write_all(stdout_fd, "\x1B[H\x1B[J", 6);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user