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