aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/upnp/SsdpConnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/upnp/SsdpConnection.cpp')
-rw-r--r--src/modules/upnp/SsdpConnection.cpp164
1 files changed, 79 insertions, 85 deletions
diff --git a/src/modules/upnp/SsdpConnection.cpp b/src/modules/upnp/SsdpConnection.cpp
index 7440d10d1..11a316ce6 100644
--- a/src/modules/upnp/SsdpConnection.cpp
+++ b/src/modules/upnp/SsdpConnection.cpp
@@ -43,110 +43,104 @@
namespace UPnP
{
-SsdpConnection::SsdpConnection()
-: QObject()
-{
- m_pSocket = new QUdpSocket();
- connect(m_pSocket, SIGNAL(readyRead()), this, SLOT(slotDataReceived()));
-}
-
-SsdpConnection::~SsdpConnection()
-{
- if(m_pSocket != 0)
+ SsdpConnection::SsdpConnection()
+ : QObject()
{
- m_pSocket->close();
- delete m_pSocket;
+ m_pSocket = new QUdpSocket();
+ connect(m_pSocket, SIGNAL(readyRead()), this, SLOT(slotDataReceived()));
}
-}
-
-
-// Data was received by the socket
-void SsdpConnection::slotDataReceived()
-{
- qDebug() << "UPnP::SsdpConnection: received " << m_pSocket->bytesAvailable() << " bytes." << endl;
-
- // Response from Diederik's Acatel router:
- //
- // HTTP/1.1 200 OK
- // CACHE-CONTROL:max-age=1800
- // EXT:
- // LOCATION:http://10.0.0.138:80/IGD.xml
- // SERVER:SpeedTouch 510 4.0.2.0.0 UPnP/1.0 (0313QZ6S2)
- // ST:upnp:rootdevice
- // USN:uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F::upnp:rootdevice
- //
+ SsdpConnection::~SsdpConnection()
+ {
+ if(m_pSocket != 0)
+ {
+ m_pSocket->close();
+ delete m_pSocket;
+ }
+ }
- // This is from a Zyxel router:
- //
- // HTTP/1.1 200 OK
- // ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1
- // USN:uuid:11111111-%04x-c0a8-fcb30002cf618c::urn:schemas-upnp-org:device:InternetGatewayDevice:1
- // Location:http://192.168.252.179:80/DeviceDescription.xml
- // Cache-Control: max-age=480
- // Server: ZyXEL-RomPlug/4.51 UPnP/1.0 IGD/1.00
- // Ext:
+ // Data was received by the socket
+ void SsdpConnection::slotDataReceived()
+ {
+ qDebug() << "UPnP::SsdpConnection: received " << m_pSocket->bytesAvailable() << " bytes." << endl;
- while (m_pSocket->hasPendingDatagrams()) {
- QByteArray datagram;
- datagram.resize(m_pSocket->pendingDatagramSize());
- m_pSocket->readDatagram(datagram.data(), datagram.size());
+ // Response from Diederik's Acatel router:
+ //
+ // HTTP/1.1 200 OK
+ // CACHE-CONTROL:max-age=1800
+ // EXT:
+ // LOCATION:http://10.0.0.138:80/IGD.xml
+ // SERVER:SpeedTouch 510 4.0.2.0.0 UPnP/1.0 (0313QZ6S2)
+ // ST:upnp:rootdevice
+ // USN:uuid:UPnP-SpeedTouch510-1_00-90-D0-8E-A1-6F::upnp:rootdevice
+ //
- qDebug("Received datagram: %s\n",datagram.data());
+ // This is from a Zyxel router:
+ //
+ // HTTP/1.1 200 OK
+ // ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1
+ // USN:uuid:11111111-%04x-c0a8-fcb30002cf618c::urn:schemas-upnp-org:device:InternetGatewayDevice:1
+ // Location:http://192.168.252.179:80/DeviceDescription.xml
+ // Cache-Control: max-age=480
+ // Server: ZyXEL-RomPlug/4.51 UPnP/1.0 IGD/1.00
+ // Ext:
- QString sspdResponse = QString::fromUtf8(datagram.data(), datagram.size());
+ while(m_pSocket->hasPendingDatagrams())
+ {
+ QByteArray datagram;
+ datagram.resize(m_pSocket->pendingDatagramSize());
+ m_pSocket->readDatagram(datagram.data(), datagram.size());
- // Find the location field manually, MimeMessage is not required
- int locationStart = sspdResponse.indexOf("LOCATION:",0,Qt::CaseInsensitive);
- int locationEnd = sspdResponse.indexOf("\r\n",locationStart,Qt::CaseSensitive);
+ qDebug("Received datagram: %s\n", datagram.data());
- locationStart += 9; // length of field name
- QString location = sspdResponse.mid(locationStart, locationEnd - locationStart);
+ QString sspdResponse = QString::fromUtf8(datagram.data(), datagram.size());
- // Parse the URL syntax using KURL
- QUrl url(location.trimmed());
+ // Find the location field manually, MimeMessage is not required
+ int locationStart = sspdResponse.indexOf("LOCATION:", 0, Qt::CaseInsensitive);
+ int locationEnd = sspdResponse.indexOf("\r\n", locationStart, Qt::CaseSensitive);
- qDebug("Found internet gateway: %s\n", location.toUtf8().data());
- // Emit success
- emit deviceFound(url.host(), url.port(), url.path());
+ locationStart += 9; // length of field name
+ QString location = sspdResponse.mid(locationStart, locationEnd - locationStart);
+ // Parse the URL syntax using KURL
+ QUrl url(location.trimmed());
+ qDebug("Found internet gateway: %s\n", location.toUtf8().data());
+ // Emit success
+ emit deviceFound(url.host(), url.port(), url.path());
+ }
}
-}
+ // Send a broadcast to detect all devices
+ void SsdpConnection::queryDevices(int bindPort)
+ {
+ qDebug() << "UPnP::SsdpConnection: sending broadcast packet." << endl;
-// Send a broadcast to detect all devices
-void SsdpConnection::queryDevices(int bindPort)
-{
- qDebug() << "UPnP::SsdpConnection: sending broadcast packet." << endl;
+ // Send a packet to a broadcast address
+ QHostAddress address("239.255.255.250");
- // Send a packet to a broadcast address
- QHostAddress address("239.255.255.250");
+ QString data = "M-SEARCH * HTTP/1.1\r\n"
+ "Host:239.255.255.250:1900\r\n"
+ "ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n"
+ "Man:\"ssdp:discover\"\r\n"
+ "MX:3\r\n"
+ "\r\n";
- QString data = "M-SEARCH * HTTP/1.1\r\n"
- "Host:239.255.255.250:1900\r\n"
- "ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n"
- "Man:\"ssdp:discover\"\r\n"
- "MX:3\r\n"
- "\r\n";
+ // Bind the socket to a certain port
+ bool success = m_pSocket->bind(bindPort);
+ if(!success)
+ {
+ qDebug() << "UPnP::SsdpConnection: failed to bind to port " << bindPort << "." << endl;
+ }
- // Bind the socket to a certain port
- bool success = m_pSocket->bind(bindPort);
- if(! success)
- {
- qDebug() << "UPnP::SsdpConnection: failed to bind to port " << bindPort << "." << endl;
- }
+ // Send the data
+ QByteArray dataBlock = data.toUtf8();
+ int bytesWritten = m_pSocket->writeDatagram(dataBlock.data(), dataBlock.size(), address, 1900);
- // Send the data
- QByteArray dataBlock = data.toUtf8();
- int bytesWritten = m_pSocket->writeDatagram(dataBlock.data(), dataBlock.size(), address, 1900);
-
- if(bytesWritten == -1)
- {
- qDebug() << "UPnP::SsdpConnection: failed to send the UPnP broadcast packet." << endl;
+ if(bytesWritten == -1)
+ {
+ qDebug() << "UPnP::SsdpConnection: failed to send the UPnP broadcast packet." << endl;
+ }
}
-}
-
-
-} // end of namespace
+} // end of namespace