diff --git a/Makefile.am b/Makefile.am index 9b5ab08f..57dc3bda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,6 +29,7 @@ DIST_SUBDIRS = \ src/common-ssh \ src/terminal \ src/guacd \ + src/guacenc \ src/protocols/rdp \ src/protocols/ssh \ src/protocols/telnet \ @@ -39,6 +40,7 @@ SUBDIRS = \ src/libguac \ src/common \ src/guacd \ + src/guacenc \ tests if ENABLE_COMMON_SSH diff --git a/configure.ac b/configure.ac index 1617c295..d4d2644e 100644 --- a/configure.ac +++ b/configure.ac @@ -974,6 +974,7 @@ AC_CONFIG_FILES([Makefile src/terminal/Makefile src/libguac/Makefile src/guacd/Makefile + src/guacenc/Makefile src/protocols/rdp/Makefile src/protocols/ssh/Makefile src/protocols/telnet/Makefile diff --git a/src/guacenc/.gitignore b/src/guacenc/.gitignore new file mode 100644 index 00000000..d705721b --- /dev/null +++ b/src/guacenc/.gitignore @@ -0,0 +1,5 @@ + +# Compiled guacenc +guacenc +guacenc.exe + diff --git a/src/guacenc/Makefile.am b/src/guacenc/Makefile.am new file mode 100644 index 00000000..87f17cba --- /dev/null +++ b/src/guacenc/Makefile.am @@ -0,0 +1,42 @@ +# +# Copyright (C) 2016 Glyptodon, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# + +AUTOMAKE_OPTIONS = foreign + +bin_PROGRAMS = guacenc + +noinst_HEADERS = \ + encode.h \ + log.h + +guacenc_SOURCES = \ + encode.c \ + guacenc.c \ + log.c + +guacenc_CFLAGS = \ + -Werror -Wall -pedantic \ + @LIBGUAC_INCLUDE@ + +guacenc_LDADD = \ + @LIBGUAC_LTLIB@ + diff --git a/src/guacenc/encode.c b/src/guacenc/encode.c new file mode 100644 index 00000000..e4d8eca3 --- /dev/null +++ b/src/guacenc/encode.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" +#include "log.h" + +#include + +#include +#include +#include +#include +#include +#include + +int guacenc_encode(const char* path) { + + /* STUB */ + guacenc_log(GUAC_LOG_INFO, "STUB: Encoding \"%s\" ...", path); + + /* Open input file */ + int fd = open(path, O_RDONLY); + if (fd < 0) { + guacenc_log(GUAC_LOG_ERROR, "%s: %s", path, strerror(errno)); + return 1; + } + + /* Close input file */ + close(fd); + + /* Encoding was successful */ + return 0; + +} + diff --git a/src/guacenc/encode.h b/src/guacenc/encode.h new file mode 100644 index 00000000..66f12573 --- /dev/null +++ b/src/guacenc/encode.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUACENC_ENCODE_H +#define GUACENC_ENCODE_H + +#include "config.h" + +/** + * Encodes the given Guacamole protocol dump as video. + * + * @param path + * The path to the file containing the raw Guacamole protocol dump. + * + * @return + * Zero on success, non-zero if an error prevented successful encoding of + * the video. + */ +int guacenc_encode(const char* path); + +#endif + diff --git a/src/guacenc/guacenc.c b/src/guacenc/guacenc.c new file mode 100644 index 00000000..5fe057ac --- /dev/null +++ b/src/guacenc/guacenc.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" + +#include "encode.h" +#include "log.h" + +int main(int argc, char* argv[]) { + + int i; + + /* Log start */ + guacenc_log(GUAC_LOG_INFO, "Guacamole video encoder (guacenc) " + "version " VERSION); + + /* Abort if no files given */ + if (argc == 1) { + guacenc_log(GUAC_LOG_INFO, "No input files specified. Nothing to do."); + return 0; + } + + /* Track number of overall failures */ + int failures = 0; + + /* Encode all input files */ + for (i = 1; i < argc; i++) { + + /* Get current filename */ + const char* path = argv[i]; + + /* Attempt encoding, log granular success/failure at debug level */ + if (guacenc_encode(path)) { + failures++; + guacenc_log(GUAC_LOG_DEBUG, + "%s was NOT successfully encoded.", path); + } + else + guacenc_log(GUAC_LOG_DEBUG, "%s was successfully encoded.", path); + + } + + /* Warn if at least one file failed */ + if (failures != 0) + guacenc_log(GUAC_LOG_WARNING, "Encoding failed for %i file(s).", + failures); + + /* Notify of success */ + else + guacenc_log(GUAC_LOG_INFO, "All files encoded successfully."); + + /* Encoding complete */ + return 0; + +} + diff --git a/src/guacenc/log.c b/src/guacenc/log.c new file mode 100644 index 00000000..f8050930 --- /dev/null +++ b/src/guacenc/log.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "config.h" +#include "log.h" + +#include +#include + +#include +#include + +int guacenc_log_level = GUAC_LOG_INFO; + +void vguacenc_log(guac_client_log_level level, const char* format, + va_list args) { + + const char* priority_name; + char message[2048]; + + /* Don't bother if the log level is too high */ + if (level > guacenc_log_level) + return; + + /* Copy log message into buffer */ + vsnprintf(message, sizeof(message), format, args); + + /* Convert log level to human-readable name */ + switch (level) { + + /* Error log level */ + case GUAC_LOG_ERROR: + priority_name = "ERROR"; + break; + + /* Warning log level */ + case GUAC_LOG_WARNING: + priority_name = "WARNING"; + break; + + /* Informational log level */ + case GUAC_LOG_INFO: + priority_name = "INFO"; + break; + + /* Debug log level */ + case GUAC_LOG_DEBUG: + priority_name = "DEBUG"; + break; + + /* Any unknown/undefined log level */ + default: + priority_name = "UNKNOWN"; + break; + } + + /* Log to STDERR */ + fprintf(stderr, GUACENC_LOG_NAME ": %s: %s\n", priority_name, message); + +} + +void guacenc_log(guac_client_log_level level, const char* format, ...) { + va_list args; + va_start(args, format); + vguacenc_log(level, format, args); + va_end(args); +} + diff --git a/src/guacenc/log.h b/src/guacenc/log.h new file mode 100644 index 00000000..417e37c3 --- /dev/null +++ b/src/guacenc/log.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2016 Glyptodon, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef GUACENC_LOG_H +#define GUACENC_LOG_H + +#include "config.h" + +#include + +#include + +/** + * The maximum level at which to log messages. All other messages will be + * dropped. + */ +extern int guacenc_log_level; + +/** + * The string to prepend to all log messages. + */ +#define GUACENC_LOG_NAME "guacenc" + +/** + * Writes a message to guacenc's logs. This function takes a format and + * va_list, similar to vprintf. + * + * @param level + * The level at which to log this message. + * + * @param format + * A printf-style format string to log. + * + * @param args + * The va_list containing the arguments to be used when filling the format + * string for printing. + */ +void vguacenc_log(guac_client_log_level level, const char* format, + va_list args); + +/** + * Writes a message to guacenc's logs. This function accepts parameters + * identically to printf. + * + * @param level + * The level at which to log this message. + * + * @param format + * A printf-style format string to log. + * + * @param ... + * Arguments to use when filling the format string for printing. + */ +void guacenc_log(guac_client_log_level level, const char* format, ...); + +#endif +