update for HEAD-2003091401
[reactos.git] / ntoskrnl / lpc / create.c
1 /* $Id$
2  * 
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            ntoskrnl/lpc/create.c
6  * PURPOSE:         Communication mechanism
7  * PROGRAMMER:      David Welch (welch@cwcom.net)
8  * UPDATE HISTORY:
9  *                  Created 22/05/98
10  */
11
12 /* INCLUDES *****************************************************************/
13
14 #define NTOS_MODE_KERNEL
15 #include <ntos.h>
16 #include <internal/port.h>
17 #include <internal/dbg.h>
18
19 #define NDEBUG
20 #include <internal/debug.h>
21
22 STATIC NTSTATUS STDCALL 
23 VerifyCreateParameters (IN      PHANDLE                 PortHandle,
24                         IN      POBJECT_ATTRIBUTES      ObjectAttributes,
25                         IN      ULONG                   MaxConnectInfoLength,
26                         IN      ULONG                   MaxDataLength,
27                         IN      ULONG                   Reserved)
28 {
29   if (NULL == PortHandle)
30     {
31       return (STATUS_INVALID_PARAMETER_1);
32     }
33   if (NULL == ObjectAttributes)
34     {
35       return (STATUS_INVALID_PARAMETER_2);
36     }
37   if ((ObjectAttributes->Attributes    & OBJ_OPENLINK)
38       || (ObjectAttributes->Attributes & OBJ_OPENIF)
39       || (ObjectAttributes->Attributes & OBJ_EXCLUSIVE)
40       || (ObjectAttributes->Attributes & OBJ_PERMANENT)
41       || (ObjectAttributes->Attributes & OBJ_INHERIT))
42   {
43     return (STATUS_INVALID_PORT_ATTRIBUTES);
44   }
45   if (MaxConnectInfoLength > 0x104) /* FIXME: use a macro! */
46     {
47       return (STATUS_INVALID_PARAMETER_3);
48     }
49   if (MaxDataLength > 0x148) /* FIXME: use a macro! */
50     {
51       return (STATUS_INVALID_PARAMETER_4);
52     }
53   /* FIXME: some checking is done also on Reserved */
54   return (STATUS_SUCCESS);
55 }
56
57
58 NTSTATUS STDCALL
59 NiCreatePort (PVOID                     ObjectBody,
60               PVOID                     Parent,
61               PWSTR                     RemainingPath,
62               POBJECT_ATTRIBUTES        ObjectAttributes)
63 {
64   if (RemainingPath == NULL)
65     {
66       return (STATUS_SUCCESS);
67     }
68   
69   if (wcschr(RemainingPath+1, '\\') != NULL)
70     {
71       return (STATUS_UNSUCCESSFUL);
72     }
73   
74   return (STATUS_SUCCESS);
75 }
76
77
78 /**********************************************************************
79  * NAME                                                 EXPORTED
80  *      NtCreatePort@20
81  *      
82  * DESCRIPTION
83  *
84  * ARGUMENTS
85  *      PortHandle,
86  *      ObjectAttributes,
87  *      MaxConnectInfoLength,
88  *      MaxDataLength,
89  *      Reserved
90  * 
91  * RETURN VALUE
92  */
93 EXPORTED NTSTATUS STDCALL 
94 NtCreatePort (PHANDLE                 PortHandle,
95               POBJECT_ATTRIBUTES    ObjectAttributes,
96               ULONG            MaxConnectInfoLength,
97               ULONG                     MaxDataLength,
98               ULONG                     Reserved)
99 {
100   PEPORT                Port;
101   NTSTATUS      Status;
102   
103   DPRINT("NtCreatePort() Name %x\n", ObjectAttributes->ObjectName->Buffer);
104   
105   /* Verify parameters */
106   Status = VerifyCreateParameters (PortHandle,
107                                    ObjectAttributes,
108                                    MaxConnectInfoLength,
109                                    MaxDataLength,
110                                    Reserved);
111   if (!NT_SUCCESS(Status))
112     {
113       return (Status);
114     }
115   /* Ask Ob to create the object */
116   Status = ObRosCreateObject (PortHandle,
117                            PORT_ALL_ACCESS,
118                            ObjectAttributes,
119                            ExPortType,
120                            (PVOID*)&Port);
121   if (!NT_SUCCESS(Status))
122     {
123       return (Status);
124     }
125   
126   Status = NiInitializePort (Port);
127   Port->MaxConnectInfoLength = 260; /* FIXME: use a macro! */
128   Port->MaxDataLength = 328; /* FIXME: use a macro! */
129   
130   ObDereferenceObject (Port);
131   
132   return (Status);
133 }
134
135 /**********************************************************************
136  * NAME                                                 EXPORTED
137  *      NtCreateWaitablePort@20
138  *      
139  * DESCRIPTION
140  *      Waitable ports can be connected to with NtSecureConnectPort.
141  *      No port interface can be used with waitable ports but
142  *      NtReplyWaitReceivePort and NtReplyWaitReceivePortEx.
143  *      Present only in w2k+.
144  *
145  * ARGUMENTS
146  *      PortHandle,
147  *      ObjectAttributes,
148  *      MaxConnectInfoLength,
149  *      MaxDataLength,
150  *      Reserved
151  * 
152  * RETURN VALUE
153  */
154 EXPORTED NTSTATUS STDCALL
155 NtCreateWaitablePort (OUT       PHANDLE                 PortHandle,
156                       IN        POBJECT_ATTRIBUTES      ObjectAttributes,
157                       IN        ULONG                   MaxConnectInfoLength,
158                       IN        ULONG                   MaxDataLength,
159                       IN        ULONG                   Reserved)
160 {
161   NTSTATUS Status;
162   
163   /* Verify parameters */
164   Status = VerifyCreateParameters (PortHandle,
165                                    ObjectAttributes,
166                                    MaxConnectInfoLength,
167                                    MaxDataLength,
168                                    Reserved);
169   if (STATUS_SUCCESS != Status)
170     {
171       return (Status);
172     }
173   /* TODO */
174   return (STATUS_NOT_IMPLEMENTED);
175 }
176
177 /* EOF */