diff options
Diffstat (limited to 'src/ext/NetFx/be/netfxsearch.cpp')
-rw-r--r-- | src/ext/NetFx/be/netfxsearch.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/ext/NetFx/be/netfxsearch.cpp b/src/ext/NetFx/be/netfxsearch.cpp new file mode 100644 index 00000000..3c12161d --- /dev/null +++ b/src/ext/NetFx/be/netfxsearch.cpp | |||
@@ -0,0 +1,149 @@ | |||
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 NetfxSearchParseFromXml( | ||
7 | __in NETFX_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 Netfx search nodes. | ||
18 | hr = XmlSelectNodes(pixnBundleExtension, L"NetFxNetCoreSearch", &pixnNodes); | ||
19 | BextExitOnFailure(hr, "Failed to select Netfx search nodes."); | ||
20 | |||
21 | // Get Netfx search node count. | ||
22 | hr = pixnNodes->get_length((long*)&cNodes); | ||
23 | BextExitOnFailure(hr, "Failed to get Netfx search node count."); | ||
24 | |||
25 | if (!cNodes) | ||
26 | { | ||
27 | ExitFunction(); | ||
28 | } | ||
29 | |||
30 | // Allocate memory for searches. | ||
31 | pSearches->rgSearches = (NETFX_SEARCH*)MemAlloc(sizeof(NETFX_SEARCH) * cNodes, TRUE); | ||
32 | BextExitOnNull(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 | NETFX_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
40 | |||
41 | hr = XmlNextElement(pixnNodes, &pixnNode, &bstrNodeName); | ||
42 | BextExitOnFailure(hr, "Failed to get next node."); | ||
43 | |||
44 | // @Id | ||
45 | hr = XmlGetAttributeEx(pixnNode, L"Id", &pSearch->sczId); | ||
46 | BextExitOnFailure(hr, "Failed to get @Id."); | ||
47 | |||
48 | // Read type specific attributes. | ||
49 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, bstrNodeName, -1, L"NetFxNetCoreSearch", -1)) | ||
50 | { | ||
51 | pSearch->Type = NETFX_SEARCH_TYPE_NET_CORE_SEARCH; | ||
52 | |||
53 | // @RuntimeType | ||
54 | hr = XmlGetAttributeUInt32(pixnNode, L"RuntimeType", reinterpret_cast<DWORD*>(&pSearch->NetCoreSearch.runtimeType)); | ||
55 | BextExitOnFailure(hr, "Failed to get @RuntimeType."); | ||
56 | |||
57 | // @Platform | ||
58 | hr = XmlGetAttributeUInt32(pixnNode, L"Platform", reinterpret_cast<DWORD*>(&pSearch->NetCoreSearch.platform)); | ||
59 | BextExitOnFailure(hr, "Failed to get @Platform."); | ||
60 | |||
61 | // @MajorVersion | ||
62 | hr = XmlGetAttributeEx(pixnNode, L"MajorVersion", &pSearch->NetCoreSearch.sczMajorVersion); | ||
63 | BextExitOnFailure(hr, "Failed to get @MajorVersion."); | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | BextExitWithRootFailure(hr, E_UNEXPECTED, "Unexpected element name: %ls", bstrNodeName); | ||
68 | } | ||
69 | |||
70 | // prepare next iteration | ||
71 | ReleaseNullObject(pixnNode); | ||
72 | ReleaseNullBSTR(bstrNodeName); | ||
73 | } | ||
74 | |||
75 | LExit: | ||
76 | ReleaseBSTR(bstrNodeName); | ||
77 | ReleaseObject(pixnNode); | ||
78 | ReleaseObject(pixnNodes); | ||
79 | |||
80 | return hr; | ||
81 | } | ||
82 | |||
83 | void NetfxSearchUninitialize( | ||
84 | __in NETFX_SEARCHES* pSearches | ||
85 | ) | ||
86 | { | ||
87 | if (pSearches->rgSearches) | ||
88 | { | ||
89 | for (DWORD i = 0; i < pSearches->cSearches; ++i) | ||
90 | { | ||
91 | NETFX_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
92 | |||
93 | ReleaseStr(pSearch->sczId); | ||
94 | } | ||
95 | MemFree(pSearches->rgSearches); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | STDMETHODIMP NetfxSearchExecute( | ||
100 | __in NETFX_SEARCHES* pSearches, | ||
101 | __in LPCWSTR wzSearchId, | ||
102 | __in LPCWSTR wzVariable, | ||
103 | __in IBundleExtensionEngine* pEngine, | ||
104 | __in LPCWSTR wzBaseDirectory | ||
105 | ) | ||
106 | { | ||
107 | HRESULT hr = S_OK; | ||
108 | NETFX_SEARCH* pSearch = NULL; | ||
109 | |||
110 | hr = NetfxSearchFindById(pSearches, wzSearchId, &pSearch); | ||
111 | BextExitOnFailure(hr, "Search id '%ls' is unknown to the util extension.", wzSearchId); | ||
112 | |||
113 | switch (pSearch->Type) | ||
114 | { | ||
115 | case NETFX_SEARCH_TYPE_NET_CORE_SEARCH: | ||
116 | hr = NetfxPerformDetectNetCore(wzVariable, pSearch, pEngine, wzBaseDirectory); | ||
117 | break; | ||
118 | default: | ||
119 | hr = E_UNEXPECTED; | ||
120 | } | ||
121 | |||
122 | LExit: | ||
123 | return hr; | ||
124 | } | ||
125 | |||
126 | STDMETHODIMP NetfxSearchFindById( | ||
127 | __in NETFX_SEARCHES* pSearches, | ||
128 | __in LPCWSTR wzId, | ||
129 | __out NETFX_SEARCH** ppSearch | ||
130 | ) | ||
131 | { | ||
132 | HRESULT hr = S_OK; | ||
133 | |||
134 | for (DWORD i = 0; i < pSearches->cSearches; ++i) | ||
135 | { | ||
136 | NETFX_SEARCH* pSearch = &pSearches->rgSearches[i]; | ||
137 | |||
138 | if (CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, pSearch->sczId, -1, wzId, -1)) | ||
139 | { | ||
140 | *ppSearch = pSearch; | ||
141 | ExitFunction1(hr = S_OK); | ||
142 | } | ||
143 | } | ||
144 | |||
145 | hr = E_NOTFOUND; | ||
146 | |||
147 | LExit: | ||
148 | return hr; | ||
149 | } | ||