From 690dd7a33ddc90678367d73adf313533536e10f2 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Fri, 29 Apr 2016 23:57:30 +0100 Subject: Apply clang-format --- src/modules/upnp/RootService.cpp | 481 +++++++++++++++++++-------------------- 1 file changed, 233 insertions(+), 248 deletions(-) (limited to 'src/modules/upnp/RootService.cpp') diff --git a/src/modules/upnp/RootService.cpp b/src/modules/upnp/RootService.cpp index abf945da8..81cd7b23a 100644 --- a/src/modules/upnp/RootService.cpp +++ b/src/modules/upnp/RootService.cpp @@ -43,274 +43,259 @@ namespace UPnP { - // Example message result: - // - // - // - // 1 - // 0 - // - // http://10.0.0.138 - // - // urn:schemas-upnp-org:device:InternetGatewayDevice:1 - // SpeedTouch 510 (0313QZ6S2) - // THOMSON multimedia - // http://www.thomson-multimedia.com - // DSL Internet Gateway - // SpeedTouch - // 510 - // http://www.speedtouch.com - // 0313QZ6S2 - // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F - // /index.htm - // - // - // urn:schemas-upnp-org:service:Layer3Forwarding:1 - // urn:upnp-org:serviceId:layer3f - // /upnp/control/layer3f - // /upnp/event/layer3f - // /Layer3Forwarding.xml - // - // - // - // - // urn:schemas-upnp-org:device:LANDevice:1 - // LANDevice - // THOMSON multimedia - // SpeedTouch - // 0313QZ6S2 - // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F_LD - // - // - // urn:schemas-upnp-org:service:LANHostConfigManagement:1 - // urn:upnp-org:serviceId:lanhcm - // /upnp/control/lanhcm - // /upnp/event/lanhcm - // /LANHostConfigManagement.xml - // - // - // - // - // urn:schemas-upnp-org:device:WANDevice:1 - // WANDevice - // THOMSON multimedia - // SpeedTouch - // 0313QZ6S2 - // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F_WD - // - // - // urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 - // urn:upnp-org:serviceId:wancic - // /upnp/control/wancic - // /upnp/event/wancic - // /WANCommonInterfaceConfig.xml - // - // - // - // - // urn:schemas-upnp-org:device:WANConnectionDevice:1 - // WANConnectionDevice - // THOMSON multimedia - // SpeedTouch - // 0313QZ6S2 - // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F_WCDpppoa - // - // - // urn:schemas-upnp-org:service:WANDSLLinkConfig:1 - // urn:upnp-org:serviceId:wandsllc:pppoa - // /upnp/control/wandsllcpppoa - // /upnp/event/wandsllcpppoa - // /WANDSLLinkConfig.xml - // - // - // urn:schemas-upnp-org:service:WANPPPConnection:1 - // urn:upnp-org:serviceId:wanpppc:pppoa - // /upnp/control/wanpppcpppoa - // /upnp/event/wanpppcpppoa - // /WANPPPConnection.xml - // - // - // - // - // - // - // - // - - -// The contructor -RootService::RootService(const QString &hostname, int port, const QString &rootUrl) -: Service(hostname, port, rootUrl) -, m_szHostname(hostname) -, m_iPort(port) -{ - -} - - -// The destructor -RootService::~RootService() -{ - -} - - -// Recursively add all devices and embedded devices to the deviceServices_ map -void RootService::addDeviceServices(const QDomNode &device) -{ - qDebug() << "UPnP discovered device " << XmlFunctions::getNodeValue(device, "/UDN") << endl; - - if(XmlFunctions::getNodeValue(device, "/deviceType") == InternetGatewayDeviceType) + // Example message result: + // + // + // + // 1 + // 0 + // + // http://10.0.0.138 + // + // urn:schemas-upnp-org:device:InternetGatewayDevice:1 + // SpeedTouch 510 (0313QZ6S2) + // THOMSON multimedia + // http://www.thomson-multimedia.com + // DSL Internet Gateway + // SpeedTouch + // 510 + // http://www.speedtouch.com + // 0313QZ6S2 + // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F + // /index.htm + // + // + // urn:schemas-upnp-org:service:Layer3Forwarding:1 + // urn:upnp-org:serviceId:layer3f + // /upnp/control/layer3f + // /upnp/event/layer3f + // /Layer3Forwarding.xml + // + // + // + // + // urn:schemas-upnp-org:device:LANDevice:1 + // LANDevice + // THOMSON multimedia + // SpeedTouch + // 0313QZ6S2 + // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F_LD + // + // + // urn:schemas-upnp-org:service:LANHostConfigManagement:1 + // urn:upnp-org:serviceId:lanhcm + // /upnp/control/lanhcm + // /upnp/event/lanhcm + // /LANHostConfigManagement.xml + // + // + // + // + // urn:schemas-upnp-org:device:WANDevice:1 + // WANDevice + // THOMSON multimedia + // SpeedTouch + // 0313QZ6S2 + // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F_WD + // + // + // urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1 + // urn:upnp-org:serviceId:wancic + // /upnp/control/wancic + // /upnp/event/wancic + // /WANCommonInterfaceConfig.xml + // + // + // + // + // urn:schemas-upnp-org:device:WANConnectionDevice:1 + // WANConnectionDevice + // THOMSON multimedia + // SpeedTouch + // 0313QZ6S2 + // uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F_WCDpppoa + // + // + // urn:schemas-upnp-org:service:WANDSLLinkConfig:1 + // urn:upnp-org:serviceId:wandsllc:pppoa + // /upnp/control/wandsllcpppoa + // /upnp/event/wandsllcpppoa + // /WANDSLLinkConfig.xml + // + // + // urn:schemas-upnp-org:service:WANPPPConnection:1 + // urn:upnp-org:serviceId:wanpppc:pppoa + // /upnp/control/wanpppcpppoa + // /upnp/event/wanpppcpppoa + // /WANPPPConnection.xml + // + // + // + // + // + // + // + // + + // The contructor + RootService::RootService(const QString & hostname, int port, const QString & rootUrl) + : Service(hostname, port, rootUrl), m_szHostname(hostname), m_iPort(port) { - QString description; - description = XmlFunctions::getNodeValue(device, "/friendlyName"); - if(description.isNull()) - description = XmlFunctions::getNodeValue(device, "/modelDescription"); - if(description.isNull()) - description = XmlFunctions::getNodeValue(device, "/modelName") + " " + XmlFunctions::getNodeValue(device, "/modelNumber"); - if(description.isNull()) - description = __tr2qs("Unknown"); - - qDebug() << "Model: " << description << endl; - - g_pApp->activeConsole()->output(KVI_OUT_GENERICSTATUS,__tr2qs_ctx("[UPNP]: found gateway device: %s","upnp"), description.toUtf8().data()); - - } - // Insert the given device node - // The "key" is the device/UDN tag, the value is a list of device/serviceList/service nodes - m_deviceServices.insert(XmlFunctions::getNodeValue(device, "/UDN"), - device.namedItem("serviceList").childNodes()); - // Find all embedded device nodes - QDomNodeList embeddedDevices = device.namedItem("deviceList").childNodes(); - for(int i = 0; i < embeddedDevices.count(); i++) + // The destructor + RootService::~RootService() { - if(embeddedDevices.item(i).nodeName() != "device") continue; - addDeviceServices(embeddedDevices.item(i)); } -} - - - -// Return the device type -QString RootService::getDeviceType() const -{ - return m_szDeviceType; -} - -// Return a service from the cached root device entry -ServiceParameters RootService::getServiceById(const QString &serviceId) const -{ - // Get a /root/device/serviceList/service/ tag - - ServiceParameters params; - QMap::const_iterator i = m_deviceServices.constBegin(); - while (i != m_deviceServices.constEnd()) { - if(getServiceById(serviceId, i.key(), params)) - return params; - ++i; + // Recursively add all devices and embedded devices to the deviceServices_ map + void RootService::addDeviceServices(const QDomNode & device) + { + qDebug() << "UPnP discovered device " << XmlFunctions::getNodeValue(device, "/UDN") << endl; + + if(XmlFunctions::getNodeValue(device, "/deviceType") == InternetGatewayDeviceType) + { + QString description; + description = XmlFunctions::getNodeValue(device, "/friendlyName"); + if(description.isNull()) + description = XmlFunctions::getNodeValue(device, "/modelDescription"); + if(description.isNull()) + description = XmlFunctions::getNodeValue(device, "/modelName") + " " + XmlFunctions::getNodeValue(device, "/modelNumber"); + if(description.isNull()) + description = __tr2qs("Unknown"); + + qDebug() << "Model: " << description << endl; + + g_pApp->activeConsole()->output(KVI_OUT_GENERICSTATUS, __tr2qs_ctx("[UPNP]: found gateway device: %s", "upnp"), description.toUtf8().data()); + } + // Insert the given device node + // The "key" is the device/UDN tag, the value is a list of device/serviceList/service nodes + m_deviceServices.insert(XmlFunctions::getNodeValue(device, "/UDN"), + device.namedItem("serviceList").childNodes()); + + // Find all embedded device nodes + QDomNodeList embeddedDevices = device.namedItem("deviceList").childNodes(); + for(int i = 0; i < embeddedDevices.count(); i++) + { + if(embeddedDevices.item(i).nodeName() != "device") + continue; + addDeviceServices(embeddedDevices.item(i)); + } } - //calling function check this field to understand if the struct is null - params.controlUrl = QString(); - return params; -} - -// Return a service from a cached embedded device entry -bool RootService::getServiceById(const QString &serviceId, const QString &deviceUdn, ServiceParameters ¶ms) const -{ - // Get a /root/device/deviceList/device/.../serviceList/service/serviceId tag - QDomNode service = XmlFunctions::getNodeChildByKey( m_deviceServices[deviceUdn], "serviceId", serviceId ); - - if(! service.isNull()) + // Return the device type + QString RootService::getDeviceType() const { - params.hostname = m_szHostname; - params.port = m_iPort; - params.controlUrl = XmlFunctions::getNodeValue(service, "/controlURL"); - params.scpdUrl = XmlFunctions::getNodeValue(service, "/SCPDURL"); - params.serviceId = XmlFunctions::getNodeValue(service, "/serviceId"); - params.serviceType = XmlFunctions::getNodeValue(service, "/serviceType"); - - return true; - } else { - return false; + return m_szDeviceType; } -} - - -// Return a service from the cached root device entry -ServiceParameters RootService::getServiceByType(const QString &serviceType) const -{ - // Get a /root/device/serviceList/service/ tag - ServiceParameters params; - QMap::const_iterator i = m_deviceServices.constBegin(); - while (i != m_deviceServices.constEnd()) { - if(getServiceByType(serviceType, i.key(), params)) - return params; - ++i; + // Return a service from the cached root device entry + ServiceParameters RootService::getServiceById(const QString & serviceId) const + { + // Get a /root/device/serviceList/service/ tag + + ServiceParameters params; + QMap::const_iterator i = m_deviceServices.constBegin(); + while(i != m_deviceServices.constEnd()) + { + if(getServiceById(serviceId, i.key(), params)) + return params; + ++i; + } + + //calling function check this field to understand if the struct is null + params.controlUrl = QString(); + return params; } - //calling function check this field to understand if the struct is null - params.controlUrl = QString(); - return params; - -} - - - -// Return a service from a cached embedded device entry -bool RootService::getServiceByType(const QString &serviceType, const QString &deviceUdn, ServiceParameters ¶ms) const -{ - // Get a /root/device/deviceList/device/.../serviceList/service/serviceType tag - QDomNode service = XmlFunctions::getNodeChildByKey( m_deviceServices[deviceUdn], "serviceType", serviceType ); - - if(! service.isNull()) + // Return a service from a cached embedded device entry + bool RootService::getServiceById(const QString & serviceId, const QString & deviceUdn, ServiceParameters & params) const { - params.hostname = m_szHostname; - params.port = m_iPort; - params.controlUrl = XmlFunctions::getNodeValue(service, "/controlURL"); - params.scpdUrl = XmlFunctions::getNodeValue(service, "/SCPDURL"); - params.serviceId = XmlFunctions::getNodeValue(service, "/serviceId"); - params.serviceType = serviceType; - - return true; - } else { - qWarning() << "UPnP::RootService::getServiceByType -" - << " type '" << serviceType << "' not found for device '" << deviceUdn << "'." << endl; - - return false; + // Get a /root/device/deviceList/device/.../serviceList/service/serviceId tag + QDomNode service = XmlFunctions::getNodeChildByKey(m_deviceServices[deviceUdn], "serviceId", serviceId); + + if(!service.isNull()) + { + params.hostname = m_szHostname; + params.port = m_iPort; + params.controlUrl = XmlFunctions::getNodeValue(service, "/controlURL"); + params.scpdUrl = XmlFunctions::getNodeValue(service, "/SCPDURL"); + params.serviceId = XmlFunctions::getNodeValue(service, "/serviceId"); + params.serviceType = XmlFunctions::getNodeValue(service, "/serviceType"); + + return true; + } + else + { + return false; + } } -} - + // Return a service from the cached root device entry + ServiceParameters RootService::getServiceByType(const QString & serviceType) const + { + // Get a /root/device/serviceList/service/ tag + + ServiceParameters params; + QMap::const_iterator i = m_deviceServices.constBegin(); + while(i != m_deviceServices.constEnd()) + { + if(getServiceByType(serviceType, i.key(), params)) + return params; + ++i; + } + + //calling function check this field to understand if the struct is null + params.controlUrl = QString(); + return params; + } -// The control point received a response to callInformationUrl() -void RootService::gotInformationResponse(const QDomNode &response) -{ - // Register all device UDN nodes for later - m_deviceServices.clear(); - addDeviceServices( XmlFunctions::getNode(response, "/device") ); - - // Fetch the required data - m_szDeviceType = XmlFunctions::getNodeValue(response, "/device/deviceType"); - m_szRootUdn = XmlFunctions::getNodeValue(response, "/device/UDN"); - - // The rootUdn_ is used to retrieve - // the /root/device/serviceList/service - // nodes from the deviceServices_ map -} - + // Return a service from a cached embedded device entry + bool RootService::getServiceByType(const QString & serviceType, const QString & deviceUdn, ServiceParameters & params) const + { + // Get a /root/device/deviceList/device/.../serviceList/service/serviceType tag + QDomNode service = XmlFunctions::getNodeChildByKey(m_deviceServices[deviceUdn], "serviceType", serviceType); + + if(!service.isNull()) + { + params.hostname = m_szHostname; + params.port = m_iPort; + params.controlUrl = XmlFunctions::getNodeValue(service, "/controlURL"); + params.scpdUrl = XmlFunctions::getNodeValue(service, "/SCPDURL"); + params.serviceId = XmlFunctions::getNodeValue(service, "/serviceId"); + params.serviceType = serviceType; + + return true; + } + else + { + qWarning() << "UPnP::RootService::getServiceByType -" + << " type '" << serviceType << "' not found for device '" << deviceUdn << "'." << endl; + + return false; + } + } + // The control point received a response to callInformationUrl() + void RootService::gotInformationResponse(const QDomNode & response) + { + // Register all device UDN nodes for later + m_deviceServices.clear(); + addDeviceServices(XmlFunctions::getNode(response, "/device")); -// Query the device for its service list -void RootService::queryDevice() -{ - callInformationUrl(); -} + // Fetch the required data + m_szDeviceType = XmlFunctions::getNodeValue(response, "/device/deviceType"); + m_szRootUdn = XmlFunctions::getNodeValue(response, "/device/UDN"); + // The rootUdn_ is used to retrieve + // the /root/device/serviceList/service + // nodes from the deviceServices_ map + } + // Query the device for its service list + void RootService::queryDevice() + { + callInformationUrl(); + } } // end of namespae -- cgit v1.3.1-10-gc9f91