Convert the dnsapi stuff to a consistent 4 spaces indentation
[reactos.git] / reactos / dll / win32 / 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(DWORD CredentialsFlags, PVOID Credentials, HANDLE *ContextHandle);
34
35 DNS_STATUS WINAPI
36 DnsAcquireContextHandle_W(DWORD CredentialsFlags,
37 PVOID Credentials,
38 HANDLE *ContextHandle)
39 {
40 if(CredentialsFlags)
41 {
42 PWINDNS_CONTEXT Context;
43 int adns_status;
44
45 /* For now, don't worry about the user's identity. */
46 Context = (PWINDNS_CONTEXT)RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(WINDNS_CONTEXT));
47
48 if(!Context)
49 {
50 *ContextHandle = 0;
51 return ERROR_OUTOFMEMORY;
52 }
53
54 /* The real work here is to create an adns_state that will help us
55 * do what we want to later. */
56 adns_status = adns_init(&Context->State, adns_if_noenv | adns_if_noerrprint | adns_if_noserverwarn, 0);
57
58 if(adns_status != adns_s_ok)
59 {
60 *ContextHandle = 0;
61 RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
62 return DnsIntTranslateAdnsToDNS_STATUS(adns_status);
63 }
64 else
65 {
66 *ContextHandle = (HANDLE)Context;
67 return ERROR_SUCCESS;
68 }
69 }
70 else
71 {
72 return DnsAcquireContextHandle_UTF8(CredentialsFlags, Credentials, ContextHandle);
73 }
74 }
75
76 DNS_STATUS WINAPI
77 DnsAcquireContextHandle_UTF8(DWORD CredentialsFlags,
78 PVOID Credentials,
79 HANDLE *ContextHandle)
80 {
81 if( CredentialsFlags )
82 {
83 return DnsAcquireContextHandle_W(CredentialsFlags, Credentials, ContextHandle);
84 }
85 else
86 {
87 /* Convert to unicode, then call the _W version
88 * For now, there is no conversion */
89 DNS_STATUS Status;
90
91 Status = DnsAcquireContextHandle_W(TRUE, Credentials, /* XXX arty */ ContextHandle);
92
93 /* Free the unicode credentials when they exist. */
94
95 return Status;
96 }
97 }
98
99 DNS_STATUS WINAPI
100 DnsAcquireContextHandle_A(DWORD CredentialFlags,
101 PVOID Credentials,
102 HANDLE *ContextHandle)
103 {
104 if(CredentialFlags)
105 {
106 return DnsAcquireContextHandle_W(CredentialFlags, Credentials, ContextHandle);
107 }
108 else
109 {
110 return DnsAcquireContextHandle_UTF8(CredentialFlags, Credentials, ContextHandle);
111 }
112 }
113
114 /* DnsReleaseContextHandle *************
115 * Release a context handle, freeing all resources.
116 */
117 void WINAPI
118 DnsReleaseContextHandle(HANDLE ContextHandle)
119 {
120 PWINDNS_CONTEXT Context = (PWINDNS_CONTEXT)ContextHandle;
121
122 adns_finish(Context->State);
123 RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
124 }