aboutsummaryrefslogtreecommitdiff
path: root/src/be/utilsearch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/be/utilsearch.cpp')
-rw-r--r--src/be/utilsearch.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/be/utilsearch.cpp b/src/be/utilsearch.cpp
new file mode 100644
index 00000000..4e9d86a1
--- /dev/null
+++ b/src/be/utilsearch.cpp
@@ -0,0 +1,137 @@
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
6STDMETHODIMP 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
17 // Select Util search nodes.
18 hr = XmlSelectNodes(pixnBundleExtension, L"WixDetectSHA2Support", &pixnNodes);
19 ExitOnFailure(hr, "Failed to select Util search nodes.");
20
21 // Get Util search node count.
22 hr = pixnNodes->get_length((long*)&cNodes);
23 ExitOnFailure(hr, "Failed to get Util search node count.");
24
25 if (!cNodes)
26 {
27 ExitFunction();
28 }
29
30 // Allocate memory for searches.
31 pSearches->rgSearches = (UTIL_SEARCH*)MemAlloc(sizeof(UTIL_SEARCH) * cNodes, TRUE);
32 ExitOnNull(pSearches->rgSearches, hr, E_OUTOFMEMORY, "Failed to allocate memory for search structs.");
33
34 pSearches->cSearches = cNodes;
35
36 // Parse search elements.
37 for (DWORD i = 0; i < cNodes; ++i)
38 {
39 UTIL_SEARCH* pSearch = &pSearches->rgSearches[i];
40
41 hr = XmlNextElement(pixnNodes, &pixnNode, &bstrNodeName);
42 ExitOnFailure(hr, "Failed to get next node.");
43
44 // @Id
45 hr = XmlGetAttributeEx(pixnNode, L"Id", &pSearch->sczId);
46 ExitOnFailure(hr, "Failed to get @Id.");
47
48 // Read type specific attributes.
49 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"WixDetectSHA2Support", -1))
50 {
51 pSearch->Type = UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT;
52 }
53 else
54 {
55 hr = E_UNEXPECTED;
56 ExitOnFailure(hr, "Unexpected element name: %ls", bstrNodeName);
57 }
58
59 // prepare next iteration
60 ReleaseNullObject(pixnNode);
61 ReleaseNullBSTR(bstrNodeName);
62 }
63
64LExit:
65 ReleaseBSTR(bstrNodeName);
66 ReleaseObject(pixnNode);
67 ReleaseObject(pixnNodes);
68
69 return hr;
70}
71
72void UtilSearchUninitialize(
73 __in UTIL_SEARCHES* pSearches
74 )
75{
76 if (pSearches->rgSearches)
77 {
78 for (DWORD i = 0; i < pSearches->cSearches; ++i)
79 {
80 UTIL_SEARCH* pSearch = &pSearches->rgSearches[i];
81
82 ReleaseStr(pSearch->sczId);
83 }
84 MemFree(pSearches->rgSearches);
85 }
86}
87
88STDMETHODIMP UtilSearchExecute(
89 __in UTIL_SEARCHES* pSearches,
90 __in LPCWSTR wzSearchId,
91 __in LPCWSTR wzVariable,
92 __in IBundleExtensionEngine* pEngine
93 )
94{
95 HRESULT hr = S_OK;
96 UTIL_SEARCH* pSearch = NULL;
97
98 hr = UtilSearchFindById(pSearches, wzSearchId, &pSearch);
99 ExitOnFailure(hr, "Search id '%ls' is unknown to the util extension.");
100
101 switch (pSearch->Type)
102 {
103 case UTIL_SEARCH_TYPE_DETECT_SHA2_SUPPORT:
104 hr = UtilPerformDetectSHA2Support(wzVariable, pSearch, pEngine);
105 break;
106 default:
107 hr = E_UNEXPECTED;
108 }
109
110LExit:
111 return hr;
112}
113
114STDMETHODIMP UtilSearchFindById(
115 __in UTIL_SEARCHES* pSearches,
116 __in LPCWSTR wzId,
117 __out UTIL_SEARCH** ppSearch
118 )
119{
120 HRESULT hr = S_OK;
121
122 for (DWORD i = 0; i < pSearches->cSearches; ++i)
123 {
124 UTIL_SEARCH* pSearch = &pSearches->rgSearches[i];
125
126 if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pSearch->sczId, -1, wzId, -1))
127 {
128 *ppSearch = pSearch;
129 ExitFunction1(hr = S_OK);
130 }
131 }
132
133 hr = E_NOTFOUND;
134
135LExit:
136 return hr;
137}