return ret;
}
-/* Replace NULL with CRLF. Leave NULL NULL as the end marker. */
-int format_environment(TCHAR *env, unsigned long envlen, TCHAR **formatted, unsigned long *newlen) {
- unsigned long i, j;
- *newlen = envlen;
-
- if (! *newlen) {
- *formatted = 0;
- return 0;
- }
-
- for (i = 0; i < envlen; i++) if (! env[i] && env[i + 1]) ++*newlen;
-
- *formatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR));
- if (! *formatted) {
- *newlen = 0;
- return 1;
- }
-
- for (i = 0, j = 0; i < envlen; i++) {
- (*formatted)[j] = env[i];
- if (! env[i]) {
- if (env[i + 1]) {
- (*formatted)[j] = _T('\r');
- (*formatted)[++j] = _T('\n');
- }
- }
- j++;
- }
-
- return 0;
-}
-
-/* Strip CR and replace LF with NULL. */
-int unformat_environment(TCHAR *env, unsigned long envlen, TCHAR **unformatted, unsigned long *newlen) {
- unsigned long i, j;
- *newlen = 0;
-
- if (! envlen) {
- *unformatted = 0;
- return 0;
- }
-
- for (i = 0; i < envlen; i++) if (env[i] != _T('\r')) ++*newlen;
- /* Must end with two NULLs. */
- *newlen += 2;
-
- *unformatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR));
- if (! *unformatted) return 1;
-
- for (i = 0, j = 0; i < envlen; i++) {
- if (env[i] == _T('\r')) continue;
- if (env[i] == _T('\n')) (*unformatted)[j] = _T('\0');
- else (*unformatted)[j] = env[i];
- j++;
- }
-
- return 0;
-}
-
/*
Verify an environment block.
Returns: 1 if environment is invalid.
int set_environment_block(TCHAR *);
int clear_environment();
int duplicate_environment(TCHAR *);
-int format_environment(TCHAR *, unsigned long, TCHAR **, unsigned long *);
-int unformat_environment(TCHAR *, unsigned long, TCHAR **, unsigned long *);
int test_environment(TCHAR *);
#endif
if (envlen) {\r
TCHAR *formatted;\r
unsigned long newlen;\r
- if (format_environment(env, envlen, &formatted, &newlen)) {\r
+ if (format_double_null(env, envlen, &formatted, &newlen)) {\r
popup_message(dlg, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("nssm_dlg()"));\r
}\r
else {\r
\r
TCHAR *newenv;\r
unsigned long newlen;\r
- if (unformat_environment(env, envlen, &newenv, &newlen)) {\r
+ if (unformat_double_null(env, envlen, &newenv, &newlen)) {\r
HeapFree(GetProcessHeap(), 0, env);\r
popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_EVENT_OUT_OF_MEMORY, _T("environment"), _T("install()"));\r
cleanup_nssm_service(service);\r
return get_number(key, value, number, true);\r
}\r
\r
+/* Replace NULL with CRLF. Leave NULL NULL as the end marker. */\r
+int format_double_null(TCHAR *dn, unsigned long dnlen, TCHAR **formatted, unsigned long *newlen) {\r
+ unsigned long i, j;\r
+ *newlen = dnlen;\r
+\r
+ if (! *newlen) {\r
+ *formatted = 0;\r
+ return 0;\r
+ }\r
+\r
+ for (i = 0; i < dnlen; i++) if (! dn[i] && dn[i + 1]) ++*newlen;\r
+\r
+ *formatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR));\r
+ if (! *formatted) {\r
+ *newlen = 0;\r
+ return 1;\r
+ }\r
+\r
+ for (i = 0, j = 0; i < dnlen; i++) {\r
+ (*formatted)[j] = dn[i];\r
+ if (! dn[i]) {\r
+ if (dn[i + 1]) {\r
+ (*formatted)[j] = _T('\r');\r
+ (*formatted)[++j] = _T('\n');\r
+ }\r
+ }\r
+ j++;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+/* Strip CR and replace LF with NULL. */\r
+int unformat_double_null(TCHAR *dn, unsigned long dnlen, TCHAR **unformatted, unsigned long *newlen) {\r
+ unsigned long i, j;\r
+ *newlen = 0;\r
+\r
+ if (! dnlen) {\r
+ *unformatted = 0;\r
+ return 0;\r
+ }\r
+\r
+ for (i = 0; i < dnlen; i++) if (dn[i] != _T('\r')) ++*newlen;\r
+ /* Must end with two NULLs. */\r
+ *newlen += 2;\r
+\r
+ *unformatted = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *newlen * sizeof(TCHAR));\r
+ if (! *unformatted) return 1;\r
+\r
+ for (i = 0, j = 0; i < dnlen; i++) {\r
+ if (dn[i] == _T('\r')) continue;\r
+ if (dn[i] == _T('\n')) (*unformatted)[j] = _T('\0');\r
+ else (*unformatted)[j] = dn[i];\r
+ j++;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
void override_milliseconds(TCHAR *service_name, HKEY key, TCHAR *value, unsigned long *buffer, unsigned long default_value, unsigned long event) {\r
unsigned long type = REG_DWORD;\r
unsigned long buflen = sizeof(unsigned long);\r
int set_number(HKEY, TCHAR *, unsigned long);\r
int get_number(HKEY, TCHAR *, unsigned long *, bool);\r
int get_number(HKEY, TCHAR *, unsigned long *);\r
+int format_double_null(TCHAR *, unsigned long, TCHAR **, unsigned long *);\r
+int unformat_double_null(TCHAR *, unsigned long, TCHAR **, unsigned long *);\r
void override_milliseconds(TCHAR *, HKEY, TCHAR *, unsigned long *, unsigned long, unsigned long);\r
int get_io_parameters(nssm_service_t *, HKEY);\r
int get_parameters(nssm_service_t *, STARTUPINFO *);\r
unsigned long envlen = (unsigned long) _tcslen(value->string) + 1;
TCHAR *unformatted = 0;
unsigned long newlen;
- if (unformat_environment(value->string, envlen, &unformatted, &newlen)) return -1;
+ if (unformat_double_null(value->string, envlen, &unformatted, &newlen)) return -1;
if (test_environment(unformatted)) {
HeapFree(GetProcessHeap(), 0, unformatted);
TCHAR *formatted;
unsigned long newlen;
- if (format_environment(env, envlen, &formatted, &newlen)) return -1;
+ if (format_double_null(env, envlen, &formatted, &newlen)) return -1;
int ret;
if (additional) {