diff --git a/localization.c b/localization.c index 3b95f35..40a5768 100644 --- a/localization.c +++ b/localization.c @@ -33,7 +33,7 @@ #include "options.h" #include "registry.h" -extern struct options o; +extern options_t o; static const LANGID fallbackLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL); static LANGID gui_language; diff --git a/main.c b/main.c index 06d8634..5c2b6ce 100644 --- a/main.c +++ b/main.c @@ -54,7 +54,7 @@ TCHAR szClassName[ ] = _T("OpenVPN-GUI"); TCHAR szTitleText[ ] = _T("OpenVPN"); /* Options structure */ -struct options o; +options_t o; int WINAPI WinMain (HINSTANCE hThisInstance, UNUSED HINSTANCE hPrevInstance, @@ -68,7 +68,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, /* initialize options to default state */ - init_options (&o); + InitOptions(&o); #ifdef DEBUG /* Open debug file for output */ @@ -109,7 +109,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, /* Parse command-line options */ - Createargcargv(&o, GetCommandLine()); + ProcessCommandLine(&o, GetCommandLine()); /* Check if a previous instance is already running. */ if ((FindWindow (szClassName, NULL)) != NULL) @@ -224,7 +224,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM StopOpenVPN(LOWORD(wParam) - IDM_DISCONNECTMENU); } if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) { - ShowWindow(o.cnn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW); + ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW); } if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) { ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU); @@ -281,13 +281,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM /* Suspend running connections */ for (i=0; iconfig_file, filename, _tsizeof(conn->config_file) - 1); @@ -178,3 +178,39 @@ BuildFileList() } } + +/* + * Returns TRUE if option exist in config file. + */ +bool +ConfigFileOptionExist(int config, const char *option) +{ + FILE *fp; + char line[256]; + TCHAR path[MAX_PATH]; + + _tcsncpy(path, o.conn[config].config_dir, _tsizeof(path)); + if (path[_tcslen(path) - 1] != _T('\\')) + _tcscat(path, _T("\\")); + _tcsncat(path, o.conn[config].config_file, _tsizeof(path) - _tcslen(path) - 1); + + fp = _tfopen(path, _T("r")); + if (fp == NULL) + { + ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, path); + return false; + } + + while (fgets(line, sizeof(line), fp)) + { + if (strncmp(line, option, sizeof(option)) == 0) + { + fclose(fp); + return true; + } + } + + fclose(fp); + return false; +} + diff --git a/openvpn_config.h b/openvpn_config.h index e23468b..6c83664 100644 --- a/openvpn_config.h +++ b/openvpn_config.h @@ -22,6 +22,9 @@ #ifndef OPENVPN_CONFIG_H #define OPENVPN_CONFIG_H +#include "main.h" + void BuildFileList(); +bool ConfigFileOptionExist(int, const char *); #endif diff --git a/openvpn_monitor_process.c b/openvpn_monitor_process.c index 625d358..6594edf 100644 --- a/openvpn_monitor_process.c +++ b/openvpn_monitor_process.c @@ -38,7 +38,7 @@ #include "tray.h" #include "localization.h" -extern struct options o; +extern options_t o; /* Wait for a complete line (CR/LF) and return it. * Return values: @@ -203,29 +203,29 @@ void monitor_openvpnlog_while_connecting(int config, char *line) RunConnectScript(config, false); /* Save time when we got connected. */ - o.cnn[config].connected_since = time(NULL); + o.conn[config].connected_since = time(NULL); - o.cnn[config].connect_status = CONNECTED; - SetMenuStatus(config, CONNECTED); - SetTrayIcon(CONNECTED); + o.conn[config].state = connected; + SetMenuStatus(config, connected); + SetTrayIcon(connected); /* Remove Proxy Auth file */ DeleteFile(o.proxy_authfile); /* Zero psw attempt counter */ - o.cnn[config].failed_psw_attempts = 0; + o.conn[config].failed_psw_attempts = 0; /* UserInfo: Connected */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); - SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTED); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); + SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTED); /* Show Tray Balloon msg */ if (o.show_balloon[0] != '0') { - LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); - if (_tcslen(o.cnn[config].ip) > 0) + LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.conn[config].config_name); + if (_tcslen(o.conn[config].ip) > 0) { - ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); + ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.conn[config].ip)); } else { @@ -234,7 +234,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line) } /* Hide Status Window */ - ShowWindow(o.cnn[config].hwndStatus, SW_HIDE); + ShowWindow(o.conn[config].hwndStatus, SW_HIDE); } /* Check for failed passphrase log message */ @@ -244,9 +244,9 @@ void monitor_openvpnlog_while_connecting(int config, char *line) (strstr(line, "Received AUTH_FAILED control message") != NULL) || (strstr(line, "Auth username is empty") != NULL)) { - o.cnn[config].failed_psw_attempts++; - o.cnn[config].failed_psw=1; - o.cnn[config].restart=true; + o.conn[config].failed_psw_attempts++; + o.conn[config].failed_psw=1; + o.conn[config].restart=true; } /* Check for "certificate has expired" message */ @@ -280,10 +280,10 @@ void monitor_openvpnlog_while_connecting(int config, char *line) #ifdef _UNICODE /* Convert the IP address to Unicode */ - o.cnn[config].ip[0] = _T('\0'); - MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.cnn[config].ip, _tsizeof(o.cnn[config].ip)); + o.conn[config].ip[0] = _T('\0'); + MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.conn[config].ip, _tsizeof(o.conn[config].ip)); #else - strncpy(o.cnn[config].ip, ip_addr, sizeof(o.cnn[config].ip)); + strncpy(o.conn[config].ip, ip_addr, sizeof(o.conn[config].ip)); #endif } } @@ -298,12 +298,12 @@ void monitor_openvpnlog_while_connected(int config, char *line) if (strstr(line, "process restarting") != NULL) { /* Set connect_status = ReConnecting */ - o.cnn[config].connect_status = RECONNECTING; + o.conn[config].state = reconnecting; CheckAndSetTrayIcon(); /* Set Status Window Controls "ReConnecting" */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_RECONNECTING)); - SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTING); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_RECONNECTING)); + SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTING); } } @@ -319,20 +319,20 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line) /* Check for Connected message */ if (strstr(line, o.connect_string) != NULL) { - o.cnn[config].connect_status = CONNECTED; - SetTrayIcon(CONNECTED); + o.conn[config].state = connected; + SetTrayIcon(connected); /* Set Status Window Controls "Connected" */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); - SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_CONNECTED); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); + SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_CONNECTED); /* Show Tray Balloon msg */ if (o.show_balloon[0] == '2') { - LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.cnn[config].config_name); - if (_tcslen(o.cnn[config].ip) > 0) + LoadLocalizedStringBuf(msg, _tsizeof(msg), IDS_NFO_NOW_CONNECTED, o.conn[config].config_name); + if (_tcslen(o.conn[config].ip) > 0) { - ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.cnn[config].ip)); + ShowTrayBalloon(msg, LoadLocalizedString(IDS_NFO_ASSIGN_IP, o.conn[config].ip)); } else { @@ -348,9 +348,9 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line) (strstr(line, "Received AUTH_FAILED control message") != NULL) || (strstr(line, "Auth username is empty") != NULL)) { - o.cnn[config].failed_psw_attempts++; - o.cnn[config].failed_psw=1; - o.cnn[config].restart=true; + o.conn[config].failed_psw_attempts++; + o.conn[config].failed_psw=1; + o.conn[config].restart=true; } /* Check for "certificate has expired" message */ @@ -384,10 +384,10 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line) #ifdef _UNICODE /* Convert the IP address to Unicode */ - o.cnn[config].ip[0] = _T('\0'); - MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.cnn[config].ip, _tsizeof(o.cnn[config].ip)); + o.conn[config].ip[0] = _T('\0'); + MultiByteToWideChar(CP_ACP, 0, ip_addr, -1, o.conn[config].ip, _tsizeof(o.conn[config].ip)); #else - strncpy(o.cnn[config].ip, ip_addr, sizeof(o.cnn[config].ip)); + strncpy(o.conn[config].ip, ip_addr, sizeof(o.conn[config].ip)); #endif } } @@ -416,25 +416,25 @@ void WatchOpenVPNProcess(int config) filemode[0] = _T('a'); /* Set Connect_Status = "Connecting" */ - o.cnn[config].connect_status = CONNECTING; + o.conn[config].state = connecting; /* Set Tray Icon = "Connecting" if no other connections are running */ CheckAndSetTrayIcon(); /* Set MenuStatus = "Connecting" */ - SetMenuStatus(config, CONNECTING); + SetMenuStatus(config, connecting); /* Clear failed_password flag */ - o.cnn[config].failed_psw = 0; + o.conn[config].failed_psw = 0; /* Open log file */ - if ((fd=_tfopen(o.cnn[config].log_path, filemode)) == NULL) - ShowLocalizedMsg(IDS_ERR_OPEN_LOG_WRITE, o.cnn[config].log_path); + if ((fd=_tfopen(o.conn[config].log_path, filemode)) == NULL) + ShowLocalizedMsg(IDS_ERR_OPEN_LOG_WRITE, o.conn[config].log_path); - LogWindow = GetDlgItem(o.cnn[config].hwndStatus, ID_EDT_LOG); + LogWindow = GetDlgItem(o.conn[config].hwndStatus, ID_EDT_LOG); while(TRUE) { - if ((ret=ReadLineFromStdOut(o.cnn[config].hStdOut, config, line)) == 1) + if ((ret=ReadLineFromStdOut(o.conn[config].hStdOut, config, line)) == 1) { /* Do nothing if line length = 0 */ @@ -469,13 +469,13 @@ void WatchOpenVPNProcess(int config) SendMessage(LogWindow, EM_REPLACESEL, FALSE, (LPARAM) line); #endif - if (o.cnn[config].connect_status == CONNECTING) /* Connecting state */ + if (o.conn[config].state == connecting) /* Connecting state */ monitor_openvpnlog_while_connecting(config, line); - if (o.cnn[config].connect_status == CONNECTED) /* Connected state */ + if (o.conn[config].state == connected) /* Connected state */ monitor_openvpnlog_while_connected(config, line); - if (o.cnn[config].connect_status == RECONNECTING) /* ReConnecting state */ + if (o.conn[config].state == reconnecting) /* ReConnecting state */ monitor_openvpnlog_while_reconnecting(config, line); } else break; @@ -489,56 +489,56 @@ void WatchOpenVPNProcess(int config) if (fd != NULL) fclose(fd); /* Close StdIn/StdOut handles */ - CloseHandle(o.cnn[config].hStdIn); - CloseHandle(o.cnn[config].hStdOut); + CloseHandle(o.conn[config].hStdIn); + CloseHandle(o.conn[config].hStdOut); /* Close exitevent handle */ - CloseHandle(o.cnn[config].exit_event); - o.cnn[config].exit_event = NULL; + CloseHandle(o.conn[config].exit_event); + o.conn[config].exit_event = NULL; /* Enable/Disable menuitems for this connections */ - SetMenuStatus(config, DISCONNECTING); + SetMenuStatus(config, disconnecting); /* Remove Proxy Auth file */ DeleteFile(o.proxy_authfile); /* Process died outside our control */ - if(o.cnn[config].connect_status == CONNECTED) + if(o.conn[config].state == connected) { /* Zero psw attempt counter */ - o.cnn[config].failed_psw_attempts = 0; + o.conn[config].failed_psw_attempts = 0; /* Set connect_status = "Not Connected" */ - o.cnn[config].connect_status=DISCONNECTED; + o.conn[config].state=disconnected; /* Change tray icon if no more connections is running */ CheckAndSetTrayIcon(); /* Show Status Window */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONNECTED)); - SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_DISCONNECTED); - EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); - EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); - SetForegroundWindow(o.cnn[config].hwndStatus); - ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); - ShowLocalizedMsg(IDS_NFO_CONN_TERMINATED, o.cnn[config].config_name); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONNECTED)); + SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_DISCONNECTED); + EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE); + EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE); + SetForegroundWindow(o.conn[config].hwndStatus); + ShowWindow(o.conn[config].hwndStatus, SW_SHOW); + ShowLocalizedMsg(IDS_NFO_CONN_TERMINATED, o.conn[config].config_name); /* Close Status Window */ - SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); + SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0); } /* We have failed to connect */ - else if(o.cnn[config].connect_status == CONNECTING) + else if(o.conn[config].state == connecting) { /* Set connect_status = "DisConnecting" */ - o.cnn[config].connect_status=DISCONNECTING; + o.conn[config].state=disconnecting; /* Change tray icon if no more connections is running */ CheckAndSetTrayIcon(); - if ((o.cnn[config].failed_psw) && - (o.cnn[config].failed_psw_attempts < o.psw_attempts)) + if ((o.conn[config].failed_psw) && + (o.conn[config].failed_psw_attempts < o.psw_attempts)) { /* Restart OpenVPN to make another attempt to connect */ PostMessage(o.hWnd, WM_COMMAND, (WPARAM) IDM_CONNECTMENU + config, 0); @@ -546,42 +546,42 @@ void WatchOpenVPNProcess(int config) else { /* Show Status Window */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED)); - SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_DISCONNECTED); - EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); - EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); - SetForegroundWindow(o.cnn[config].hwndStatus); - ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED)); + SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_DISCONNECTED); + EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE); + EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE); + SetForegroundWindow(o.conn[config].hwndStatus); + ShowWindow(o.conn[config].hwndStatus, SW_SHOW); /* Zero psw attempt counter */ - o.cnn[config].failed_psw_attempts = 0; + o.conn[config].failed_psw_attempts = 0; - ShowLocalizedMsg(IDS_NFO_CONN_FAILED, o.cnn[config].config_name); + ShowLocalizedMsg(IDS_NFO_CONN_FAILED, o.conn[config].config_name); /* Set connect_status = "Not Connected" */ - o.cnn[config].connect_status=DISCONNECTED; + o.conn[config].state=disconnected; /* Close Status Window */ - SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); + SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0); /* Reset restart flag */ - o.cnn[config].restart=false; + o.conn[config].restart=false; } } /* We have failed to reconnect */ - else if(o.cnn[config].connect_status == RECONNECTING) + else if(o.conn[config].state == reconnecting) { /* Set connect_status = "DisConnecting" */ - o.cnn[config].connect_status=DISCONNECTING; + o.conn[config].state=disconnecting; /* Change tray icon if no more connections is running */ CheckAndSetTrayIcon(); - if ((o.cnn[config].failed_psw) && - (o.cnn[config].failed_psw_attempts < o.psw_attempts)) + if ((o.conn[config].failed_psw) && + (o.conn[config].failed_psw_attempts < o.psw_attempts)) { /* Restart OpenVPN to make another attempt to connect */ PostMessage(o.hWnd, WM_COMMAND, (WPARAM) IDM_CONNECTMENU + config, 0); @@ -589,42 +589,42 @@ void WatchOpenVPNProcess(int config) else { /* Show Status Window */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED_RECONN)); - SetStatusWinIcon(o.cnn[config].hwndStatus, ID_ICO_DISCONNECTED); - EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); - EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); - SetForegroundWindow(o.cnn[config].hwndStatus); - ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_FAILED_RECONN)); + SetStatusWinIcon(o.conn[config].hwndStatus, ID_ICO_DISCONNECTED); + EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_DISCONNECT), FALSE); + EnableWindow(GetDlgItem(o.conn[config].hwndStatus, ID_RESTART), FALSE); + SetForegroundWindow(o.conn[config].hwndStatus); + ShowWindow(o.conn[config].hwndStatus, SW_SHOW); /* Zero psw attempt counter */ - o.cnn[config].failed_psw_attempts = 0; + o.conn[config].failed_psw_attempts = 0; - ShowLocalizedMsg(IDS_NFO_RECONN_FAILED, o.cnn[config].config_name); + ShowLocalizedMsg(IDS_NFO_RECONN_FAILED, o.conn[config].config_name); /* Set connect_status = "Not Connected" */ - o.cnn[config].connect_status=DISCONNECTED; + o.conn[config].state=disconnected; /* Close Status Window */ - SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); + SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0); /* Reset restart flag */ - o.cnn[config].restart=false; + o.conn[config].restart=false; } } /* We have chosed to Disconnect */ - else if(o.cnn[config].connect_status == DISCONNECTING) + else if(o.conn[config].state == disconnecting) { /* Zero psw attempt counter */ - o.cnn[config].failed_psw_attempts = 0; + o.conn[config].failed_psw_attempts = 0; /* Set connect_status = "Not Connected" */ - o.cnn[config].connect_status=DISCONNECTED; + o.conn[config].state=disconnected; /* Change tray icon if no more connections is running */ CheckAndSetTrayIcon(); - if (o.cnn[config].restart) + if (o.conn[config].restart) { /* Restart OpenVPN */ StartOpenVPN(config); @@ -632,26 +632,26 @@ void WatchOpenVPNProcess(int config) else { /* Close Status Window */ - SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0); + SendMessage(o.conn[config].hwndStatus, WM_CLOSE, 0, 0); } } /* We have chosed to Suspend */ - else if(o.cnn[config].connect_status == SUSPENDING) + else if(o.conn[config].state == suspending) { /* Zero psw attempt counter */ - o.cnn[config].failed_psw_attempts = 0; + o.conn[config].failed_psw_attempts = 0; /* Set connect_status = "SUSPENDED" */ - o.cnn[config].connect_status=SUSPENDED; - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_SUSPENDED)); + o.conn[config].state=suspended; + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_SUSPENDED)); /* Change tray icon if no more connections is running */ CheckAndSetTrayIcon(); } /* Enable/Disable menuitems for this connections */ - SetMenuStatus(config, DISCONNECTED); + SetMenuStatus(config, disconnected); } diff --git a/options.c b/options.c index 4577e66..1cd1d4d 100644 --- a/options.c +++ b/options.c @@ -2,6 +2,7 @@ * OpenVPN-GUI -- A Windows GUI for OpenVPN. * * Copyright (C) 2004 Mathias Sundman + * 2010 Heiko Hund * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,313 +32,262 @@ #include "openvpn-gui-res.h" #include "localization.h" -extern struct options o; +#define streq(x, y) (_tcscmp((x), (y)) == 0) -void -init_options (struct options *opt) +extern options_t o; + +static int +add_option(options_t *options, int i, TCHAR **p) { - CLEAR (*opt); + if (streq(p[0], _T("help"))) + { + TCHAR caption[200]; + LoadLocalizedStringBuf(caption, _tsizeof(caption), IDS_NFO_USAGECAPTION); + MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), caption, MB_OK); + exit(0); + } + else if (streq(p[0], _T("connect")) && p[1]) + { + ++i; + static int auto_connect_nr = 0; + if (auto_connect_nr == MAX_CONFIGS) + { + /* Too many configs */ + ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); + exit(1); + } + options->auto_connect[auto_connect_nr++] = p[1]; + } + else if (streq(p[0], _T("exe_path")) && p[1]) + { + ++i; + _tcsncpy(options->exe_path, p[1], _tsizeof(options->exe_path) - 1); + } + else if (streq(p[0], _T("config_dir")) && p[1]) + { + ++i; + _tcsncpy(options->config_dir, p[1], _tsizeof(options->config_dir) - 1); + } + else if (streq(p[0], _T("ext_string")) && p[1]) + { + ++i; + _tcsncpy(options->ext_string, p[1], _tsizeof(options->ext_string) - 1); + } + else if (streq(p[0], _T("log_dir")) && p[1]) + { + ++i; + _tcsncpy(options->log_dir, p[1], _tsizeof(options->log_dir) - 1); + } + else if (streq(p[0], _T("priority_string")) && p[1]) + { + ++i; + _tcsncpy(options->priority_string, p[1], _tsizeof(options->priority_string) - 1); + } + else if (streq(p[0], _T("append_string")) && p[1]) + { + ++i; + _tcsncpy(options->append_string, p[1], _tsizeof(options->append_string) - 1); + } + else if (streq(p[0], _T("log_viewer")) && p[1]) + { + ++i; + _tcsncpy(options->log_viewer, p[1], _tsizeof(options->log_viewer) - 1); + } + else if (streq(p[0], _T("editor")) && p[1]) + { + ++i; + _tcsncpy(options->editor, p[1], _tsizeof(options->editor) - 1); + } + else if (streq(p[0], _T("allow_edit")) && p[1]) + { + ++i; + _tcsncpy(options->allow_edit, p[1], _tsizeof(options->allow_edit) - 1); + } + else if (streq(p[0], _T("allow_service")) && p[1]) + { + ++i; + _tcsncpy(options->allow_service, p[1], _tsizeof(options->allow_service) - 1); + } + else if (streq(p[0], _T("allow_password")) && p[1]) + { + ++i; + _tcsncpy(options->allow_password, p[1], _tsizeof(options->allow_password) - 1); + } + else if (streq(p[0], _T("allow_proxy")) && p[1]) + { + ++i; + _tcsncpy(options->allow_proxy, p[1], _tsizeof(options->allow_proxy) - 1); + } + else if (streq(p[0], _T("show_balloon")) && p[1]) + { + ++i; + _tcsncpy(options->show_balloon, p[1], _tsizeof(options->show_balloon) - 1); + } + else if (streq(p[0], _T("service_only")) && p[1]) + { + ++i; + _tcsncpy(options->service_only, p[1], _tsizeof(options->service_only) - 1); + } + else if (streq(p[0], _T("show_script_window")) && p[1]) + { + ++i; + _tcsncpy(options->show_script_window, p[1], _tsizeof(options->show_script_window) - 1); + } + else if (streq(p[0], _T("silent_connection")) && p[1]) + { + ++i; + _tcsncpy(options->silent_connection, p[1], _tsizeof(options->silent_connection) - 1); + } + else if (streq(p[0], _T("passphrase_attempts")) && p[1]) + { + ++i; + _tcsncpy(options->psw_attempts_string, p[1], _tsizeof(options->psw_attempts_string) - 1); + } + else if (streq(p[0], _T("connectscript_timeout")) && p[1]) + { + ++i; + _tcsncpy(options->connectscript_timeout_string, p[1], _tsizeof(options->connectscript_timeout_string) - 1); + } + else if (streq(p[0], _T("disconnectscript_timeout")) && p[1]) + { + ++i; + _tcsncpy(options->disconnectscript_timeout_string, p[1], _tsizeof(options->disconnectscript_timeout_string) - 1); + } + else if (streq(p[0], _T("preconnectscript_timeout")) && p[1]) + { + ++i; + _tcsncpy(options->preconnectscript_timeout_string, p[1], _tsizeof(options->preconnectscript_timeout_string) - 1); + } + else + { + /* Unrecognized option or missing parameter */ + ShowLocalizedMsg(IDS_ERR_BAD_OPTION, p[0]); + exit(1); + } + return i; } -int Createargcargv(struct options *options, TCHAR *command_line) + +static void +parse_argv(options_t *options, int argc, TCHAR **argv) { + int i, j; - int argc; + /* parse command line */ + for (i = 1; i < argc; ++i) + { + TCHAR *p[MAX_PARMS]; + CLEAR(p); + p[0] = argv[i]; + if (_tcsncmp(p[0], _T("--"), 2) != 0) + { + /* Missing -- before option. */ + ShowLocalizedMsg(IDS_ERR_BAD_PARAMETER, p[0]); + exit(0); + } + + p[0] += 2; + + for (j = 1; j < MAX_PARMS; ++j) + { + if (i + j < argc) + { + TCHAR *arg = argv[i + j]; + if (_tcsncmp(arg, _T("--"), 2) == 0) + break; + p[j] = arg; + } + } + i = add_option(options, i, p); + } +} + + +void +InitOptions(options_t *opt) +{ + CLEAR(*opt); +} + + +void +ProcessCommandLine(options_t *options, TCHAR *command_line) +{ TCHAR **argv; + TCHAR *pos = command_line; + int argc = 0; - TCHAR* arg; - int myindex; + /* Count the arguments */ + do + { + while (*pos == _T(' ')) + ++pos; - // count the arguments + if (*pos == _T('\0')) + break; - argc = 0; - arg = command_line; + ++argc; - while (arg[0] != 0) { + while (*pos != _T('\0') && *pos != _T(' ')) + ++pos; + } + while (*pos != _T('\0')); - while (arg[0] != 0 && arg[0] == ' ') { - arg++; - } + if (argc == 0) + return; - if (arg[0] != 0) { - - argc++; - - if (arg[0] == '\"') { - arg++; - while (arg[0] != 0 && arg[0] != '\"') { - arg++; - } - } - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - - } - - } - - // tokenize the arguments + /* Tokenize the arguments */ argv = (TCHAR**) malloc(argc * sizeof(TCHAR*)); + pos = command_line; + argc = 0; - arg = command_line; - myindex = 0; + do + { + while (*pos == _T(' ')) + pos++; - while (arg[0] != 0) { + if (*pos == _T('\0')) + break; - while (arg[0] != 0 && arg[0] == ' ') { - arg++; + if (*pos == _T('\"')) + { + argv[argc++] = ++pos; + while (*pos != _T('\0') && *pos != _T('\"')) + ++pos; + } + else + { + argv[argc++] = pos; + while (*pos != _T('\0') && *pos != _T(' ')) + ++pos; } - if (arg[0] != 0) { + if (*pos == _T('\0')) + break; - if (arg[0] == '\"') { - arg++; - argv[myindex] = arg; - myindex++; - while (arg[0] != 0 && arg[0] != '\"') { - arg++; - } - if (arg[0] != 0) { - arg[0] = 0; - arg++; - } - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - } - else { - argv[myindex] = arg; - myindex++; - while (arg[0] != 0 && arg[0] != ' ') { - arg++; - } - if (arg[0] != 0) { - arg[0] = 0; - arg++; - } - } - - - } - - } + *pos++ = _T('\0'); + } + while (*pos != _T('\0')); parse_argv(options, argc, argv); free(argv); - return(0); - } -static int -add_option (struct options *options, - int i, - TCHAR *p[]) + +/* Return num of connections with state = check */ +int +CountConnState(conn_state_t check) { + int i; + int count = 0; - if (streq (p[0], _T("help"))) + for (i = 0; i < o.num_configs; ++i) { - TCHAR usagecaption[200]; - - LoadLocalizedStringBuf(usagecaption, _tsizeof(usagecaption), IDS_NFO_USAGECAPTION); - MessageBox(NULL, LoadLocalizedString(IDS_NFO_USAGE), usagecaption, MB_OK); - exit(0); + if (o.conn[i].state == check) + ++count; } - else if (streq (p[0], _T("connect")) && p[1]) - { - ++i; - static int auto_connect_nr=0; - if (auto_connect_nr == MAX_CONFIGS) - { - /* Too many configs */ - ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); - exit(1); - } - options->auto_connect[auto_connect_nr] = p[1]; - auto_connect_nr++; - } - else if (streq (p[0], _T("exe_path")) && p[1]) - { - ++i; - _tcsncpy(options->exe_path, p[1], _tsizeof(options->exe_path) - 1); - } - else if (streq (p[0], _T("config_dir")) && p[1]) - { - ++i; - _tcsncpy(options->config_dir, p[1], _tsizeof(options->config_dir) - 1); - } - else if (streq (p[0], _T("ext_string")) && p[1]) - { - ++i; - _tcsncpy(options->ext_string, p[1], _tsizeof(options->ext_string) - 1); - } - else if (streq (p[0], _T("log_dir")) && p[1]) - { - ++i; - _tcsncpy(options->log_dir, p[1], _tsizeof(options->log_dir) - 1); - } - else if (streq (p[0], _T("priority_string")) && p[1]) - { - ++i; - _tcsncpy(options->priority_string, p[1], _tsizeof(options->priority_string) - 1); - } - else if (streq (p[0], _T("append_string")) && p[1]) - { - ++i; - _tcsncpy(options->append_string, p[1], _tsizeof(options->append_string) - 1); - } - else if (streq (p[0], _T("log_viewer")) && p[1]) - { - ++i; - _tcsncpy(options->log_viewer, p[1], _tsizeof(options->log_viewer) - 1); - } - else if (streq (p[0], _T("editor")) && p[1]) - { - ++i; - _tcsncpy(options->editor, p[1], _tsizeof(options->editor) - 1); - } - else if (streq (p[0], _T("allow_edit")) && p[1]) - { - ++i; - _tcsncpy(options->allow_edit, p[1], _tsizeof(options->allow_edit) - 1); - } - else if (streq (p[0], _T("allow_service")) && p[1]) - { - ++i; - _tcsncpy(options->allow_service, p[1], _tsizeof(options->allow_service) - 1); - } - else if (streq (p[0], _T("allow_password")) && p[1]) - { - ++i; - _tcsncpy(options->allow_password, p[1], _tsizeof(options->allow_password) - 1); - } - else if (streq (p[0], _T("allow_proxy")) && p[1]) - { - ++i; - _tcsncpy(options->allow_proxy, p[1], _tsizeof(options->allow_proxy) - 1); - } - else if (streq (p[0], _T("show_balloon")) && p[1]) - { - ++i; - _tcsncpy(options->show_balloon, p[1], _tsizeof(options->show_balloon) - 1); - } - else if (streq (p[0], _T("service_only")) && p[1]) - { - ++i; - _tcsncpy(options->service_only, p[1], _tsizeof(options->service_only) - 1); - } - else if (streq (p[0], _T("show_script_window")) && p[1]) - { - ++i; - _tcsncpy(options->show_script_window, p[1], _tsizeof(options->show_script_window) - 1); - } - else if (streq (p[0], _T("silent_connection")) && p[1]) - { - ++i; - _tcsncpy(options->silent_connection, p[1], _tsizeof(options->silent_connection) - 1); - } - else if (streq (p[0], _T("passphrase_attempts")) && p[1]) - { - ++i; - _tcsncpy(options->psw_attempts_string, p[1], _tsizeof(options->psw_attempts_string) - 1); - } - else if (streq (p[0], _T("connectscript_timeout")) && p[1]) - { - ++i; - _tcsncpy(options->connectscript_timeout_string, p[1], _tsizeof(options->connectscript_timeout_string) - 1); - } - else if (streq (p[0], _T("disconnectscript_timeout")) && p[1]) - { - ++i; - _tcsncpy(options->disconnectscript_timeout_string, p[1], - _tsizeof(options->disconnectscript_timeout_string) - 1); - } - else if (streq (p[0], _T("preconnectscript_timeout")) && p[1]) - { - ++i; - _tcsncpy(options->preconnectscript_timeout_string, p[1], - _tsizeof(options->preconnectscript_timeout_string) - 1); - } - else - { - /* Unrecognized option or missing parameter */ - ShowLocalizedMsg(IDS_ERR_BAD_OPTION, p[0]); - exit(1); - } - return i; -} - -void -parse_argv (struct options* options, - int argc, - TCHAR *argv[]) -{ - int i, j; - - /* parse command line */ - for (i = 1; i < argc; ++i) - { - TCHAR *p[MAX_PARMS]; - CLEAR (p); - p[0] = argv[i]; - if (_tcsncmp(p[0], _T("--"), 2)) - { - /* Missing -- before option. */ - ShowLocalizedMsg(IDS_ERR_BAD_PARAMETER, p[0]); - exit(0); - } - else - p[0] += 2; - - for (j = 1; j < MAX_PARMS; ++j) - { - if (i + j < argc) - { - TCHAR *arg = argv[i + j]; - if (_tcsncmp (arg, _T("--"), 2)) - p[j] = arg; - else - break; - } - } - i = add_option (options, i, p); - } -} - -/* - * Returns TRUE if option exist in config file. - */ -int ConfigFileOptionExist(int config, const char *option) -{ - FILE *fp; - char line[256]; - TCHAR configfile_path[MAX_PATH]; - - _tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path)); - if (configfile_path[_tcslen(configfile_path) - 1] != _T('\\')) - _tcscat(configfile_path, _T("\\")); - _tcsncat(configfile_path, o.cnn[config].config_file, - _tsizeof(configfile_path) - _tcslen(configfile_path) - 1); - - if (!(fp=_tfopen(configfile_path, _T("r")))) - { - /* can't open config file */ - ShowLocalizedMsg(IDS_ERR_OPEN_CONFIG, configfile_path); - return(0); - } - - while (fgets(line, sizeof (line), fp)) - { - if ((strncmp(line, option, sizeof(option)) == 0)) - { - fclose(fp); - return(1); - } - } - - fclose(fp); - return(0); + return count; } diff --git a/options.h b/options.h index a1fbb64..93b57dd 100644 --- a/options.h +++ b/options.h @@ -2,6 +2,7 @@ * OpenVPN-GUI -- A Windows GUI for OpenVPN. * * Copyright (C) 2004 Mathias Sundman + * 2010 Heiko Hund * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +21,9 @@ * */ +#ifndef OPTIONS_H +#define OPTIONS_H + #include #include @@ -27,110 +31,123 @@ * Maximum number of parameters associated with an option, * including the option name itself. */ -#define MAX_PARMS 5 -#define MAX_CONFIGS 50 /* Max number of config-files to read. */ -#define MAX_CONFIG_SUBDIRS 50 /* Max number of subdirs to scan */ +#define MAX_PARMS 5 /* May number of parameters per option */ +#define MAX_CONFIGS 50 /* Max number of config-files to read */ +#define MAX_CONFIG_SUBDIRS 50 /* Max number of subdirs to scan for configs */ -/* connect_status STATES */ -#define DISCONNECTED 0 -#define CONNECTING 1 -#define CONNECTED 2 -#define RECONNECTING 3 -#define DISCONNECTING 4 -#define SUSPENDING 5 -#define SUSPENDED 6 -/* OpenVPN Service STATES */ -#define SERVICE_NOACCESS -1 -#define SERVICE_DISCONNECTED 0 -#define SERVICE_CONNECTING 1 -#define SERVICE_CONNECTED 2 +/* connection states */ +typedef enum { + disconnected, + connecting, + reconnecting, + connected, + disconnecting, + suspending, + suspended +} conn_state_t; /* Connections parameters */ -typedef struct -{ - TCHAR config_file[MAX_PATH]; /* Name of the config file */ - TCHAR config_name[MAX_PATH]; /* Name of the connection */ - TCHAR config_dir[MAX_PATH]; /* Path to this configs dir */ - TCHAR log_path[MAX_PATH]; /* Path to Logfile */ - TCHAR ip[16]; /* Assigned IP address for this connection */ - TCHAR exit_event_name[50]; /* Exit Event name for this connection */ - int connect_status; /* 0=Not Connected 1=Connecting - 2=Connected 3=Reconnecting 4=Disconnecting */ - int auto_connect; /* true=AutoConnect at startup */ - int failed_psw; /* 1=OpenVPN failed because of wrong psw */ - int failed_psw_attempts; /* # of failed attempts maid to enter psw */ - int restart; /* true=Restart connection after termination */ - time_t connected_since; /* Time when the connection was established */ +typedef struct { + TCHAR config_file[MAX_PATH]; /* Name of the config file */ + TCHAR config_name[MAX_PATH]; /* Name of the connection */ + TCHAR config_dir[MAX_PATH]; /* Path to this configs dir */ + TCHAR log_path[MAX_PATH]; /* Path to Logfile */ + TCHAR ip[16]; /* Assigned IP address for this connection */ + TCHAR exit_event_name[50]; /* Exit Event name for this connection */ + BOOL auto_connect; /* AutoConnect at startup id TRUE */ + BOOL restart; /* Restart connection after termination if TRUE*/ + BOOL failed_psw; /* TRUE if OpenVPN failed because of wrong psw */ + conn_state_t state; /* State the connection currently is in */ + int failed_psw_attempts; /* # of failed attempts made to enter psw */ + time_t connected_since; /* Time when the connection was established */ - HANDLE exit_event; - HANDLE hProcess; - HANDLE hStdOut; - HANDLE hStdIn; - HWND hwndStatus; /* Handle to Status Dialog Window */ + HANDLE exit_event; + HANDLE hProcess; + HANDLE hStdOut; + HANDLE hStdIn; + HWND hwndStatus; } connection_t; + +typedef enum { + service_noaccess = -1, + service_disconnected = 0, + service_connecting = 1, + service_connected = 2 +} service_state_t; + +typedef enum { + config, + browser, + manual +} proxy_source_t; + +typedef enum { + http, + socks +} proxy_t; + /* All options used within OpenVPN GUI */ -struct options -{ - /* Array of configs to autostart */ - const TCHAR *auto_connect[MAX_CONFIGS]; +typedef struct { + /* Array of configs to autostart */ + const TCHAR *auto_connect[MAX_CONFIGS]; - /* Connection parameters */ - connection_t cnn[MAX_CONFIGS]; /* Connection structure */ - int num_configs; /* Number of configs */ + /* Connection parameters */ + connection_t conn[MAX_CONFIGS]; /* Connection structure */ + int num_configs; /* Number of configs */ - int oldversion; /* 1=OpenVPN version below 2.0-beta6 */ - char connect_string[100]; /* String to look for to report connected */ - int psw_attempts; /* Number of psw attemps to allow */ - int connectscript_timeout; /* Connect Script execution timeout (sec) */ - int disconnectscript_timeout; /* Disconnect Script execution timeout (sec) */ - int preconnectscript_timeout; /* Preconnect Script execution timeout (sec) */ - int service_running; /* true if OpenVPN Service is started */ - HWND hWnd; /* Main Window Handle */ - HINSTANCE hInstance; + BOOL oldversion; /* OpenVPN version below 2.0-beta6 if TRUE */ + service_state_t service_state; /* State of the OpenVPN Service */ + char connect_string[100]; /* String to look for to report connected */ + int psw_attempts; /* Number of psw attemps to allow */ + int connectscript_timeout; /* Connect Script execution timeout (sec) */ + int disconnectscript_timeout; /* Disconnect Script execution timeout (sec) */ + int preconnectscript_timeout; /* Preconnect Script execution timeout (sec) */ - /* Registry values */ - TCHAR exe_path[MAX_PATH]; - TCHAR config_dir[MAX_PATH]; - TCHAR ext_string[16]; - TCHAR log_dir[MAX_PATH]; - TCHAR priority_string[64]; - TCHAR append_string[2]; - TCHAR log_viewer[MAX_PATH]; - TCHAR editor[MAX_PATH]; - TCHAR allow_edit[2]; - TCHAR allow_service[2]; - TCHAR allow_password[2]; - TCHAR allow_proxy[2]; - TCHAR silent_connection[2]; - TCHAR service_only[2]; - TCHAR show_balloon[2]; - TCHAR show_script_window[2]; - TCHAR psw_attempts_string[2]; - TCHAR disconnect_on_suspend[2]; - TCHAR connectscript_timeout_string[4]; - TCHAR disconnectscript_timeout_string[4]; - TCHAR preconnectscript_timeout_string[4]; + /* Proxy Settings */ + proxy_source_t proxy_source; /* Where to get proxy information from */ + proxy_t proxy_type; /* The type of proxy to use */ + BOOL proxy_http_auth; /* TRUE is proxy authentication is used */ + TCHAR proxy_http_address[100]; /* HTTP Proxy Address */ + TCHAR proxy_http_port[6]; /* HTTP Proxy Port */ + TCHAR proxy_socks_address[100]; /* SOCKS Proxy Address */ + TCHAR proxy_socks_port[6]; /* SOCKS Proxy Address */ + TCHAR proxy_authfile[100]; /* Path to proxy auth file */ - /* Proxy Settings */ - int proxy_source; /* 0=OpenVPN config, 1=IE, 2=Manual */ - int proxy_type; /* 0=HTTP, 1=SOCKS */ - int proxy_http_auth; /* 0=Auth Disabled, 1=Auth Enabled */ - TCHAR proxy_http_address[100]; /* HTTP Proxy Address */ - TCHAR proxy_http_port[6]; /* HTTP Proxy Port */ - TCHAR proxy_socks_address[100]; /* SOCKS Proxy Address */ - TCHAR proxy_socks_port[6]; /* SOCKS Proxy Address */ - TCHAR proxy_authfile[100]; /* Path to proxy auth file */ + /* Registry values */ + TCHAR exe_path[MAX_PATH]; + TCHAR config_dir[MAX_PATH]; + TCHAR ext_string[16]; + TCHAR log_dir[MAX_PATH]; + TCHAR priority_string[64]; + TCHAR append_string[2]; + TCHAR log_viewer[MAX_PATH]; + TCHAR editor[MAX_PATH]; + TCHAR allow_edit[2]; + TCHAR allow_service[2]; + TCHAR allow_password[2]; + TCHAR allow_proxy[2]; + TCHAR silent_connection[2]; + TCHAR service_only[2]; + TCHAR show_balloon[2]; + TCHAR show_script_window[2]; + TCHAR psw_attempts_string[2]; + TCHAR disconnect_on_suspend[2]; + TCHAR connectscript_timeout_string[4]; + TCHAR disconnectscript_timeout_string[4]; + TCHAR preconnectscript_timeout_string[4]; - /* Debug file pointer */ #ifdef DEBUG - FILE *debug_fp; + FILE *debug_fp; #endif -}; -#define streq(x, y) (!_tcscmp((x), (y))) -void init_options (struct options *o); -int Createargcargv(struct options* options, TCHAR* command_line); -void parse_argv (struct options* options, int argc, TCHAR *argv[]); -int ConfigFileOptionExist(int config, const char *option); + HWND hWnd; + HINSTANCE hInstance; +} options_t; + +void InitOptions(options_t *); +void ProcessCommandLine(options_t *, TCHAR *); +int CountConnState(conn_state_t); + +#endif diff --git a/passphrase.c b/passphrase.c index f2eb6f6..5374b13 100644 --- a/passphrase.c +++ b/passphrase.c @@ -37,7 +37,7 @@ #endif WCHAR passphrase[256]; -extern struct options o; +extern options_t o; int ConvertUnicode2Ascii(WCHAR str_unicode[], char str_ascii[], unsigned int str_ascii_size) { @@ -85,14 +85,14 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config) CLEAR(passphrase_ascii); ConvertUnicode2Ascii(passphrase, passphrase_ascii, sizeof(passphrase_ascii)); - if (!WriteFile(o.cnn[config].hStdIn, passphrase_ascii, + if (!WriteFile(o.conn[config].hStdIn, passphrase_ascii, strlen(passphrase_ascii), &nCharsWritten, NULL)) { /* PassPhrase -> stdin failed */ ShowLocalizedMsg(IDS_ERR_PASSPHRASE2STDIN); } } - if (!WriteFile(o.cnn[config].hStdIn, "\r\n", + if (!WriteFile(o.conn[config].hStdIn, "\r\n", 2, &nCharsWritten, NULL)) { /* CR -> stdin failed */ @@ -120,7 +120,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config) CLEAR(passphrase_ascii); ConvertUnicode2Ascii(passphrase, passphrase_ascii, sizeof(passphrase_ascii)); - if (!WriteFile(o.cnn[config].hStdIn, passphrase_ascii, + if (!WriteFile(o.conn[config].hStdIn, passphrase_ascii, strlen(passphrase_ascii), &nCharsWritten, NULL)) { /* PassPhrase -> stdin failed */ @@ -129,7 +129,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config) } else { - if (!WriteFile(o.cnn[config].hStdIn, "\n", + if (!WriteFile(o.conn[config].hStdIn, "\n", 1, &nCharsWritten, NULL)) { /* CR -> stdin failed */ @@ -163,7 +163,7 @@ void CheckAuthUsernamePrompt (char *line, int config) if (strlen(user_auth.username) > 0) { - if (!WriteFile(o.cnn[config].hStdIn, user_auth.username, + if (!WriteFile(o.conn[config].hStdIn, user_auth.username, strlen(user_auth.username), &nCharsWritten, NULL)) { ShowLocalizedMsg(IDS_ERR_AUTH_USERNAME2STDIN); @@ -171,7 +171,7 @@ void CheckAuthUsernamePrompt (char *line, int config) } else { - if (!WriteFile(o.cnn[config].hStdIn, "\n", + if (!WriteFile(o.conn[config].hStdIn, "\n", 1, &nCharsWritten, NULL)) { ShowLocalizedMsg(IDS_ERR_CR2STDIN); @@ -180,7 +180,7 @@ void CheckAuthUsernamePrompt (char *line, int config) if (strlen(user_auth.password) > 0) { - if (!WriteFile(o.cnn[config].hStdIn, user_auth.password, + if (!WriteFile(o.conn[config].hStdIn, user_auth.password, strlen(user_auth.password), &nCharsWritten, NULL)) { ShowLocalizedMsg(IDS_ERR_AUTH_PASSWORD2STDIN); @@ -188,7 +188,7 @@ void CheckAuthUsernamePrompt (char *line, int config) } else { - if (!WriteFile(o.cnn[config].hStdIn, "\n", + if (!WriteFile(o.conn[config].hStdIn, "\n", 1, &nCharsWritten, NULL)) { ShowLocalizedMsg(IDS_ERR_CR2STDIN); @@ -331,7 +331,7 @@ void ChangePassphraseThread(int config) int keyfile_format=0; /* Cut of extention from config filename. */ - _tcsncpy(conn_name, o.cnn[config].config_file, _tsizeof(conn_name)); + _tcsncpy(conn_name, o.conn[config].config_file, _tsizeof(conn_name)); conn_name[_tcslen(conn_name) - (_tcslen(o.ext_string)+1)]=0; /* Get Key filename from config file */ @@ -594,7 +594,7 @@ int ParseKeyFilenameLine(int config, TCHAR *keyfilename, size_t keyfilenamesize, /* Prepend filename with configdir path if needed */ if ((keyfilename[0] != '\\') && (keyfilename[0] != '/') && (keyfilename[1] != ':')) { - _tcsncpy(temp_filename, o.cnn[config].config_dir, _tsizeof(temp_filename)); + _tcsncpy(temp_filename, o.conn[config].config_dir, _tsizeof(temp_filename)); if (temp_filename[_tcslen(temp_filename) - 1] != '\\') _tcscat(temp_filename, _T("\\")); _tcsncat(temp_filename, keyfilename, @@ -820,10 +820,10 @@ int GetKeyFilename(int config, TCHAR *keyfilename, size_t keyfilenamesize, int * int found_pkcs12=0; TCHAR configfile_path[MAX_PATH]; - _tcsncpy(configfile_path, o.cnn[config].config_dir, _tsizeof(configfile_path)); + _tcsncpy(configfile_path, o.conn[config].config_dir, _tsizeof(configfile_path)); if (!(configfile_path[_tcslen(configfile_path)-1] == '\\')) _tcscat(configfile_path, _T("\\")); - _tcsncat(configfile_path, o.cnn[config].config_file, + _tcsncat(configfile_path, o.conn[config].config_file, _tsizeof(configfile_path) - _tcslen(configfile_path) - 1); if (!(fp=_tfopen(configfile_path, _T("r")))) diff --git a/proxy.c b/proxy.c index 028f892..7480f1f 100644 --- a/proxy.c +++ b/proxy.c @@ -33,7 +33,7 @@ #include "openvpn-gui-res.h" #include "localization.h" -extern struct options o; +extern options_t o; bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) { @@ -181,7 +181,7 @@ int CheckProxySettings(HWND hwndDlg) void LoadProxySettings(HWND hwndDlg) { /* Set Proxy type, address and port */ - if (o.proxy_type == 0) /* HTTP Proxy */ + if (o.proxy_type == http) /* HTTP Proxy */ { CheckRadioButton(hwndDlg, ID_RB_PROXY_HTTP, ID_RB_PROXY_SOCKS, ID_RB_PROXY_HTTP); SetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address); @@ -197,11 +197,11 @@ void LoadProxySettings(HWND hwndDlg) if (o.proxy_http_auth) CheckDlgButton(hwndDlg, ID_CB_PROXY_AUTH, BST_CHECKED); /* Set Proxy Settings Source */ - if (o.proxy_source == 0) + if (o.proxy_source == config) SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_OPENVPN), BM_CLICK, 0, 0); - if (o.proxy_source == 1) + if (o.proxy_source == browser) SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MSIE), BM_CLICK, 0, 0); - if (o.proxy_source == 2) + if (o.proxy_source == manual) SendMessage(GetDlgItem(hwndDlg, ID_RB_PROXY_MANUAL), BM_CLICK, 0, 0); } @@ -216,24 +216,24 @@ void SaveProxySettings(HWND hwndDlg) /* Save Proxy Settings Source */ if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_OPENVPN) == BST_CHECKED) { - o.proxy_source = 0; + o.proxy_source = config; proxy_source_string[0] = _T('0'); } if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED) { - o.proxy_source = 1; + o.proxy_source = browser; proxy_source_string[0] = _T('1'); } if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED) { - o.proxy_source = 2; + o.proxy_source = manual; proxy_source_string[0] = _T('2'); } /* Save Proxy type, address and port */ if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_HTTP) == BST_CHECKED) { - o.proxy_type = 0; + o.proxy_type = http; proxy_type_string[0] = _T('0'); GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_http_address, @@ -247,7 +247,7 @@ void SaveProxySettings(HWND hwndDlg) } else { - o.proxy_type = 1; + o.proxy_type = socks; proxy_type_string[0] = _T('1'); GetDlgItemText(hwndDlg, ID_EDT_PROXY_ADDRESS, o.proxy_socks_address, @@ -332,17 +332,17 @@ void GetProxyRegistrySettings() _tsizeof(proxy_http_auth_string)); if (proxy_source_string[0] == _T('1')) - o.proxy_source=1; + o.proxy_source = config; if (proxy_source_string[0] == _T('2')) - o.proxy_source=2; + o.proxy_source = browser; if (proxy_source_string[0] == _T('3')) - o.proxy_source=3; + o.proxy_source = manual; if (proxy_type_string[0] == _T('1')) - o.proxy_type=1; + o.proxy_type = socks; if (proxy_http_auth_string[0] == _T('1')) - o.proxy_http_auth=1; + o.proxy_http_auth = TRUE; RegCloseKey(regkey); } @@ -467,11 +467,11 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size) CLEAR(proxy_string); - if (o.proxy_source == PROXY_SOURCE_MANUAL) + if (o.proxy_source == manual) { - if (o.proxy_type == PROXY_TYPE_HTTP) + if (o.proxy_type == http) { - if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) + if (o.proxy_http_auth) { /* Ask for Proxy username/password */ LocalizedDialogBox(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc); @@ -487,7 +487,7 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size) o.proxy_http_port); } } - if (o.proxy_type == PROXY_TYPE_SOCKS) + if (o.proxy_type == socks) { _sntprintf_0(proxy_string, _T("--socks-proxy %s %s"), o.proxy_socks_address, @@ -495,7 +495,7 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size) } } - else if (o.proxy_source == PROXY_SOURCE_IE) + else if (o.proxy_source == browser) { TCHAR host[64]; TCHAR port[6]; @@ -504,7 +504,7 @@ void ConstructProxyCmdLine(TCHAR *proxy_string_ptr, unsigned int size) if (GetIeHttpProxy(host, &hostlen, port, &portlen) && hostlen != 0) { - if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) + if (o.proxy_http_auth) { /* Ask for Proxy username/password */ LocalizedDialogBox(ID_DLG_PROXY_AUTH, ProxyAuthDialogFunc); diff --git a/proxy.h b/proxy.h index accff40..7a2fba2 100644 --- a/proxy.h +++ b/proxy.h @@ -19,14 +19,6 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define PROXY_SOURCE_OPENVPN 0 -#define PROXY_SOURCE_IE 1 -#define PROXY_SOURCE_MANUAL 2 -#define PROXY_TYPE_HTTP 0 -#define PROXY_TYPE_SOCKS 1 -#define PROXY_HTTP_NO_AUTH 0 -#define PROXY_HTTP_ASK_AUTH 1 - BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); int CheckProxySettings(HWND hwndDlg); void LoadProxySettings(HWND hwndDlg); diff --git a/registry.c b/registry.c index 1f00136..e4e35e9 100644 --- a/registry.c +++ b/registry.c @@ -32,7 +32,7 @@ #include "registry.h" #include "localization.h" -extern struct options o; +extern options_t o; int GetRegistryKeys() diff --git a/scripts.c b/scripts.c index 9aad6ec..0c68dc4 100644 --- a/scripts.c +++ b/scripts.c @@ -29,7 +29,7 @@ #include "options.h" #include "localization.h" -extern struct options o; +extern options_t o; void RunConnectScript(int config, int run_as_service) { @@ -45,10 +45,10 @@ void RunConnectScript(int config, int run_as_service) int i, TimeOut; /* Cut of extention from config filename and add "_up.bat". */ - _tcsncpy(batch_file, o.cnn[config].config_file, _tsizeof(batch_file)); + _tcsncpy(batch_file, o.conn[config].config_file, _tsizeof(batch_file)); batch_file[_tcslen(batch_file) - (_tcslen(o.ext_string)+1)]=0; _tcsncat(batch_file, _T("_up.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1); - _sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); + _sntprintf_0(command_line, _T("%s\\%s"), o.conn[config].config_dir, batch_file); /* Return if no script exists */ @@ -63,7 +63,7 @@ void RunConnectScript(int config, int run_as_service) if (!run_as_service) { /* UserInfo: Connect Script running */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT)); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONN_SCRIPT)); } CLEAR (start_info); @@ -87,7 +87,7 @@ void RunConnectScript(int config, int run_as_service) ((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE : (DWORD) CREATE_NO_WINDOW), NULL, - o.cnn[config].config_dir, //start-up dir + o.conn[config].config_dir, //start-up dir &start_info, &proc_info)) { @@ -146,9 +146,9 @@ void RunDisconnectScript(int config, int run_as_service) int i, TimeOut; /* Append "_down.bat" to config name. */ - _tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file)); + _tcsncpy(batch_file, o.conn[config].config_name, _tsizeof(batch_file)); _tcsncat(batch_file, _T("_down.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1); - _sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); + _sntprintf_0(command_line, _T("%s\\%s"), o.conn[config].config_dir, batch_file); /* Return if no script exists */ @@ -163,7 +163,7 @@ void RunDisconnectScript(int config, int run_as_service) if (!run_as_service) { /* UserInfo: Disconnect Script running */ - SetDlgItemText(o.cnn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONN_SCRIPT)); + SetDlgItemText(o.conn[config].hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_DISCONN_SCRIPT)); } CLEAR (start_info); @@ -187,7 +187,7 @@ void RunDisconnectScript(int config, int run_as_service) ((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE : (DWORD) CREATE_NO_WINDOW), NULL, - o.cnn[config].config_dir, //start-up dir + o.conn[config].config_dir, //start-up dir &start_info, &proc_info)) { @@ -226,9 +226,9 @@ void RunPreconnectScript(int config) int i, TimeOut; /* Append "_pre.bat" to config name. */ - _tcsncpy(batch_file, o.cnn[config].config_name, _tsizeof(batch_file)); + _tcsncpy(batch_file, o.conn[config].config_name, _tsizeof(batch_file)); _tcsncat(batch_file, _T("_pre.bat"), _tsizeof(batch_file) - _tcslen(batch_file) - 1); - _sntprintf_0(command_line, _T("%s\\%s"), o.cnn[config].config_dir, batch_file); + _sntprintf_0(command_line, _T("%s\\%s"), o.conn[config].config_dir, batch_file); /* Return if no script exists */ @@ -261,7 +261,7 @@ void RunPreconnectScript(int config) ((o.show_script_window[0] == '1') ? (DWORD) CREATE_NEW_CONSOLE : (DWORD) CREATE_NO_WINDOW), NULL, - o.cnn[config].config_dir, //start-up dir + o.conn[config].config_dir, //start-up dir &start_info, &proc_info)) { diff --git a/service.c b/service.c index e75a339..21f14e2 100644 --- a/service.c +++ b/service.c @@ -32,7 +32,7 @@ #include "openvpn-gui-res.h" #include "localization.h" -extern struct options o; +extern options_t o; int MyStartService() { @@ -46,7 +46,7 @@ int MyStartService() int i; /* Set Service Status = Connecting */ - o.service_running = SERVICE_CONNECTING; + o.service_state = service_connecting; SetServiceMenuStatus(); CheckAndSetTrayIcon(); @@ -157,7 +157,7 @@ int MyStartService() RunConnectScript(i, true); /* Set Service Status = Connected */ - o.service_running = SERVICE_CONNECTED; + o.service_state = service_connected; SetServiceMenuStatus(); CheckAndSetTrayIcon(); @@ -169,7 +169,7 @@ int MyStartService() failed: /* Set Service Status = Disconnecting */ - o.service_running = SERVICE_DISCONNECTED; + o.service_state = service_disconnected; SetServiceMenuStatus(); CheckAndSetTrayIcon(); return(false); @@ -220,7 +220,7 @@ int MyStopService() return(false); } - o.service_running = SERVICE_DISCONNECTED; + o.service_state = service_disconnected; SetServiceMenuStatus(); CheckAndSetTrayIcon(); return(true); @@ -253,7 +253,7 @@ int CheckServiceStatus() SC_MANAGER_CONNECT); // Connect rights if (NULL == schSCManager) { - o.service_running = SERVICE_NOACCESS; + o.service_state = service_noaccess; SetServiceMenuStatus(); return(false); } @@ -266,7 +266,7 @@ int CheckServiceStatus() if (schService == NULL) { /* open vpn service failed */ ShowLocalizedMsg(IDS_ERR_OPEN_VPN_SERVICE); - o.service_running = SERVICE_NOACCESS; + o.service_state = service_noaccess; SetServiceMenuStatus(); return(false); } @@ -282,16 +282,16 @@ int CheckServiceStatus() if (ssStatus.dwCurrentState == SERVICE_RUNNING) { - o.service_running = SERVICE_CONNECTED; + o.service_state = service_connected; SetServiceMenuStatus(); - SetTrayIcon(CONNECTED); + SetTrayIcon(connected); return(true); } else { - o.service_running = SERVICE_DISCONNECTED; + o.service_state = service_disconnected; SetServiceMenuStatus(); - SetTrayIcon(DISCONNECTED); + SetTrayIcon(disconnected); return(false); } } diff --git a/tray.c b/tray.c index 33e525a..01a641b 100644 --- a/tray.c +++ b/tray.c @@ -50,7 +50,7 @@ HMENU hMenuConn[MAX_CONFIGS]; HMENU hMenuService; NOTIFYICONDATA ni; -extern struct options o; +extern options_t o; // Mouse clicks on tray void OnNotifyTray(LPARAM lParam) @@ -63,7 +63,7 @@ void OnNotifyTray(LPARAM lParam) switch(lParam) { case WM_RBUTTONDOWN: /* Re-read configs and re-create menus if no connection is running */ - if (CountConnectedState(DISCONNECTED) == o.num_configs) + if (CountConnState(disconnected) == o.num_configs) { DestroyPopupMenus(); BuildFileList(); @@ -82,11 +82,11 @@ void OnNotifyTray(LPARAM lParam) if (o.service_only[0]=='1') { /* Start OpenVPN Service */ - if (o.service_running == SERVICE_DISCONNECTED) + if (o.service_state == service_disconnected) { MyStartService(); } - else if (o.service_running == SERVICE_CONNECTED) + else if (o.service_state == service_connected) { /* Stop OpenVPN service */ if (MessageBox(NULL, LoadLocalizedString(IDS_MENU_ASK_STOP_SERVICE), _T(PACKAGE_NAME), MB_YESNO | MB_SETFOREGROUND) == IDYES) @@ -101,7 +101,7 @@ void OnNotifyTray(LPARAM lParam) connected_config = -1; for (i=0; i < o.num_configs; i++) { - if(o.cnn[i].connect_status != DISCONNECTED) + if(o.conn[i].state != disconnected) { if (connected_config == -1) { @@ -116,19 +116,19 @@ void OnNotifyTray(LPARAM lParam) } if (connected_config != -1) { - ShowWindow(o.cnn[connected_config].hwndStatus, SW_SHOW); - SetForegroundWindow(o.cnn[connected_config].hwndStatus); + ShowWindow(o.conn[connected_config].hwndStatus, SW_SHOW); + SetForegroundWindow(o.conn[connected_config].hwndStatus); } /* Re-read configs and re-create menus if no connection is running */ - if (CountConnectedState(DISCONNECTED) == o.num_configs) + if (CountConnState(disconnected) == o.num_configs) { DestroyPopupMenus(); BuildFileList(); CreatePopupMenus(); /* Start connection if only one config exist */ - if ((o.num_configs == 1) && (o.cnn[0].connect_status == DISCONNECTED)) + if ((o.num_configs == 1) && (o.conn[0].state == disconnected)) StartOpenVPN(0); } } @@ -152,7 +152,6 @@ void OnDestroyTray() void CreatePopupMenus() { int i; - //extern struct options o; /* Create Main menu */ hMenu=CreatePopupMenu(); @@ -230,14 +229,14 @@ void CreateItemList() AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, LoadLocalizedString(IDS_MENU_ABOUT)); AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDS_MENU_CLOSE)); - SetMenuStatus(0, DISCONNECTED); + SetMenuStatus(0, disconnected); } else { /* Create Main menu with all connections */ for (i=0; i < o.num_configs; i++) - AppendMenu(hMenu,MF_POPUP,(UINT) hMenuConn[i],o.cnn[i].config_name); + AppendMenu(hMenu,MF_POPUP,(UINT) hMenuConn[i],o.conn[i].config_name); if (o.num_configs > 0) AppendMenu(hMenu,MF_SEPARATOR,0,0); if (o.allow_service[0]=='1' && o.service_only[0]=='0') @@ -279,7 +278,7 @@ void CreateItemList() } #endif - SetMenuStatus(i, DISCONNECTED); + SetMenuStatus(i, disconnected); } } @@ -331,7 +330,7 @@ void ShowTrayIcon() * connected=1 -> Connecting * connected=2 -> Connected */ -void SetTrayIcon(int connected) +void SetTrayIcon(conn_state_t connected) { TCHAR msg[500]; TCHAR msg_connected[100]; @@ -353,14 +352,14 @@ void SetTrayIcon(int connected) first_conn=1; for (i=0; i < o.num_configs; i++) { - if(o.cnn[i].connect_status == CONNECTED) + if(o.conn[i].state == connected) { /* Append connection name to Icon Tip Msg */ if (first_conn) _tcsncat(msg, msg_connected, _tsizeof(msg) - _tcslen(msg) - 1); else _tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1); - _tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); + _tcsncat(msg, o.conn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); first_conn=0; config=i; } @@ -369,32 +368,32 @@ void SetTrayIcon(int connected) first_conn=1; for (i=0; i < o.num_configs; i++) { - if((o.cnn[i].connect_status == CONNECTING) || - (o.cnn[i].connect_status == RECONNECTING)) + if((o.conn[i].state == connecting) || + (o.conn[i].state == reconnecting)) { /* Append connection name to Icon Tip Msg */ if (first_conn) _tcsncat(msg, msg_connecting, _tsizeof(msg) - _tcslen(msg) - 1); else _tcsncat(msg, _T(", "), _tsizeof(msg) - _tcslen(msg) - 1); - _tcsncat(msg, o.cnn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); + _tcsncat(msg, o.conn[i].config_name, _tsizeof(msg) - _tcslen(msg) - 1); first_conn=0; } } - if (CountConnectedState(CONNECTED) == 1) + if (CountConnState(connected) == 1) { /* Append "Connected Since and Assigned IP msg" */ time_t con_time; con_time=time(NULL); _tcsftime(connected_since, _tsizeof(connected_since), _T("%b %d, %H:%M"), - localtime(&o.cnn[config].connected_since)); + localtime(&o.conn[config].connected_since)); _tcsncat(msg, LoadLocalizedString(IDS_TIP_CONNECTED_SINCE), _tsizeof(msg) - _tcslen(msg) - 1); _tcsncat(msg, connected_since, _tsizeof(msg) - _tcslen(msg) - 1); - if (_tcslen(o.cnn[config].ip) > 0) + if (_tcslen(o.conn[config].ip) > 0) { TCHAR assigned_ip[100]; - _sntprintf_0(assigned_ip, LoadLocalizedString(IDS_TIP_ASSIGNED_IP), o.cnn[config].ip); + _sntprintf_0(assigned_ip, LoadLocalizedString(IDS_TIP_ASSIGNED_IP), o.conn[config].ip); _tcsncat(msg, assigned_ip, _tsizeof(msg) - _tcslen(msg) - 1); } } @@ -427,7 +426,7 @@ void ShowTrayBalloon(TCHAR *infotitle_msg, TCHAR *info_msg) } -void SetMenuStatus (int config, int bCheck) +void SetMenuStatus (int config, conn_state_t state) { /* bCheck values: * 0 - Not Connected @@ -441,25 +440,25 @@ void SetMenuStatus (int config, int bCheck) if (o.num_configs == 1) { - if (bCheck == DISCONNECTED) + if (state == disconnected) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_GRAYED); } - if (bCheck == CONNECTING) + if (state == connecting) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED); } - if (bCheck == CONNECTED) + if (state == connected) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_ENABLED); EnableMenuItem(hMenu, IDM_STATUSMENU, MF_ENABLED); } - if (bCheck == DISCONNECTING) + if (state == disconnecting) { EnableMenuItem(hMenu, IDM_CONNECTMENU, MF_GRAYED); EnableMenuItem(hMenu, IDM_DISCONNECTMENU, MF_GRAYED); @@ -468,29 +467,29 @@ void SetMenuStatus (int config, int bCheck) } else { - iState = ((bCheck == CONNECTED) || (bCheck == DISCONNECTING)) ? + iState = ((state == connected) || (state == disconnecting)) ? MF_CHECKED : MF_UNCHECKED ; CheckMenuItem (hMenu, (UINT) hMenuConn[config], iState) ; - if (bCheck == DISCONNECTED) + if (state == disconnected) { EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_GRAYED); } - if (bCheck == CONNECTING) + if (state == connecting) { EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_ENABLED); } - if (bCheck == CONNECTED) + if (state == connected) { EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_ENABLED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_STATUSMENU + config, MF_ENABLED); } - if (bCheck == DISCONNECTING) + if (state == disconnecting) { EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_CONNECTMENU + config, MF_GRAYED); EnableMenuItem(hMenuConn[config], (UINT_PTR)IDM_DISCONNECTMENU + config, MF_GRAYED); @@ -513,15 +512,15 @@ void SetServiceMenuStatus() hMenuHandle = hMenuService; - if ((o.service_running == SERVICE_NOACCESS) || - (o.service_running == SERVICE_CONNECTING)) + if ((o.service_state == service_noaccess) || + (o.service_state == service_connecting)) { /* Service is disabled */ EnableMenuItem(hMenuHandle, IDM_SERVICE_START, MF_GRAYED); EnableMenuItem(hMenuHandle, IDM_SERVICE_STOP, MF_GRAYED); EnableMenuItem(hMenuHandle, IDM_SERVICE_RESTART, MF_GRAYED); } - else if (o.service_running == SERVICE_CONNECTED) + else if (o.service_state == service_connected) { /* Service is running */ EnableMenuItem(hMenuHandle, IDM_SERVICE_START, MF_GRAYED); diff --git a/tray.h b/tray.h index 7a22f35..00573b9 100644 --- a/tray.h +++ b/tray.h @@ -19,6 +19,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "options.h" + #define WM_NOTIFYICONTRAY (WM_APP + 1) //Popup Menu items @@ -52,10 +54,10 @@ void DestroyPopupMenus(); //Destroy popup menus void OnNotifyTray(LPARAM lParam); //Tray message (mouse clicks on tray icon) void OnDestroyTray(void); //WM_DESTROY message void ShowTrayIcon(); //Put app icon in systray -void SetTrayIcon(int connected); //Change systray icon +void SetTrayIcon(conn_state_t connected); //Change systray icon BOOL LoadAppIcon(); //Application icon void CreateItemList(); //Crate Popup menu -void SetMenuStatus (int config, int bCheck); //Mark connection as connected/disconnected +void SetMenuStatus (int config, conn_state_t state); //Mark connection as connected/disconnected void SetServiceMenuStatus(); //Diabled Service menu items. void ShowTrayBalloon(TCHAR *infotitle_msg, TCHAR *info_msg); diff --git a/viewlog.c b/viewlog.c index 3aa3f53..539e6fa 100644 --- a/viewlog.c +++ b/viewlog.c @@ -30,7 +30,7 @@ #include "openvpn-gui-res.h" #include "localization.h" -extern struct options o; +extern options_t o; void ViewLog(int config) { @@ -46,7 +46,7 @@ void ViewLog(int config) CLEAR (sa); CLEAR (sd); - _sntprintf_0(filename, _T("%s \"%s\""), o.log_viewer, o.cnn[config].log_path); + _sntprintf_0(filename, _T("%s \"%s\""), o.log_viewer, o.conn[config].log_path); /* fill in STARTUPINFO struct */ GetStartupInfo(&start_info); @@ -88,7 +88,7 @@ void EditConfig(int config) CLEAR (sa); CLEAR (sd); - _sntprintf_0(filename, _T("%s \"%s\\%s\""), o.editor, o.cnn[config].config_dir, o.cnn[config].config_file); + _sntprintf_0(filename, _T("%s \"%s\\%s\""), o.editor, o.conn[config].config_dir, o.conn[config].config_file); /* fill in STARTUPINFO struct */ GetStartupInfo(&start_info); @@ -105,7 +105,7 @@ void EditConfig(int config) TRUE, CREATE_NEW_CONSOLE, NULL, - o.cnn[config].config_dir, //start-up dir + o.conn[config].config_dir, //start-up dir &start_info, &proc_info)) {