summaryrefslogblamecommitdiffstats
path: root/public/sdk/inc/ilinkp.hxx
blob: 7229f9f13a5ce60dc6bf753ce69b0222968afc6a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424







































































































































































































































































































































































































































                                                                               
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1992 - 1992.
//
//  File:       ilinkp.hxx
//
//  Contents:   Declarations PRIVATE to link tracking code across
//              multiple Cairo projects.
//              Do not use these declarations without first contacting
//              the current owner of this file.
//
//  Classes:    CTracker              -- base for all tracking links
//              COleTrackingLink      -- base for shell and ole links
//              COleLinkTrackingLink  -- tracking for IOleLink def link
//              COleShellTrackingLink -- tracking for shell ref
//
//  Functions:
//
//  History:    07-Aug-93   BillMo      Created.
//
//  Note:       Id's of source are retrieved only when the source is bound to.
//
//--------------------------------------------------------------------------

#ifndef __ILINKP_HXX__
#define __ILINKP_HXX__

#include <lnkobjid.hxx>

#define ELEMENTS(x) (sizeof(x)/sizeof((x)[0]))
#define WCHARS(x) ELEMENTS(x)
#define ALIGN8(cb) (((cb-1) & (~7)) + 8)

#define WCH_COMP_SEPARATOR L'\\'
#define WCH_ROOT_SEPARATOR L':'

#define USER_REGISTRY_ROOT L"SoftWare\\Microsoft\\LinkSearch"
#define ABSOLUTE_MAX_AUTO    64      // volumes in auto searchlist
#define DEFAULT_MAX_AUTO     10
#define MAX_BROADCASTS       10
#define BROADCAST_REPLY_WAIT 300

#define DEFAULT_GROVEL_MONIKER_SIZE 1024

// new (ExceptOnFail) SFindObjectOut [FSCTL_OUT_BUFFER_SIZE];
#define FSCTL_OUT_BUFFER_SIZE 10

//
// treepatcher won't allow paths > MAX_DOS_NETWORK_PATH
//
#define MAX_DOS_NETWORK_PATH 384
#define MAX_NT_HEADER        20
#define MAX_NT_NETWORK_PATH  (MAX_DOS_NETWORK_PATH + MAX_NT_HEADER)

#define MAX_EMBEDDINGLEVELS  40

#define TREECOPY_PAGESIZE 4096
#define TREEPATCHER_SIG LONGSIG('h','c','p','y')



class CVolume;
class CSearchContext;
class CEmbeddedMonikers;

//--------------------------------------------------------------------------
//
// Currently private definitions that may become public.
//
//--------------------------------------------------------------------------

typedef DWORD HCOPY;

//--------------------------------------------------------------------------
//
// Private error codes.
//
//--------------------------------------------------------------------------

#if !defined(LNK_NO_OLE2)

//
// Error codes (HRESULT)0x80081580 to 0x800815bf are internal
// to link tracking.
//

//
// Generated by CVolume::FindObject to indicate the volume was
// not even searched.
//
#define LINKP_E_VOLUME_NOT_SEARCHED  ((HRESULT)0x80081580)

//
// Generated by objectid.cxx::ReadObjectId(IPropertyStorage*,OBJECTID*)
// as an internal error to GetObjectId.
//
#define LINKP_E_NOSUCHPROPERTY       ((HRESULT)0x80081581)

//
// Generated by CVolume::FindObject to indicate that the volume was
// successfully contacted, but no object with matching id was found.
//
#define LINKP_E_VOLUME_SEARCHED_OBJECT_NOT_FOUND ((HRESULT)0x80081582)

//
// Used in failure testing
//
#define LINKP_E_FAILTEST ((HRESULT)0x80081583)

//
// Returned by ReplaceFileMoniker if there is no file moniker to replace.
//
#define LINKP_E_NOFILEMONIKER ((HRESULT)0x80081584)

//
// IEnumMoniker::Next returned S_FALSE immediately after IMoniker::Enum
// was called successfully.
//
#define LINKP_E_NOMONIKERS    ((HRESULT)0x80081585)

//
// Couldn't rebuild moniker to pseudo-object because there
// weren't enough monikers in the enumeration.
//
#define LINKP_E_RANGE_INACCESSIBLE ((HRESULT) 0x80081586)

//
// The path passed to CPathWalker was too long (i.e. absolute moniker
// path name too long.)
//
#define LINKP_E_INVALID_PATH ((HRESULT) 0x80081587)

//
// The ancestor was not found by CPathWalker
//
#define LINKP_E_ANCESTOR_NOT_FOUND ((HRESULT) 0x80081588)

//
// No object which is the only object with matching lineage and
// last component of name
//
#define LINKP_E_NOLINEAGEMATCH     ((HRESULT) 0x80081589)

//
// No object exactly matches the id
//
#define LINKP_E_NOEXACTMATCH       ((HRESULT) 0x80081589)

//
// No monikers in IMoniker::Enum
//
#define LINKP_E_ENUMEMPTY          ((HRESULT) 0x8008158a)

//
// Too many nesting levels
//
#define LINKP_E_TOOMANYEMBEDDINGLEVELS ((HRESULT) 0x8008158b)

//
// Used when throwing exceptions due to not enough memory
//
#define LINK_E_NOT_ENOUGH_MEMORY \
    (HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY))

#endif // !defined(LNK_NO_OLE2)

//--------------------------------------------------------------------------
//
// Defines for tracker object serialized form
//
//--------------------------------------------------------------------------

#define SHELLMK_SIG        0x0033
#define OLEMK_SIG          0x0022
#define MAX_LINK_EXPANSION 262144

#define LINK_FLAG_DOMAINID 0x00000001
#define LINK_FLAG_VOLUMEID 0x00000002
#define LINK_FLAG_OBJECTID 0x00000004

//--------------------------------------------------------------------------
//
// Function predeclarations
//
//--------------------------------------------------------------------------

void UpdateAutoSearchList(void);

//--------------------------------------------------------------------------
//
// Functions used by DRT.
//
//--------------------------------------------------------------------------

const WCHAR *ObjectIdToString(const OBJECTID &oid);

//+-------------------------------------------------------------------------
//
//  Class:      DFSID
//
//  Purpose:    Encapsulate specifics of DFS domain and volume ids.
//
//--------------------------------------------------------------------------

class DFSID
{
public:
    DFSID()
    {
        Invalidate();
    }
    VOID Invalidate(VOID)
    {
        memset(&g, 0, sizeof(g));
    }
    operator GUID ()
    {
        return(g);
    }
    operator GUID * ()
    {
        return(&g);
    }
    operator == (const DFSID &other)
    {
        return(0 == memcmp(&g, &other.g, sizeof(g)));
    }
    BOOL IsValid(VOID)
    {
        DFSID i;

        return(i != *this);
    }
private:
    GUID g;
};

typedef DFSID DOMAINID;
typedef DFSID VOLUMEID;

//+-------------------------------------------------------------------------
//
//  Class:      CTracker
//
//  Purpose:    Base class for 1. extending Ole links, 2. supporting
//              shell references, 3. supporting win32 links.
//
//              This class contains code common to all types.
//
//  Interface:
//
//  History:    07-Aug-93   BillMo      Created.
//
//  Notes:
//
//--------------------------------------------------------------------------

#if !defined(LNK_NO_OLE2)

// this should be put in its own header
class CTracker
{
public:

            CTracker();

            // assignment operators/ctors needed because of pointer.

            // doesn't copy expansion data
            CTracker(const CTracker &);

            // doesn't overwrite expansion data
            CTracker & CTracker::operator = (const CTracker & t);

            ~CTracker();


    //
    // For OLE2 tracking
    //
    BOOL    operator == (const CTracker &t);
    BOOL    operator != (const CTracker &t);

    HRESULT Load(IStorage *pstg);
    HRESULT Save(IStorage *pstg);
    HRESULT BindToObject(IBindCtx *pbc,
                         IMoniker *pmkToLeft,
                         REFIID    riid,
                         void **   ppv,
                         IMoniker**ppmk);
    HRESULT UpdateIdsFromMoniker(IBindCtx *pbc, IMoniker *pmk);

    //
    // For OLE1 tracking
    //
    VOID    SetObjectId(const OBJECTID &oid);

    //
    // For OLE1 and OLE2 tracking
    //
    HRESULT FindObjectName(CVolume * pVolume,
                           BOOL fHintedVolumeValid,
                           WCHAR ** ppwszPath,
                           CEmbeddedMonikers *pem,
                           CSearchContext *psc,
                           const WCHAR *pwszOriginal);

private:

    HRESULT SaveTrackingInfo(USHORT usSig, LPSTREAM pstm);
    void    Read(LPSTREAM pstm, void *pv, ULONG cbExpected);
    HRESULT LoadTrackingInfo(USHORT usSig, LPSTREAM pstm);
    HRESULT SearchEnumVolumes(CVolume *pVolume,
                              WCHAR **ppwszPath,
                              CEmbeddedMonikers *pem,
                              CSearchContext *psc,
                              const WCHAR *pwszOriginal);
    HRESULT GetEmbeddedObjectsId(IBindCtx *pbc, IMoniker *pmk);
    HRESULT wBindToObject(CSearchContext *psc,
                         IMoniker *pmkToLeft,
                         REFIID    riid,
                         void **   ppv,
                         IMoniker**ppmk);

    HRESULT GetVolume(IBindCtx * pbc, IMoniker *pmkFile, CVolume *pVolume);


    //
    // if persistent data is added, then GetSizeMax must be
    // changed.
    //
    ULONG       _ulFlags;

    DOMAINID    _didDomain;
    VOLUMEID    _vidVolume;
    OBJECTID    _oidFile;
    OBJECTID    _oidEmbed;
    LONG        _cNoStorage;

    // other cairo info

    // expansion data
    ULONG       _cbExpansion;
    BYTE *      _pbExpansion;

};
#endif // !defined(LNK_NO_OLE2)

#if !defined(LNK_NO_NTDEF)
NTSTATUS PatchObjectId(UNICODE_STRING *pus, const OBJECTID &oid);
#endif

// BUGBUG this class definition should be in its own header file
//        when we get rid of lnkfsctl.exe's dependence on lnktrack.dll

#if !defined(LNK_NO_EXCEPTIONS)
//+-------------------------------------------------------------------------
//
//  Class:  CFileHandle
//
//  Purpose:    Handle opening files for caller if necessary.
//
//  Interface:  CFileHandle::CFileHandle  -- Initialize.
//              CFileHandle::Open         -- Open path.
//              CFileHandle::OpenIf       -- Open path if handle is not passed.
//              CFileHandle::~CFileHandle -- Close file if we opened it.
//
//  History:    07-Jun-92   BillMo      Created.
//
//  Notes:      BUGBUG: should probably have a single unwindable object
//                      which contains all these resources.
//
//--------------------------------------------------------------------------

#include <except.hxx>

class CFileHandle
{
public:
            CFileHandle();
            ~CFileHandle();

    NTSTATUS OpenIf(HANDLE           hFile,
                    const WCHAR *    pwszPath,
                    DWORD            dwAccess,
                    DWORD            dwShare);

    NTSTATUS Open(const WCHAR *  pwszDosPath,
                  ACCESS_MASK    AccessMask = GENERIC_READ | SYNCHRONIZE,
                  ULONG          ShareAccess = FILE_SHARE_READ);

    inline  operator HANDLE ();

private:

    HANDLE  _hFile;
    BOOL    _fOpened;
};

//+-------------------------------------------------------------------
//
//  Member:     CFileHandle::operator HANDLE, public
//
//  Synopsis:   Return internal handle.  For HANDLE parameter passing.
//
//  History:    25-Jan-93 BillMo    Created.
//
//  Notes:
//
//--------------------------------------------------------------------

CFileHandle::operator HANDLE (void)
{
    return(_hFile);
}
#endif // !defined(LNK_NO_EXCEPTIONS)

#if !defined(LNK_NO_NTDEF)
VOID PrependNtObjectName(UNICODE_STRING *pus);
#endif

#endif