/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2004, Apple Computer, 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 Computer, 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.
Change History (most recent first):
$Log: dnssd_clientlib.c,v $
Revision 1.11 2006/08/14 23:05:53 cheshire
Added "tab-width" emacs header line
Revision 1.10 2005/04/06 02:06:56 shersche
Add DNSSD_API macro to TXTRecord API calls
Revision 1.9 2004/10/06 02:22:19 cheshire
Changed MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
Revision 1.8 2004/10/01 22:15:55 rpantos
rdar://problem/3824265: Replace APSL in client lib with BSD license.
Revision 1.7 2004/06/26 03:16:34 shersche
clean up warning messages on Win32 platform
Submitted by: herscher
Revision 1.6 2004/06/12 01:09:45 cheshire
To be callable from the broadest range of clients on Windows (e.g. Visual Basic, C#, etc.)
API routines have to be declared as "__stdcall", instead of the C default, "__cdecl"
Revision 1.5 2004/05/25 18:29:33 cheshire
Move DNSServiceConstructFullName() from dnssd_clientstub.c to dnssd_clientlib.c,
so that it's also accessible to dnssd_clientshim.c (single address space) clients.
Revision 1.4 2004/05/25 17:08:55 cheshire
Fix compiler warning (doesn't make sense for function return type to be const)
Revision 1.3 2004/05/21 21:41:35 cheshire
Add TXT record building and parsing APIs
Revision 1.2 2004/05/20 22:22:21 cheshire
Enable code that was bracketed by "#if 0"
Revision 1.1 2004/03/12 21:30:29 cheshire
Build a System-Context Shared Library from mDNSCore, for the benefit of developers
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#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
*
*********************************************************************************************/
{
{
{
}
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
*
*********************************************************************************************/
(
char *fullName,
const char *service, /* may be NULL */
const char *regtype,
const char *domain
)
{
unsigned long len;
unsigned char c;
const char *s = service;
const char *r = regtype;
const char *d = domain;
if (service)
{
while(*s)
{
c = (unsigned char)*s++;
else if (c <= ' ') // escape non-printable characters
{
*fn++ = '\\';
c = (unsigned char)('0' + (c % 10));
}
*fn++ = (char)c;
}
*fn++ = '.';
}
if (!regtype) return -1;
while(*r) *fn++ = *r++;
while(*d) *fn++ = *d++;
*fn = '\0';
return 0;
}
/*********************************************************************************************
*
* 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);
}