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