@@ -48,28 +48,29 @@ where
4848}
4949
5050fn parse_control_url_scan_device ( device : & Element ) -> Result < String , SearchError > {
51- let service_list = device. get_child ( "serviceList" ) . ok_or ( SearchError :: InvalidResponse ) ?;
52- let child_elements = service_list. children . iter ( ) . filter_map ( |n| match n {
53- xmltree:: XMLNode :: Element ( e) => Some ( e) ,
54- _ => None ,
55- } ) ;
56- for element in child_elements {
57- if element. name != "service" {
58- continue ;
59- } ;
60- let service_type = match element. get_child ( "serviceType" ) {
61- Some ( e) => e,
62- _ => continue ,
63- } ;
64- let service_type_text = service_type. get_text ( ) . map ( |s| s. into_owned ( ) ) . unwrap_or ( "" . into ( ) ) ;
65- if service_type_text != "urn:schemas-upnp-org:service:WANPPPConnection:1"
66- && service_type_text != "urn:schemas-upnp-org:service:WANIPConnection:1"
67- {
68- continue ;
69- }
70- if let Some ( control_url) = element. get_child ( "controlURL" ) {
71- if let Some ( text) = control_url. get_text ( ) {
72- return Ok ( text. into_owned ( ) ) ;
51+ if let Some ( service_list) = device. get_child ( "serviceList" ) {
52+ let child_elements = service_list. children . iter ( ) . filter_map ( |n| match n {
53+ xmltree:: XMLNode :: Element ( e) => Some ( e) ,
54+ _ => None ,
55+ } ) ;
56+ for element in child_elements {
57+ if element. name != "service" {
58+ continue ;
59+ } ;
60+ let service_type = match element. get_child ( "serviceType" ) {
61+ Some ( e) => e,
62+ _ => continue ,
63+ } ;
64+ let service_type_text = service_type. get_text ( ) . map ( |s| s. into_owned ( ) ) . unwrap_or ( "" . into ( ) ) ;
65+ if service_type_text != "urn:schemas-upnp-org:service:WANPPPConnection:1"
66+ && service_type_text != "urn:schemas-upnp-org:service:WANIPConnection:1"
67+ {
68+ continue ;
69+ }
70+ if let Some ( control_url) = element. get_child ( "controlURL" ) {
71+ if let Some ( text) = control_url. get_text ( ) {
72+ return Ok ( text. into_owned ( ) ) ;
73+ }
7374 }
7475 }
7576 }
@@ -515,3 +516,88 @@ fn test_parse_device2() {
515516 let control_url = result. unwrap ( ) ;
516517 assert_eq ! ( control_url, "/igdupnp/control/WANIPConn1" ) ;
517518}
519+
520+ #[ test]
521+ fn test_parse_device3 ( ) {
522+ let text = r#"<?xml version="1.0" encoding="UTF-8"?>
523+ <root xmlns="urn:schemas-upnp-org:device-1-0">
524+ <specVersion>
525+ <major>1</major>
526+ <minor>0</minor>
527+ </specVersion>
528+ <device xmlns="urn:schemas-upnp-org:device-1-0">
529+ <deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
530+ <friendlyName></friendlyName>
531+ <manufacturer></manufacturer>
532+ <manufacturerURL></manufacturerURL>
533+ <modelDescription></modelDescription>
534+ <modelName></modelName>
535+ <modelNumber></modelNumber>
536+ <serialNumber></serialNumber>
537+ <presentationURL>http://192.168.1.1</presentationURL>
538+ <UDN>uuid:00000000-0000-0000-0000-000000000000</UDN>
539+ <UPC>999999999001</UPC>
540+ <iconList>
541+ <icon>
542+ <mimetype>image/png</mimetype>
543+ <width>16</width>
544+ <height>16</height>
545+ <depth>8</depth>
546+ <url>/ligd.png</url>
547+ </icon>
548+ </iconList>
549+ <deviceList>
550+ <device>
551+ <deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
552+ <friendlyName></friendlyName>
553+ <manufacturer></manufacturer>
554+ <manufacturerURL></manufacturerURL>
555+ <modelDescription></modelDescription>
556+ <modelName></modelName>
557+ <modelNumber></modelNumber>
558+ <modelURL></modelURL>
559+ <serialNumber></serialNumber>
560+ <presentationURL>http://192.168.1.254</presentationURL>
561+ <UDN>uuid:00000000-0000-0000-0000-000000000000</UDN>
562+ <UPC>999999999001</UPC>
563+ <serviceList>
564+ <service>
565+ <serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
566+ <serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
567+ <controlURL>/upnp/control/WANCommonIFC1</controlURL>
568+ <eventSubURL>/upnp/control/WANCommonIFC1</eventSubURL>
569+ <SCPDURL>/332b484d/wancomicfgSCPD.xml</SCPDURL>
570+ </service>
571+ </serviceList>
572+ <deviceList>
573+ <device>
574+ <deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
575+ <friendlyName></friendlyName>
576+ <manufacturer></manufacturer>
577+ <manufacturerURL></manufacturerURL>
578+ <modelDescription></modelDescription>
579+ <modelName></modelName>
580+ <modelNumber></modelNumber>
581+ <modelURL></modelURL>
582+ <serialNumber></serialNumber>
583+ <presentationURL>http://192.168.1.254</presentationURL>
584+ <UDN>uuid:00000000-0000-0000-0000-000000000000</UDN>
585+ <UPC>999999999001</UPC>
586+ <serviceList>
587+ <service>
588+ <serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
589+ <serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
590+ <controlURL>/upnp/control/WANIPConn1</controlURL>
591+ <eventSubURL>/upnp/control/WANIPConn1</eventSubURL>
592+ <SCPDURL>/332b484d/wanipconnSCPD.xml</SCPDURL>
593+ </service>
594+ </serviceList>
595+ </device>
596+ </deviceList>
597+ </device>
598+ </deviceList>
599+ </device>
600+ </root>"# ;
601+
602+ assert_eq ! ( parse_control_url( text. as_bytes( ) ) . unwrap( ) , "/upnp/control/WANIPConn1" ) ;
603+ }
0 commit comments