|
53 | 53 | NSString* const GCDWebServerOption_Port = @"Port"; |
54 | 54 | NSString* const GCDWebServerOption_BonjourName = @"BonjourName"; |
55 | 55 | NSString* const GCDWebServerOption_BonjourType = @"BonjourType"; |
| 56 | +NSString* const GCDWebServerOption_BonjourTXTData = @"BonjourTXTData"; |
56 | 57 | NSString* const GCDWebServerOption_RequestNATPortMapping = @"RequestNATPortMapping"; |
57 | 58 | NSString* const GCDWebServerOption_BindToLocalhost = @"BindToLocalhost"; |
58 | 59 | NSString* const GCDWebServerOption_MaxPendingConnections = @"MaxPendingConnections"; |
@@ -590,6 +591,29 @@ - (BOOL)_start:(NSError**)error { |
590 | 591 | CFNetServiceSetClient(_registrationService, _NetServiceRegisterCallBack, &context); |
591 | 592 | CFNetServiceScheduleWithRunLoop(_registrationService, CFRunLoopGetMain(), kCFRunLoopCommonModes); |
592 | 593 | CFStreamError streamError = {0}; |
| 594 | + |
| 595 | + NSDictionary* txtDataDictionary = _GetOption(_options, GCDWebServerOption_BonjourTXTData, nil); |
| 596 | + if (txtDataDictionary != nil) { |
| 597 | + NSUInteger count = txtDataDictionary.count; |
| 598 | + CFStringRef keys[count]; |
| 599 | + CFStringRef values[count]; |
| 600 | + NSUInteger index = 0; |
| 601 | + for (NSString *key in txtDataDictionary) { |
| 602 | + NSString *value = txtDataDictionary[key]; |
| 603 | + keys[index] = (__bridge CFStringRef)(key); |
| 604 | + values[index] = (__bridge CFStringRef)(value); |
| 605 | + index ++; |
| 606 | + } |
| 607 | + CFDictionaryRef txtDictionary = CFDictionaryCreate(CFAllocatorGetDefault(), (void *)keys, (void *)values, count, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); |
| 608 | + if (txtDictionary != NULL) { |
| 609 | + CFDataRef txtData = CFNetServiceCreateTXTDataWithDictionary(nil, txtDictionary); |
| 610 | + Boolean setTXTDataResult = CFNetServiceSetTXTData(_registrationService, txtData); |
| 611 | + if (!setTXTDataResult) { |
| 612 | + GWS_LOG_ERROR(@"Failed setting TXTData"); |
| 613 | + } |
| 614 | + } |
| 615 | + } |
| 616 | + |
593 | 617 | CFNetServiceRegisterWithOptions(_registrationService, 0, &streamError); |
594 | 618 |
|
595 | 619 | _resolutionService = CFNetServiceCreateCopy(kCFAllocatorDefault, _registrationService); |
|
0 commit comments