int guac_client_init(guac_client* client, int argc, char** argv) { guac_socket* socket = client->socket; ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data)); /* Init client data */ client->data = client_data; client_data->mod_alt = client_data->mod_ctrl = client_data->mod_shift = 0; client_data->clipboard_data = NULL; client_data->term_channel = NULL; if (argc != SSH_ARGS_COUNT) { guac_client_log_error(client, "Wrong number of arguments"); return -1; } /* Read parameters */ strcpy(client_data->hostname, argv[IDX_HOSTNAME]); strcpy(client_data->username, argv[IDX_USERNAME]); strcpy(client_data->password, argv[IDX_PASSWORD]); /* Read font name */ if (argv[IDX_FONT_NAME][0] != 0) strcpy(client_data->font_name, argv[IDX_FONT_NAME]); else strcpy(client_data->font_name, GUAC_SSH_DEFAULT_FONT_NAME ); /* Read font size */ if (argv[IDX_FONT_SIZE][0] != 0) client_data->font_size = atoi(argv[IDX_FONT_SIZE]); else client_data->font_size = GUAC_SSH_DEFAULT_FONT_SIZE; /* Read port */ if (argv[IDX_PORT][0] != 0) client_data->port = atoi(argv[IDX_PORT]); else client_data->port = GUAC_SSH_DEFAULT_PORT; /* Create terminal */ client_data->term = guac_terminal_create(client, client_data->font_name, client_data->font_size, client->info.optimal_width, client->info.optimal_height); /* Fail if terminal init failed */ if (client_data->term == NULL) { guac_error = GUAC_STATUS_BAD_STATE; guac_error_message = "Terminal initialization failed"; return -1; } /* Set up I-bar pointer */ client_data->ibar_cursor = guac_ssh_create_ibar(client); /* Set up blank pointer */ client_data->blank_cursor = guac_ssh_create_blank(client); /* Send initial name */ guac_protocol_send_name(socket, client_data->hostname); /* Initialize pointer */ client_data->current_cursor = client_data->blank_cursor; guac_ssh_set_cursor(client, client_data->current_cursor); guac_socket_flush(socket); /* Set basic handlers */ client->handle_messages = ssh_guac_client_handle_messages; client->clipboard_handler = ssh_guac_client_clipboard_handler; client->key_handler = ssh_guac_client_key_handler; client->mouse_handler = ssh_guac_client_mouse_handler; client->size_handler = ssh_guac_client_size_handler; client->free_handler = ssh_guac_client_free_handler; /* Start client thread */ if (pthread_create(&(client_data->client_thread), NULL, ssh_client_thread, (void*) client)) { guac_client_log_error(client, "Unable to SSH client thread"); return -1; } /* Success */ return 0; }
int guac_client_init(guac_client* client, int argc, char** argv) { guac_socket* socket = client->socket; ssh_guac_client_data* client_data = malloc(sizeof(ssh_guac_client_data)); /* Init client data */ client->data = client_data; client_data->mod_alt = client_data->mod_ctrl = client_data->mod_shift = 0; client_data->clipboard = guac_common_clipboard_alloc(GUAC_SSH_CLIPBOARD_MAX_LENGTH); client_data->term_channel = NULL; if (argc != SSH_ARGS_COUNT) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Wrong number of arguments"); return -1; } /* Read parameters */ strcpy(client_data->hostname, argv[IDX_HOSTNAME]); strcpy(client_data->username, argv[IDX_USERNAME]); strcpy(client_data->password, argv[IDX_PASSWORD]); /* Init public key auth information */ client_data->key = NULL; strcpy(client_data->key_base64, argv[IDX_PRIVATE_KEY]); strcpy(client_data->key_passphrase, argv[IDX_PASSPHRASE]); /* Read font name */ if (argv[IDX_FONT_NAME][0] != 0) strcpy(client_data->font_name, argv[IDX_FONT_NAME]); else strcpy(client_data->font_name, GUAC_SSH_DEFAULT_FONT_NAME ); /* Read font size */ if (argv[IDX_FONT_SIZE][0] != 0) client_data->font_size = atoi(argv[IDX_FONT_SIZE]); else client_data->font_size = GUAC_SSH_DEFAULT_FONT_SIZE; /* Parse SFTP enable */ client_data->enable_sftp = strcmp(argv[IDX_ENABLE_SFTP], "true") == 0; client_data->sftp_session = NULL; client_data->sftp_ssh_session = NULL; strcpy(client_data->sftp_upload_path, "."); #ifdef ENABLE_SSH_AGENT client_data->enable_agent = strcmp(argv[IDX_ENABLE_AGENT], "true") == 0; #endif /* Read port */ if (argv[IDX_PORT][0] != 0) strcpy(client_data->port, argv[IDX_PORT]); else strcpy(client_data->port, GUAC_SSH_DEFAULT_PORT); /* Create terminal */ client_data->term = guac_terminal_create(client, client_data->font_name, client_data->font_size, client->info.optimal_resolution, client->info.optimal_width, client->info.optimal_height); /* Fail if terminal init failed */ if (client_data->term == NULL) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Terminal initialization failed"); return -1; } /* Set up I-bar pointer */ client_data->ibar_cursor = guac_ssh_create_ibar(client); /* Set up blank pointer */ client_data->blank_cursor = guac_ssh_create_blank(client); /* Send initial name */ guac_protocol_send_name(socket, client_data->hostname); /* Initialize pointer */ client_data->current_cursor = client_data->blank_cursor; guac_ssh_set_cursor(client, client_data->current_cursor); guac_socket_flush(socket); /* Set basic handlers */ client->handle_messages = ssh_guac_client_handle_messages; client->clipboard_handler = ssh_guac_client_clipboard_handler; client->key_handler = ssh_guac_client_key_handler; client->mouse_handler = ssh_guac_client_mouse_handler; client->size_handler = ssh_guac_client_size_handler; client->free_handler = ssh_guac_client_free_handler; /* Start client thread */ if (pthread_create(&(client_data->client_thread), NULL, ssh_client_thread, (void*) client)) { guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR, "Unable to start SSH client thread"); return -1; } /* Success */ return 0; }