blob: 4e91687132c6468a30e7cb197a46c9c7b4c981ee [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_WIN32_H_
12#define RTC_BASE_WIN32_H_
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
Mirko Bonadeie0623852018-02-01 11:17:40 +010014#ifndef WEBRTC_WIN
15#error "Only #include this header in Windows builds"
16#endif
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020018#ifndef WIN32_LEAN_AND_MEAN
19#define WIN32_LEAN_AND_MEAN
20#endif
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000021
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020022// Make sure we don't get min/max macros
23#ifndef NOMINMAX
24#define NOMINMAX
25#endif
26
27#include <winsock2.h>
28#include <windows.h>
29
30#ifndef SECURITY_MANDATORY_LABEL_AUTHORITY
31// Add defines that we use if we are compiling against older sdks
32#define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L)
33#define TokenIntegrityLevel static_cast<TOKEN_INFORMATION_CLASS>(0x19)
34typedef struct _TOKEN_MANDATORY_LABEL {
35 SID_AND_ATTRIBUTES Label;
36} TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL;
37#endif // SECURITY_MANDATORY_LABEL_AUTHORITY
38
39#undef SetPort
40
41#include <string>
42
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020043#include "rtc_base/basictypes.h"
44#include "rtc_base/stringutils.h"
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020045
46namespace rtc {
47
48const char* win32_inet_ntop(int af, const void *src, char* dst, socklen_t size);
49int win32_inet_pton(int af, const char* src, void *dst);
50
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020051// Convert a Utf8 path representation to a non-length-limited Unicode pathname.
52bool Utf8ToWindowsFilename(const std::string& utf8, std::wstring* filename);
53
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020054enum WindowsMajorVersions {
55 kWindows2000 = 5,
56 kWindowsVista = 6,
braveyao8944f6a2018-04-06 10:59:50 -070057 kWindows10 = 10,
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020058};
59bool GetOsVersion(int* major, int* minor, int* build);
60
61inline bool IsWindowsVistaOrLater() {
62 int major;
63 return (GetOsVersion(&major, nullptr, nullptr) && major >= kWindowsVista);
64}
65
66inline bool IsWindowsXpOrLater() {
67 int major, minor;
68 return (GetOsVersion(&major, &minor, nullptr) &&
69 (major >= kWindowsVista || (major == kWindows2000 && minor >= 1)));
70}
71
72inline bool IsWindows8OrLater() {
73 int major, minor;
74 return (GetOsVersion(&major, &minor, nullptr) &&
75 (major > kWindowsVista || (major == kWindowsVista && minor >= 2)));
76}
77
braveyao8944f6a2018-04-06 10:59:50 -070078inline bool IsWindows10OrLater() {
79 int major;
80 return (GetOsVersion(&major, nullptr, nullptr) && (major >= kWindows10));
81}
82
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020083// Determine the current integrity level of the process.
84bool GetCurrentProcessIntegrityLevel(int* level);
85
86inline bool IsCurrentProcessLowIntegrity() {
87 int level;
88 return (GetCurrentProcessIntegrityLevel(&level) &&
89 level < SECURITY_MANDATORY_MEDIUM_RID);
90}
91
92} // namespace rtc
93
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020094#endif // RTC_BASE_WIN32_H_