IOTechSystems / onvif

full and enhanced onvif protocol stack in golang.
MIT License
17 stars 12 forks source link

Unable to parse XML containing attribute list #22

Closed ajcasagrande closed 1 year ago

ajcasagrande commented 1 year ago

In xml, an attribute is allowed to be duplicated, thus making it a list. The code in here incorrectly defines this and fails to parse this xml.

Here is one example:

<xs:attribute name="SupportedEAPMethods" type="tt:IntList">
  <xs:annotation>
    <xs:documentation>EAP Methods supported by the device. The int values refer to the <a href="http://www.iana.org/assignments/eap-numbers/eap-numbers.xhtml">IANA EAP Registry</a>.</xs:documentation>
  </xs:annotation>
</xs:attribute>
<xs:simpleType name="IntList">
  <xs:list itemType="xs:int"/>
</xs:simpleType>
<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
    <Header xmlns="http://www.w3.org/2003/05/soap-envelope"></Header>
    <Body xmlns="http://www.w3.org/2003/05/soap-envelope">
        <Content>
            <Capabilities>
                <Network IPFilter="true" ZeroConfiguration="true" IPVersion6="true" DynDNS="true"
                         Dot11Configuration="false" Dot1XConfigurations="0" HostnameFromDHCP="true" NTP="1"
                         DHCPv6="true"></Network>
                <Security TLS1_0="false" TLS1_1="false" TLS1_2="false" OnboardKeyGeneration="false"
                          AccessPolicyConfig="false" DefaultAccessPolicy="true" Dot1X="false" RemoteUserHandling="false"
                          X_509Token="false" SAMLToken="false" KerberosToken="false" UsernameToken="true"
                          HttpDigest="true" RELToken="false" SupportedEAPMethods="0" MaxUsers="32"
                          MaxUserNameLength="32" MaxPasswordLength="16"></Security>
                <System DiscoveryResolve="false" DiscoveryBye="true" RemoteDiscovery="false" SystemBackup="false"
                        SystemLogging="true" FirmwareUpgrade="true" HttpFirmwareUpgrade="true" HttpSystemBackup="false"
                        HttpSystemLogging="false" HttpSupportInformation="false" StorageConfiguration="true"
                        MaxStorageConfigurations="8" GeoLocationEntries="0"></System>
                <Misc></Misc>
            </Capabilities>
        </Content>
    </Body>
</Envelope>

Notice the SupportedEAPMethods="0". So the result should be [0], an array containing 1 item, the value 0.

However, parsing fails:

level=ERROR ts=2023-02-24T01:09:51.624822237Z app=device-onvif-camera source=restrouter.go:168 X-Correlation-ID=6d23a4fc-31f4-4795-9ce0-1532f35c8e5b msg="error reading DeviceResourece DeviceCapabilities for HIKVISION-DS-2DE2A404IW-DE3-099f4000-4d50-11b4-82c8-c06ded544d67 -> failed to execute read command -> failed to create 'GetServiceCapabilities' response for the web service 'Device' -> cannot unmarshal into device.EAPMethodTypes"