GUAC-236: Add stub guacenc utility (encode Guacamole protocol to video).
This commit is contained in:
parent
35746efca8
commit
652ea5ddf9
@ -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
|
||||
|
@ -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
|
||||
|
5
src/guacenc/.gitignore
vendored
Normal file
5
src/guacenc/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
# Compiled guacenc
|
||||
guacenc
|
||||
guacenc.exe
|
||||
|
42
src/guacenc/Makefile.am
Normal file
42
src/guacenc/Makefile.am
Normal file
@ -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@
|
||||
|
54
src/guacenc/encode.c
Normal file
54
src/guacenc/encode.c
Normal file
@ -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 <guacamole/client.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
41
src/guacenc/encode.h
Normal file
41
src/guacenc/encode.h
Normal file
@ -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
|
||||
|
75
src/guacenc/guacenc.c
Normal file
75
src/guacenc/guacenc.c
Normal file
@ -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;
|
||||
|
||||
}
|
||||
|
87
src/guacenc/log.c
Normal file
87
src/guacenc/log.c
Normal file
@ -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 <guacamole/client.h>
|
||||
#include <guacamole/error.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
76
src/guacenc/log.h
Normal file
76
src/guacenc/log.h
Normal file
@ -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 <guacamole/client.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
Loading…
Reference in New Issue
Block a user