From 9335ba3db88d0979920371843a12f2231ec7eaaa Mon Sep 17 00:00:00 2001 From: LawrenceK Date: Wed, 16 Jan 2013 13:28:10 +0000 Subject: Allow for any non 0 and the string to also be true. These are the tests used elsewhere in the xrdp code. --- common/log.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/log.c b/common/log.c index 9b2e9289..e8e005f0 100644 --- a/common/log.c +++ b/common/log.c @@ -424,9 +424,10 @@ internalInitAndAllocStruct(void) int APP_CC text2bool(char *s) { - if (0 == g_strcasecmp(s, "1") || - 0 == g_strcasecmp(s, "true") || - 0 == g_strcasecmp(s, "yes")) + if ( (g_atoi(s) != 0) || + (0 == g_strcasecmp(s, "true")) || + (0 == g_strcasecmp(s, "on")) || + (0 == g_strcasecmp(s, "yes"))) { return 1; } -- cgit v1.2.1 From 09dba93bb5a7ec9545f767cd651686871f8a31e0 Mon Sep 17 00:00:00 2001 From: LawrenceK Date: Wed, 16 Jan 2013 13:41:57 +0000 Subject: refactor and use test2bool instead of duplicated code testing for on,yes,true, non zero --- libxrdp/xrdp_rdp.c | 31 ++++++------------------------- xrdp/xrdp_listen.c | 28 ++++------------------------ xrdp/xrdp_mm.c | 11 ++--------- xrdp/xrdp_wm.c | 8 +------- 4 files changed, 13 insertions(+), 65 deletions(-) diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 264f6096..eff2a654 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -19,6 +19,7 @@ */ #include "libxrdp.h" +#include "log.h" #if defined(XRDP_FREERDP1) #include @@ -87,30 +88,15 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) if (g_strcasecmp(item, "bitmap_cache") == 0) { - if ((g_strcasecmp(value, "yes") == 0) || - (g_strcasecmp(value, "true") == 0) || - (g_strcasecmp(value, "1") == 0)) - { - client_info->use_bitmap_cache = 1; - } + client_info->use_bitmap_cache = text2bool(value); } else if (g_strcasecmp(item, "bitmap_compression") == 0) { - if (g_strcasecmp(value, "yes") == 0 || - g_strcasecmp(value, "true") == 0 || - g_strcasecmp(value, "1") == 0) - { - client_info->use_bitmap_comp = 1; - } + client_info->use_bitmap_comp = text2bool(value); } else if (g_strcasecmp(item, "bulk_compression") == 0) { - if (g_strcasecmp(value, "yes") == 0 || - g_strcasecmp(value, "true") == 0 || - g_strcasecmp(value, "1") == 0) - { - client_info->use_bulk_comp = 1; - } + client_info->use_bulk_comp = text2bool(value); } else if (g_strcasecmp(item, "crypt_level") == 0) { @@ -135,13 +121,8 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) } else if (g_strcasecmp(item, "channel_code") == 0) { - if ((g_strcasecmp(value, "yes") == 0) || - (g_strcasecmp(value, "1") == 0) || - (g_strcasecmp(value, "true") == 0)) - { - client_info->channel_code = 1; - } - else + client_info->channel_code = text2bool(value); + if (client_info->channel_code == 0) { g_writeln("Info: All channels are disabled"); } diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index 704fc214..e31c5405 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -19,6 +19,7 @@ */ #include "xrdp.h" +#include "log.h" /* 'g_process' is protected by the semaphore 'g_process_sem'. One thread sets g_process and waits for the other to process it */ @@ -198,40 +199,19 @@ xrdp_listen_get_port_address(char *port, int port_bytes, if (g_strcasecmp(val, "fork") == 0) { val = (char *)list_get_item(values, index); - - if ((g_strcasecmp(val, "yes") == 0) || - (g_strcasecmp(val, "on") == 0) || - (g_strcasecmp(val, "true") == 0) || - (g_atoi(val) != 0)) - { - startup_param->fork = 1; - } + startup_param->fork = text2bool(val); } if (g_strcasecmp(val, "tcp_nodelay") == 0) { val = (char *)list_get_item(values, index); - - if ((g_strcasecmp(val, "yes") == 0) || - (g_strcasecmp(val, "on") == 0) || - (g_strcasecmp(val, "true") == 0) || - (g_atoi(val) != 0)) - { - *tcp_nodelay = 1 ; - } + *tcp_nodelay = text2bool(val); } if (g_strcasecmp(val, "tcp_keepalive") == 0) { val = (char *)list_get_item(values, index); - - if ((g_strcasecmp(val, "yes") == 0) || - (g_strcasecmp(val, "on") == 0) || - (g_strcasecmp(val, "true") == 0) || - (g_atoi(val) != 0)) - { - *tcp_keepalive = 1 ; - } + *tcp_keepalive = text2bool(val); } } } diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index 9b0de186..a59271a5 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -2034,15 +2034,8 @@ is_channel_enabled(char *inName, struct list *names, struct list *values) if ( index >= 0 ) { val = (char *)list_get_item(values, index); - - if ((g_strcasecmp(val, "yes") == 0) || - (g_strcasecmp(val, "on") == 0) || - (g_strcasecmp(val, "true") == 0) || - (g_atoi(val) != 0)) - { - reply = 1; - } - else + reply = text2bool(val); + if (reply == 0) { g_writeln("This channel is disabled: %s", name); } diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index 24362f54..0a2600f2 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -444,13 +444,7 @@ xrdp_wm_load_static_colors_plus(struct xrdp_wm *self, char *autorun_name) else if (g_strcasecmp(val, "hidelogwindow") == 0) { val = (char *)list_get_item(values, index); - - if ((g_strcasecmp(val, "yes") == 0) || - (g_strcasecmp(val, "1") == 0) || - (g_strcasecmp(val, "true") == 0)) - { - self->hide_log_window = 1; - } + self->hide_log_window = text2bool(val); } } } -- cgit v1.2.1