VirtualBox

Changeset 20851 in vbox


Ignore:
Timestamp:
Jun 23, 2009 3:34:25 PM (15 years ago)
Author:
vboxsync
Message:

Webservice: handle NULL pointer object arguments in methods and return values correctly, both in raw webservice and OO JAX-WS wrappers

Location:
trunk/src/VBox/Main/webservice
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/glue-jaxws.xsl

    r20844 r20851  
    289289             </xsl:call-template>
    290290           </xsl:variable>
    291            <xsl:value-of select="concat('new ', $gluetype, '(', $value,', port)')" />
     291           <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
     292           <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
    292293        </xsl:otherwise>
    293294      </xsl:choose>
  • trunk/src/VBox/Main/webservice/vboxweb.cpp

    r18265 r20851  
    11071107 */
    11081108int ManagedObjectRef::findRefFromId(const WSDLT_ID &id,
    1109                                     ManagedObjectRef **pRef)
     1109                                    ManagedObjectRef **pRef,
     1110                                    bool fNullAllowed)
    11101111{
    11111112    int rc = 0;
     
    11131114    do
    11141115    {
     1116        // allow NULL (== empty string) input reference, which should return a NULL pointer
     1117        if (!id.length() && fNullAllowed)
     1118        {
     1119            *pRef = NULL;
     1120            return 0;
     1121        }
     1122
    11151123        uint64_t sessid;
    11161124        uint64_t objid;
     
    11791187    do {
    11801188        ManagedObjectRef *pRef;
    1181         if (!ManagedObjectRef::findRefFromId(req->_USCOREthis, &pRef))
     1189        if (!ManagedObjectRef::findRefFromId(req->_USCOREthis, &pRef, false))
    11821190            resp->returnval = pRef->getInterfaceName();
    11831191
     
    12101218    do {
    12111219        ManagedObjectRef *pRef;
    1212         if ((rc = ManagedObjectRef::findRefFromId(req->_USCOREthis, &pRef)))
     1220        if ((rc = ManagedObjectRef::findRefFromId(req->_USCOREthis, &pRef, false)))
    12131221        {
    12141222            RaiseSoapInvalidObjectFault(soap, req->_USCOREthis);
  • trunk/src/VBox/Main/webservice/vboxweb.h

    r16301 r20851  
    186186
    187187        static int findRefFromId(const WSDLT_ID &id,
    188                                  ManagedObjectRef **pRef);
     188                                 ManagedObjectRef **pRef,
     189                                 bool fNullAllowed);
    189190
    190191        static ManagedObjectRef* findFromPtr(ComPtr<IUnknown> pcu);
     
    204205 *
    205206 * @param soap
    206  * @param id integer managed object reference, as passed in by web service client
    207  * @param pComPtr reference to COM pointer object that receives the com pointer,
     207 * @param id in: integer managed object reference, as passed in by web service client
     208 * @param pComPtr out: reference to COM pointer object that receives the com pointer,
    208209 *                if SOAP_OK is returned
     210 * @param fNullAllowed in: if true, then this func returns a NULL COM pointer if an
     211 *                empty MOR is passed in (i.e. NULL pointers are allowed). If false,
     212 *                then this fails; this will be false when called for the "this"
     213 *                argument of method calls, which really shouldn't be NULL.
    209214 * @return error code or SOAP_OK if no error
    210215 */
     
    212217int findComPtrFromId(struct soap *soap,
    213218                     const WSDLT_ID &id,
    214                      ComPtr<T> &pComPtr)
     219                     ComPtr<T> &pComPtr,
     220                     bool fNullAllowed)
    215221{
    216222    int rc;
    217223    ManagedObjectRef *pRef;
    218     if ((rc = ManagedObjectRef::findRefFromId(id, &pRef)))
     224    if ((rc = ManagedObjectRef::findRefFromId(id, &pRef, fNullAllowed)))
    219225        RaiseSoapInvalidObjectFault(soap, id);
    220226    else
     
    247253                                   const ComPtr<T> &pc)
    248254{
     255    // NULL comptr should return NULL MOR
     256    if (pc.isNull())
     257    {
     258        WEBDEBUG(("   createOrFindRefFromComPtr(): returning empty MOR for NULL COM pointer\n"));
     259        return "";
     260    }
     261
    249262    WebServiceSession* pSession;
    250263    if ((pSession = WebServiceSession::findSessionFromRef(idParent)))
  • trunk/src/VBox/Main/webservice/websrv-cpp.xsl

    r16602 r20851  
    626626    </xsl:when>
    627627    <xsl:when test="($wsmap='managed')">
    628       <xsl:text>        // look up managed object reference for method call</xsl:text>
    629       <xsl:call-template name="emitNewlineIndent8" />
    630       <xsl:value-of select="concat('ComPtr&lt;', $ifname, '&gt; pObj;')" />
    631       <xsl:call-template name="emitNewlineIndent8" />
    632       <xsl:value-of select="concat('if (!', $G_requestElementVarName, ')')" />
    633       <xsl:call-template name="emitNewlineIndent8" />
    634       <xsl:text>{</xsl:text>
    635       <xsl:call-template name="emitNewlineIndent8" />
    636       <xsl:text>    RaiseSoapInvalidObjectFault(soap, "");</xsl:text>
    637       <xsl:call-template name="emitNewlineIndent8" />
    638       <xsl:text>    break;</xsl:text>
    639       <xsl:call-template name="emitNewlineIndent8" />
    640       <xsl:text>}</xsl:text>
    641       <xsl:call-template name="emitNewlineIndent8" />
    642       <xsl:value-of select="concat('const WSDLT_ID &amp;idThis = ', $structprefix, $G_nameObjectRefEncoded, ';')" />
    643       <xsl:call-template name="emitNewlineIndent8" />
    644       <xsl:value-of select="'if ((rc = findComPtrFromId(soap, idThis, pObj)))'" />
    645       <xsl:call-template name="emitNewlineIndent8" />
    646       <xsl:text>    break;</xsl:text>
    647       <xsl:call-template name="emitNewline" />
     628      <xsl:text>        // look up managed object reference for method call&#10;</xsl:text>
     629      <xsl:value-of select="concat('        ComPtr&lt;', $ifname, '&gt; pObj;&#10;')" />
     630      <xsl:value-of select="concat('        if (!', $G_requestElementVarName, ')&#10;')" />
     631      <xsl:text>        {&#10;</xsl:text>
     632      <xsl:text>            RaiseSoapInvalidObjectFault(soap, "");&#10;</xsl:text>
     633      <xsl:text>            break;&#10;</xsl:text>
     634      <xsl:text>        }&#10;</xsl:text>
     635      <xsl:value-of select="concat('        const WSDLT_ID &amp;idThis = ', $structprefix, $G_nameObjectRefEncoded, ';&#10;')" />
     636      <xsl:value-of select="'        if ((rc = findComPtrFromId(soap, idThis, pObj, false)))&#10;'" />
     637      <xsl:text>            break;&#10;</xsl:text>
    648638    </xsl:when>
    649639  </xsl:choose>
     
    687677          <xsl:value-of select="'    ComPtr&lt;IUnknown&gt; tmpObject;'" />
    688678          <xsl:call-template name="emitNewlineIndent8" />
    689           <xsl:value-of select="concat('    if ((rc = findComPtrFromId(soap, ', $structprefix, $name, '[i], tmpObject)))')" />
     679          <xsl:value-of select="concat('    if ((rc = findComPtrFromId(soap, ', $structprefix, $name, '[i], tmpObject, true)))')" />
    690680          <xsl:call-template name="emitNewlineIndent8" />
    691681          <xsl:text>        break;</xsl:text>
     
    740730          <xsl:value-of select="concat(' comcall_', $name, ';')" />
    741731          <xsl:call-template name="emitNewlineIndent8" />
    742           <xsl:value-of select="concat('if ((rc = findComPtrFromId(soap, ', $structprefix, $name, ', comcall_', $name,')))')" />
     732          <xsl:value-of select="concat('if ((rc = findComPtrFromId(soap, ', $structprefix, $name, ', comcall_', $name,', true)))')" />
    743733          <xsl:call-template name="emitNewlineIndent8" />
    744734          <xsl:text>    break</xsl:text>
     
    758748              <xsl:value-of select="concat(' comcall_', $name, ';')" />
    759749              <xsl:call-template name="emitNewlineIndent8" />
    760               <xsl:value-of select="concat('if ((rc = findComPtrFromId(soap, ', $structprefix, $name, ', comcall_', $name,')))')" />
     750              <xsl:value-of select="concat('if ((rc = findComPtrFromId(soap, ', $structprefix, $name, ', comcall_', $name,', true)))')" />
    761751              <xsl:call-template name="emitNewlineIndent8" />
    762752              <xsl:text>    break</xsl:text>
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette