#include <stdio.h>
#include <string.h>
#include <limits.h>
+#include <errno.h>
#include "i18n.h"
strncpy(dest+pos, "\\\\", 2);
pos++;
- if (pos >= destSize) {
- vlog.error(_("Encoding backslash: The size of the buffer dest "
- "is to small, it needs to be more than %d bytes bigger."),
- (destSize - 1 - i));
+ if (pos >= destSize)
return false;
- }
} else {
if (val[i] == replaceMap[j].first) {
dest[pos] = '\\';
pos++;
- if (pos >= destSize) {
- vlog.error(_("Encoding escape sequence: The size of the buffer "
- "dest is to small, it needs to be more than %d bytes "
- "bigger."), (destSize - 1 - i));
+ if (pos >= destSize)
return false;
- }
dest[pos] = replaceMap[j].second;
normalCharacter = false;
normalCharacter = true; // Reset for next loop
pos++;
- if (pos >= destSize) {
- vlog.error(_("Encoding normal character: The size of the buffer dest "
- "is to small, it needs to be more than %d bytes bigger."),
- (destSize - 1 - i));
+ if (pos >= destSize)
return false;
- }
-
}
dest[pos] = '\0';
dest[pos] = val[i];
i++;
} else {
- vlog.error(_("Unknown escape sequence at character %d"), i);
return false;
}
}
escapedCharacter = false; // Reset for next loop
pos++;
if (pos >= destSize) {
- vlog.error(_("Decoding: The size of the buffer dest is to small, "
- "it needs to be 1 byte bigger."));
return false;
}
}
wchar_t name[buffersize];
unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize);
if (size >= buffersize) {
- vlog.error(_("Could not convert the parameter-name %s to wchar_t* when "
- "writing to the Registry, the buffersize is to small."),
- _name);
+ vlog.error(_("The name of the parameter %s was too large to write to the registry"), _name);
return;
}
char encodingBuffer[buffersize];
if (!encodeValue(_value, encodingBuffer, buffersize)) {
- vlog.error(_("Could not encode the parameter-value %s when "
- "writing to the Registry."), _value);
+ vlog.error(_("The parameter %s was too large to write to the registry"), _name);
return;
}
wchar_t value[buffersize];
size = fl_utf8towc(encodingBuffer, strlen(encodingBuffer)+1, value, buffersize);
if (size >= buffersize) {
- vlog.error(_("Could not convert the parameter-value %s to wchar_t* when "
- "writing to the Registry, the buffersize is to small."),
- _value);
+ vlog.error(_("The parameter %s was too large to write to the registry"), _name);
return;
}
LONG res = RegSetValueExW(*hKey, name, 0, REG_SZ, (BYTE*)&value, (wcslen(value)+1)*2);
if (res != ERROR_SUCCESS) {
- vlog.error(_("Error(%d) writing %s(REG_SZ) to Registry."), res, _value);
+ vlog.error(_("Failed to write parameter %s of type %s to the registry: %d"),
+ _name, "REG_SZ", res);
return;
}
}
unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize);
if (size >= buffersize) {
- vlog.error(_("Could not convert the parameter-name %s to wchar_t* when "
- "writing to the Registry, the buffersize is to small."),
- _name);
+ vlog.error(_("The name of the parameter %s was too large to write to the registry"), _name);
return;
}
LONG res = RegSetValueExW(*hKey, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
if (res != ERROR_SUCCESS) {
- vlog.error(_("Error(%d) writing %d(REG_DWORD) to Registry."), res, _value);
+ vlog.error(_("Failed to write parameter %s of type %s to the registry: %d"),
+ _name, "REG_DWORD", res);
return;
}
}
unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize);
if (size >= buffersize) {
- vlog.error(_("Could not convert the parameter-name %s to wchar_t* when "
- "reading from the Registry, the buffersize is to small."),
- _name);
+ vlog.error(_("The name of the parameter %s was too large to read from the registry"), _name);
return false;
}
if (res == ERROR_FILE_NOT_FOUND) {
// The value does not exist, defaults will be used.
} else {
- vlog.error(_("Error(%d) reading %s from Registry."), res, _name);
+ vlog.error(_("Failed to read parameter %s from the registry: %d"),
+ _name, res);
}
return false;
}
char utf8val[destSize];
size = fl_utf8fromwc(utf8val, sizeof(utf8val), value, wcslen(value)+1);
if (size >= sizeof(utf8val)) {
- vlog.error(_("Could not convert the parameter-value for %s to utf8 "
- "char* when reading from the Registry, the buffer dest is "
- "to small."), _name);
+ vlog.error(_("The parameter %s was too large to read from the registry"), _name);
return false;
}
const char *ret = utf8val;
unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize);
if (size >= buffersize) {
- vlog.error(_("Could not convert the parameter-name %s to wchar_t* when "
- "reading from the Registry, the buffersize is to small."),
- _name);
+ vlog.error(_("The name of the parameter %s was too large to read from the registry"), _name);
return false;
}
if (res == ERROR_FILE_NOT_FOUND) {
// The value does not exist, defaults will be used.
} else {
- vlog.error(_("Error(%d) reading %s from Registry."), res, _name);
+ vlog.error(_("Failed to read parameter %s from the registry: %d"),
+ _name, res);
}
return false;
}
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey, NULL);
if (res != ERROR_SUCCESS) {
- vlog.error(_("Error(%d) creating key: Software\\TigerVNC\\vncviewer"), res);
+ vlog.error(_("Failed to create registry key: %d"), res);
return;
}
} else if (dynamic_cast<BoolParameter*>(parameterArray[i]) != NULL) {
setKeyInt(parameterArray[i]->getName(), (int)*(BoolParameter*)parameterArray[i], &hKey);
} else {
- vlog.info(_("The parameterArray contains a object of a invalid type "
- "at line %d."), i);
+ vlog.error(_("Unknown parameter type for parameter %s"),
+ parameterArray[i]->getName());
}
}
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS) {
- vlog.error(_("Error(%d) closing key: Software\\TigerVNC\\vncviewer"), res);
+ vlog.error(_("Failed to close registry key: %d"), res);
}
}
if (res == ERROR_FILE_NOT_FOUND) {
// The key does not exist, defaults will be used.
} else {
- vlog.error(_("Error(%d) opening key: Software\\TigerVNC\\vncviewer"), res);
+ vlog.error(_("Failed to open registry key: %d"), res);
}
return NULL;
}
if (getKeyInt(parameterArray[i]->getName(), &intValue, &hKey))
((BoolParameter*)parameterArray[i])->setParam(intValue);
} else {
- vlog.info(_("The parameterArray contains a object of a invalid type at line %d."), i);
+ vlog.error(_("Unknown parameter type for parameter %s"),
+ parameterArray[i]->getName());
}
}
res = RegCloseKey(hKey);
if (res != ERROR_SUCCESS){
- vlog.error(_("Error(%d) closing key: Software\\TigerVNC\\vncviewer"), res);
+ vlog.error(_("Failed to close registry key: %d"), res);
}
return servername;
FILE* f = fopen(filepath, "w+");
if (!f) {
snprintf(write_error, sizeof(write_error),
- _("Failed to write configuration file, can't open %s"), filepath);
+ _("Failed to write configuration file, can't open %s: %s"),
+ filepath, strerror(errno));
throw Exception(write_error);
}
} else if (dynamic_cast<BoolParameter*>(parameterArray[i]) != NULL) {
fprintf(f, "%s=%d\n", ((BoolParameter*)parameterArray[i])->getName(), (int)*(BoolParameter*)parameterArray[i]);
} else {
- vlog.info(_("The parameterArray contains a object of a invalid type "
- "at line %d."), i);
+ vlog.error(_("Unknown parameter type for parameter %s"),
+ parameterArray[i]->getName());
}
}
fclose(f);
if (!filename)
return NULL; // Use defaults.
snprintf(readError, sizeof(readError),
- _("Failed to read configuration file, can't open %s"), filepath);
+ _("Failed to read configuration file, can't open %s: %s"),
+ filepath, strerror(errno));
throw Exception(readError);
}
lineNr++;
if (!fgets(line, sizeof(line), f)) {
if (line[sizeof(line) -1] != '\0') {
- vlog.error(_("Could not read the line(%d) in the configuration file,"
- "the buffersize is to small."), lineNr);
- return NULL;
+ snprintf(readError, sizeof(readError),
+ _("Failed to read line %d in file %s: %s"),
+ lineNr, filepath, _("Line too long"));
+ throw Exception(readError);
}
if (feof(f))
break;
snprintf(readError, sizeof(readError),
- _("Failed to read line %d in file %s"), lineNr, filepath);
+ _("Failed to read line %d in file %s: %s"),
+ lineNr, filepath, strerror(errno));
throw Exception(readError);
}
continue;
} else {
snprintf(readError, sizeof(readError),
- _("Line 1 in file %s\nmust contain the TigerVNC "
- "configuration file identifier string:\n"
- "\"%s\""), filepath, IDENTIFIER_STRING);
+ _("Configuration file %s is in an invalid format"),
+ filepath);
throw Exception(readError);
}
}
// Find the parameter value
char *value = strchr(line, '=');
if (value == NULL) {
- vlog.info(_("Bad Name/Value pair on line: %d in file: %s"),
- lineNr, filepath);
+ vlog.error(_("Failed to read line %d in file %s: %s"),
+ lineNr, filepath, _("Invalid format"));
continue;
}
*value = '\0'; // line only contains the parameter name below.
if (strcasecmp(line, "ServerName") == 0) {
if(!decodeValue(value, decodingBuffer, sizeof(decodingBuffer))) {
- vlog.info(_("The value of the parameter %s on line %d in file %s "
- "is invalid."), line, lineNr, filepath);
+ vlog.error(_("Failed to read line %d in file %s: %s"),
+ lineNr, filepath, _("Invalid format or too large value"));
continue;
}
snprintf(servername, sizeof(decodingBuffer), "%s", decodingBuffer);
if (strcasecmp(line, ((StringParameter*)parameterArray[i])->getName()) == 0) {
if(!decodeValue(value, decodingBuffer, sizeof(decodingBuffer))) {
- vlog.info(_("The value of the parameter %s on line %d in file %s "
- "is invalid."), line, lineNr, filepath);
+ vlog.error(_("Failed to read line %d in file %s: %s"),
+ lineNr, filepath, _("Invalid format or too large value"));
continue;
}
((StringParameter*)parameterArray[i])->setParam(decodingBuffer);
}
} else {
- vlog.info(_("The parameterArray contains a object of a invalid type "
- "at line %d."), lineNr);
+ vlog.error(_("Unknown parameter type for parameter %s"),
+ parameterArray[i]->getName());
}
}
}
if (invalidParameterName)
- vlog.info(_("Invalid parameter name on line: %d in file: %s"),
- lineNr, filepath);
+ vlog.info(_("Unknown parameter %s on line %d in file %s"),
+ line, lineNr, filepath);
}
fclose(f); f=0;