closer-to-vc7-support-20030528
[openafs.git] / src / WINNT / client_osi / osidb.c
1 /* 
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* Copyright (C) 1994 Cazamar Systems, Inc. */
11
12
13 #include <afs/param.h>
14 #include <afs/stds.h>
15
16 #include <windows.h>
17 #include <rpc.h>
18 #include <malloc.h>
19 #include "osi.h"
20 #include "dbrpc.h"
21 #include <assert.h>
22
23 long osi_maxCalls = OSI_MAXRPCCALLS;
24
25 static UUID debugType = { /* 95EEEAE0-1BD3-101B-8953-204C4F4F5020 */
26         0x95EEEAE0,
27         0x1BD3,
28         0x101B,
29         {0x89, 0x53, 0x20, 0x4C, 0x4F, 0x4F, 0x50, 0x20}
30 };
31
32 void dbrpc_Ping(handle_t handle)
33 {
34         return;
35 }
36
37 void dbrpc_GetFormat(handle_t handle, unsigned char *namep, long region, long index,
38         osi_remFormat_t *formatp, long *codep)
39 {
40         osi_fdType_t *typep;
41         osi_fdTypeFormat_t *fp;
42
43         typep = osi_FindFDType(namep);
44         if (typep == NULL) {
45                 *codep = OSI_DBRPC_NOENTRY;     /* no such type */
46                 return;
47         }
48
49         for(fp = typep->formatListp; fp; fp=fp->nextp) {
50                 if (region == fp->region && index == fp->index) {
51                         /* found the one to return */
52                         strncpy(formatp->label, fp->labelp, sizeof(formatp->label));
53                         formatp->format = fp->format;
54                         *codep = 0;
55                         return;
56                 }
57         }
58
59         /* if we get here, we didn't find the type, so return no such entry */
60         *codep = OSI_DBRPC_EOF;
61         return;
62 }
63
64 void dbrpc_Open(handle_t handle, unsigned char *namep, osi_remHyper_t *fnp, long *codep)
65 {
66         osi_fd_t *fdp;
67
68         fdp = osi_AllocFD(namep);
69         if (!fdp) {
70                 *codep = OSI_DBRPC_NOFD;
71         }
72         else {
73                 /* wire supports 64 bits but we only use 32 */
74                 fnp->LowPart = fdp->fd;
75                 fnp->HighPart = 0;
76                 *codep = 0;
77         }
78 }
79
80 void dbrpc_GetInfo(handle_t handle, osi_remHyper_t *fnp, osi_remGetInfoParms_t *parmsp,
81         long *codep)
82 {
83         osi_fd_t *fdp;
84
85         /* always init return values */
86         parmsp->icount = 0;
87         parmsp->scount = 0;
88
89         fdp = osi_FindFD(fnp->LowPart);
90         if (fdp) {
91                 *codep = (fdp->opsp->GetInfo)(fdp, parmsp);
92         }
93         else *codep = OSI_DBRPC_NOFD;
94
95         return;
96 }
97
98 void dbrpc_Close(handle_t handle, osi_remHyper_t *fnp, long *codep)
99 {
100         osi_fd_t *fdp;
101
102         fdp = osi_FindFD(fnp->LowPart);
103         if (fdp) {
104                 *codep = osi_CloseFD(fdp);
105         }
106         else
107                 *codep = OSI_DBRPC_NOFD;
108 }
109
110 #ifdef notdef
111 long osi_CleanupRPCEntry(char *exportName)
112 {
113         UUID_VECTOR uuidvp;
114         RPC_NS_HANDLE thandle;
115         UUID tuuid;
116         long code;
117
118         code = RpcNsEntryObjectInqBegin(RPC_C_NS_SYNTAX_DCE, exportName, &thandle);
119         if (code != RPC_S_OK && code != RPC_S_ENTRY_NOT_FOUND) return code;
120         while(1) {
121                 code = RpcNsEntryObjectInqNext(thandle, &tuuid);
122                 if (code == RPC_S_NO_MORE_MEMBERS) {
123                         code = 0;
124                         break;
125                 }
126                 else if (code != RPC_S_OK) {
127                         break;
128                 }
129                 uuidvp.Count = 1;
130                 uuidvp.Uuid[0] = &tuuid;
131                 code = RpcNsBindingUnexport(RPC_C_NS_SYNTAX_DCE, exportName, dbrpc_v1_0_s_ifspec,
132                         &uuidvp);
133                 if (code != RPC_S_OK && code != RPC_S_INTERFACE_NOT_FOUND) break;
134         }
135         RpcNsEntryObjectInqDone(&thandle);
136         return code;
137 }
138 #endif /* notdef */
139
140 long osi_InitDebug(osi_uid_t *exportIDp)
141 {
142         RPC_STATUS rpcStatus;
143         RPC_BINDING_VECTOR *bindingVector;
144         UUID_VECTOR uuidVector;
145         static osi_once_t once;
146
147         if (!osi_Once(&once)) return 0;
148
149         osi_Init();
150
151         osi_InitFD();
152
153         /* create local socket */
154         rpcStatus = RpcServerUseAllProtseqs(osi_maxCalls, (void *) 0);
155         if (rpcStatus != RPC_S_OK) goto done;
156
157         /* register sockets with runtime */
158         rpcStatus = RpcServerRegisterIf(dbrpc_v1_0_s_ifspec, &debugType, NULL);
159         if (rpcStatus != RPC_S_OK) goto done;
160
161         rpcStatus = RpcObjectSetType(exportIDp, &debugType);
162         if (rpcStatus != RPC_S_OK) goto done;
163
164         rpcStatus = RpcServerInqBindings(&bindingVector);
165         if (rpcStatus != RPC_S_OK) goto done;
166
167         /* the UUID_VECTOR structure contains an array of pointers to UUIDs,
168          * amazingly enough.  Aren't those folks C programmers?  Anyway, this
169          * represents the set of objects this server supports, and we register
170          * our unique UUID so that someone who finds our name can track down our
171          * unique instance, since the endpoint mapper doesn't see the name, but
172          * only sees the interface (duplicated of course) and the object UUID.
173          */
174         uuidVector.Count = 1;
175         uuidVector.Uuid[0] = exportIDp;
176
177 #ifdef notdef
178         /* don't use CDS any longer; too big and slow */
179         rpcStatus = osi_CleanupRPCEntry(exportName);
180         if (rpcStatus) goto done;
181 #endif /* notdef */
182
183         rpcStatus = RpcEpRegister(dbrpc_v1_0_s_ifspec, bindingVector,
184                 &uuidVector, (unsigned char *) 0);
185         if (rpcStatus != RPC_S_OK) goto done;
186
187 #ifdef notdef
188         /* don't use CDS */
189         rpcStatus = RpcNsBindingExport(RPC_C_NS_SYNTAX_DCE, exportName,
190                 dbrpc_v1_0_s_ifspec, bindingVector, &uuidVector);
191 #endif /* notdef */
192
193         rpcStatus = RpcBindingVectorFree(&bindingVector);
194         if (rpcStatus != RPC_S_OK) goto done;
195
196 #ifdef  OSISTARTRPCSERVER       /* Now done later */
197
198         /* now start server listening with appropriate # of threads */
199         rpcStatus = RpcServerListen(osi_maxCalls, osi_maxCalls, /* dontwait */1);
200         if (rpcStatus != RPC_S_OK) goto done;
201
202 #endif  /* OSISTARTRPCSERVER */
203
204         rpcStatus = 0;
205
206 done:
207         osi_EndOnce(&once);
208         return rpcStatus;
209 }