diff Xml/PolicyFile.cs @ 0:3ab940a0c7a0

Initial commit
author Ivo Smits <Ivo@UCIS.nl>
date Tue, 11 Sep 2012 16:28:53 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Xml/PolicyFile.cs	Tue Sep 11 16:28:53 2012 +0200
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using UCIS.Net;
+
+namespace UCIS.Xml {
+	public class XmlPolicyFile : XmlServer.IModule {
+		private string[] pHosts;
+		private string pPorts;
+
+		public XmlPolicyFile(string[] Hosts) : this(Hosts, null) { }
+		public XmlPolicyFile(string[] Hosts, int[] Ports) {
+			pHosts = Hosts;
+			if (Ports != null) {
+				pPorts = "";
+				foreach (int Port in Ports) {
+					pPorts += "," + Port.ToString();
+				}
+				pPorts = pPorts.Substring(1);
+			} else {
+				pPorts = null;
+			}
+		}
+
+		public void Accept(XmlSocket Socket, System.Xml.XmlDocument FirstMessage) {
+			Socket.WriterSettings.OmitXmlDeclaration = false;
+
+			Socket.WriteStartDocument();
+			Socket.WriteDocType("cross-domain-policy", null, "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd", null);
+			Socket.WriteStartElement("cross-domain-policy");
+
+			foreach (string Host in pHosts) {
+				Socket.WriteStartElement("allow-access-from");
+				Socket.WriteAttributeString("domain", Host);
+				if (pPorts != null) Socket.WriteAttributeString("to-ports", pPorts);
+				Socket.WriteEndElement();
+			}
+
+			Socket.WriteEndElement();
+			Socket.WriteEndDocument();
+		}
+	}
+}