return 0;\r
}\r
\r
-int expand_parameter(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool sanitise, bool must_exist) {\r
+int get_string(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool expand, bool sanitise, bool must_exist) {\r
TCHAR *buffer = (TCHAR *) HeapAlloc(GetProcessHeap(), 0, datalen);\r
if (! buffer) {\r
- log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, _T("expand_parameter()"), 0);\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, _T("get_string()"), 0);\r
return 1;\r
}\r
\r
/* Paths aren't allowed to contain quotes. */\r
if (sanitise) PathUnquoteSpaces(buffer);\r
\r
+ /* Do we want to expand the string? */\r
+ if (! expand) {\r
+ if (type == REG_EXPAND_SZ) type = REG_SZ;\r
+ }\r
+\r
/* Technically we shouldn't expand environment strings from REG_SZ values */\r
if (type != REG_EXPAND_SZ) {\r
memmove(data, buffer, buflen);\r
return 0;\r
}\r
\r
+int get_string(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool sanitise) {\r
+ return get_string(key, value, data, datalen, false, sanitise, true);\r
+}\r
+\r
+int expand_parameter(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool sanitise, bool must_exist) {\r
+ return get_string(key, value, data, datalen, true, sanitise, must_exist);\r
+}\r
+\r
int expand_parameter(HKEY key, TCHAR *value, TCHAR *data, unsigned long datalen, bool sanitise) {\r
return expand_parameter(key, value, data, datalen, sanitise, true);\r
}\r
Returns: 0 if it was set.\r
1 on error.\r
*/\r
-int set_expand_string(HKEY key, TCHAR *value, TCHAR *string) {\r
- if (RegSetValueEx(key, value, 0, REG_EXPAND_SZ, (const unsigned char *) string, (unsigned long) (_tcslen(string) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS) return 0;\r
+int set_string(HKEY key, TCHAR *value, TCHAR *string, bool expand) {\r
+ unsigned long type = expand ? REG_EXPAND_SZ : REG_SZ;\r
+ if (RegSetValueEx(key, value, 0, type, (const unsigned char *) string, (unsigned long) (_tcslen(string) + 1) * sizeof(TCHAR)) == ERROR_SUCCESS) return 0;\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_SETVALUE_FAILED, value, error_string(GetLastError()), 0);\r
return 1;\r
}\r
\r
+int set_string(HKEY key, TCHAR *value, TCHAR *string) {\r
+ return set_string(key, value, string, false);\r
+ return 1;\r
+}\r
+\r
+int set_expand_string(HKEY key, TCHAR *value, TCHAR *string) {\r
+ return set_string(key, value, string, true);\r
+ return 1;\r
+}\r
+\r
/*\r
Set an unsigned long in the registry.\r
Returns: 0 if it was set.\r
int set_environment(TCHAR *, HKEY, TCHAR *, TCHAR **, unsigned long *);\r
int format_environment(TCHAR *, unsigned long, TCHAR **, unsigned long *);\r
int unformat_environment(TCHAR *, unsigned long, TCHAR **, unsigned long *);\r
+int get_string(HKEY, TCHAR *, TCHAR *, unsigned long, bool, bool, bool);\r
+int get_string(HKEY, TCHAR *, TCHAR *, unsigned long, bool);\r
int expand_parameter(HKEY, TCHAR *, TCHAR *, unsigned long, bool, bool);\r
int expand_parameter(HKEY, TCHAR *, TCHAR *, unsigned long, bool);\r
+int set_string(HKEY, TCHAR *, TCHAR *, bool);\r
+int set_string(HKEY, TCHAR *, TCHAR *);\r
int set_expand_string(HKEY, TCHAR *, TCHAR *);\r
int set_number(HKEY, TCHAR *, unsigned long);\r
int get_number(HKEY, TCHAR *, unsigned long *, bool);\r