Resolve chained CNAME records
[reactos.git] / reactos / lib / dnsapi / dnsapi / context.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/dnsapi/dnsapi/context.c
5 * PURPOSE: DNSAPI functions built on the ADNS library.
6 * PROGRAMER: Art Yerkes
7 * UPDATE HISTORY:
8 * 12/15/03 -- Created
9 */
10
11 #include "precomp.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* DnsAcquireContextHandle *************
17 * Create a context handle that will allow us to open and retrieve queries.
18 *
19 * DWORD CredentialsFlags -- TRUE -- Unicode
20 * FALSE -- Ansi or UTF-8?
21 *
22 * PVOID Credentials -- Pointer to a SEC_WINNT_AUTH_IDENTITY
23 * TODO: Use it.
24 *
25 * PHANDLE ContextHandle -- Pointer to a HANDLE that will receive
26 * our context pointer.
27 *
28 * RETURNS:
29 * ERROR_SUCCESS or a failure code.
30 * TODO: Which ones area allowed?
31 */
32
33 extern DNS_STATUS WINAPI DnsAcquireContextHandle_UTF8
34 ( DWORD CredentialsFlags,
35 PVOID Credentials,
36 HANDLE *ContextHandle );
37
38 DNS_STATUS WINAPI DnsAcquireContextHandle_W
39 ( DWORD CredentialsFlags,
40 PVOID Credentials,
41 HANDLE *ContextHandle ) {
42 if( CredentialsFlags ) {
43 PWINDNS_CONTEXT Context;
44 int adns_status;
45
46 /* For now, don't worry about the user's identity. */
47 Context = (PWINDNS_CONTEXT)RtlAllocateHeap( RtlGetProcessHeap(), 0,
48 sizeof( WINDNS_CONTEXT ) );
49 /* The real work here is to create an adns_state that will help us
50 * do what we want to later. */
51 adns_status = adns_init( &Context->State,
52 adns_if_noenv |
53 adns_if_noerrprint |
54 adns_if_noserverwarn,
55 0 );
56 if( adns_status != adns_s_ok ) {
57 *ContextHandle = 0;
58 return DnsIntTranslateAdnsToDNS_STATUS( adns_status );
59 } else {
60 *ContextHandle = (HANDLE)Context;
61 return ERROR_SUCCESS;
62 }
63 } else {
64 return DnsAcquireContextHandle_UTF8( CredentialsFlags,
65 Credentials,
66 ContextHandle );
67 }
68 }
69
70 DNS_STATUS WINAPI DnsAcquireContextHandle_UTF8
71 ( DWORD CredentialsFlags,
72 PVOID Credentials,
73 HANDLE *ContextHandle ) {
74 if( CredentialsFlags ) {
75 return DnsAcquireContextHandle_W( CredentialsFlags,
76 Credentials,
77 ContextHandle );
78 } else {
79 /* Convert to unicode, then call the _W version
80 * For now, there is no conversion */
81 DNS_STATUS Status;
82
83 Status = DnsAcquireContextHandle_W( TRUE,
84 Credentials, /* XXX arty */
85 ContextHandle );
86
87 /* Free the unicode credentials when they exist. */
88
89 return Status;
90 }
91 }
92
93 DNS_STATUS WINAPI DnsAcquireContextHandle_A
94 ( DWORD CredentialFlags,
95 PVOID Credentials,
96 HANDLE *ContextHandle ) {
97 if( CredentialFlags ) {
98 return DnsAcquireContextHandle_W( CredentialFlags,
99 Credentials,
100 ContextHandle );
101 } else {
102 return DnsAcquireContextHandle_UTF8( CredentialFlags,
103 Credentials,
104 ContextHandle );
105 }
106 }
107 /* DnsReleaseContextHandle *************
108 * Release a context handle, freeing all resources.
109 */
110
111 void WINAPI DnsReleaseContextHandle
112 ( HANDLE ContextHandle ) {
113 PWINDNS_CONTEXT Context = (PWINDNS_CONTEXT)ContextHandle;
114 adns_finish( Context->State );
115 RtlFreeHeap( RtlGetProcessHeap(), 0, Context );
116 }
117