Skip to content

Commit 1c2fbcb

Browse files
committed
Adding '/version' command line argument to IEDriverServer.exe
1 parent 5412433 commit 1c2fbcb

File tree

3 files changed

+84
-70
lines changed

3 files changed

+84
-70
lines changed

cpp/iedriverserver/CommandLineArguments.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ std::wstring CommandLineArguments::GetValue(std::wstring arg_name,
3636

3737
void CommandLineArguments::ParseArguments(int argc, _TCHAR* argv[]) {
3838
this->is_help_requested_ = false;
39+
this->is_version_requested_ = false;
3940
for (int i = 1; i < argc; ++i) {
4041
std::wstring raw_arg(argv[i]);
4142
int switch_delimiter_length = GetSwitchDelimiterLength(raw_arg);
@@ -68,6 +69,10 @@ void CommandLineArguments::ParseArguments(int argc, _TCHAR* argv[]) {
6869
this->is_help_requested_ = true;
6970
}
7071

72+
if (arg_name == L"v" || arg_name == L"version") {
73+
this->is_version_requested_ = true;
74+
}
75+
7176
this->args_map_[arg_name] = arg_value;
7277
}
7378
}

cpp/iedriverserver/CommandLineArguments.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ class CommandLineArguments {
3131

3232
std::wstring GetValue(std::wstring arg_name,
3333
std::wstring default_value);
34-
bool is_help_requested (void) const { return this->is_help_requested_; }
34+
bool is_help_requested(void) const { return this->is_help_requested_; }
35+
bool is_version_requested(void) const { return this->is_version_requested_; }
3536

3637
private:
3738
void ParseArguments(int argc, _TCHAR* argv[]);
3839
int GetSwitchDelimiterLength(std::wstring arg);
3940

4041
bool is_help_requested_;
42+
bool is_version_requested_;
4143
std::map<std::wstring, std::wstring> args_map_;
4244
};
4345

cpp/iedriverserver/IEDriverServer.cpp

Lines changed: 76 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void ShowUsage(void) {
164164
<< std::endl
165165
<< L"IEDriverServer [/port=<port>] [/host=<host>] [/log-level=<level>]" << std::endl
166166
<< L" [/log-file=<file>] [/extract-path=<path>] [/silent]" << std::endl
167-
<< L" [/whitelisted-ips=<whitelisted-ips>]" << std::endl
167+
<< L" [/whitelisted-ips=<whitelisted-ips>] [/version]" << std::endl
168168
<< std::endl
169169
<< L" /port=<port> Specifies the port on which the server will listen for" << std::endl
170170
<< L" commands. Defaults to 5555 if not specified." << std::endl
@@ -188,7 +188,9 @@ void ShowUsage(void) {
188188
<< L" /silent Suppresses diagnostic output when the server is started." << std::endl
189189
<< L" /whitelisted-ips=<whitelisted-ips>" << std::endl
190190
<< L" Comma-separated whitelist of remote IPv4 addresses which" << std::endl
191-
<< L" are allowed to connect to the WebDriver server." << std::endl;
191+
<< L" are allowed to connect to the WebDriver server." << std::endl
192+
<< L" /version Displays version information and exits. All other arguments" << std::endl
193+
<< L" are ignored." << std::endl;
192194
}
193195

194196
int _tmain(int argc, _TCHAR* argv[]) {
@@ -263,78 +265,83 @@ int _tmain(int argc, _TCHAR* argv[]) {
263265
implementation.begin(),
264266
toupper);
265267

266-
267-
void* server_value = start_server_ex_proc(port,
268-
host_address,
269-
log_level,
270-
log_file,
271-
executable_version + L" (" + executable_architecture + L")",
272-
implementation,
273-
whitelist);
274-
if (server_value == NULL) {
275-
std::wcout << L"Failed to start the server with: "
276-
<< L"port = '" << port << L"', "
277-
<< L"host = '" << host_address << L"', "
278-
<< L"log level = '" << log_level << L"', "
279-
<< L"log file = '" << log_file << L"', "
280-
<< L"whitelisted ips = '" << whitelist << L"'.";
281-
return ERR_SERVER_START;
282-
}
283-
if (!silent) {
284-
std::wcout << L"Started InternetExplorerDriver server"
285-
<< L" (" << executable_architecture << L")"
286-
<< std::endl;
287-
std::wcout << executable_version
288-
<< std::endl;
289-
std::wcout << L"Listening on port " << port << std::endl;
290-
if (host_address.size() > 0) {
291-
std::wcout << L"Bound to network adapter with IP address "
292-
<< host_address
293-
<< std::endl;
268+
if (args.is_version_requested()) {
269+
std::wcout << L"IEDriverServer.exe"
270+
<< L" " << executable_version
271+
<< L" (" << executable_architecture << L")" << std::endl;
272+
} else {
273+
void* server_value = start_server_ex_proc(port,
274+
host_address,
275+
log_level,
276+
log_file,
277+
executable_version + L" (" + executable_architecture + L")",
278+
implementation,
279+
whitelist);
280+
if (server_value == NULL) {
281+
std::wcout << L"Failed to start the server with: "
282+
<< L"port = '" << port << L"', "
283+
<< L"host = '" << host_address << L"', "
284+
<< L"log level = '" << log_level << L"', "
285+
<< L"log file = '" << log_file << L"', "
286+
<< L"whitelisted ips = '" << whitelist << L"'.";
287+
return ERR_SERVER_START;
294288
}
295-
if (log_level.size() > 0) {
296-
std::wcout << L"Log level is set to "
297-
<< log_level
289+
if (!silent) {
290+
std::wcout << L"Started InternetExplorerDriver server"
291+
<< L" (" << executable_architecture << L")"
298292
<< std::endl;
299-
}
300-
if (log_file.size() > 0) {
301-
std::wcout << L"Log file is set to "
302-
<< log_file
293+
std::wcout << executable_version
303294
<< std::endl;
295+
std::wcout << L"Listening on port " << port << std::endl;
296+
if (host_address.size() > 0) {
297+
std::wcout << L"Bound to network adapter with IP address "
298+
<< host_address
299+
<< std::endl;
300+
}
301+
if (log_level.size() > 0) {
302+
std::wcout << L"Log level is set to "
303+
<< log_level
304+
<< std::endl;
305+
}
306+
if (log_file.size() > 0) {
307+
std::wcout << L"Log file is set to "
308+
<< log_file
309+
<< std::endl;
310+
}
311+
if (implementation.size() > 0) {
312+
std::wcout << L"Driver implementation set to "
313+
<< implementation
314+
<< std::endl;
315+
}
316+
if (extraction_path_arg.size() > 0) {
317+
std::wcout << L"Library extracted to "
318+
<< extraction_path_arg
319+
<< std::endl;
320+
}
321+
if (whitelist.size() > 0) {
322+
std::wcout << L"IP addresses allowed to connect are "
323+
<< whitelist
324+
<< std::endl;
325+
} else {
326+
std::wcout << L"Only local connections are allowed"
327+
<< std::endl;
328+
}
304329
}
305-
if (implementation.size() > 0) {
306-
std::wcout << L"Driver implementation set to "
307-
<< implementation
308-
<< std::endl;
309-
}
310-
if (extraction_path_arg.size() > 0) {
311-
std::wcout << L"Library extracted to "
312-
<< extraction_path_arg
313-
<< std::endl;
314-
}
315-
if (whitelist.size() > 0) {
316-
std::wcout << L"IP addresses allowed to connect are "
317-
<< whitelist
318-
<< std::endl;
319-
} else {
320-
std::wcout << L"Only local connections are allowed"
321-
<< std::endl;
322-
}
323-
}
324330

325-
// Create the shutdown event and wait for it to be signaled.
326-
DWORD process_id = ::GetCurrentProcessId();
327-
vector<wchar_t> process_id_buffer(10);
328-
_ltow_s(process_id, &process_id_buffer[0], process_id_buffer.size(), 10);
329-
std::wstring process_id_string(&process_id_buffer[0]);
330-
std::wstring event_name = IESERVER_SHUTDOWN_EVENT_NAME + process_id_string;
331-
HANDLE event_handle = ::CreateEvent(NULL,
332-
TRUE,
333-
FALSE,
334-
event_name.c_str());
335-
::WaitForSingleObject(event_handle, INFINITE);
336-
::CloseHandle(event_handle);
337-
stop_server_proc();
331+
// Create the shutdown event and wait for it to be signaled.
332+
DWORD process_id = ::GetCurrentProcessId();
333+
vector<wchar_t> process_id_buffer(10);
334+
_ltow_s(process_id, &process_id_buffer[0], process_id_buffer.size(), 10);
335+
std::wstring process_id_string(&process_id_buffer[0]);
336+
std::wstring event_name = IESERVER_SHUTDOWN_EVENT_NAME + process_id_string;
337+
HANDLE event_handle = ::CreateEvent(NULL,
338+
TRUE,
339+
FALSE,
340+
event_name.c_str());
341+
::WaitForSingleObject(event_handle, INFINITE);
342+
::CloseHandle(event_handle);
343+
stop_server_proc();
344+
}
338345

339346
::FreeLibrary(module_handle);
340347
::DeleteFile(temp_file_name.c_str());

0 commit comments

Comments
 (0)