VirtualBox

Changeset 102816 in vbox


Ignore:
Timestamp:
Jan 10, 2024 1:46:14 PM (11 months ago)
Author:
vboxsync
Message:

Shared Clipboard/Transfers: Added ShClTransferHttpConvertToStringList(). bugref:9437

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/SharedClipboard-transfers.h

    r100676 r102816  
    12451245char *ShClTransferHttpServerGetAddressA(PSHCLHTTPSERVER pSrv);
    12461246char *ShClTransferHttpServerGetUrlA(PSHCLHTTPSERVER pSrv, SHCLTRANSFERID idTransfer, uint64_t idxEntry);
     1247int ShClTransferHttpConvertToStringList(PSHCLHTTPSERVER pSrv, PSHCLTRANSFER pTransfer, char **ppszData, size_t *pcbData);
    12471248bool ShClTransferHttpServerIsInitialized(PSHCLHTTPSERVER pSrv);
    12481249bool ShClTransferHttpServerIsRunning(PSHCLHTTPSERVER pSrv);
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-transfers-http.cpp

    r102566 r102816  
    12451245
    12461246/**
     1247 * Converts a HTTP transfer to a string list.
     1248 *
     1249 * @returns VBox status code.
     1250 * @param   pHttpSrv            HTTP server that contains the transfer.
     1251 * @param   pTransfer           Transfer to convert data from.
     1252 * @param   pszSep              Separator to use for the transfer entries.
     1253 * @param   ppszData            Where to store the string list on success.
     1254 * @param   pcbData             Where to return the bytes of \a ppszData on success.
     1255 *                              Includes terminator. Optional.
     1256 */
     1257static int shClTransferHttpConvertToStringListEx(PSHCLHTTPSERVER pSrv, PSHCLTRANSFER pTransfer, const char *pszSep,
     1258                                                 char **ppszData, size_t *pcbData)
     1259{
     1260    AssertPtrReturn(pTransfer, VERR_INVALID_POINTER);
     1261    AssertPtrReturn(pszSep, VERR_INVALID_POINTER);
     1262    AssertPtrReturn(ppszData, VERR_INVALID_POINTER);
     1263    /* pcbData is optional. */
     1264
     1265    int   rc      = VINF_SUCCESS;
     1266    char *pszData = NULL;
     1267
     1268    uint64_t const cRoots = ShClTransferRootsCount(pTransfer);
     1269    for (uint32_t i = 0; i < cRoots; i++)
     1270    {
     1271        char *pszEntry = ShClTransferHttpServerGetUrlA(pSrv, ShClTransferGetID(pTransfer), i /* Entry index */);
     1272        AssertPtrBreakStmt(pszEntry, rc = VERR_NO_MEMORY);
     1273
     1274        if (i > 0)
     1275        {
     1276            rc = RTStrAAppend(&pszData, pszSep); /* Separate entries with a newline. */
     1277            AssertRCBreak(rc);
     1278        }
     1279
     1280        rc = RTStrAAppend(&pszData, pszEntry);
     1281        AssertRCBreak(rc);
     1282
     1283        RTStrFree(pszEntry);
     1284    }
     1285
     1286    if (RT_FAILURE(rc))
     1287    {
     1288        RTStrFree(pszData);
     1289        return rc;
     1290    }
     1291
     1292    *ppszData = pszData;
     1293    if (pcbData)
     1294        *pcbData = RTStrNLen(pszData, RTSTR_MAX) + 1 /* Terminator. */;
     1295
     1296    return VINF_SUCCESS;
     1297}
     1298
     1299/**
     1300 * Converts a HTTP transfer to a string list.
     1301 *
     1302 * @returns VBox status code.
     1303 * @param   pHttpSrv            HTTP server that contains the transfer.
     1304 * @param   pTransfer           Transfer to convert data from.
     1305 * @param   ppszData            Where to store the string list on success.
     1306 * @param   pcbData             Where to return the bytes of \a ppszData on success.
     1307 *                              Includes terminator. Optional.
     1308 *
     1309 * @note    Uses '\n' as the separator. @sa ShClTransferHttpConvertToStringListEx().
     1310 */
     1311int ShClTransferHttpConvertToStringList(PSHCLHTTPSERVER pSrv, PSHCLTRANSFER pTransfer, char **ppszData, size_t *pcbData)
     1312{
     1313    return shClTransferHttpConvertToStringListEx(pSrv, pTransfer, "\n", ppszData, pcbData);
     1314}
     1315
     1316/**
    12471317 * Returns whether a given HTTP server instance is initialized or not.
    12481318 *
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