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