dnsapi.h 3.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20
 */

21 22 23
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif
24

25
static inline void *heap_alloc( SIZE_T size )
26 27 28 29
{
    return HeapAlloc( GetProcessHeap(), 0, size );
}

30
static inline void *heap_alloc_zero( SIZE_T size )
31 32 33 34
{
    return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
}

35
static inline BOOL heap_free( LPVOID mem )
36
{
37
    return HeapFree( GetProcessHeap(), 0, mem );
38 39
}

40 41 42 43 44
static inline LPSTR dns_strdup_a( LPCSTR src )
{
    LPSTR dst;

    if (!src) return NULL;
45
    dst = heap_alloc( (lstrlenA( src ) + 1) * sizeof(char) );
46 47 48 49 50 51 52 53 54
    if (dst) lstrcpyA( dst, src );
    return dst;
}

static inline char *dns_strdup_u( const char *src )
{
    char *dst;

    if (!src) return NULL;
55
    dst = heap_alloc( (strlen( src ) + 1) * sizeof(char) );
56 57 58 59 60 61 62 63 64
    if (dst) strcpy( dst, src );
    return dst;
}

static inline LPWSTR dns_strdup_w( LPCWSTR src )
{
    LPWSTR dst;

    if (!src) return NULL;
65
    dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
66 67 68 69
    if (dst) lstrcpyW( dst, src );
    return dst;
}

70 71 72 73 74 75
static inline LPWSTR dns_strdup_aw( LPCSTR str )
{
    LPWSTR ret = NULL;
    if (str)
    {
        DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
76
        if ((ret = heap_alloc( len * sizeof(WCHAR) )))
77 78 79 80
            MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
    }
    return ret;
}
81 82 83 84 85 86 87

static inline LPWSTR dns_strdup_uw( const char *str )
{
    LPWSTR ret = NULL;
    if (str)
    {
        DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
88
        if ((ret = heap_alloc( len * sizeof(WCHAR) )))
89 90 91 92 93 94 95 96 97 98 99
            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 );
100
        if ((ret = heap_alloc( len )))
101 102 103 104 105 106 107 108 109 110 111
            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 );
112
        if ((ret = heap_alloc( len )))
113 114 115 116 117 118 119 120 121 122 123 124 125
            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 );
126
        heap_free( ret );
127 128 129 130 131 132 133 134 135 136 137 138
    }
    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 );
139
        heap_free( ret );
140 141 142
    }
    return dst;
}
143

144 145
const char *dns_type_to_str( unsigned short );

146
#ifdef HAVE_RESOLV
147 148 149 150
int dns_ns_initparse( const u_char *, int, ns_msg * );
int dns_ns_parserr( ns_msg *, ns_sect, int, ns_rr * );
int dns_ns_name_skip( const u_char **, const u_char * );
int dns_ns_name_uncompress( const u_char *, const u_char *, const u_char *, char *, size_t );
151
#endif