GUAC-1452: Store filenames within typescript struct.

This commit is contained in:
Michael Jumper 2016-01-27 12:21:50 -08:00
parent 7c7a68975b
commit c68f96741d
2 changed files with 38 additions and 26 deletions

View File

@ -114,44 +114,44 @@ static int guac_terminal_typescript_open_data_file(const char* path,
guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path, guac_terminal_typescript* guac_terminal_typescript_alloc(const char* path,
const char* name, int create_path) { const char* name, int create_path) {
char basename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
char timing_name[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
guac_terminal_typescript* typescript;
int data_fd, timing_fd;
/* Create path if it does not exist, fail if impossible */ /* Create path if it does not exist, fail if impossible */
if (create_path && mkdir(path, S_IRWXU) && errno != EEXIST) if (create_path && mkdir(path, S_IRWXU) && errno != EEXIST)
return NULL; return NULL;
/* Allocate space for new typescript */
guac_terminal_typescript* typescript =
malloc(sizeof(guac_terminal_typescript));
/* Attempt to open typescript data file */ /* Attempt to open typescript data file */
data_fd = guac_terminal_typescript_open_data_file(path, name, basename, typescript->data_fd = guac_terminal_typescript_open_data_file(
sizeof(basename) - sizeof(GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX)); path, name, typescript->data_filename,
if (data_fd == -1) sizeof(typescript->data_filename)
return NULL; - sizeof(GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX));
if (typescript->data_fd == -1) {
/* Append suffix to basename */ free(typescript);
sprintf(timing_name, "%s.%s", basename,
GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX);
/* Attempt to open typescript timing file */
timing_fd = open(timing_name,
O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR);
if (timing_fd == -1) {
close(data_fd);
return NULL; return NULL;
} }
/* Init newly-created typescript */ /* Append suffix to basename */
typescript = malloc(sizeof(guac_terminal_typescript)); sprintf(typescript->timing_filename, "%s.%s", typescript->data_filename,
typescript->data_fd = data_fd; GUAC_TERMINAL_TYPESCRIPT_TIMING_SUFFIX);
typescript->timing_fd = timing_fd;
/* Attempt to open typescript timing file */
typescript->timing_fd = open(typescript->timing_filename,
O_CREAT | O_EXCL | O_WRONLY,
S_IRUSR | S_IWUSR);
if (typescript->timing_fd == -1) {
free(typescript);
close(typescript->data_fd);
return NULL;
}
/* Typescript starts out flushed */
typescript->length = 0; typescript->length = 0;
typescript->last_flush = guac_timestamp_current(); typescript->last_flush = guac_timestamp_current();
/* Write header */ /* Write header */
guac_common_write(data_fd, GUAC_TERMINAL_TYPESCRIPT_HEADER, guac_common_write(typescript->data_fd, GUAC_TERMINAL_TYPESCRIPT_HEADER,
sizeof(GUAC_TERMINAL_TYPESCRIPT_HEADER) - 1); sizeof(GUAC_TERMINAL_TYPESCRIPT_HEADER) - 1);
return typescript; return typescript;

View File

@ -90,6 +90,18 @@ typedef struct guac_terminal_typescript {
*/ */
int length; int length;
/**
* The full path to the file which will contain the raw terminal output for
* this typescript.
*/
char data_filename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
/**
* The full path to the file which will contain the timing information for
* this typescript.
*/
char timing_filename[GUAC_TERMINAL_TYPESCRIPT_MAX_NAME_LENGTH];
/** /**
* The file descriptor of the file into which raw terminal output should be * The file descriptor of the file into which raw terminal output should be
* written. * written.