From 33c361c8a927624df0d0bf60fb8bc6f1e00b80a1 Mon Sep 17 00:00:00 2001 From: Jan Zerebecki Date: Thu, 23 Aug 2007 20:21:28 +0200 Subject: [PATCH] push 599a9d3db769aad8dabfd10a59120f719b00f4ee --- dlls/advapi32/crypt.c | 7 +- dlls/advapi32/service.c | 64 +++------- dlls/advapi32/tests/crypt.c | 76 ++++++++++++ dlls/advpack/files.c | 82 ++++++------- dlls/atl/Makefile.in | 2 +- dlls/atl/registrar.c | 5 +- dlls/cabinet/cabinet.h | 34 +++--- dlls/cabinet/cabinet_main.c | 67 ++++++----- dlls/crypt32/main.c | 12 -- dlls/crypt32/msg.c | 146 ++++++++++++++++++++++- dlls/crypt32/tests/msg.c | 165 +++++++++++++++++++++++++- dlls/dsound/primary.c | 257 ++++++++++++++++------------------------- dlls/gdi32/dc.c | 24 ++-- dlls/gdi32/gdiobj.c | 14 +-- dlls/gdi32/printdrv.c | 2 +- dlls/gphoto2.ds/Makefile.in | 2 +- dlls/gphoto2.ds/gphoto2_De.rc | 8 +- dlls/gphoto2.ds/gphoto2_En.rc | 8 +- dlls/gphoto2.ds/gphoto2_Fr.rc | 8 +- dlls/gphoto2.ds/gphoto2_Ko.rc | 8 +- dlls/gphoto2.ds/gphoto2_Nl.rc | 8 +- dlls/gphoto2.ds/gphoto2_No.rc | 8 +- dlls/gphoto2.ds/gphoto2_Pl.rc | 8 +- dlls/gphoto2.ds/resource.h | 2 + dlls/gphoto2.ds/ui.c | 103 +++++++++++------ dlls/msvcrt/mbcs.c | 87 ++++++++------ dlls/msvcrt/tests/string.c | 87 +++++++++++++- dlls/oleaut32/regsvr.c | 76 +----------- dlls/opengl32/tests/opengl.c | 42 +++++++ dlls/quartz/regsvr.c | 84 ++------------ dlls/rsaenh/des.c | 9 +- dlls/rsaenh/mpi.c | 110 +++++++++--------- dlls/rsaenh/tomcrypt.h | 114 +++++++++--------- dlls/wined3d/device.c | 4 +- dlls/wined3d/drawprim.c | 19 ++- dlls/wined3d/query.c | 45 ++++++-- dlls/wined3d/state.c | 31 +++-- dlls/wined3d/surface.c | 9 ++ dlls/wined3d/wined3d_private.h | 3 + dlls/winex11.drv/opengl.c | 69 ++++------- dlls/wininet/ftp.c | 6 + dlls/wininet/http.c | 10 +- dlls/wininet/internet.c | 15 ++- dlls/wininet/internet.h | 5 +- dlls/winspool.drv/info.c | 97 ++++++++++------ include/winioctl.h | 34 +++++- programs/winecfg/theme.c | 147 +++++++++++++++++------ programs/winetest/main.c | 8 +- programs/wordpad/wordpad.c | 5 +- tools/wineprefixcreate.in | 2 + 50 files changed, 1365 insertions(+), 873 deletions(-) diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index 60131bb28df..63f89f6869a 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -2134,12 +2134,7 @@ BOOL WINAPI CryptVerifySignatureW (HCRYPTHASH hHash, CONST BYTE *pbSignature, DW TRACE("(0x%lx, %p, %d, 0x%lx, %s, %08x)\n", hHash, pbSignature, dwSigLen, hPubKey, debugstr_w(sDescription), dwFlags); - if (!hash || !key) - { - SetLastError(ERROR_INVALID_HANDLE); - return FALSE; - } - if (!pbSignature || !dwSigLen || + if (!hash || !key || !hash->pProvider || hash->pProvider->dwMagic != MAGIC_CRYPTPROV || !key->pProvider || key->pProvider->dwMagic != MAGIC_CRYPTPROV) { diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c index 458653c85fa..fbc888dbf9e 100644 --- a/dlls/advapi32/service.c +++ b/dlls/advapi32/service.c @@ -69,7 +69,6 @@ typedef struct service_start_info_t #define WINESERV_STARTINFO 1 #define WINESERV_GETSTATUS 2 #define WINESERV_SENDCONTROL 3 -#define WINESERV_SETPID 4 typedef struct service_data_t { @@ -454,7 +453,8 @@ static BOOL service_handle_start(HANDLE pipe, service_data *service, DWORD count if (service->thread) { - ERR("service is not stopped\n"); + WARN("service is not stopped\n"); + result = ERROR_SERVICE_ALREADY_RUNNING; goto end; } @@ -503,7 +503,14 @@ static BOOL service_send_start_message(HANDLE pipe, LPCWSTR *argv, DWORD argc) r = WriteFile(pipe, ssi, sizeof *ssi + len*sizeof(WCHAR), &count, NULL); if (r) + { r = ReadFile(pipe, &result, sizeof result, &count, NULL); + if (r && result) + { + SetLastError(result); + r = FALSE; + } + } HeapFree(GetProcessHeap(),0,ssi); @@ -545,41 +552,6 @@ static BOOL service_get_status(HANDLE pipe, LPSERVICE_STATUS_PROCESS status) } /****************************************************************************** - * service_handle_set_processID - */ -static BOOL service_handle_set_processID(HANDLE pipe, service_data *service, DWORD dwProcessId) -{ - DWORD count, ret = ERROR_SUCCESS; - - TRACE("received control %d\n", dwProcessId); - service->status.dwProcessId = dwProcessId; - return WriteFile(pipe, &ret, sizeof ret , &count, NULL); -} - -/****************************************************************************** - * service_set_processID - */ -static BOOL service_set_processID(HANDLE pipe, DWORD dwprocessId, LPDWORD dwResult) -{ - DWORD cmd[2], count = 0; - BOOL r; - - cmd[0] = WINESERV_SETPID; - cmd[1] = dwprocessId; - r = WriteFile( pipe, cmd, sizeof cmd, &count, NULL ); - if (!r || count != sizeof cmd) - { - ERR("service protocol error - failed to write pipe!\n"); - return r; - } - r = ReadFile( pipe, dwResult, sizeof *dwResult, &count, NULL ); - if (!r || count != sizeof *dwResult) - ERR("service protocol error - failed to read pipe " - "r = %d count = %d!\n", r, count); - return r; -} - -/****************************************************************************** * service_send_control */ static BOOL service_send_control(HANDLE pipe, DWORD dwControl, DWORD *result) @@ -764,9 +736,6 @@ static DWORD WINAPI service_control_dispatcher(LPVOID arg) case WINESERV_SENDCONTROL: service_handle_control(pipe, service, req[1]); break; - case WINESERV_SETPID: - service_handle_set_processID(pipe, service, req[1]); - break; default: ERR("received invalid command %d length %d\n", req[0], req[1]); } @@ -792,15 +761,18 @@ static BOOL service_run_threads(void) count = list_count( &service_list ); - TRACE("starting %d pipe listener threads\n", count); + TRACE("Starting %d pipe listener threads. Services running as process %d\n", count, GetCurrentProcessId()); handles = HeapAlloc(GetProcessHeap(), 0, sizeof(HANDLE) * (count + 1)); handles[n++] = __wine_make_process_system(); LIST_FOR_EACH_ENTRY( service, &service_list, service_data, entry ) + { + service->status.dwProcessId = GetCurrentProcessId(); handles[n++] = CreateThread( NULL, 0, service_control_dispatcher, service, 0, NULL ); + } assert(n == count + 1); LeaveCriticalSection( &service_cs ); @@ -1733,7 +1705,6 @@ BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, { struct sc_service *hsvc; BOOL r = FALSE; - DWORD dwResult, dwProcessId = 0; SC_LOCK hLock; HANDLE handle = INVALID_HANDLE_VALUE; @@ -1754,7 +1725,7 @@ BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, if (handle==INVALID_HANDLE_VALUE) { /* start the service process */ - if (service_start_process(hsvc, &dwProcessId)) + if (service_start_process(hsvc, NULL)) handle = service_open_pipe(hsvc->name); } @@ -1764,13 +1735,6 @@ BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, CloseHandle(handle); } - handle = service_open_pipe(hsvc->name); - if (handle != INVALID_HANDLE_VALUE) - { - service_set_processID(handle, dwProcessId, &dwResult); - CloseHandle(handle); - } - UnlockServiceDatabase( hLock ); TRACE("returning %d\n", r); diff --git a/dlls/advapi32/tests/crypt.c b/dlls/advapi32/tests/crypt.c index a8db3849cd7..9fa532cb1d0 100644 --- a/dlls/advapi32/tests/crypt.c +++ b/dlls/advapi32/tests/crypt.c @@ -349,6 +349,81 @@ static void test_incorrect_api_usage(void) ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); } +static const BYTE privKey[] = { + 0x07, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, + 0x02, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x79, 0x10, 0x1c, 0xd0, 0x6b, 0x10, + 0x18, 0x30, 0x94, 0x61, 0xdc, 0x0e, 0xcb, 0x96, 0x4e, 0x21, 0x3f, 0x79, 0xcd, + 0xa9, 0x17, 0x62, 0xbc, 0xbb, 0x61, 0x4c, 0xe0, 0x75, 0x38, 0x6c, 0xf3, 0xde, + 0x60, 0x86, 0x03, 0x97, 0x65, 0xeb, 0x1e, 0x6b, 0xdb, 0x53, 0x85, 0xad, 0x68, + 0x21, 0xf1, 0x5d, 0xe7, 0x1f, 0xe6, 0x53, 0xb4, 0xbb, 0x59, 0x3e, 0x14, 0x27, + 0xb1, 0x83, 0xa7, 0x3a, 0x54, 0xe2, 0x8f, 0x65, 0x8e, 0x6a, 0x4a, 0xcf, 0x3b, + 0x1f, 0x65, 0xff, 0xfe, 0xf1, 0x31, 0x3a, 0x37, 0x7a, 0x8b, 0xcb, 0xc6, 0xd4, + 0x98, 0x50, 0x36, 0x67, 0xe4, 0xa1, 0xe8, 0x7e, 0x8a, 0xc5, 0x23, 0xf2, 0x77, + 0xf5, 0x37, 0x61, 0x49, 0x72, 0x59, 0xe8, 0x3d, 0xf7, 0x60, 0xb2, 0x77, 0xca, + 0x78, 0x54, 0x6d, 0x65, 0x9e, 0x03, 0x97, 0x1b, 0x61, 0xbd, 0x0c, 0xd8, 0x06, + 0x63, 0xe2, 0xc5, 0x48, 0xef, 0xb3, 0xe2, 0x6e, 0x98, 0x7d, 0xbd, 0x4e, 0x72, + 0x91, 0xdb, 0x31, 0x57, 0xe3, 0x65, 0x3a, 0x49, 0xca, 0xec, 0xd2, 0x02, 0x4e, + 0x22, 0x7e, 0x72, 0x8e, 0xf9, 0x79, 0x84, 0x82, 0xdf, 0x7b, 0x92, 0x2d, 0xaf, + 0xc9, 0xe4, 0x33, 0xef, 0x89, 0x5c, 0x66, 0x99, 0xd8, 0x80, 0x81, 0x47, 0x2b, + 0xb1, 0x66, 0x02, 0x84, 0x59, 0x7b, 0xc3, 0xbe, 0x98, 0x45, 0x4a, 0x3d, 0xdd, + 0xea, 0x2b, 0xdf, 0x4e, 0xb4, 0x24, 0x6b, 0xec, 0xe7, 0xd9, 0x0c, 0x45, 0xb8, + 0xbe, 0xca, 0x69, 0x37, 0x92, 0x4c, 0x38, 0x6b, 0x96, 0x6d, 0xcd, 0x86, 0x67, + 0x5c, 0xea, 0x54, 0x94, 0xa4, 0xca, 0xa4, 0x02, 0xa5, 0x21, 0x4d, 0xae, 0x40, + 0x8f, 0x9d, 0x51, 0x83, 0xf2, 0x3f, 0x33, 0xc1, 0x72, 0xb4, 0x1d, 0x94, 0x6e, + 0x7d, 0xe4, 0x27, 0x3f, 0xea, 0xff, 0xe5, 0x9b, 0xa7, 0x5e, 0x55, 0x8e, 0x0d, + 0x69, 0x1c, 0x7a, 0xff, 0x81, 0x9d, 0x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda, + 0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78, + 0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 }; + +static void test_verify_sig(void) +{ + BOOL ret; + HCRYPTPROV prov; + HCRYPTKEY key; + HCRYPTHASH hash; + BYTE bogus[] = { 0 }; + + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(0, NULL, 0, 0, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); + ret = pCryptAcquireContextA(&prov, szKeySet, NULL, PROV_RSA_FULL, + CRYPT_NEWKEYSET); + if (!ret && GetLastError() == NTE_EXISTS) + ret = pCryptAcquireContextA(&prov, szKeySet, NULL, PROV_RSA_FULL, 0); + ret = pCryptImportKey(prov, (LPBYTE)privKey, sizeof(privKey), 0, 0, &key); + ok(ret, "CryptImportKey failed: %08x\n", GetLastError()); + ret = pCryptCreateHash(prov, CALG_MD5, 0, 0, &hash); + ok(ret, "CryptCreateHash failed: %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, NULL, 0, 0, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(0, NULL, 0, key, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, NULL, 0, key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, NULL, sizeof(bogus), key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, bogus, 0, key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = pCryptVerifySignatureW(hash, bogus, sizeof(bogus), key, NULL, 0); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + pCryptDestroyKey(key); + pCryptDestroyHash(hash); + pCryptReleaseContext(prov, 0); +} + static BOOL FindProvRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName, DWORD *pcbProvName, DWORD *pdwProvCount) { @@ -779,6 +854,7 @@ START_TEST(crypt) init_environment(); test_acquire_context(); test_incorrect_api_usage(); + test_verify_sig(); clean_up_environment(); } diff --git a/dlls/advpack/files.c b/dlls/advpack/files.c index 163f994cdf1..d0f948caca3 100644 --- a/dlls/advpack/files.c +++ b/dlls/advpack/files.c @@ -29,6 +29,7 @@ #include "winternl.h" #include "setupapi.h" #include "advpub.h" +#include "fdi.h" #include "wine/debug.h" #include "wine/unicode.h" #include "advpack_private.h" @@ -515,28 +516,29 @@ HRESULT WINAPI DelNodeRunDLL32W(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT /* The following defintions were copied from dlls/cabinet/cabinet.h */ -/* EXTRACTdest flags */ +/* SESSION Operation */ #define EXTRACT_FILLFILELIST 0x00000001 #define EXTRACT_EXTRACTFILES 0x00000002 -struct ExtractFileList { - LPSTR filename; - struct ExtractFileList *next; - BOOL unknown; /* always 1L */ -} ; +struct FILELIST{ + LPSTR FileName; + struct FILELIST *next; + BOOL Extracted; +}; -/* the first parameter of the function Extract */ typedef struct { - long result1; /* 0x000 */ - long unknown1[3]; /* 0x004 */ - struct ExtractFileList *filelist; /* 0x010 */ - long filecount; /* 0x014 */ - DWORD flags; /* 0x018 */ - char directory[0x104]; /* 0x01c */ - char lastfile[0x20c]; /* 0x120 */ -} EXTRACTdest; - -static HRESULT (WINAPI *pExtract)(EXTRACTdest*, LPCSTR); + INT FileSize; + ERF Error; + struct FILELIST *FileList; + INT FileCount; + INT Operation; + CHAR Destination[MAX_PATH]; + CHAR CurrentFile[MAX_PATH]; + CHAR Reserved[MAX_PATH]; + struct FILELIST *FilterList; +} SESSION; + +static HRESULT (WINAPI *pExtract)(SESSION*, LPCSTR); /* removes legal characters before and after file list, and * converts the file list to a NULL-separated list @@ -591,9 +593,9 @@ static LPSTR convert_file_list(LPCSTR FileList, DWORD *dwNumFiles) return szConvertedList; } -static void free_file_node(struct ExtractFileList *pNode) +static void free_file_node(struct FILELIST *pNode) { - HeapFree(GetProcessHeap(), 0, pNode->filename); + HeapFree(GetProcessHeap(), 0, pNode->FileName); HeapFree(GetProcessHeap(), 0, pNode); } @@ -622,23 +624,23 @@ static BOOL file_in_list(LPCSTR szFile, LPCSTR szFileList) /* removes nodes from the linked list that aren't specified in szFileList * returns the number of files that are in both the linked list and szFileList */ -static DWORD fill_file_list(EXTRACTdest *extractDest, LPCSTR szCabName, LPCSTR szFileList) +static DWORD fill_file_list(SESSION *session, LPCSTR szCabName, LPCSTR szFileList) { DWORD dwNumFound = 0; - struct ExtractFileList *pNode; - struct ExtractFileList *prev = NULL; + struct FILELIST *pNode; + struct FILELIST *prev = NULL; - extractDest->flags |= EXTRACT_FILLFILELIST; - if (pExtract(extractDest, szCabName)) + session->Operation |= EXTRACT_FILLFILELIST; + if (pExtract(session, szCabName)) { - extractDest->flags &= ~EXTRACT_FILLFILELIST; + session->Operation &= ~EXTRACT_FILLFILELIST; return -1; } - pNode = extractDest->filelist; + pNode = session->FileList; while (pNode) { - if (file_in_list(pNode->filename, szFileList)) + if (file_in_list(pNode->FileName, szFileList)) { prev = pNode; pNode = pNode->next; @@ -652,13 +654,13 @@ static DWORD fill_file_list(EXTRACTdest *extractDest, LPCSTR szCabName, LPCSTR s } else { - extractDest->filelist = pNode->next; + session->FileList = pNode->next; free_file_node(pNode); - pNode = extractDest->filelist; + pNode = session->FileList; } } - extractDest->flags &= ~EXTRACT_FILLFILELIST; + session->Operation &= ~EXTRACT_FILLFILELIST; return dwNumFound; } @@ -690,7 +692,7 @@ static DWORD fill_file_list(EXTRACTdest *extractDest, LPCSTR szCabName, LPCSTR s HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags, LPCSTR FileList, LPVOID LReserved, DWORD Reserved) { - EXTRACTdest extractDest; + SESSION session; HMODULE hCabinet; HRESULT res = S_OK; DWORD dwFileCount = 0; @@ -717,8 +719,8 @@ HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags, goto done; } - ZeroMemory(&extractDest, sizeof(EXTRACTdest)); - lstrcpyA(extractDest.directory, ExpandDir); + ZeroMemory(&session, sizeof(SESSION)); + lstrcpyA(session.Destination, ExpandDir); if (FileList) { @@ -729,7 +731,7 @@ HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags, goto done; } - dwFilesFound = fill_file_list(&extractDest, CabName, szConvertedList); + dwFilesFound = fill_file_list(&session, CabName, szConvertedList); if (dwFilesFound != dwFileCount) { res = E_FAIL; @@ -737,15 +739,15 @@ HRESULT WINAPI ExtractFilesA(LPCSTR CabName, LPCSTR ExpandDir, DWORD Flags, } } else - extractDest.flags |= EXTRACT_FILLFILELIST; + session.Operation |= EXTRACT_FILLFILELIST; - extractDest.flags |= EXTRACT_EXTRACTFILES; - res = pExtract(&extractDest, CabName); + session.Operation |= EXTRACT_EXTRACTFILES; + res = pExtract(&session, CabName); - if (extractDest.filelist) + if (session.FileList) { - struct ExtractFileList* curr = extractDest.filelist; - struct ExtractFileList* next; + struct FILELIST *curr = session.FileList; + struct FILELIST *next; while (curr) { diff --git a/dlls/atl/Makefile.in b/dlls/atl/Makefile.in index d419a5d558d..413c50d0719 100644 --- a/dlls/atl/Makefile.in +++ b/dlls/atl/Makefile.in @@ -4,7 +4,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = atl.dll IMPORTLIB = libatl.$(IMPLIBEXT) -IMPORTS = ole32 oleaut32 shlwapi user32 gdi32 advapi32 kernel32 +IMPORTS = ole32 oleaut32 user32 gdi32 advapi32 kernel32 EXTRALIBS = -luuid C_SRCS = \ diff --git a/dlls/atl/registrar.c b/dlls/atl/registrar.c index 2bc078d968c..9c0c73b6d85 100644 --- a/dlls/atl/registrar.c +++ b/dlls/atl/registrar.c @@ -27,7 +27,6 @@ #include "winreg.h" #include "objbase.h" #include "oaidl.h" -#include "shlwapi.h" #define ATL_INITGUID #include "atliface.h" @@ -243,10 +242,10 @@ static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOO strbuf_write(buf->str, &name, -1); }else if(key_type == DO_DELETE) { TRACE("Deleting %s\n", debugstr_w(buf->str)); - lres = SHDeleteKeyW(parent_key, buf->str); + lres = RegDeleteTreeW(parent_key, buf->str); }else { if(key_type == FORCE_REMOVE) - SHDeleteKeyW(parent_key, buf->str); + RegDeleteTreeW(parent_key, buf->str); lres = RegCreateKeyW(parent_key, buf->str, &hkey); if(lres != ERROR_SUCCESS) { WARN("Could not create(open) key: %08x\n", lres); diff --git a/dlls/cabinet/cabinet.h b/dlls/cabinet/cabinet.h index 4cd1f77e276..3b72ff8da61 100644 --- a/dlls/cabinet/cabinet.h +++ b/dlls/cabinet/cabinet.h @@ -631,29 +631,27 @@ static const cab_UWORD Zipmask[17] = { 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff \ } -/* EXTRACTdest flags */ +/* SESSION Operation */ #define EXTRACT_FILLFILELIST 0x00000001 #define EXTRACT_EXTRACTFILES 0x00000002 -struct ExtractFileList { - LPSTR filename; - struct ExtractFileList *next; - BOOL flag; -} ; +struct FILELIST{ + LPSTR FileName; + struct FILELIST *next; + BOOL Extracted; +}; -/* the first parameter of the function extract */ typedef struct { - long result1; /* 0x000 */ - long unknown1[3]; /* 0x004 */ - struct ExtractFileList *filelist; /* 0x010 */ - long filecount; /* 0x014 */ - DWORD flags; /* 0x018 */ - char directory[MAX_PATH]; /* 0x01c */ - char lastfile[MAX_PATH]; /* 0x120 */ - char unknown2[MAX_PATH]; /* 0x224 */ - struct ExtractFileList *filterlist; /* 0x328 */ -} EXTRACTdest; - + INT FileSize; + ERF Error; + struct FILELIST *FileList; + INT FileCount; + INT Operation; + CHAR Destination[MAX_PATH]; + CHAR CurrentFile[MAX_PATH]; + CHAR Reserved[MAX_PATH]; + struct FILELIST *FilterList; +} SESSION; /* from fdi.c */ void QTMupdatemodel(struct QTMmodel *model, int sym); diff --git a/dlls/cabinet/cabinet_main.c b/dlls/cabinet/cabinet_main.c index 6483a3f36d7..8b3c621e160 100644 --- a/dlls/cabinet/cabinet_main.c +++ b/dlls/cabinet/cabinet_main.c @@ -154,20 +154,20 @@ static long fdi_seek(INT_PTR hf, long dist, int seektype) return SetFilePointer(handle, dist, NULL, seektype); } -static void fill_file_node(struct ExtractFileList *pNode, LPCSTR szFilename) +static void fill_file_node(struct FILELIST *pNode, LPCSTR szFilename) { pNode->next = NULL; - pNode->flag = FALSE; + pNode->Extracted = FALSE; - pNode->filename = HeapAlloc(GetProcessHeap(), 0, strlen(szFilename) + 1); - lstrcpyA(pNode->filename, szFilename); + pNode->FileName = HeapAlloc(GetProcessHeap(), 0, strlen(szFilename) + 1); + lstrcpyA(pNode->FileName, szFilename); } -static BOOL file_in_list(const struct ExtractFileList *pNode, LPCSTR szFilename) +static BOOL file_in_list(const struct FILELIST *pNode, LPCSTR szFilename) { while (pNode) { - if (!lstrcmpiA(pNode->filename, szFilename)) + if (!lstrcmpiA(pNode->FileName, szFilename)) return TRUE; pNode = pNode->next; @@ -182,17 +182,17 @@ static INT_PTR fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pf { case fdintCOPY_FILE: { - struct ExtractFileList **fileList; - EXTRACTdest *pDestination = pfdin->pv; + struct FILELIST **fileList; + SESSION *pDestination = pfdin->pv; LPSTR szFullPath, szDirectory; HANDLE hFile = 0; DWORD dwSize; - dwSize = lstrlenA(pDestination->directory) + + dwSize = lstrlenA(pDestination->Destination) + lstrlenA("\\") + lstrlenA(pfdin->psz1) + 1; szFullPath = HeapAlloc(GetProcessHeap(), 0, dwSize); - lstrcpyA(szFullPath, pDestination->directory); + lstrcpyA(szFullPath, pDestination->Destination); lstrcatA(szFullPath, "\\"); lstrcatA(szFullPath, pfdin->psz1); @@ -201,26 +201,26 @@ static INT_PTR fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pf szDirectory = HeapAlloc(GetProcessHeap(), 0, dwSize); lstrcpynA(szDirectory, szFullPath, dwSize); - if (pDestination->flags & EXTRACT_FILLFILELIST) + if (pDestination->Operation & EXTRACT_FILLFILELIST) { - fileList = &pDestination->filelist; + fileList = &pDestination->FileList; while (*fileList) fileList = &((*fileList)->next); *fileList = HeapAlloc(GetProcessHeap(), 0, - sizeof(struct ExtractFileList)); + sizeof(struct FILELIST)); fill_file_node(*fileList, pfdin->psz1); - lstrcpyA(pDestination->lastfile, szFullPath); - pDestination->filecount++; + lstrcpyA(pDestination->CurrentFile, szFullPath); + pDestination->FileCount++; } - if ((pDestination->flags & EXTRACT_EXTRACTFILES) || - file_in_list(pDestination->filterlist, pfdin->psz1)) + if ((pDestination->Operation & EXTRACT_EXTRACTFILES) || + file_in_list(pDestination->FilterList, pfdin->psz1)) { /* skip this file if it is not in the file list */ - if (!file_in_list(pDestination->filelist, pfdin->psz1)) + if (!file_in_list(pDestination->FileList, pfdin->psz1)) return 0; /* create the destination directory if it doesn't exist */ @@ -281,25 +281,28 @@ static INT_PTR fdi_notify_extract(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pf * NOTES * The following members of the dest struct control the operation * of Extract: - * filelist [I] A linked list of filenames. Extract only extracts - * files from the cabinet that are in this list. - * filecount [O] Contains the number of files in filelist on - * completion. - * flags [I] See Operation. - * directory [I] The destination directory. - * lastfile [O] The last file extracted. + * FileSize [O] The size of all files extracted up to CurrentFile. + * Error [O] The error in case the extract operation fails. + * FileList [I] A linked list of filenames. Extract only extracts + * files from the cabinet that are in this list. + * FileCount [O] Contains the number of files in FileList on + * completion. + * Operation [I] See Operation. + * Destination [I] The destination directory. + * CurrentFile [O] The last file extracted. + * FilterList [I] A linked list of files that should not be extracted. * * Operation - * If flags contains EXTRACT_FILLFILELIST, then filelist will be - * filled with all the files in the cabinet. If flags contains - * EXTRACT_EXTRACTFILES, then only the files in the filelist will + * If Operation contains EXTRACT_FILLFILELIST, then FileList will be + * filled with all the files in the cabinet. If Operation contains + * EXTRACT_EXTRACTFILES, then only the files in the FileList will * be extracted from the cabinet. EXTRACT_FILLFILELIST can be called - * by itself, but EXTRACT_EXTRACTFILES must have a valid filelist - * in order to succeed. If flags contains both EXTRACT_FILLFILELIST + * by itself, but EXTRACT_EXTRACTFILES must have a valid FileList + * in order to succeed. If Operation contains both EXTRACT_FILLFILELIST * and EXTRACT_EXTRACTFILES, then all the files in the cabinet * will be extracted. */ -HRESULT WINAPI Extract(EXTRACTdest *dest, LPCSTR szCabName) +HRESULT WINAPI Extract(SESSION *dest, LPCSTR szCabName) { HRESULT res = S_OK; HFDI hfdi; @@ -321,7 +324,7 @@ HRESULT WINAPI Extract(EXTRACTdest *dest, LPCSTR szCabName) if (!hfdi) return E_FAIL; - if (GetFileAttributesA(dest->directory) == INVALID_FILE_ATTRIBUTES) + if (GetFileAttributesA(dest->Destination) == INVALID_FILE_ATTRIBUTES) return S_OK; /* split the cabinet name into path + name */ diff --git a/dlls/crypt32/main.c b/dlls/crypt32/main.c index aec288dbc23..9e53e4b5307 100644 --- a/dlls/crypt32/main.c +++ b/dlls/crypt32/main.c @@ -235,15 +235,3 @@ BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void* pvObject, phCertStore, phMsg, ppvContext); return FALSE; } - -BOOL WINAPI CryptVerifyMessageSignature(PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara, - DWORD dwSignerIndex, const BYTE* pbSignedBlob, DWORD cbSignedBlob, - BYTE* pbDecoded, DWORD* pcbDecoded, PCCERT_CONTEXT* ppSignerCert) -{ - FIXME("stub: %p, %d, %p, %d, %p, %p, %p\n", - pVerifyPara, dwSignerIndex, pbSignedBlob, cbSignedBlob, - pbDecoded, pcbDecoded, ppSignerCert); - if (ppSignerCert) - *ppSignerCert = NULL; - return FALSE; -} diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c index 3ce2bca2b5f..7cf1a301a2d 100644 --- a/dlls/crypt32/msg.c +++ b/dlls/crypt32/msg.c @@ -2114,15 +2114,21 @@ static BOOL CDecodeSignedMsg_VerifySignature(CDecodeMsg *msg, PCERT_INFO info) if (ret) { HCRYPTHASH hash; + CRYPT_HASH_BLOB reversedHash; if (msg->u.signed_data.info->rgSignerInfo[i].AuthAttrs.cAttr) hash = msg->u.signed_data.signerHandles[i].authAttrHash; else hash = msg->u.signed_data.signerHandles[i].contentHash; - ret = CryptVerifySignatureW(hash, - msg->u.signed_data.info->rgSignerInfo[i].EncryptedHash.pbData, - msg->u.signed_data.info->rgSignerInfo[i].EncryptedHash.cbData, - key, NULL, 0); + ret = CRYPT_ConstructBlob(&reversedHash, + &msg->u.signed_data.info->rgSignerInfo[i].EncryptedHash); + if (ret) + { + CRYPT_ReverseBytes(&reversedHash); + ret = CryptVerifySignatureW(hash, reversedHash.pbData, + reversedHash.cbData, key, NULL, 0); + CryptMemFree(reversedHash.pbData); + } CryptDestroyKey(key); } } @@ -2315,3 +2321,135 @@ LONG WINAPI CryptGetMessageSignerCount(DWORD dwMsgEncodingType, } return count; } + +static CERT_INFO *CRYPT_GetSignerCertInfoFromMsg(HCRYPTMSG msg, + DWORD dwSignerIndex) +{ + CERT_INFO *certInfo = NULL; + DWORD size; + + if (CryptMsgGetParam(msg, CMSG_SIGNER_CERT_INFO_PARAM, dwSignerIndex, NULL, + &size)) + { + certInfo = CryptMemAlloc(size); + if (certInfo) + { + if (!CryptMsgGetParam(msg, CMSG_SIGNER_CERT_INFO_PARAM, + dwSignerIndex, certInfo, &size)) + { + CryptMemFree(certInfo); + certInfo = NULL; + } + } + } + return certInfo; +} + +static PCCERT_CONTEXT WINAPI CRYPT_DefaultGetSignerCertificate(void *pvGetArg, + DWORD dwCertEncodingType, PCERT_INFO pSignerId, HCERTSTORE hMsgCertStore) +{ + return CertFindCertificateInStore(hMsgCertStore, dwCertEncodingType, 0, + CERT_FIND_SUBJECT_CERT, pSignerId, NULL); +} + +static inline PCCERT_CONTEXT CRYPT_GetSignerCertificate(HCRYPTMSG msg, + PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara, PCERT_INFO certInfo, HCERTSTORE store) +{ + PFN_CRYPT_GET_SIGNER_CERTIFICATE getCert; + + if (pVerifyPara->pfnGetSignerCertificate) + getCert = pVerifyPara->pfnGetSignerCertificate; + else + getCert = CRYPT_DefaultGetSignerCertificate; + return getCert(pVerifyPara->pvGetArg, + pVerifyPara->dwMsgAndCertEncodingType, certInfo, store); +} + +BOOL WINAPI CryptVerifyMessageSignature(PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara, + DWORD dwSignerIndex, const BYTE* pbSignedBlob, DWORD cbSignedBlob, + BYTE* pbDecoded, DWORD* pcbDecoded, PCCERT_CONTEXT* ppSignerCert) +{ + BOOL ret = FALSE; + DWORD size; + CRYPT_CONTENT_INFO *contentInfo; + + TRACE("(%p, %d, %p, %d, %p, %p, %p)\n", + pVerifyPara, dwSignerIndex, pbSignedBlob, cbSignedBlob, + pbDecoded, pcbDecoded, ppSignerCert); + + if (ppSignerCert) + *ppSignerCert = NULL; + if (pcbDecoded) + *pcbDecoded = 0; + if (!pVerifyPara || + pVerifyPara->cbSize != sizeof(CRYPT_VERIFY_MESSAGE_PARA) || + GET_CMSG_ENCODING_TYPE(pVerifyPara->dwMsgAndCertEncodingType) != + PKCS_7_ASN_ENCODING) + { + SetLastError(E_INVALIDARG); + return FALSE; + } + + ret = CryptDecodeObjectEx(pVerifyPara->dwMsgAndCertEncodingType, + PKCS_CONTENT_INFO, pbSignedBlob, cbSignedBlob, + CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG, NULL, + (LPBYTE)&contentInfo, &size); + if (ret) + { + if (strcmp(contentInfo->pszObjId, szOID_RSA_signedData)) + { + SetLastError(CRYPT_E_UNEXPECTED_MSG_TYPE); + ret = FALSE; + } + else + { + HCRYPTMSG msg = CryptMsgOpenToDecode( + pVerifyPara->dwMsgAndCertEncodingType, 0, CMSG_SIGNED, + pVerifyPara->hCryptProv, NULL, NULL); + + if (msg) + { + ret = CryptMsgUpdate(msg, contentInfo->Content.pbData, + contentInfo->Content.cbData, TRUE); + if (ret && pcbDecoded) + ret = CRYPT_CopyParam(pbDecoded, pcbDecoded, + contentInfo->Content.pbData, contentInfo->Content.cbData); + if (ret) + { + CERT_INFO *certInfo = CRYPT_GetSignerCertInfoFromMsg(msg, + dwSignerIndex); + + ret = FALSE; + if (certInfo) + { + HCERTSTORE store = CertOpenStore(CERT_STORE_PROV_MSG, + pVerifyPara->dwMsgAndCertEncodingType, + pVerifyPara->hCryptProv, 0, msg); + + if (store) + { + PCCERT_CONTEXT cert = CRYPT_GetSignerCertificate( + msg, pVerifyPara, certInfo, store); + + if (cert) + { + ret = CryptMsgControl(msg, 0, + CMSG_CTRL_VERIFY_SIGNATURE, cert->pCertInfo); + if (ret && ppSignerCert) + *ppSignerCert = cert; + else + CertFreeCertificateContext(cert); + } + CertCloseStore(store, 0); + } + } + CryptMemFree(certInfo); + } + CryptMsgClose(msg); + } + } + LocalFree(contentInfo); + } + TRACE("returning %d\n", ret); + return ret; +} diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c index 33b29c31a3a..68487a51d81 100644 --- a/dlls/crypt32/tests/msg.c +++ b/dlls/crypt32/tests/msg.c @@ -1110,6 +1110,12 @@ static const BYTE privKey[] = { 0x69, 0x1c, 0x7a, 0xff, 0x81, 0x9d, 0x53, 0x52, 0x97, 0x9a, 0x76, 0x79, 0xda, 0x93, 0x32, 0x16, 0xec, 0x69, 0x51, 0x1a, 0x4e, 0xc3, 0xf1, 0x72, 0x80, 0x78, 0x5e, 0x66, 0x4a, 0x8d, 0x85, 0x2f, 0x3f, 0xb2, 0xa7 }; +static BYTE pubKey[] = { +0x30,0x48,0x02,0x41,0x00,0xe2,0x54,0x3a,0xa7,0x83,0xb1,0x27,0x14,0x3e,0x59, +0xbb,0xb4,0x53,0xe6,0x1f,0xe7,0x5d,0xf1,0x21,0x68,0xad,0x85,0x53,0xdb,0x6b, +0x1e,0xeb,0x65,0x97,0x03,0x86,0x60,0xde,0xf3,0x6c,0x38,0x75,0xe0,0x4c,0x61, +0xbb,0xbc,0x62,0x17,0xa9,0xcd,0x79,0x3f,0x21,0x4e,0x96,0xcb,0x0e,0xdc,0x61, +0x94,0x30,0x18,0x10,0x6b,0xd0,0x1c,0x10,0x79,0x02,0x03,0x01,0x00,0x01 }; static void test_signed_msg_update(void) { @@ -2424,7 +2430,24 @@ static void test_msg_control(void) ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); CryptMsgClose(msg); - /* FIXME: need to test with a message with a valid signature and signer */ + /* A message with no data doesn't have a valid signature */ + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, 0, 0, NULL, NULL); + CryptMsgUpdate(msg, signedWithCertWithValidPubKeyEmptyContent, + sizeof(signedWithCertWithValidPubKeyEmptyContent), TRUE); + certInfo.SubjectPublicKeyInfo.Algorithm.pszObjId = oid_rsa_rsa; + certInfo.SubjectPublicKeyInfo.PublicKey.cbData = sizeof(pubKey); + certInfo.SubjectPublicKeyInfo.PublicKey.pbData = pubKey; + SetLastError(0xdeadbeef); + ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_SIGNATURE, &certInfo); + ok(!ret && GetLastError() == NTE_BAD_SIGNATURE, + "Expected NTE_BAD_SIGNATURE, got %08x\n", GetLastError()); + CryptMsgClose(msg); + /* Finally, this succeeds */ + msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING, 0, 0, 0, NULL, NULL); + CryptMsgUpdate(msg, signedWithCertWithValidPubKeyContent, + sizeof(signedWithCertWithValidPubKeyContent), TRUE); + ret = CryptMsgControl(msg, 0, CMSG_CTRL_VERIFY_SIGNATURE, &certInfo); + ok(ret, "CryptMsgControl failed: %08x\n", GetLastError()); } static void test_msg_get_signer_count(void) @@ -2464,6 +2487,145 @@ static void test_msg_get_signer_count(void) ok(count == 1, "Expected 1, got %d\n", count); } +static const BYTE signedWithCertEmptyContent[] = { +0x30,0x81,0xdf,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0, +0x81,0xd1,0x30,0x81,0xce,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a, +0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x02,0x06,0x00,0xa0,0x7c, +0x30,0x7a,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30,0x11, +0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e, +0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,0x30, +0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30, +0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11,0x06, +0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67, +0x00,0x30,0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00,0xa3,0x16,0x30,0x14,0x30, +0x12,0x06,0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01, +0xff,0x02,0x01,0x01,0x31,0x37,0x30,0x35,0x02,0x01,0x01,0x30,0x1a,0x30,0x15, +0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e, +0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86, +0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04, +0x00 }; +static const BYTE signedWithCertContent[] = { +0x30,0x82,0x01,0x32,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02, +0xa0,0x82,0x01,0x23,0x30,0x82,0x01,0x1f,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c, +0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x13,0x06, +0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x06,0x04,0x04,0x01, +0x02,0x03,0x04,0xa0,0x7c,0x30,0x7a,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30, +0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61, +0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31, +0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36, +0x30,0x31,0x30,0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15, +0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e, +0x20,0x4c,0x61,0x6e,0x67,0x00,0x30,0x07,0x30,0x02,0x06,0x00,0x03,0x01,0x00, +0xa3,0x16,0x30,0x14,0x30,0x12,0x06,0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04, +0x08,0x30,0x06,0x01,0x01,0xff,0x02,0x01,0x01,0x31,0x77,0x30,0x75,0x02,0x01, +0x01,0x30,0x1a,0x30,0x15,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13, +0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30, +0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04, +0x06,0x00,0x05,0x00,0x04,0x40,0x81,0xa6,0x70,0xb3,0xef,0x59,0xd1,0x66,0xd1, +0x9b,0xc0,0x9a,0xb6,0x9a,0x5e,0x6d,0x6f,0x6d,0x0d,0x59,0xa9,0xaa,0x6e,0xe9, +0x2c,0xa0,0x1e,0xee,0xc2,0x60,0xbc,0x59,0xbe,0x3f,0x63,0x06,0x8d,0xc9,0x11, +0x1d,0x23,0x64,0x92,0xef,0x2e,0xfc,0x57,0x29,0xa4,0xaf,0xe0,0xee,0x93,0x19, +0x39,0x51,0xe4,0x44,0xb8,0x0b,0x28,0xf4,0xa8,0x0d }; +static const BYTE signedWithCertWithPubKeyContent[] = { +0x30,0x81,0xfc,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x02,0xa0, +0x81,0xee,0x30,0x81,0xeb,0x02,0x01,0x01,0x31,0x0e,0x30,0x0c,0x06,0x08,0x2a, +0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x02,0x06,0x00,0xa0,0x81, +0x98,0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13, +0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c, +0x61,0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30, +0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30, +0x31,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30, +0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61, +0x6e,0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d, +0x01,0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06, +0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12, +0x06,0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff, +0x02,0x01,0x01,0x31,0x37,0x30,0x35,0x02,0x01,0x01,0x30,0x1a,0x30,0x15,0x31, +0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20, +0x4c,0x61,0x6e,0x67,0x00,0x02,0x01,0x01,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48, +0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x00 }; + +static void test_verify_message_signature(void) +{ + BOOL ret; + CRYPT_VERIFY_MESSAGE_PARA para = { 0 }; + PCCERT_CONTEXT cert; + DWORD cbDecoded; + + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(NULL, 0, NULL, 0, NULL, 0, NULL); + ok(!ret && GetLastError() == E_INVALIDARG, + "Expected E_INVALIDARG, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, NULL, 0, NULL, 0, NULL); + ok(!ret && GetLastError() == E_INVALIDARG, + "Expected E_INVALIDARG, got %08x\n", GetLastError()); + para.cbSize = sizeof(para); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, NULL, 0, NULL, 0, NULL); + ok(!ret && GetLastError() == E_INVALIDARG, + "Expected E_INVALIDARG, got %08x\n", GetLastError()); + para.cbSize = 0; + para.dwMsgAndCertEncodingType = PKCS_7_ASN_ENCODING; + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, NULL, 0, NULL, 0, NULL); + ok(!ret && GetLastError() == E_INVALIDARG, + "Expected E_INVALIDARG, got %08x\n", GetLastError()); + para.cbSize = sizeof(para); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, NULL, 0, NULL, 0, NULL); + ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD, + "Expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError()); + /* Check whether cert is set on error */ + cert = (PCCERT_CONTEXT)0xdeadbeef; + ret = CryptVerifyMessageSignature(¶, 0, NULL, 0, NULL, 0, &cert); + ok(cert == NULL, "Expected NULL cert\n"); + /* Check whether cbDecoded is set on error */ + cbDecoded = 0xdeadbeef; + ret = CryptVerifyMessageSignature(¶, 0, NULL, 0, NULL, &cbDecoded, + NULL); + ok(!cbDecoded, "Expected 0\n"); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, dataEmptyBareContent, + sizeof(dataEmptyBareContent), NULL, 0, NULL); + ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG, + "Expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, dataEmptyContent, + sizeof(dataEmptyContent), NULL, 0, NULL); + ok(!ret && GetLastError() == CRYPT_E_UNEXPECTED_MSG_TYPE, + "Expected CRYPT_E_UNEXPECTED_MSG_TYPE, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, signedEmptyBareContent, + sizeof(signedEmptyBareContent), NULL, 0, NULL); + ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG, + "Expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, signedEmptyContent, + sizeof(signedEmptyContent), NULL, 0, NULL); + ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND, + "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = CryptVerifyMessageSignature(¶, 0, signedContent, + sizeof(signedContent), NULL, 0, NULL); + ok(!ret && GetLastError() == CRYPT_E_NOT_FOUND, + "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError()); + /* FIXME: Windows fails with CRYPT_E_NOT_FOUND for these messages, but + * their signer certs have invalid public keys that fail to decode. In + * Wine therefore the failure is an ASN error. Need some messages with + * valid public keys and invalid signatures to check against. + */ + ret = CryptVerifyMessageSignature(¶, 0, signedWithCertEmptyContent, + sizeof(signedWithCertEmptyContent), NULL, 0, NULL); + ok(!ret, "Expected failure\n"); + ret = CryptVerifyMessageSignature(¶, 0, signedWithCertContent, + sizeof(signedWithCertContent), NULL, 0, NULL); + ok(!ret, "Expected failure\n"); + ret = CryptVerifyMessageSignature(¶, 0, signedWithCertWithPubKeyContent, + sizeof(signedWithCertWithPubKeyContent), NULL, 0, NULL); + ok(!ret, "Expected failure\n"); +} + START_TEST(msg) { init_function_pointers(); @@ -2483,4 +2645,5 @@ START_TEST(msg) /* simplified message functions */ test_msg_get_signer_count(); + test_verify_message_signature(); } diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index 65dc7d6619b..2470675ff02 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -57,10 +57,6 @@ static void DSOUND_RecalcPrimary(DirectSoundDevice *device) if (device->pwfx->nSamplesPerSec >= 80000) fraglen *= 2; - /* If in emulation mode, reduce fragment size until an integer number of them fits in the buffer */ - if (!device->driver) - while (device->buflen % fraglen) - fraglen -= nBlockAlign; device->fraglen = fraglen; device->helfrags = device->buflen / fraglen; TRACE("fraglen=%d helfrags=%d\n", device->fraglen, device->helfrags); @@ -77,20 +73,51 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) HRESULT err = DS_OK; TRACE("(%p)\n", device); + if (device->driver) + { + err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx, + DSBCAPS_PRIMARYBUFFER,0, + &(device->buflen),&(device->buffer), + (LPVOID*)&(device->hwbuf)); + + if (err != DS_OK) { + WARN("IDsDriver_CreateSoundBuffer failed, falling back to waveout\n"); + /* Wine-only: close wine directsound driver, then reopen without WAVE_DIRECTSOUND */ + device->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT; + IDsDriver_Close(device->driver); + waveOutClose(device->hwo); + IDsDriver_Release(device->driver); + device->driver = NULL; + device->buffer = NULL; + device->hwo = 0; + err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode, device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device, CALLBACK_FUNCTION)); + if (err != DS_OK) + { + WARN("Falling back to waveout failed too! Giving up\n"); + return err; + } + } + } + + if (device->state == STATE_PLAYING) device->state = STATE_STARTING; + else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED; + /* are we using waveOut stuff? */ if (!device->driver) { LPBYTE newbuf; LPWAVEHDR headers = NULL; - DWORD buflen; - HRESULT merr = DS_OK; + DWORD buflen, overshot, oldbuflen; + unsigned int c; + /* Start in pause mode, to allow buffers to get filled */ waveOutPause(device->hwo); - if (device->state == STATE_PLAYING) device->state = STATE_STARTING; - else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED; /* on original windows, the buffer it set to a fixed size, no matter what the settings are. on windows this size is always fixed (tested on win-xp) */ - buflen = ds_hel_buflen; + if (!device->buflen) + buflen = ds_hel_buflen; + else /* In case we move from hw accelerated to waveout */ + buflen = device->buflen; buflen -= ds_hel_buflen % device->pwfx->nBlockAlign; TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer); @@ -101,18 +128,14 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) else newbuf = HeapAlloc(GetProcessHeap(),0,buflen); - - if (newbuf == NULL) { + if (!newbuf) { ERR("failed to allocate primary buffer\n"); - merr = DSERR_OUTOFMEMORY; + return DSERR_OUTOFMEMORY; /* but the old buffer might still exist and must be re-prepared */ - } else { - device->playpos = 0; - device->mixpos = 0; - device->buffer = newbuf; - device->buflen = buflen; } + oldbuflen = device->buflen; + device->buflen = buflen; DSOUND_RecalcPrimary(device); if (device->pwave) headers = HeapReAlloc(GetProcessHeap(),0,device->pwave, device->helfrags * sizeof(WAVEHDR)); @@ -121,60 +144,42 @@ static HRESULT DSOUND_PrimaryOpen(DirectSoundDevice *device) if (!headers) { ERR("failed to allocate wave headers\n"); - merr = DSERR_OUTOFMEMORY; + HeapFree(GetProcessHeap(), 0, newbuf); + device->buflen = oldbuflen; + DSOUND_RecalcPrimary(device); + return DSERR_OUTOFMEMORY; } - else if (device->buffer) { - unsigned c; - - device->pwave = headers; - - /* sanity */ - if(device->buflen % device->helfrags){ - ERR("Bad helfrags resolution\n"); - } - /* prepare fragment headers */ - for (c=0; chelfrags; c++) { - device->pwave[c].lpData = (char*)device->buffer + c*device->fraglen; - device->pwave[c].dwBufferLength = device->fraglen; - device->pwave[c].dwUser = (DWORD)device; - device->pwave[c].dwFlags = 0; - device->pwave[c].dwLoops = 0; - err = mmErr(waveOutPrepareHeader(device->hwo,&device->pwave[c],sizeof(WAVEHDR))); - if (err != DS_OK) { - while (c--) - waveOutUnprepareHeader(device->hwo,&device->pwave[c],sizeof(WAVEHDR)); - break; - } + device->buffer = newbuf; + device->pwave = headers; + + /* prepare fragment headers */ + for (c=0; chelfrags; c++) { + device->pwave[c].lpData = (char*)device->buffer + c*device->fraglen; + device->pwave[c].dwBufferLength = device->fraglen; + device->pwave[c].dwUser = (DWORD)device; + device->pwave[c].dwFlags = 0; + device->pwave[c].dwLoops = 0; + err = mmErr(waveOutPrepareHeader(device->hwo,&device->pwave[c],sizeof(WAVEHDR))); + if (err != DS_OK) { + while (c--) + waveOutUnprepareHeader(device->hwo,&device->pwave[c],sizeof(WAVEHDR)); + break; } - - device->pwplay = 0; - device->pwqueue = 0; - device->playpos = 0; - device->mixpos = 0; - FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0); - TRACE("fraglen=%d\n", device->fraglen); } - if ((err == DS_OK) && (merr != DS_OK)) - err = merr; - } else if (!device->hwbuf) { - device->playpos = 0; - device->mixpos = 0; - err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx, - DSBCAPS_PRIMARYBUFFER,0, - &(device->buflen),&(device->buffer), - (LPVOID*)&(device->hwbuf)); - if (err != DS_OK) { - WARN("IDsDriver_CreateSoundBuffer failed\n"); - return err; + + overshot = device->buflen % device->helfrags; + /* sanity */ + if(overshot) + { + WARN("helfrags (%d x %d) doesn't fit entirely in buflen (%d) overshot: %d\n", device->helfrags, device->fraglen, device->buflen, overshot); + device->pwave[device->helfrags - 1].dwBufferLength += overshot; } - if (device->state == STATE_PLAYING) device->state = STATE_STARTING; - else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED; - device->playpos = 0; - device->mixpos = 0; - FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0); + TRACE("fraglen=%d\n", device->fraglen); } + FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0); + device->pwplay = device->pwqueue = device->playpos = device->mixpos = 0; DSOUND_RecalcPrimary(device); return err; @@ -212,35 +217,7 @@ HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) HRESULT err = DS_OK; TRACE("(%p)\n", device); - device->playpos = 0; - device->mixpos = 0; - device->buflen = device->pwfx->nAvgBytesPerSec; - - /* FIXME: verify that hardware capabilities (DSCAPS_PRIMARY flags) match */ - - if (device->driver) { - err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx, - DSBCAPS_PRIMARYBUFFER,0, - &(device->buflen),&(device->buffer), - (LPVOID*)&(device->hwbuf)); - if (err != DS_OK) { - WARN("IDsDriver_CreateSoundBuffer failed, falling back to waveout\n"); - /* Wine-only: close wine directsound driver, then reopen without WAVE_DIRECTSOUND */ - device->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT; - waveOutClose(device->hwo); - IDsDriver_Release(device->driver); - device->driver = NULL; - device->buffer = NULL; - device->hwo = 0; - err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode, device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device, CALLBACK_FUNCTION)); - if (err != DS_OK) - { - WARN("Falling back to waveout failed too! Giving up\n"); - return err; - } - } - } - + device->buflen = ds_hel_buflen; err = DSOUND_PrimaryOpen(device); if (err != DS_OK) { @@ -302,34 +279,10 @@ HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) if (device->hwbuf) { err = IDsDriverBuffer_Stop(device->hwbuf); if (err == DSERR_BUFFERLOST) { - DWORD flags = CALLBACK_FUNCTION | WAVE_DIRECTSOUND; - /* Wine-only: the driver wants us to reopen the device */ - /* FIXME: check for errors */ - IDsDriverBuffer_Release(device->hwbuf); - waveOutClose(device->hwo); - device->hwo = 0; - err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode, - device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device, - flags)); - if (err == DS_OK) { - device->playpos = 0; - device->mixpos = 0; - err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx, - DSBCAPS_PRIMARYBUFFER,0, - &(device->buflen),&(device->buffer), - (LPVOID)&(device->hwbuf)); - if (err != DS_OK) - WARN("IDsDriver_CreateSoundBuffer failed\n"); - else if (device->state == STATE_STOPPING) - device->state = STATE_STOPPED; - else if (device->state == STATE_PLAYING) - device->state = STATE_STARTING; - if (err == DS_OK) - FillMemory(device->buffer, device->buflen, (device->pwfx->wBitsPerSample == 8) ? 128 : 0); - - } else { - WARN("waveOutOpen failed\n"); - } + DSOUND_PrimaryClose(device); + err = DSOUND_PrimaryOpen(device); + if (FAILED(err)) + WARN("DSOUND_PrimaryOpen failed\n"); } else if (err != DS_OK) { WARN("IDsDriverBuffer_Stop failed\n"); } @@ -423,50 +376,36 @@ HRESULT DSOUND_PrimarySetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) CopyMemory(device->pwfx, wfex, cp_size); - if (device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) { - DWORD flags = CALLBACK_FUNCTION; - if (device->driver) - flags |= WAVE_DIRECTSOUND; - /* FIXME: check for errors */ - DSOUND_PrimaryClose(device); - waveOutClose(device->hwo); - device->hwo = 0; - err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode, - device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device, - flags)); - if (err == DS_OK) { - err = DSOUND_PrimaryOpen(device); - if (err != DS_OK) { - WARN("DSOUND_PrimaryOpen failed\n"); - goto done; - } - } else { - WARN("waveOutOpen failed\n"); + if (!(device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) && device->hwbuf) { + err = IDsDriverBuffer_SetFormat(device->hwbuf, device->pwfx); + if (err != DSERR_BUFFERLOST && FAILED(err)) { + WARN("IDsDriverBuffer_SetFormat failed\n"); goto done; } - } else if (device->hwbuf) { - err = IDsDriverBuffer_SetFormat(device->hwbuf, device->pwfx); - if (err == DSERR_BUFFERLOST) { - /* Wine-only: the driver wants us to recreate the HW buffer */ - IDsDriverBuffer_Release(device->hwbuf); - device->playpos = 0; - device->mixpos = 0; - err = IDsDriver_CreateSoundBuffer(device->driver,device->pwfx, - DSBCAPS_PRIMARYBUFFER,0, - &(device->buflen),&(device->buffer), - (LPVOID)&(device->hwbuf)); - if (err != DS_OK) { - WARN("IDsDriver_CreateSoundBuffer failed\n"); + else DSOUND_RecalcPrimary(device); + } + + if (err == DSERR_BUFFERLOST || device->drvdesc.dwFlags & DSDDESC_DOMMSYSTEMSETFORMAT) + { + DSOUND_PrimaryClose(device); + + if (!device->driver) + { + waveOutClose(device->hwo); + device->hwo = 0; + err = mmErr(waveOutOpen(&(device->hwo), device->drvdesc.dnDevNode, device->pwfx, (DWORD_PTR)DSOUND_callback, (DWORD)device, CALLBACK_FUNCTION)); + if (FAILED(err)) + { + WARN("waveOutOpen failed\n"); goto done; } - if (device->state == STATE_PLAYING) device->state = STATE_STARTING; - else if (device->state == STATE_STOPPING) device->state = STATE_STOPPED; - } else if (FAILED(err)) { - WARN("IDsDriverBuffer_SetFormat failed\n"); + } + + err = DSOUND_PrimaryOpen(device); + if (err != DS_OK) { + WARN("DSOUND_PrimaryOpen failed\n"); goto done; } - /* FIXME: should we set err back to DS_OK in all cases ? */ - DSOUND_RecalcPrimary(device); } if (nSamplesPerSec != device->pwfx->nSamplesPerSec || bpp != device->pwfx->wBitsPerSample || chans != device->pwfx->nChannels) { diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index 4bf19b4bf12..a3689eb406a 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -200,7 +200,7 @@ BOOL DC_FreeDCPtr( DC *dc ) */ static BOOL DC_DeleteObject( HGDIOBJ handle, void *obj ) { - DC_ReleaseDCPtr( obj ); + GDI_ReleaseObj( handle ); return DeleteDC( handle ); } @@ -740,25 +740,23 @@ HDC WINAPI CreateICW( LPCWSTR driver, LPCWSTR device, LPCWSTR output, HDC WINAPI CreateCompatibleDC( HDC hdc ) { DC *dc, *origDC; - const DC_FUNCTIONS *funcs; - PHYSDEV physDev; + const DC_FUNCTIONS *funcs = NULL; + PHYSDEV physDev = NULL; GDI_CheckNotLock(); - if ((origDC = GDI_GetObjPtr( hdc, DC_MAGIC ))) + if ((origDC = DC_GetDCPtr( hdc ))) { - funcs = origDC->funcs; - physDev = origDC->physDev; + if (GetObjectType( hdc ) == OBJ_DC) + { + funcs = origDC->funcs; + physDev = origDC->physDev; + } DC_ReleaseDCPtr( origDC ); /* can't hold the lock while loading the driver */ - funcs = DRIVER_get_driver( funcs ); - } - else - { - funcs = DRIVER_load_driver( displayW ); - physDev = NULL; + if (funcs) funcs = DRIVER_get_driver( funcs ); } - if (!funcs) return 0; + if (!funcs && !(funcs = DRIVER_load_driver( displayW ))) return 0; if (!(dc = DC_AllocDC( funcs, MEMORY_DC_MAGIC ))) goto error; diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c index f2dd4e14c62..0388c71b941 100644 --- a/dlls/gdi32/gdiobj.c +++ b/dlls/gdi32/gdiobj.c @@ -528,15 +528,9 @@ static DWORD get_dpi( void ) * * Increment the reference count of a GDI object. */ -static inline void inc_ref_count( HGDIOBJ handle ) +static inline void inc_ref_count( GDIOBJHDR *header ) { - GDIOBJHDR *header; - - if ((header = GDI_GetObjPtr( handle, MAGIC_DONTCARE ))) - { - header->dwCount++; - GDI_ReleaseObj( handle ); - } + header->dwCount++; } @@ -829,7 +823,7 @@ BOOL WINAPI DeleteObject( HGDIOBJ obj ) { if(dc->funcs->pDeleteObject) dc->funcs->pDeleteObject( dc->physDev, obj ); - GDI_ReleaseObj( header->hdcs->hdc ); + DC_ReleaseDCPtr( dc ); } tmp = header->hdcs; header->hdcs = header->hdcs->next; @@ -1159,7 +1153,7 @@ HGDIOBJ WINAPI SelectObject( HDC hdc, HGDIOBJ hObj ) ret = header->funcs->pSelectObject( hObj, header, hdc ); if (ret && ret != hObj && HandleToULong(ret) > COMPLEXREGION) { - inc_ref_count( hObj ); + inc_ref_count( header ); dec_ref_count( ret ); } } diff --git a/dlls/gdi32/printdrv.c b/dlls/gdi32/printdrv.c index 0cca2ad08ee..944453685ea 100644 --- a/dlls/gdi32/printdrv.c +++ b/dlls/gdi32/printdrv.c @@ -468,7 +468,7 @@ static int CreateSpoolFile(LPCSTR pszOutput) RegCloseKey(hkey); } if (!psCmd[0] && !strncmp("LPR:",pszOutput,4)) - sprintf(psCmd,"|lpr -P%s",pszOutput+4); + sprintf(psCmd,"|lpr -P'%s'",pszOutput+4); TRACE("Got printerSpoolCommand '%s' for output device '%s'\n", psCmd, pszOutput); diff --git a/dlls/gphoto2.ds/Makefile.in b/dlls/gphoto2.ds/Makefile.in index 042cbc3322f..4858200f4d9 100644 --- a/dlls/gphoto2.ds/Makefile.in +++ b/dlls/gphoto2.ds/Makefile.in @@ -3,7 +3,7 @@ TOPOBJDIR = ../.. SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = gphoto2.ds -IMPORTS = comctl32 user32 gdi32 kernel32 ntdll +IMPORTS = comctl32 user32 gdi32 advapi32 kernel32 ntdll EXTRALIBS = @GPHOTO2LIBS@ EXTRAINCL = @GPHOTO2INCL@ diff --git a/dlls/gphoto2.ds/gphoto2_De.rc b/dlls/gphoto2.ds/gphoto2_De.rc index 000f3e3a968..ee17d6f4a11 100644 --- a/dlls/gphoto2.ds/gphoto2_De.rc +++ b/dlls/gphoto2.ds/gphoto2_De.rc @@ -29,9 +29,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "Gewählte importieren",IDC_IMPORT,225,252,56,14 - PUSHBUTTON "Alle importieren",IDC_IMPORTALL,7,252,52,14 - PUSHBUTTON "Beenden",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "Gewählte importieren",IDC_IMPORT,152,252,72,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,64,14 + PUSHBUTTON "Alle importieren",IDC_IMPORTALL,80,252,64,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,230,252,76,14 + PUSHBUTTON "Beenden",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/gphoto2_En.rc b/dlls/gphoto2.ds/gphoto2_En.rc index 8b3b47973ef..793bfa48125 100644 --- a/dlls/gphoto2.ds/gphoto2_En.rc +++ b/dlls/gphoto2.ds/gphoto2_En.rc @@ -29,9 +29,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "Import Selected",IDC_IMPORT,225,252,56,14 - PUSHBUTTON "Import All",IDC_IMPORTALL,7,252,52,14 - PUSHBUTTON "Exit",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "Import Selected",IDC_IMPORT,152,252,72,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,64,14 + PUSHBUTTON "Import All",IDC_IMPORTALL,80,252,64,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,230,252,76,14 + PUSHBUTTON "Exit",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/gphoto2_Fr.rc b/dlls/gphoto2.ds/gphoto2_Fr.rc index c8a53be88b7..2645fdf7ec6 100644 --- a/dlls/gphoto2.ds/gphoto2_Fr.rc +++ b/dlls/gphoto2.ds/gphoto2_Fr.rc @@ -29,9 +29,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "Importer la sélection",IDC_IMPORT,225,252,56,14 - PUSHBUTTON "Importer tous",IDC_IMPORTALL,7,252,52,14 - PUSHBUTTON "Fermer",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "Importer la sélection",IDC_IMPORT,152,252,72,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,64,14 + PUSHBUTTON "Importer tous",IDC_IMPORTALL,80,252,64,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,230,252,76,14 + PUSHBUTTON "Fermer",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/gphoto2_Ko.rc b/dlls/gphoto2.ds/gphoto2_Ko.rc index a486ce80fae..daaf24c3b5e 100644 --- a/dlls/gphoto2.ds/gphoto2_Ko.rc +++ b/dlls/gphoto2.ds/gphoto2_Ko.rc @@ -30,9 +30,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "¼±ÅÃµÈ °ÍÀ» ºÒ·¯¿À±â",IDC_IMPORT,225,252,56,14 - PUSHBUTTON "¸ðµÎ ºÒ·¯¿À±â",IDC_IMPORTALL,7,252,52,14 - PUSHBUTTON "³ª°¡±â",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "¼±ÅÃµÈ °ÍÀ» ºÒ·¯¿À±â",IDC_IMPORT,152,252,72,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,64,14 + PUSHBUTTON "¸ðµÎ ºÒ·¯¿À±â",IDC_IMPORTALL,80,252,64,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,230,252,76,14 + PUSHBUTTON "³ª°¡±â",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/gphoto2_Nl.rc b/dlls/gphoto2.ds/gphoto2_Nl.rc index 805ce492a0d..fe8c0061cca 100644 --- a/dlls/gphoto2.ds/gphoto2_Nl.rc +++ b/dlls/gphoto2.ds/gphoto2_Nl.rc @@ -29,9 +29,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "Importeer geselecteerde bestanden",IDC_IMPORT,225,252,56,14 - PUSHBUTTON "Importeer alles",IDC_IMPORTALL,7,252,52,14 - PUSHBUTTON "Afsluiten",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "Importeer geselecteerde bestanden",IDC_IMPORT,120,252,120,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,48,14 + PUSHBUTTON "Importeer alles",IDC_IMPORTALL,60,252,56,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,244,252,76,14 + PUSHBUTTON "Afsluiten",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/gphoto2_No.rc b/dlls/gphoto2.ds/gphoto2_No.rc index a5c5ad0eb82..f29beb29f29 100644 --- a/dlls/gphoto2.ds/gphoto2_No.rc +++ b/dlls/gphoto2.ds/gphoto2_No.rc @@ -29,9 +29,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "Importer valgte",IDC_IMPORT,225,252,56,14 - PUSHBUTTON "Importer alle",IDC_IMPORTALL,7,252,52,14 - PUSHBUTTON "Avslutt",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "Importer valgte",IDC_IMPORT,152,252,72,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,64,14 + PUSHBUTTON "Importer alle",IDC_IMPORTALL,80,252,64,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,230,252,76,14 + PUSHBUTTON "Avslutt",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/gphoto2_Pl.rc b/dlls/gphoto2.ds/gphoto2_Pl.rc index c95eb20c022..e8657afd1ff 100644 --- a/dlls/gphoto2.ds/gphoto2_Pl.rc +++ b/dlls/gphoto2.ds/gphoto2_Pl.rc @@ -30,9 +30,11 @@ FONT 8, "MS Sans Serif" BEGIN CONTROL "List1",IDC_LIST1,"SysListView32", LVS_ICON | WS_BORDER | WS_TABSTOP,7,7,358,229 - DEFPUSHBUTTON "Skopiuj wybrane",IDC_IMPORT,205,252,76,14 - PUSHBUTTON "Skopiuj wszystkie",IDC_IMPORTALL,7,252,72,14 - PUSHBUTTON "Zakoñcz",IDC_EXIT,295,252,50,14 + DEFPUSHBUTTON "Skopiuj wybrane",IDC_IMPORT,152,252,72,14 + PUSHBUTTON "Preview",IDC_FETCH,7,252,64,14 + PUSHBUTTON "Skopiuj wszystkie",IDC_IMPORTALL,80,252,64,14 + CONTROL "Skip This Dialog",IDC_SKIP,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,230,252,76,14 + PUSHBUTTON "Zakoñcz",IDC_EXIT,315,252,50,14 END IDD_DIALOG1 DIALOG DISCARDABLE 0, 0, 186, 46 diff --git a/dlls/gphoto2.ds/resource.h b/dlls/gphoto2.ds/resource.h index d972978e648..a13915a4766 100644 --- a/dlls/gphoto2.ds/resource.h +++ b/dlls/gphoto2.ds/resource.h @@ -28,3 +28,5 @@ #define IDC_IMPORTALL 1002 #define IDC_EXIT 1003 #define IDC_BITMAP 1004 +#define IDC_FETCH 1005 +#define IDC_SKIP 1006 diff --git a/dlls/gphoto2.ds/ui.c b/dlls/gphoto2.ds/ui.c index e709984fac7..7d43744765d 100644 --- a/dlls/gphoto2.ds/ui.c +++ b/dlls/gphoto2.ds/ui.c @@ -31,6 +31,7 @@ #include "winuser.h" #include "winnls.h" #include "wingdi.h" +#include "winreg.h" #include "commctrl.h" #include "prsht.h" #include "twain.h" @@ -38,6 +39,9 @@ #include "wine/debug.h" #include "resource.h" +LPCSTR settings_key = "Software\\Wine\\Gphoto2"; +LPCSTR settings_value = "SkipUI"; +static BOOL disable_dialog; static HBITMAP static_bitmap; static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -45,6 +49,43 @@ static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA return FALSE; } +static void on_disable_dialog_clicked(HWND dialog) +{ + if (IsDlgButtonChecked(dialog, IDC_SKIP) == BST_CHECKED) + disable_dialog = TRUE; + else + disable_dialog = FALSE; +} + +static void UI_EndDialog(HWND hwnd, INT_PTR rc) +{ + if (disable_dialog) + { + HKEY key; + const DWORD data = 1; + if (RegCreateKeyExA(HKEY_CURRENT_USER, settings_key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS) + { + RegSetValueExA(key, settings_value, 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD)); + RegCloseKey(key); + } + } + EndDialog(hwnd, rc); +} + +static int GetAllImages() +{ + struct gphoto2_file *file; + int has_images = 0; + + LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry) + { + if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) + file->download = TRUE; + has_images = 1; + } + return has_images; +} + static void PopulateListView(HWND List) { struct gphoto2_file *file; @@ -120,14 +161,8 @@ static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP { case WM_INITDIALOG: { - HIMAGELIST ilist = 0; - HWND list = GetDlgItem(hwnd,IDC_LIST1); + disable_dialog = FALSE; EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE); - - PopulateImageList(&ilist,list); - - SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist); - PopulateListView(list); } break; case WM_NOTIFY: @@ -144,8 +179,11 @@ static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP case WM_COMMAND: switch LOWORD(wParam) { + case IDC_SKIP: + on_disable_dialog_clicked(hwnd); + break; case IDC_EXIT: - EndDialog(hwnd,0); + UI_EndDialog(hwnd,0); break; case IDC_IMPORT: { @@ -155,7 +193,7 @@ static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP if (count ==0) { - EndDialog(hwnd,0); + UI_EndDialog(hwnd,0); return FALSE; } @@ -184,38 +222,28 @@ static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP } } - EndDialog(hwnd,1); + UI_EndDialog(hwnd,1); } break; case IDC_IMPORTALL: { - HWND list = GetDlgItem(hwnd,IDC_LIST1); - int count = SendMessageA(list,LVM_GETITEMCOUNT,0,0); - int i; - - if (count ==0) + if (!GetAllImages()) { - EndDialog(hwnd,0); + UI_EndDialog(hwnd,0); return FALSE; } + UI_EndDialog(hwnd,1); + } + break; + case IDC_FETCH: + { + HIMAGELIST ilist = 0; + HWND list = GetDlgItem(hwnd,IDC_LIST1); + PopulateImageList(&ilist,list); - for ( i = 0; i < count; i++) - { - LVITEMA item; - struct gphoto2_file *file; - - - item.mask = LVIF_PARAM; - item.iItem = i; - item.iSubItem = 0; - - SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item); - - file = (struct gphoto2_file*)item.lParam; - file->download = TRUE; - } - - EndDialog(hwnd,1); + SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist); + PopulateListView(list); + EnableWindow(GetDlgItem(hwnd,IDC_FETCH),FALSE); } break; } @@ -226,6 +254,15 @@ static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP BOOL DoCameraUI(void) { + HKEY key; + DWORD data = 0; + DWORD size = sizeof(data); + if (RegOpenKeyExA(HKEY_CURRENT_USER, settings_key, 0, KEY_READ, &key) == ERROR_SUCCESS) { + RegQueryValueExA(key, settings_value, NULL, NULL, (LPBYTE) &data, &size); + RegCloseKey(key); + if (data) + return GetAllImages(); + } return DialogBoxW(GPHOTO2_instance, (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc); } diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index 38c249b7490..718e3871332 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -27,10 +27,13 @@ #include "wine/unicode.h" #include "wine/debug.h" #include "msvcrt/mbctype.h" +#include "msvcrt/mbstring.h" WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); unsigned char MSVCRT_mbctype[257]; +static int g_mbcp_is_multibyte = 0; + int MSVCRT___mb_cur_max = 1; extern int MSVCRT___lc_collate_cp; @@ -48,7 +51,7 @@ static struct cp_extra_info_t g_cpextrainfo[] = {936, {0x40, 0xfe, 0, 0}}, {949, {0x41, 0xfe, 0, 0}}, {950, {0x40, 0x7e, 0xa1, 0xfe, 0, 0}}, - {20932, {1, 255, 0, 0}}, + {20932, {1, 255, 0, 0}}, /* seems to give different results on different systems */ {0, {1, 255, 0, 0}} /* match all with FIXME */ }; @@ -207,6 +210,8 @@ int CDECL _setmbcp(int cp) { /* trail bytes not available through kernel32 but stored in a structure in msvcrt */ struct cp_extra_info_t *cpextra = g_cpextrainfo; + + g_mbcp_is_multibyte = 1; while (TRUE) { if (cpextra->cp == 0 || cpextra->cp == newcp) @@ -226,6 +231,8 @@ int CDECL _setmbcp(int cp) cpextra++; } } + else + g_mbcp_is_multibyte = 0; /* we can't use GetStringTypeA directly because we don't have a locale - only a code page */ @@ -329,10 +336,7 @@ unsigned char* CDECL _mbsdec(const unsigned char* start, const unsigned char* cu */ unsigned char* CDECL _mbsinc(const unsigned char* str) { - if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*str)) - return (unsigned char*)str + 2; /* MB char */ - - return (unsigned char*)str + 1; /* ASCII CP or SB char */ + return (unsigned char *)(str + _mbclen(str)); } /********************************************************************* @@ -340,15 +344,22 @@ unsigned char* CDECL _mbsinc(const unsigned char* str) */ unsigned char* CDECL _mbsninc(const unsigned char* str, MSVCRT_size_t num) { - if(!str || num < 1) + if(!str) return NULL; - if(MSVCRT___mb_cur_max > 1) + + while (num > 0 && *str) { - while(num--) - str = _mbsinc(str); - return (unsigned char*)str; + if (_ismbblead(*str)) + { + if (!*(str+1)) + break; + str++; + } + str++; + num--; } - return (unsigned char*)str + num; /* ASCII CP */ + + return (unsigned char*)str; } /********************************************************************* @@ -385,26 +396,39 @@ MSVCRT_size_t CDECL _mbslen(const unsigned char* str) void CDECL _mbccpy(unsigned char* dest, const unsigned char* src) { *dest = *src; - if(MSVCRT___mb_cur_max > 1 && MSVCRT_isleadbyte(*src)) + if(_ismbblead(*src)) *++dest = *++src; /* MB char */ } /********************************************************************* * _mbsncpy(MSVCRT.@) + * REMARKS + * The parameter n is the number or characters to copy, not the size of + * the buffer. Use _mbsnbcpy for a function analogical to strncpy */ unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n) { unsigned char* ret = dst; if(!n) return dst; - if(MSVCRT___mb_cur_max > 1) + if (g_mbcp_is_multibyte) { while (*src && n) { n--; - *dst++ = *src; - if (MSVCRT_isleadbyte(*src++)) - *dst++ = *src++; + if (_ismbblead(*src)) + { + if (!*(src+1)) + { + *dst++ = 0; + *dst++ = 0; + break; + } + + *dst++ = *src++; + } + + *dst++ = *src++; } } else @@ -421,32 +445,27 @@ unsigned char* CDECL _mbsncpy(unsigned char* dst, const unsigned char* src, MSVC /********************************************************************* * _mbsnbcpy(MSVCRT.@) + * REMARKS + * Like strncpy this function doesn't enforce the string to be + * NUL-terminated */ unsigned char* CDECL _mbsnbcpy(unsigned char* dst, const unsigned char* src, MSVCRT_size_t n) { unsigned char* ret = dst; if(!n) return dst; - if(MSVCRT___mb_cur_max > 1) + if(g_mbcp_is_multibyte) { - while (*src && (n > 1)) - { - n--; - *dst++ = *src; - if (MSVCRT_isleadbyte(*src++)) - { - *dst++ = *src++; - n--; - } - } - if (*src && n && !MSVCRT_isleadbyte(*src)) + int is_lead = 0; + while (*src && n) { - /* If the last character is a multi-byte character then - * we cannot copy it since we have only one byte left - */ - *dst++ = *src; + is_lead = (!is_lead && _ismbblead(*src)); n--; + *dst++ = *src++; } + + if (is_lead) /* if string ends with a lead, remove it */ + *(dst - 1) = 0; } else { @@ -1334,7 +1353,7 @@ MSVCRT_size_t CDECL _mbsspn(const unsigned char* string, const unsigned char* se /********************************************************************* * _mbsspnp (MSVCRT.@) */ -const unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* set) +unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned char* set) { const unsigned char *p, *q; @@ -1362,7 +1381,7 @@ const unsigned char* CDECL _mbsspnp(const unsigned char* string, const unsigned } if (*p == '\0') return NULL; - return p; + return (unsigned char *)p; } /********************************************************************* diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 4f8265292cf..004d059c6f8 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -23,9 +23,26 @@ #include #include #include +#include #include +#include + +static char *buf_to_string(const unsigned char *bin, int len, int nr) +{ + static char buf[2][1024]; + char *w = buf[nr]; + int i; + + for (i = 0; i < len; i++) + { + sprintf(w, "%02x ", (unsigned char)bin[i]); + w += strlen(w); + } + return buf[nr]; +} #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); } +#define expect_bin(buf, value, len) { ok(memcmp((buf), value, len) == 0, "Binary buffer mismatch - expected %s, got %s\n", buf_to_string((unsigned char *)value, len, 1), buf_to_string((buf), len, 0)); } static void* (*pmemcpy)(void *, const void *, size_t n); static int* (*pmemcmp)(void *, const void *, size_t n); @@ -33,6 +50,8 @@ static int* (*pmemcmp)(void *, const void *, size_t n); #define SETNOFAIL(x,y) x = (void*)GetProcAddress(hMsvcrt,y) #define SET(x,y) SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y) +HMODULE hMsvcrt; + static void test_swab( void ) { char original[] = "BADCFEHGJILKNMPORQTSVUXWZY@#"; char expected1[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ@#"; @@ -124,12 +143,9 @@ static int result_cp_949_mbctype[] = { 0x0,66, 0x18,26, 0x8,6, 0x28,26, 0x8,6, 0 0,1 }; static int result_cp_950_mbctype[] = { 0x0,65, 0x8,1, 0x18,26, 0x8,6, 0x28,26, 0x8,4, 0x0,2, 0x4,32, 0xc,94, 0,1 }; -static int result_cp_20932_mbctype[] = { 0x0,2, 0x8,64, 0x18,26, 0x8,6, 0x28,26, 0x8,19, - 0xc,1, 0x8,18, 0xc,94, 0,1 }; static int todo_none[] = { -2 }; static int todo_cp_932[] = { 254, -2 }; -static int todo_cp_20932[] = { 143, -2 }; void test_cp_table(int cp, int *result, int *todo) { @@ -167,7 +183,9 @@ static void test_mbcp(void) int curr_mbcp = _getmbcp(); unsigned char *mbstring = (unsigned char *)"\xb0\xb1\xb2 \xb3\xb4 \xb5"; /* incorrect string */ unsigned char *mbstring2 = (unsigned char *)"\xb0\xb1\xb2\xb3Q\xb4\xb5"; /* correct string */ - unsigned char *mbsonlylead = (unsigned char *)"\xb0"; + unsigned char *mbsonlylead = (unsigned char *)"\xb0\0\xb1\xb2"; + unsigned char buf[16]; + int step; /* some two single-byte code pages*/ test_codepage(1252); @@ -177,7 +195,6 @@ static void test_mbcp(void) test_codepage(936); test_codepage(949); test_codepage(950); - test_codepage_todo(20932, todo_cp_20932); _setmbcp(936); ok(__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", __mb_cur_max, mb_orig_max); @@ -201,6 +218,65 @@ static void test_mbcp(void) expect_eq(_mbslen(mbsonlylead), 0, int, "%d"); /* lead + NUL not counted as character */ expect_eq(_mbslen(mbstring), 4, int, "%d"); /* lead + invalid trail counted */ + /* _mbccpy/_mbsncpy */ + memset(buf, 0xff, sizeof(buf)); + _mbccpy(buf, mbstring); + expect_bin(buf, "\xb0\xb1\xff", 3); + + memset(buf, 0xff, sizeof(buf)); + _mbsncpy(buf, mbstring, 1); + expect_bin(buf, "\xb0\xb1\xff", 3); + memset(buf, 0xff, sizeof(buf)); + _mbsncpy(buf, mbstring, 2); + expect_bin(buf, "\xb0\xb1\xb2 \xff", 5); + memset(buf, 0xff, sizeof(buf)); + _mbsncpy(buf, mbstring, 3); + expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4\xff", 7); + memset(buf, 0xff, sizeof(buf)); + _mbsncpy(buf, mbstring, 4); + expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \xff", 8); + memset(buf, 0xff, sizeof(buf)); + _mbsncpy(buf, mbstring, 5); + expect_bin(buf, "\xb0\xb1\xb2 \xb3\xb4 \0\0\xff", 10); + memset(buf, 0xff, sizeof(buf)); + _mbsncpy(buf, mbsonlylead, 6); + expect_bin(buf, "\0\0\0\0\0\0\0\xff", 8); + + memset(buf, 0xff, sizeof(buf)); + _mbsnbcpy(buf, mbstring2, 2); + expect_bin(buf, "\xb0\xb1\xff", 3); + _mbsnbcpy(buf, mbstring2, 3); + expect_bin(buf, "\xb0\xb1\0\xff", 4); + _mbsnbcpy(buf, mbstring2, 4); + expect_bin(buf, "\xb0\xb1\xb2\xb3\xff", 5); + memset(buf, 0xff, sizeof(buf)); + _mbsnbcpy(buf, mbsonlylead, 5); + expect_bin(buf, "\0\0\0\0\0\xff", 6); + + /* _mbsinc/mbsdec */ + step = _mbsinc(mbstring) - mbstring; + ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step); + step = _mbsinc(&mbstring[2]) - &mbstring[2]; /* lead + invalid tail */ + ok(step == 2, "_mbsinc adds %d (exp. 2)\n", step); + + step = _mbsninc(mbsonlylead, 1) - mbsonlylead; + ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step); + step = _mbsninc(mbsonlylead, 2) - mbsonlylead; /* lead + NUL byte + lead + char */ + ok(step == 0, "_mbsninc adds %d (exp. 0)\n", step); + step = _mbsninc(mbstring2, 0) - mbstring2; + ok(step == 0, "_mbsninc adds %d (exp. 2)\n", step); + step = _mbsninc(mbstring2, 1) - mbstring2; + ok(step == 2, "_mbsninc adds %d (exp. 2)\n", step); + step = _mbsninc(mbstring2, 2) - mbstring2; + ok(step == 4, "_mbsninc adds %d (exp. 4)\n", step); + step = _mbsninc(mbstring2, 3) - mbstring2; + ok(step == 5, "_mbsninc adds %d (exp. 5)\n", step); + step = _mbsninc(mbstring2, 4) - mbstring2; + ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step); + step = _mbsninc(mbstring2, 5) - mbstring2; + ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step); + step = _mbsninc(mbstring2, 17) - mbstring2; + ok(step == 7, "_mbsninc adds %d (exp. 7)\n", step); /* functions that depend on locale codepage, not mbcp. * we hope the current locale to be SBCS because setlocale(LC_ALL, ".1252") seems not to work yet @@ -263,7 +339,6 @@ START_TEST(string) void *mem; static const char xilstring[]="c:/xilinx"; int nLen; - HMODULE hMsvcrt; hMsvcrt = GetModuleHandleA("msvcrt.dll"); if (!hMsvcrt) diff --git a/dlls/oleaut32/regsvr.c b/dlls/oleaut32/regsvr.c index b1dd7140134..a65c1091236 100644 --- a/dlls/oleaut32/regsvr.c +++ b/dlls/oleaut32/regsvr.c @@ -108,9 +108,6 @@ static LONG register_key_defvalueW(HKEY base, WCHAR const *name, WCHAR const *value); static LONG register_key_defvalueA(HKEY base, WCHAR const *name, char const *value); -static LONG recursive_delete_key(HKEY key); -static LONG recursive_delete_keyA(HKEY base, char const *name); -static LONG recursive_delete_keyW(HKEY base, WCHAR const *name); /*********************************************************************** * register_interfaces @@ -199,7 +196,8 @@ static HRESULT unregister_interfaces(struct regsvr_interface const *list) WCHAR buf[39]; StringFromGUID2(list->iid, buf, 39); - res = recursive_delete_keyW(interface_key, buf); + res = RegDeleteTreeW(interface_key, buf); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; } RegCloseKey(interface_key); @@ -309,11 +307,13 @@ static HRESULT unregister_coclasses(struct regsvr_coclass const *list) WCHAR buf[39]; StringFromGUID2(list->clsid, buf, 39); - res = recursive_delete_keyW(coclass_key, buf); + res = RegDeleteTreeW(coclass_key, buf); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; if (res != ERROR_SUCCESS) goto error_close_coclass_key; if (list->progid) { - res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->progid); + res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; if (res != ERROR_SUCCESS) goto error_close_coclass_key; } } @@ -376,70 +376,6 @@ static LONG register_key_defvalueA( } /*********************************************************************** - * recursive_delete_key - */ -static LONG recursive_delete_key(HKEY key) -{ - LONG res; - WCHAR subkey_name[MAX_PATH]; - DWORD cName; - HKEY subkey; - - for (;;) { - cName = sizeof(subkey_name) / sizeof(WCHAR); - res = RegEnumKeyExW(key, 0, subkey_name, &cName, - NULL, NULL, NULL, NULL); - if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) { - res = ERROR_SUCCESS; /* presumably we're done enumerating */ - break; - } - res = RegOpenKeyExW(key, subkey_name, 0, - KEY_READ | KEY_WRITE, &subkey); - if (res == ERROR_FILE_NOT_FOUND) continue; - if (res != ERROR_SUCCESS) break; - - res = recursive_delete_key(subkey); - RegCloseKey(subkey); - if (res != ERROR_SUCCESS) break; - } - - if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0); - return res; -} - -/*********************************************************************** - * recursive_delete_keyA - */ -static LONG recursive_delete_keyA(HKEY base, char const *name) -{ - LONG res; - HKEY key; - - res = RegOpenKeyExA(base, name, 0, KEY_READ | KEY_WRITE, &key); - if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS; - if (res != ERROR_SUCCESS) return res; - res = recursive_delete_key(key); - RegCloseKey(key); - return res; -} - -/*********************************************************************** - * recursive_delete_keyW - */ -static LONG recursive_delete_keyW(HKEY base, WCHAR const *name) -{ - LONG res; - HKEY key; - - res = RegOpenKeyExW(base, name, 0, KEY_READ | KEY_WRITE, &key); - if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS; - if (res != ERROR_SUCCESS) return res; - res = recursive_delete_key(key); - RegCloseKey(key); - return res; -} - -/*********************************************************************** * coclass list */ static GUID const CLSID_RecordInfo = { diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c index ccf5e3dd86f..268bece3c08 100644 --- a/dlls/opengl32/tests/opengl.c +++ b/dlls/opengl32/tests/opengl.c @@ -29,6 +29,10 @@ typedef void* HPBUFFERARB; static const char* (WINAPI *pwglGetExtensionsStringARB)(HDC); static int (WINAPI *pwglReleasePbufferDCARB)(HPBUFFERARB, HDC); +/* WGL_ARB_make_current_read */ +static BOOL (WINAPI *pwglMakeContextCurrentARB)(HDC hdraw, HDC hread, HGLRC hglrc); +static HDC (WINAPI *pwglGetCurrentReadDCARB)(); + /* WGL_ARB_pixel_format */ #define WGL_COLOR_BITS_ARB 0x2014 #define WGL_RED_BITS_ARB 0x2015 @@ -58,6 +62,10 @@ static void init_functions(void) /* WGL_ARB_extensions_string */ GET_PROC(wglGetExtensionsStringARB) + /* WGL_ARB_make_current_read */ + GET_PROC(wglMakeContextCurrentARB); + GET_PROC(wglGetCurrentReadDCARB); + /* WGL_ARB_pixel_format */ GET_PROC(wglChoosePixelFormatARB) GET_PROC(wglGetPixelFormatAttribivARB) @@ -257,6 +265,35 @@ static void test_gdi_dbuf(HDC hdc) } } +static void test_make_current_read(HDC hdc) +{ + int res; + HDC hread; + HGLRC hglrc = wglCreateContext(hdc); + + if(!hglrc) + { + skip("wglCreateContext failed!\n"); + return; + } + + res = wglMakeCurrent(hdc, hglrc); + if(!res) + { + skip("wglMakeCurrent failed!\n"); + return; + } + + /* Test what wglGetCurrentReadDCARB does for wglMakeCurrent as the spec doesn't mention it */ + hread = pwglGetCurrentReadDCARB(); + trace("hread %p, hdc %p\n", hread, hdc); + ok(hread == hdc, "wglGetCurrentReadDCARB failed for standard wglMakeCurrent\n"); + + pwglMakeContextCurrentARB(hdc, hdc, hglrc); + hread = pwglGetCurrentReadDCARB(); + ok(hread == hdc, "wglGetCurrentReadDCARB failed for wglMakeContextCurrent\n"); +} + START_TEST(opengl) { HWND hwnd; @@ -311,6 +348,11 @@ START_TEST(opengl) wgl_extensions = pwglGetExtensionsStringARB(hdc); if(wgl_extensions == NULL) skip("Skipping opengl32 tests because this OpenGL implementation doesn't support WGL extensions!\n"); + if(strstr(wgl_extensions, "WGL_ARB_make_current_read")) + test_make_current_read(hdc); + else + trace("WGL_ARB_make_current_read not supported, skipping test\n"); + if(strstr(wgl_extensions, "WGL_ARB_pbuffer")) test_pbuffers(hdc); else diff --git a/dlls/quartz/regsvr.c b/dlls/quartz/regsvr.c index 20bc5c4e731..8b93601afaa 100644 --- a/dlls/quartz/regsvr.c +++ b/dlls/quartz/regsvr.c @@ -172,9 +172,6 @@ static LONG register_key_defvalueA(HKEY base, WCHAR const *name, static LONG register_progid(WCHAR const *clsid, char const *progid, char const *curver_progid, char const *name, char const *extra); -static LONG recursive_delete_key(HKEY key); -static LONG recursive_delete_keyA(HKEY base, char const *name); -static LONG recursive_delete_keyW(HKEY base, WCHAR const *name); /*********************************************************************** * register_interfaces @@ -263,7 +260,8 @@ static HRESULT unregister_interfaces(struct regsvr_interface const *list) WCHAR buf[39]; StringFromGUID2(list->iid, buf, 39); - res = recursive_delete_keyW(interface_key, buf); + res = RegDeleteTreeW(interface_key, buf); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; } RegCloseKey(interface_key); @@ -370,16 +368,19 @@ static HRESULT unregister_coclasses(struct regsvr_coclass const *list) WCHAR buf[39]; StringFromGUID2(list->clsid, buf, 39); - res = recursive_delete_keyW(coclass_key, buf); + res = RegDeleteTreeW(coclass_key, buf); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; if (res != ERROR_SUCCESS) goto error_close_coclass_key; if (list->progid) { - res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->progid); + res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; if (res != ERROR_SUCCESS) goto error_close_coclass_key; } if (list->viprogid) { - res = recursive_delete_keyA(HKEY_CLASSES_ROOT, list->viprogid); + res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid); + if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; if (res != ERROR_SUCCESS) goto error_close_coclass_key; } } @@ -521,7 +522,7 @@ static HRESULT unregister_mediatypes_parsing(struct regsvr_mediatype_parsing con if (res != ERROR_SUCCESS) break; StringFromGUID2(list->subtype, buf, 39); - res = recursive_delete_keyW(majortype_key, buf); + res = RegDeleteTreeW(majortype_key, buf); if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; /* Removed majortype key if there is no more subtype key */ @@ -556,7 +557,7 @@ static HRESULT unregister_mediatypes_extension(struct regsvr_mediatype_extension res = ERROR_SUCCESS; else if (res == ERROR_SUCCESS) for (; res == ERROR_SUCCESS && list->majortype; ++list) { - res = recursive_delete_keyA(extensions_root_key, list->extension); + res = RegDeleteTreeA(extensions_root_key, list->extension); if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS; } @@ -775,71 +776,6 @@ error_close_progid_key: return res; } -/*********************************************************************** - * recursive_delete_key - */ -static LONG recursive_delete_key(HKEY key) -{ - LONG res; - WCHAR subkey_name[MAX_PATH]; - DWORD cName; - HKEY subkey; - - for (;;) { - cName = sizeof(subkey_name) / sizeof(WCHAR); - res = RegEnumKeyExW(key, 0, subkey_name, &cName, - NULL, NULL, NULL, NULL); - if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA) { - res = ERROR_SUCCESS; /* presumably we're done enumerating */ - break; - } - res = RegOpenKeyExW(key, subkey_name, 0, - KEY_READ | KEY_WRITE, &subkey); - if (res == ERROR_FILE_NOT_FOUND) continue; - if (res != ERROR_SUCCESS) break; - - res = recursive_delete_key(subkey); - RegCloseKey(subkey); - if (res != ERROR_SUCCESS) break; - } - - if (res == ERROR_SUCCESS) res = RegDeleteKeyW(key, 0); - return res; -} - -/*********************************************************************** - * recursive_delete_keyA - */ -static LONG recursive_delete_keyA(HKEY base, char const *name) -{ - LONG res; - HKEY key; - - res = RegOpenKeyExA(base, name, 0, KEY_READ | KEY_WRITE, &key); - if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS; - if (res != ERROR_SUCCESS) return res; - res = recursive_delete_key(key); - RegCloseKey(key); - return res; -} - -/*********************************************************************** - * recursive_delete_keyW - */ -static LONG recursive_delete_keyW(HKEY base, WCHAR const *name) -{ - LONG res; - HKEY key; - - res = RegOpenKeyExW(base, name, 0, KEY_READ | KEY_WRITE, &key); - if (res == ERROR_FILE_NOT_FOUND) return ERROR_SUCCESS; - if (res != ERROR_SUCCESS) return res; - res = recursive_delete_key(key); - RegCloseKey(key); - return res; -} - - static GUID const CLSID_PSFactoryBuffer = { 0x92a3a302, 0xda7c, 0x4a1f, {0xba,0x7e,0x18,0x02,0xbb,0x5d,0x2d,0x02} }; diff --git a/dlls/rsaenh/des.c b/dlls/rsaenh/des.c index 58528f0ca55..f94b6d8aa81 100644 --- a/dlls/rsaenh/des.c +++ b/dlls/rsaenh/des.c @@ -1450,7 +1450,7 @@ int des3_setup(const unsigned char *key, int keylen, int num_rounds, des3_key *d return CRYPT_OK; } -void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des_key *des) +void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des_key *des) { ulong32 work[2]; LOAD32H(work[0], pt+0); @@ -1460,7 +1460,7 @@ void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des_key *des) STORE32H(work[1],ct+4); } -void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des_key *des) +void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des_key *des) { ulong32 work[2]; LOAD32H(work[0], ct+0); @@ -1470,10 +1470,9 @@ void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des_key *des) STORE32H(work[1],pt+4); } -void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des3_key *des3) +void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des3_key *des3) { ulong32 work[2]; - LOAD32H(work[0], pt+0); LOAD32H(work[1], pt+4); desfunc(work, des3->ek[0]); @@ -1483,7 +1482,7 @@ void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des3_key *des3 STORE32H(work[1],ct+4); } -void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des3_key *des3) +void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des3_key *des3) { ulong32 work[2]; LOAD32H(work[0], ct+0); diff --git a/dlls/rsaenh/mpi.c b/dlls/rsaenh/mpi.c index a037c93b28c..a7408a4243c 100644 --- a/dlls/rsaenh/mpi.c +++ b/dlls/rsaenh/mpi.c @@ -46,7 +46,7 @@ static const int KARATSUBA_MUL_CUTOFF = 88, /* Min. number of digits before Kar * odd as per HAC Note 14.64 on pp. 610 */ int -fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c) +fast_mp_invmod (const mp_int * a, mp_int * b, mp_int * c) { mp_int x, y, u, v, B, D; int res, neg; @@ -176,7 +176,7 @@ __ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL); * Based on Algorithm 14.32 on pp.601 of HAC. */ int -fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) +fast_mp_montgomery_reduce (mp_int * x, const mp_int * n, mp_digit rho) { int ix, res, olduse; mp_word W[MP_WARRAY]; @@ -336,7 +336,7 @@ fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) * */ int -fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) +fast_s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs) { int olduse, res, pa, ix, iz; mp_digit W[MP_WARRAY]; @@ -415,7 +415,7 @@ fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) * Based on Algorithm 14.12 on pp.595 of HAC. */ int -fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) +fast_s_mp_mul_high_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs) { int olduse, res, pa, ix, iz; mp_digit W[MP_WARRAY]; @@ -512,7 +512,7 @@ Remove W2 and don't memset W */ -int fast_s_mp_sqr (mp_int * a, mp_int * b) +int fast_s_mp_sqr (const mp_int * a, mp_int * b) { int olduse, res, pa, ix, iz; mp_digit W[MP_WARRAY], *tmpx; @@ -627,7 +627,7 @@ mp_2expt (mp_int * a, int b) * Simple function copies the input and fixes the sign to positive */ int -mp_abs (mp_int * a, mp_int * b) +mp_abs (const mp_int * a, mp_int * b) { int res; @@ -824,7 +824,7 @@ void mp_clear_multi(mp_int *mp, ...) /* compare two ints (signed)*/ int -mp_cmp (mp_int * a, mp_int * b) +mp_cmp (const mp_int * a, const mp_int * b) { /* compare based on sign */ if (a->sign != b->sign) { @@ -845,7 +845,7 @@ mp_cmp (mp_int * a, mp_int * b) } /* compare a digit */ -int mp_cmp_d(mp_int * a, mp_digit b) +int mp_cmp_d(const mp_int * a, mp_digit b) { /* compare based on sign */ if (a->sign == MP_NEG) { @@ -868,7 +868,7 @@ int mp_cmp_d(mp_int * a, mp_digit b) } /* compare maginitude of two ints (unsigned) */ -int mp_cmp_mag (mp_int * a, mp_int * b) +int mp_cmp_mag (const mp_int * a, const mp_int * b) { int n; mp_digit *tmpa, *tmpb; @@ -906,7 +906,7 @@ static const int lnz[16] = { }; /* Counts the number of lsbs which are zero before the first zero bit */ -int mp_cnt_lsb(mp_int *a) +int mp_cnt_lsb(const mp_int *a) { int x; mp_digit q, qq; @@ -981,7 +981,7 @@ mp_copy (const mp_int * a, mp_int * b) /* returns the number of bits in an int */ int -mp_count_bits (mp_int * a) +mp_count_bits (const mp_int * a) { int r; mp_digit q; @@ -1016,7 +1016,7 @@ mp_count_bits (mp_int * a) * The overall algorithm is as described as * 14.20 from HAC but fixed to treat these cases. */ -int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d) +int mp_div (const mp_int * a, const mp_int * b, mp_int * c, mp_int * d) { mp_int q, x, y, t1, t2; int res, n, t, i, norm, neg; @@ -1200,7 +1200,7 @@ __Q:mp_clear (&q); } /* b = a/2 */ -int mp_div_2(mp_int * a, mp_int * b) +int mp_div_2(const mp_int * a, mp_int * b) { int x, res, oldused; @@ -1247,7 +1247,7 @@ int mp_div_2(mp_int * a, mp_int * b) } /* shift right by a certain bit count (store quotient in c, optional remainder in d) */ -int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d) +int mp_div_2d (const mp_int * a, int b, mp_int * c, mp_int * d) { mp_digit D, r, rr; int x, res; @@ -1336,7 +1336,7 @@ static int s_is_power_of_two(mp_digit b, int *p) } /* single digit division (based on routine from MPI) */ -int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) +int mp_div_d (const mp_int * a, mp_digit b, mp_int * c, mp_digit * d) { mp_int q; mp_word w; @@ -1418,7 +1418,7 @@ int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d) * Input x must be in the range 0 <= x <= (n-1)**2 */ int -mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k) +mp_dr_reduce (mp_int * x, const mp_int * n, mp_digit k) { int err, i, m; mp_word r; @@ -1477,7 +1477,7 @@ top: } /* determines the setup value */ -void mp_dr_setup(mp_int *a, mp_digit *d) +void mp_dr_setup(const mp_int *a, mp_digit *d) { /* the casts are required if DIGIT_BIT is one less than * the number of bits in a mp_digit [e.g. DIGIT_BIT==31] @@ -1504,7 +1504,7 @@ mp_exch (mp_int * a, mp_int * b) * embedded in the normal function but that wasted a lot of stack space * for nothing (since 99% of the time the Montgomery code would be called) */ -int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) +int mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y) { int dr; @@ -1563,7 +1563,7 @@ int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) */ int -mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode) +mp_exptmod_fast (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y, int redmode) { mp_int M[256], res; mp_digit buf, mp; @@ -1573,7 +1573,7 @@ mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode) * one of many reduction algorithms without modding the guts of * the code with if statements everywhere. */ - int (*redux)(mp_int*,mp_int*,mp_digit); + int (*redux)(mp_int*,const mp_int*,mp_digit); /* find window size */ x = mp_count_bits (X); @@ -1815,7 +1815,7 @@ __M: } /* Greatest Common Divisor using the binary method */ -int mp_gcd (mp_int * a, mp_int * b, mp_int * c) +int mp_gcd (const mp_int * a, const mp_int * b, mp_int * c) { mp_int u, v; int k, u_lsb, v_lsb, res; @@ -1907,7 +1907,7 @@ __U:mp_clear (&v); } /* get the lower 32-bits of an mp_int */ -unsigned long mp_get_int(mp_int * a) +unsigned long mp_get_int(const mp_int * a) { int i; unsigned long res; @@ -2066,7 +2066,7 @@ int mp_init_size (mp_int * a, int size) } /* hac 14.61, pp608 */ -int mp_invmod (mp_int * a, mp_int * b, mp_int * c) +int mp_invmod (const mp_int * a, mp_int * b, mp_int * c) { /* b cannot be negative */ if (b->sign == MP_NEG || mp_iszero(b) == 1) { @@ -2082,7 +2082,7 @@ int mp_invmod (mp_int * a, mp_int * b, mp_int * c) } /* hac 14.61, pp608 */ -int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c) +int mp_invmod_slow (const mp_int * a, mp_int * b, mp_int * c) { mp_int x, y, u, v, A, B, C, D; int res; @@ -2264,7 +2264,7 @@ __ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL); * Generally though the overhead of this method doesn't pay off * until a certain size (N ~ 80) is reached. */ -int mp_karatsuba_mul (mp_int * a, mp_int * b, mp_int * c) +int mp_karatsuba_mul (const mp_int * a, const mp_int * b, mp_int * c) { mp_int x0, x1, y0, y1, t1, x0y0, x1y1; int B, err; @@ -2388,7 +2388,7 @@ ERR: * is essentially the same algorithm but merely * tuned to perform recursive squarings. */ -int mp_karatsuba_sqr (mp_int * a, mp_int * b) +int mp_karatsuba_sqr (const mp_int * a, mp_int * b) { mp_int x0, x1, t1, t2, x0x0, x1x1; int B, err; @@ -2482,7 +2482,7 @@ ERR: } /* computes least common multiple as |a*b|/(a, b) */ -int mp_lcm (mp_int * a, mp_int * b, mp_int * c) +int mp_lcm (const mp_int * a, const mp_int * b, mp_int * c) { int res; mp_int t1, t2; @@ -2568,7 +2568,7 @@ int mp_lshd (mp_int * a, int b) /* c = a mod b, 0 <= c < b */ int -mp_mod (mp_int * a, mp_int * b, mp_int * c) +mp_mod (const mp_int * a, mp_int * b, mp_int * c) { mp_int t; int res; @@ -2595,7 +2595,7 @@ mp_mod (mp_int * a, mp_int * b, mp_int * c) /* calc a value mod 2**b */ int -mp_mod_2d (mp_int * a, int b, mp_int * c) +mp_mod_2d (const mp_int * a, int b, mp_int * c) { int x, res; @@ -2628,7 +2628,7 @@ mp_mod_2d (mp_int * a, int b, mp_int * c) } int -mp_mod_d (mp_int * a, mp_digit b, mp_digit * c) +mp_mod_d (const mp_int * a, mp_digit b, mp_digit * c) { return mp_div_d(a, b, NULL, c); } @@ -2639,7 +2639,7 @@ mp_mod_d (mp_int * a, mp_digit b, mp_digit * c) * The method is slightly modified to shift B unconditionally up to just under * the leading bit of b. This saves a lot of multiple precision shifting. */ -int mp_montgomery_calc_normalization (mp_int * a, mp_int * b) +int mp_montgomery_calc_normalization (mp_int * a, const mp_int * b) { int x, bits, res; @@ -2674,7 +2674,7 @@ int mp_montgomery_calc_normalization (mp_int * a, mp_int * b) /* computes xR**-1 == x (mod N) via Montgomery Reduction */ int -mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) +mp_montgomery_reduce (mp_int * x, const mp_int * n, mp_digit rho) { int ix, res, digs; mp_digit mu; @@ -2771,7 +2771,7 @@ mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) /* setups the montgomery reduction stuff */ int -mp_montgomery_setup (mp_int * n, mp_digit * rho) +mp_montgomery_setup (const mp_int * n, mp_digit * rho) { mp_digit x, b; @@ -2801,7 +2801,7 @@ mp_montgomery_setup (mp_int * n, mp_digit * rho) } /* high level multiplication (handles sign) */ -int mp_mul (mp_int * a, mp_int * b, mp_int * c) +int mp_mul (const mp_int * a, const mp_int * b, mp_int * c) { int res, neg; neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; @@ -2831,7 +2831,7 @@ int mp_mul (mp_int * a, mp_int * b, mp_int * c) } /* b = a*2 */ -int mp_mul_2(mp_int * a, mp_int * b) +int mp_mul_2(const mp_int * a, mp_int * b) { int x, res, oldused; @@ -2892,7 +2892,7 @@ int mp_mul_2(mp_int * a, mp_int * b) } /* shift left by a certain bit count */ -int mp_mul_2d (mp_int * a, int b, mp_int * c) +int mp_mul_2d (const mp_int * a, int b, mp_int * c) { mp_digit d; int res; @@ -2957,7 +2957,7 @@ int mp_mul_2d (mp_int * a, int b, mp_int * c) /* multiply by a digit */ int -mp_mul_d (mp_int * a, mp_digit b, mp_int * c) +mp_mul_d (const mp_int * a, mp_digit b, mp_int * c) { mp_digit u, *tmpa, *tmpc; mp_word r; @@ -3014,7 +3014,7 @@ mp_mul_d (mp_int * a, mp_digit b, mp_int * c) /* d = a * b (mod c) */ int -mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) +mp_mulmod (const mp_int * a, const mp_int * b, mp_int * c, mp_int * d) { int res; mp_int t; @@ -3037,7 +3037,7 @@ mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) * * sets result to 0 if not, 1 if yes */ -int mp_prime_is_divisible (mp_int * a, int *result) +int mp_prime_is_divisible (const mp_int * a, int *result) { int err, ix; mp_digit res; @@ -3130,7 +3130,7 @@ __B:mp_clear (&b); * Randomly the chance of error is no more than 1/4 and often * very much lower. */ -int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result) +int mp_prime_miller_rabin (mp_int * a, const mp_int * b, int *result) { mp_int n1, y, r; int s, j, err; @@ -3371,7 +3371,7 @@ mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c) * From HAC pp.604 Algorithm 14.42 */ int -mp_reduce (mp_int * x, mp_int * m, mp_int * mu) +mp_reduce (mp_int * x, const mp_int * m, const mp_int * mu) { mp_int q; int res, um = m->used; @@ -3437,7 +3437,7 @@ CLEANUP: /* reduces a modulo n where n is of the form 2**p - d */ int -mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d) +mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d) { mp_int q; int p, res; @@ -3477,7 +3477,7 @@ ERR: /* determines the setup value */ int -mp_reduce_2k_setup(mp_int *a, mp_digit *d) +mp_reduce_2k_setup(const mp_int *a, mp_digit *d) { int res, p; mp_int tmp; @@ -3505,10 +3505,10 @@ mp_reduce_2k_setup(mp_int *a, mp_digit *d) /* pre-calculate the value required for Barrett reduction * For a given modulus "b" it calulates the value required in "a" */ -int mp_reduce_setup (mp_int * a, mp_int * b) +int mp_reduce_setup (mp_int * a, const mp_int * b) { int res; - + if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) { return res; } @@ -3616,14 +3616,14 @@ int mp_shrink (mp_int * a) } /* get the size for an signed equivalent */ -int mp_signed_bin_size (mp_int * a) +int mp_signed_bin_size (const mp_int * a) { return 1 + mp_unsigned_bin_size (a); } /* computes b = a*a */ int -mp_sqr (mp_int * a, mp_int * b) +mp_sqr (const mp_int * a, mp_int * b) { int res; @@ -3645,7 +3645,7 @@ if (a->used >= KARATSUBA_SQR_CUTOFF) { /* c = a * a (mod b) */ int -mp_sqrmod (mp_int * a, mp_int * b, mp_int * c) +mp_sqrmod (const mp_int * a, mp_int * b, mp_int * c) { int res; mp_int t; @@ -3769,7 +3769,7 @@ mp_sub_d (mp_int * a, mp_digit b, mp_int * c) /* store in unsigned [big endian] format */ int -mp_to_unsigned_bin (mp_int * a, unsigned char *b) +mp_to_unsigned_bin (const mp_int * a, unsigned char *b) { int x, res; mp_int t; @@ -3793,7 +3793,7 @@ mp_to_unsigned_bin (mp_int * a, unsigned char *b) /* get the size for an unsigned equivalent */ int -mp_unsigned_bin_size (mp_int * a) +mp_unsigned_bin_size (const mp_int * a) { int size = mp_count_bits (a); return (size / 8 + ((size & 7) != 0 ? 1 : 0)); @@ -3952,7 +3952,7 @@ s_mp_add (mp_int * a, mp_int * b, mp_int * c) return MP_OKAY; } -int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y) +int s_mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y) { mp_int M[256], res, mu; mp_digit buf; @@ -4164,7 +4164,7 @@ __M: * many digits of output are created. */ int -s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) +s_mp_mul_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs) { mp_int t; int res, pa, pb, ix, iy; @@ -4233,7 +4233,7 @@ s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) * [meant to get the higher part of the product] */ int -s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) +s_mp_mul_high_digs (const mp_int * a, const mp_int * b, mp_int * c, int digs) { mp_int t; int res, pa, pb, ix, iy; @@ -4289,7 +4289,7 @@ s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) /* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */ int -s_mp_sqr (mp_int * a, mp_int * b) +s_mp_sqr (const mp_int * a, mp_int * b) { mp_int t; int res, ix, iy, pa; @@ -4353,7 +4353,7 @@ s_mp_sqr (mp_int * a, mp_int * b) /* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */ int -s_mp_sub (mp_int * a, mp_int * b, mp_int * c) +s_mp_sub (const mp_int * a, const mp_int * b, mp_int * c) { int olduse, res, min, max; diff --git a/dlls/rsaenh/tomcrypt.h b/dlls/rsaenh/tomcrypt.h index bd0c1c10662..b9e29d9d5a0 100644 --- a/dlls/rsaenh/tomcrypt.h +++ b/dlls/rsaenh/tomcrypt.h @@ -134,12 +134,12 @@ void rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, rc2_key *key); void rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, rc2_key *key); int des_setup(const unsigned char *key, int keylen, int num_rounds, des_key *skey); -void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des_key *key); -void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des_key *key); +void des_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des_key *key); +void des_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des_key *key); int des3_setup(const unsigned char *key, int keylen, int num_rounds, des3_key *skey); -void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, des3_key *key); -void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, des3_key *key); +void des3_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const des3_key *key); +void des3_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const des3_key *key); typedef struct tag_md2_state { unsigned char chksum[16], X[48], buf[16]; @@ -266,7 +266,7 @@ void mp_set(mp_int *a, mp_digit b); int mp_set_int(mp_int *a, unsigned long b); /* get a 32-bit value */ -unsigned long mp_get_int(mp_int * a); +unsigned long mp_get_int(const mp_int * a); /* initialize and set a digit */ int mp_init_set (mp_int * a, mp_digit b); @@ -292,25 +292,25 @@ void mp_rshd(mp_int *a, int b); int mp_lshd(mp_int *a, int b); /* c = a / 2**b */ -int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d); +int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d); /* b = a/2 */ -int mp_div_2(mp_int *a, mp_int *b); +int mp_div_2(const mp_int *a, mp_int *b); /* c = a * 2**b */ -int mp_mul_2d(mp_int *a, int b, mp_int *c); +int mp_mul_2d(const mp_int *a, int b, mp_int *c); /* b = a*2 */ -int mp_mul_2(mp_int *a, mp_int *b); +int mp_mul_2(const mp_int *a, mp_int *b); /* c = a mod 2**d */ -int mp_mod_2d(mp_int *a, int b, mp_int *c); +int mp_mod_2d(const mp_int *a, int b, mp_int *c); /* computes a = 2**b */ int mp_2expt(mp_int *a, int b); /* Counts the number of lsbs which are zero before the first zero bit */ -int mp_cnt_lsb(mp_int *a); +int mp_cnt_lsb(const mp_int *a); /* I Love Earth! */ @@ -333,13 +333,13 @@ int mp_and(mp_int *a, mp_int *b, mp_int *c); int mp_neg(mp_int *a, mp_int *b); /* b = |a| */ -int mp_abs(mp_int *a, mp_int *b); +int mp_abs(const mp_int *a, mp_int *b); /* compare a to b */ -int mp_cmp(mp_int *a, mp_int *b); +int mp_cmp(const mp_int *a, const mp_int *b); /* compare |a| to |b| */ -int mp_cmp_mag(mp_int *a, mp_int *b); +int mp_cmp_mag(const mp_int *a, const mp_int *b); /* c = a + b */ int mp_add(mp_int *a, mp_int *b, mp_int *c); @@ -348,21 +348,21 @@ int mp_add(mp_int *a, mp_int *b, mp_int *c); int mp_sub(mp_int *a, mp_int *b, mp_int *c); /* c = a * b */ -int mp_mul(mp_int *a, mp_int *b, mp_int *c); +int mp_mul(const mp_int *a, const mp_int *b, mp_int *c); /* b = a*a */ -int mp_sqr(mp_int *a, mp_int *b); +int mp_sqr(const mp_int *a, mp_int *b); /* a/b => cb + d == a */ -int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d); +int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d); /* c = a mod b, 0 <= c < b */ -int mp_mod(mp_int *a, mp_int *b, mp_int *c); +int mp_mod(const mp_int *a, mp_int *b, mp_int *c); /* ---> single digit functions <--- */ /* compare against a single digit */ -int mp_cmp_d(mp_int *a, mp_digit b); +int mp_cmp_d(const mp_int *a, mp_digit b); /* c = a + b */ int mp_add_d(mp_int *a, mp_digit b, mp_int *c); @@ -371,10 +371,10 @@ int mp_add_d(mp_int *a, mp_digit b, mp_int *c); int mp_sub_d(mp_int *a, mp_digit b, mp_int *c); /* c = a * b */ -int mp_mul_d(mp_int *a, mp_digit b, mp_int *c); +int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c); /* a/b => cb + d == a */ -int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d); +int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d); /* a/3 => 3c + d == a */ int mp_div_3(mp_int *a, mp_int *c, mp_digit *d); @@ -383,7 +383,7 @@ int mp_div_3(mp_int *a, mp_int *c, mp_digit *d); int mp_expt_d(mp_int *a, mp_digit b, mp_int *c); /* c = a mod b, 0 <= c < b */ -int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c); +int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c); /* ---> number theory <--- */ @@ -394,22 +394,22 @@ int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d); int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d); /* d = a * b (mod c) */ -int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d); +int mp_mulmod(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d); /* c = a * a (mod b) */ -int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c); +int mp_sqrmod(const mp_int *a, mp_int *b, mp_int *c); /* c = 1/a (mod b) */ -int mp_invmod(mp_int *a, mp_int *b, mp_int *c); +int mp_invmod(const mp_int *a, mp_int *b, mp_int *c); /* c = (a, b) */ -int mp_gcd(mp_int *a, mp_int *b, mp_int *c); +int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c); /* produces value such that U1*a + U2*b = U3 */ int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3); /* c = [a, b] or (a*b)/(a, b) */ -int mp_lcm(mp_int *a, mp_int *b, mp_int *c); +int mp_lcm(const mp_int *a, const mp_int *b, mp_int *c); /* finds one of the b'th root of a, such that |c|**b <= |a| * @@ -427,46 +427,46 @@ int mp_is_square(mp_int *arg, int *ret); int mp_jacobi(mp_int *a, mp_int *n, int *c); /* used to setup the Barrett reduction for a given modulus b */ -int mp_reduce_setup(mp_int *a, mp_int *b); +int mp_reduce_setup(mp_int *a, const mp_int *b); /* Barrett Reduction, computes a (mod b) with a precomputed value c * * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code]. */ -int mp_reduce(mp_int *a, mp_int *b, mp_int *c); +int mp_reduce(mp_int *a, const mp_int *b, const mp_int *c); /* setups the montgomery reduction */ -int mp_montgomery_setup(mp_int *a, mp_digit *mp); +int mp_montgomery_setup(const mp_int *a, mp_digit *mp); /* computes a = B**n mod b without division or multiplication useful for * normalizing numbers in a Montgomery system. */ -int mp_montgomery_calc_normalization(mp_int *a, mp_int *b); +int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b); /* computes x/R == x (mod N) via Montgomery Reduction */ -int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp); +int mp_montgomery_reduce(mp_int *a, const mp_int *m, mp_digit mp); /* returns 1 if a is a valid DR modulus */ int mp_dr_is_modulus(mp_int *a); /* sets the value of "d" required for mp_dr_reduce */ -void mp_dr_setup(mp_int *a, mp_digit *d); +void mp_dr_setup(const mp_int *a, mp_digit *d); /* reduces a modulo b using the Diminished Radix method */ -int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp); +int mp_dr_reduce(mp_int *a, const mp_int *b, mp_digit mp); /* returns true if a can be reduced with mp_reduce_2k */ int mp_reduce_is_2k(mp_int *a); /* determines k value for 2k reduction */ -int mp_reduce_2k_setup(mp_int *a, mp_digit *d); +int mp_reduce_2k_setup(const mp_int *a, mp_digit *d); /* reduces a modulo b where b is of the form 2**p - k [0 <= a] */ -int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d); +int mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d); /* d = a**b (mod c) */ -int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d); +int mp_exptmod(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d); /* ---> Primes <--- */ @@ -477,7 +477,7 @@ int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d); extern const mp_digit __prime_tab[]; /* result=1 if a is divisible by one of the first PRIME_SIZE primes */ -int mp_prime_is_divisible(mp_int *a, int *result); +int mp_prime_is_divisible(const mp_int *a, int *result); /* performs one Fermat test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime @@ -487,7 +487,7 @@ int mp_prime_fermat(mp_int *a, mp_int *b, int *result); /* performs one Miller-Rabin test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime */ -int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result); +int mp_prime_miller_rabin(mp_int *a, const mp_int *b, int *result); /* This gives [for a given bit size] the number of trials required * such that Miller-Rabin gives a prob of failure lower than 2^-96 @@ -538,13 +538,13 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style); int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat); /* ---> radix conversion <--- */ -int mp_count_bits(mp_int *a); +int mp_count_bits(const mp_int *a); -int mp_unsigned_bin_size(mp_int *a); +int mp_unsigned_bin_size(const mp_int *a); int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c); -int mp_to_unsigned_bin(mp_int *a, unsigned char *b); +int mp_to_unsigned_bin(const mp_int *a, unsigned char *b); -int mp_signed_bin_size(mp_int *a); +int mp_signed_bin_size(const mp_int *a); int mp_read_signed_bin(mp_int *a, unsigned char *b, int c); int mp_to_signed_bin(mp_int *a, unsigned char *b); @@ -570,23 +570,23 @@ int mp_fwrite(mp_int *a, int radix, FILE *stream); /* lowlevel functions, do not call! */ int s_mp_add(mp_int *a, mp_int *b, mp_int *c); -int s_mp_sub(mp_int *a, mp_int *b, mp_int *c); +int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) -int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs); -int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs); -int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs); -int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs); -int fast_s_mp_sqr(mp_int *a, mp_int *b); -int s_mp_sqr(mp_int *a, mp_int *b); -int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c); +int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); +int fast_s_mp_sqr(const mp_int *a, mp_int *b); +int s_mp_sqr(const mp_int *a, mp_int *b); +int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c); -int mp_karatsuba_sqr(mp_int *a, mp_int *b); +int mp_karatsuba_sqr(const mp_int *a, mp_int *b); int mp_toom_sqr(mp_int *a, mp_int *b); -int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c); -int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c); -int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp); -int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode); -int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y); +int fast_mp_invmod(const mp_int *a, mp_int *b, mp_int *c); +int mp_invmod_slow (const mp_int * a, mp_int * b, mp_int * c); +int fast_mp_montgomery_reduce(mp_int *a, const mp_int *m, mp_digit mp); +int mp_exptmod_fast(const mp_int *G, const mp_int *X, mp_int *P, mp_int *Y, int mode); +int s_mp_exptmod (const mp_int * G, const mp_int * X, mp_int * P, mp_int * Y); void bn_reverse(unsigned char *s, int len); extern const char *mp_s_rmap; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index e7583371d82..0a5091d5b29 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -1140,18 +1140,20 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateQuery(IWineD3DDevice *iface, WINE TRACE("(%p) Allocating data for an occlusion query\n", This); object->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineQueryOcclusionData)); GL_EXTCALL(glGenQueriesARB(1, &((WineQueryOcclusionData *)(object->extendedData))->queryId)); + ((WineQueryOcclusionData *)(object->extendedData))->ctx = This->activeContext; break; } case WINED3DQUERYTYPE_EVENT: - /* TODO: GL_APPLE_fence */ if(GL_SUPPORT(APPLE_FENCE)) { object->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineQueryEventData)); GL_EXTCALL(glGenFencesAPPLE(1, &((WineQueryEventData *)(object->extendedData))->fenceId)); checkGLcall("glGenFencesAPPLE"); + ((WineQueryEventData *)(object->extendedData))->ctx = This->activeContext; } else if(GL_SUPPORT(NV_FENCE)) { object->extendedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WineQueryEventData)); GL_EXTCALL(glGenFencesNV(1, &((WineQueryEventData *)(object->extendedData))->fenceId)); checkGLcall("glGenFencesNV"); + ((WineQueryEventData *)(object->extendedData))->ctx = This->activeContext; } break; diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c index 0d4f1e27146..3a47912aa08 100644 --- a/dlls/wined3d/drawprim.c +++ b/dlls/wined3d/drawprim.c @@ -1050,13 +1050,22 @@ void drawPrimitive(IWineD3DDevice *iface, if (numberOfVertices == 0 ) numberOfVertices = calculatedNumberOfindices; - if(!This->strided_streams.u.s.position_transformed && !use_vs(This)) { - if(This->activeContext->num_untracked_materials && - This->stateBlock->renderState[WINED3DRS_LIGHTING]) { - IWineD3DVertexBufferImpl *vb; - + if(!use_vs(This)) { + if(!This->strided_streams.u.s.position_transformed && This->activeContext->num_untracked_materials && + This->stateBlock->renderState[WINED3DRS_LIGHTING]) { FIXME("Using software emulation because not all material properties could be tracked\n"); emulation = TRUE; + } + else if(This->activeContext->fog_coord && This->stateBlock->renderState[WINED3DRS_FOGENABLE]) { + /* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte + * to a float in the vertex buffer + */ + FIXME("Using software emulation because manual fog coordinates are provided\n"); + emulation = TRUE; + } + + if(emulation) { + IWineD3DVertexBufferImpl *vb; strided = &stridedlcl; memcpy(&stridedlcl, &This->strided_streams, sizeof(stridedlcl)); diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c index 99390f867ea..7c91f2ee663 100644 --- a/dlls/wined3d/query.c +++ b/dlls/wined3d/query.c @@ -167,7 +167,12 @@ static HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pDa case WINED3DQUERYTYPE_EVENT: { BOOL* data = pData; - if(GL_SUPPORT(APPLE_FENCE)) { + WineD3DContext *ctx = ((WineQueryEventData *)This->extendedData)->ctx; + if(ctx != This->wineD3DDevice->activeContext || ctx->tid != GetCurrentThreadId()) { + /* See comment in IWineD3DQuery::Issue, event query codeblock */ + WARN("Query context not active, reporting GPU idle\n"); + *data = TRUE; + } else if(GL_SUPPORT(APPLE_FENCE)) { *data = GL_EXTCALL(glTestFenceAPPLE(((WineQueryEventData *)This->extendedData)->fenceId)); checkGLcall("glTestFenceAPPLE"); } else if(GL_SUPPORT(NV_FENCE)) { @@ -182,7 +187,9 @@ static HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pDa case WINED3DQUERYTYPE_OCCLUSION: { DWORD* data = pData; - if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) { + if (GL_SUPPORT(ARB_OCCLUSION_QUERY) && + ((WineQueryOcclusionData *)This->extendedData)->ctx == This->wineD3DDevice->activeContext && + This->wineD3DDevice->activeContext->tid == GetCurrentThreadId()) { GLuint available; GLuint samples; GLuint queryId = ((WineQueryOcclusionData *)This->extendedData)->queryId; @@ -201,7 +208,7 @@ static HRESULT WINAPI IWineD3DQueryImpl_GetData(IWineD3DQuery* iface, void* pDa res = S_FALSE; } } else { - FIXME("(%p) : Occlusion queries not supported. Returning 1.\n", This); + WARN("(%p) : Occlusion queries not supported, or wrong context. Returning 1.\n", This); *data = 1; res = S_OK; } @@ -375,13 +382,19 @@ static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIs switch (This->type) { case WINED3DQUERYTYPE_OCCLUSION: if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) { - if (dwIssueFlags & WINED3DISSUE_BEGIN) { - GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, ((WineQueryOcclusionData *)This->extendedData)->queryId)); - checkGLcall("glBeginQuery()"); - } - if (dwIssueFlags & WINED3DISSUE_END) { - GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); - checkGLcall("glEndQuery()"); + WineD3DContext *ctx = ((WineQueryOcclusionData *)This->extendedData)->ctx; + + if(ctx != This->wineD3DDevice->activeContext || ctx->tid != GetCurrentThreadId()) { + WARN("Not the owning context, can't start query\n"); + } else { + if (dwIssueFlags & WINED3DISSUE_BEGIN) { + GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, ((WineQueryOcclusionData *)This->extendedData)->queryId)); + checkGLcall("glBeginQuery()"); + } + if (dwIssueFlags & WINED3DISSUE_END) { + GL_EXTCALL(glEndQueryARB(GL_SAMPLES_PASSED_ARB)); + checkGLcall("glEndQuery()"); + } } } else { FIXME("(%p) : Occlusion queries not supported\n", This); @@ -390,7 +403,17 @@ static HRESULT WINAPI IWineD3DQueryImpl_Issue(IWineD3DQuery* iface, DWORD dwIs case WINED3DQUERYTYPE_EVENT: { if (dwIssueFlags & WINED3DISSUE_END) { - if(GL_SUPPORT(APPLE_FENCE)) { + WineD3DContext *ctx = ((WineQueryEventData *)This->extendedData)->ctx; + if(ctx != This->wineD3DDevice->activeContext || ctx->tid != GetCurrentThreadId()) { + /* GL fences can be used only from the context that created them, + * so if a different context is active, don't bother setting the query. The penalty + * of a context switch is most likely higher than the gain of a correct query result + * + * If the query is used from a different thread, don't bother creating a multithread + * context - there's no point in doing that as the query would be unusable anyway + */ + WARN("Query context not active\n"); + } else if(GL_SUPPORT(APPLE_FENCE)) { GL_EXTCALL(glSetFenceAPPLE(((WineQueryEventData *)This->extendedData)->fenceId)); checkGLcall("glSetFenceAPPLE"); } else if (GL_SUPPORT(NV_FENCE)) { diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index fb060c5104a..20a7fa56e3f 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -803,9 +803,10 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo fogend = 0.0; } - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } context->last_was_foggy_shader = TRUE; } @@ -843,9 +844,10 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %d\n", stateblock->renderState[WINED3DRS_FOGVERTEXMODE]); } - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } } /* DX 7 sdk: "If both render states(vertex and table fog) are set to valid modes, @@ -862,9 +864,10 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo if(!context->last_was_rhw) { glFogi(GL_FOG_MODE, GL_EXP); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP"); - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } break; } @@ -873,9 +876,10 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo if(!context->last_was_rhw) { glFogi(GL_FOG_MODE, GL_EXP2); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2"); - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } break; } @@ -884,9 +888,10 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo if(!context->last_was_rhw) { glFogi(GL_FOG_MODE, GL_LINEAR); checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR"); - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } break; } @@ -897,8 +902,11 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo * Same happens with Vertexfog on transformed vertices */ if(GL_SUPPORT(EXT_FOG_COORD)) { - glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); - checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)\n"); + if(context->fog_coord == FALSE) { + glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); + checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT)\n"); + context->fog_coord = TRUE; + } glFogi(GL_FOG_MODE, GL_LINEAR); checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR)"); fogstart = 0xff; @@ -920,27 +928,30 @@ static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DCo case WINED3DFOG_EXP: glFogi(GL_FOG_MODE, GL_EXP); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP"); - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } break; case WINED3DFOG_EXP2: glFogi(GL_FOG_MODE, GL_EXP2); checkGLcall("glFogi(GL_FOG_MODE, GL_EXP2"); - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } break; case WINED3DFOG_LINEAR: glFogi(GL_FOG_MODE, GL_LINEAR); checkGLcall("glFogi(GL_FOG_MODE, GL_LINEAR"); - if(GL_SUPPORT(EXT_FOG_COORD)) { + if(GL_SUPPORT(EXT_FOG_COORD) && context->fog_coord) { glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT"); + context->fog_coord = FALSE; } break; diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 20ade5c8708..2abb277db33 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -673,6 +673,10 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED TRACE("(%p) : rect@%p flags(%08x), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->resource.allocatedMemory); + if (This->Flags & SFLAG_LOCKED) { + WARN("Surface is already locked, returning D3DERR_INVALIDCALL\n"); + return WINED3DERR_INVALIDCALL; + } if (!(This->Flags & SFLAG_LOCKABLE)) { /* Note: UpdateTextures calls CopyRects which calls this routine to populate the texture regions, and since the destination is an unlockable region we need @@ -1452,6 +1456,11 @@ HRESULT WINAPI IWineD3DSurfaceImpl_ReleaseDC(IWineD3DSurface *iface, HDC hDC) { if (!(This->Flags & SFLAG_DCINUSE)) return WINED3DERR_INVALIDCALL; + if (This->hDC !=hDC) { + WARN("Application tries to release an invalid DC(%p), surface dc is %p\n", hDC, This->hDC); + return WINED3DERR_INVALIDCALL; + } + /* we locked first, so unlock now */ IWineD3DSurface_UnlockRect(iface); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 29bd24d42c5..032878090e6 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -518,6 +518,7 @@ struct WineD3DContext { GLenum untracked_materials[2]; BOOL last_was_blit, last_was_ckey; char texShaderBumpMap; + BOOL fog_coord; /* The actual opengl context */ HGLRC glCtx; @@ -1459,10 +1460,12 @@ extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl; /* Datastructures for IWineD3DQueryImpl.extendedData */ typedef struct WineQueryOcclusionData { GLuint queryId; + WineD3DContext *ctx; } WineQueryOcclusionData; typedef struct WineQueryEventData { GLuint fenceId; + WineD3DContext *ctx; } WineQueryEventData; /***************************************************************************** diff --git a/dlls/winex11.drv/opengl.c b/dlls/winex11.drv/opengl.c index 98ecedb9fde..793bf72f45b 100644 --- a/dlls/winex11.drv/opengl.c +++ b/dlls/winex11.drv/opengl.c @@ -110,6 +110,7 @@ typedef struct wine_glcontext { GLXContext ctx; BOOL do_escape; X11DRV_PDEVICE *physDev; + X11DRV_PDEVICE *pReadDev; RECT viewport; RECT scissor; BOOL scissor_enabled; @@ -546,30 +547,6 @@ static inline void free_context(Wine_GLContext *context) HeapFree(GetProcessHeap(), 0, context); } -static inline Wine_GLContext *get_context_from_GLXContext(GLXContext ctx) -{ - Wine_GLContext *ret; - if (!ctx) return NULL; - for (ret = context_list; ret; ret = ret->next) if (ctx == ret->ctx) break; - return ret; -} - -/** - * get_hdc_from_Drawable (internal) - * - * For use by wglGetCurrentReadDCARB. - */ -static inline HDC get_hdc_from_Drawable(GLXDrawable d) -{ - Wine_GLContext *ret; - for (ret = context_list; ret; ret = ret->next) { - if (d == ret->physDev->drawable) { - return ret->hdc; - } - } - return NULL; -} - static inline BOOL is_valid_context( Wine_GLContext *ctx ) { Wine_GLContext *ptr; @@ -1532,17 +1509,14 @@ BOOL X11DRV_wglDeleteContext(HGLRC hglrc) */ static HDC WINAPI X11DRV_wglGetCurrentReadDCARB(void) { - GLXDrawable gl_d; - HDC ret; - - TRACE("()\n"); + HDC ret = 0; + Wine_GLContext *ctx = NtCurrentTeb()->glContext; + X11DRV_PDEVICE *physDev = ctx ? ctx->pReadDev : NULL; - wine_tsx11_lock(); - gl_d = pglXGetCurrentReadDrawable(); - ret = get_hdc_from_Drawable(gl_d); - wine_tsx11_unlock(); + if(physDev) + ret = physDev->hdc; - TRACE(" returning %p (GL drawable %lu)\n", ret, gl_d); + TRACE(" returning %p (GL drawable %lu)\n", ret, physDev ? physDev->drawable : 0); return ret; } @@ -1680,7 +1654,9 @@ BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) { NtCurrentTeb()->glContext = ctx; if(ret) { + ctx->hdc = hdc; ctx->physDev = physDev; + ctx->pReadDev = physDev; if (type == OBJ_MEMDC) { @@ -1703,10 +1679,10 @@ BOOL X11DRV_wglMakeCurrent(X11DRV_PDEVICE *physDev, HGLRC hglrc) { * * For OpenGL32 wglMakeContextCurrentARB */ -BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* hReadDev, HGLRC hglrc) +BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* pDrawDev, X11DRV_PDEVICE* pReadDev, HGLRC hglrc) { BOOL ret; - TRACE("(%p,%p,%p)\n", hDrawDev, hReadDev, hglrc); + TRACE("(%p,%p,%p)\n", pDrawDev, pReadDev, hglrc); if (!has_opengl()) { ERR("No libGL on this box - disabling OpenGL support !\n"); @@ -1722,13 +1698,16 @@ BOOL X11DRV_wglMakeContextCurrentARB(X11DRV_PDEVICE* hDrawDev, X11DRV_PDEVICE* h ret = FALSE; } else { Wine_GLContext *ctx = (Wine_GLContext *) hglrc; - Drawable d_draw = get_glxdrawable(hDrawDev); - Drawable d_read = get_glxdrawable(hReadDev); + Drawable d_draw = get_glxdrawable(pDrawDev); + Drawable d_read = get_glxdrawable(pReadDev); if (ctx->ctx == NULL) { - ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, GetObjectType(hDrawDev->hdc) == OBJ_MEMDC ? False : True); + ctx->ctx = pglXCreateContext(gdi_display, ctx->vis, NULL, GetObjectType(pDrawDev->hdc) == OBJ_MEMDC ? False : True); TRACE(" created a delayed OpenGL context (%p)\n", ctx->ctx); } + ctx->hdc = pDrawDev->hdc; + ctx->physDev = pDrawDev; + ctx->pReadDev = pReadDev; ret = pglXMakeContextCurrent(gdi_display, d_draw, d_read, ctx->ctx); NtCurrentTeb()->glContext = ctx; } @@ -1764,7 +1743,7 @@ BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) { describeContext(org); if(org->vis) - org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True); + org->ctx = pglXCreateContext(gdi_display, org->vis, NULL, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True); else /* Create a GLX Context for a pbuffer */ org->ctx = pglXCreateNewContext(gdi_display, org->fmt->fbconfig, org->fmt->render_type, NULL, True); wine_tsx11_unlock(); @@ -1775,7 +1754,7 @@ BOOL X11DRV_wglShareLists(HGLRC hglrc1, HGLRC hglrc2) { describeContext(dest); /* Create the destination context with display lists shared */ if(dest->vis) - dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, GetObjectType(org->physDev->hdc) == OBJ_MEMDC ? False : True); + dest->ctx = pglXCreateContext(gdi_display, dest->vis, org->ctx, GetObjectType(org->hdc) == OBJ_MEMDC ? False : True); else /* Create a GLX Context for a pbuffer */ dest->ctx = pglXCreateNewContext(gdi_display, dest->fmt->fbconfig, dest->fmt->render_type, org->ctx, True); wine_tsx11_unlock(); @@ -1992,8 +1971,7 @@ static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params) { case GL_DEPTH_BITS: { - GLXContext gl_ctx = pglXGetCurrentContext(); - Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx); + Wine_GLContext *ctx = NtCurrentTeb()->glContext; pglGetIntegerv(pname, params); /** @@ -2001,7 +1979,7 @@ static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params) * we only have the default wine desktop context, * so if we have only a 24 depth say we have 32 */ - if (NULL == ret && 24 == *params) { + if (!ctx && *params == 24) { *params = 32; } TRACE("returns GL_DEPTH_BITS as '%d'\n", *params); @@ -2009,10 +1987,9 @@ static void WINAPI X11DRV_wglGetIntegerv(GLenum pname, GLint* params) } case GL_ALPHA_BITS: { - GLXContext gl_ctx = pglXGetCurrentContext(); - Wine_GLContext* ret = get_context_from_GLXContext(gl_ctx); + Wine_GLContext *ctx = NtCurrentTeb()->glContext; - pglXGetFBConfigAttrib(gdi_display, ret->fmt->fbconfig, GLX_ALPHA_SIZE, params); + pglXGetFBConfigAttrib(gdi_display, ctx->fmt->fbconfig, GLX_ALPHA_SIZE, params); TRACE("returns GL_ALPHA_BITS as '%d'\n", *params); break; } diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c index d9291c25ec0..b0c36f94500 100644 --- a/dlls/wininet/ftp.c +++ b/dlls/wininet/ftp.c @@ -1121,6 +1121,7 @@ HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, lpwh->hdr.dwFlags = dwFlags; lpwh->hdr.dwContext = dwContext; lpwh->hdr.dwRefCount = 1; + lpwh->hdr.close_connection = NULL; lpwh->hdr.destroy = FTP_CloseFileTransferHandle; lpwh->hdr.lpfnStatusCB = lpwfs->hdr.lpfnStatusCB; lpwh->nDataSocket = nDataSocket; @@ -1897,6 +1898,10 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, lpwfs->hdr.dwContext = dwContext; lpwfs->hdr.dwInternalFlags = dwInternalFlags; lpwfs->hdr.dwRefCount = 1; + /* FIXME: Native sends INTERNET_STATUS_CLOSING_CONNECTION and + * INTERNET_STATUS_CONNECTION_CLOSED, need an equivalent FTP_CloseConnection + * function */ + lpwfs->hdr.close_connection = NULL; lpwfs->hdr.destroy = FTP_CloseSessionHandle; lpwfs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB; lpwfs->download_in_progress = NULL; @@ -3006,6 +3011,7 @@ static HINTERNET FTP_ReceiveFileList(LPWININETFTPSESSIONW lpwfs, INT nSocket, LP lpwfn->hdr.htype = WH_HFTPFINDNEXT; lpwfn->hdr.dwContext = dwContext; lpwfn->hdr.dwRefCount = 1; + lpwfn->hdr.close_connection = NULL; lpwfn->hdr.destroy = FTP_CloseFindNextHandle; lpwfn->hdr.lpfnStatusCB = lpwfs->hdr.lpfnStatusCB; lpwfn->index = 1; /* Next index is 1 since we return index 0 */ diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index b676f48100c..08be913a1e8 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -103,6 +103,7 @@ struct HttpAuthInfo BOOL finished; /* finished authenticating */ }; +static void HTTP_CloseConnection(LPWININETHANDLEHEADER hdr); static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr); static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr); static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr); @@ -1363,6 +1364,7 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs, lpwhr->hdr.dwFlags = dwFlags; lpwhr->hdr.dwContext = dwContext; lpwhr->hdr.dwRefCount = 1; + lpwhr->hdr.close_connection = HTTP_CloseConnection; lpwhr->hdr.destroy = HTTP_CloseHTTPRequestHandle; lpwhr->hdr.lpfnStatusCB = lpwhs->hdr.lpfnStatusCB; lpwhr->hdr.dwInternalFlags = lpwhs->hdr.dwInternalFlags & INET_CALLBACKW; @@ -2816,6 +2818,7 @@ HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, lpwhs->hdr.dwContext = dwContext; lpwhs->hdr.dwInternalFlags = dwInternalFlags | (hIC->hdr.dwInternalFlags & INET_CALLBACKW); lpwhs->hdr.dwRefCount = 1; + lpwhs->hdr.close_connection = NULL; lpwhs->hdr.destroy = HTTP_CloseHTTPSessionHandle; lpwhs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB; @@ -3319,8 +3322,9 @@ static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR v * Close socket connection * */ -static VOID HTTP_CloseConnection(LPWININETHTTPREQW lpwhr) +static void HTTP_CloseConnection(LPWININETHANDLEHEADER hdr) { + LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr; LPWININETHTTPSESSIONW lpwhs = NULL; LPWININETAPPINFOW hIC = NULL; @@ -3380,7 +3384,7 @@ BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr) &dwBufferSize, NULL) || strcmpiW(szConnectionResponse, szKeepAlive)) { - HTTP_CloseConnection(lpwhr); + HTTP_CloseConnection(&lpwhr->hdr); } /* FIXME: store data in the URL cache here */ @@ -3403,8 +3407,6 @@ static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr) WININET_Release(&lpwhr->lpHttpSession->hdr); - HTTP_CloseConnection(lpwhr); - HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb); HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index d24eed34157..9355500c220 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -173,6 +173,14 @@ BOOL WININET_Release( LPWININETHANDLEHEADER info ) TRACE( "object %p refcount = %d\n", info, info->dwRefCount ); if( !info->dwRefCount ) { + if ( info->close_connection ) + { + TRACE( "closing connection %p\n", info); + info->close_connection( info ); + } + INTERNET_SendCallback(info, info->dwContext, + INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet, + sizeof(HINTERNET)); TRACE( "destroying object %p\n", info); info->destroy( info ); } @@ -477,6 +485,7 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, lpwai->hdr.htype = WH_HINIT; lpwai->hdr.dwFlags = dwFlags; lpwai->hdr.dwRefCount = 1; + lpwai->hdr.close_connection = NULL; lpwai->hdr.destroy = INTERNET_CloseHandle; lpwai->dwAccessType = dwAccessType; lpwai->lpszProxyUsername = NULL; @@ -984,12 +993,6 @@ BOOL WINAPI InternetCloseHandle(HINTERNET hInternet) return FALSE; } - /* FIXME: native appears to send this from the equivalent of - * WININET_Release */ - INTERNET_SendCallback(lpwh, lpwh->dwContext, - INTERNET_STATUS_HANDLE_CLOSING, &hInternet, - sizeof(HINTERNET)); - WININET_FreeHandle( hInternet ); WININET_Release( lpwh ); diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h index 6101aca2eea..42ade48353f 100644 --- a/dlls/wininet/internet.h +++ b/dlls/wininet/internet.h @@ -135,7 +135,7 @@ typedef enum struct _WININETHANDLEHEADER; typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER; -typedef void (*WININET_object_destructor)( LPWININETHANDLEHEADER ); +typedef void (*WININET_object_function)( LPWININETHANDLEHEADER ); struct _WININETHANDLEHEADER { @@ -146,7 +146,8 @@ struct _WININETHANDLEHEADER DWORD dwError; DWORD dwInternalFlags; DWORD dwRefCount; - WININET_object_destructor destroy; + WININET_object_function close_connection; + WININET_object_function destroy; INTERNET_STATUS_CALLBACK lpfnStatusCB; }; diff --git a/dlls/winspool.drv/info.c b/dlls/winspool.drv/info.c index 56203da0cf9..fee2210b90f 100644 --- a/dlls/winspool.drv/info.c +++ b/dlls/winspool.drv/info.c @@ -470,31 +470,35 @@ static BOOL add_printer_driver(const char *name) { DRIVER_INFO_3A di3a; - static char driver_path[] = "wineps16", - data_file[] = "", - config_file[] = "wineps16", - help_file[] = "", - dep_file[] = "\0", - monitor_name[] = "", + static char driver_9x[] = "wineps16.drv", + driver_nt[] = "wineps.drv", + env_9x[] = "Windows 4.0", + env_nt[] = "Windows NT x86", + data_file[] = "generic.ppd", default_data_type[] = "RAW"; - di3a.cVersion = (GetVersion() & 0x80000000) ? 0 : 3; /* FIXME: add 1, 2 */ + ZeroMemory(&di3a, sizeof(DRIVER_INFO_3A)); + di3a.cVersion = 3; di3a.pName = (char *)name; - di3a.pEnvironment = NULL; /* NULL means auto */ - di3a.pDriverPath = driver_path; + di3a.pEnvironment = env_nt; + di3a.pDriverPath = driver_nt; di3a.pDataFile = data_file; - di3a.pConfigFile = config_file; - di3a.pHelpFile = help_file; - di3a.pDependentFiles = dep_file; - di3a.pMonitorName = monitor_name; + di3a.pConfigFile = driver_nt; di3a.pDefaultDataType = default_data_type; - if (!AddPrinterDriverA(NULL, 3, (LPBYTE)&di3a)) + if (AddPrinterDriverA(NULL, 3, (LPBYTE)&di3a)) { - ERR("Failed adding driver (%d)\n", GetLastError()); - return FALSE; + di3a.cVersion = 0; + di3a.pEnvironment = env_9x; + di3a.pDriverPath = driver_9x; + di3a.pConfigFile = driver_9x; + if (AddPrinterDriverA(NULL, 3, (LPBYTE)&di3a)) + { + return TRUE; + } } - return TRUE; + ERR("Failed adding driver %s: %u\n", debugstr_a(di3a.pDriverPath), GetLastError()); + return FALSE; } #ifdef SONAME_LIBCUPS @@ -6649,7 +6653,8 @@ BOOL WINAPI AddPrinterDriverExA(LPSTR pName, DWORD Level, LPBYTE pDriverInfo, DW DWORD len; DWORD res = FALSE; - FIXME("(%s, %d, %p, 0x%x)\n", debugstr_a(pName), Level, pDriverInfo, dwFileCopyFlags); + TRACE("(%s, %d, %p, 0x%x)\n", debugstr_a(pName), Level, pDriverInfo, dwFileCopyFlags); + diA = (DRIVER_INFO_8A *) pDriverInfo; ZeroMemory(&diW, sizeof(diW)); @@ -6673,61 +6678,81 @@ BOOL WINAPI AddPrinterDriverExA(LPSTR pName, DWORD Level, LPBYTE pDriverInfo, DW /* common fields */ diW.cVersion = diA->cVersion; - len = MultiByteToWideChar(CP_ACP, 0, diA->pName, -1, NULL, 0); - diW.pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, diA->pName, -1, diW.pName, len); + if (diA->pName) { + len = MultiByteToWideChar(CP_ACP, 0, diA->pName, -1, NULL, 0); + diW.pName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, diA->pName, -1, diW.pName, len); + } - len = MultiByteToWideChar(CP_ACP, 0, diA->pEnvironment, -1, NULL, 0); - diW.pEnvironment = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, diA->pEnvironment, -1, diW.pEnvironment, len); + if (diA->pEnvironment) { + len = MultiByteToWideChar(CP_ACP, 0, diA->pEnvironment, -1, NULL, 0); + diW.pEnvironment = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, diA->pEnvironment, -1, diW.pEnvironment, len); + } - len = MultiByteToWideChar(CP_ACP, 0, diA->pDriverPath, -1, NULL, 0); - diW.pDriverPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, diA->pDriverPath, -1, diW.pDriverPath, len); + if (diA->pDriverPath) { + len = MultiByteToWideChar(CP_ACP, 0, diA->pDriverPath, -1, NULL, 0); + diW.pDriverPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, diA->pDriverPath, -1, diW.pDriverPath, len); + } - len = MultiByteToWideChar(CP_ACP, 0, diA->pDataFile, -1, NULL, 0); - diW.pDataFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, diA->pDataFile, -1, diW.pDataFile, len); + if (diA->pDataFile) { + len = MultiByteToWideChar(CP_ACP, 0, diA->pDataFile, -1, NULL, 0); + diW.pDataFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, diA->pDataFile, -1, diW.pDataFile, len); + } - len = MultiByteToWideChar(CP_ACP, 0, diA->pConfigFile, -1, NULL, 0); - diW.pConfigFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); - MultiByteToWideChar(CP_ACP, 0, diA->pConfigFile, -1, diW.pConfigFile, len); + if (diA->pConfigFile) { + len = MultiByteToWideChar(CP_ACP, 0, diA->pConfigFile, -1, NULL, 0); + diW.pConfigFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, diA->pConfigFile, -1, diW.pConfigFile, len); + } - if (Level > 2) { + if ((Level > 2) && diA->pDependentFiles) { lenA = multi_sz_lenA(diA->pDependentFiles); len = MultiByteToWideChar(CP_ACP, 0, diA->pDependentFiles, lenA, NULL, 0); diW.pDependentFiles = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pDependentFiles, lenA, diW.pDependentFiles, len); + } + if ((Level > 2) && diA->pMonitorName) { len = MultiByteToWideChar(CP_ACP, 0, diA->pMonitorName, -1, NULL, 0); diW.pMonitorName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pMonitorName, -1, diW.pMonitorName, len); } - if (Level > 3) { + if ((Level > 3) && diA->pDefaultDataType) { len = MultiByteToWideChar(CP_ACP, 0, diA->pDefaultDataType, -1, NULL, 0); diW.pDefaultDataType = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pDefaultDataType, -1, diW.pDefaultDataType, len); + } + if ((Level > 3) && diA->pszzPreviousNames) { lenA = multi_sz_lenA(diA->pszzPreviousNames); len = MultiByteToWideChar(CP_ACP, 0, diA->pszzPreviousNames, lenA, NULL, 0); diW.pszzPreviousNames = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pszzPreviousNames, lenA, diW.pszzPreviousNames, len); } - if (Level > 5) { + if ((Level > 5) && diA->pszMfgName) { len = MultiByteToWideChar(CP_ACP, 0, diA->pszMfgName, -1, NULL, 0); diW.pszMfgName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pszMfgName, -1, diW.pszMfgName, len); + } + if ((Level > 5) && diA->pszOEMUrl) { len = MultiByteToWideChar(CP_ACP, 0, diA->pszOEMUrl, -1, NULL, 0); diW.pszOEMUrl = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pszOEMUrl, -1, diW.pszOEMUrl, len); + } + if ((Level > 5) && diA->pszHardwareID) { len = MultiByteToWideChar(CP_ACP, 0, diA->pszHardwareID, -1, NULL, 0); diW.pszHardwareID = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pszHardwareID, -1, diW.pszHardwareID, len); + } + if ((Level > 5) && diA->pszProvider) { len = MultiByteToWideChar(CP_ACP, 0, diA->pszProvider, -1, NULL, 0); diW.pszProvider = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, diA->pszProvider, -1, diW.pszProvider, len); diff --git a/include/winioctl.h b/include/winioctl.h index a54c5a588aa..10c6f5e7e75 100644 --- a/include/winioctl.h +++ b/include/winioctl.h @@ -176,20 +176,29 @@ #define IOCTL_STORAGE_BASE FILE_DEVICE_MASS_STORAGE #define IOCTL_STORAGE_CHECK_VERIFY CTL_CODE(IOCTL_STORAGE_BASE, 0x0200, METHOD_BUFFERED, FILE_READ_ACCESS) +#define IOCTL_STORAGE_CHECK_VERIFY2 CTL_CODE(IOCTL_STORAGE_BASE, 0x0200, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_STORAGE_MEDIA_REMOVAL CTL_CODE(IOCTL_STORAGE_BASE, 0x0201, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_EJECT_MEDIA CTL_CODE(IOCTL_STORAGE_BASE, 0x0202, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_LOAD_MEDIA CTL_CODE(IOCTL_STORAGE_BASE, 0x0203, METHOD_BUFFERED, FILE_READ_ACCESS) +#define IOCTL_STORAGE_LOAD_MEDIA2 CTL_CODE(IOCTL_STORAGE_BASE, 0x0203, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_STORAGE_RESERVE CTL_CODE(IOCTL_STORAGE_BASE, 0x0204, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_RELEASE CTL_CODE(IOCTL_STORAGE_BASE, 0x0205, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_FIND_NEW_DEVICES CTL_CODE(IOCTL_STORAGE_BASE, 0x0206, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_EJECTION_CONTROL CTL_CODE(IOCTL_STORAGE_BASE, 0x0250, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_STORAGE_MCN_CONTROL CTL_CODE(IOCTL_STORAGE_BASE, 0x0251, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IOCTL_STORAGE_GET_MEDIA_TYPES CTL_CODE(IOCTL_STORAGE_BASE, 0x0300, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define IOCTL_STORAGE_GET_MEDIA_TYPES_EX CTL_CODE(IOCTL_STORAGE_BASE, 0x0301, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_STORAGE_GET_MEDIA_TYPES CTL_CODE(IOCTL_STORAGE_BASE, 0x0300, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_STORAGE_GET_MEDIA_TYPES_EX CTL_CODE(IOCTL_STORAGE_BASE, 0x0301, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER CTL_CODE(IOCTL_STORAGE_BASE, 0x0304, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_STORAGE_GET_HOTPLUG_INFO CTL_CODE(IOCTL_STORAGE_BASE, 0x0305, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_STORAGE_SET_HOTPLUG_INFO CTL_CODE(IOCTL_STORAGE_BASE, 0x0306, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_RESET_BUS CTL_CODE(IOCTL_STORAGE_BASE, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_STORAGE_RESET_DEVICE CTL_CODE(IOCTL_STORAGE_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS) +#define IOCTL_STORAGE_BREAK_RESERCATION CTL_CODE(IOCTL_STORAGE_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS); +#define IOCTL_STORAGE_PERSISTENT_RESERVE_IN CTL_CODE(IOCTL_STORAGE_BASE, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS); +#define IOCTL_STORAGE_PERSISTENT_RESERVE_OUT CTL_CODE(IOCTL_STORAGE_BASE, 0x0407, METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS); + #define IOCTL_STORAGE_GET_DEVICE_NUMBER CTL_CODE(IOCTL_STORAGE_BASE, 0x0420, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_DISK_BASE FILE_DEVICE_DISK @@ -225,6 +234,9 @@ #define SMART_GET_VERSION CTL_CODE(IOCTL_DISK_BASE, 0x0020, METHOD_BUFFERED, FILE_READ_ACCESS) #define SMART_SEND_DRIVE_COMMAND CTL_CODE(IOCTL_DISK_BASE, 0x0021, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define SMART_RCV_DRIVE_DATA CTL_CODE(IOCTL_DISK_BASE, 0x0022, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) + +#define IOCTL_VOLUME_BASE ((DWORD)'V') +#define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS CTL_CODE(IOCTL_VOLUME_BASE, 0, METHOD_BUFFERED, FILE_ANY_ACCESS) /* End: For _WIN32_WINNT >= 0x0400 */ #define IOCTL_SERIAL_LSRMST_INSERT CTL_CODE(FILE_DEVICE_SERIAL_PORT,31,METHOD_BUFFERED,FILE_ANY_ACCESS) @@ -316,12 +328,26 @@ typedef struct _REASSIGN_BLOCKS { DWORD BlockNumber[1]; } REASSIGN_BLOCKS, *PREASSIGN_BLOCKS; -#if(_WIN32_WINNT >= 0x0400) +/* Start: _WIN32_WINNT >= 0x0400 */ + typedef struct _DISK_CONTROLLER_NUMBER { DWORD ControllerNumber; DWORD DiskNumber; } DISK_CONTROLLER_NUMBER, *PDISK_CONTROLLER_NUMBER; -#endif /* _WIN32_WINNT >= 0x0400 */ + +/* VOLUME_GET_VOLUME_DISK_EXTENTS */ +typedef struct _DISK_EXTENT { + DWORD DiskNumber; + LARGE_INTEGER StartingOffset; + LARGE_INTEGER ExtentLength; +} DISK_EXTENT; + +typedef struct _VOLUME_DISK_EXTENTS { + DWORD NumberOfDiskExtents; + DISK_EXTENT Extents[1]; +} VOLUME_DISK_EXTENTS; + +/* End: _WIN32_WINNT >= 0x0400 */ /* Device Io Stuff - Most VxD support. * NOTE: All VxD messages seem to start with a hiword or 0 diff --git a/programs/winecfg/theme.c b/programs/winecfg/theme.c index 5797c9624df..ca67914da7b 100644 --- a/programs/winecfg/theme.c +++ b/programs/winecfg/theme.c @@ -496,9 +496,111 @@ static void apply_theme(HWND dialog) theme_dirty = FALSE; } +static struct +{ + int sm_idx, color_idx; + const char *color_reg; + int size; + COLORREF color; + LOGFONTW lf; +} metrics[] = +{ + {-1, COLOR_BTNFACE, "ButtonFace" }, /* IDC_SYSPARAMS_BUTTON */ + {-1, COLOR_BTNTEXT, "ButtonText" }, /* IDC_SYSPARAMS_BUTTON_TEXT */ + {-1, COLOR_BACKGROUND, "Background" }, /* IDC_SYSPARAMS_DESKTOP */ + {SM_CXMENUSIZE, COLOR_MENU, "Menu" }, /* IDC_SYSPARAMS_MENU */ + {-1, COLOR_MENUTEXT, "MenuText" }, /* IDC_SYSPARAMS_MENU_TEXT */ + {SM_CXVSCROLL, COLOR_SCROLLBAR, "Scrollbar" }, /* IDC_SYSPARAMS_SCROLLBAR */ + {-1, COLOR_HIGHLIGHT, "Hilight" }, /* IDC_SYSPARAMS_SELECTION */ + {-1, COLOR_HIGHLIGHTTEXT, "HilightText" }, /* IDC_SYSPARAMS_SELECTION_TEXT */ + {-1, COLOR_INFOBK, "InfoWindow" }, /* IDC_SYSPARAMS_TOOLTIP */ + {-1, COLOR_INFOTEXT, "InfoText" }, /* IDC_SYSPARAMS_TOOLTIP_TEXT */ + {-1, COLOR_WINDOW, "Window" }, /* IDC_SYSPARAMS_WINDOW */ + {-1, COLOR_WINDOWTEXT, "WindowText" }, /* IDC_SYSPARAMS_WINDOW_TEXT */ + {SM_CXSIZE, COLOR_ACTIVECAPTION, "ActiveTitle" }, /* IDC_SYSPARAMS_ACTIVE_TITLE */ + {-1, COLOR_CAPTIONTEXT, "TitleText" }, /* IDC_SYSPARAMS_ACTIVE_TITLE_TEXT */ + {-1, COLOR_INACTIVECAPTION, "InactiveTitle" }, /* IDC_SYSPARAMS_INACTIVE_TITLE */ + {-1, COLOR_INACTIVECAPTIONTEXT,"InactiveTitleText" }, /* IDC_SYSPARAMS_INACTIVE_TITLE_TEXT */ + {-1, -1, "MsgBoxText" }, /* IDC_SYSPARAMS_MSGBOX_TEXT */ +}; + +static void save_sys_color(int idx, COLORREF clr) +{ + char buffer[13]; + + sprintf(buffer, "%d %d %d", GetRValue (clr), GetGValue (clr), GetBValue (clr)); + set_reg_key(HKEY_CURRENT_USER, "Control Panel\\Colors", metrics[idx].color_reg, buffer); +} + +static void set_color_from_theme(WCHAR *keyName, COLORREF color) +{ + char *keyNameA = NULL; + int keyNameSize=0, i=0; + + keyNameSize = WideCharToMultiByte(CP_ACP, 0, keyName, -1, keyNameA, 0, NULL, NULL); + keyNameA = HeapAlloc(GetProcessHeap(), 0, keyNameSize); + WideCharToMultiByte(CP_ACP, 0, keyName, -1, keyNameA, -1, NULL, NULL); + + for (i=0; i