Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public CreatePortMappingMessage(Mapping mapping, IPAddress localIpAddress, UpnpNatDevice device)
     : base(device)
 {
     this.mapping        = mapping;
     this.localIpAddress = localIpAddress;
 }
Exemplo n.º 3
0
 public DeletePortMappingMessage(Mapping mapping, UpnpNatDevice device)
     : base(device)
 {
     this.mapping = mapping;
 }
Exemplo n.º 4
0
 protected MessageBase(UpnpNatDevice device)
 {
     this.device = device;
 }
Exemplo n.º 5
0
 public GetExternalIPAddressMessage(UpnpNatDevice device)
     : base(device)
 {
 }
 public GetGenericPortMappingEntry(int index, UpnpNatDevice device)
     : base(device)
 {
     this.index = index;
 }
Exemplo n.º 7
0
 public GetSpecificPortMappingEntryMessage(Protocol protocol, int externalPort, UpnpNatDevice device)
     : base(device)
 {
     this.protocol     = protocol;
     this.externalPort = externalPort;
 }