/src/FreeRDP/winpr/libwinpr/io/io.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /**  | 
2  |  |  * WinPR: Windows Portable Runtime  | 
3  |  |  * Asynchronous I/O Functions  | 
4  |  |  *  | 
5  |  |  * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>  | 
6  |  |  *  | 
7  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
8  |  |  * you may not use this file except in compliance with the License.  | 
9  |  |  * You may obtain a copy of the License at  | 
10  |  |  *  | 
11  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
12  |  |  *  | 
13  |  |  * Unless required by applicable law or agreed to in writing, software  | 
14  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
15  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
16  |  |  * See the License for the specific language governing permissions and  | 
17  |  |  * limitations under the License.  | 
18  |  |  */  | 
19  |  |  | 
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  | 0  | { | 
54  | 0  | #if 1  | 
55  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
56  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
57  | 0  |   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  | 0  | }  | 
129  |  |  | 
130  |  | BOOL GetOverlappedResultEx(HANDLE hFile, LPOVERLAPPED lpOverlapped,  | 
131  |  |                            LPDWORD lpNumberOfBytesTransferred, DWORD dwMilliseconds,  | 
132  |  |                            BOOL bAlertable)  | 
133  | 0  | { | 
134  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
135  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
136  | 0  |   return FALSE;  | 
137  | 0  | }  | 
138  |  |  | 
139  |  | BOOL DeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize,  | 
140  |  |                      LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned,  | 
141  |  |                      LPOVERLAPPED lpOverlapped)  | 
142  | 0  | { | 
143  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
144  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
145  | 0  |   return FALSE;  | 
146  | 0  | }  | 
147  |  |  | 
148  |  | HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,  | 
149  |  |                               ULONG_PTR CompletionKey, DWORD NumberOfConcurrentThreads)  | 
150  | 0  | { | 
151  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
152  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
153  | 0  |   return NULL;  | 
154  | 0  | }  | 
155  |  |  | 
156  |  | BOOL GetQueuedCompletionStatus(HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,  | 
157  |  |                                PULONG_PTR lpCompletionKey, LPOVERLAPPED* lpOverlapped,  | 
158  |  |                                DWORD dwMilliseconds)  | 
159  | 0  | { | 
160  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
161  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
162  | 0  |   return FALSE;  | 
163  | 0  | }  | 
164  |  |  | 
165  |  | BOOL GetQueuedCompletionStatusEx(HANDLE CompletionPort, LPOVERLAPPED_ENTRY lpCompletionPortEntries,  | 
166  |  |                                  ULONG ulCount, PULONG ulNumEntriesRemoved, DWORD dwMilliseconds,  | 
167  |  |                                  BOOL fAlertable)  | 
168  | 0  | { | 
169  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
170  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
171  | 0  |   return FALSE;  | 
172  | 0  | }  | 
173  |  |  | 
174  |  | BOOL PostQueuedCompletionStatus(HANDLE CompletionPort, DWORD dwNumberOfBytesTransferred,  | 
175  |  |                                 ULONG_PTR dwCompletionKey, LPOVERLAPPED lpOverlapped)  | 
176  | 0  | { | 
177  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
178  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
179  | 0  |   return FALSE;  | 
180  | 0  | }  | 
181  |  |  | 
182  |  | BOOL CancelIo(HANDLE hFile)  | 
183  | 0  | { | 
184  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
185  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
186  | 0  |   return FALSE;  | 
187  | 0  | }  | 
188  |  |  | 
189  |  | BOOL CancelIoEx(HANDLE hFile, LPOVERLAPPED lpOverlapped)  | 
190  | 0  | { | 
191  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
192  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
193  | 0  |   return FALSE;  | 
194  | 0  | }  | 
195  |  |  | 
196  |  | BOOL CancelSynchronousIo(HANDLE hThread)  | 
197  | 0  | { | 
198  | 0  |   WLog_ERR(TAG, "Not implemented");  | 
199  | 0  |   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);  | 
200  | 0  |   return FALSE;  | 
201  | 0  | }  | 
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  |