int ccnl_frag_RX_CCNx2013(RX_datagram callback, struct ccnl_relay_s *relay, struct ccnl_face_s *from, unsigned char **data, int *datalen) { int rc, num, typ, pdutypelen; unsigned char *pdutype = 0; struct serialFragPDU_s s; DEBUGMSG_EFRA(TRACE, "ccnl_frag_RX_CCNx2013 (%d bytes)\n", *datalen); serialFragPDU_init(&s); while (ccnl_ccnb_dehead(data, datalen, &num, &typ) == 0) { if (num==0 && typ==0) break; // end if (typ == CCN_TT_DTAG) { switch (num) { case CCNL_DTAG_FRAG2013_TYPE: if (ccnl_ccnb_hunt_for_end(data, datalen, &pdutype, &pdutypelen) || pdutypelen != 3) goto Bail; continue; case CCNL_DTAG_FRAG2013_SEQNR: getNumField(s.ourseq, s.ourseqwidth, HAS_OSEQ, "ourseq"); continue; case CCNL_DTAG_FRAG2013_FLAGS: getNumField(s.flags, s.flagwidth, HAS_FLAGS, "flags"); continue; case CCN_DTAG_CONTENT: // if (frag) // error: more than one content entry if (ccnl_ccnb_consume(typ, num, data, datalen, &s.content,&s.contlen) < 0) goto Bail; continue; // CCNL extensions: case CCN_DTAG_INTEREST: case CCN_DTAG_CONTENTOBJ: // rc = ccnl_ccnb_forwarder(relay, from, data, datalen); rc = callback(relay, from, data, datalen); if (rc < 0) return rc; continue; case CCNL_DTAG_FRAG2013_OLOSS: getNumField(s.ourloss, s.ourlosswidth, HAS_OLOS, "ourloss"); continue; case CCNL_DTAG_FRAG2013_YSEQN: getNumField(s.yourseq, s.yourseqwidth, HAS_YSEQ, "yourseq"); continue; default: break; } } if (ccnl_ccnb_consume(typ, num, data, datalen, 0, 0) < 0) goto Bail; } if (!pdutype || !s.content ) { /* || (s.HAS&(HAS_FLAGS|HAS_OSEQ)) != (HAS_FLAGS|HAS_OSEQ) ) { */ DEBUGMSG_EFRA(WARNING, "* incomplete frag\n"); return 0; } if (memcmp(pdutype, CCNL_FRAG_TYPE_CCNx2013_VAL, 3) == 0) { // hop-by-hop if (from) { if (!from->frag) from->frag = ccnl_frag_new(CCNL_FRAG_CCNx2013, relay->ifs[from->ifndx].mtu); if (from->frag && from->frag->protocol == CCNL_FRAG_CCNx2013) ccnl_frag_RX_serialfragment(callback, relay, from, &s); else DEBUGMSG_EFRA(WARNING, "WRONG FRAG PROTOCOL\n"); } else ccnl_frag_RX_serialfragment(callback, relay, from, &s); } /* * echo "FMTE" | base64 -d | hexdump -v -e '/1 "@x%02x"'| tr @ '\\'; echo */ if (memcmp(pdutype, "\x14\xc4\xc4", 3) == 0) { // mid-to-end fragment // not implemented yet } return 0; Bail: DEBUGMSG_EFRA(WARNING, "* frag bailing\n"); return -1; }
struct ccnl_buf_s* ccnl_ccnb_extract(unsigned char **data, int *datalen, int *scope, int *aok, int *min, int *max, struct ccnl_prefix_s **prefix, struct ccnl_buf_s **nonce, struct ccnl_buf_s **ppkd, unsigned char **content, int *contlen) { unsigned char *start = *data - 2 /* account for outer TAG hdr */, *cp; int num, typ, len; struct ccnl_prefix_s *p; struct ccnl_buf_s *buf, *n = 0, *pub = 0; DEBUGMSG(99, "ccnl_ccnb_extract\n"); p = (struct ccnl_prefix_s *) ccnl_calloc(1, sizeof(struct ccnl_prefix_s)); if (!p) return NULL; p->comp = (unsigned char**) ccnl_malloc(CCNL_MAX_NAME_COMP * sizeof(unsigned char**)); p->complen = (int*) ccnl_malloc(CCNL_MAX_NAME_COMP * sizeof(int)); if (!p->comp || !p->complen) goto Bail; while (ccnl_ccnb_dehead(data, datalen, &num, &typ) == 0) { if (num==0 && typ==0) break; // end if (typ == CCN_TT_DTAG) { if (num == CCN_DTAG_NAME) { for (;;) { if (ccnl_ccnb_dehead(data, datalen, &num, &typ) != 0) goto Bail; if (num==0 && typ==0) break; if (typ == CCN_TT_DTAG && num == CCN_DTAG_COMPONENT && p->compcnt < CCNL_MAX_NAME_COMP) { if (ccnl_ccnb_hunt_for_end(data, datalen, p->comp + p->compcnt, p->complen + p->compcnt) < 0) goto Bail; p->compcnt++; } else { if (ccnl_ccnb_consume(typ, num, data, datalen, 0, 0) < 0) goto Bail; } } continue; } if (num == CCN_DTAG_SCOPE || num == CCN_DTAG_NONCE || num == CCN_DTAG_MINSUFFCOMP || num == CCN_DTAG_MAXSUFFCOMP || num == CCN_DTAG_PUBPUBKDIGEST) { if (ccnl_ccnb_hunt_for_end(data, datalen, &cp, &len) < 0) goto Bail; if (num == CCN_DTAG_SCOPE && len == 1 && scope) *scope = isdigit(*cp) && (*cp < '3') ? *cp - '0' : -1; if (num == CCN_DTAG_ANSWERORIGKIND && aok) *aok = ccnl_ccnb_data2uint(cp, len); if (num == CCN_DTAG_MINSUFFCOMP && min) *min = ccnl_ccnb_data2uint(cp, len); if (num == CCN_DTAG_MAXSUFFCOMP && max) *max = ccnl_ccnb_data2uint(cp, len); if (num == CCN_DTAG_NONCE && !n) n = ccnl_buf_new(cp, len); if (num == CCN_DTAG_PUBPUBKDIGEST && !pub) pub = ccnl_buf_new(cp, len); if (num == CCN_DTAG_EXCLUDE) { DEBUGMSG(49, "warning: 'exclude' field ignored\n"); } else continue; } if (num == CCN_DTAG_CONTENT) { if (ccnl_ccnb_consume(typ, num, data, datalen, content, contlen) < 0) goto Bail; continue; } } if (ccnl_ccnb_consume(typ, num, data, datalen, 0, 0) < 0) goto Bail; } if (prefix) *prefix = p; else free_prefix(p); if (nonce) *nonce = n; else ccnl_free(n); if (ppkd) *ppkd = pub; else ccnl_free(pub); buf = ccnl_buf_new(start, *data - start); // carefully rebase ptrs to new buf because of 64bit pointers: if (content) *content = buf->data + (*content - start); for (num = 0; num < p->compcnt; num++) p->comp[num] = buf->data + (p->comp[num] - start); return buf; Bail: free_prefix(p); free_2ptr_list(n, pub); return NULL; }