Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "curl_setup.h"
00024
00025 #if defined(WIN32)
00026
00027 #include <curl/curl.h>
00028 #include "system_win32.h"
00029
00030
00031 #include "curl_memory.h"
00032 #include "memdebug.h"
00033
00034 #if defined(USE_WINDOWS_SSPI) || (!defined(CURL_DISABLE_TELNET) && \
00035 defined(USE_WINSOCK))
00036
00037
00038 #if !defined(LOAD_WITH_ALTERED_SEARCH_PATH)
00039 #define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008
00040 #endif
00041
00042 #if !defined(LOAD_LIBRARY_SEARCH_SYSTEM32)
00043 #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
00044 #endif
00045
00046
00047 typedef HMODULE (APIENTRY *LOADLIBRARYEX_FN)(LPCTSTR, HANDLE, DWORD);
00048
00049
00050 #ifdef UNICODE
00051 # ifdef _WIN32_WCE
00052 # define LOADLIBARYEX L"LoadLibraryExW"
00053 # else
00054 # define LOADLIBARYEX "LoadLibraryExW"
00055 # endif
00056 #else
00057 # define LOADLIBARYEX "LoadLibraryExA"
00058 #endif
00059
00060 #endif
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 bool Curl_verify_windows_version(const unsigned int majorVersion,
00080 const unsigned int minorVersion,
00081 const PlatformIdentifier platform,
00082 const VersionCondition condition)
00083 {
00084 bool matched = FALSE;
00085
00086 #if defined(CURL_WINDOWS_APP)
00087
00088
00089 const WORD fullVersion = MAKEWORD(minorVersion, majorVersion);
00090 const WORD targetVersion = (WORD)_WIN32_WINNT;
00091
00092 switch(condition) {
00093 case VERSION_LESS_THAN:
00094 matched = targetVersion < fullVersion;
00095 break;
00096
00097 case VERSION_LESS_THAN_EQUAL:
00098 matched = targetVersion <= fullVersion;
00099 break;
00100
00101 case VERSION_EQUAL:
00102 matched = targetVersion == fullVersion;
00103 break;
00104
00105 case VERSION_GREATER_THAN_EQUAL:
00106 matched = targetVersion >= fullVersion;
00107 break;
00108
00109 case VERSION_GREATER_THAN:
00110 matched = targetVersion > fullVersion;
00111 break;
00112 }
00113
00114 if(matched && (platform == PLATFORM_WINDOWS)) {
00115
00116 matched = FALSE;
00117 }
00118 #elif !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_WIN2K) || \
00119 (_WIN32_WINNT < _WIN32_WINNT_WIN2K)
00120 OSVERSIONINFO osver;
00121
00122 memset(&osver, 0, sizeof(osver));
00123 osver.dwOSVersionInfoSize = sizeof(osver);
00124
00125
00126 if(GetVersionEx(&osver)) {
00127
00128 switch(condition) {
00129 case VERSION_LESS_THAN:
00130 if(osver.dwMajorVersion < majorVersion ||
00131 (osver.dwMajorVersion == majorVersion &&
00132 osver.dwMinorVersion < minorVersion))
00133 matched = TRUE;
00134 break;
00135
00136 case VERSION_LESS_THAN_EQUAL:
00137 if(osver.dwMajorVersion <= majorVersion &&
00138 osver.dwMinorVersion <= minorVersion)
00139 matched = TRUE;
00140 break;
00141
00142 case VERSION_EQUAL:
00143 if(osver.dwMajorVersion == majorVersion &&
00144 osver.dwMinorVersion == minorVersion)
00145 matched = TRUE;
00146 break;
00147
00148 case VERSION_GREATER_THAN_EQUAL:
00149 if(osver.dwMajorVersion >= majorVersion &&
00150 osver.dwMinorVersion >= minorVersion)
00151 matched = TRUE;
00152 break;
00153
00154 case VERSION_GREATER_THAN:
00155 if(osver.dwMajorVersion > majorVersion ||
00156 (osver.dwMajorVersion == majorVersion &&
00157 osver.dwMinorVersion > minorVersion))
00158 matched = TRUE;
00159 break;
00160 }
00161
00162
00163 if(matched) {
00164 switch(platform) {
00165 case PLATFORM_WINDOWS:
00166 if(osver.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)
00167 matched = FALSE;
00168 break;
00169
00170 case PLATFORM_WINNT:
00171 if(osver.dwPlatformId != VER_PLATFORM_WIN32_NT)
00172 matched = FALSE;
00173
00174 default:
00175 break;
00176 }
00177 }
00178 }
00179 #else
00180 ULONGLONG cm = 0;
00181 OSVERSIONINFOEX osver;
00182 BYTE majorCondition;
00183 BYTE minorCondition;
00184 BYTE spMajorCondition;
00185 BYTE spMinorCondition;
00186
00187 switch(condition) {
00188 case VERSION_LESS_THAN:
00189 majorCondition = VER_LESS;
00190 minorCondition = VER_LESS;
00191 spMajorCondition = VER_LESS_EQUAL;
00192 spMinorCondition = VER_LESS_EQUAL;
00193 break;
00194
00195 case VERSION_LESS_THAN_EQUAL:
00196 majorCondition = VER_LESS_EQUAL;
00197 minorCondition = VER_LESS_EQUAL;
00198 spMajorCondition = VER_LESS_EQUAL;
00199 spMinorCondition = VER_LESS_EQUAL;
00200 break;
00201
00202 case VERSION_EQUAL:
00203 majorCondition = VER_EQUAL;
00204 minorCondition = VER_EQUAL;
00205 spMajorCondition = VER_GREATER_EQUAL;
00206 spMinorCondition = VER_GREATER_EQUAL;
00207 break;
00208
00209 case VERSION_GREATER_THAN_EQUAL:
00210 majorCondition = VER_GREATER_EQUAL;
00211 minorCondition = VER_GREATER_EQUAL;
00212 spMajorCondition = VER_GREATER_EQUAL;
00213 spMinorCondition = VER_GREATER_EQUAL;
00214 break;
00215
00216 case VERSION_GREATER_THAN:
00217 majorCondition = VER_GREATER;
00218 minorCondition = VER_GREATER;
00219 spMajorCondition = VER_GREATER_EQUAL;
00220 spMinorCondition = VER_GREATER_EQUAL;
00221 break;
00222
00223 default:
00224 return FALSE;
00225 }
00226
00227 memset(&osver, 0, sizeof(osver));
00228 osver.dwOSVersionInfoSize = sizeof(osver);
00229 osver.dwMajorVersion = majorVersion;
00230 osver.dwMinorVersion = minorVersion;
00231 if(platform == PLATFORM_WINDOWS)
00232 osver.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
00233 else if(platform == PLATFORM_WINNT)
00234 osver.dwPlatformId = VER_PLATFORM_WIN32_NT;
00235
00236 cm = VerSetConditionMask(cm, VER_MAJORVERSION, majorCondition);
00237 cm = VerSetConditionMask(cm, VER_MINORVERSION, minorCondition);
00238 cm = VerSetConditionMask(cm, VER_SERVICEPACKMAJOR, spMajorCondition);
00239 cm = VerSetConditionMask(cm, VER_SERVICEPACKMINOR, spMinorCondition);
00240 if(platform != PLATFORM_DONT_CARE)
00241 cm = VerSetConditionMask(cm, VER_PLATFORMID, VER_EQUAL);
00242
00243 if(VerifyVersionInfo(&osver, (VER_MAJORVERSION | VER_MINORVERSION |
00244 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR),
00245 cm))
00246 matched = TRUE;
00247 #endif
00248
00249 return matched;
00250 }
00251
00252 #if defined(USE_WINDOWS_SSPI) || (!defined(CURL_DISABLE_TELNET) && \
00253 defined(USE_WINSOCK))
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 HMODULE Curl_load_library(LPCTSTR filename)
00270 {
00271 HMODULE hModule = NULL;
00272 LOADLIBRARYEX_FN pLoadLibraryEx = NULL;
00273
00274
00275 HMODULE hKernel32 = GetModuleHandle(TEXT("kernel32"));
00276 if(!hKernel32)
00277 return NULL;
00278
00279
00280
00281 pLoadLibraryEx = (LOADLIBRARYEX_FN) GetProcAddress(hKernel32, LOADLIBARYEX);
00282
00283
00284
00285
00286
00287 if(_tcspbrk(filename, TEXT("\\/"))) {
00289 hModule = pLoadLibraryEx ?
00290 pLoadLibraryEx(filename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) :
00291 LoadLibrary(filename);
00292 }
00293
00294
00295
00296 else if(pLoadLibraryEx && GetProcAddress(hKernel32, "AddDllDirectory")) {
00297
00298 hModule = pLoadLibraryEx(filename, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
00299 }
00300 else {
00301
00302 UINT systemdirlen = GetSystemDirectory(NULL, 0);
00303 if(systemdirlen) {
00304
00305
00306 size_t filenamelen = _tcslen(filename);
00307 TCHAR *path = malloc(sizeof(TCHAR) * (systemdirlen + 1 + filenamelen));
00308 if(path && GetSystemDirectory(path, systemdirlen)) {
00309
00310 _tcscpy(path + _tcslen(path), TEXT("\\"));
00311 _tcscpy(path + _tcslen(path), filename);
00312
00313
00315 hModule = pLoadLibraryEx ?
00316 pLoadLibraryEx(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH) :
00317 LoadLibrary(path);
00318
00319 }
00320 free(path);
00321 }
00322 }
00323
00324 return hModule;
00325 }
00326
00327 #endif
00328
00329 #endif