From 82aabd487bd00b79147ee23f4f76d692fdd0ced3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 25 Aug 2006 18:45:17 +0000 Subject: [PATCH] update to newer dns_sd.h copy from Apple git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1274 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-compat-libdns_sd/compat.c | 2 +- avahi-compat-libdns_sd/dns_sd.h | 86 ++++++++++++++++++++++------ avahi-compat-libdns_sd/unsupported.c | 4 +- 3 files changed, 72 insertions(+), 20 deletions(-) diff --git a/avahi-compat-libdns_sd/compat.c b/avahi-compat-libdns_sd/compat.c index 88a98a7..e6b6042 100644 --- a/avahi-compat-libdns_sd/compat.c +++ b/avahi-compat-libdns_sd/compat.c @@ -707,7 +707,7 @@ static void service_resolver_callback( strcat(full_name, "."); - sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_NoError, full_name, host_name, htons(port), l, p, sdref->context); + sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_NoError, full_name, host_name, htons(port), l, (unsigned char*) p, sdref->context); avahi_free(p); break; diff --git a/avahi-compat-libdns_sd/dns_sd.h b/avahi-compat-libdns_sd/dns_sd.h index 0d8a583..b7eb8a2 100644 --- a/avahi-compat-libdns_sd/dns_sd.h +++ b/avahi-compat-libdns_sd/dns_sd.h @@ -1,4 +1,5 @@ -/* +/* -*- Mode: C; tab-width: 4 -*- + * * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,17 +34,32 @@ #endif /* standard calling convention under Win32 is __stdcall */ -#if defined(_WIN32) +/* Note: When compiling Intel EFI (Extensible Firmware Interface) under MS Visual Studio, the */ +/* _WIN32 symbol is defined by the compiler even though it's NOT compiling code for Windows32 */ +#if defined(_WIN32) && !defined(EFI32) && !defined(EFI64) #define DNSSD_API __stdcall #else #define DNSSD_API #endif -#if defined(__FreeBSD_version) && (__FreeBSD_version < 500000) || defined(__OpenBSD__) /* stdint.h does not exist on FreeBSD 4.x; its types are defined in sys/types.h instead */ +#if defined(__FreeBSD__) && (__FreeBSD__ < 5) #include + +/* Likewise, on Sun, standard integer types are in sys/types.h */ #elif defined(__sun__) #include + +/* EFI does not have stdint.h, or anything else equivalent */ +#elif defined(EFI32) || defined(EFI64) +typedef UINT8 uint8_t; +typedef INT8 int8_t; +typedef UINT16 uint16_t; +typedef INT16 int16_t; +typedef UINT32 uint32_t; +typedef INT32 int32_t; + +/* Windows has its own differences */ #elif defined(_WIN32) #include #define _UNUSED @@ -56,6 +72,8 @@ typedef INT16 int16_t; typedef UINT32 uint32_t; typedef INT32 int32_t; #endif + +/* All other Posix platforms use stdint.h */ #else #include #endif @@ -128,10 +146,15 @@ enum * (queries from hosts more than one hop away; hosts not directly connected to the local link). */ - kDNSServiceFlagsForceMulticast = 0x400 + kDNSServiceFlagsForceMulticast = 0x400, /* Flag for signifying that a query or registration should be performed exclusively via multicast DNS, * even for a name in a domain (e.g. foo.apple.com.) that would normally imply unicast DNS. */ + + kDNSServiceFlagsReturnCNAME = 0x800 + /* Flag for returning CNAME records in the DNSServiceQueryRecord call. CNAME records are + * normally followed without indicating to the client that there was a CNAME record. + */ }; /* @@ -179,7 +202,7 @@ enum kDNSServiceType_KEY = 25, /* Security key. */ kDNSServiceType_PX = 26, /* X.400 mail mapping. */ kDNSServiceType_GPOS = 27, /* Geographical position (withdrawn). */ - kDNSServiceType_AAAA = 28, /* Ip6 Address. */ + kDNSServiceType_AAAA = 28, /* IPv6 Address. */ kDNSServiceType_LOC = 29, /* Location Information. */ kDNSServiceType_NXT = 30, /* Next domain (security). */ kDNSServiceType_EID = 31, /* Endpoint identifier. */ @@ -189,7 +212,7 @@ enum kDNSServiceType_NAPTR = 35, /* Naming Authority PoinTeR */ kDNSServiceType_KX = 36, /* Key Exchange */ kDNSServiceType_CERT = 37, /* Certification record */ - kDNSServiceType_A6 = 38, /* IPv6 address (deprecates AAAA) */ + kDNSServiceType_A6 = 38, /* IPv6 Address (deprecated) */ kDNSServiceType_DNAME = 39, /* Non-terminal DNAME (for IPv6) */ kDNSServiceType_SINK = 40, /* Kitchen sink (experimentatl) */ kDNSServiceType_OPT = 41, /* EDNS0 option (meta-RR) */ @@ -301,7 +324,7 @@ enum * * If the client passes 0 for interface index, that means "do the right thing", * which (at present) means, "if the name is in an mDNS local multicast domain - * (e.g. 'local.', '254.169.in-addr.arpa.', '0.8.E.F.ip6.arpa.') then multicast + * (e.g. 'local.', '254.169.in-addr.arpa.', '{8,9,A,B}.E.F.ip6.arpa.') then multicast * on all applicable interfaces, otherwise send via unicast to the appropriate * DNS server." Normally, most clients will use 0 for interface index to * automatically get the default sensible behaviour. @@ -606,6 +629,9 @@ typedef void (DNSSD_API *DNSServiceRegisterReply) * i.e. it creates a TXT record of length one containing a single empty string. * RFC 1035 doesn't allow a TXT record to contain *zero* strings, so a single empty * string is the smallest legal DNS TXT record. + * As with the other parameters, the DNSServiceRegister call copies the txtRecord + * data; e.g. if you allocated the storage for the txtRecord parameter with malloc() + * then you can safely free that memory right after the DNSServiceRegister call returns. * * callBack: The function to be called when the registration completes or asynchronously * fails. The client MAY pass NULL for the callback - The client will NOT be notified @@ -621,7 +647,6 @@ typedef void (DNSSD_API *DNSServiceRegisterReply) * errors are delivered to the callback), otherwise returns an error code indicating * the error that occurred (the callback is never invoked and the DNSServiceRef * is not initialized.) - * */ DNSServiceErrorType DNSSD_API DNSServiceRegister @@ -648,6 +673,12 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister * The record can later be updated or deregistered by passing the RecordRef initialized * by this function to DNSServiceUpdateRecord() or DNSServiceRemoveRecord(). * + * Note that the DNSServiceAddRecord/UpdateRecord/RemoveRecord are *NOT* thread-safe + * with respect to a single DNSServiceRef. If you plan to have multiple threads + * in your program simultaneously add, update, or remove records from the same + * DNSServiceRef, then it's the caller's responsibility to use a mutext lock + * or take similar appropriate precautions to serialize those calls. + * * * Parameters; * @@ -897,9 +928,23 @@ DNSServiceErrorType DNSSD_API DNSServiceBrowse * * txtRecord: The service's primary txt record, in standard txt record format. * - * context: The context pointer that was passed to the callout. * + * NOTE: In earlier versions of this header file, the txtRecord parameter was declared "const char *" + * This is incorrect, since it contains length bytes which are values in the range 0 to 255, not -128 to +127. + * Depending on your compiler settings, this change may cause signed/unsigned mismatch warnings. + * These should be fixed by updating your own callback function definition to match the corrected + * function signature using "const unsigned char *txtRecord". Making this change may also fix inadvertent + * bugs in your callback function, where it could have incorrectly interpreted a length byte with value 250 + * as being -6 instead, with various bad consequences ranging from incorrect operation to software crashes. + * If you need to maintain portable code that will compile cleanly with both the old and new versions of + * this header file, you should update your callback function definition to use the correct unsigned value, + * and then in the place where you pass your callback function to DNSServiceResolve(), use a cast to eliminate + * the compiler warning, e.g.: + * DNSServiceResolve(sd, flags, index, name, regtype, domain, (DNSServiceResolveReply)MyCallback, context); + * This will ensure that your code compiles cleanly without warnings (and more importantly, works correctly) + * with both the old header and with the new corrected version. + * */ typedef void (DNSSD_API *DNSServiceResolveReply) @@ -912,7 +957,7 @@ typedef void (DNSSD_API *DNSServiceResolveReply) const char *hosttarget, uint16_t port, uint16_t txtLen, - const char *txtRecord, + const unsigned char *txtRecord, void *context ); @@ -1005,7 +1050,7 @@ DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef); * DNSServiceRegisterRecordReply() parameters: * * sdRef: The connected DNSServiceRef initialized by - * DNSServiceDiscoveryConnect(). + * DNSServiceCreateConnection(). * * RecordRef: The DNSRecordRef initialized by DNSServiceRegisterRecord(). If the above * DNSServiceRef is passed to DNSServiceRefDeallocate(), this DNSRecordRef is @@ -1220,7 +1265,7 @@ DNSServiceErrorType DNSSD_API DNSServiceQueryRecord * */ -void DNSSD_API DNSServiceReconfirmRecord +DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord ( DNSServiceFlags flags, uint32_t interfaceIndex, @@ -1300,7 +1345,7 @@ int DNSSD_API DNSServiceConstructFullName * Note: Represents a DNS-SD TXT record. */ -typedef struct _TXTRecordRef_t { char privatedata[16]; } TXTRecordRef; +typedef union _TXTRecordRef_t { char PrivateData[16]; char *ForceNaturalAlignment; } TXTRecordRef; /* TXTRecordCreate() @@ -1426,7 +1471,6 @@ DNSServiceErrorType DNSSD_API TXTRecordSetValue * return value: Returns kDNSServiceErr_NoError on success. * Returns kDNSServiceErr_NoSuchKey if the "key" does not * exist in the TXTRecordRef. - * */ DNSServiceErrorType DNSSD_API TXTRecordRemoveValue @@ -1446,7 +1490,6 @@ DNSServiceErrorType DNSSD_API TXTRecordRemoveValue * which you can pass directly to DNSServiceRegister() or * to DNSServiceUpdateRecord(). * Returns 0 if the TXTRecordRef is empty. - * */ uint16_t DNSSD_API TXTRecordGetLength @@ -1464,7 +1507,6 @@ uint16_t DNSSD_API TXTRecordGetLength * return value: Returns a pointer to the raw bytes inside the TXTRecordRef * which you can pass directly to DNSServiceRegister() or * to DNSServiceUpdateRecord(). - * */ const void * DNSSD_API TXTRecordGetBytesPtr @@ -1519,7 +1561,6 @@ const void * DNSSD_API TXTRecordGetBytesPtr * * return value: Returns 1 if the TXT Record contains the specified key. * Otherwise, it returns 0. - * */ int DNSSD_API TXTRecordContainsKey @@ -1663,6 +1704,17 @@ DNSServiceErrorType DNSSD_API DNSServiceSetDefaultDomainForUser #endif //__APPLE_API_PRIVATE +// Some C compiler cleverness. We can make the compiler check certain things for us, +// and report errors at compile-time if anything is wrong. The usual way to do this would +// be to use a run-time "if" statement or the conventional run-time "assert" mechanism, but +// then you don't find out what's wrong until you run the software. This way, if the assertion +// condition is false, the array size is negative, and the complier complains immediately. + +struct DNS_SD_CompileTimeAssertionChecks + { + char assert0[(sizeof(union _TXTRecordRef_t) == 16) ? 1 : -1]; + }; + #ifdef __cplusplus } #endif diff --git a/avahi-compat-libdns_sd/unsupported.c b/avahi-compat-libdns_sd/unsupported.c index 2df3847..a460b41 100644 --- a/avahi-compat-libdns_sd/unsupported.c +++ b/avahi-compat-libdns_sd/unsupported.c @@ -62,7 +62,7 @@ DNSServiceErrorType DNSSD_API DNSServiceQueryRecord ( return kDNSServiceErr_Unsupported; } -void DNSSD_API DNSServiceReconfirmRecord ( +DNSServiceErrorType DNSSD_API DNSServiceReconfirmRecord ( AVAHI_GCC_UNUSED DNSServiceFlags flags, AVAHI_GCC_UNUSED uint32_t interfaceIndex, AVAHI_GCC_UNUSED const char *fullname, @@ -73,7 +73,7 @@ void DNSSD_API DNSServiceReconfirmRecord ( AVAHI_WARN_UNSUPPORTED; - return; + return kDNSServiceErr_Unsupported; } DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(AVAHI_GCC_UNUSED DNSServiceRef *sdRef) { -- 2.39.5