You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improving cross-platform compatibility of webdriver-server C++ code.
This commit makes the common webdriver-server C++ code more easily
cross-platform. It does this mainly by removing use of std::tr1::regex,
which has issues compiling under gcc. In its place, we now use a custom
URL matching algorithm for matching URLs in the WebDriver JSON Wire
Protocol. While this matching algorithm may be a source of future errors,
a nice side effect of it is a 3% performance increase in server execution
times over using regular expressions.
Additionally, this commit includes an alias for snprintf, which throws
buffer overrun warnings when used with Visual Studio. It also contains
some header #include rearranging and linting of the C++ code.
Copy file name to clipboardExpand all lines: cpp/webdriver-server/server.cc
+60-75
Original file line number
Diff line number
Diff line change
@@ -11,14 +11,33 @@
11
11
// See the License for the specific language governing permissions and
12
12
// limitations under the License.
13
13
14
-
#include<regex>
15
14
#include"server.h"
15
+
#include<cstdio>
16
+
#include<cstring>
17
+
#include<sstream>
18
+
#include"session.h"
19
+
#include"uri_info.h"
16
20
#include"logging.h"
17
21
18
22
#defineSERVER_DEFAULT_PAGE"<html><head><title>WebDriver</title></head><body><p id='main'>This is the initial start page for the WebDriver server.</p></body></html>"
19
23
#defineHTML_CONTENT_TYPE"text/html"
20
24
#defineJSON_CONTENT_TYPE"application/json"
21
25
26
+
#if defined(WINDOWS)
27
+
#include<cstdarg>
28
+
inlineintwd_snprintf(char* str, size_t size, constchar* format, ...) {
29
+
va_list args;
30
+
va_start(args, format);
31
+
int count = _vscprintf(format, args);
32
+
if (str != NULL && size > 0) {
33
+
count = _vsnprintf_s(str, size, _TRUNCATE, format, args);
34
+
}
35
+
va_end(args);
36
+
return count;
37
+
}
38
+
#definesnprintf wd_snprintf
39
+
#endif
40
+
22
41
namespacewebdriver {
23
42
24
43
Server::Server(constint port) {
@@ -50,7 +69,8 @@ void Server::Initialize(const int port,
50
69
const std::string& log_file) {
51
70
LOG::Level(log_level);
52
71
LOG::File(log_file);
53
-
LOG(INFO) << "Starting WebDriver server on port: '" << port << "' on host: '" << host << "'";
72
+
LOG(INFO) << "Starting WebDriver server on port: '"
73
+
<< port << "' on host: '" << host << "'";
54
74
this->port_ = port;
55
75
this->host_ = host;
56
76
this->PopulateCommandRepository();
@@ -74,19 +94,20 @@ bool Server::Start() {
74
94
// empty string.
75
95
port_format_string = "%s%d";
76
96
}
77
-
int formatted_string_size = _scprintf(port_format_string.c_str(),
0 commit comments