ReactOS  0.4.13-dev-544-gede3fdd
context.c
Go to the documentation of this file.
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
37  PVOID Credentials,
38  HANDLE *ContextHandle)
39 {
40  if(CredentialsFlags)
41  {
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. */
57 
58  if(adns_status != adns_s_ok)
59  {
60  *ContextHandle = 0;
61  RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
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
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
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
119 {
120  PWINDNS_CONTEXT Context = (PWINDNS_CONTEXT)ContextHandle;
121 
122  adns_finish(Context->State);
123  RtlFreeHeap(RtlGetProcessHeap(), 0, Context);
124 }
DNS_STATUS WINAPI DnsAcquireContextHandle_A(DWORD CredentialFlags, PVOID Credentials, HANDLE *ContextHandle)
Definition: context.c:100
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
ADNS_API void adns_finish(adns_state ads)
Definition: setup.c:650
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
DNS_STATUS WINAPI DnsAcquireContextHandle_W(DWORD CredentialsFlags, PVOID Credentials, HANDLE *ContextHandle)
Definition: context.c:36
struct WINDNS_CONTEXT * PWINDNS_CONTEXT
adns_status
Definition: adns.h:215
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define WINAPI
Definition: msvc.h:8
DNS_STATUS DnsIntTranslateAdnsToDNS_STATUS(int Status)
Definition: adns.c:17
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
DNS_STATUS WINAPI DnsAcquireContextHandle_UTF8(DWORD CredentialsFlags, PVOID Credentials, HANDLE *ContextHandle)
Definition: context.c:77
Status
Definition: gdiplustypes.h:24
ADNS_API int adns_init(adns_state *newstate_r, adns_initflags flags, FILE *diagfile)
Definition: setup.c:568
struct tagContext Context
Definition: acpixf.h:1012
void WINAPI DnsReleaseContextHandle(HANDLE ContextHandle)
Definition: context.c:118
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13