| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | #include "precomp.h" |
| 4 | // sql queries |
| 5 | LPCWSTR vcsWebLogQuery7 = L"SELECT `Log`, `Format` " |
| 6 | L"FROM `Wix4IIsWebLog` WHERE `Log`=?"; |
| 7 | |
| 8 | enum eWebLogQuery { wlqLog = 1, wlqFormat }; |
| 9 | |
| 10 | /* **************************************************************** |
| 11 | * ScaGetWebLog7 -Retrieves Log table data for the specified Log key |
| 12 | * |
| 13 | * ****************************************************************/ |
| 14 | HRESULT ScaGetWebLog7( |
| 15 | __in_z LPCWSTR wzLog, |
| 16 | __in WCA_WRAPQUERY_HANDLE hWebLogQuery, |
| 17 | __out SCA_WEB_LOG* pswl |
| 18 | ) |
| 19 | { |
| 20 | HRESULT hr = S_OK; |
| 21 | LPWSTR pwzData = NULL; |
| 22 | MSIHANDLE hRec; |
| 23 | |
| 24 | if (0 == WcaGetQueryRecords(hWebLogQuery)) |
| 25 | { |
| 26 | WcaLog(LOGMSG_VERBOSE, "Skipping ScaGetWebLog() - no records to process"); |
| 27 | ExitFunction1(hr = S_FALSE); |
| 28 | } |
| 29 | |
| 30 | WcaFetchWrappedReset(hWebLogQuery); |
| 31 | |
| 32 | hr = WcaFetchWrappedRecordWhereString(hWebLogQuery, wlqLog, wzLog, &hRec); |
| 33 | if (E_NOMOREITEMS == hr) |
| 34 | { |
| 35 | ExitOnFailure(hr, "cannot locate IIsWebLog.Log='%ls'", wzLog); |
| 36 | } |
| 37 | HRESULT hrTemp = WcaFetchWrappedRecordWhereString(hWebLogQuery, wlqLog, wzLog, &hRec); |
| 38 | |
| 39 | if (SUCCEEDED(hrTemp)) |
| 40 | { |
| 41 | ExitOnFailure(hr, "error - found multiple matching IIsWebLog rows"); |
| 42 | } |
| 43 | |
| 44 | ::ZeroMemory(pswl, sizeof(SCA_WEB_LOG)); |
| 45 | |
| 46 | // check that log key matches |
| 47 | hr = WcaGetRecordString(hRec, wlqLog, &pwzData); |
| 48 | ExitOnFailure(hr, "failed to get IIsWebLog.Log for Log: %ls", wzLog); |
| 49 | hr = ::StringCchCopyW(pswl->wzLog, countof(pswl->wzLog), pwzData); |
| 50 | ExitOnFailure(hr, "failed to copy log name: %ls", pwzData); |
| 51 | |
| 52 | hr = WcaGetRecordString(hRec, wlqFormat, &pwzData); |
| 53 | ExitOnFailure(hr, "failed to get IIsWebLog.Format for Log: %ls", wzLog); |
| 54 | |
| 55 | //translate WIX log format name strings to IIS7 |
| 56 | if (0 == lstrcmpW(pwzData, L"Microsoft IIS Log File Format")) |
| 57 | { |
| 58 | hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"IIS"); |
| 59 | ExitOnFailure(hr, "failed to copy log format: %ls", pwzData); |
| 60 | } |
| 61 | else if (0 == lstrcmpW(pwzData, L"NCSA Common Log File Format")) |
| 62 | { |
| 63 | hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"NCSA"); |
| 64 | ExitOnFailure(hr, "failed to copy log format: %ls", pwzData); |
| 65 | } |
| 66 | else if (0 == lstrcmpW(pwzData, L"none")) |
| 67 | { |
| 68 | hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"none"); |
| 69 | ExitOnFailure(hr, "failed to copy log format: %ls", pwzData); |
| 70 | } |
| 71 | else if (0 == lstrcmpW(pwzData, L"ODBC Logging")) |
| 72 | { |
| 73 | hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"W3C"); |
| 74 | ExitOnFailure(hr, "failed to copy log format: %ls", pwzData); |
| 75 | } |
| 76 | else if (0 == lstrcmpW(pwzData, L"W3C Extended Log File Format")) |
| 77 | { |
| 78 | hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"W3C"); |
| 79 | ExitOnFailure(hr, "failed to copy log format: %ls", pwzData); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_INDEX); |
| 84 | ExitOnFailure(hr, "Invalid log file format: %ls", pwzData); |
| 85 | } |
| 86 | |
| 87 | LExit: |
| 88 | ReleaseStr(pwzData); |
| 89 | |
| 90 | return hr; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | /* **************************************************************** |
| 95 | * ScaWriteWebLog -Writes the IIS log values to the metabase. |
| 96 | * |
| 97 | * ****************************************************************/ |
| 98 | HRESULT ScaWriteWebLog7( |
| 99 | LPCWSTR wzWebBase, |
| 100 | const SCA_WEB_LOG *pswl |
| 101 | ) |
| 102 | { |
| 103 | HRESULT hr = S_OK; |
| 104 | |
| 105 | if (*pswl->wzFormat) |
| 106 | { |
| 107 | //write pswl->wzFormat |
| 108 | hr = ScaWriteConfigID(IIS_WEBLOG); |
| 109 | ExitOnFailure(hr, "Failed to write log format id"); |
| 110 | hr = ScaWriteConfigString(wzWebBase); |
| 111 | ExitOnFailure(hr, "Failed to write log web key"); |
| 112 | hr = ScaWriteConfigString(pswl->wzFormat); |
| 113 | ExitOnFailure(hr, "Failed to write log format string"); |
| 114 | } |
| 115 | |
| 116 | LExit: |
| 117 | return hr; |
| 118 | } |
| 119 | |
| 120 |