VirtualBox

Changeset 87042 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Dec 4, 2020 12:10:36 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141732
Message:

Shared Clipboard/Transfers: More cleanup / documentation work. bugref:9874

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/http-server.cpp

    r87041 r87042  
    328328
    329329/**
     330 * Initializes a HTTP body.
     331 *
     332 * @param   pBody               Body to initialize.
     333 * @param   cbSize              Size of body (in bytes) to allocate. Optional and can be 0.
     334 */
     335static int rtHttpServerBodyInit(PRTHTTPBODY pBody, size_t cbSize)
     336{
     337    if (cbSize)
     338    {
     339        pBody->pvBody      = RTMemAlloc(cbSize);
     340        AssertPtrReturn(pBody->pvBody, VERR_NO_MEMORY);
     341        pBody->cbBodyAlloc = cbSize;
     342    }
     343    else
     344    {
     345        pBody->pvBody      = NULL;
     346        pBody->cbBodyAlloc = 0;
     347    }
     348
     349    pBody->cbBodyUsed = 0;
     350    pBody->offBody    = 0;
     351
     352    return VINF_SUCCESS;
     353}
     354
     355/**
     356 * Destroys a HTTP body.
     357 *
     358 * @param   pBody               Body to destroy.
     359 */
     360static void rtHttpServerBodyDestroy(PRTHTTPBODY pBody)
     361{
     362    if (!pBody)
     363        return;
     364
     365    if (pBody->pvBody)
     366    {
     367        Assert(pBody->cbBodyAlloc);
     368
     369        RTMemFree(pBody->pvBody);
     370        pBody->pvBody = NULL;
     371    }
     372
     373    pBody->cbBodyAlloc  = 0;
     374    pBody->cbBodyUsed   = 0;
     375    pBody->offBody      = 0;
     376}
     377
     378/**
    330379 * Allocates and initializes a new client request.
    331380 *
     
    341390    AssertRC(rc2);
    342391
     392    rc2 = rtHttpServerBodyInit(&pReq->Body, 0 /* cbSize */);
     393    AssertRC(rc2);
     394
    343395    return pReq;
    344396}
     
    356408    RTHttpHeaderListDestroy(pReq->hHdrLst);
    357409
    358     RTMemFree(pReq->pvBody);
    359     pReq->pvBody = NULL;
     410    rtHttpServerBodyDestroy(&pReq->Body);
    360411
    361412    RTMemFree(pReq);
     
    376427    AssertRCReturn(rc, rc);
    377428
    378     if (cbBody)
    379     {
    380         pResp->pvBody      = RTMemAlloc(cbBody);
    381         AssertPtrReturn(pResp->pvBody, VERR_NO_MEMORY);
    382         pResp->cbBodyAlloc = cbBody;
    383     }
    384     else
    385     {
    386         pResp->cbBodyAlloc = 0;
    387     }
    388 
    389     pResp->cbBodyUsed = 0;
     429    rc = rtHttpServerBodyInit(&pResp->Body, cbBody);
    390430
    391431    return rc;
     
    417457    RTHttpHeaderListDestroy(pResp->hHdrLst);
    418458
    419     if (pResp->pvBody)
    420     {
    421         Assert(pResp->cbBodyAlloc);
    422 
    423         RTMemFree(pResp->pvBody);
    424         pResp->pvBody = NULL;
    425     }
    426 
    427     pResp->cbBodyAlloc = 0;
    428     pResp->cbBodyUsed  = 0;
     459    rtHttpServerBodyDestroy(&pResp->Body);
    429460}
    430461
Note: See TracChangeset for help on using the changeset viewer.

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