Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
Implement Windows DNSSD support (still does not work)
Browse files Browse the repository at this point in the history
  • Loading branch information
velitasali committed Apr 10, 2019
1 parent f0184ba commit 56ee8c6
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 26 deletions.
36 changes: 32 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,35 @@ set(UTIL_LIBRARY

if (KF5DNSSD_FOUND)
add_definitions(-DUSE_DNSSD_FEATURE=1)
elseif (WIN32)
add_definitions(-DWIN32)
add_definitions(-DNDEBUG)
add_definitions(-D_WINDOWS)
add_definitions(-D_USRDLL)
add_definitions(-DQT_BUILD_ZEROCONF_LIB)
add_definitions(-DMDNS_DEBUGMSGS=1)
add_definitions(-DWIN32_LEAN_AND_MEAN)
add_definitions(-DUSE_TCP_LOOPBACK)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1)
add_definitions(-DNOT_HAVE_SA_LEN)

set(UTIL_LIBRARY ${UTIL_LIBRARY}
qzeroconf/qzeroconfservice.h
qzeroconf/qzeroconfservice.cpp
qzeroconf/qzeroconfglobal.h
qzeroconf/qzeroconf.h
qzeroconf/bonjour_p.h
qzeroconf/bonjour.cpp
qzeroconf/bonjour-sdk/CommonServices.h
qzeroconf/bonjour-sdk/DebugServices.h
qzeroconf/bonjour-sdk/dns_sd.h
qzeroconf/bonjour-sdk/dnssd_clientlib.c
qzeroconf/bonjour-sdk/dnssd_clientstub.c
qzeroconf/bonjour-sdk/dnssd_ipc.c
qzeroconf/bonjour-sdk/dnssd_ipc.h)
endif ()
# old code was here

add_executable(${PROJECT_EXECUTABLE} src/main.cpp ${UTIL_LIBRARY} ${UI_HEADERS} ${QRCS})

Expand All @@ -182,14 +210,14 @@ if (NOT TARGET Qt5::WinMain)
add_library(Qt5::WinMain STATIC IMPORTED)
endif ()

target_link_libraries(${PROJECT_EXECUTABLE} PUBLIC Qt5::Core Qt5::Gui Qt5::Network Qt5::Sql Qt5::Widgets)

if (KF5DNSSD_FOUND)
target_link_libraries(${PROJECT_EXECUTABLE} PUBLIC KF5::DNSSD)
else ()
add_subdirectory(qzeroconf)
elseif (WIN32)
target_link_libraries(${PROJECT_EXECUTABLE} PUBLIC wsock32 ws2_32)
endif ()

target_link_libraries(${PROJECT_EXECUTABLE} PUBLIC Qt5::Core Qt5::Gui Qt5::Network Qt5::Sql Qt5::Widgets)

fix_win_compiler()

if (NOT WIN32)
Expand Down
13 changes: 0 additions & 13 deletions qzeroconf/CMakeLists.txt

This file was deleted.

Empty file modified qzeroconf/bonjour-sdk/dns_sd.h
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions qzeroconf/bonjour-sdk/dnssd_clientstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ static int gDaemonErr = kDNSServiceErr_NoError;
#if defined(_WIN32)

#define _SSIZE_T
#include <CommonServices.h>
#include <DebugServices.h>
#include <qzeroconf/bonjour-sdk/CommonServices.h>
#include <qzeroconf/bonjour-sdk/DebugServices.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
Expand Down
6 changes: 3 additions & 3 deletions qzeroconf/bonjour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void QZeroConf::startServicePublish(const char *name, const char *type, const ch
DNSServiceErrorType err;

if (pri->dnssRef) {
emit error(QZeroConf::serviceRegistrationFailed);
emit error(QZeroConf::registrationRefError);
return;
}

Expand All @@ -298,7 +298,7 @@ void QZeroConf::startServicePublish(const char *name, const char *type, const ch
int sockfd = DNSServiceRefSockFD(pri->dnssRef);
if (sockfd == -1) {
pri->cleanUp(pri->dnssRef);
emit error(QZeroConf::serviceRegistrationFailed);
emit error(QZeroConf::registrationSockFdError);
}
else {
pri->bs = new QSocketNotifier(sockfd, QSocketNotifier::Read, this);
Expand All @@ -307,7 +307,7 @@ void QZeroConf::startServicePublish(const char *name, const char *type, const ch
}
else {
pri->cleanUp(pri->dnssRef);
emit error(QZeroConf::serviceRegistrationFailed);
emit error((error_t) err);
}
}

Expand Down
2 changes: 1 addition & 1 deletion qzeroconf/bonjour_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifndef QZEROCONFPRIVATE_H_
#define QZEROCONFPRIVATE_H_

#include <dns_sd.h>
#include <qzeroconf/bonjour-sdk/dns_sd.h>
#include <QSocketNotifier>
#include <QtEndian>
#include <QHostAddress>
Expand Down
2 changes: 2 additions & 0 deletions qzeroconf/qzeroconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ friend class QZeroConfPrivate;
serviceRegistrationFailed = -1,
serviceNameCollision = -2,
browserFailed = -3,
registrationRefError = -4,
registrationSockFdError = -5
};
QZeroConf(QObject *parent = Q_NULLPTR);
~QZeroConf();
Expand Down
26 changes: 24 additions & 2 deletions src/broadcast/DNSSDService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,30 @@ void DNSSDService::start()

#else
DNSSDService::DNSSDService(QObject *parent) : QObject(parent)
{}
{
connect(&m_zeroConf, &QZeroConf::error, this, &DNSSDService::error);
connect(&m_zeroConf, &QZeroConf::serviceAdded, this, &DNSSDService::serviceAdded);
m_zeroConf.addServiceTxtRecord("socket_URL", "{host}:{port}");
}

DNSSDService::~DNSSDService() {
m_zeroConf.stopServicePublish();
m_zeroConf.stopBrowser();
}

void DNSSDService::error(QZeroConf::error_t error) {
qDebug() << this << error;
}

void DNSSDService::start()
{}
{
m_zeroConf.startServicePublish(TS_SERVICE_NAME, TS_SERVICE_TYPE, nullptr, PORT_COMMUNICATION_DEFAULT);
m_zeroConf.startBrowser(TS_SERVICE_TYPE);
}

void DNSSDService::serviceAdded(QZeroConfService service)
{
qDebug() << "service added";
}

#endif // USE_DNSSD_FEATURE
13 changes: 12 additions & 1 deletion src/broadcast/DNSSDService.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,26 @@ public slots:
KDNSSD::ServiceBrowser *m_serviceBrowser;
};

#else
#elif defined(QT_BUILD_ZEROCONF_LIB)
#include <QObject>
#include <src/util/NetworkDeviceLoader.h>
#include <qzeroconf/qzeroconf.h>

class DNSSDService : public QObject {
Q_OBJECT

public:
explicit DNSSDService(QObject* parent = nullptr);

~DNSSDService() override;

void error(QZeroConf::error_t error);

void start();

void serviceAdded(QZeroConfService service);

protected:
QZeroConf m_zeroConf;
};
#endif // USE_DNSSD_FEATURE

0 comments on commit 56ee8c6

Please sign in to comment.