| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2004--2005, Google Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef TALK_BASE_WIN32_H_ | |
| 29 #define TALK_BASE_WIN32_H_ | |
| 30 | |
| 31 #ifdef WIN32 | |
| 32 | |
| 33 #ifndef WIN32_LEAN_AND_MEAN | |
| 34 #define WIN32_LEAN_AND_MEAN | |
| 35 #endif | |
| 36 #include <winsock2.h> | |
| 37 #include <windows.h> | |
| 38 | |
| 39 #ifndef SECURITY_MANDATORY_LABEL_AUTHORITY | |
| 40 // Add defines that we use if we are compiling against older sdks | |
| 41 #define SECURITY_MANDATORY_MEDIUM_RID (0x00002000L) | |
| 42 #define TokenIntegrityLevel static_cast<TOKEN_INFORMATION_CLASS>(0x19) | |
| 43 typedef struct _TOKEN_MANDATORY_LABEL { | |
| 44 SID_AND_ATTRIBUTES Label; | |
| 45 } TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL; | |
| 46 #endif // SECURITY_MANDATORY_LABEL_AUTHORITY | |
| 47 | |
| 48 #undef SetPort | |
| 49 | |
| 50 #include <string> | |
| 51 | |
| 52 #include "talk/base/stringutils.h" | |
| 53 #include "talk/base/basictypes.h" | |
| 54 | |
| 55 namespace talk_base { | |
| 56 | |
| 57 const char* win32_inet_ntop(int af, const void *src, char* dst, socklen_t size); | |
| 58 int win32_inet_pton(int af, const char* src, void *dst); | |
| 59 | |
| 60 /////////////////////////////////////////////////////////////////////////////// | |
| 61 | |
| 62 inline std::wstring ToUtf16(const char* utf8, size_t len) { | |
| 63 int len16 = ::MultiByteToWideChar(CP_UTF8, 0, utf8, len, NULL, 0); | |
| 64 wchar_t* ws = STACK_ARRAY(wchar_t, len16); | |
| 65 ::MultiByteToWideChar(CP_UTF8, 0, utf8, len, ws, len16); | |
| 66 return std::wstring(ws, len16); | |
| 67 } | |
| 68 | |
| 69 inline std::wstring ToUtf16(const std::string& str) { | |
| 70 return ToUtf16(str.data(), str.length()); | |
| 71 } | |
| 72 | |
| 73 inline std::string ToUtf8(const wchar_t* wide, size_t len) { | |
| 74 int len8 = ::WideCharToMultiByte(CP_UTF8, 0, wide, len, NULL, 0, NULL, NULL); | |
| 75 char* ns = STACK_ARRAY(char, len8); | |
| 76 ::WideCharToMultiByte(CP_UTF8, 0, wide, len, ns, len8, NULL, NULL); | |
| 77 return std::string(ns, len8); | |
| 78 } | |
| 79 | |
| 80 inline std::string ToUtf8(const std::wstring& wstr) { | |
| 81 return ToUtf8(wstr.data(), wstr.length()); | |
| 82 } | |
| 83 | |
| 84 // Convert FILETIME to time_t | |
| 85 void FileTimeToUnixTime(const FILETIME& ft, time_t* ut); | |
| 86 | |
| 87 // Convert time_t to FILETIME | |
| 88 void UnixTimeToFileTime(const time_t& ut, FILETIME * ft); | |
| 89 | |
| 90 // Convert a Utf8 path representation to a non-length-limited Unicode pathname. | |
| 91 bool Utf8ToWindowsFilename(const std::string& utf8, std::wstring* filename); | |
| 92 | |
| 93 // Convert a FILETIME to a UInt64 | |
| 94 inline uint64 ToUInt64(const FILETIME& ft) { | |
| 95 ULARGE_INTEGER r = {ft.dwLowDateTime, ft.dwHighDateTime}; | |
| 96 return r.QuadPart; | |
| 97 } | |
| 98 | |
| 99 enum WindowsMajorVersions { | |
| 100 kWindows2000 = 5, | |
| 101 kWindowsVista = 6, | |
| 102 }; | |
| 103 bool GetOsVersion(int* major, int* minor, int* build); | |
| 104 | |
| 105 inline bool IsWindowsVistaOrLater() { | |
| 106 int major; | |
| 107 return (GetOsVersion(&major, NULL, NULL) && major >= kWindowsVista); | |
| 108 } | |
| 109 | |
| 110 inline bool IsWindowsXpOrLater() { | |
| 111 int major, minor; | |
| 112 return (GetOsVersion(&major, &minor, NULL) && | |
| 113 (major >= kWindowsVista || | |
| 114 (major == kWindows2000 && minor >= 1))); | |
| 115 } | |
| 116 | |
| 117 // Determine the current integrity level of the process. | |
| 118 bool GetCurrentProcessIntegrityLevel(int* level); | |
| 119 | |
| 120 inline bool IsCurrentProcessLowIntegrity() { | |
| 121 int level; | |
| 122 return (GetCurrentProcessIntegrityLevel(&level) && | |
| 123 level < SECURITY_MANDATORY_MEDIUM_RID); | |
| 124 } | |
| 125 | |
| 126 bool AdjustCurrentProcessPrivilege(const TCHAR* privilege, bool to_enable); | |
| 127 | |
| 128 /////////////////////////////////////////////////////////////////////////////// | |
| 129 | |
| 130 } // namespace talk_base | |
| 131 | |
| 132 #endif // WIN32 | |
| 133 #endif // TALK_BASE_WIN32_H_ | |
| OLD | NEW |