diff options
author | Rob Mensching <rob@firegiant.com> | 2021-05-03 09:55:22 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-05-03 09:55:22 -0700 |
commit | ff659159e041bf6c083e6b7fcb9b726065a9dd73 (patch) | |
tree | ea95bf3d3e031edcee65de33b9e6954178be669c /src/ext/Util/be/utilsearch.cpp | |
parent | 8a8a25695351ee542f08886a9d0957c78c6af366 (diff) | |
download | wix-ff659159e041bf6c083e6b7fcb9b726065a9dd73.tar.gz wix-ff659159e041bf6c083e6b7fcb9b726065a9dd73.tar.bz2 wix-ff659159e041bf6c083e6b7fcb9b726065a9dd73.zip |
Move Util.wixext into ext
Diffstat (limited to 'src/ext/Util/be/utilsearch.cpp')
-rw-r--r-- | src/ext/Util/be/utilsearch.cpp | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/src/ext/Util/be/utilsearch.cpp b/src/ext/Util/be/utilsearch.cpp new file mode 100644 index 00000000..7cd2ea09 --- /dev/null +++ b/src/ext/Util/be/utilsearch.cpp | |||
@@ -0,0 +1,160 @@ | |||
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 | |||
5 | |||
6 | STDMETHODIMP UtilSearchParseFromXml( | ||
7 | __in UTIL_SEARCHES* pSearches, | ||
8 | __in IXMLDOMNode* pixnBundleExtension | ||
9 | ) | ||
10 | { | ||
11 | HRESULT hr = S_OK; | ||
12 | IXMLDOMNodeList* pixnNodes = NULL; | ||
13 | IXMLDOMNode* pixnNode = NULL; | ||
14 | DWORD cNodes = 0; | ||
15 | BSTR bstrNodeName = NULL; | ||
16 | LPWSTR scz = NULL; | ||
17 | |||
18 | // Select Util search nodes. | ||
19 | hr = XmlSelectNodes(pixnBundleExtension, L"WixWindowsFeatureSearch", &pixnNodes); | ||
20 | ExitOnFailure(hr, "Failed to select Util search nodes."); | ||
21 | |||
22 | // Get Util search node count. | ||
23 | hr = pixnNodes->get_length((long*)&cNodes); | ||
24 | ExitOnFailure(hr, "Failed to get Util search node count."); | ||
25 | |||
26 | if (!cNodes) | ||
27 | { | ||
28 | ExitFunction(); | ||
29 | } | ||
30 | |||
31 | // Allocate memory for searches. | ||
32 | pSearches->rgSearches = (UTIL_SEARCH*)MemAlloc(sizeof(UTIL_SEARCH) * cNodes, TRUE); | ||
33 | ExitOnNull(pSearches->rgSearches, hr, E_OUTOFMEMORY, "Failed to allocate memory for search structs."); | ||
34 | |||
35 | pSearches->cSearches = cNodes; | ||
36 | |||
37 | // Parse search elements. | ||
38 | for (DWORD i = 0; i < cNodes; ++i) | ||
39 | { | ||
40 | UTIL_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
41 | |||
42 | hr = XmlNextElement(pixnNodes, &pixnNode, &bstrNodeName); | ||
43 | ExitOnFailure(hr, "Failed to get next node."); | ||
44 | |||
45 | // @Id | ||
46 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pSearch->sczId); | ||
47 | ExitOnFailure(hr, "Failed to get @Id."); | ||
48 | |||
49 | // Read type specific attributes. | ||
50 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixWindowsFeatureSearch", -1)) | ||
51 | { | ||
52 | pSearch->Type = UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH; | ||
53 | |||
54 | // @Type | ||
55 | hr = XmlGetAttributeEx(pixnNode, L"Type", &scz); | ||
56 | ExitOnFailure(hr, "Failed to get @Type."); | ||
57 | |||
58 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, scz, -1, L"sha2CodeSigning", -1)) | ||
59 | { | ||
60 | pSearch->WindowsFeatureSearch.type = UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING; | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | hr = E_INVALIDARG; | ||
65 | ExitOnFailure(hr, "Invalid value for @Type: %ls", scz); | ||
66 | } | ||
67 | } | ||
68 | else | ||
69 | { | ||
70 | hr = E_UNEXPECTED; | ||
71 | ExitOnFailure(hr, "Unexpected element name: %ls", bstrNodeName); | ||
72 | } | ||
73 | |||
74 | // prepare next iteration | ||
75 | ReleaseNullObject(pixnNode); | ||
76 | ReleaseNullBSTR(bstrNodeName); | ||
77 | } | ||
78 | |||
79 | LExit: | ||
80 | ReleaseStr(scz); | ||
81 | ReleaseBSTR(bstrNodeName); | ||
82 | ReleaseObject(pixnNode); | ||
83 | ReleaseObject(pixnNodes); | ||
84 | |||
85 | return hr; | ||
86 | } | ||
87 | |||
88 | void UtilSearchUninitialize( | ||
89 | __in UTIL_SEARCHES* pSearches | ||
90 | ) | ||
91 | { | ||
92 | if (pSearches->rgSearches) | ||
93 | { | ||
94 | for (DWORD i = 0; i < pSearches->cSearches; ++i) | ||
95 | { | ||
96 | UTIL_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
97 | |||
98 | ReleaseStr(pSearch->sczId); | ||
99 | } | ||
100 | MemFree(pSearches->rgSearches); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | STDMETHODIMP UtilSearchExecute( | ||
105 | __in UTIL_SEARCHES* pSearches, | ||
106 | __in LPCWSTR wzSearchId, | ||
107 | __in LPCWSTR wzVariable, | ||
108 | __in IBundleExtensionEngine* pEngine | ||
109 | ) | ||
110 | { | ||
111 | HRESULT hr = S_OK; | ||
112 | UTIL_SEARCH* pSearch = NULL; | ||
113 | |||
114 | hr = UtilSearchFindById(pSearches, wzSearchId, &pSearch); | ||
115 | ExitOnFailure(hr, "Search id '%ls' is unknown to the util extension."); | ||
116 | |||
117 | switch (pSearch->Type) | ||
118 | { | ||
119 | case UTIL_SEARCH_TYPE_WINDOWS_FEATURE_SEARCH: | ||
120 | switch (pSearch->WindowsFeatureSearch.type) | ||
121 | { | ||
122 | case UTIL_WINDOWS_FEATURE_SEARCH_TYPE_SHA2_CODE_SIGNING: | ||
123 | hr = UtilPerformDetectSHA2CodeSigning(wzVariable, pSearch, pEngine); | ||
124 | break; | ||
125 | default: | ||
126 | hr = E_UNEXPECTED; | ||
127 | } | ||
128 | break; | ||
129 | default: | ||
130 | hr = E_UNEXPECTED; | ||
131 | } | ||
132 | |||
133 | LExit: | ||
134 | return hr; | ||
135 | } | ||
136 | |||
137 | STDMETHODIMP UtilSearchFindById( | ||
138 | __in UTIL_SEARCHES* pSearches, | ||
139 | __in LPCWSTR wzId, | ||
140 | __out UTIL_SEARCH** ppSearch | ||
141 | ) | ||
142 | { | ||
143 | HRESULT hr = S_OK; | ||
144 | |||
145 | for (DWORD i = 0; i < pSearches->cSearches; ++i) | ||
146 | { | ||
147 | UTIL_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
148 | |||
149 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pSearch->sczId, -1, wzId, -1)) | ||
150 | { | ||
151 | *ppSearch = pSearch; | ||
152 | ExitFunction1(hr = S_OK); | ||
153 | } | ||
154 | } | ||
155 | |||
156 | hr = E_NOTFOUND; | ||
157 | |||
158 | LExit: | ||
159 | return hr; | ||
160 | } | ||