ole32: Release the global interface table in the tests when it is no longer needed.
[wine] / dlls / dnsapi / dnsapi.h
1 /*
2  * DNS support
3  *
4  * Copyright 2006 Hans Leidekker
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 static inline void *dns_alloc( SIZE_T size )
23 {
24     return HeapAlloc( GetProcessHeap(), 0, size );
25 }
26
27 static inline void *dns_zero_alloc( SIZE_T size )
28 {
29     return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size );
30 }
31
32 static inline void dns_free( LPVOID mem )
33 {
34     HeapFree( GetProcessHeap(), 0, mem );
35 }
36
37 static inline LPSTR dns_strdup_a( LPCSTR src )
38 {
39     LPSTR dst;
40
41     if (!src) return NULL;
42     dst = dns_alloc( (lstrlenA( src ) + 1) * sizeof(char) );
43     if (dst) lstrcpyA( dst, src );
44     return dst;
45 }
46
47 static inline char *dns_strdup_u( const char *src )
48 {
49     char *dst;
50
51     if (!src) return NULL;
52     dst = dns_alloc( (strlen( src ) + 1) * sizeof(char) );
53     if (dst) strcpy( dst, src );
54     return dst;
55 }
56
57 static inline LPWSTR dns_strdup_w( LPCWSTR src )
58 {
59     LPWSTR dst;
60
61     if (!src) return NULL;
62     dst = dns_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
63     if (dst) lstrcpyW( dst, src );
64     return dst;
65 }
66
67 static inline LPWSTR dns_strdup_aw( LPCSTR str )
68 {
69     LPWSTR ret = NULL;
70     if (str)
71     {
72         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
73         if ((ret = dns_alloc( len * sizeof(WCHAR) )))
74             MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
75     }
76     return ret;
77 }
78
79 static inline LPWSTR dns_strdup_uw( const char *str )
80 {
81     LPWSTR ret = NULL;
82     if (str)
83     {
84         DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
85         if ((ret = dns_alloc( len * sizeof(WCHAR) )))
86             MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
87     }
88     return ret;
89 }
90
91 static inline LPSTR dns_strdup_wa( LPCWSTR str )
92 {
93     LPSTR ret = NULL;
94     if (str)
95     {
96         DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
97         if ((ret = dns_alloc( len )))
98             WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
99     }
100     return ret;
101 }
102
103 static inline char *dns_strdup_wu( LPCWSTR str )
104 {
105     LPSTR ret = NULL;
106     if (str)
107     {
108         DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
109         if ((ret = dns_alloc( len )))
110             WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
111     }
112     return ret;
113 }
114
115 static inline char *dns_strdup_au( LPCSTR src )
116 {
117     char *dst = NULL;
118     LPWSTR ret = dns_strdup_aw( src );
119
120     if (ret)
121     {
122         dst = dns_strdup_wu( ret );
123         dns_free( ret );
124     }
125     return dst;
126 }
127
128 static inline LPSTR dns_strdup_ua( const char *src )
129 {
130     LPSTR dst = NULL;
131     LPWSTR ret = dns_strdup_uw( src );
132
133     if (ret)
134     {
135         dst = dns_strdup_wa( ret );
136         dns_free( ret );
137     }
138     return dst;
139 }
140
141 const char *dns_type_to_str( unsigned short );
142
143 int dns_ns_initparse( const u_char *, int, ns_msg * );
144 int dns_ns_parserr( ns_msg *, ns_sect, int, ns_rr * );
145 int dns_ns_name_skip( const u_char **, const u_char * );
146 int dns_ns_name_uncompress( const u_char *, const u_char *, const u_char *, char *, size_t );