Added/fixed some documentation reported by winapi_check.
[wine] / misc / network.c
1 /*
2  * USER Windows Network functions
3  */
4
5 #include <ctype.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <pwd.h>
9 #include <unistd.h>
10
11 #include "winbase.h"
12 #include "wine/winnet16.h"
13 #include "winnetwk.h"
14 #include "drive.h"
15 #include "debugtools.h"
16 #include "heap.h"
17
18 DEFAULT_DEBUG_CHANNEL(wnet)
19
20 /*
21  * Remote printing 
22  */
23
24 /**************************************************************************
25  *              WNetOpenJob16       [USER.501]
26  */
27 WORD WINAPI WNetOpenJob16( LPSTR szQueue, LPSTR szJobTitle, WORD nCopies, LPINT16 pfh )
28 {
29     FIXME( "(%s, %s, %d, %p): stub\n",
30            debugstr_a(szQueue), debugstr_a(szJobTitle), nCopies, pfh );
31     return WN16_NET_ERROR;
32 }
33
34 /**************************************************************************
35  *              WNetCloseJob16      [USER.502]
36  */
37 WORD WINAPI WNetCloseJob16( WORD fh, LPINT16 pidJob, LPSTR szQueue )
38 {
39     FIXME( "(%d, %p, %s): stub\n", fh, pidJob, debugstr_a(szQueue) );
40     return WN16_NET_ERROR;
41 }
42
43 /**************************************************************************
44  *              WNetWriteJob16      [USER.524]
45  */
46 WORD WINAPI WNetWriteJob16( HANDLE16 hJob, LPSTR lpData, LPINT16 lpcbData )
47 {
48     FIXME( "(%04x, %p, %p): stub\n", hJob, lpData, lpcbData );
49     return WN16_NET_ERROR;
50 }
51
52 /**************************************************************************
53  *              WNetAbortJob16       [USER.503]
54  */
55 WORD WINAPI WNetAbortJob16( LPSTR szQueue, WORD wJobId )
56 {
57     FIXME( "(%s, %d): stub\n", debugstr_a(szQueue), wJobId );
58     return WN16_NET_ERROR;
59 }
60
61 /**************************************************************************
62  *              WNetHoldJob16       [USER.504]
63  */
64 WORD WINAPI WNetHoldJob16( LPSTR szQueue, WORD wJobId )
65 {
66     FIXME( "(%s, %d): stub\n", debugstr_a(szQueue), wJobId );
67     return WN16_NET_ERROR;
68 }
69
70 /**************************************************************************
71  *              WNetReleaseJob16       [USER.505]
72  */
73 WORD WINAPI WNetReleaseJob16( LPSTR szQueue, WORD wJobId )
74 {
75     FIXME( "(%s, %d): stub\n", debugstr_a(szQueue), wJobId );
76     return WN16_NET_ERROR;
77 }
78
79 /**************************************************************************
80  *              WNetCancelJob16       [USER.506]
81  */
82 WORD WINAPI WNetCancelJob16( LPSTR szQueue, WORD wJobId )
83 {
84     FIXME( "(%s, %d): stub\n", debugstr_a(szQueue), wJobId );
85     return WN16_NET_ERROR;
86 }
87
88 /**************************************************************************
89  *              WNetSetJobCopies16     [USER.507]
90  */
91 WORD WINAPI WNetSetJobCopies16( LPSTR szQueue, WORD wJobId, WORD nCopies )
92 {
93     FIXME( "(%s, %d, %d): stub\n", debugstr_a(szQueue), wJobId, nCopies );
94     return WN16_NET_ERROR;
95 }
96
97 /**************************************************************************
98  *              WNetWatchQueue16       [USER.508]
99  */
100 WORD WINAPI WNetWatchQueue16( HWND16 hWnd, LPSTR szLocal, LPSTR szUser, WORD nQueue )
101 {
102     FIXME( "(%04x, %s, %s, %d): stub\n", 
103            hWnd, debugstr_a(szLocal), debugstr_a(szUser), nQueue );
104     return WN16_NET_ERROR;
105 }
106
107 /**************************************************************************
108  *              WNetUnwatchQueue16     [USER.509]
109  */
110 WORD WINAPI WNetUnwatchQueue16( LPSTR szQueue )
111 {
112     FIXME( "(%s): stub\n", debugstr_a(szQueue) );
113     return WN16_NET_ERROR;
114 }
115
116 /**************************************************************************
117  *              WNetLockQueueData16       [USER.510]
118  */
119 WORD WINAPI WNetLockQueueData16( LPSTR szQueue, LPSTR szUser, 
120                                  LPQUEUESTRUCT16 *lplpQueueStruct )
121 {
122     FIXME( "(%s, %s, %p): stub\n", 
123            debugstr_a(szQueue), debugstr_a(szUser), lplpQueueStruct );
124     return WN16_NET_ERROR;
125 }
126
127 /**************************************************************************
128  *              WNetUnlockQueueData16       [USER.511]
129  */
130 WORD WINAPI WNetUnlockQueueData16( LPSTR szQueue )
131 {
132     FIXME( "(%s): stub\n", debugstr_a(szQueue) );
133     return WN16_NET_ERROR;
134 }
135
136
137 /*
138  * Connections
139  */
140
141 /********************************************************************
142  *  WNetAddConnection16 [USER.517]  Directs a local device to net
143  * 
144  * Redirects a local device (either a disk drive or printer port)
145  * to a shared device on a remote server.
146  */
147 WORD WINAPI WNetAddConnection16( LPSTR lpNetPath, LPSTR lpPassWord,
148                                  LPSTR lpLocalName )
149 {       
150     FIXME( "(%s, %p, %s): stub\n", 
151            debugstr_a(lpNetPath), lpPassWord, debugstr_a(lpLocalName) );
152     return WN16_NET_ERROR;
153 }
154
155 /********************************************************************
156  *   WNetCancelConnection16 [USER.518]  undirects a local device
157  */
158 WORD WINAPI WNetCancelConnection16( LPSTR lpName, BOOL16 bForce )
159 {
160     FIXME( "(%s, %04X): stub\n", debugstr_a(lpName), bForce);
161     return WN16_NOT_SUPPORTED;
162 }
163
164 /********************************************************************
165  * WNetGetConnection16 [USER.512] reverse-resolves a local device
166  */
167 WORD WINAPI WNetGetConnection16( LPSTR lpLocalName, 
168                                  LPSTR lpRemoteName, UINT16 *cbRemoteName )
169 {
170     const char *path;
171
172     TRACE( "local %s\n", lpLocalName );
173     if (lpLocalName[1] == ':')
174     {
175         int drive = toupper(lpLocalName[0]) - 'A';
176         switch(DRIVE_GetType(drive))
177         {
178         case TYPE_INVALID:
179             return WN16_BAD_LOCALNAME;
180         case TYPE_NETWORK:
181             path = DRIVE_GetLabel(drive);
182             if (strlen(path) + 1 > *cbRemoteName)
183             {
184                 *cbRemoteName = strlen(path) + 1;
185                 return WN16_MORE_DATA;
186             }
187             strcpy( lpRemoteName, path );
188             *cbRemoteName = strlen(lpRemoteName) + 1;
189             return WN16_SUCCESS;
190         case TYPE_FLOPPY:
191         case TYPE_HD:
192         case TYPE_CDROM:
193           TRACE("file is local\n");
194           return WN16_NOT_CONNECTED;
195         default:
196             return WN16_BAD_LOCALNAME;
197         }
198     }
199     return WN16_BAD_LOCALNAME;
200 }
201
202 /**************************************************************************
203  *              WNetRestoreConnection16       [USER.523]
204  */
205 WORD WINAPI WNetRestoreConnection16( HWND16 hwndOwner, LPSTR lpszDevice )
206 {
207     FIXME( "(%04x, %s): stub\n", hwndOwner, debugstr_a(lpszDevice) );
208     return WN16_NOT_SUPPORTED;
209 }
210
211
212 /*
213  * Capabilities
214  */
215
216 /**************************************************************************
217  *              WNetGetCaps16           [USER.513]
218  */
219 WORD WINAPI WNetGetCaps16( WORD capability )
220 {
221     switch (capability) 
222     {
223     case WNNC16_SPEC_VERSION:
224         return 0x30a; /* WfW 3.11 (and apparently other 3.1x) */
225
226     case WNNC16_NET_TYPE:
227         /* hi byte = network type, 
228            lo byte = network vendor (Netware = 0x03) [15 types] */
229         return WNNC16_NET_MultiNet | WNNC16_SUBNET_WinWorkgroups;
230
231     case WNNC16_DRIVER_VERSION:
232         /* driver version of vendor */
233         return 0x100; /* WfW 3.11 */
234
235     case WNNC16_USER:
236         /* 1 = WNetGetUser is supported */
237         return 1;
238
239     case WNNC16_CONNECTION:
240         /* returns mask of the supported connection functions */
241         return   WNNC16_CON_AddConnection | WNNC16_CON_CancelConnection
242                | WNNC16_CON_GetConnections /* | WNNC16_CON_AutoConnect */
243                | WNNC16_CON_BrowseDialog | WNNC16_CON_RestoreConnection;
244
245     case WNNC16_PRINTING:
246         /* returns mask of the supported printing functions */
247         return   WNNC16_PRT_OpenJob | WNNC16_PRT_CloseJob | WNNC16_PRT_HoldJob
248                | WNNC16_PRT_ReleaseJob | WNNC16_PRT_CancelJob
249                | WNNC16_PRT_SetJobCopies | WNNC16_PRT_WatchQueue
250                | WNNC16_PRT_UnwatchQueue | WNNC16_PRT_LockQueueData
251                | WNNC16_PRT_UnlockQueueData | WNNC16_PRT_AbortJob
252                | WNNC16_PRT_WriteJob;
253
254     case WNNC16_DIALOG:
255         /* returns mask of the supported dialog functions */
256         return   WNNC16_DLG_DeviceMode | WNNC16_DLG_BrowseDialog
257                | WNNC16_DLG_ConnectDialog | WNNC16_DLG_DisconnectDialog
258                | WNNC16_DLG_ViewQueueDialog | WNNC16_DLG_PropertyDialog
259                | WNNC16_DLG_ConnectionDialog
260             /* | WNNC16_DLG_PrinterConnectDialog
261                | WNNC16_DLG_SharesDialog | WNNC16_DLG_ShareAsDialog */;
262
263     case WNNC16_ADMIN:
264         /* returns mask of the supported administration functions */
265         /* not sure if long file names is a good idea */
266         return   WNNC16_ADM_GetDirectoryType
267             /* | WNNC16_ADM_DirectoryNotify */ /*not yet supported*/
268                | WNNC16_ADM_LongNames /* | WNNC16_ADM_SetDefaultDrive */;
269
270     case WNNC16_ERROR:
271         /* returns mask of the supported error functions */
272         return   WNNC16_ERR_GetError | WNNC16_ERR_GetErrorText;
273
274     case WNNC16_PRINTMGREXT:
275         /* returns the Print Manager version in major and 
276            minor format if Print Manager functions are available */
277         return 0x30e; /* printman version of WfW 3.11 */
278
279     case 0xffff:
280         /* Win 3.11 returns HMODULE of network driver here
281            FIXME: what should we return ?
282            logonoff.exe needs it, msmail crashes with wrong value */
283         return 0;
284
285     default:
286         return 0;
287     }
288 }
289
290
291 /*
292  * Get User
293  */
294
295 /**************************************************************************
296  *              WNetGetUser16                   [USER.516]
297  */
298 WORD WINAPI WNetGetUser16( LPSTR szUser, LPINT16 nBufferSize )
299 {
300     FIXME( "(%p, %p): stub\n", szUser, nBufferSize );
301     return WN16_NOT_SUPPORTED;
302 }
303
304
305 /*
306  * Browsing
307  */
308
309 /**************************************************************************
310  *              WNetDeviceMode16       [USER.514]
311  */
312 WORD WINAPI WNetDeviceMode16( HWND16 hWndOwner )
313 {
314     FIXME( "(%04x): stub\n", hWndOwner );
315     return WN16_NOT_SUPPORTED;
316 }
317
318 /**************************************************************************
319  *              WNetBrowseDialog16       [USER.515]
320  */
321 WORD WINAPI WNetBrowseDialog16( HWND16 hParent, WORD nType, LPSTR szPath )
322 {
323     FIXME( "(%04x, %x, %s): stub\n", hParent, nType, szPath );
324     return WN16_NOT_SUPPORTED;
325 }
326
327 /********************************************************************
328  *              WNetConnectDialog16       [USER.525]
329  */
330 WORD WINAPI WNetConnectDialog( HWND16 hWndParent, WORD iType )
331 {
332     FIXME( "(%04x, %x): stub\n", hWndParent, iType );
333     return WN16_SUCCESS;
334 }
335
336 /**************************************************************************
337  *              WNetDisconnectDialog16       [USER.526]
338  */
339 WORD WINAPI WNetDisconnectDialog16( HWND16 hwndOwner, WORD iType )
340 {
341     FIXME( "(%04x, %x): stub\n", hwndOwner, iType );
342     return WN16_NOT_SUPPORTED;
343 }
344
345 /**************************************************************************
346  *              WnetConnectionDialog16     [USER.527]
347  */
348 WORD WINAPI WNetConnectionDialog16( HWND16 hWndParent, WORD iType )
349 {
350     FIXME( "(%04x, %x): stub\n", hWndParent, iType );
351     return WN16_SUCCESS;
352 }
353
354 /**************************************************************************
355  *              WNetViewQueueDialog16       [USER.528]
356  */
357 WORD WINAPI WNetViewQueueDialog16( HWND16 hwndOwner, LPSTR lpszQueue )
358 {
359     FIXME(" (%04x, %s): stub\n", hwndOwner, debugstr_a(lpszQueue) );
360     return WN16_NOT_SUPPORTED;
361 }
362
363 /**************************************************************************
364  *              WNetPropertyDialog16       [USER.529]
365  */
366 WORD WINAPI WNetPropertyDialog16( HWND16 hwndParent, WORD iButton,
367                                   WORD nPropSel, LPSTR lpszName, WORD nType )
368 {
369     FIXME( "(%04x, %x, %x, %s, %x ): stub\n",
370           hwndParent, iButton, nPropSel, debugstr_a(lpszName), nType );
371     return WN16_NOT_SUPPORTED;
372 }
373
374 /**************************************************************************
375  *              WNetGetPropertyText16       [USER.532]
376  */
377 WORD WINAPI WNetGetPropertyText16( WORD iButton, WORD nPropSel, LPSTR lpszName,
378                                    LPSTR lpszButtonName, WORD cbButtonName, WORD nType )
379 {
380     FIXME( "(%04x, %04x, %s, %s, %04x): stub\n",
381            iButton, nPropSel, debugstr_a(lpszName), debugstr_a(lpszButtonName), nType);
382     return WN16_NOT_SUPPORTED;
383 }
384
385
386 /*
387  * Admin
388  */
389
390 /*********************************************************************
391  *  WNetGetDirectoryType16 [USER.530]  Decides whether resource is local
392  *
393  * RETURNS
394  *    on success,  puts one of the following in *lpType:
395  * - WNDT_NETWORK   on a network
396  * - WNDT_LOCAL     local
397  */
398 WORD WINAPI WNetGetDirectoryType16( LPSTR lpName, LPINT16 lpType )
399 {
400     UINT type = GetDriveTypeA(lpName);
401     if ( type == DRIVE_DOESNOTEXIST )
402         type = GetDriveTypeA(NULL);
403
404     *lpType = (type == DRIVE_REMOTE)? WNDT_NETWORK : WNDT_NORMAL;
405
406     TRACE( "%s is %s\n", debugstr_a(lpName), 
407            (*lpType == WNDT_NETWORK)? "WNDT_NETWORK" : "WNDT_NORMAL" );
408     return WN16_SUCCESS;
409 }
410
411 /**************************************************************************
412  *              WNetDirectoryNotify16       [USER.531]
413  */
414 WORD WINAPI WNetDirectoryNotify16( HWND16 hwndOwner, LPSTR lpDir, WORD wOper )
415 {
416     FIXME( "(%04x, %s, %s): stub\n", hwndOwner, debugstr_a(lpDir),
417            (wOper == WNDN_MKDIR)? "WNDN_MKDIR" :
418            (wOper == WNDN_MVDIR)? "WNDN_MVDIR" :
419            (wOper == WNDN_RMDIR)? "WNDN_RMDIR" : "unknown" );
420     return WN16_NOT_SUPPORTED;
421 }
422
423
424 /*
425  * Error handling
426  */
427
428 /**************************************************************************
429  *              WNetGetError16       [USER.519]
430  */
431 WORD WINAPI WNetGetError16( LPINT16 nError )
432 {
433     FIXME( "(%p): stub\n", nError );
434     return WN16_NOT_SUPPORTED;
435 }
436
437 /**************************************************************************
438  *              WNetGetErrorText16       [USER.520]
439  */
440 WORD WINAPI WNetGetErrorText16( WORD nError, LPSTR lpBuffer, LPINT16 nBufferSize )
441 {
442     FIXME( "(%x, %p, %p): stub\n", nError, lpBuffer, nBufferSize );
443     return WN16_NET_ERROR;
444 }
445
446 /**************************************************************************
447  *              WNetErrorText16       [USER.499]
448  */
449 WORD WINAPI WNetErrorText16( WORD nError, LPSTR lpszText, WORD cbText )
450 {
451     FIXME("(%x, %p, %x): stub\n", nError, lpszText, cbText );
452     return FALSE;
453 }
454