VirtualBox

Ignore:
Timestamp:
Jan 25, 2012 4:26:55 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75918
Message:

IPRT: Implemented RTStrConvertHexBytes; Added RTManifestEntryQueryAttr and RTManifestQueryAttr.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/manifest2.cpp

    r39080 r39877  
    127127
    128128/**
    129  * Argument package used by RTManifestEqualsEx to pass it's arguments to the
     129 * Argument package used by RTManifestEqualsEx to pass its arguments to the
    130130 * enumeration callback functions.
    131131 */
     
    166166typedef RTMANIFESTEQUALS *PRTMANIFESTEQUALS;
    167167
     168/**
     169 * Argument package used by rtMainfestQueryAttrWorker to pass its search
     170 * criteria to rtMainfestQueryAttrEnumCallback and get a result back.
     171 */
     172typedef struct RTMANIFESTQUERYATTRARGS
     173{
     174    /** The attribute types we're hunting for. */
     175    uint32_t        fType;
     176    /** What we've found. */
     177    PRTMANIFESTATTR pAttr;
     178} RTMANIFESTQUERYATTRARGS;
     179/** Pointer to a rtMainfestQueryAttrEnumCallback argument packet. */
     180typedef RTMANIFESTQUERYATTRARGS *PRTMANIFESTQUERYATTRARGS;
     181
    168182
    169183/**
     
    754768
    755769/**
     770 * Callback employed by rtManifestQueryAttrWorker to search by attribute type.
     771 *
     772 * @returns VINF_SUCCESS or VINF_CALLBACK_RETURN.
     773 * @param   pStr                The attribute string node.
     774 * @param   pvUser              The argument package.
     775 */
     776static DECLCALLBACK(int) rtMainfestQueryAttrEnumCallback(PRTSTRSPACECORE pStr, void *pvUser)
     777{
     778    PRTMANIFESTATTR             pAttr = (PRTMANIFESTATTR)pStr;
     779    PRTMANIFESTQUERYATTRARGS    pArgs = (PRTMANIFESTQUERYATTRARGS)pvUser;
     780
     781    if (pAttr->fType & pArgs->fType)
     782    {
     783        pArgs->pAttr = pAttr;
     784        return VINF_CALLBACK_RETURN;
     785    }
     786    return VINF_SUCCESS;
     787}
     788
     789
     790/**
     791 * Worker common to RTManifestQueryAttr and RTManifestEntryQueryAttr.
     792 *
     793 * @returns IPRT status code.
     794 * @param   pEntry              The entry.
     795 * @param   pszAttr             The attribute name.  If NULL, it will be
     796 *                              selected by @a fType alone.
     797 * @param   fType               The attribute types the entry should match. Pass
     798 *                              Pass RTMANIFEST_ATTR_ANY match any.  If more
     799 *                              than one is given, the first matching one is
     800 *                              returned.
     801 * @param   pszValue            Where to return value.
     802 * @param   cbValue             The size of the buffer @a pszValue points to.
     803 * @param   pfType              Where to return the attribute type value.
     804 */
     805static int rtManifestQueryAttrWorker(PRTMANIFESTENTRY pEntry, const char *pszAttr, uint32_t fType,
     806                                     char *pszValue, size_t cbValue, uint32_t *pfType)
     807{
     808    /*
     809     * Find the requested attribute.
     810     */
     811    PRTMANIFESTATTR pAttr;
     812    if (pszAttr)
     813    {
     814        /* By name. */
     815        pAttr = (PRTMANIFESTATTR)RTStrSpaceGet(&pEntry->Attributes, pszAttr);
     816        if (!pAttr)
     817            return VERR_MANIFEST_ATTR_NOT_FOUND;
     818        if (!(pAttr->fType & fType))
     819            return VERR_MANIFEST_ATTR_TYPE_MISMATCH;
     820    }
     821    else
     822    {
     823        /* By type. */
     824        RTMANIFESTQUERYATTRARGS Args;
     825        Args.fType = fType;
     826        Args.pAttr = NULL;
     827        int rc = RTStrSpaceEnumerate(&pEntry->Attributes, rtMainfestQueryAttrEnumCallback, &Args);
     828        AssertRCReturn(rc, rc);
     829        pAttr = Args.pAttr;
     830        if (!pAttr)
     831            return VERR_MANIFEST_ATTR_TYPE_NOT_FOUND;
     832    }
     833
     834    /*
     835     * Set the return values.
     836     */
     837    if (cbValue || pszValue)
     838    {
     839        size_t cbNeeded = strlen(pAttr->pszValue) + 1;
     840        if (cbNeeded > cbValue)
     841            return VERR_BUFFER_OVERFLOW;
     842        memcpy(pszValue, pAttr->pszValue, cbNeeded);
     843    }
     844
     845    if (pfType)
     846        *pfType = pAttr->fType;
     847
     848    return VINF_SUCCESS;
     849}
     850
     851
     852RTDECL(int) RTManifestQueryAttr(RTMANIFEST hManifest, const char *pszAttr, uint32_t fType,
     853                                char *pszValue, size_t cbValue, uint32_t *pfType)
     854{
     855    RTMANIFESTINT *pThis = hManifest;
     856    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     857    AssertReturn(pThis->u32Magic == RTMANIFEST_MAGIC, VERR_INVALID_HANDLE);
     858    AssertPtrNull(pszAttr);
     859    AssertPtr(pszValue);
     860
     861    return rtManifestQueryAttrWorker(&pThis->SelfEntry, pszAttr, fType, pszValue, cbValue, pfType);
     862}
     863
     864
     865/**
    756866 * Validates the name entry.
    757867 *
     
    9421052    if (RT_SUCCESS(rc))
    9431053        rc = rtManifestUnsetAttrWorker(pEntry, pszAttr);
     1054    return rc;
     1055}
     1056
     1057
     1058RTDECL(int) RTManifestEntryQueryAttr(RTMANIFEST hManifest, const char *pszEntry, const char *pszAttr, uint32_t fType,
     1059                                     char *pszValue, size_t cbValue, uint32_t *pfType)
     1060{
     1061    RTMANIFESTINT *pThis = hManifest;
     1062    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1063    AssertReturn(pThis->u32Magic == RTMANIFEST_MAGIC, VERR_INVALID_HANDLE);
     1064    AssertPtr(pszEntry);
     1065    AssertPtrNull(pszAttr);
     1066    AssertPtr(pszValue);
     1067
     1068    /*
     1069     * Look up the entry.
     1070     */
     1071    bool    fNeedNormalization;
     1072    size_t  cchEntry;
     1073    int rc = rtManifestValidateNameEntry(pszEntry, &fNeedNormalization, &cchEntry);
     1074    AssertRCReturn(rc, rc);
     1075
     1076    PRTMANIFESTENTRY pEntry;
     1077    rc = rtManifestGetEntry(pThis, pszEntry, fNeedNormalization, cchEntry, &pEntry);
     1078    if (RT_SUCCESS(rc))
     1079        rc = rtManifestQueryAttrWorker(pEntry, pszAttr, fType, pszValue, cbValue, pfType);
    9441080    return rc;
    9451081}
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