-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Open Connectivity Foundation DCPs
- Loading branch information
Showing
14 changed files
with
6,425 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.zip | ||
*.sublime-workspace | ||
*.sublime-workspace | ||
*.download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gen: | ||
(cd cmd/goupnpdcpgen/; go install); go generate ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,107 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
// DCP contains extra metadata to use when generating DCP source files. | ||
type DCPMetadata struct { | ||
Name string // What to name the Go DCP package. | ||
OfficialName string // Official name for the DCP. | ||
DocURL string // Optional - URL for further documentation about the DCP. | ||
XMLSpecURL string // Where to download the XML spec from. | ||
// Any special-case functions to run against the DCP before writing it out. | ||
Hacks []DCPHackFn | ||
Src dcpProvider | ||
} | ||
|
||
var dcpMetadata = []DCPMetadata{ | ||
{ | ||
Name: "internetgateway1", | ||
OfficialName: "Internet Gateway Device v1", | ||
DocURL: "http://upnp.org/specs/gw/UPnP-gw-InternetGatewayDevice-v1-Device.pdf", | ||
XMLSpecURL: "http://upnp.org/specs/gw/UPnP-gw-IGD-TestFiles-20010921.zip", | ||
Hacks: []DCPHackFn{totalBytesHack}, | ||
Src: upnpdotorg{ | ||
DocURL: "http://upnp.org/specs/gw/UPnP-gw-InternetGatewayDevice-v1-Device.pdf", | ||
XMLSpecURL: "http://upnp.org/specs/gw/UPnP-gw-IGD-TestFiles-20010921.zip", | ||
Hacks: []DCPHackFn{totalBytesHack}, | ||
}, | ||
}, | ||
{ | ||
Name: "internetgateway2", | ||
OfficialName: "Internet Gateway Device v2", | ||
DocURL: "http://upnp.org/specs/gw/UPnP-gw-InternetGatewayDevice-v2-Device.pdf", | ||
XMLSpecURL: "http://upnp.org/specs/gw/UPnP-gw-IGD-Testfiles-20110224.zip", | ||
Hacks: []DCPHackFn{ | ||
func(dcp *DCP) error { | ||
missingURN := "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1" | ||
if _, ok := dcp.ServiceTypes[missingURN]; ok { | ||
return nil | ||
} | ||
urnParts, err := extractURNParts(missingURN, serviceURNPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
dcp.ServiceTypes[missingURN] = urnParts | ||
return nil | ||
}, totalBytesHack, | ||
Src: upnpdotorg{ | ||
DocURL: "http://upnp.org/specs/gw/UPnP-gw-InternetGatewayDevice-v2-Device.pdf", | ||
XMLSpecURL: "http://upnp.org/specs/gw/UPnP-gw-IGD-Testfiles-20110224.zip", | ||
Hacks: []DCPHackFn{ | ||
fixMissingURN("urn:schemas-upnp-org:service:WANIPv6FirewallControl:1"), | ||
totalBytesHack, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "av1", | ||
OfficialName: "MediaServer v1 and MediaRenderer v1", | ||
DocURL: "http://upnp.org/specs/av/av1/", | ||
XMLSpecURL: "http://upnp.org/specs/av/UPnP-av-TestFiles-20070927.zip", | ||
Src: upnpdotorg{ | ||
DocURL: "http://upnp.org/specs/av/av1/", | ||
XMLSpecURL: "http://upnp.org/specs/av/UPnP-av-TestFiles-20070927.zip", | ||
}, | ||
}, | ||
{ | ||
Name: "ocf/internetgateway1", | ||
OfficialName: "Internet Gateway Device v1 - Open Connectivity Foundation", | ||
Src: openconnectivitydotorg{ | ||
SpecsURL: ocfSpecsURL, | ||
DocPath: "*/DeviceProtection_1/UPnP-gw-*v1*.pdf", | ||
XMLSpecZipPath: "*/DeviceProtection_1/UPnP-gw-IGD-TestFiles-*.zip", | ||
XMLServicePath: []string{"*/service/*1.xml"}, | ||
XMLDevicePath: []string{"*/device/*1.xml"}, | ||
Hacks: []DCPHackFn{ | ||
fixMissingURN("urn:schemas-upnp-org:service:DeviceProtection:1"), | ||
fixMissingURN("urn:schemas-upnp-org:service:WANIPv6FirewallControl:1"), | ||
totalBytesHack, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "ocf/internetgateway2", | ||
OfficialName: "Internet Gateway Device v2 - Open Connectivity Foundation", | ||
Src: openconnectivitydotorg{ | ||
SpecsURL: ocfSpecsURL, | ||
DocPath: "*/Internet Gateway_2/UPnP-gw-*.pdf", | ||
XMLSpecZipPath: "*/Internet Gateway_2/UPnP-gw-IGD-TestFiles-*.zip", | ||
XMLServicePath: []string{"*/service/*1.xml", "*/service/*2.xml"}, | ||
XMLDevicePath: []string{"*/device/*1.xml", "*/device/*2.xml"}, | ||
Hacks: []DCPHackFn{ | ||
fixMissingURN("urn:schemas-upnp-org:service:DeviceProtection:1"), | ||
totalBytesHack, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func totalBytesHack(dcp *DCP) error { | ||
for _, service := range dcp.Services { | ||
if service.URN == "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" { | ||
variables := service.SCPD.StateVariables | ||
for key, variable := range variables { | ||
varName := variable.Name | ||
if varName == "TotalBytesSent" || varName == "TotalBytesReceived" { | ||
// Fix size of total bytes which is by default ui4 or maximum 4 GiB. | ||
variable.DataType.Name = "ui8" | ||
variables[key] = variable | ||
} | ||
variables := service.SCPD.StateVariables | ||
for key, variable := range variables { | ||
varName := variable.Name | ||
if strings.HasSuffix(varName, "TotalBytesSent") || | ||
strings.HasSuffix(varName, "TotalBytesReceived") { | ||
// Fix size of total bytes which is by default ui4 or maximum 4 GiB. | ||
variable.DataType.Name = "ui8" | ||
variables[key] = variable | ||
} | ||
|
||
break | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func fixMissingURN(missingURN string) func(dcp *DCP) error { | ||
return func(dcp *DCP) error { | ||
if _, ok := dcp.ServiceTypes[missingURN]; ok { | ||
return nil | ||
} | ||
urnParts, err := extractURNParts(missingURN, serviceURNPrefix) | ||
if err != nil { | ||
return err | ||
} | ||
dcp.ServiceTypes[missingURN] = urnParts | ||
return nil | ||
} | ||
} | ||
|
||
type DCPHackFn func(*DCP) error |
Oops, something went wrong.