/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2004-2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* 3. Neither the name of Apple Inc. ("Apple") nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include "dns_sd.h"
#endif
#if defined(_WIN32)
// disable warning "conversion from <data> to uint16_t"
#endif
/*********************************************************************************************
*
* Supporting Functions
*
*********************************************************************************************/
// DomainEndsInDot returns 1 if name ends with a dot, 0 otherwise
// (DNSServiceConstructFullName depends this returning 1 for true, rather than any non-zero value meaning true)
{
{
{
}
else dom++; // else goto next character
}
return (dom[0] == '.');
}
(
const void *txtRecord,
const char *key,
unsigned long *keylen
)
{
while (p<e)
{
uint8_t *x = p;
p += 1 + p[0];
}
return(NULL);
}
/*********************************************************************************************
*
* General Utility Functions
*
*********************************************************************************************/
// Note: Need to make sure we don't write more than kDNSServiceMaxDomainName (1009) bytes to fullName
// In earlier builds this constant was defined to be 1005, so to avoid buffer overruns on clients
// compiled with that constant we'll actually limit the output to 1005 bytes.
(
char *const fullName,
const char *const service, // May be NULL
const char *const regtype,
const char *const domain
)
{
const char *s = service;
const char *r = regtype;
const char *d = domain;
// regtype must be at least "x._udp" or "x._tcp"
if (strncasecmp((regtype + len - 4), "_tcp", 4) && strncasecmp((regtype + len - 4), "_udp", 4)) return kDNSServiceErr_BadParam;
{
while (*s)
{
unsigned char c = *s++; // Needs to be unsigned, or values like 0xFF will be interpreted as < 32
if (c <= ' ') // Escape non-printable characters
{
*fn++ = '\\';
c = '0' + (c ) % 10;
}
else if (c == '.' || (c == '\\')) // Escape dot and backslash literals
{
*fn++ = '\\';
}
else
*fn++ = (char)c;
}
*fn++ = '.';
}
*fn = '\0';
return kDNSServiceErr_NoError;
fail:
*fn = '\0';
return kDNSServiceErr_BadParam;
}
/*********************************************************************************************
*
* TXT Record Construction Functions
*
*********************************************************************************************/
typedef struct _TXTRecordRefRealType
{
// The opaque storage defined in the public dns_sd.h header is 16 bytes;
// make sure we don't exceed that.
{
};
(
void *buffer
)
{
}
{
}
(
const char *key,
const void *value
)
{
const char *k;
{
unsigned char *newbuf;
if (!newbuf) return(kDNSServiceErr_NoMemory);
}
p = start + 1;
p += keysize;
if (value)
{
*p++ = '=';
p += valueSize;
}
return(kDNSServiceErr_NoError);
}
(
const char *key
)
{
if (!item) return(kDNSServiceErr_NoSuchKey);
// Use memmove because memcpy behaviour is undefined for overlapping regions
return(kDNSServiceErr_NoError);
}
const void * DNSSD_API TXTRecordGetBytesPtr(const TXTRecordRef *txtRecord) { return(txtRec->buffer); }
/*********************************************************************************************
*
* TXT Record Parsing Functions
*
*********************************************************************************************/
(
const void *txtRecord,
const char *key
)
{
unsigned long keylen;
}
(
const void *txtRecord,
const char *key,
)
{
unsigned long keylen;
if (!item || item[0] <= keylen) return(NULL); // If key not found, or found with no value, return NULL
}
(
const void *txtRecord
)
{
while (p<e) { p += 1 + p[0]; count++; }
}
(
const void *txtRecord,
char *key,
const void **value
)
{
if (p<e && p + 1 + p[0] <= e) // If valid
{
uint8_t *x = p+1;
unsigned long len = 0;
e = p + 1 + p[0];
if (x+len<e) // If we found '='
{
}
else
{
*valueLen = 0;
}
return(kDNSServiceErr_NoError);
}
return(kDNSServiceErr_Invalid);
}
/*********************************************************************************************
*
* SCCS-compatible version string
*
*********************************************************************************************/
// For convenience when using the "strings" command, this is the last thing in the file
// Note: The C preprocessor stringify operator ('#') makes a string from its argument, without macro expansion
// e.g. If "version" is #define'd to be "4", then STRINGIFY_AWE(version) will return the string "version", not "4"
// To expand "version" to its value before making the string, use STRINGIFY(version) instead
#define STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s) # s
// NOT static -- otherwise the compiler may optimize it out
// The "@(#) " pattern is a special prefix the "what" command looks for
#ifndef MDNS_VERSIONSTR_NODTS
const char VersionString_SCCS_libdnssd[] = "@(#) libdns_sd " STRINGIFY(mDNSResponderVersion) " (" __DATE__ " " __TIME__ ")";
#else
#endif