Browse Source

Avoid duplicating configuration setting

Let the string helpers call the more fancy setParam(). This makes sure
we can avoid duplicating things.
pull/1587/head
Pierre Ossman 1 year ago
parent
commit
ea6afa9b79
1 changed files with 7 additions and 16 deletions
  1. 7
    16
      common/rfb/Configuration.cxx

+ 7
- 16
common/rfb/Configuration.cxx View File



if (*v == 0 || strcasecmp(v, "1") == 0 || strcasecmp(v, "on") == 0 if (*v == 0 || strcasecmp(v, "1") == 0 || strcasecmp(v, "on") == 0
|| strcasecmp(v, "true") == 0 || strcasecmp(v, "yes") == 0) || strcasecmp(v, "true") == 0 || strcasecmp(v, "yes") == 0)
value = 1;
setParam(true);
else if (strcasecmp(v, "0") == 0 || strcasecmp(v, "off") == 0 else if (strcasecmp(v, "0") == 0 || strcasecmp(v, "off") == 0
|| strcasecmp(v, "false") == 0 || strcasecmp(v, "no") == 0) || strcasecmp(v, "false") == 0 || strcasecmp(v, "no") == 0)
value = 0;
setParam(false);
else { else {
vlog.error("Bool parameter %s: invalid value '%s'", getName(), v); vlog.error("Bool parameter %s: invalid value '%s'", getName(), v);
return false; return false;
} }


vlog.debug("set %s(Bool) to %s(%d)", getName(), v, value);
return true; return true;
} }


bool bool
IntParameter::setParam(const char* v) { IntParameter::setParam(const char* v) {
if (immutable) return true; if (immutable) return true;
vlog.debug("set %s(Int) to %s", getName(), v);
int i = strtol(v, NULL, 0);
if (i < minValue || i > maxValue)
return false;
value = i;
return true;
return setParam(strtol(v, NULL, 0));
} }


bool bool
} }


bool BinaryParameter::setParam(const char* v) { bool BinaryParameter::setParam(const char* v) {
LOCK_CONFIG;
if (immutable) return true; if (immutable) return true;
vlog.debug("set %s(Binary) to %s", getName(), v);
delete [] value;
length = 0;
value = hexToBin(v, strlen(v));
if (value == NULL)
uint8_t *newValue = hexToBin(v, strlen(v));
if (newValue == NULL)
return false; return false;
length = strlen(v)/2;
setParam(newValue, strlen(v)/2);
delete [] newValue;
return true; return true;
} }



Loading…
Cancel
Save