summaryrefslogtreecommitdiffstats
path: root/private/ole32/dcomss/objex/shrmem/dcom95/mid.hxx
blob: b16526e9801f9ca41c15820143aefea6586b2be6 (plain) (blame)
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
/*++

Copyright (c) 1995 Microsoft Corporation

Module Name:

    Mid.hxx

Abstract:

   Class representing string bindings and security bindings for a particular 
   machine.  Provides a mapping between the bindings and a local machine 
   unique ID for that machine.  


Author:

    Mario Goertzel    [MarioGo]

Revision History:

    MarioGo     12-13-95    Bits 'n pieces

--*/

#ifndef __MID_HXX
#define __MID_HXX

class CResolverHandle : public CTableElement 
{
public:

    CResolverHandle(MID id, BOOL fSecure)
    {
        _Key.Init(id);
        _hOR = NULL;
        _fSecure = fSecure;
    }

    ~CResolverHandle()
    {
        Clear();
    }

    void Clear()
    {
        if (_hOR != NULL)
        {
            RpcBindingFree(&_hOR);
            _hOR = NULL;
        }
    }

    ORSTATUS Reset(RPC_BINDING_HANDLE hIn)
    {
        ASSERT(hIn != NULL);
        Clear();

        if (_fSecure)
        {
            RPC_STATUS status = RpcBindingSetAuthInfo(hIn,
                                           0,
                                           RPC_C_AUTHN_LEVEL_CONNECT,
                                           RPC_C_AUTHN_WINNT,
                                           0,
                                           0);

            if (status != RPC_S_OK)
            {
                ComDebOut((DEB_OXID,"OR: RpcBindingSetAuthInfo failed for OR handle with %d\n",
                           status));

                // Just fall back on unsecure.
            }
        }

        return RpcBindingCopy(hIn,&_hOR);
    }

    virtual operator ISearchKey&()
    {
        return _Key;
    }

    operator RPC_BINDING_HANDLE&()
    {
        return _hOR;
    }

private:

    CIdKey              _Key;
    RPC_BINDING_HANDLE  _hOR;
    BOOL                _fSecure;
};



DEFINE_TABLE(CResolverHandle)

typedef CDSA CMidKey;

class CMid : public CTableElement
/*++

Class Description:

    Represents the local and remote machines.  Each unique (different)
    set of string bindings and security bindings are assigned a unique
    local ID.  This ID is used along with the OID and OXID of the remote
    machine objects index these objects locally.  Instances of this class
    are referenced by COids.

    This class is indexed by string and security bindings.  There is no
    index by MID.
    
Members:

    _id - The locally unique ID of this set of bindings.

    _iStringBinding - Index into _dsa->aStringArray of the
        compressed string binding used to create a handle.

    _iSecurityBinding - Index into _dsaSecurityArray of the

    _dsa - The set of compressed bindings.

--*/
{

public:

    CMid(
      DUALSTRINGARRAY *pdsa, 
      ORSTATUS& status,
      USHORT wProtSeq                 // if the SCM tells us what to use
      ) :
        _id(AllocateId()),
        _iStringBinding(0),
        _iSecurityBinding(0),
        _fBindingWorking(FALSE),
        _dsa(pdsa,TRUE,status),
        _setID(0)
     {
            if (wProtSeq > 0)
            {
                PWSTR pwstr = FindMatchingProtseq(wProtSeq,pdsa->aStringArray);

                if (NULL != pwstr)
                {
                    _iStringBinding = pwstr - pdsa->aStringArray;
                }
            }
     }

    ~CMid() 
    {
        if (gpMidTable != NULL)  // this might happen during initialization 
        {                        // of globals, e.g., gpLocalMid
            gpMidTable->Remove(*this);
        }
    }

	void * operator new(size_t s)
	{
		return OrMemAlloc(s);
	}

	void * operator new(size_t s, size_t extra)
	{
		return OrMemAlloc(s+extra);
	}

	void operator delete(void * p)	  // do not inherit this!
	{
		OrMemFree(p);
	}

    operator ISearchKey&()                     // allows us to be a ISearchKey
    {
        return _dsa;
    }

    virtual BOOL
    Compare(ISearchKey &tk) 
    {
        return(_dsa.Compare(tk));
    }


    DUALSTRINGARRAY *
    GetStrings() 
    {
        return(_dsa);
    }

    USHORT ProtseqOfServer() 
    {
        if (_fBindingWorking)
        {
            return(_dsa->aStringArray[_iStringBinding]);
        }
        else
        {
            return(0);
        }
    }

    BOOL IsLocal() 
    {
        return (_id == gLocalMID);
    }

    MID GetMID() 
    {
        return(_id);
    }

    ORSTATUS PingServer();

    ORSTATUS AddClientOid(COid *pOid)
    {
        ORSTATUS status = OR_OK;

        // this way, we have the same number of refs on the Oid
        // as we would if we were already pinging it.  The ref is
        // held by the _addOidList instead of the _pingSet

        if (_pingSet.Lookup(*pOid) == NULL)
        {
            _addOidList.Insert(status,pOid);   
        }

        return status;
    }

    ORSTATUS DropClientOid(COid *pOid)
    {
        ORSTATUS status = OR_OK;
        COid *pt;

        // this way, we have the same number of refs on the Oid
        // as we would if we were already pinging it.  The ref is
        // held by the _addOidList instead of the _pingSet

        if ((pt = _pingSet.Remove(*pOid)) == pOid)
        {
            _dropOidList.Insert(status,pOid);   
        }
        else if (pt == NULL)
        {
             ComDebOut((DEB_OXID,"Trying to stop pinging OID not belonging to MID=%08x",_id));
             ASSERT(0);
        }
        else
        {
            ComDebOut((DEB_OXID,"Trying to stop pinging bogus COid object at MID=%08x",_id));
            ASSERT(0);
        }

        return status;
    }

    ORSTATUS ResolveRemoteOxid(
        OXID Oxid,
        OXID_INFO *poxidInfo
        );

#if DBG
    PWSTR PrintableName() 
    {
        return(&_dsa->aStringArray[_iStringBinding + 1]);
    }
#endif

private:

    friend class COrBindingIterator;

    ID                  _id;
    USHORT              _iStringBinding;
    USHORT              _iSecurityBinding;
    CDSA                _dsa;
    BOOL                _fBindingWorking;

    COidTable           _pingSet;
    COidList            _addOidList;
    COidList            _dropOidList;
    ID                  _setID;
    USHORT              _sequenceNum;
    USHORT              _pingBackoffFactor;

};

DEFINE_TABLE(CMid)


class COrBindingIterator
{
public:

    COrBindingIterator(
        CMid *pMid,
        ORSTATUS &status
        );

    RPC_BINDING_HANDLE First()
    {
        RPC_BINDING_HANDLE hMachine = *_pCurrentHandle;   // auto conversion

        if (hMachine != NULL)
        {
            return hMachine;    // Already have one, so try it
        }
        else
        {
            return Next();
        }
    }

    RPC_BINDING_HANDLE Next();

private:

    CMid             *_pMid;
    CBindingIterator  _bIter;   
    CResolverHandle  *_pCurrentHandle;
};

#endif // __MID_HXX