diff options
Diffstat (limited to 'Mono.Nat/Upnp/Messages')
12 files changed, 0 insertions, 603 deletions
diff --git a/Mono.Nat/Upnp/Messages/ErrorMessage.cs b/Mono.Nat/Upnp/Messages/ErrorMessage.cs index f2755c93e9..7c0c44d8e8 100644 --- a/Mono.Nat/Upnp/Messages/ErrorMessage.cs +++ b/Mono.Nat/Upnp/Messages/ErrorMessage.cs @@ -59,10 +59,5 @@ namespace Mono.Nat.Upnp { throw new NotImplementedException(); } - - public override System.Net.WebRequest Encode(out byte[] body) - { - throw new NotImplementedException(); - } } } diff --git a/Mono.Nat/Upnp/Messages/GetServicesMessage.cs b/Mono.Nat/Upnp/Messages/GetServicesMessage.cs index 87dcb59e4d..9d29f98fdf 100644 --- a/Mono.Nat/Upnp/Messages/GetServicesMessage.cs +++ b/Mono.Nat/Upnp/Messages/GetServicesMessage.cs @@ -60,17 +60,6 @@ namespace Mono.Nat.Upnp } } - public override WebRequest Encode(out byte[] body) - { - HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://" + this.hostAddress.ToString() + this.servicesDescriptionUrl); - req.Headers.Add("ACCEPT-LANGUAGE", "en"); - req.Method = "GET"; - - body = new byte[0]; - return req; - } - - public override HttpRequestOptions Encode() { var req = new HttpRequestOptions(); diff --git a/Mono.Nat/Upnp/Messages/Requests/CreatePortMappingMessage.cs b/Mono.Nat/Upnp/Messages/Requests/CreatePortMappingMessage.cs index 2d128f8e7e..e9caa916d1 100644 --- a/Mono.Nat/Upnp/Messages/Requests/CreatePortMappingMessage.cs +++ b/Mono.Nat/Upnp/Messages/Requests/CreatePortMappingMessage.cs @@ -71,25 +71,5 @@ namespace Mono.Nat.Upnp writer.Flush(); return CreateRequest("AddPortMapping", builder.ToString()); } - - public override WebRequest Encode(out byte[] body) - { - CultureInfo culture = CultureInfo.InvariantCulture; - - StringBuilder builder = new StringBuilder(256); - XmlWriter writer = CreateWriter(builder); - - WriteFullElement(writer, "NewRemoteHost", string.Empty); - WriteFullElement(writer, "NewExternalPort", this.mapping.PublicPort.ToString(culture)); - WriteFullElement(writer, "NewProtocol", this.mapping.Protocol == Protocol.Tcp ? "TCP" : "UDP"); - WriteFullElement(writer, "NewInternalPort", this.mapping.PrivatePort.ToString(culture)); - WriteFullElement(writer, "NewInternalClient", this.localIpAddress.ToString()); - WriteFullElement(writer, "NewEnabled", "1"); - WriteFullElement(writer, "NewPortMappingDescription", string.IsNullOrEmpty(mapping.Description) ? "Mono.Nat" : mapping.Description); - WriteFullElement(writer, "NewLeaseDuration", mapping.Lifetime.ToString()); - - writer.Flush(); - return CreateRequest("AddPortMapping", builder.ToString(), out body); - } } } diff --git a/Mono.Nat/Upnp/Messages/Requests/DeletePortMappingMessage.cs b/Mono.Nat/Upnp/Messages/Requests/DeletePortMappingMessage.cs deleted file mode 100644 index ac04a66db1..0000000000 --- a/Mono.Nat/Upnp/Messages/Requests/DeletePortMappingMessage.cs +++ /dev/null @@ -1,71 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System.Net; -using System.IO; -using System.Text; -using System.Xml; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class DeletePortMappingMessage : MessageBase - { - private Mapping mapping; - - public DeletePortMappingMessage(Mapping mapping, UpnpNatDevice device) - : base(device) - { - this.mapping = mapping; - } - - public override HttpRequestOptions Encode() - { - StringBuilder builder = new StringBuilder(256); - XmlWriter writer = CreateWriter(builder); - - WriteFullElement(writer, "NewRemoteHost", string.Empty); - WriteFullElement(writer, "NewExternalPort", mapping.PublicPort.ToString(MessageBase.Culture)); - WriteFullElement(writer, "NewProtocol", mapping.Protocol == Protocol.Tcp ? "TCP" : "UDP"); - - writer.Flush(); - return CreateRequest("DeletePortMapping", builder.ToString()); - } - - public override WebRequest Encode(out byte[] body) - { - StringBuilder builder = new StringBuilder(256); - XmlWriter writer = CreateWriter(builder); - - WriteFullElement(writer, "NewRemoteHost", string.Empty); - WriteFullElement(writer, "NewExternalPort", mapping.PublicPort.ToString(MessageBase.Culture)); - WriteFullElement(writer, "NewProtocol", mapping.Protocol == Protocol.Tcp ? "TCP" : "UDP"); - - writer.Flush(); - return CreateRequest("DeletePortMapping", builder.ToString(), out body); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/Requests/GetExternalIPAddressMessage.cs b/Mono.Nat/Upnp/Messages/Requests/GetExternalIPAddressMessage.cs deleted file mode 100644 index b5c9caf9cc..0000000000 --- a/Mono.Nat/Upnp/Messages/Requests/GetExternalIPAddressMessage.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; -using System.Net; -using System.IO; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class GetExternalIPAddressMessage : MessageBase - { - - #region Constructors - public GetExternalIPAddressMessage(UpnpNatDevice device) - :base(device) - { - } - #endregion - - public override HttpRequestOptions Encode() - { - return CreateRequest("GetExternalIPAddress", string.Empty); - } - - public override WebRequest Encode(out byte[] body) - { - return CreateRequest("GetExternalIPAddress", string.Empty, out body); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/Requests/GetGenericPortMappingEntry.cs b/Mono.Nat/Upnp/Messages/Requests/GetGenericPortMappingEntry.cs deleted file mode 100644 index 89980c30c4..0000000000 --- a/Mono.Nat/Upnp/Messages/Requests/GetGenericPortMappingEntry.cs +++ /dev/null @@ -1,67 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class GetGenericPortMappingEntry : MessageBase - { - private int index; - - public GetGenericPortMappingEntry(int index, UpnpNatDevice device) - :base(device) - { - this.index = index; - } - - public override HttpRequestOptions Encode() - { - StringBuilder sb = new StringBuilder(128); - XmlWriter writer = CreateWriter(sb); - - WriteFullElement(writer, "NewPortMappingIndex", index.ToString()); - - writer.Flush(); - return CreateRequest("GetGenericPortMappingEntry", sb.ToString()); - } - - public override System.Net.WebRequest Encode(out byte[] body) - { - StringBuilder sb = new StringBuilder(128); - XmlWriter writer = CreateWriter(sb); - - WriteFullElement(writer, "NewPortMappingIndex", index.ToString()); - - writer.Flush(); - return CreateRequest("GetGenericPortMappingEntry", sb.ToString(), out body); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/Requests/GetSpecificPortMappingEntryMessage.cs b/Mono.Nat/Upnp/Messages/Requests/GetSpecificPortMappingEntryMessage.cs deleted file mode 100644 index 3e6bac2a8e..0000000000 --- a/Mono.Nat/Upnp/Messages/Requests/GetSpecificPortMappingEntryMessage.cs +++ /dev/null @@ -1,74 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; -using System.Net; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class GetSpecificPortMappingEntryMessage : MessageBase - { - internal Protocol protocol; - internal int externalPort; - - public GetSpecificPortMappingEntryMessage(Protocol protocol, int externalPort, UpnpNatDevice device) - : base(device) - { - this.protocol = protocol; - this.externalPort = externalPort; - } - - public override WebRequest Encode(out byte[] body) - { - StringBuilder sb = new StringBuilder(64); - XmlWriter writer = CreateWriter(sb); - - WriteFullElement(writer, "NewRemoteHost", string.Empty); - WriteFullElement(writer, "NewExternalPort", externalPort.ToString()); - WriteFullElement(writer, "NewProtocol", protocol == Protocol.Tcp ? "TCP" : "UDP"); - writer.Flush(); - - return CreateRequest("GetSpecificPortMappingEntry", sb.ToString(), out body); - } - - public override HttpRequestOptions Encode() - { - StringBuilder sb = new StringBuilder(64); - XmlWriter writer = CreateWriter(sb); - - WriteFullElement(writer, "NewRemoteHost", string.Empty); - WriteFullElement(writer, "NewExternalPort", externalPort.ToString()); - WriteFullElement(writer, "NewProtocol", protocol == Protocol.Tcp ? "TCP" : "UDP"); - writer.Flush(); - - return CreateRequest("GetSpecificPortMappingEntry", sb.ToString()); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/Responses/CreatePortMappingResponseMessage.cs b/Mono.Nat/Upnp/Messages/Responses/CreatePortMappingResponseMessage.cs index b8128f0b54..48776dd6f9 100644 --- a/Mono.Nat/Upnp/Messages/Responses/CreatePortMappingResponseMessage.cs +++ b/Mono.Nat/Upnp/Messages/Responses/CreatePortMappingResponseMessage.cs @@ -44,10 +44,5 @@ namespace Mono.Nat.Upnp { throw new NotImplementedException(); } - - public override System.Net.WebRequest Encode(out byte[] body) - { - throw new NotImplementedException(); - } } } diff --git a/Mono.Nat/Upnp/Messages/Responses/DeletePortMappingResponseMessage.cs b/Mono.Nat/Upnp/Messages/Responses/DeletePortMappingResponseMessage.cs deleted file mode 100644 index 69d32126ad..0000000000 --- a/Mono.Nat/Upnp/Messages/Responses/DeletePortMappingResponseMessage.cs +++ /dev/null @@ -1,51 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - - - -using System; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class DeletePortMapResponseMessage : MessageBase - { - public DeletePortMapResponseMessage() - :base(null) - { - } - - public override HttpRequestOptions Encode() - { - throw new NotSupportedException(); - } - - public override System.Net.WebRequest Encode(out byte[] body) - { - throw new NotSupportedException(); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/Responses/GetExternalIPAddressResponseMessage.cs b/Mono.Nat/Upnp/Messages/Responses/GetExternalIPAddressResponseMessage.cs deleted file mode 100644 index 201296556f..0000000000 --- a/Mono.Nat/Upnp/Messages/Responses/GetExternalIPAddressResponseMessage.cs +++ /dev/null @@ -1,59 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; -using System.Net; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class GetExternalIPAddressResponseMessage : MessageBase - { - public IPAddress ExternalIPAddress - { - get { return this.externalIPAddress; } - } - private IPAddress externalIPAddress; - - public GetExternalIPAddressResponseMessage(string ip) - :base(null) - { - this.externalIPAddress = IPAddress.Parse(ip); - } - - public override HttpRequestOptions Encode() - { - throw new NotImplementedException(); - } - - public override WebRequest Encode(out byte[] body) - { - throw new NotImplementedException(); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/Responses/GetGenericPortMappingEntryResponseMessage.cs b/Mono.Nat/Upnp/Messages/Responses/GetGenericPortMappingEntryResponseMessage.cs deleted file mode 100644 index 51584cc7e3..0000000000 --- a/Mono.Nat/Upnp/Messages/Responses/GetGenericPortMappingEntryResponseMessage.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -// Authors: -// Alan McGovern alan.mcgovern@gmail.com -// -// Copyright (C) 2006 Alan McGovern -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.Text; -using System.Xml; -using MediaBrowser.Common.Net; - -namespace Mono.Nat.Upnp -{ - internal class GetGenericPortMappingEntryResponseMessage : MessageBase - { - private string remoteHost; - private int externalPort; - private Protocol protocol; - private int internalPort; - private string internalClient; - private bool enabled; - private string portMappingDescription; - private int leaseDuration; - - public string RemoteHost - { - get { return this.remoteHost; } - } - - public int ExternalPort - { - get { return this.externalPort; } - } - - public Protocol Protocol - { - get { return this.protocol; } - } - - public int InternalPort - { - get { return this.internalPort; } - } - - public string InternalClient - { - get { return this.internalClient; } - } - - public bool Enabled - { - get { return this.enabled; } - } - - public string PortMappingDescription - { - get { return this.portMappingDescription; } - } - - public int LeaseDuration - { - get { return this.leaseDuration; } - } - - - public GetGenericPortMappingEntryResponseMessage(XmlNode data, bool genericMapping) - : base(null) - { - remoteHost = (genericMapping) ? data["NewRemoteHost"].InnerText : string.Empty; - externalPort = (genericMapping) ? Convert.ToInt32(data["NewExternalPort"].InnerText) : -1; - if (genericMapping) - protocol = data["NewProtocol"].InnerText.Equals("TCP", StringComparison.InvariantCultureIgnoreCase) ? Protocol.Tcp : Protocol.Udp; - else - protocol = Protocol.Udp; - - internalPort = Convert.ToInt32(data["NewInternalPort"].InnerText); - internalClient = data["NewInternalClient"].InnerText; - enabled = data["NewEnabled"].InnerText == "1" ? true : false; - portMappingDescription = data["NewPortMappingDescription"].InnerText; - leaseDuration = Convert.ToInt32(data["NewLeaseDuration"].InnerText); - } - - public override HttpRequestOptions Encode() - { - throw new NotImplementedException(); - } - - public override System.Net.WebRequest Encode(out byte[] body) - { - throw new NotImplementedException(); - } - } -} diff --git a/Mono.Nat/Upnp/Messages/UpnpMessage.cs b/Mono.Nat/Upnp/Messages/UpnpMessage.cs index 11e4462773..54cca44947 100644 --- a/Mono.Nat/Upnp/Messages/UpnpMessage.cs +++ b/Mono.Nat/Upnp/Messages/UpnpMessage.cs @@ -45,33 +45,6 @@ namespace Mono.Nat.Upnp this.device = device; } - protected WebRequest CreateRequest(string upnpMethod, string methodParameters, out byte[] body) - { - string ss = "http://" + this.device.HostEndPoint.ToString() + this.device.ControlUrl; - NatUtility.Log("Initiating request to: {0}", ss); - Uri location = new Uri(ss); - - HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(location); - req.KeepAlive = false; - req.Method = "POST"; - req.ContentType = "text/xml; charset=\"utf-8\""; - req.Headers.Add("SOAPACTION", "\"" + device.ServiceType + "#" + upnpMethod + "\""); - - string bodyString = "<s:Envelope " - + "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " - + "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" - + "<s:Body>" - + "<u:" + upnpMethod + " " - + "xmlns:u=\"" + device.ServiceType + "\">" - + methodParameters - + "</u:" + upnpMethod + ">" - + "</s:Body>" - + "</s:Envelope>\r\n\r\n"; - - body = System.Text.Encoding.UTF8.GetBytes(bodyString); - return req; - } - protected HttpRequestOptions CreateRequest(string upnpMethod, string methodParameters) { string ss = "http://" + this.device.HostEndPoint.ToString() + this.device.ControlUrl; @@ -98,50 +71,7 @@ namespace Mono.Nat.Upnp return req; } - public static MessageBase Decode(UpnpNatDevice device, string message) - { - XmlNode node; - XmlDocument doc = new XmlDocument(); - doc.LoadXml(message); - - XmlNamespaceManager nsm = new XmlNamespaceManager(doc.NameTable); - - // Error messages should be found under this namespace - nsm.AddNamespace("errorNs", "urn:schemas-upnp-org:control-1-0"); - nsm.AddNamespace("responseNs", device.ServiceType); - - // Check to see if we have a fault code message. - if ((node = doc.SelectSingleNode("//errorNs:UPnPError", nsm)) != null) { - string errorCode = node["errorCode"] != null ? node["errorCode"].InnerText : ""; - string errorDescription = node["errorDescription"] != null ? node["errorDescription"].InnerText : ""; - - return new ErrorMessage(Convert.ToInt32(errorCode, CultureInfo.InvariantCulture), errorDescription); - } - - if ((doc.SelectSingleNode("//responseNs:AddPortMappingResponse", nsm)) != null) - return new CreatePortMappingResponseMessage(); - - if ((doc.SelectSingleNode("//responseNs:DeletePortMappingResponse", nsm)) != null) - return new DeletePortMapResponseMessage(); - - if ((node = doc.SelectSingleNode("//responseNs:GetExternalIPAddressResponse", nsm)) != null) { - string newExternalIPAddress = node["NewExternalIPAddress"] != null ? node["NewExternalIPAddress"].InnerText : ""; - return new GetExternalIPAddressResponseMessage(newExternalIPAddress); - } - - if ((node = doc.SelectSingleNode("//responseNs:GetGenericPortMappingEntryResponse", nsm)) != null) - return new GetGenericPortMappingEntryResponseMessage(node, true); - - if ((node = doc.SelectSingleNode("//responseNs:GetSpecificPortMappingEntryResponse", nsm)) != null) - return new GetGenericPortMappingEntryResponseMessage(node, false); - - NatUtility.Log("Unknown message returned. Please send me back the following XML:"); - NatUtility.Log(message); - return null; - } - public abstract HttpRequestOptions Encode(); - public abstract WebRequest Encode(out byte[] body); public virtual string Method { |
