2006-04-09 16:35:48 +00:00
|
|
|
/*
|
|
|
|
* DNS support
|
|
|
|
*
|
|
|
|
* Copyright 2006 Hans Leidekker
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-04-09 16:35:48 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-25 14:14:51 +00:00
|
|
|
#ifndef __WINE_CONFIG_H
|
|
|
|
# error You must include config.h to use this header
|
|
|
|
#endif
|
2006-04-09 16:35:48 +00:00
|
|
|
|
2007-11-27 23:11:14 +00:00
|
|
|
static inline void *heap_alloc( SIZE_T size )
|
2006-04-09 16:35:48 +00:00
|
|
|
{
|
|
|
|
return HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
}
|
|
|
|
|
2007-11-27 23:11:14 +00:00
|
|
|
static inline void *heap_alloc_zero( SIZE_T size )
|
2006-05-01 14:29:14 +00:00
|
|
|
{
|
|
|
|
return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
|
|
|
|
}
|
|
|
|
|
2007-11-27 23:11:14 +00:00
|
|
|
static inline BOOL heap_free( LPVOID mem )
|
2006-04-09 16:35:48 +00:00
|
|
|
{
|
2007-11-27 23:11:14 +00:00
|
|
|
return HeapFree( GetProcessHeap(), 0, mem );
|
2006-04-09 16:35:48 +00:00
|
|
|
}
|
|
|
|
|
2006-05-01 14:29:14 +00:00
|
|
|
static inline LPSTR dns_strdup_a( LPCSTR src )
|
|
|
|
{
|
|
|
|
LPSTR dst;
|
|
|
|
|
|
|
|
if (!src) return NULL;
|
2007-11-27 23:11:14 +00:00
|
|
|
dst = heap_alloc( (lstrlenA( src ) + 1) * sizeof(char) );
|
2006-05-01 14:29:14 +00:00
|
|
|
if (dst) lstrcpyA( dst, src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *dns_strdup_u( const char *src )
|
|
|
|
{
|
|
|
|
char *dst;
|
|
|
|
|
|
|
|
if (!src) return NULL;
|
2007-11-27 23:11:14 +00:00
|
|
|
dst = heap_alloc( (strlen( src ) + 1) * sizeof(char) );
|
2006-05-01 14:29:14 +00:00
|
|
|
if (dst) strcpy( dst, src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline LPWSTR dns_strdup_w( LPCWSTR src )
|
|
|
|
{
|
|
|
|
LPWSTR dst;
|
|
|
|
|
|
|
|
if (!src) return NULL;
|
2007-11-27 23:11:14 +00:00
|
|
|
dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
|
2006-05-01 14:29:14 +00:00
|
|
|
if (dst) lstrcpyW( dst, src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2006-04-09 16:35:48 +00:00
|
|
|
static inline LPWSTR dns_strdup_aw( LPCSTR str )
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
|
2007-11-27 23:11:14 +00:00
|
|
|
if ((ret = heap_alloc( len * sizeof(WCHAR) )))
|
2006-04-09 16:35:48 +00:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2006-05-01 14:29:14 +00:00
|
|
|
|
|
|
|
static inline LPWSTR dns_strdup_uw( const char *str )
|
|
|
|
{
|
|
|
|
LPWSTR ret = NULL;
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
|
2007-11-27 23:11:14 +00:00
|
|
|
if ((ret = heap_alloc( len * sizeof(WCHAR) )))
|
2006-05-01 14:29:14 +00:00
|
|
|
MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline LPSTR dns_strdup_wa( LPCWSTR str )
|
|
|
|
{
|
|
|
|
LPSTR ret = NULL;
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
|
2007-11-27 23:11:14 +00:00
|
|
|
if ((ret = heap_alloc( len )))
|
2006-05-01 14:29:14 +00:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *dns_strdup_wu( LPCWSTR str )
|
|
|
|
{
|
|
|
|
LPSTR ret = NULL;
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
|
2007-11-27 23:11:14 +00:00
|
|
|
if ((ret = heap_alloc( len )))
|
2006-05-01 14:29:14 +00:00
|
|
|
WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *dns_strdup_au( LPCSTR src )
|
|
|
|
{
|
|
|
|
char *dst = NULL;
|
|
|
|
LPWSTR ret = dns_strdup_aw( src );
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
dst = dns_strdup_wu( ret );
|
2007-11-27 23:11:14 +00:00
|
|
|
heap_free( ret );
|
2006-05-01 14:29:14 +00:00
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline LPSTR dns_strdup_ua( const char *src )
|
|
|
|
{
|
|
|
|
LPSTR dst = NULL;
|
|
|
|
LPWSTR ret = dns_strdup_uw( src );
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
dst = dns_strdup_wa( ret );
|
2007-11-27 23:11:14 +00:00
|
|
|
heap_free( ret );
|
2006-05-01 14:29:14 +00:00
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
2006-05-29 10:47:19 +00:00
|
|
|
|
2011-05-13 15:01:53 +00:00
|
|
|
const char *dns_type_to_str( unsigned short ) DECLSPEC_HIDDEN;
|
2006-05-29 10:47:31 +00:00
|
|
|
|
2008-08-25 14:14:51 +00:00
|
|
|
#ifdef HAVE_RESOLV
|
2011-05-13 15:01:53 +00:00
|
|
|
int dns_ns_initparse( const u_char *, int, ns_msg * ) DECLSPEC_HIDDEN;
|
|
|
|
int dns_ns_parserr( ns_msg *, ns_sect, int, ns_rr * ) DECLSPEC_HIDDEN;
|
|
|
|
int dns_ns_name_skip( const u_char **, const u_char * ) DECLSPEC_HIDDEN;
|
|
|
|
int dns_ns_name_uncompress( const u_char *, const u_char *, const u_char *, char *, size_t ) DECLSPEC_HIDDEN;
|
2008-08-25 14:14:51 +00:00
|
|
|
#endif
|