GUAC-911: Separate parsing of level name into own function.

This commit is contained in:
Michael Jumper 2014-11-09 19:39:11 -08:00
parent 4b92233084
commit 3ff5d5d690
3 changed files with 24 additions and 10 deletions

View File

@ -77,23 +77,16 @@ static int guacd_conf_callback(const char* section, const char* param, const cha
/* Max log level */
else if (strcmp(param, "log_level") == 0) {
/* Translate level name */
if (strcmp(value, "info") == 0)
config->max_log_level = GUAC_LOG_INFO;
else if (strcmp(value, "error") == 0)
config->max_log_level = GUAC_LOG_ERROR;
else if (strcmp(value, "warning") == 0)
config->max_log_level = GUAC_LOG_WARNING;
else if (strcmp(value, "debug") == 0)
config->max_log_level = GUAC_LOG_DEBUG;
int level = guacd_parse_log_level(value);
/* Invalid log level */
else {
if (level < 0) {
guacd_conf_parse_error = "Invalid log level. Valid levels are: \"debug\", \"info\", \"warning\", and \"error\".";
return 1;
}
/* Valid log level */
config->max_log_level = level;
return 0;
}

View File

@ -24,6 +24,8 @@
#include "conf-parse.h"
#include <guacamole/client.h>
#include <ctype.h>
#include <string.h>
@ -521,3 +523,16 @@ int guacd_parse_conf(guacd_param_callback* callback, char* buffer, int length, v
}
int guacd_parse_log_level(const char* name) {
/* Translate log level name */
if (strcmp(name, "info") == 0) return GUAC_LOG_INFO;
if (strcmp(name, "error") == 0) return GUAC_LOG_ERROR;
if (strcmp(name, "warning") == 0) return GUAC_LOG_WARNING;
if (strcmp(name, "debug") == 0) return GUAC_LOG_DEBUG;
/* No such log level */
return -1;
}

View File

@ -50,6 +50,12 @@ typedef int guacd_param_callback(const char* section, const char* param, const c
*/
int guacd_parse_conf(guacd_param_callback* callback, char* buffer, int length, void* data);
/**
* Parses the given level name, returning the corresponding log level, or -1 if
* no such log level exists.
*/
int guacd_parse_log_level(const char* name);
/**
* Human-readable description of the current error, if any.
*/