VirtualBox

Changeset 73839 in vbox for trunk/src


Ignore:
Timestamp:
Aug 22, 2018 4:45:17 PM (6 years ago)
Author:
vboxsync
Message:

http-curl.c: Factor out CURLcode rtHttpSetWriteCallback() and use it
both for the public RTHttpSetWriteCallback and internally. Fix
internal callbacks singatures to match FNRTHTTPWRITECALLBACK (i.e.
curl_write_callback) - the buffer parameter is char *, not void *.

No functional change intended.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/http-curl.cpp

    r73837 r73839  
    259259static int rtHttpDarwinTryConfigProxies(PRTHTTPINTERNAL pThis, CFArrayRef hArrayProxies, CFURLRef hUrlTarget, bool fIgnorePacType);
    260260#endif
     261static CURLcode rtHttpSetWriteCallback(PRTHTTPINTERNAL pThis, PFNRTHTTPWRITECALLBACK pfnWrite, void *pvUser);
    261262
    262263
     
    22992300 * cURL callback for writing data.
    23002301 */
    2301 static size_t rtHttpWriteData(void *pvBuf, size_t cbUnit, size_t cUnits, void *pvUser)
     2302static size_t rtHttpWriteData(char *pcBuf, size_t cbUnit, size_t cUnits, void *pvUser)
    23022303{
    23032304    PRTHTTPINTERNAL pThis = (PRTHTTPINTERNAL)pvUser;
     
    23142315        if (cbNewSize + 1 <= pThis->Output.Mem.cbAllocated)
    23152316        {
    2316             memcpy(&pThis->Output.Mem.pb[cbCurSize], pvBuf, cbToAppend);
     2317            memcpy(&pThis->Output.Mem.pb[cbCurSize], pcBuf, cbToAppend);
    23172318            pThis->Output.Mem.cb = cbNewSize;
    23182319            pThis->Output.Mem.pb[cbNewSize] = '\0';
     
    23322333        if (pbNew)
    23332334        {
    2334             memcpy(&pbNew[cbCurSize], pvBuf, cbToAppend);
     2335            memcpy(&pbNew[cbCurSize], pcBuf, cbToAppend);
    23352336            pbNew[cbNewSize] = '\0';
    23362337
     
    24022403    {
    24032404        RT_ZERO(pThis->Output.Mem);
    2404         int rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteData);
    2405         if (!CURL_FAILURE(rcCurl))
    2406             rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEDATA, (void *)pThis);
     2405        int rcCurl = rtHttpSetWriteCallback(pThis, &rtHttpWriteData, (void *)pThis);
    24072406        if (fNoBody)
    24082407        {
     
    25082507 * cURL callback for writing data to a file.
    25092508 */
    2510 static size_t rtHttpWriteDataToFile(void *pvBuf, size_t cbUnit, size_t cUnits, void *pvUser)
     2509static size_t rtHttpWriteDataToFile(char *pcBuf, size_t cbUnit, size_t cUnits, void *pvUser)
    25112510{
    25122511    PRTHTTPINTERNAL pThis = (PRTHTTPINTERNAL)pvUser;
    25132512    size_t cbWritten = 0;
    2514     int rc = RTFileWrite(pThis->Output.hFile, pvBuf, cbUnit * cUnits, &cbWritten);
     2513    int rc = RTFileWrite(pThis->Output.hFile, pcBuf, cbUnit * cUnits, &cbWritten);
    25152514    if (RT_SUCCESS(rc))
    25162515        return cbWritten;
     
    25442543    {
    25452544        pThis->Output.hFile = NIL_RTFILE;
    2546         int rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteDataToFile);
    2547         if (!CURL_FAILURE(rcCurl))
    2548             rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEDATA, (void *)pThis);
     2545        int rcCurl = rtHttpSetWriteCallback(pThis, &rtHttpWriteDataToFile, (void *)pThis);
    25492546        if (!CURL_FAILURE(rcCurl))
    25502547        {
     
    26092606
    26102607
     2608static CURLcode rtHttpSetWriteCallback(PRTHTTPINTERNAL pThis, PFNRTHTTPWRITECALLBACK pfnWrite, void *pvUser)
     2609{
     2610    CURLcode rcCurl;
     2611
     2612    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEFUNCTION, pfnWrite);
     2613    if (CURL_FAILURE(rcCurl))
     2614        return rcCurl;
     2615
     2616    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEDATA, pvUser);
     2617    if (CURL_FAILURE(rcCurl))
     2618        return rcCurl;
     2619
     2620    return rcCurl;
     2621}
     2622
     2623
    26112624RTR3DECL(int) RTHttpSetWriteCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACK pfnWrite, void *pvUser)
    26122625{
    2613     CURLcode rcCurl;
    2614 
    26152626    PRTHTTPINTERNAL pThis = hHttp;
    26162627    RTHTTP_VALID_RETURN(pThis);
    26172628
    2618     rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEFUNCTION, pfnWrite);
    2619     if (CURL_FAILURE(rcCurl))
    2620         return VERR_HTTP_CURL_ERROR;
    2621 
    2622     rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEDATA, pvUser);
     2629    CURLcode rcCurl = rtHttpSetWriteCallback(pThis, pfnWrite, pvUser);
    26232630    if (CURL_FAILURE(rcCurl))
    26242631        return VERR_HTTP_CURL_ERROR;
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