summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-25 08:35:33 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-25 09:23:17 (GMT)
commitb33a2937fe4a3cae0017892ad7f5c27b8a6f976d (patch)
tree35d0e88461026b6ca31e3dc7246bc6b8d3100f9f /Swiften/LinkLocal/BonjourResolveServiceQuery.h
parentef4284acb29aca0bdf792ab40356c7955902e307 (diff)
downloadswift-contrib-b33a2937fe4a3cae0017892ad7f5c27b8a6f976d.zip
swift-contrib-b33a2937fe4a3cae0017892ad7f5c27b8a6f976d.tar.bz2
Implement more DNSSD queries.
Diffstat (limited to 'Swiften/LinkLocal/BonjourResolveServiceQuery.h')
-rw-r--r--Swiften/LinkLocal/BonjourResolveServiceQuery.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/Swiften/LinkLocal/BonjourResolveServiceQuery.h b/Swiften/LinkLocal/BonjourResolveServiceQuery.h
new file mode 100644
index 0000000..e4f02ee
--- /dev/null
+++ b/Swiften/LinkLocal/BonjourResolveServiceQuery.h
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "Swiften/LinkLocal/BonjourQuery.h"
+#include "Swiften/LinkLocal/DNSSDResolveServiceQuery.h"
+#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/EventLoop/MainEventLoop.h"
+
+namespace Swift {
+ class BonjourQuerier;
+
+ class BonjourResolveServiceQuery : public DNSSDResolveServiceQuery, public BonjourQuery {
+ public:
+ BonjourResolveServiceQuery(const LinkLocalServiceID& service, boost::shared_ptr<BonjourQuerier> querier) : BonjourQuery(querier) {
+ DNSServiceErrorType result = DNSServiceResolve(
+ &sdRef, 0, service.getNetworkInterfaceID(),
+ service.getName().getUTF8Data(), service.getType().getUTF8Data(),
+ service.getDomain().getUTF8Data(),
+ &BonjourResolveServiceQuery::handleServiceResolvedStatic, this);
+ if (result != kDNSServiceErr_NoError) {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ }
+ }
+
+ void start() {
+ run();
+ }
+
+ void stop() {
+ finish();
+ }
+
+ private:
+ static void handleServiceResolvedStatic(DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context) {
+ static_cast<BonjourResolveServiceQuery*>(context)->handleServiceResolved(errorCode, fullname, hosttarget, port, txtLen, txtRecord);
+ }
+
+ void handleServiceResolved(DNSServiceErrorType errorCode, const char* fullName, const char* host, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord) {
+ if (errorCode != kDNSServiceErr_NoError) {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onServiceResolved), boost::optional<Result>()), shared_from_this());
+ }
+ else {
+ MainEventLoop::postEvent(
+ boost::bind(
+ boost::ref(onServiceResolved),
+ Result(String(fullName), String(host), port,
+ LinkLocalServiceInfo::createFromTXTRecord(
+ ByteArray(reinterpret_cast<const char*>(txtRecord), txtLen)))),
+ shared_from_this());
+ }
+ }
+ };
+}