public static MessageBase Decode(UpnpNatDevice device, string message) { XmlNode node = null; 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) { return(new ErrorMessage(Convert.ToInt32(node["errorCode"].InnerText, System.Globalization.CultureInfo.InvariantCulture), node["errorDescription"].InnerText)); } if ((node = doc.SelectSingleNode("//responseNs:AddPortMappingResponse", nsm)) != null) { return(new CreatePortMappingResponseMessage()); } if ((node = doc.SelectSingleNode("//responseNs:DeletePortMappingResponse", nsm)) != null) { return(new DeletePortMapResponseMessage()); } if ((node = doc.SelectSingleNode("//responseNs:GetExternalIPAddressResponse", nsm)) != null) { return(new GetExternalIPAddressResponseMessage(node["NewExternalIPAddress"].InnerText)); } 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 CreatePortMappingMessage(Mapping mapping, IPAddress localIpAddress, UpnpNatDevice device) : base(device) { this.mapping = mapping; this.localIpAddress = localIpAddress; }
public DeletePortMappingMessage(Mapping mapping, UpnpNatDevice device) : base(device) { this.mapping = mapping; }
protected MessageBase(UpnpNatDevice device) { this.device = device; }
public GetExternalIPAddressMessage(UpnpNatDevice device) : base(device) { }
public GetGenericPortMappingEntry(int index, UpnpNatDevice device) : base(device) { this.index = index; }
public GetSpecificPortMappingEntryMessage(Protocol protocol, int externalPort, UpnpNatDevice device) : base(device) { this.protocol = protocol; this.externalPort = externalPort; }