diff options
Diffstat (limited to 'src/wixext/FirewallCompiler.cs')
-rw-r--r-- | src/wixext/FirewallCompiler.cs | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/wixext/FirewallCompiler.cs b/src/wixext/FirewallCompiler.cs index 353afff3..16136954 100644 --- a/src/wixext/FirewallCompiler.cs +++ b/src/wixext/FirewallCompiler.cs | |||
@@ -28,8 +28,8 @@ namespace WixToolset.Firewall | |||
28 | switch (parentElement.Name.LocalName) | 28 | switch (parentElement.Name.LocalName) |
29 | { | 29 | { |
30 | case "File": | 30 | case "File": |
31 | string fileId = context["FileId"]; | 31 | var fileId = context["FileId"]; |
32 | string fileComponentId = context["ComponentId"]; | 32 | var fileComponentId = context["ComponentId"]; |
33 | 33 | ||
34 | switch (element.Name.LocalName) | 34 | switch (element.Name.LocalName) |
35 | { | 35 | { |
@@ -42,7 +42,7 @@ namespace WixToolset.Firewall | |||
42 | } | 42 | } |
43 | break; | 43 | break; |
44 | case "Component": | 44 | case "Component": |
45 | string componentId = context["ComponentId"]; | 45 | var componentId = context["ComponentId"]; |
46 | 46 | ||
47 | switch (element.Name.LocalName) | 47 | switch (element.Name.LocalName) |
48 | { | 48 | { |
@@ -68,22 +68,20 @@ namespace WixToolset.Firewall | |||
68 | /// <param name="fileId">The file identifier of the parent element (null if nested under Component).</param> | 68 | /// <param name="fileId">The file identifier of the parent element (null if nested under Component).</param> |
69 | private void ParseFirewallExceptionElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string fileId) | 69 | private void ParseFirewallExceptionElement(Intermediate intermediate, IntermediateSection section, XElement element, string componentId, string fileId) |
70 | { | 70 | { |
71 | SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | 71 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); |
72 | Identifier id = null; | 72 | Identifier id = null; |
73 | string name = null; | 73 | string name = null; |
74 | int attributes = 0; | 74 | int attributes = 0; |
75 | string file = null; | 75 | string file = null; |
76 | string program = null; | 76 | string program = null; |
77 | string port = null; | 77 | string port = null; |
78 | string protocolValue = null; | ||
79 | int? protocol = null; | 78 | int? protocol = null; |
80 | string profileValue = null; | ||
81 | int? profile = null; | 79 | int? profile = null; |
82 | string scope = null; | 80 | string scope = null; |
83 | string remoteAddresses = null; | 81 | string remoteAddresses = null; |
84 | string description = null; | 82 | string description = null; |
85 | 83 | ||
86 | foreach (XAttribute attrib in element.Attributes()) | 84 | foreach (var attrib in element.Attributes()) |
87 | { | 85 | { |
88 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | 86 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) |
89 | { | 87 | { |
@@ -125,7 +123,7 @@ namespace WixToolset.Firewall | |||
125 | port = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | 123 | port = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
126 | break; | 124 | break; |
127 | case "Protocol": | 125 | case "Protocol": |
128 | protocolValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | 126 | var protocolValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
129 | switch (protocolValue) | 127 | switch (protocolValue) |
130 | { | 128 | { |
131 | case "tcp": | 129 | case "tcp": |
@@ -155,7 +153,7 @@ namespace WixToolset.Firewall | |||
155 | } | 153 | } |
156 | break; | 154 | break; |
157 | case "Profile": | 155 | case "Profile": |
158 | profileValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); | 156 | var profileValue = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
159 | switch (profileValue) | 157 | switch (profileValue) |
160 | { | 158 | { |
161 | case "domain": | 159 | case "domain": |
@@ -190,11 +188,10 @@ namespace WixToolset.Firewall | |||
190 | } | 188 | } |
191 | 189 | ||
192 | // parse RemoteAddress children | 190 | // parse RemoteAddress children |
193 | foreach (XElement child in element.Elements()) | 191 | foreach (var child in element.Elements()) |
194 | { | 192 | { |
195 | if (this.Namespace == child.Name.Namespace) | 193 | if (this.Namespace == child.Name.Namespace) |
196 | { | 194 | { |
197 | SourceLineNumber childSourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(child); | ||
198 | switch (child.Name.LocalName) | 195 | switch (child.Name.LocalName) |
199 | { | 196 | { |
200 | case "RemoteAddress": | 197 | case "RemoteAddress": |
@@ -218,12 +215,12 @@ namespace WixToolset.Firewall | |||
218 | } | 215 | } |
219 | } | 216 | } |
220 | 217 | ||
221 | // Id and Name are required | ||
222 | if (null == id) | 218 | if (null == id) |
223 | { | 219 | { |
224 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); | 220 | id = this.ParseHelper.CreateIdentifier("fex", name, remoteAddresses, componentId); |
225 | } | 221 | } |
226 | 222 | ||
223 | // Name is required | ||
227 | if (null == name) | 224 | if (null == name) |
228 | { | 225 | { |
229 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Name")); | 226 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Name")); |
@@ -255,14 +252,14 @@ namespace WixToolset.Firewall | |||
255 | fileId = file; | 252 | fileId = file; |
256 | } | 253 | } |
257 | 254 | ||
258 | var tuple = new WixFirewallExceptionTuple(sourceLineNumbers, id) | 255 | var tuple = section.AddTuple(new WixFirewallExceptionTuple(sourceLineNumbers, id) |
259 | { | 256 | { |
260 | Name = name, | 257 | Name = name, |
261 | RemoteAddresses = remoteAddresses, | 258 | RemoteAddresses = remoteAddresses, |
262 | Profile = profile ?? FirewallConstants.NET_FW_PROFILE2_ALL, | 259 | Profile = profile ?? FirewallConstants.NET_FW_PROFILE2_ALL, |
263 | ComponentRef = componentId, | 260 | ComponentRef = componentId, |
264 | Description = description, | 261 | Description = description, |
265 | }; | 262 | }); |
266 | 263 | ||
267 | if (!String.IsNullOrEmpty(port)) | 264 | if (!String.IsNullOrEmpty(port)) |
268 | { | 265 | { |
@@ -275,12 +272,15 @@ namespace WixToolset.Firewall | |||
275 | } | 272 | } |
276 | } | 273 | } |
277 | 274 | ||
278 | tuple.Protocol = protocol.Value; | 275 | if (protocol.HasValue) |
276 | { | ||
277 | tuple.Protocol = protocol.Value; | ||
278 | } | ||
279 | 279 | ||
280 | if (!String.IsNullOrEmpty(fileId)) | 280 | if (!String.IsNullOrEmpty(fileId)) |
281 | { | 281 | { |
282 | tuple.Program = $"[#{fileId}]"; | 282 | tuple.Program = $"[#{fileId}]"; |
283 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "File", fileId); | 283 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.File, fileId); |
284 | } | 284 | } |
285 | else if (!String.IsNullOrEmpty(program)) | 285 | else if (!String.IsNullOrEmpty(program)) |
286 | { | 286 | { |
@@ -292,19 +292,17 @@ namespace WixToolset.Firewall | |||
292 | tuple.Attributes = attributes; | 292 | tuple.Attributes = attributes; |
293 | } | 293 | } |
294 | 294 | ||
295 | section.Tuples.Add(tuple); | ||
296 | |||
297 | if (this.Context.Platform == Platform.ARM) | 295 | if (this.Context.Platform == Platform.ARM) |
298 | { | 296 | { |
299 | // Ensure ARM version of the CA is referenced | 297 | // Ensure ARM version of the CA is referenced |
300 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedFirewallExceptionsInstall_ARM"); | 298 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedFirewallExceptionsInstall_ARM"); |
301 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedFirewallExceptionsUninstall_ARM"); | 299 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedFirewallExceptionsUninstall_ARM"); |
302 | } | 300 | } |
303 | else | 301 | else |
304 | { | 302 | { |
305 | // All other supported platforms use x86 | 303 | // All other supported platforms use x86 |
306 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedFirewallExceptionsInstall"); | 304 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedFirewallExceptionsInstall"); |
307 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "WixSchedFirewallExceptionsUninstall"); | 305 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "WixSchedFirewallExceptionsUninstall"); |
308 | } | 306 | } |
309 | } | 307 | } |
310 | } | 308 | } |
@@ -315,10 +313,10 @@ namespace WixToolset.Firewall | |||
315 | /// <param name="element">The element to parse.</param> | 313 | /// <param name="element">The element to parse.</param> |
316 | private void ParseRemoteAddressElement(Intermediate intermediate, IntermediateSection section, XElement element, ref string remoteAddresses) | 314 | private void ParseRemoteAddressElement(Intermediate intermediate, IntermediateSection section, XElement element, ref string remoteAddresses) |
317 | { | 315 | { |
318 | SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); | 316 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); |
319 | 317 | ||
320 | // no attributes | 318 | // no attributes |
321 | foreach (XAttribute attrib in element.Attributes()) | 319 | foreach (var attrib in element.Attributes()) |
322 | { | 320 | { |
323 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) | 321 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) |
324 | { | 322 | { |
@@ -332,7 +330,7 @@ namespace WixToolset.Firewall | |||
332 | 330 | ||
333 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); | 331 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); |
334 | 332 | ||
335 | string address = this.ParseHelper.GetTrimmedInnerText(element); | 333 | var address = this.ParseHelper.GetTrimmedInnerText(element); |
336 | if (String.IsNullOrEmpty(address)) | 334 | if (String.IsNullOrEmpty(address)) |
337 | { | 335 | { |
338 | this.Messaging.Write(FirewallErrors.IllegalEmptyRemoteAddress(sourceLineNumbers)); | 336 | this.Messaging.Write(FirewallErrors.IllegalEmptyRemoteAddress(sourceLineNumbers)); |