当前位置: 首页>>代码示例>>C++>>正文


C++ VmDirStringLenA函数代码示例

本文整理汇总了C++中VmDirStringLenA函数的典型用法代码示例。如果您正苦于以下问题:C++ VmDirStringLenA函数的具体用法?C++ VmDirStringLenA怎么用?C++ VmDirStringLenA使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了VmDirStringLenA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: VmDirIsValidSecret

/* a fixed time string comparision function */
BOOLEAN
VmDirIsValidSecret(
    PCSTR pszTheirs,
    PCSTR pszOurs
    )
{
    ULONG ret = 0;
    int  len = 0;
    int  i = 0;
    PCSTR p = NULL;

    if (pszOurs == NULL)
    {
        return FALSE;
    }

    len = VmDirStringLenA(pszOurs);
    if (pszTheirs == NULL || VmDirStringLenA(pszTheirs) != len)
    {
        ret = 1;
        p = pszOurs;
    } else
    {
        p = pszTheirs;
    }

    for (i = len - 1; i >= 0; i--)
       ret |= p[i] ^ pszOurs[i];
    return ret == 0;
}
开发者ID:DhanashreeA,项目名称:lightwave,代码行数:31,代码来源:string.c

示例2: VmDirCreateRequestVoteCtrl

int
VmDirCreateRequestVoteCtrl(
    PVDIR_REQUEST_VOTE_CONTROL_VALUE pRequestVoteCtrlValue,
    LDAPControl*    pRequestVoteCtrl
    )
{
    int             retVal = LDAP_SUCCESS;
    BerElement*     pBer = NULL;
    BerValue        candidateIdBV = {0};
    BerValue        lastLogIndexBV = {0};

    if (!pRequestVoteCtrlValue || !pRequestVoteCtrl)
    {
        BAIL_WITH_VMDIR_ERROR(retVal, VMDIR_ERROR_INVALID_PARAMETER);
    }

    if ((pBer = ber_alloc()) == NULL)
    {
        BAIL_WITH_VMDIR_ERROR(retVal, VMDIR_ERROR_NO_MEMORY);
    }

    candidateIdBV.bv_val = pRequestVoteCtrlValue->candidateId;
    candidateIdBV.bv_len = VmDirStringLenA(pRequestVoteCtrlValue->candidateId);

    retVal = VmDirAllocateStringPrintf(&lastLogIndexBV.bv_val, "%"PRIu64, pRequestVoteCtrlValue->lastLogIndex);
    BAIL_ON_VMDIR_ERROR( retVal );
    lastLogIndexBV.bv_len = VmDirStringLenA(lastLogIndexBV.bv_val);

    if ( ber_printf( pBer, "{iOOi}", pRequestVoteCtrlValue->term, &candidateIdBV,
                    &lastLogIndexBV, pRequestVoteCtrlValue->lastLogTerm) == -1)
    {
        VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "%s: ber_printf failed.", __FUNCTION__ );
        BAIL_WITH_VMDIR_ERROR(retVal, VMDIR_ERROR_NO_MEMORY);
    }

    memset( pRequestVoteCtrl, 0, sizeof( LDAPControl ));
    pRequestVoteCtrl->ldctl_oid = LDAP_REQUEST_VOTE_CONTROL;
    pRequestVoteCtrl->ldctl_iscritical = '1';
    if (ber_flatten2(pBer, &pRequestVoteCtrl->ldctl_value, 1))
    {
        BAIL_WITH_VMDIR_ERROR(retVal, VMDIR_ERROR_NO_MEMORY);
    }

cleanup:
    VMDIR_SAFE_FREE_MEMORY(lastLogIndexBV.bv_val);
    if (pBer)
    {
        ber_free(pBer, 1);
    }
    return retVal;

error:
    VmDirFreeCtrlContent(pRequestVoteCtrl);
    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:55,代码来源:controls.c

示例3: VmDirAddModSingleAttributeReplace

//Add one more single value replace mod onto the LdapOp's mods
DWORD
VmDirAddModSingleAttributeReplace(
    PVDIR_OPERATION     pLdapOp,
    PCSTR               pszNormDN,
    PCSTR               pszAttrName,
    PVDIR_BERVALUE      pBervAttrValue
    )
{
    DWORD               dwError = 0;
    PVDIR_MODIFICATION  pMod = NULL;

    if (!pszNormDN || !pszAttrName || !pBervAttrValue)
    {
        dwError = VMDIR_ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    pLdapOp->reqDn.lberbv.bv_val = (PSTR)pszNormDN;
    pLdapOp->reqDn.lberbv.bv_len = VmDirStringLenA(pszNormDN);

    dwError = VmDirAllocateMemory(sizeof(*pMod)*1, (PVOID)&pMod);
    BAIL_ON_VMDIR_ERROR(dwError);

    pMod->operation = MOD_OP_REPLACE;
    dwError = VmDirModAddSingleValueAttribute(
            pMod,
            pLdapOp->pSchemaCtx,
            pszAttrName,
            pBervAttrValue->lberbv.bv_val,
            pBervAttrValue->lberbv.bv_len);
    BAIL_ON_VMDIR_ERROR(dwError);

    pLdapOp->request.modifyReq.dn.lberbv.bv_val = (PSTR)pszNormDN;
    pLdapOp->request.modifyReq.dn.lberbv.bv_len = VmDirStringLenA(pszNormDN);
    pMod->next = pLdapOp->request.modifyReq.mods;
    pLdapOp->request.modifyReq.mods = pMod;
    pLdapOp->request.modifyReq.numMods++;
    pMod = NULL;

cleanup:

    if (pMod)
    {
        VmDirModificationFree(pMod);
    }

    return dwError;

error:
    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:52,代码来源:modify.c

示例4: VmDirRegConfigMultiStringToDwords

static
DWORD
VmDirRegConfigMultiStringToDwords(
    PCSTR   pszValues,
    PDWORD* ppdwValues,
    DWORD*  pdwValuesLen
    )
{
    DWORD dwError = 0;
    PDWORD pdwValues = NULL;
    DWORD dwValuesLen = 0;
    DWORD dwCount = 0;
    PCSTR pszIter = NULL;

    if (pszValues)
    {
        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            dwValuesLen++;

            pszIter += VmDirStringLenA(pszIter) + 1;
        }

        /* Allocate space for one even if no space is really needed,
         * that way we have a valid pointer.
         */
        dwError = VmDirAllocateMemory(sizeof(DWORD) * (dwValuesLen == 0 ? 1 : dwValuesLen), (PVOID)&pdwValues);
        BAIL_ON_VMDIR_ERROR(dwError);

        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            DWORD dwVal = atoi(pszIter);
            pdwValues[dwCount++] = dwVal;
            pszIter += VmDirStringLenA(pszIter) + 1;
        }
    }

    *ppdwValues = pdwValues;
    *pdwValuesLen = dwValuesLen;

cleanup:
    return dwError;

error:
    VMDIR_SAFE_FREE_MEMORY(pdwValues);
    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:49,代码来源:regconfig.c

示例5: VmDirDeleteEntryViaDN

DWORD
VmDirDeleteEntryViaDN(
    PCSTR   pszDN
    )
{
    DWORD dwError = 0;
    VDIR_OPERATION op = {0};
    DeleteReq *dr = NULL;

    if (IsNullOrEmptyString(pszDN))
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirInitStackOperation(&op, VDIR_OPERATION_TYPE_INTERNAL, LDAP_REQ_DELETE, NULL);
    BAIL_ON_VMDIR_ERROR(dwError);

    op.pBEIF = VmDirBackendSelect(NULL);
    op.reqDn.lberbv_val = (PSTR)pszDN;
    op.reqDn.lberbv_len = VmDirStringLenA(pszDN);

    dr = &op.request.deleteReq;
    dr->dn.lberbv.bv_val = op.reqDn.lberbv.bv_val;
    dr->dn.lberbv.bv_len = op.reqDn.lberbv.bv_len;

    dwError = VmDirInternalDeleteEntry(&op);
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    VmDirFreeOperationContent(&op);
    return dwError;
error:
    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:34,代码来源:vmdirentry.c

示例6: _CreateCopyOperation

static
DWORD
_CreateCopyOperation(
        LDAPMessage *pEntry,
        PVDIR_OPERATION pLdapOp
        )
{
    DWORD dwError = 0;

    dwError = VmDirInitStackOperation(
            pLdapOp,
            VDIR_OPERATION_TYPE_REPL,
            LDAP_REQ_MODIFY,
            NULL);
    BAIL_ON_VMDIR_ERROR(dwError);

    pLdapOp->pBEIF = VmDirBackendSelect(NULL);
    assert(pLdapOp->pBEIF);

    pLdapOp->reqDn.lberbv.bv_val = SUB_SCHEMA_SUB_ENTRY_DN;
    pLdapOp->reqDn.lberbv.bv_len = VmDirStringLenA(SUB_SCHEMA_SUB_ENTRY_DN);
    pLdapOp->request.modifyReq.dn.lberbv.bv_val = pLdapOp->reqDn.lberbv.bv_val;
    pLdapOp->request.modifyReq.dn.lberbv.bv_len = pLdapOp->reqDn.lberbv.bv_len;

cleanup:
    return dwError;

error:
    VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL,
            "%s,%d failed, error(%d)", __FUNCTION__, __LINE__, dwError );

    goto cleanup;
}
开发者ID:divyamehta,项目名称:lightwave,代码行数:33,代码来源:partnerschema.c

示例7: VmDirStringToBervalContent

/*
 * Allocate string into pDupBerval
 */
DWORD
VmDirStringToBervalContent(
    PCSTR              pszBerval,
    PVDIR_BERVALUE     pDupBerval
    )
{
    DWORD    dwError = 0;

    VmDirFreeBervalContent(pDupBerval);

    dwError = VmDirAllocateStringA(pszBerval, &pDupBerval->lberbv.bv_val);
    BAIL_ON_VMDIR_ERROR(dwError);

    pDupBerval->bOwnBvVal = TRUE;

    pDupBerval->lberbv.bv_len = VmDirStringLenA(pDupBerval->lberbv.bv_val);

cleanup:

    return dwError;

error:

    VmDirFreeBervalContent(pDupBerval);

    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:30,代码来源:vmdirentry.c

示例8: VmDirEntryAddSingleValueStrAttribute

/*
 * Convenient function to add a single "string" type attribute to pEntry.
 */
DWORD
VmDirEntryAddSingleValueStrAttribute(
    PVDIR_ENTRY pEntry,
    PCSTR pszAttrName,
    PCSTR pszAttrValue)
{
    DWORD       dwError = 0;

    if (!pEntry || !pEntry->pSchemaCtx || !pszAttrName || !pszAttrValue)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = VmDirEntryAddSingleValueAttribute(
            pEntry,
            pszAttrName,
            pszAttrValue,
            VmDirStringLenA(pszAttrValue));
    BAIL_ON_VMDIR_ERROR(dwError);

error:

    return dwError;
}
开发者ID:vmware,项目名称:lightwave,代码行数:28,代码来源:vmdirentry.c

示例9: VmDirRegConfigMultiStringToStrList

static
DWORD
VmDirRegConfigMultiStringToStrList(
    PCSTR               pszValues,
    PVMDIR_STRING_LIST* ppStrList
    )
{
    DWORD               dwError = 0;
    DWORD               dwValuesLen = 0;
    PCSTR               pszIter = NULL;
    PVMDIR_STRING_LIST  pStrList = NULL;

    if (pszValues)
    {
        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            dwValuesLen++;

            pszIter += VmDirStringLenA(pszIter) + 1;
        }

        dwError = VmDirStringListInitialize(&pStrList, dwValuesLen);
        BAIL_ON_VMDIR_ERROR(dwError);

        pszIter = pszValues;
        while (pszIter != NULL && *pszIter != '\0')
        {
            dwError = VmDirStringListAddStrClone(pszIter, pStrList);
            BAIL_ON_VMDIR_ERROR(dwError);

            pszIter += VmDirStringLenA(pszIter) + 1;
        }

        *ppStrList = pStrList; pStrList = NULL;
    }

cleanup:
    if (pStrList)
    {
        VmDirStringListFree(pStrList);
    }
    return dwError;

error:
    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:47,代码来源:regconfig.c

示例10: VmDirSimpleEntryDeleteAttribute

DWORD
VmDirSimpleEntryDeleteAttribute(
    PCSTR   pszDN,
    PCSTR   pszAttr
    )
{
    DWORD   dwError = 0;
    size_t  dnlen = 0;
    size_t  attrlen = 0;
    VDIR_OPERATION  ldapOp = {0};

    if (IsNullOrEmptyString(pszDN) || IsNullOrEmptyString(pszAttr))
    {
        BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER);
    }

    dwError = VmDirInitStackOperation(
            &ldapOp,
            VDIR_OPERATION_TYPE_INTERNAL,
            LDAP_REQ_MODIFY,
            NULL);
    BAIL_ON_VMDIR_ERROR(dwError);

    dnlen = VmDirStringLenA(pszDN);
    attrlen = VmDirStringLenA(pszAttr);

    ldapOp.pBEIF = VmDirBackendSelect(NULL);
    ldapOp.reqDn.lberbv_val = (PSTR)pszDN;
    ldapOp.reqDn.lberbv_len = dnlen;

    ldapOp.request.modifyReq.dn.lberbv_val = ldapOp.reqDn.lberbv_val;
    ldapOp.request.modifyReq.dn.lberbv_len = ldapOp.reqDn.lberbv_len;

    dwError = VmDirAppendAMod(
            &ldapOp, MOD_OP_DELETE, pszAttr, attrlen, NULL, 0);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirInternalModifyEntry(&ldapOp);
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    VmDirFreeOperationContent(&ldapOp);
    return dwError;

error:
    goto cleanup;
}
开发者ID:vmware,项目名称:lightwave,代码行数:47,代码来源:vmdirentry.c

示例11: VmDirAttributeAllocate

/*
 * Create an Attribute on the heap and establish its pATDesc
 * two memory allocate
 * 1. pAttribute
 * 2. pAttribute->vals (BerValue array is one more then requested)
 */
DWORD
VmDirAttributeAllocate(
    PCSTR   pszName,
    USHORT  usBerSize,
    PVDIR_SCHEMA_CTX pCtx,
    PVDIR_ATTRIBUTE* ppOutAttr)
{
    DWORD    dwError = 0;
    PVDIR_ATTRIBUTE    pAttr = NULL;

    if (!ppOutAttr)
    {
        return 0;
    }

    dwError = VmDirAllocateMemory(
            sizeof(VDIR_ATTRIBUTE),
            (PVOID*)&pAttr);
    BAIL_ON_VMDIR_ERROR(dwError);

    // add one more BerValue as Encode/Decode entry in data store layer needs it.
    dwError = VmDirAllocateMemory(
            sizeof(VDIR_BERVALUE) * (usBerSize + 1),
            (PVOID*)&pAttr->vals);
    BAIL_ON_VMDIR_ERROR(dwError);

    pAttr->numVals = usBerSize;

    pAttr->pATDesc = VmDirSchemaAttrNameToDesc(
                    pCtx,
                    pszName);
    if (!pAttr->pATDesc)
    {
        dwError = VMDIR_ERROR_NO_SUCH_ATTRIBUTE;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // pAttr->type.lberbv.bv_val always store in-place
    pAttr->type.lberbv.bv_val = pAttr->pATDesc->pszName;
    pAttr->type.lberbv.bv_len = VmDirStringLenA(pAttr->type.lberbv.bv_val);

    *ppOutAttr = pAttr;

cleanup:

    return dwError;

error:

    if (pAttr)
    {
        VmDirFreeAttribute(pAttr);
    }

    VmDirLog( LDAP_DEBUG_ANY, "AllocateAttribute failed (%d)(%s)",
              dwError, VDIR_SAFE_STRING(pszName));

    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:65,代码来源:vmdirentry.c

示例12: VmDirAppendAMod

DWORD
VmDirAppendAMod(
    PVDIR_OPERATION   pOperation,
    int               modOp,
    char *            attrName,
    int               attrNameLen,
    char *            attrVal,
    size_t            attrValLen
    )
{
    DWORD          dwError = 0;
    VDIR_MODIFICATION * mod = NULL;
    ModifyReq *    modReq = &(pOperation->request.modifyReq);

    VmDirLog( LDAP_DEBUG_TRACE, "appendAMod: Begin, entry DN = %s", modReq->dn.lberbv.bv_val );

    dwError = VmDirAllocateMemory( sizeof( VDIR_MODIFICATION ), (PVOID *)&(mod) );
    BAIL_ON_VMDIR_ERROR( dwError );

    mod->operation = modOp;

    mod->attr.next = NULL;
    if ((mod->attr.pATDesc = VmDirSchemaAttrNameToDesc( pOperation->pSchemaCtx, attrName)) == NULL)
    {
        VmDirLog( LDAP_DEBUG_ANY, "appendAMod: VmDirSchemaAttrNameToDesc failed.");
        dwError = -1; /* Any value except 0 should do. */
        BAIL_ON_VMDIR_ERROR( dwError );
    }
    mod->attr.type.lberbv.bv_val = mod->attr.pATDesc->pszName;
    mod->attr.type.lberbv.bv_len = VmDirStringLenA(mod->attr.pATDesc->pszName);

    dwError = VmDirAllocateMemory( 2 * sizeof( VDIR_BERVALUE ), (PVOID *)&(mod->attr.vals) );
    BAIL_ON_VMDIR_ERROR( dwError );

    if ( attrVal && attrValLen > 0 )
    {
        dwError = VmDirAllocateMemory( attrValLen + 1, (PVOID *)&(mod->attr.vals[0].lberbv.bv_val) );
        BAIL_ON_VMDIR_ERROR( dwError );

        dwError = VmDirCopyMemory( mod->attr.vals[0].lberbv.bv_val, attrValLen + 1, attrVal, attrValLen);
        BAIL_ON_VMDIR_ERROR( dwError );

        mod->attr.vals[0].lberbv.bv_len = attrValLen;
        mod->attr.vals[0].bOwnBvVal = TRUE;

        mod->attr.numVals = 1;
    }

    mod->next = modReq->mods;
    modReq->mods = mod;
    modReq->numMods++;

cleanup:
    VmDirLog( LDAP_DEBUG_TRACE, "appendAMod: End." );
    return dwError;

error:
    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:59,代码来源:oprequestutil.c

示例13: _VmDirSchemaCheckNameform

static
DWORD
_VmDirSchemaCheckNameform(
    PVDIR_SCHEMA_CTX        pCtx,
    PVDIR_ENTRY             pEntry,
    PVDIR_SCHEMA_OC_DESC    pStructOCDesc
    )
{
    DWORD       dwError = 0;
    PSTR        pszLocalErrorMsg = NULL;

    if ( !pCtx || !pStructOCDesc || !pEntry || !pEntry->dn.bvnorm_val )
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

#if 0

    // should NOT enable this until we have all namform and structure rule defined
    if ( pStructOCDesc->usNumMustRDNs > 0 )
    {   // not yet support multi RDNs case.  only check the first MUST RDN for now.
        size_t  iLen = VmDirStringLenA(pStructOCDesc->ppszMustRDNs[0]);

        if ( VmDirStringNCompareA( pEntry->dn.bvnorm_val,
                                   pStructOCDesc->ppszMustRDNs[0],
                                   iLen,
                                   FALSE ) != 0
             ||
             pEntry->dn.bvnorm_val[iLen] != '='
           )
        {
            dwError = ERROR_INVALID_ENTRY;
            BAIL_ON_VMDIR_ERROR_WITH_MSG( dwError, pszLocalErrorMsg,
                                          "_VmDirSchemaCheckNameform: rdn must be (%s). (%d)",
                                          VDIR_SAFE_STRING( pStructOCDesc->ppszMustRDNs[0] ), dwError );
        }
    }

#endif

cleanup:

    VMDIR_SAFE_FREE_MEMORY(pszLocalErrorMsg);

    return dwError;

error:

    if ( !pCtx->pszErrorMsg )
    {
        pCtx->pszErrorMsg = pszLocalErrorMsg;
        pszLocalErrorMsg = NULL;

        pCtx->dwErrorCode = dwError;
    }

    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:59,代码来源:check.c

示例14: VmDirMDBSimpleDnToEntry

DWORD
VmDirMDBSimpleDnToEntry(
    PSTR        pszEntryDN,
    PVDIR_ENTRY pEntry
    )
{
    DWORD               dwError = 0;
    PVDIR_SCHEMA_CTX    pSchemaCtx = NULL;
    VDIR_BERVALUE       entryDn = VDIR_BERVALUE_INIT;
    VDIR_BACKEND_CTX    mdbBECtx = {0};
    BOOLEAN             bHasTxn = FALSE;

    assert(pEntry);

    dwError = VmDirSchemaCtxAcquire(&pSchemaCtx);
    BAIL_ON_VMDIR_ERROR(dwError);

    entryDn.lberbv.bv_val = pszEntryDN;
    entryDn.lberbv.bv_len = VmDirStringLenA(entryDn.lberbv.bv_val);

    dwError = VmDirMDBTxnBegin(&mdbBECtx, VDIR_BACKEND_TXN_READ);
    BAIL_ON_VMDIR_ERROR(dwError);
    bHasTxn = TRUE;

    dwError = VmDirMDBDNToEntry(    &mdbBECtx,
                                    pSchemaCtx,
                                    &entryDn,
                                    pEntry,
                                    VDIR_BACKEND_ENTRY_LOCK_READ);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirMDBTxnCommit(&mdbBECtx);
    bHasTxn = FALSE;
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:

    if (pSchemaCtx)
    {
        VmDirSchemaCtxRelease(pSchemaCtx);
    }

    mdbBECtx.pBEPrivate = NULL;
    VmDirBackendCtxContentFree(&mdbBECtx);
    VmDirFreeBervalContent(&entryDn);

    return dwError;

error:

    if (bHasTxn)
    {
        VmDirMDBTxnAbort(&mdbBECtx);
    }

    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:57,代码来源:entry.c

示例15: VmDirModAddSingleValueAttribute

/*
 * Convenient function to add a single attribute to pMod.
 *
 * Currently, only handle adding content to EMPTY pMod->attr and use with
 * pMod->operation = MOD_OP_REPLACE or MOD_OP_ADD or MOD_OP_DELETE
 * to manipulate ONE attribute value
 *
 */
DWORD
VmDirModAddSingleValueAttribute(
    PVDIR_MODIFICATION      pMod,
    PVDIR_SCHEMA_CTX        pSchemaCtx,
    PCSTR                   pszAttrName,
    PCSTR                   pszAttrValue,
    size_t                  iAttrValueLen
    )
{
    DWORD dwError = 0;

    if (!pMod || pMod->attr.pATDesc || pMod->attr.vals || !pSchemaCtx ||
        !pszAttrName || !pszAttrValue || iAttrValueLen < 1)
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // add one more BerValue as Encode/Decode entry in data store layer needs it.
    dwError = VmDirAllocateMemory(
                    sizeof(VDIR_BERVALUE) * (1 + 1),
                    (PVOID*)&pMod->attr.vals);
    BAIL_ON_VMDIR_ERROR(dwError);
    pMod->attr.numVals = 1;

    pMod->attr.pATDesc = VmDirSchemaAttrNameToDesc(pSchemaCtx, pszAttrName);
    if (!pMod->attr.pATDesc)
    {
        dwError = ERROR_NO_SCHEMA;
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    // pAttr->type.lberbv.bv_val always store in-place
    pMod->attr.type.lberbv.bv_val = pMod->attr.pATDesc->pszName;
    pMod->attr.type.lberbv.bv_len = VmDirStringLenA(pMod->attr.type.lberbv.bv_val);

    dwError = VmDirAllocateMemory(
                    iAttrValueLen + 1,                  // want string null terminated.
                    (PVOID*)&pMod->attr.vals[0].lberbv.bv_val );
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = VmDirCopyMemory( pMod->attr.vals[0].lberbv.bv_val, iAttrValueLen + 1, (PCVOID)pszAttrValue, iAttrValueLen );
    BAIL_ON_VMDIR_ERROR(dwError);

    pMod->attr.vals[0].bOwnBvVal = TRUE;
    pMod->attr.vals[0].lberbv.bv_len = iAttrValueLen;

cleanup:

    return dwError;

error:

    // pMod owns the memory allocated in this function.

    goto cleanup;
}
开发者ID:Dan-McGee,项目名称:lightwave,代码行数:65,代码来源:oprequestutil.c


注:本文中的VmDirStringLenA函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。