From 2d8dc8775d350d5c8b1be502ae8c7ddeb02ce5d9 Mon Sep 17 00:00:00 2001 From: gezihuzi Date: Sat, 14 Dec 2019 23:02:23 +0800 Subject: [PATCH 1/2] Support setting txtData --- GCDWebServer/Core/GCDWebServer.h | 7 +++++++ GCDWebServer/Core/GCDWebServer.m | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/GCDWebServer/Core/GCDWebServer.h b/GCDWebServer/Core/GCDWebServer.h index 70cb70c..d9d2879 100644 --- a/GCDWebServer/Core/GCDWebServer.h +++ b/GCDWebServer/Core/GCDWebServer.h @@ -92,6 +92,13 @@ extern NSString* const GCDWebServerOption_Port; */ extern NSString* const GCDWebServerOption_BonjourName; +/** +* The Bonjour TXT Data used by the GCDWebServer (NSDictionary). +* +* The default value is nil. +*/ +extern NSString* const GCDWebServerOption_BonjourTXTData; + /** * The Bonjour service type used by the GCDWebServer (NSString). * diff --git a/GCDWebServer/Core/GCDWebServer.m b/GCDWebServer/Core/GCDWebServer.m index cb1b295..8df784c 100644 --- a/GCDWebServer/Core/GCDWebServer.m +++ b/GCDWebServer/Core/GCDWebServer.m @@ -53,6 +53,7 @@ NSString* const GCDWebServerOption_Port = @"Port"; NSString* const GCDWebServerOption_BonjourName = @"BonjourName"; NSString* const GCDWebServerOption_BonjourType = @"BonjourType"; +NSString* const GCDWebServerOption_BonjourTXTData = @"BonjourTXTData"; NSString* const GCDWebServerOption_RequestNATPortMapping = @"RequestNATPortMapping"; NSString* const GCDWebServerOption_BindToLocalhost = @"BindToLocalhost"; NSString* const GCDWebServerOption_MaxPendingConnections = @"MaxPendingConnections"; @@ -590,6 +591,29 @@ static inline NSString* _EncodeBase64(NSString* string) { CFNetServiceSetClient(_registrationService, _NetServiceRegisterCallBack, &context); CFNetServiceScheduleWithRunLoop(_registrationService, CFRunLoopGetMain(), kCFRunLoopCommonModes); CFStreamError streamError = {0}; + + NSDictionary* txtDataDictionary = _GetOption(_options, GCDWebServerOption_BonjourTXTData, nil); + if (txtDataDictionary != nil) { + NSUInteger count = txtDataDictionary.count; + CFStringRef keys[count]; + CFStringRef values[count]; + NSUInteger index = 0; + for (NSString *key in txtDataDictionary) { + NSString *value = txtDataDictionary[key]; + keys[index] = (__bridge CFStringRef)(key); + values[index] = (__bridge CFStringRef)(value); + index ++; + } + CFDictionaryRef txtDictionary = CFDictionaryCreate(CFAllocatorGetDefault(), (void *)keys, (void *)values, count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + if (txtDictionary != NULL) { + CFDataRef txtData = CFNetServiceCreateTXTDataWithDictionary(nil, txtDictionary); + Boolean setTXTDataResult = CFNetServiceSetTXTData(_registrationService, txtData); + if (!setTXTDataResult) { + GWS_LOG_ERROR(@"Failed setting TXTData"); + } + } + } + CFNetServiceRegisterWithOptions(_registrationService, 0, &streamError); _resolutionService = CFNetServiceCreateCopy(kCFAllocatorDefault, _registrationService); From f4cf591e50eb0c56ce64066b31fea6855ffb5bd2 Mon Sep 17 00:00:00 2001 From: gezihuzi Date: Fri, 29 May 2020 15:39:20 +0800 Subject: [PATCH 2/2] replace MobileCoreServices to CoreServices --- GCDWebServer.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GCDWebServer.podspec b/GCDWebServer.podspec index 615222d..f54cbca 100644 --- a/GCDWebServer.podspec +++ b/GCDWebServer.podspec @@ -26,9 +26,9 @@ Pod::Spec.new do |s| cs.private_header_files = "GCDWebServer/Core/GCDWebServerPrivate.h" cs.requires_arc = true cs.ios.library = 'z' - cs.ios.frameworks = 'MobileCoreServices', 'CFNetwork' + cs.ios.frameworks = 'CoreServices', 'CFNetwork' cs.tvos.library = 'z' - cs.tvos.frameworks = 'MobileCoreServices', 'CFNetwork' + cs.tvos.frameworks = 'CoreServices', 'CFNetwork' cs.osx.library = 'z' cs.osx.framework = 'SystemConfiguration' end