// write given prefix and chunknum *before* buf[offs], adjust offset
// and return bytes used
int
ccnl_ccntlv_prependName(struct ccnl_prefix_s *name,
                        int *offset, unsigned char *buf,
                        unsigned int *lastchunknum) {

    int nameend, cnt;

    if (lastchunknum) {
        if (ccnl_ccntlv_prependNetworkVarUInt(CCNX_TLV_M_ENDChunk,
                                              *lastchunknum, offset, buf) < 0)
            return -1;
    }

    nameend = *offset;

    if (name->chunknum &&
        ccnl_ccntlv_prependNetworkVarUInt(CCNX_TLV_N_Chunk,
                                          *name->chunknum, offset, buf) < 0)
            return -1;

    // optional: (not used)
    // CCNX_TLV_N_Meta

#ifdef USE_NFN
    if (name->nfnflags & CCNL_PREFIX_NFN)
        if (ccnl_pkt_prependComponent(name->suite, "NFN", offset, buf) < 0)
            return -1;
    if (name->nfnflags & CCNL_PREFIX_THUNK)
        if (ccnl_pkt_prependComponent(name->suite, "THUNK", offset, buf) < 0)
            return -1;
#endif
    for (cnt = name->compcnt - 1; cnt >= 0; cnt--) {
        if (*offset < name->complen[cnt])
            return -1;
        *offset -= name->complen[cnt];
        memcpy(buf + *offset, name->comp[cnt], name->complen[cnt]);
    }
    if (ccnl_ccntlv_prependTL(CCNX_TLV_M_Name, nameend - *offset,
                              offset, buf) < 0)
        return -1;

    return 0;
}
Пример #2
0
// write given prefix and chunknum *before* buf[offs], adjust offset.
// Returns 0 on success, non-zero on failure.
int8_t
ccnl_ccntlv_prependName(struct ccnl_prefix_s *name,
                        size_t *offset, uint8_t *buf,
                        const uint32_t *lastchunknum) {

    size_t cnt;
    size_t nameend;

    if (lastchunknum) {
        if (ccnl_ccntlv_prependNetworkVarUInt(CCNX_TLV_M_ENDChunk,
                                              *lastchunknum, offset, buf)) {
            return -1;
        }
    }

    nameend = *offset;

    if (name->chunknum &&
        ccnl_ccntlv_prependNetworkVarUInt(CCNX_TLV_N_Chunk,
                                          *name->chunknum, offset, buf)) {
        return -1;
    }

    // optional: (not used)
    // CCNX_TLV_N_Meta

    for (cnt = name->compcnt; cnt > 0; cnt--) {
        if (*offset < name->complen[cnt-1]) {
            return -1;
        }
        *offset -= name->complen[cnt-1];
        memcpy(buf + *offset, name->comp[cnt-1], name->complen[cnt-1]);
    }
    if (ccnl_ccntlv_prependTL(CCNX_TLV_M_Name, nameend - *offset,
                              offset, buf)) {
        return -1;
    }

    return 0;
}