diff options
author | Pierre Ossman <ossman@cendio.se> | 2014-12-03 14:03:29 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2014-12-03 14:03:29 +0100 |
commit | 1bfbcb57d89e6a1d9a7b7287da93a3d0dc51f716 (patch) | |
tree | 7758ed29ee2c61be97daea312d4060a2cf3715a4 /vncviewer | |
parent | 2aef35cfa2f475f3be6c200e93e28f40d99eea43 (diff) | |
download | tigervnc-1bfbcb57d89e6a1d9a7b7287da93a3d0dc51f716.tar.gz tigervnc-1bfbcb57d89e6a1d9a7b7287da93a3d0dc51f716.zip |
Rework the error message in parameters.cxx
They were not very end user friendly so redo more or less all of them.
Diffstat (limited to 'vncviewer')
-rw-r--r-- | vncviewer/parameters.cxx | 122 |
1 files changed, 51 insertions, 71 deletions
diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index 9a164813..bda7818d 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -43,6 +43,7 @@ #include <stdio.h> #include <string.h> #include <limits.h> +#include <errno.h> #include "i18n.h" @@ -196,12 +197,8 @@ bool encodeValue(const char* val, char* dest, size_t destSize) { 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 { @@ -210,12 +207,8 @@ bool encodeValue(const char* val, char* dest, size_t destSize) { 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; @@ -230,13 +223,8 @@ bool encodeValue(const char* val, char* dest, size_t destSize) { 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'; @@ -268,7 +256,6 @@ bool decodeValue(const char* val, char* dest, size_t destSize) { dest[pos] = val[i]; i++; } else { - vlog.error(_("Unknown escape sequence at character %d"), i); return false; } } @@ -280,8 +267,6 @@ bool decodeValue(const char* val, char* dest, size_t destSize) { 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; } } @@ -299,31 +284,27 @@ void setKeyString(const char *_name, const char *_value, HKEY* hKey) { 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; } } @@ -337,15 +318,14 @@ void setKeyInt(const char *_name, const int _value, HKEY* hKey) { 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; } } @@ -359,9 +339,7 @@ bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) { 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; } @@ -370,7 +348,8 @@ bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) { 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; } @@ -378,9 +357,7 @@ bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) { 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; @@ -401,9 +378,7 @@ bool getKeyInt(const char* _name, int* dest, HKEY* hKey) { 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; } @@ -412,7 +387,8 @@ bool getKeyInt(const char* _name, int* dest, HKEY* hKey) { 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; } @@ -431,7 +407,7 @@ void saveToReg(const char* servername) { 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; } @@ -445,14 +421,14 @@ void saveToReg(const char* servername) { } 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); } } @@ -468,7 +444,7 @@ char* loadFromReg() { 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; } @@ -494,13 +470,14 @@ char* loadFromReg() { 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; @@ -539,7 +516,8 @@ void saveViewerParameters(const char *filename, const char *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); } @@ -558,8 +536,8 @@ void saveViewerParameters(const char *filename, const char *servername) { } 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); @@ -599,7 +577,8 @@ char* loadViewerParameters(const char *filename) { 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); } @@ -610,15 +589,17 @@ char* loadViewerParameters(const char *filename) { 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); } @@ -628,9 +609,8 @@ char* loadViewerParameters(const char *filename) { 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); } } @@ -648,8 +628,8 @@ char* loadViewerParameters(const char *filename) { // 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. @@ -661,8 +641,8 @@ char* loadViewerParameters(const char *filename) { 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); @@ -677,8 +657,8 @@ char* loadViewerParameters(const char *filename) { 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); @@ -698,15 +678,15 @@ char* loadViewerParameters(const char *filename) { } } 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; |