aboutsummaryrefslogtreecommitdiff
path: root/src/ext/Iis/ca/scaweblog7.cpp
blob: 8164e298f7d401e4d091882de0528b204ed73009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 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.

#include "precomp.h"
// sql queries
LPCWSTR vcsWebLogQuery7 = L"SELECT `Log`, `Format` "
                          L"FROM `Wix4IIsWebLog` WHERE `Log`=?";

enum eWebLogQuery { wlqLog = 1, wlqFormat };

/* ****************************************************************
 * ScaGetWebLog7 -Retrieves Log table data for the specified Log key
 *
 * ****************************************************************/
HRESULT ScaGetWebLog7(
    __in_z LPCWSTR wzLog,
    __in WCA_WRAPQUERY_HANDLE hWebLogQuery,
    __out SCA_WEB_LOG* pswl
    )
{
    HRESULT hr = S_OK;
    LPWSTR pwzData = NULL;
    MSIHANDLE hRec;

    if (0 == WcaGetQueryRecords(hWebLogQuery))
    {
        WcaLog(LOGMSG_VERBOSE, "Skipping ScaGetWebLog() - no records to process");
        ExitFunction1(hr = S_FALSE);
    }

    WcaFetchWrappedReset(hWebLogQuery);

    hr = WcaFetchWrappedRecordWhereString(hWebLogQuery, wlqLog, wzLog, &hRec);
    if (E_NOMOREITEMS == hr)
    {
        ExitOnFailure(hr, "cannot locate IIsWebLog.Log='%ls'", wzLog);
    }
    HRESULT hrTemp = WcaFetchWrappedRecordWhereString(hWebLogQuery, wlqLog, wzLog, &hRec);

    if (SUCCEEDED(hrTemp))
    {
        ExitOnFailure(hr, "error - found multiple matching IIsWebLog rows");
    }

    ::ZeroMemory(pswl, sizeof(SCA_WEB_LOG));

    // check that log key matches
    hr = WcaGetRecordString(hRec, wlqLog, &pwzData);
    ExitOnFailure(hr, "failed to get IIsWebLog.Log for Log: %ls", wzLog);
    hr = ::StringCchCopyW(pswl->wzLog, countof(pswl->wzLog), pwzData);
    ExitOnFailure(hr, "failed to copy log name: %ls", pwzData);

    hr = WcaGetRecordString(hRec, wlqFormat, &pwzData);
    ExitOnFailure(hr, "failed to get IIsWebLog.Format for Log: %ls", wzLog);

    //translate WIX log format name strings to IIS7
    if (0 == lstrcmpW(pwzData, L"Microsoft IIS Log File Format"))
    {
        hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"IIS");
        ExitOnFailure(hr, "failed to copy log format: %ls", pwzData);
    }
    else if (0 == lstrcmpW(pwzData, L"NCSA Common Log File Format"))
    {
        hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"NCSA");
        ExitOnFailure(hr, "failed to copy log format: %ls", pwzData);
    }
    else if (0 == lstrcmpW(pwzData, L"none"))
    {
        hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"none");
        ExitOnFailure(hr, "failed to copy log format: %ls", pwzData);
    }
    else if (0 == lstrcmpW(pwzData, L"ODBC Logging"))
    {
        hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"W3C");
        ExitOnFailure(hr, "failed to copy log format: %ls", pwzData);
    }
    else if (0 == lstrcmpW(pwzData, L"W3C Extended Log File Format"))
    {
        hr = ::StringCchCopyW(pswl->wzFormat, countof(pswl->wzFormat), L"W3C");
        ExitOnFailure(hr, "failed to copy log format: %ls", pwzData);
    }
    else
    {
        hr = HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
        ExitOnFailure(hr, "Invalid log file format: %ls", pwzData);
    }

LExit:
    ReleaseStr(pwzData);

    return hr;
}


/* ****************************************************************
 * ScaWriteWebLog -Writes the IIS log values to the metabase.
 *
 * ****************************************************************/
HRESULT ScaWriteWebLog7(
    LPCWSTR wzWebBase,
    const SCA_WEB_LOG *pswl
    )
{
    HRESULT hr = S_OK;

    if (*pswl->wzFormat)
    {
        //write pswl->wzFormat
        hr = ScaWriteConfigID(IIS_WEBLOG);
        ExitOnFailure(hr, "Failed to write log format id");
        hr = ScaWriteConfigString(wzWebBase);
        ExitOnFailure(hr, "Failed to write log web key");
        hr = ScaWriteConfigString(pswl->wzFormat);
        ExitOnFailure(hr, "Failed to write log format string");
    }

LExit:
    return hr;
}