~ubuntu-branches/ubuntu/oneiric/virtualbox-ose/oneiric

« back to all changes in this revision

Viewing changes to src/VBox/Main/webservice/vboxweb.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * vboxweb.h:
3
3
 *      header file for "real" web server code.
4
4
 *
5
 
 * Copyright (C) 2006-2010 Oracle Corporation
 
5
 * Copyright (C) 2006-2011 Oracle Corporation
6
6
 *
7
7
 * This file is part of VirtualBox Open Source Edition (OSE), as
8
8
 * available from http://www.virtualbox.org. This file is free software;
40
40
 
41
41
/****************************************************************************
42
42
 *
 
43
 * typedefs
 
44
 *
 
45
 ****************************************************************************/
 
46
 
 
47
// type used by gSOAP-generated code
 
48
typedef std::string WSDLT_ID;               // combined managed object ref (session ID plus object ID)
 
49
typedef std::string vbox__uuid;
 
50
 
 
51
/****************************************************************************
 
52
 *
43
53
 * global variables
44
54
 *
45
55
 ****************************************************************************/
46
56
 
47
 
extern ComPtr<IVirtualBox> g_pVirtualBox;
48
57
extern bool g_fVerbose;
49
58
 
50
59
extern PRTSTREAM g_pstrLog;
52
61
extern util::WriteLockHandle  *g_pAuthLibLockHandle;
53
62
extern util::WriteLockHandle  *g_pSessionsLockHandle;
54
63
 
55
 
/****************************************************************************
56
 
 *
57
 
 * typedefs
58
 
 *
59
 
 ****************************************************************************/
60
 
 
61
 
// type used by gSOAP-generated code
62
 
typedef std::string WSDLT_ID;               // combined managed object ref (session ID plus object ID)
63
 
typedef std::string vbox__uuid;
 
64
extern const WSDLT_ID          g_EmptyWSDLID;
64
65
 
65
66
/****************************************************************************
66
67
 *
70
71
 
71
72
void RaiseSoapInvalidObjectFault(struct soap *soap, WSDLT_ID obj);
72
73
 
73
 
void RaiseSoapRuntimeFault(struct soap *soap, HRESULT apirc, IUnknown *pObj);
 
74
void RaiseSoapRuntimeFault2(struct soap *soap, HRESULT apirc, IUnknown *pObj, const com::Guid &iid);
 
75
 
 
76
/**
 
77
 * Template function called everywhere from methodmaps.cpp which calls
 
78
 * RaiseSoapRuntimeFault2() with the correct COM interface ID.
 
79
 * @param soap
 
80
 * @param apirc
 
81
 * @param pObj
 
82
 */
 
83
template <class T>
 
84
void RaiseSoapRuntimeFault(struct soap *soap, HRESULT apirc, const ComPtr<T> &pObj)
 
85
{
 
86
    RaiseSoapRuntimeFault2(soap, apirc, pObj, COM_IIDOF(T));
 
87
}
74
88
 
75
89
/****************************************************************************
76
90
 *
118
132
        ~WebServiceSession();
119
133
 
120
134
        int authenticate(const char *pcszUsername,
121
 
                         const char *pcszPassword);
 
135
                         const char *pcszPassword,
 
136
                         IVirtualBox **ppVirtualBox);
122
137
 
123
 
        ManagedObjectRef* findRefFromPtr(const ComPtr<IUnknown> &pcu);
 
138
        ManagedObjectRef* findRefFromPtr(const IUnknown *pObject);
124
139
 
125
140
        uint64_t getID() const
126
141
        {
127
142
            return _uSessionID;
128
143
        }
129
144
 
130
 
        WSDLT_ID getSessionObject() const;
 
145
        const WSDLT_ID& getSessionWSDLID() const;
131
146
 
132
147
        void touch();
133
148
 
156
171
        // owning session:
157
172
        WebServiceSession           &_session;
158
173
 
159
 
        // value:
160
 
        ComPtr<IUnknown>            _pObj;
161
 
        const char                  *_pcszInterface;
 
174
 
 
175
        IUnknown                    *_pobjUnknown;          // pointer to IUnknown interface for this MOR
 
176
 
 
177
        void                        *_pobjInterface;        // pointer to COM interface represented by _guidInterface, for which this MOR
 
178
                                                            // was created; this may be an IUnknown or something more specific
 
179
        com::Guid                   _guidInterface;         // the interface which _pvObj represents
 
180
 
 
181
        const char                  *_pcszInterface;        // string representation of that interface (e.g. "IMachine")
162
182
 
163
183
        // keys:
164
184
        uint64_t                    _id;
169
189
 
170
190
    public:
171
191
        ManagedObjectRef(WebServiceSession &session,
172
 
                         const char *pcszInterface,
173
 
                         const ComPtr<IUnknown> &obj);
 
192
                         IUnknown *pobjUnknown,
 
193
                         void *pobjInterface,
 
194
                         const com::Guid &guidInterface,
 
195
                         const char *pcszInterface);
174
196
        ~ManagedObjectRef();
175
197
 
176
198
        uint64_t getID()
178
200
            return _id;
179
201
        }
180
202
 
181
 
        ComPtr<IUnknown> getComPtr()
182
 
        {
183
 
            return _pObj;
184
 
        }
185
 
 
186
 
        WSDLT_ID toWSDL() const;
 
203
        /**
 
204
         * Returns the contained COM pointer and the UUID of the COM interface
 
205
         * which it supports.
 
206
         * @param
 
207
         * @return
 
208
         */
 
209
        const com::Guid& getPtr(void **ppobjInterface,
 
210
                                IUnknown **ppobjUnknown)
 
211
        {
 
212
            *ppobjInterface = _pobjInterface;
 
213
            *ppobjUnknown = _pobjUnknown;
 
214
            return _guidInterface;
 
215
        }
 
216
 
 
217
        /**
 
218
         * Returns the ID of this managed object reference to string
 
219
         * form, for returning with SOAP data or similar.
 
220
         *
 
221
         * @return The ID in string form.
 
222
         */
 
223
        const WSDLT_ID& getWSDLID() const
 
224
        {
 
225
            return _strID;
 
226
        }
 
227
 
187
228
        const char* getInterfaceName() const
188
229
        {
189
230
            return _pcszInterface;
201
242
 
202
243
/**
203
244
 * Template function that resolves a managed object reference to a COM pointer
204
 
 * of the template class T. Gets called from tons of generated code in
205
 
 * methodmaps.cpp.
 
245
 * of the template class T.
 
246
 *
 
247
 * This gets called only from tons of generated code in methodmaps.cpp to
 
248
 * resolve objects in *input* parameters to COM methods (i.e. translate
 
249
 * MOR strings to COM objects which should exist already).
206
250
 *
207
251
 * This is a template function so that we can support ComPtr's for arbitrary
208
252
 * interfaces and automatically verify that the managed object reference on
209
 
 * the internal stack actually is of the expected interface.
 
253
 * the internal stack actually is of the expected interface. We also now avoid
 
254
 * calling QueryInterface for the case that the interface desired by the caller
 
255
 * is the same as the interface for which the MOR was originally created. In
 
256
 * that case, the lookup is very fast.
210
257
 *
211
258
 * @param soap
212
259
 * @param id in: integer managed object reference, as passed in by web service client
230
277
    int rc;
231
278
    ManagedObjectRef *pRef;
232
279
    if ((rc = ManagedObjectRef::findRefFromId(id, &pRef, fNullAllowed)))
 
280
        // error:
233
281
        RaiseSoapInvalidObjectFault(soap, id);
234
282
    else
235
283
    {
236
284
        if (fNullAllowed && pRef == NULL)
237
285
        {
 
286
            WEBDEBUG(("   %s(): returning NULL object as permitted\n", __FUNCTION__));
238
287
            pComPtr.setNull();
239
288
            return 0;
240
289
        }
241
290
 
242
 
        // pRef->getComPtr returns a ComPtr<IUnknown>; by casting it to
243
 
        // ComPtr<T>, we implicitly do a COM queryInterface() call
244
 
        if (pComPtr = pRef->getComPtr())
245
 
            return 0;
 
291
        const com::Guid &guidCaller = COM_IIDOF(T);
 
292
 
 
293
        // pRef->getPtr returns both a void* for its specific interface pointer as well as a generic IUnknown*
 
294
        void *pobjInterface;
 
295
        IUnknown *pobjUnknown;
 
296
        const com::Guid &guidInterface = pRef->getPtr(&pobjInterface, &pobjUnknown);
 
297
 
 
298
        if (guidInterface == guidCaller)
 
299
        {
 
300
            // same interface: then no QueryInterface needed
 
301
            WEBDEBUG(("   %s(): returning original %s*=0x%lX (IUnknown*=0x%lX)\n", __FUNCTION__, pRef->getInterfaceName(), pobjInterface, pobjUnknown));
 
302
            pComPtr = (T*)pobjInterface;        // this calls AddRef() once
 
303
            return 0;
 
304
        }
 
305
 
 
306
        // QueryInterface tests whether p actually supports the templated T interface desired by caller
 
307
        T *pT;
 
308
        pobjUnknown->QueryInterface(guidCaller.ref(), (void**)&pT);      // this adds a reference count
 
309
        if (pT)
 
310
        {
 
311
            // assign to caller's ComPtr<T>; use asOutParam() to avoid adding another reference, QueryInterface() already added one
 
312
            WEBDEBUG(("   %s(): returning pointer 0x%lX for queried interface %RTuuid (IUnknown*=0x%lX)\n", __FUNCTION__, pT, guidCaller.raw(), pobjUnknown));
 
313
            *(pComPtr.asOutParam()) = pT;
 
314
            return 0;
 
315
        }
246
316
 
247
317
        WEBDEBUG(("    Interface not supported for object reference %s, which is of class %s\n", id.c_str(), pRef->getInterfaceName()));
248
318
        rc = VERR_WEB_UNSUPPORTED_INTERFACE;
253
323
}
254
324
 
255
325
/**
256
 
 * Template function that creates a new managed object for the given COM
257
 
 * pointer of the template class T. If a reference already exists for the
258
 
 * given pointer, then that reference's ID is returned instead.
 
326
 * Creates a new managed object for the given COM pointer. If a reference already exists
 
327
 * for the given pointer, then that reference's ID is returned instead.
 
328
 *
 
329
 * This gets called from tons of generated code in methodmaps.cpp to
 
330
 * resolve objects *returned* from COM methods (i.e. create MOR strings from COM objects
 
331
 * which might have been newly created).
259
332
 *
260
333
 * @param idParent managed object reference of calling object; used to extract session ID
261
334
 * @param pc COM object for which to create a reference
262
335
 * @return existing or new managed object reference
263
336
 */
264
337
template <class T>
265
 
WSDLT_ID createOrFindRefFromComPtr(const WSDLT_ID &idParent,
266
 
                                   const char *pcszInterface,
267
 
                                   const ComPtr<T> &pc)
 
338
const WSDLT_ID& createOrFindRefFromComPtr(const WSDLT_ID &idParent,
 
339
                                          const char *pcszInterface,
 
340
                                          ComPtr<T> &pc)
268
341
{
269
342
    // NULL comptr should return NULL MOR
270
343
    if (pc.isNull())
271
344
    {
272
 
        WEBDEBUG(("   createOrFindRefFromComPtr(): returning empty MOR for NULL %s pointer\n", pcszInterface));
273
 
        return "";
 
345
        WEBDEBUG(("   createOrFindRefFromComPtr(): returning empty MOR for NULL COM pointer\n"));
 
346
        return g_EmptyWSDLID;
274
347
    }
275
348
 
276
349
    util::AutoWriteLock lock(g_pSessionsLockHandle COMMA_LOCKVAL_SRC_POS);
277
350
    WebServiceSession *pSession;
278
351
    if ((pSession = WebServiceSession::findSessionFromRef(idParent)))
279
352
    {
280
 
        // WEBDEBUG(("\n-- found session for %s\n", idParent.c_str()));
281
353
        ManagedObjectRef *pRef;
282
 
        if (    ((pRef = pSession->findRefFromPtr(pc)))
283
 
             || ((pRef = new ManagedObjectRef(*pSession, pcszInterface, pc)))
 
354
 
 
355
        // we need an IUnknown pointer for the MOR
 
356
        ComPtr<IUnknown> pobjUnknown = pc;
 
357
 
 
358
        if (    ((pRef = pSession->findRefFromPtr(pobjUnknown)))
 
359
             || ((pRef = new ManagedObjectRef(*pSession,
 
360
                                              pobjUnknown,          // IUnknown *pobjUnknown
 
361
                                              pc,                   // void *pobjInterface
 
362
                                              COM_IIDOF(T),
 
363
                                              pcszInterface)))
284
364
           )
285
 
            return pRef->toWSDL();
 
365
            return pRef->getWSDLID();
286
366
    }
287
367
 
288
368
    // session has expired, return an empty MOR instead of allocating a
289
369
    // new reference which couldn't be used anyway.
290
 
    return "";
 
370
    return g_EmptyWSDLID;
291
371
}
292