dnsapi.h 3.79 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
#include <stdlib.h>
22 23 24 25 26
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "winternl.h"
#include "wine/unixlib.h"
27

28
static inline char *strdup_a( const char *src )
29
{
30
    char *dst;
31
    if (!src) return NULL;
32
    dst = malloc( (lstrlenA( src ) + 1) * sizeof(char) );
33 34 35 36
    if (dst) lstrcpyA( dst, src );
    return dst;
}

37
static inline char *strdup_u( const char *src )
38 39 40
{
    char *dst;
    if (!src) return NULL;
41
    dst = malloc( (strlen( src ) + 1) * sizeof(char) );
42 43 44 45
    if (dst) strcpy( dst, src );
    return dst;
}

46
static inline WCHAR *strdup_w( const WCHAR *src )
47
{
48
    WCHAR *dst;
49
    if (!src) return NULL;
50
    dst = malloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
51 52 53 54
    if (dst) lstrcpyW( dst, src );
    return dst;
}

55
static inline WCHAR *strdup_aw( const char *str )
56
{
57
    WCHAR *ret = NULL;
58 59 60
    if (str)
    {
        DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
61
        if ((ret = malloc( len * sizeof(WCHAR) )))
62 63 64 65
            MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
    }
    return ret;
}
66

67
static inline WCHAR *strdup_uw( const char *str )
68
{
69
    WCHAR *ret = NULL;
70 71 72
    if (str)
    {
        DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
73
        if ((ret = malloc( len * sizeof(WCHAR) )))
74 75 76 77 78
            MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
    }
    return ret;
}

79
static inline char *strdup_wa( const WCHAR *str )
80
{
81
    char *ret = NULL;
82 83 84
    if (str)
    {
        DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
85
        if ((ret = malloc( len )))
86 87 88 89 90
            WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
    }
    return ret;
}

91
static inline char *strdup_wu( const WCHAR *str )
92
{
93
    char *ret = NULL;
94 95 96
    if (str)
    {
        DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
97
        if ((ret = malloc( len )))
98 99 100 101 102
            WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
    }
    return ret;
}

103
static inline char *strdup_au( const char *src )
104 105
{
    char *dst = NULL;
106
    WCHAR *ret = strdup_aw( src );
107 108
    if (ret)
    {
109
        dst = strdup_wu( ret );
110
        free( ret );
111 112 113 114
    }
    return dst;
}

115
static inline char *strdup_ua( const char *src )
116
{
117 118
    char *dst = NULL;
    WCHAR *ret = strdup_uw( src );
119 120
    if (ret)
    {
121
        dst = strdup_wa( ret );
122
        free( ret );
123 124 125
    }
    return dst;
}
126

127
extern const char *debugstr_type( unsigned short ) DECLSPEC_HIDDEN;
128

129
struct get_searchlist_params
130
{
131 132
    DNS_TXT_DATAW   *list;
    DWORD           *len;
133 134
};

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
struct get_serverlist_params
{
    USHORT           family;
    DNS_ADDR_ARRAY  *addrs;
    DWORD           *len;
};

struct query_params
{
    const char      *name;
    WORD             type;
    DWORD            options;
    void            *buf;
    DWORD           *len;
};

enum unix_funcs
{
    unix_get_searchlist,
    unix_get_serverlist,
    unix_set_serverlist,
    unix_query,
};

extern unixlib_handle_t resolv_handle;

#define RESOLV_CALL( func, params ) __wine_unix_call( resolv_handle, unix_ ## func, params )