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