- declare PT_RAS_FOLDER for the "RAS Connections" folder
[wine] / dlls / shell32 / debughlp.c
1 /*
2  * Helper functions for debugging
3  *
4  * Copyright 1998, 2002 Juergen Schmied
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 <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "pidl.h"
28 #include "shlguid.h"
29 #include "wine/debug.h"
30 #include "debughlp.h"
31 #include "docobj.h"
32 #include "shell32_main.h"
33
34
35 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
36
37 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
38 {
39         WORD len;
40
41         if(pidl)
42         {
43           len =  pidl->mkid.cb;
44           if (len)
45           {
46             return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
47           }
48         }
49         return NULL;
50 }
51
52 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
53 {
54         return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
55 }
56
57 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
58 {
59         if(pidl && pidl->mkid.cb != 0x00)
60           return (LPPIDLDATA) &(pidl->mkid.abID);
61         return NULL;
62 }
63
64 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
65 {
66         LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
67
68         if (pdata)
69         {
70           switch (pdata->type)
71           {
72             case PT_MYCOMP:
73             case PT_SPECIAL:
74               return NULL;
75
76             case PT_DRIVE:
77             case PT_DRIVE1:
78             case PT_DRIVE2:
79             case PT_DRIVE3:
80               return (LPSTR)&(pdata->u.drive.szDriveName);
81
82             case PT_FOLDER:
83             case PT_FOLDER1:
84             case PT_VALUE:
85             case PT_IESPECIAL1:
86             case PT_RAS_FOLDER:
87             case PT_IESPECIAL2:
88               return (LPSTR)&(pdata->u.file.szNames);
89
90             case PT_WORKGRP:
91             case PT_COMP:
92             case PT_NETWORK:
93             case PT_NETPROVIDER:
94             case PT_SHARE:
95               return (LPSTR)&(pdata->u.network.szNames);
96           }
97         }
98         return NULL;
99 }
100
101 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
102 {
103         LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
104
105         if (pdata)
106         {
107           switch (pdata->type)
108           {
109             case PT_FOLDER:
110             case PT_VALUE:
111             case PT_IESPECIAL1:
112             case PT_RAS_FOLDER:
113             case PT_IESPECIAL2:
114               return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
115
116             case PT_WORKGRP:
117               return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
118           }
119         }
120         return NULL;
121 }
122
123 REFIID _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
124 {
125         LPPIDLDATA pdata =_ILGetDataPointer(pidl);
126
127         if (pdata)
128         {
129           switch (pdata->type)
130           {
131             case PT_SPECIAL:
132             case PT_MYCOMP:
133               return (REFIID) &(pdata->u.mycomp.guid);
134           }
135         }
136         return NULL;
137 }
138
139 DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
140 {
141         DWORD           dwReturn=0;
142         LPSTR           szSrc;
143         GUID const *    riid;
144         char szTemp[MAX_PATH];
145
146         if (!pidl) return 0;
147
148         if (szOut)
149           *szOut = 0;
150
151         if (_dbg_ILIsDesktop(pidl))
152         {
153          /* desktop */
154           if (szOut) strncpy(szOut, "Desktop", uOutSize);
155           dwReturn = strlen ("Desktop");
156         }
157         else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
158         {
159           /* filesystem */
160           if (szOut) strncpy(szOut, szSrc, uOutSize);
161           dwReturn = strlen(szSrc);
162         }
163         else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
164         {
165           if (szOut)
166             sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
167                  riid->Data1, riid->Data2, riid->Data3,
168                  riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
169                  riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
170           dwReturn = strlen (szTemp);
171         }
172         return dwReturn;
173 }
174
175
176
177
178 void pdump (LPCITEMIDLIST pidl)
179 {
180         LPCITEMIDLIST pidltemp = pidl;
181
182         if (!TRACE_ON(pidl)) return;
183
184         if (! pidltemp)
185         {
186           MESSAGE ("-------- pidl=NULL (Desktop)\n");
187         }
188         else
189         {
190           MESSAGE ("-------- pidl=%p\n", pidl);
191           if (pidltemp->mkid.cb)
192           {
193             do
194             {
195               DWORD dwAttrib = 0;
196               LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
197               DWORD type         = pData->type;
198               LPSTR szLongName   = _dbg_ILGetTextPointer(pidltemp);
199               LPSTR szShortName  = _dbg_ILGetSTextPointer(pidltemp);
200               char szName[MAX_PATH];
201
202               _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
203               if( PT_FOLDER == type)
204                 dwAttrib = pData->u.folder.uFileAttribs;
205               else if( PT_VALUE == type)
206                 dwAttrib = pData->u.file.uFileAttribs;
207
208               MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
209                        pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
210
211               pidltemp = _dbg_ILGetNext(pidltemp);
212
213             } while (pidltemp->mkid.cb);
214           }
215           else
216           {
217             MESSAGE ("empty pidl (Desktop)\n");
218           }
219           pcheck(pidl);
220         }
221 }
222 #define BYTES_PRINTED 32
223 BOOL pcheck (LPCITEMIDLIST pidl)
224 {
225         DWORD type, ret=TRUE;
226         LPCITEMIDLIST pidltemp = pidl;
227
228         if (pidltemp && pidltemp->mkid.cb)
229         { do
230           { type   = _dbg_ILGetDataPointer(pidltemp)->type;
231             switch (type)
232             { case PT_DESKTOP:
233               case PT_MYCOMP:
234               case PT_SPECIAL:
235               case PT_DRIVE:
236               case PT_DRIVE1:
237               case PT_DRIVE2:
238               case PT_DRIVE3:
239               case PT_FOLDER:
240               case PT_VALUE:
241               case PT_FOLDER1:
242               case PT_WORKGRP:
243               case PT_COMP:
244               case PT_NETPROVIDER:
245               case PT_NETWORK:
246               case PT_IESPECIAL1:
247               case PT_RAS_FOLDER:
248               case PT_IESPECIAL2:
249               case PT_SHARE:
250                 break;
251               default:
252               {
253                 char szTemp[BYTES_PRINTED*4 + 1];
254                 int i;
255                 unsigned char c;
256
257                 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
258                 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
259                 {
260                   c = ((unsigned char *)pidltemp)[i];
261
262                   szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
263                   szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
264                   szTemp[i*3+2] = ' ';
265                   szTemp[i+BYTES_PRINTED*3]  =  (c>=0x20 && c <=0x80) ? c : '.';
266                 }
267                 szTemp[BYTES_PRINTED*4] = 0x00;
268                 ERR("unknown IDLIST %p [%p] size=%u type=%lx\n%s\n",pidl, pidltemp, pidltemp->mkid.cb,type, szTemp);
269                 ret = FALSE;
270               }
271             }
272             pidltemp = _dbg_ILGetNext(pidltemp);
273           } while (pidltemp->mkid.cb);
274         }
275         return ret;
276 }
277
278 static char shdebugstr_buf1[100];
279 static char shdebugstr_buf2[100];
280 static char * shdebugstr_buf = shdebugstr_buf1;
281
282 static struct {
283         REFIID  riid;
284         char    *name;
285 } InterfaceDesc[] = {
286         {&IID_IUnknown,                 "IID_IUnknown"},
287         {&IID_IClassFactory,            "IID_IClassFactory"},
288         {&IID_IShellView,               "IID_IShellView"},
289         {&IID_IOleCommandTarget,        "IID_IOleCommandTarget"},
290         {&IID_IDropTarget,              "IID_IDropTarget"},
291         {&IID_IDropSource,              "IID_IDropSource"},
292         {&IID_IViewObject,              "IID_IViewObject"},
293         {&IID_IContextMenu,             "IID_IContextMenu"},
294         {&IID_IShellExtInit,            "IID_IShellExtInit"},
295         {&IID_IShellFolder,             "IID_IShellFolder"},
296         {&IID_IShellFolder2,            "IID_IShellFolder2"},
297         {&IID_IPersist,                 "IID_IPersist"},
298         {&IID_IPersistFolder,           "IID_IPersistFolder"},
299         {&IID_IPersistFolder2,          "IID_IPersistFolder2"},
300         {&IID_IPersistFolder3,          "IID_IPersistFolder3"},
301         {&IID_IExtractIconA,            "IID_IExtractIconA"},
302         {&IID_IExtractIconW,            "IID_IExtractIconW"},
303         {&IID_IDataObject,              "IID_IDataObject"},
304         {NULL,NULL}};
305
306 const char * shdebugstr_guid( const struct _GUID *id )
307 {
308         int i;
309         char* name = NULL;
310         char clsidbuf[100];
311
312         shdebugstr_buf = (shdebugstr_buf == shdebugstr_buf1) ? shdebugstr_buf2 : shdebugstr_buf1;
313
314         if (!id) {
315           strcpy (shdebugstr_buf, "(null)");
316         } else {
317             for (i=0;InterfaceDesc[i].riid && !name;i++) {
318                 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
319             }
320             if (!name) {
321                 if (HCR_GetClassNameA(id, clsidbuf, 100))
322                     name = clsidbuf;
323             }
324
325             sprintf( shdebugstr_buf, "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
326                  id->Data1, id->Data2, id->Data3,
327                  id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
328                  id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
329         }
330         return shdebugstr_buf;
331 }