Skip to content

Commit fafbea3

Browse files
committed
Minor Formatting and Comments
1 parent 8d7c138 commit fafbea3

1 file changed

Lines changed: 34 additions & 33 deletions

File tree

src/webui.c

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ static void _webui_remove_firefox_profile_ini(const char* path, const char* prof
17001700
if (path[0] == '~') {
17011701
const char* home = getenv("HOME");
17021702
if (home) {
1703-
WEBUI_SN_PRINTF_STATIC(full_path, sizeof(full_path), "%s/%s", home,&path[1]);
1703+
WEBUI_SN_PRINTF_STATIC(full_path, sizeof(full_path), "%s/%s", home, &path[1]);
17041704
} else {
17051705
// If for some reason HOME isn't set
17061706
// fall back to the original path.
@@ -3399,7 +3399,7 @@ char* webui_encode(const char* str) {
33993399
size_t buf_len = (((len + 2) / 3) * 4) + 8;
34003400
char* buf = (char*)_webui_malloc(buf_len);
34013401

3402-
int ret = mg_base64_encode((const unsigned char*)str, len, buf,&buf_len);
3402+
int ret = mg_base64_encode((const unsigned char*)str, len, buf, &buf_len);
34033403

34043404
if (ret > (-1)) {
34053405

@@ -3441,7 +3441,7 @@ char* webui_decode(const char* str) {
34413441
size_t buf_len = (((len + 2) / 3) * 4) + 8;
34423442
unsigned char* buf = (unsigned char*)_webui_malloc(buf_len);
34433443

3444-
int ret = mg_base64_decode(str, len, buf,&buf_len);
3444+
int ret = mg_base64_decode(str, len, buf, &buf_len);
34453445

34463446
if (ret > (-1)) {
34473447

@@ -3589,23 +3589,24 @@ void webui_wait(void) {
35893589

35903590
// Check if there is atleast one window (UI)
35913591
// is running. Otherwise the mutex condition
3592-
// signal will never come
3592+
// signal will never be fired.
35933593
if (!_webui.ui) {
35943594

35953595
#ifdef WEBUI_LOG
35963596
_webui_log_debug("[Loop] webui_wait() -> No window is found. Stop\n");
35973597
#endif
3598+
// No window is found, Stop.
35983599
return;
35993600
}
36003601

3602+
// The mutex conditional signal will
3603+
// be fired when no more UI (servers)
3604+
// are running.
36013605
#ifdef WEBUI_LOG
36023606
_webui_log_debug("[Loop] webui_wait() -> Waiting (Timeout in %zu seconds)\n",
36033607
_webui.startup_timeout);
36043608
#endif
3605-
3606-
// The mutex conditional signal will
3607-
// be fired when no more UI (servers)
3608-
// is running.
3609+
36093610
} else {
36103611

36113612
#ifdef WEBUI_LOG
@@ -3628,7 +3629,7 @@ void webui_wait(void) {
36283629

36293630
_webui.is_browser_main_run = true;
36303631
_webui_mutex_lock(&_webui.mutex_wait);
3631-
_webui_condition_wait(&_webui.condition_wait,&_webui.mutex_wait);
3632+
_webui_condition_wait(&_webui.condition_wait, &_webui.mutex_wait);
36323633
_webui.is_browser_main_run = false;
36333634
}
36343635
else {
@@ -3639,7 +3640,7 @@ void webui_wait(void) {
36393640
#endif
36403641

36413642
_webui_mutex_lock(&_webui.mutex_wait);
3642-
_webui_condition_wait(&_webui.condition_wait,&_webui.mutex_wait);
3643+
_webui_condition_wait(&_webui.condition_wait, &_webui.mutex_wait);
36433644
}
36443645
#elif __linux__
36453646
if (!_webui.is_webview) {
@@ -3651,7 +3652,7 @@ void webui_wait(void) {
36513652

36523653
_webui.is_browser_main_run = true;
36533654
_webui_mutex_lock(&_webui.mutex_wait);
3654-
_webui_condition_wait(&_webui.condition_wait,&_webui.mutex_wait);
3655+
_webui_condition_wait(&_webui.condition_wait, &_webui.mutex_wait);
36553656
_webui.is_browser_main_run = false;
36563657
}
36573658
else {
@@ -3678,7 +3679,7 @@ void webui_wait(void) {
36783679

36793680
_webui.is_browser_main_run = true;
36803681
_webui_mutex_lock(&_webui.mutex_wait);
3681-
_webui_condition_wait(&_webui.condition_wait,&_webui.mutex_wait);
3682+
_webui_condition_wait(&_webui.condition_wait, &_webui.mutex_wait);
36823683
_webui.is_browser_main_run = false;
36833684
}
36843685
else {
@@ -4670,7 +4671,7 @@ static bool _webui_timer_is_end(_webui_timer_t* t, size_t ms) {
46704671

46714672
_webui_timer_clock_gettime(&t->now);
46724673

4673-
size_t def = (size_t) _webui_timer_diff(&t->start,&t->now);
4674+
size_t def = (size_t) _webui_timer_diff(&t->start, &t->now);
46744675
if (def > ms)
46754676
return true;
46764677
return false;
@@ -5259,7 +5260,7 @@ static const char* _webui_interpret_command(const char* cmd) {
52595260
// Redirect stderr to stdout
52605261
char cmd_with_redirection[512] = {0};
52615262
WEBUI_SN_PRINTF_STATIC(cmd_with_redirection, sizeof(cmd_with_redirection), "cmd.exe /c %s 2>&1", cmd);
5262-
_webui_system_win32_out(cmd_with_redirection,&out, false);
5263+
_webui_system_win32_out(cmd_with_redirection, &out, false);
52635264
#else
52645265
// Redirect stderr to stdout
52655266
char cmd_with_redirection[512] = {0};
@@ -6137,7 +6138,7 @@ static const char* _webui_get_temp_path() {
61376138
#ifdef _MSC_VER
61386139
char* WinUserProfile = NULL;
61396140
size_t sz = 0;
6140-
if (_dupenv_s(&WinUserProfile,&sz, "USERPROFILE") != 0 || WinUserProfile == NULL)
6141+
if (_dupenv_s(&WinUserProfile, &sz, "USERPROFILE") != 0 || WinUserProfile == NULL)
61416142
return "";
61426143
#else
61436144
char* WinUserProfile = getenv("USERPROFILE");
@@ -7714,7 +7715,7 @@ static bool _webui_is_process_running(const char* process_name) {
77147715
if (hSnapshot == INVALID_HANDLE_VALUE)
77157716
return false;
77167717
pe32.dwSize = sizeof(PROCESSENTRY32);
7717-
if (!Process32First(hSnapshot,&pe32)) {
7718+
if (!Process32First(hSnapshot, &pe32)) {
77187719
CloseHandle(hSnapshot);
77197720
return false;
77207721
}
@@ -7723,7 +7724,7 @@ static bool _webui_is_process_running(const char* process_name) {
77237724
isRunning = true;
77247725
break;
77257726
}
7726-
} while(Process32Next(hSnapshot,&pe32));
7727+
} while(Process32Next(hSnapshot, &pe32));
77277728
CloseHandle(hSnapshot);
77287729
#elif __linux__
77297730
// Linux
@@ -7768,12 +7769,12 @@ static bool _webui_is_process_running(const char* process_name) {
77687769
};
77697770
struct kinfo_proc * procs = NULL;
77707771
size_t size;
7771-
if (sysctl(mib, 4, NULL,&size, NULL, 0) < 0)
7772+
if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0)
77727773
return false; // Failed to get process list size
77737774
procs = (struct kinfo_proc * ) malloc(size);
77747775
if (!procs)
77757776
return false; // Failed to allocate memory for process list
7776-
if (sysctl(mib, 4, procs,&size, NULL, 0) < 0) {
7777+
if (sysctl(mib, 4, procs, &size, NULL, 0) < 0) {
77777778
free(procs);
77787779
return false; // Failed to get process list
77797780
}
@@ -8001,7 +8002,7 @@ static bool _webui_tls_generate_self_signed_cert(char* root_cert, char* root_key
80018002
return false;
80028003

80038004
if (EVP_PKEY_keygen_init(root_ctx) <= 0 || EVP_PKEY_CTX_set_rsa_keygen_bits(root_ctx, bits) <= 0 ||
8004-
EVP_PKEY_keygen(root_ctx,&root_pkey) <= 0) {
8005+
EVP_PKEY_keygen(root_ctx, &root_pkey) <= 0) {
80058006
EVP_PKEY_CTX_free(root_ctx);
80068007
return false;
80078008
}
@@ -8061,7 +8062,7 @@ static bool _webui_tls_generate_self_signed_cert(char* root_cert, char* root_key
80618062
}
80628063

80638064
if (EVP_PKEY_keygen_init(ctx) <= 0 || EVP_PKEY_CTX_set_rsa_keygen_bits(ctx, bits) <= 0 ||
8064-
EVP_PKEY_keygen(ctx,&pkey) <= 0) {
8065+
EVP_PKEY_keygen(ctx, &pkey) <= 0) {
80658066
X509_free(root_x509);
80668067
EVP_PKEY_free(root_pkey);
80678068
EVP_PKEY_CTX_free(ctx);
@@ -8406,7 +8407,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
84068407
CloseHandle(thread);
84078408
#else
84088409
pthread_t thread;
8409-
pthread_create(&thread, NULL,&_webui_server_thread, (void*)win);
8410+
pthread_create(&thread, NULL, &_webui_server_thread, (void*)win);
84108411
pthread_detach(thread);
84118412
win->server_thread = thread;
84128413
#endif
@@ -8499,7 +8500,7 @@ static bool _webui_show_window(_webui_window_t* win, struct mg_connection* clien
84998500
CloseHandle(thread);
85008501
#else
85018502
pthread_t thread;
8502-
pthread_create(&thread, NULL,&_webui_server_thread, (void*)win);
8503+
pthread_create(&thread, NULL, &_webui_server_thread, (void*)win);
85038504
pthread_detach(thread);
85048505
win->server_thread = thread;
85058506
#endif
@@ -10292,7 +10293,7 @@ static void _webui_receive(_webui_window_t* win, struct mg_connection* client,
1029210293
// CloseHandle(thread);
1029310294
// #else
1029410295
// pthread_t thread;
10295-
// pthread_create(&thread, NULL,&_webui_ws_process_thread, (void*)arg);
10296+
// pthread_create(&thread, NULL, &_webui_ws_process_thread, (void*)arg);
1029610297
// pthread_detach(thread);
1029710298
// #endif
1029810299
// }
@@ -10313,7 +10314,7 @@ static void _webui_receive(_webui_window_t* win, struct mg_connection* client,
1031310314
CloseHandle(thread);
1031410315
#else
1031510316
pthread_t thread;
10316-
pthread_create(&thread, NULL,&_webui_ws_process_thread, (void*)arg);
10317+
pthread_create(&thread, NULL, &_webui_ws_process_thread, (void*)arg);
1031710318
pthread_detach(thread);
1031810319
#endif
1031910320
}
@@ -11217,7 +11218,7 @@ static bool _webui_socket_test_listen_win32(size_t port_num) {
1121711218
struct addrinfo hints;
1121811219

1121911220
// Initialize Winsock
11220-
iResult = WSAStartup(MAKEWORD(2, 2),&wsaData);
11221+
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
1122111222
if (iResult != 0) {
1122211223
// WSAStartup failed
1122311224
return false;
@@ -11231,7 +11232,7 @@ static bool _webui_socket_test_listen_win32(size_t port_num) {
1123111232
// Resolve the server address and port
1123211233
char the_port[16] = {0};
1123311234
WEBUI_SN_PRINTF_STATIC(&the_port[0], sizeof(the_port), "%zu", port_num);
11234-
iResult = getaddrinfo("127.0.0.1",&the_port[0],&hints,&result);
11235+
iResult = getaddrinfo("127.0.0.1", &the_port[0], &hints, &result);
1123511236
if (iResult != 0) {
1123611237
// WSACleanup();
1123711238
return false;
@@ -11290,7 +11291,7 @@ static int _webui_system_win32_out(const char* cmd, char ** output, bool show) {
1129011291
sa.bInheritHandle = TRUE;
1129111292
sa.lpSecurityDescriptor = NULL;
1129211293
HANDLE stdout_read, stdout_write;
11293-
if (!CreatePipe(&stdout_read,&stdout_write,&sa, 0)) {
11294+
if (!CreatePipe(&stdout_read, &stdout_write, &sa, 0)) {
1129411295
return -1;
1129511296
}
1129611297
if (!SetHandleInformation(stdout_read, HANDLE_FLAG_INHERIT, 0)) {
@@ -11333,13 +11334,13 @@ static int _webui_system_win32_out(const char* cmd, char ** output, bool show) {
1133311334

1133411335
SetFocus(pi.hProcess);
1133511336
WaitForSingleObject(pi.hProcess, WEBUI_SYS_CMD_TIMEOUT);
11336-
GetExitCodeProcess(pi.hProcess,&Return);
11337+
GetExitCodeProcess(pi.hProcess, &Return);
1133711338

1133811339
DWORD bytes_read;
1133911340
char buffer[WEBUI_STDOUT_BUF];
1134011341
size_t output_size = 0;
1134111342

11342-
while(ReadFile(stdout_read, buffer, WEBUI_STDOUT_BUF,&bytes_read, NULL) && bytes_read > 0) {
11343+
while(ReadFile(stdout_read, buffer, WEBUI_STDOUT_BUF, &bytes_read, NULL) && bytes_read > 0) {
1134311344

1134411345
char* new_output = realloc(*output, output_size + bytes_read + 1);
1134511346
if (new_output == NULL) {
@@ -11458,7 +11459,7 @@ static int _webui_system_win32(_webui_window_t* win, char* cmd, bool show) {
1145811459
// EnumWindows(_webui_enum_windows_proc_win32, (LPARAM)(pi.dwProcessId));
1145911460
// AssignProcessToJobObject(JobObject, pi.hProcess);
1146011461
WaitForSingleObject(pi.hProcess, WEBUI_SYS_CMD_TIMEOUT);
11461-
GetExitCodeProcess(pi.hProcess,&Return);
11462+
GetExitCodeProcess(pi.hProcess, &Return);
1146211463
CloseHandle(pi.hProcess);
1146311464
CloseHandle(pi.hThread);
1146411465
_webui_free_mem((void*)wcmd);
@@ -11477,14 +11478,14 @@ static bool _webui_get_windows_reg_value(HKEY key, LPCWSTR reg, LPCWSTR value_na
1147711478

1147811479
HKEY hKey;
1147911480

11480-
if (RegOpenKeyExW(key, reg, 0, KEY_READ,&hKey) == ERROR_SUCCESS) {
11481+
if (RegOpenKeyExW(key, reg, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
1148111482

1148211483
DWORD VALUE_TYPE;
1148311484
BYTE VALUE_DATA[WEBUI_MAX_PATH];
1148411485
DWORD VALUE_SIZE = sizeof(VALUE_DATA);
1148511486

1148611487
// If `value_name` is empty then it will read the "(default)" reg-key
11487-
if (RegQueryValueExW(hKey, value_name, NULL,&VALUE_TYPE, VALUE_DATA,&VALUE_SIZE) == ERROR_SUCCESS) {
11488+
if (RegQueryValueExW(hKey, value_name, NULL, &VALUE_TYPE, VALUE_DATA, &VALUE_SIZE) == ERROR_SUCCESS) {
1148811489

1148911490
if (VALUE_TYPE == REG_SZ)
1149011491
WEBUI_SN_PRINTF_STATIC(value, WEBUI_MAX_PATH, "%S", (LPCWSTR) VALUE_DATA);

0 commit comments

Comments
 (0)