extern int SyncCacheEntryFetch(struct SyncHashCacheEntry *ce) { // causes the cache entry to fetched from the repo char *here = "Sync.SyncCacheEntryFetch"; int res = 0; if (ce == NULL) { // not an entry res = -1; } else if (ce->ncL != NULL) { // it's already here res = 0; } else if ((ce->state & SyncHashState_stored) == 0) { // it's never been stored, fail quietly res = -1; } else { // at this point we try to fetch it from the local repo // a failure should complain struct SyncRootStruct *root = ce->head->root; struct SyncBaseStruct *base = root->base; struct ccn_charbuf *name = SyncNameForLocalNode(root, ce->hash); struct ccn_charbuf *content = ccn_charbuf_create(); char *why = "no fetch"; struct ccn_parsed_ContentObject pcos; res = SyncLocalRepoFetch(base, name, content, &pcos); if (res >= 0) { // parse the object const unsigned char *xp = NULL; size_t xs = 0; // get the encoded node res = ccn_content_get_value(content->buf, content->length, &pcos, &xp, &xs); if (res < 0) why = "ccn_content_get_value failed"; else { struct ccn_buf_decoder ds; struct ccn_buf_decoder *d = ccn_buf_decoder_start(&ds, xp, xs); struct SyncNodeComposite *nc = SyncAllocComposite(root->base); res |= SyncParseComposite(nc, d); if (res < 0) { // failed, so back out of the allocations why = "bad parse"; SyncFreeComposite(nc); nc = NULL; } else { res = 1; SyncNodeIncRC(nc); ce->ncL = nc; ce->state |= SyncHashState_stored; } } } if (res < 0) if (root->base->debug >= CCNL_ERROR) SyncNoteUri(root, here, why, name); ccn_charbuf_destroy(&name); ccn_charbuf_destroy(&content); } return res; }
/** * Write a file named index/stable that contains the size of * repoFile1 when the repository is shut down. */ static int r_store_write_stable_point(struct ccnr_handle *h) { struct ccn_charbuf *path = NULL; struct ccn_charbuf *cb = NULL; int fd; path = ccn_charbuf_create(); cb = ccn_charbuf_create(); ccn_charbuf_putf(path, "%s/index/stable", h->directory); unlink(ccn_charbuf_as_string(path)); /* Should not exist, but just in case. */ fd = open(ccn_charbuf_as_string(path), O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666); if (fd == -1) { ccnr_msg(h, "cannot write stable mark %s: %s", ccn_charbuf_as_string(path), strerror(errno)); unlink(ccn_charbuf_as_string(path)); } else { ccn_charbuf_putf(cb, "%ju", (uintmax_t)(h->stable)); write(fd, cb->buf, cb->length); close(fd); if (CCNSHOULDLOG(h, dfsdf, CCNL_INFO)) ccnr_msg(h, "Index marked stable - %s", ccn_charbuf_as_string(cb)); } ccn_charbuf_destroy(&path); ccn_charbuf_destroy(&cb); return(0); }
/** * Ends the download stream */ void CCNGet::endStream() { stream = ccn_fetch_close(stream); ccn_destroy(&ccn); ccn_charbuf_destroy(&templ); ccn_charbuf_destroy(&name); }
char * get_orig_router_from_info_content_name(struct ccn_charbuf * content_name) { int start,end; start=0; struct ccn_indexbuf *comps=ccn_indexbuf_create(); ccn_name_split (content_name, comps); end=check_for_name_component_in_name(content_name,comps,"nlsr"); struct ccn_charbuf *temp=ccn_charbuf_create(); ccn_name_init(temp); ccn_name_append_components( temp, content_name->buf, comps->buf[start], comps->buf[end]); struct ccn_charbuf *temp1=ccn_charbuf_create(); ccn_uri_append(temp1, temp->buf, temp->length, 0); char *orig_router=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1, sizeof(char)); memcpy(orig_router,ccn_charbuf_as_string(temp1), strlen(ccn_charbuf_as_string(temp1))); orig_router[strlen(orig_router)]='\0'; ccn_charbuf_destroy(&temp); ccn_charbuf_destroy(&temp1); ccn_indexbuf_destroy(&comps); return orig_router; }
int ccns_slice_name(struct ccn_charbuf *nm, struct ccns_slice *s) { struct ccn_charbuf *c; struct ccn_digest *digest = NULL; struct ccn_charbuf *hash = NULL; int res = 0; c = ccn_charbuf_create(); if (c == NULL) return (-1); res = append_slice(c, s); if (res < 0) goto Cleanup; digest = ccn_digest_create(CCN_DIGEST_SHA256); hash = ccn_charbuf_create_n(ccn_digest_size(digest)); if (hash == NULL) goto Cleanup; ccn_digest_init(digest); res |= ccn_digest_update(digest, c->buf, c->length); res |= ccn_digest_final(digest, hash->buf, hash->limit); if (res < 0) goto Cleanup; hash->length = hash->limit; if (ccn_name_from_uri(nm, "ccnx:/%C1.M.S.localhost/%C1.S.cs") < 0) res = -1; res |= ccn_name_append(nm, hash->buf, hash->length); Cleanup: ccn_charbuf_destroy(&c); ccn_digest_destroy(&digest); ccn_charbuf_destroy(&hash); return (res); }
static enum ccn_upcall_res seqw_incoming_interest( struct ccn_closure *selfp, enum ccn_upcall_kind kind, struct ccn_upcall_info *info) { int res; struct ccn_charbuf *cob = NULL; struct ccn_seqwriter *w = selfp->data; if (w == NULL || selfp != &(w->cl)) abort(); switch (kind) { case CCN_UPCALL_FINAL: ccn_charbuf_destroy(&w->nb); ccn_charbuf_destroy(&w->nv); ccn_charbuf_destroy(&w->buffer); ccn_charbuf_destroy(&w->cob0); free(w); break; case CCN_UPCALL_INTEREST: if (w->closed || w->buffer->length > 0) { cob = seqw_next_cob(w); if (cob == NULL) return(CCN_UPCALL_RESULT_OK); if (ccn_content_matches_interest(cob->buf, cob->length, 1, NULL, info->interest_ccnb, info->pi->offset[CCN_PI_E], info->pi)) { w->interests_possibly_pending = 0; res = ccn_put(info->h, cob->buf, cob->length); if (res >= 0) { w->buffer->length = 0; w->seqnum++; return(CCN_UPCALL_RESULT_INTEREST_CONSUMED); } } ccn_charbuf_destroy(&cob); } if (w->cob0 != NULL) { cob = w->cob0; if (ccn_content_matches_interest(cob->buf, cob->length, 1, NULL, info->interest_ccnb, info->pi->offset[CCN_PI_E], info->pi)) { w->interests_possibly_pending = 0; ccn_put(info->h, cob->buf, cob->length); return(CCN_UPCALL_RESULT_INTEREST_CONSUMED); } } w->interests_possibly_pending = 1; break; default: break; } return(CCN_UPCALL_RESULT_OK); }
/** * * Create new face by sending out a request Interest * The actual new face instance is returned * */ static struct ccn_face_instance *create_face(struct ccn *h, struct ccn_charbuf *local_scope_template, struct ccn_charbuf *no_name, struct ccn_face_instance *face_instance) { struct ccn_charbuf *newface = NULL; struct ccn_charbuf *signed_info = NULL; struct ccn_charbuf *temp = NULL; struct ccn_charbuf *name = NULL; struct ccn_charbuf *resultbuf = NULL; struct ccn_parsed_ContentObject pcobuf = {0}; struct ccn_face_instance *new_face_instance = NULL; const unsigned char *ptr = NULL; size_t length = 0; int res = 0; /* Encode the given face instance */ newface = ccn_charbuf_create(); ccnb_append_face_instance(newface, face_instance); temp = ccn_charbuf_create(); res = ccn_sign_content(h, temp, no_name, NULL, newface->buf, newface->length); resultbuf = ccn_charbuf_create(); /* Construct the Interest name that will create the face */ name = ccn_charbuf_create(); ccn_name_init(name); ccn_name_append_str(name, "ccnx"); ccn_name_append(name, face_instance->ccnd_id, face_instance->ccnd_id_size); ccn_name_append_str(name, face_instance->action); ccn_name_append(name, temp->buf, temp->length); /* send Interest to retrieve Data that contains the newly created face */ res = ccn_get(h, name, local_scope_template, 1000, resultbuf, &pcobuf, NULL, 0); ON_ERROR_CLEANUP(res); /* decode Data to get the actual face instance */ res = ccn_content_get_value(resultbuf->buf, resultbuf->length, &pcobuf, &ptr, &length); ON_ERROR_CLEANUP(res); new_face_instance = ccn_face_instance_parse(ptr, length); ccn_charbuf_destroy(&newface); ccn_charbuf_destroy(&signed_info); ccn_charbuf_destroy(&temp); ccn_charbuf_destroy(&resultbuf); ccn_charbuf_destroy(&name); return new_face_instance; cleanup: ccn_charbuf_destroy(&newface); ccn_charbuf_destroy(&signed_info); ccn_charbuf_destroy(&temp); ccn_charbuf_destroy(&resultbuf); ccn_charbuf_destroy(&name); return NULL; }
void ccn_dhcp_entry_destroy(struct ccn_dhcp_entry **de) { if (*de != NULL) { ccn_charbuf_destroy(&(*de)->name_prefix); ccn_charbuf_destroy(&(*de)->store); free(*de); *de = NULL; } }
/** * Destroy the ccnr instance, releasing all associated resources. */ PUBLIC void r_init_destroy(struct ccnr_handle **pccnr) { struct ccnr_handle *h = *pccnr; int stable; if (h == NULL) return; stable = h->active_in_fd == -1 ? 1 : 0; r_io_shutdown_all(h); ccnr_direct_client_stop(h); ccn_schedule_destroy(&h->sched); hashtb_destroy(&h->propagating_tab); hashtb_destroy(&h->nameprefix_tab); hashtb_destroy(&h->enum_state_tab); hashtb_destroy(&h->content_by_accession_tab); // SyncActions sync_stop method should be shutting down heartbeat if (h->sync_plumbing) { h->sync_plumbing->sync_methods->sync_stop(h->sync_plumbing, NULL); free(h->sync_plumbing); h->sync_plumbing = NULL; h->sync_base = NULL; // freed by sync_stop ? } r_store_final(h, stable); if (h->fds != NULL) { free(h->fds); h->fds = NULL; h->nfds = 0; } if (h->fdholder_by_fd != NULL) { free(h->fdholder_by_fd); h->fdholder_by_fd = NULL; h->face_limit = h->face_gen = 0; } if (h->content_by_cookie != NULL) { free(h->content_by_cookie); h->content_by_cookie = NULL; h->cookie_limit = 1; } ccn_charbuf_destroy(&h->scratch_charbuf); ccn_indexbuf_destroy(&h->skiplinks); ccn_indexbuf_destroy(&h->scratch_indexbuf); ccn_indexbuf_destroy(&h->unsol); if (h->parsed_policy != NULL) { ccn_indexbuf_destroy(&h->parsed_policy->namespaces); ccn_charbuf_destroy(&h->parsed_policy->store); free(h->parsed_policy); h->parsed_policy = NULL; } ccn_charbuf_destroy(&h->policy_name); ccn_charbuf_destroy(&h->policy_link_cob); ccn_charbuf_destroy(&h->ccnr_keyid); free(h); *pccnr = NULL; }
/** * Closes the stream and reclaims any resources used by the stream. * The stream object will be freed, so the client must not access it again. * @returns NULL in all cases. */ extern struct ccn_fetch_stream * ccn_fetch_close(struct ccn_fetch_stream *fs) { // destroys a ccn_fetch_stream object // implicit abort of any outstanding fetches // always returns NULL int i; FILE *debug = fs->parent->debug; ccn_fetch_flags flags = fs->parent->debugFlags; // make orphans of all outstanding requests // CallMe should handle the cleanup struct localClosure * this = fs->requests; fs->requests = NULL; while (this != NULL) { this->fs = NULL; this = this->next; } // free up the buffers fs->maxBufs = 0; PruneSegments(fs); if (fs->name != NULL) ccn_charbuf_destroy(&fs->name); if (fs->interest != NULL) ccn_charbuf_destroy(&fs->interest); struct ccn_fetch *f = fs->parent; if (f != NULL) { int ns = f->nStreams; fs->parent = NULL; for (i = 0; i < ns; i++) { struct ccn_fetch_stream *tfs = f->streams[i]; if (tfs == fs) { // found it, so get rid of it ns--; f->nStreams = ns; f->streams[i] = NULL; f->streams[i] = f->streams[ns]; f->streams[ns] = NULL; break; } } } if (debug != NULL && (flags & ccn_fetch_flags_NoteOpenClose)) { fprintf(debug, "-- ccn_fetch close, %s, segReq %jd, segsRead %jd, timeouts %jd\n", fs->id, fs->segsRequested, fs->segsRead, fs->timeoutsSeen); fflush(debug); } // finally, get rid of the stream object freeString(fs->id); free(fs); return NULL; }
/** * Destroy the result of ccn_strategy_selection_parse(). */ void ccn_strategy_selection_destroy(struct ccn_strategy_selection **pss) { if (*pss == NULL) return; ccn_charbuf_destroy(&(*pss)->name_prefix); ccn_charbuf_destroy(&(*pss)->store); free(*pss); *pss = NULL; }
char * get_orig_router_from_lsa_name(struct ccn_charbuf * content_name) { int start=0; size_t comp_size; const unsigned char *second_last_comp; char *second_comp_type; char *sep="."; char *rem; struct ccn_indexbuf *components=ccn_indexbuf_create(); struct ccn_charbuf *name=ccn_charbuf_create(); ccn_name_from_uri(name,nlsr->slice_prefix); ccn_name_split (name, components); start=components->n-2; ccn_charbuf_destroy(&name); ccn_indexbuf_destroy(&components); struct ccn_indexbuf *comps=ccn_indexbuf_create(); ccn_name_split (content_name, comps); ccn_name_comp_get( content_name->buf, comps, comps->n-1-2, &second_last_comp, &comp_size); second_comp_type=strtok_r((char *)second_last_comp, sep, &rem); if ( strcmp( second_comp_type, "lsId" ) == 0 ){ ccn_name_chop(content_name,comps,-3); } else{ ccn_name_chop(content_name,comps,-2); } struct ccn_charbuf *temp=ccn_charbuf_create(); ccn_name_init(temp); ccn_name_append_components( temp, content_name->buf, comps->buf[start+1], comps->buf[comps->n - 1]); struct ccn_charbuf *temp1=ccn_charbuf_create(); ccn_uri_append(temp1, temp->buf, temp->length, 0); char *orig_router=(char *)calloc(strlen(ccn_charbuf_as_string(temp1))+1, sizeof(char)); memcpy(orig_router,ccn_charbuf_as_string(temp1), strlen(ccn_charbuf_as_string(temp1))); orig_router[strlen(orig_router)]='\0'; ccn_charbuf_destroy(&temp); ccn_charbuf_destroy(&temp1); ccn_indexbuf_destroy(&comps); return orig_router; }
/** * Verify a signed interest * * params are as returned in upcall info structure * key is what should be used to verify * * returns: * -1 for parsing error * 0 for incorrect signature / unverified * 1 for proper verification * */ int verify_signed_interest(const unsigned char *ccnb, const struct ccn_indexbuf *comps, size_t num_comps, size_t start, size_t stop, struct ccn_pkey* key) { fprintf(stderr,"verifying signed interest...\n"); // What is info->interest_comps->n ? //fprintf(stderr, "Interest components %d\n", (int) info->interest_comps->n); unsigned char* comp; size_t size; int res; // Create a charbuf with the matched interest name incl nonce struct ccn_charbuf* name = ccn_charbuf_create(); ccn_name_init(name); res = ccn_name_append_components(name, ccnb, start, stop); // Last component, should be the signature res = ccn_name_comp_get(ccnb, comps, num_comps, (const unsigned char**)&comp, &size); if (memcmp(NS_SIGNATURE, comp, NS_SIGNATURE_LEN) != 0) { fprintf(stderr, "debug: Last component not tagged as a signature.\n"); return(-1); } // Parse our nameless, dataless content object that follows the namespace // and replace the name with the implicit name from the interest, so that // we can use the standard signature verification calls. Could be made // more efficient with different library calls. struct ccn_charbuf* co_with_name = ccn_charbuf_create(); unsigned char* co = &comp[NS_SIGNATURE_LEN]; replace_name(co_with_name, co, size-NS_SIGNATURE_LEN, name); //fprintf(stderr, "replace_name == %d (%s)\n", res, (res==0)?"ok":"fail"); // For now, use standard routines to verify signature struct ccn_parsed_ContentObject pco = {0}; fprintf(stderr,"verifying signed interest...2\n"); res = ccn_parse_ContentObject(co_with_name->buf, co_with_name->length, &pco, NULL); if (!res) { // Verify the signature against the authorized public key given to us, passed through to the handler res = ccn_verify_signature(co_with_name->buf, pco.offset[CCN_PCO_E], &pco, key ); } else { fprintf(stderr, "debug: Constructed content object parse failed (res==%d)\n", res); } fprintf(stderr,"verifying signed interest...3\n"); ccn_charbuf_destroy(&co_with_name); ccn_charbuf_destroy(&name); return (res); }
void NdnMediaProcess::initPipe(struct ccn_closure *selfp, struct ccn_upcall_info *info, UserDataBuf *userBuf) { fprintf(stderr, "initializing pipe\n"); // get seq const unsigned char *ccnb = info->content_ccnb; size_t ccnb_size = info->pco->offset[CCN_PCO_E]; struct ccn_indexbuf *comps = info->content_comps; long seq; const unsigned char *seqptr = NULL; char *endptr = NULL; size_t seq_size = 0; int k = comps->n - 2; if (userBuf->seq < 0) { seq = ccn_ref_tagged_BLOB(CCN_DTAG_Component, ccnb, comps->buf[k], comps->buf[k + 1], &seqptr, &seq_size); if (seq >= 0) { seq = strtol((const char *)seqptr, &endptr, 10); if (endptr != ((const char *)seqptr) + seq_size) seq = -1; } if (seq >= 0) { userBuf->seq = seq; } else { return; } } fprintf(stderr, "fetched content with seq %d\n", seq); // send hint-ahead interests for (int i = 0; i < hint_ahead; i ++) { userBuf->seq++; struct ccn_charbuf *pathbuf = ccn_charbuf_create(); ccn_name_init(pathbuf); ccn_name_append_components(pathbuf, ccnb, comps->buf[0], comps->buf[k]); struct ccn_charbuf *temp = ccn_charbuf_create(); ccn_charbuf_putf(temp, "%ld", userBuf->seq); ccn_name_append(pathbuf, temp->buf, temp->length); // no need to trylock as we already have the lock // this should use pipe callback, selfp is normal callback int res = ccn_express_interest(info->h, pathbuf, userBuf->data_buf.pipe_callback, NULL); if (res < 0) { fprintf(stderr, "Sending interest failed at normal processor\n"); std::exit(1); } ccn_charbuf_destroy(&pathbuf); ccn_charbuf_destroy(&temp); } }
void ccnr_internal_client_stop(struct ccnr_handle *ccnr) { ccnr->notice = NULL; /* ccn_destroy will free */ if (ccnr->notice_push != NULL) ccn_schedule_cancel(ccnr->sched, ccnr->notice_push); ccn_indexbuf_destroy(&ccnr->chface); ccn_destroy(&ccnr->internal_client); ccn_charbuf_destroy(&ccnr->service_ccnb); ccn_charbuf_destroy(&ccnr->neighbor_ccnb); if (ccnr->internal_client_refresh != NULL) ccn_schedule_cancel(ccnr->sched, ccnr->internal_client_refresh); }
void ccndc_destroy_data(struct ccndc_data **data) { struct ccndc_data *self = *data; if (self != NULL) { ccn_charbuf_destroy(&self->no_name); ccn_charbuf_destroy(&self->local_scope_template); ccn_disconnect(self->ccn_handle); ccn_destroy(&self->ccn_handle); free(self); *data = NULL; } }
int NdnMediaProcess::checkInterest() { int res = 0; QHash<QString,UserDataBuf *>::iterator it; ruMutex->lock(); for ( it = qhRemoteUser.begin(); it != qhRemoteUser.end(); ++it ) { if (!it.value()->interested) { /* Use a template to express our order preference for the first packet. */ struct ccn_charbuf *templ = ccn_charbuf_create(); struct ccn_charbuf *path = ccn_charbuf_create(); ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); ccn_charbuf_append_closer(templ); ccn_charbuf_append_tt(templ, CCN_DTAG_ChildSelector, CCN_DTAG); ccn_charbuf_append_tt(templ, 1, CCN_UDATA); ccn_charbuf_append(templ, "1", 1); /* low bit 1: rightmost */ ccn_charbuf_append_closer(templ); /*<ChildSelector>*/ ccn_charbuf_append_closer(templ); ccn_name_from_uri(path, it.key().toLocal8Bit().constData()); ccn_name_append_str(path, "audio"); if (res >= 0) { if (it.value()->data_buf.callback->p == NULL) {fprintf(stderr, "data_buf.callback is NULL!\n"); exit(1); } /* int c = 0; while (pthread_mutex_trylock(&ccn_mutex) != 0) { c++; if (c > 10000000) { fprintf(stderr, "cannot obtain lock! %s:%d\n", __FILE__, __LINE__); std::exit(1); } } */ pthread_mutex_lock(&ccn_mutex); res = ccn_express_interest(ndnState.ccn, path, it.value()->data_buf.callback, templ); pthread_mutex_unlock(&ccn_mutex); it.value()->interested = 1; fprintf(stderr, "short interest sent\n"); } if (res < 0) { fprintf(stderr, "sending the first interest failed\n"); exit(1); } ccn_charbuf_destroy(&path); ccn_charbuf_destroy(&templ); } } ruMutex->unlock(); return res; }
/** * Make a new fdholder corresponding to the fd */ PUBLIC struct fdholder * r_io_record_fd(struct ccnr_handle *h, int fd, void *who, socklen_t wholen, int setflags) { int res; struct fdholder *fdholder = NULL; res = fcntl(fd, F_SETFL, O_NONBLOCK); if (res == -1) ccnr_msg(h, "fcntl: %s", strerror(errno)); fdholder = calloc(1, sizeof(*fdholder)); if (fdholder == NULL) return(fdholder); fdholder->name = ccn_charbuf_create(); if (fdholder->name == NULL) abort(); if (who != NULL) ccn_charbuf_append(fdholder->name, who, wholen); fdholder->filedesc = fd; init_face_flags(h, fdholder, setflags); res = r_io_enroll_face(h, fdholder); if (res == -1) { ccn_charbuf_destroy(&fdholder->name); free(fdholder); fdholder = NULL; } return(fdholder); }
/* * utility, may need to be exported, to parse the buffer into a given slice * structure. */ static int slice_parse(struct ccns_slice *s, const unsigned char *p, size_t size) { int res = 0; struct ccn_buf_decoder decoder; struct ccn_buf_decoder *d = ccn_buf_decoder_start(&decoder, p, size); uintmax_t version; int op; int start; struct ccn_charbuf *clause = NULL; if (!ccn_buf_match_dtag(d, CCN_DTAG_SyncConfigSlice)) return (-1); ccn_buf_advance(d); if (!ccn_buf_match_dtag(d, CCN_DTAG_SyncVersion)) return (-1); ccn_buf_advance(d); ccn_parse_uintmax(d, &version); ccn_buf_check_close(d); if (version != SLICE_VERSION) return (-1); start = d->decoder.token_index; if (ccn_parse_Name(d, NULL) < 0) return(-1); ccn_charbuf_reset(s->topo); res = ccn_charbuf_append(s->topo, p + start, d->decoder.token_index - start); if (res < 0) return(-1); start = d->decoder.token_index; if (ccn_parse_Name(d, NULL) < 0) return(-1); ccn_charbuf_reset(s->prefix); res = ccn_charbuf_append(s->prefix, p + start, d->decoder.token_index - start); if (res < 0) return(-1); if (!ccn_buf_match_dtag(d, CCN_DTAG_SyncConfigSliceList)) return(-1); ccn_buf_advance(d); clause = ccn_charbuf_create(); if (clause == NULL) return(-1); while (ccn_buf_match_dtag(d, CCN_DTAG_SyncConfigSliceOp)) { ccn_buf_advance(d); op = ccn_parse_nonNegativeInteger(d); // op is a small integer ccn_buf_check_close(d); if (op != 0) break; ccn_charbuf_reset(clause); start = d->decoder.token_index; if (ccn_parse_Name(d, NULL) < 0) break; res = ccn_charbuf_append(clause, p + start, d->decoder.token_index - start); ccns_slice_add_clause(s, clause); } ccn_charbuf_destroy(&clause); ccn_buf_check_close(d); /* </SyncConfigSliceList> */ ccn_buf_check_close(d); /* </SyncConfigSlice> */ if (d->decoder.index != size || !CCN_FINAL_DSTATE(d->decoder.state)) return(-1); return(0); }
int main(void) { int res; struct ccn_charbuf *name = NULL; struct ccn_indexbuf *comps = NULL; const unsigned char *comp0 = NULL; size_t comp0size; gen_test(&name, &comps); res = ccn_name_comp_get(name->buf, comps, 0, &comp0, &comp0size); if (res < 0) { printf("Unable to get comp\n"); return(-__LINE__); } intmax_t rec_secs = 0; int rec_nsecs = 0; reclaim_ts(comp0, comp0size, &rec_secs, &rec_nsecs); // printf("seconds = %lu %s\n", rec_secs, (secs == rec_secs)?("YES"):("NO")); // printf("nano seconds = %d %s\n", rec_nsecs, (nsecs == rec_nsecs)?("YES"):("NO")); ccn_charbuf_destroy(&name); ccn_indexbuf_destroy(&comps); return(0); }
/** * Write a ccns_slice object to a repository. * @param h is the ccn_handle on which to write. * @param slice is a pointer to a ccns_slice object to be written. * @param name, if non-NULL, is a pointer to a charbuf which will be filled * in with the name of the slice that was written. * @returns 0 on success, -1 otherwise. */ int ccns_write_slice(struct ccn *h, struct ccns_slice *slice, struct ccn_charbuf *name) { struct ccn_charbuf *n = NULL; int res; // calculate versioned and segmented name for the slice n = ccn_charbuf_create(); if (n == NULL) return(-1); res = ccns_slice_name(n, slice); if (res < 0) goto Cleanup; res |= ccn_create_version(h, n, CCN_V_NOW, 0, 0); if (name != NULL) { ccn_charbuf_reset(name); res |= ccn_charbuf_append_charbuf(name, n); } res |= ccn_name_append_numeric(n, CCN_MARKER_SEQNUM, 0); if (res < 0) goto Cleanup; res = write_slice(h, slice, n); Cleanup: ccn_charbuf_destroy(&n); return (res); }
extern void SyncFreeBase(struct SyncBaseStruct **bp) { if (bp != NULL) { struct SyncBaseStruct *base = *bp; *bp = NULL; if (base != NULL) { struct SyncPrivate *priv = base->priv; // free the errList SyncClearErr(base); // free the roots while (priv->rootHead != NULL) { if (SyncRemRoot(priv->rootHead) != NULL) break; } // free the name accums if (priv->topoAccum != NULL) SyncFreeNameAccumAndNames(priv->topoAccum); if (priv->prefixAccum != NULL) SyncFreeNameAccumAndNames(priv->prefixAccum); if (priv->comps != NULL) ccn_indexbuf_destroy(&priv->comps); ccn_charbuf_destroy(&priv->sliceCmdPrefix); free(priv); free(base); } } }
/** * Produce ccnd debug output. * Output is produced via h->logger under the control of h->debug; * prepends decimal timestamp and process identification. * Caller should not supply newlines. * @param h the ccnd handle * @param fmt printf-like format string */ void ccnd_msg(struct ccnd_handle *h, const char *fmt, ...) { struct timeval t; va_list ap; struct ccn_charbuf *b; int res; const char *portstr; if (h == NULL || h->debug == 0 || h->logger == 0) return; b = ccn_charbuf_create(); gettimeofday(&t, NULL); if (((h->debug & 64) != 0) && ((h->logbreak-- < 0 && t.tv_sec != h->logtime) || t.tv_sec >= h->logtime + 30)) { portstr = h->portstr; if (portstr == NULL) portstr = ""; ccn_charbuf_putf(b, "%ld.000000 ccnd[%d]: %s ____________________ %s", (long)t.tv_sec, h->logpid, h->portstr, ctime(&t.tv_sec)); h->logtime = t.tv_sec; h->logbreak = 30; } ccn_charbuf_putf(b, "%ld.%06u ccnd[%d]: %s\n", (long)t.tv_sec, (unsigned)t.tv_usec, h->logpid, fmt); va_start(ap, fmt); res = (*h->logger)(h->loggerdata, (const char *)b->buf, ap); va_end(ap); ccn_charbuf_destroy(&b); /* if there's no one to hear, don't make a sound */ if (res < 0) h->debug = 0; }
/** * Produce ccnr debug output. * Output is produced via h->logger under the control of h->debug; * prepends decimal timestamp and process identification. * Caller should not supply newlines. * @param h the ccnr handle * @param fmt printf-like format string */ void ccnr_msg(struct ccnr_handle *h, const char *fmt, ...) { struct timeval t; va_list ap; struct ccn_charbuf *b; int res; if (h == NULL || h->debug == 0 || h->logger == 0) return; b = ccn_charbuf_create(); if (b == NULL) return; gettimeofday(&t, NULL); if ((h->debug >= CCNL_FINE) && ((h->logbreak-- < 0 && t.tv_sec != h->logtime) || t.tv_sec >= h->logtime + 30)) { ccn_charbuf_putf(b, "%ld.000000 ccnr[%d]: %s ____________________ %s", (long)t.tv_sec, h->logpid, h->portstr ? h->portstr : "", ctime(&t.tv_sec)); h->logtime = t.tv_sec; h->logbreak = 30; } ccn_charbuf_putf(b, "%ld.%06u ccnr[%d]: %s\n", (long)t.tv_sec, (unsigned)t.tv_usec, h->logpid, fmt); va_start(ap, fmt); /* b should already have null termination, but use call for cleanliness */ res = (*h->logger)(h->loggerdata, ccn_charbuf_as_string(b), ap); va_end(ap); ccn_charbuf_destroy(&b); /* if there's no one to hear, don't make a sound */ if (res < 0) h->debug = 0; }
/* * Utility routine to add a clause to a ccns_slice structure */ int ccns_slice_add_clause(struct ccns_slice *s, struct ccn_charbuf *c) { struct ccn_charbuf **clauses = NULL; struct ccn_charbuf *clause; clause = ccn_charbuf_create_n(c->length); if (clause == NULL) return(-1); if (s->clauses == NULL) { s->clauses = calloc(1, sizeof(s->clauses[0])); if (s->clauses == NULL) goto Cleanup; } else { clauses = realloc(s->clauses, (s->nclauses + 1) * sizeof(s->clauses[0])); if (clauses == NULL) goto Cleanup; s->clauses = clauses; } ccn_charbuf_append_charbuf(clause, c); s->clauses[s->nclauses++] = clause; return (0); Cleanup: ccn_charbuf_destroy(&clause); return (-1); }
void CcnCC_sendContent(CcnCC self, struct ccn_charbuf* name, TimeSpan expires, void* data, size_t size) { struct ccn_signing_params sp = CCN_SIGNING_PARAMS_INIT; if (expires >= 0) { sp.template_ccnb = ccn_charbuf_create(); ccn_charbuf_append_tt(sp.template_ccnb, CCN_DTAG_SignedInfo, CCN_DTAG); ccnb_tagged_putf(sp.template_ccnb, CCN_DTAG_FreshnessSeconds, "%ld", expires / 1000); sp.sp_flags |= CCN_SP_TEMPL_FRESHNESS; ccn_charbuf_append_closer(sp.template_ccnb); } struct ccn_charbuf* content = ccn_charbuf_create(); if (0 == ccn_sign_content(self->ccnh, content, name, &sp, data, size)) { ccn_put(self->ccnh, content->buf, content->length); } ccn_charbuf_destroy(&sp.template_ccnb); ccn_charbuf_destroy(&content); }
PyObject * CCNObject_New_charbuf(enum _pyccn_capsules type, struct ccn_charbuf **charbuf) { struct ccn_charbuf *p; PyObject *py_o; assert(type == CONTENT_OBJECT || type == EXCLUSION_FILTER || type == INTEREST || type == KEY_LOCATOR || type == NAME || type == SIGNATURE || type == SIGNED_INFO); p = ccn_charbuf_create(); if (!p) return PyErr_NoMemory(); py_o = CCNObject_New(type, p); if (!py_o) { ccn_charbuf_destroy(&p); return NULL; } if (charbuf) *charbuf = p; return py_o; }
static int post_face_notice(struct ccnr_handle *ccnr, unsigned filedesc) { struct fdholder *fdholder = ccnr_r_io_fdholder_from_fd(ccnr, filedesc); struct ccn_charbuf *msg = ccn_charbuf_create(); int res = -1; int port; // XXX - text version for trying out stream stuff - replace with ccnb if (fdholder == NULL) ccn_charbuf_putf(msg, "destroyface(%u);\n", filedesc); else { ccn_charbuf_putf(msg, "newface(%u, 0x%x", filedesc, fdholder->flags); if (fdholder->name->length != 0 && (fdholder->flags & (CCNR_FACE_INET | CCNR_FACE_INET6)) != 0) { ccn_charbuf_putf(msg, ", "); port = ccn_charbuf_append_sockaddr(msg, (struct sockaddr *)fdholder->name->buf); if (port < 0) msg->length--; else if (port > 0) ccn_charbuf_putf(msg, ":%d", port); } ccn_charbuf_putf(msg, ");\n", filedesc); } res = ccn_seqw_write(ccnr->notice, msg->buf, msg->length); ccn_charbuf_destroy(&msg); return(res); }
static int start_interest(struct sync_diff_data *diff_data) { static char *here = "sync_track.start_interest"; struct SyncRootStruct *root = diff_data->root; struct SyncBaseStruct *base = root->base; struct ccns_handle *ch = diff_data->client_data; struct SyncHashCacheEntry *ce = ch->next_ce; struct ccn_charbuf *prefix = SyncCopyName(diff_data->root->topoPrefix); int res = 0; struct ccn *ccn = base->sd->ccn; if (ccn == NULL) { ccn_charbuf_destroy(&prefix); return SyncNoteFailed(root, here, "bad ccn handle", __LINE__); } res |= ccn_name_append_str(prefix, "\xC1.S.ra"); res |= ccn_name_append(prefix, root->sliceHash->buf, root->sliceHash->length); if (ce != NULL) { // append the best component seen res |= ccn_name_append(prefix, ce->hash->buf, ce->hash->length); } else { // append an empty component res |= ccn_name_append(prefix, "", 0); } struct SyncNameAccum *excl = SyncExclusionsFromHashList(root, NULL, ch->hashSeen); struct ccn_charbuf *template = SyncGenInterest(NULL,
static struct ccn_charbuf * resolve_templ(struct ccn_charbuf *templ, unsigned const char *vcomp, int size) { if (templ == NULL) templ = ccn_charbuf_create(); if (size < 3 || size > 16) { ccn_charbuf_destroy(&templ); return(NULL); } templ->length = 0; ccn_charbuf_append_tt(templ, CCN_DTAG_Interest, CCN_DTAG); ccn_charbuf_append_tt(templ, CCN_DTAG_Name, CCN_DTAG); ccn_charbuf_append_closer(templ); /* </Name> */ ccn_charbuf_append_tt(templ, CCN_DTAG_Exclude, CCN_DTAG); append_filter_all(templ); ccn_charbuf_append_tt(templ, CCN_DTAG_Component, CCN_DTAG); ccn_charbuf_append_tt(templ, size, CCN_BLOB); ccn_charbuf_append(templ, vcomp, size); ccn_charbuf_append_closer(templ); /* </Component> */ append_future_vcomp(templ); append_filter_all(templ); ccn_charbuf_append_closer(templ); /* </Exclude> */ answer_highest(templ); answer_passive(templ); ccn_charbuf_append_closer(templ); /* </Interest> */ return(templ); }