FreeRDP
io/io.c
1 
20 #include <winpr/config.h>
21 
22 #include <winpr/io.h>
23 
24 #ifndef _WIN32
25 
26 #ifdef WINPR_HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 
30 #include <time.h>
31 #include <errno.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <dirent.h>
36 
37 #include <fcntl.h>
38 #include <sys/un.h>
39 #include <sys/stat.h>
40 #include <sys/socket.h>
41 
42 #include <winpr/crt.h>
43 #include <winpr/wlog.h>
44 
45 #include "../handle/handle.h"
46 #include "../pipe/pipe.h"
47 #include "../log.h"
48 
49 #define TAG WINPR_TAG("io")
50 
51 BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
52  LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
53 {
54 #if 1
55  WLog_ERR(TAG, "Not implemented");
56  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
57  return FALSE;
58 #else
59  ULONG Type;
60  WINPR_HANDLE* Object;
61 
62  if (!winpr_Handle_GetInfo(hFile, &Type, &Object))
63  return FALSE;
64 
65  else if (Type == HANDLE_TYPE_NAMED_PIPE)
66  {
67  int status = -1;
68  DWORD request;
69  PVOID lpBuffer;
70  DWORD nNumberOfBytes;
71  WINPR_NAMED_PIPE* pipe;
72 
73  pipe = (WINPR_NAMED_PIPE*)Object;
74 
75  if (!(pipe->dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED))
76  return FALSE;
77 
78  lpBuffer = lpOverlapped->Pointer;
79  request = (DWORD)lpOverlapped->Internal;
80  nNumberOfBytes = (DWORD)lpOverlapped->InternalHigh;
81 
82  if (request == 0)
83  {
84  if (pipe->clientfd == -1)
85  return FALSE;
86 
87  status = read(pipe->clientfd, lpBuffer, nNumberOfBytes);
88  }
89  else if (request == 1)
90  {
91  if (pipe->clientfd == -1)
92  return FALSE;
93 
94  status = write(pipe->clientfd, lpBuffer, nNumberOfBytes);
95  }
96  else if (request == 2)
97  {
98  socklen_t length;
99  struct sockaddr_un s = { 0 };
100 
101  if (pipe->serverfd == -1)
102  return FALSE;
103 
104  length = sizeof(struct sockaddr_un);
105 
106  status = accept(pipe->serverfd, (struct sockaddr*)&s, &length);
107 
108  if (status < 0)
109  return FALSE;
110 
111  pipe->clientfd = status;
112  pipe->ServerMode = FALSE;
113 
114  status = 0;
115  }
116 
117  if (status < 0)
118  {
119  *lpNumberOfBytesTransferred = 0;
120  return FALSE;
121  }
122 
123  *lpNumberOfBytesTransferred = status;
124  }
125 
126  return TRUE;
127 #endif
128 }
129 
130 BOOL GetOverlappedResultEx(HANDLE hFile, LPOVERLAPPED lpOverlapped,
131  LPDWORD lpNumberOfBytesTransferred, DWORD dwMilliseconds,
132  BOOL bAlertable)
133 {
134  WLog_ERR(TAG, "Not implemented");
135  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
136  return FALSE;
137 }
138 
139 BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize,
140  LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned,
141  LPOVERLAPPED lpOverlapped)
142 {
143  WLog_ERR(TAG, "Not implemented");
144  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
145  return FALSE;
146 }
147 
148 HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
149  ULONG_PTR CompletionKey, DWORD NumberOfConcurrentThreads)
150 {
151  WLog_ERR(TAG, "Not implemented");
152  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
153  return NULL;
154 }
155 
156 BOOL GetQueuedCompletionStatus(HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
157  PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,
158  DWORD dwMilliseconds)
159 {
160  WLog_ERR(TAG, "Not implemented");
161  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
162  return FALSE;
163 }
164 
165 BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort, LPOVERLAPPED_ENTRY lpCompletionPortEntries,
166  ULONG ulCount, PULONG ulNumEntriesRemoved, DWORD dwMilliseconds,
167  BOOL fAlertable)
168 {
169  WLog_ERR(TAG, "Not implemented");
170  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
171  return FALSE;
172 }
173 
174 BOOL PostQueuedCompletionStatus(HANDLE CompletionPort, DWORD dwNumberOfBytesTransferred,
175  ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped)
176 {
177  WLog_ERR(TAG, "Not implemented");
178  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
179  return FALSE;
180 }
181 
182 BOOL CancelIo(HANDLE hFile)
183 {
184  WLog_ERR(TAG, "Not implemented");
185  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
186  return FALSE;
187 }
188 
189 BOOL CancelIoEx(HANDLE hFile, LPOVERLAPPED lpOverlapped)
190 {
191  WLog_ERR(TAG, "Not implemented");
192  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
193  return FALSE;
194 }
195 
196 BOOL CancelSynchronousIo(HANDLE hThread)
197 {
198  WLog_ERR(TAG, "Not implemented");
199  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
200  return FALSE;
201 }
202 
203 #endif
204 
205 #ifdef _UWP
206 
207 #include <winpr/crt.h>
208 #include <winpr/wlog.h>
209 
210 #include "../log.h"
211 
212 #define TAG WINPR_TAG("io")
213 
214 BOOL GetOverlappedResult(HANDLE hFile, LPOVERLAPPED lpOverlapped,
215  LPDWORD lpNumberOfBytesTransferred, BOOL bWait)
216 {
217  return GetOverlappedResultEx(hFile, lpOverlapped, lpNumberOfBytesTransferred,
218  bWait ? INFINITE : 0, TRUE);
219 }
220 
221 BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize,
222  LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned,
223  LPOVERLAPPED lpOverlapped)
224 {
225  WLog_ERR(TAG, "Not implemented");
226  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
227  return FALSE;
228 }
229 
230 HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
231  ULONG_PTR CompletionKey, DWORD NumberOfConcurrentThreads)
232 {
233  WLog_ERR(TAG, "Not implemented");
234  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
235  return NULL;
236 }
237 
238 BOOL GetQueuedCompletionStatus(HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
239  PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,
240  DWORD dwMilliseconds)
241 {
242  WLog_ERR(TAG, "Not implemented");
243  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
244  return FALSE;
245 }
246 
247 BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort, LPOVERLAPPED_ENTRY lpCompletionPortEntries,
248  ULONG ulCount, PULONG ulNumEntriesRemoved, DWORD dwMilliseconds,
249  BOOL fAlertable)
250 {
251  WLog_ERR(TAG, "Not implemented");
252  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
253  return FALSE;
254 }
255 
256 BOOL PostQueuedCompletionStatus(HANDLE CompletionPort, DWORD dwNumberOfBytesTransferred,
257  ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped)
258 {
259  WLog_ERR(TAG, "Not implemented");
260  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
261  return FALSE;
262 }
263 
264 BOOL CancelIo(HANDLE hFile)
265 {
266  return CancelIoEx(hFile, NULL);
267 }
268 
269 BOOL CancelSynchronousIo(HANDLE hThread)
270 {
271  WLog_ERR(TAG, "Not implemented");
272  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
273  return FALSE;
274 }
275 
276 #endif