summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-16 06:49:57 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-16 06:49:57 (GMT)
commit14f7f9f37702635019c46d97f57ee6de8c5c749e (patch)
tree219a9e255bb05c34731eb1f8d6ba79359422b928
parentf061668e3c1d5eac01b85303e2c81df2bc560e9a (diff)
downloadswift-14f7f9f37702635019c46d97f57ee6de8c5c749e.zip
swift-14f7f9f37702635019c46d97f57ee6de8c5c749e.tar.bz2
Added small Nim test program.
-rw-r--r--Makefile3
-rw-r--r--Makefile.config.in1
-rw-r--r--Nim/.gitignore1
-rw-r--r--Nim/Makefile.inc16
-rw-r--r--Nim/main.cpp85
-rw-r--r--configure.in2
6 files changed, 108 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 77bc33d..32fd6ff 100644
--- a/Makefile
+++ b/Makefile
@@ -44,6 +44,9 @@ endif
ifeq ($(BUILD_LIMBER),yes)
include Limber/Makefile.inc
endif
+ifeq ($(BUILD_NIM),yes)
+include Nim/Makefile.inc
+endif
include QA/Makefile.inc
################################################################################
# Main targets
diff --git a/Makefile.config.in b/Makefile.config.in
index bf85659..98eae9a 100644
--- a/Makefile.config.in
+++ b/Makefile.config.in
@@ -26,5 +26,6 @@ WIN32=@CONFIG_WIN32@
MACOSX=@CONFIG_MACOSX@
BUILD_SWIFT=@BUILD_SWIFT@
BUILD_LIMBER=@BUILD_LIMBER@
+BUILD_NIM=@BUILD_NIM@
QMAKE=@QMAKE@
ARCH=@ARCH@
diff --git a/Nim/.gitignore b/Nim/.gitignore
new file mode 100644
index 0000000..6bb3f86
--- /dev/null
+++ b/Nim/.gitignore
@@ -0,0 +1 @@
+nim
diff --git a/Nim/Makefile.inc b/Nim/Makefile.inc
new file mode 100644
index 0000000..2008c6b
--- /dev/null
+++ b/Nim/Makefile.inc
@@ -0,0 +1,16 @@
+NIM_TARGET = Nim/nim
+NIM_SOURCES = \
+ Nim/main.cpp
+NIM_OBJECTS = \
+ $(NIM_SOURCES:.cpp=.o) \
+
+.PHONY: nim
+nim: $(NIM_TARGET)
+
+$(NIM_TARGET): $(SWIFTEN_TARGET) $(NIM_OBJECTS)
+ $(QUIET_LINK)$(CXX) -o $(NIM_TARGET) $(NIM_OBJECTS) $(LDFLAGS) $(SWIFTEN_TARGET) $(LIBS)
+
+#TARGETS += $(NIM_TARGET)
+CLEANFILES += $(NIM_OBJECTS)
+DEPS += \
+ $(NIM_SOURCES:.cpp=.dep) \
diff --git a/Nim/main.cpp b/Nim/main.cpp
new file mode 100644
index 0000000..52755ae
--- /dev/null
+++ b/Nim/main.cpp
@@ -0,0 +1,85 @@
+#include <dns_sd.h>
+#include <iostream>
+#include <sys/socket.h>
+
+#include "Swiften/Network/HostAddress.h"
+
+using namespace Swift;
+
+void handleServiceRegistered(DNSServiceRef sdRef, DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context ) {
+ std::cerr << "Service registered " << name << " " << regtype << " " << domain << std::endl;
+}
+
+void handleServiceDiscovered(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context ) {
+ std::cerr << "Service discovered " << interfaceIndex << " " << serviceName << " " << regtype << " " << replyDomain << " " << flags << std::endl;
+}
+
+void handleServiceResolved( DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullname, const char *hosttarget, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context ) {
+ std::cerr << "Service resolved " << fullname << " " << hosttarget << " " << port << " " << txtLen << " " << /*std::string((const char*) txtRecord, txtLen) <<*/ std::endl;
+}
+
+void handleAddressInfoReceived ( DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *hostname, const struct sockaddr *address, uint32_t ttl, void *context ) {
+ std::cerr << "Address received " << HostAddress((const unsigned char*) address->sa_data, 4).toString() << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ fd_set fdSet;
+ DNSServiceErrorType result;
+
+ DNSServiceRef registerSDRef;
+ result = DNSServiceRegister(&registerSDRef, 0, 0, "eemi", "_presence._tcp", NULL, NULL, 5269, 0, NULL, handleServiceRegistered, NULL);
+ if (result != kDNSServiceErr_NoError) {
+ std::cerr << "Error 1" << std::endl;
+ }
+ int registerSocket = DNSServiceRefSockFD(registerSDRef);
+ FD_ZERO(&fdSet);
+ FD_SET(registerSocket, &fdSet);
+ select(registerSocket+1, &fdSet, &fdSet, &fdSet, 0);
+ DNSServiceProcessResult(registerSDRef);
+
+ DNSServiceRef browseSDRef;
+ result = DNSServiceBrowse(&browseSDRef, 0, 0, "_presence._tcp", 0, handleServiceDiscovered , 0);
+ if (result != kDNSServiceErr_NoError) {
+ std::cerr << "Error 2" << std::endl;
+ }
+ int browseSocket = DNSServiceRefSockFD(browseSDRef);
+ //while(true) {
+ FD_ZERO(&fdSet);
+ FD_SET(browseSocket, &fdSet);
+ select(browseSocket+1, &fdSet, &fdSet, &fdSet, 0);
+ DNSServiceProcessResult(browseSDRef);
+ //}
+
+
+ DNSServiceRef resolveSDRef;
+ result = DNSServiceResolve(&resolveSDRef, 0, 6, "Remko@Micro", "_presence._tcp.", "local.", handleServiceResolved , 0);
+ if (result != kDNSServiceErr_NoError) {
+ std::cerr << "Error 3" << std::endl;
+ }
+ int resolveSocket = DNSServiceRefSockFD(resolveSDRef);
+ //while(true) {
+ FD_ZERO(&fdSet);
+ FD_SET(resolveSocket, &fdSet);
+ select(resolveSocket+1, &fdSet, &fdSet, &fdSet, 0);
+ DNSServiceProcessResult(resolveSDRef);
+ //}
+
+
+ DNSServiceRef addressSDRef;
+ result = DNSServiceGetAddrInfo(&addressSDRef, 0, 6, kDNSServiceProtocol_IPv4, "Micro.local.", handleAddressInfoReceived, 0);
+ if (result != kDNSServiceErr_NoError) {
+ std::cerr << "Error 4" << std::endl;
+ }
+ int addressSocket = DNSServiceRefSockFD(addressSDRef);
+ //while(true) {
+ std::cout << "GetAddrInfo2" << std::endl;
+ FD_ZERO(&fdSet);
+ FD_SET(addressSocket, &fdSet);
+ select(addressSocket+1, &fdSet, &fdSet, &fdSet, 0);
+ DNSServiceProcessResult(addressSDRef);
+ //}
+
+ // DNSServiceRefDeallocate
+
+ return 0;
+}
diff --git a/configure.in b/configure.in
index 0fbbaa6..ddb423f 100644
--- a/configure.in
+++ b/configure.in
@@ -59,6 +59,7 @@ esac
AC_CHECK_FILE([Swift/Makefile.inc], [BUILD_SWIFT="yes"], [BUILD_SWIFT="no"])
AC_CHECK_FILE([Limber/Makefile.inc], [BUILD_LIMBER="yes"], [BUILD_LIMBER="no"])
+AC_CHECK_FILE([Nim/Makefile.inc], [BUILD_NIM="yes"], [BUILD_NIM="no"])
################################################################################
# Configure options
@@ -230,6 +231,7 @@ AC_SUBST(CONFIG_HAVE_LIBXML)
AC_SUBST(QMAKE)
AC_SUBST(BUILD_SWIFT)
AC_SUBST(BUILD_LIMBER)
+AC_SUBST(BUILD_NIM)
AC_SUBST(ARCH)
AC_CONFIG_FILES([Makefile.config])