本文整理汇总了C++中ccn_charbuf_create函数的典型用法代码示例。如果您正苦于以下问题:C++ ccn_charbuf_create函数的具体用法?C++ ccn_charbuf_create怎么用?C++ ccn_charbuf_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ccn_charbuf_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ccndc_initialize_data
struct ccndc_data *
ccndc_initialize_data(void) {
struct ccndc_data *self;
const char *msg = "Unable to initialize ccndc";
int res;
self = calloc(1, sizeof(*self));
if (self == NULL) {
ON_ERROR_EXIT (-1, msg);
}
self->ccn_handle = ccn_create();
ON_ERROR_EXIT(ccn_connect(self->ccn_handle, NULL), "Unable to connect to local ccnd");
ON_ERROR_EXIT(ccndc_get_ccnd_id(self), "Unable to obtain ID of local ccnd");
/* Set up an Interest template to indicate scope 1 (Local) */
self->local_scope_template = ccn_charbuf_create();
res = ccnb_element_begin(self->local_scope_template, CCN_DTAG_Interest);
res |= ccnb_element_begin(self->local_scope_template, CCN_DTAG_Name);
res |= ccnb_element_end(self->local_scope_template); /* </Name> */
res |= ccnb_tagged_putf(self->local_scope_template, CCN_DTAG_Scope, "1");
res |= ccnb_element_end(self->local_scope_template); /* </Interest> */
ON_ERROR_EXIT(res, msg);
/* Create a null name */
self->no_name = ccn_charbuf_create();
ON_ERROR_EXIT(ccn_name_init(self->no_name), msg);
self->lifetime = (~0U) >> 1;
return self;
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:32,代码来源:ccndc.c
示例2: r_store_write_stable_point
/**
* 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);
}
开发者ID:Emat12,项目名称:ccnx,代码行数:33,代码来源:ccnr_store.c
示例3: get_orig_router_from_info_content_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;
}
开发者ID:akaash-nigam,项目名称:NLSR0.0,代码行数:35,代码来源:nlsr_km.c
示例4: ccn_charbuf_create
/**
*
* 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;
}
开发者ID:akaash-nigam,项目名称:OSPFN2.0,代码行数:64,代码来源:ccn_fib.c
示例5: add_delete_ccn_face
static int
add_delete_ccn_face(struct ccn *h, const char *uri, const char *address, const unsigned int p, int operation)
{
struct ccn_charbuf *prefix;
char port[6];
struct ccn_charbuf *local_scope_template = ccn_charbuf_create();
struct ccn_charbuf *no_name = ccn_charbuf_create();
unsigned char ccndid_storage[32] = {0};
unsigned char *ccndid = ccndid_storage;
size_t ccndid_size = 0;
struct ccn_face_instance *fi;
struct ccn_face_instance *nfi;
int res;
prefix = ccn_charbuf_create();
res = ccn_name_from_uri(prefix, uri);
ON_ERROR_CLEANUP(res);
memset(port, 0, 6);
sprintf(port, "%d", p);
init_data(local_scope_template, no_name);
ccndid_size = get_ccndid(h, local_scope_template, ccndid);
if (ccndid_size != sizeof(ccndid_storage))
{
fprintf(stderr, "Incorrect size for ccnd id in response\n");
ON_ERROR_CLEANUP(-1);
}
/* construct a face instance for new face request */
fi = construct_face(ccndid, ccndid_size, address, port);
ON_NULL_CLEANUP(fi);
/* send new face request to actually create a new face */
nfi = create_face(h, local_scope_template, no_name, fi);
ON_NULL_CLEANUP(nfi);
res = register_unregister_prefix(h, local_scope_template, no_name, prefix, nfi, operation);
ON_ERROR_CLEANUP(res);
ccn_charbuf_destroy(&local_scope_template);
ccn_charbuf_destroy(&no_name);
ccn_face_instance_destroy(&fi);
ccn_face_instance_destroy(&nfi);
ccn_charbuf_destroy(&prefix);
return 0;
cleanup:
ccn_charbuf_destroy(&prefix);
ccn_charbuf_destroy(&local_scope_template);
ccn_charbuf_destroy(&no_name);
ccn_face_instance_destroy(&fi);
ccn_face_instance_destroy(&nfi);
return -1;
}
开发者ID:akaash-nigam,项目名称:OSPFN2.0,代码行数:57,代码来源:ccn_fib.c
示例6: get_content_by_content_name
int
get_content_by_content_name(char *content_name, unsigned char **content_data,
char *orig_router)
{
int ret=-1;
struct ccn_charbuf *name = NULL;
struct ccn_charbuf *templ = NULL;
struct ccn_charbuf *resultbuf = NULL;
struct ccn_parsed_ContentObject pcobuf = { 0 };
int res;
int allow_stale = 1;
int content_only = 1;
int scope = -1;
const unsigned char *ptr,*ptr_in;
size_t length,length_in;
int resolve_version = CCN_V_HIGHEST;
int timeout_ms = 3000;
const unsigned lifetime_default = CCN_INTEREST_LIFETIME_SEC << 12;
unsigned lifetime_l12 = lifetime_default;
int get_flags = 0;
name = ccn_charbuf_create();
res = ccn_name_from_uri(name,content_name);
if (res < 0) {
fprintf(stderr, "Bad ccn URI: %s\n", content_name);
ccn_charbuf_destroy(&name);
return ret;
}
if (allow_stale || lifetime_l12 != lifetime_default || scope != -1) {
templ = 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); /* </Name> */
if (allow_stale) {
ccn_charbuf_append_tt(templ, CCN_DTAG_AnswerOriginKind, CCN_DTAG);
ccnb_append_number(templ,
CCN_AOK_DEFAULT | CCN_AOK_STALE);
ccn_charbuf_append_closer(templ); /* </AnswerOriginKind> */
}
if (scope != -1) {
ccnb_tagged_putf(templ, CCN_DTAG_Scope, "%d", scope);
}
if (lifetime_l12 != lifetime_default) {
/*
* Choose the interest lifetime so there are at least 3
* expressions (in the unsatisfied case).
*/
unsigned char buf[3] = { 0 };
int i;
for (i = sizeof(buf) - 1; i >= 0; i--, lifetime_l12 >>= 8)
buf[i] = lifetime_l12 & 0xff;
ccnb_append_tagged_blob(templ, CCN_DTAG_InterestLifetime, buf,
sizeof(buf));
}
开发者ID:myownrhyme,项目名称:NLSR0.0,代码行数:56,代码来源:nlsr_sync.c
示例7: ccn_dhcp_content_parse
int ccn_dhcp_content_parse(const unsigned char *p, size_t size, struct ccn_dhcp_entry *tail)
{
struct ccn_buf_decoder decoder;
struct ccn_buf_decoder *d = ccn_buf_decoder_start(&decoder, p, size);
int i;
int count;
struct ccn_dhcp_entry *de = tail;
if (ccn_buf_match_dtag(d, CCN_DTAG_Entry)) {
ccn_buf_advance(d);
count = ccn_parse_optional_tagged_nonNegativeInteger(d, CCN_DTAG_Count);
for (i = 0; i < count; i ++) {
struct ccn_charbuf *store = ccn_charbuf_create();
size_t start;
size_t end;
int host_off = -1;
int port_off = -1;
de->next = calloc(1, sizeof(*de));
de = de->next;
memset(de, 0, sizeof(*de));
de->store = store;
de->next = NULL;
if (ccn_buf_match_dtag(d, CCN_DTAG_Name)) {
de->name_prefix = ccn_charbuf_create();
start = d->decoder.token_index;
ccn_parse_Name(d, NULL);
end = d->decoder.token_index;
ccn_charbuf_append(de->name_prefix, p + start, end - start);
}
else
de->name_prefix = NULL;
host_off = ccn_parse_tagged_string(d, CCN_DTAG_Host, store);
port_off = ccn_parse_tagged_string(d, CCN_DTAG_Port, store);
char *b = (char *)store->buf;
char *h = b + host_off;
char *p = b + port_off;
if (host_off >= 0)
memcpy((void *)de->address, h, strlen(h));
if (port_off >= 0)
memcpy((void *)de->port, p, strlen(p));
}
}
else
d->decoder.state = -__LINE__;
if (d->decoder.index != size || !CCN_FINAL_DSTATE(d->decoder.state))
ccn_dhcp_content_destroy(tail->next);
return count;
}
开发者ID:NDN-Routing,项目名称:ccnx-dhcp,代码行数:56,代码来源:dhcp_helper.c
示例8: get_orig_router_from_lsa_name
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;
}
开发者ID:akaash-nigam,项目名称:NLSR0.0,代码行数:55,代码来源:nlsr_km.c
示例9: verify_signed_interest
/**
* 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);
}
开发者ID:named-data,项目名称:ndn-lighting,代码行数:66,代码来源:ccn_signed_interest.c
示例10: ccn_event_thread
/**
* Base loop for the background CCN task
*
* This is the main execution loop for the background task responsible for
* interacting with the CCN network. It is from this point that many of the above methods are
* called to work the inbound messages from ccnx as well as sending out the data messages.
*
* \param data the task context information setup by the parent sink element thread
*/
static void
ccn_event_thread (void *data)
{
Gstccnxsink *me = (Gstccnxsink *) data;
struct ccn_charbuf *filtName;
struct ccn_charbuf *temp;
int res = 0;
GST_DEBUG ("CCNxSink event: *** event thread starting");
temp = ccn_charbuf_create ();
filtName = ccn_charbuf_create ();
/* A closure is what defines what to do when an inbound interest arrives */
if ((me->ccn_closure = calloc (1, sizeof (struct ccn_closure))) == NULL) {
GST_ELEMENT_ERROR (me, RESOURCE, READ, (NULL), ("closure alloc failed"));
return;
}
/* We setup the closure to contain the sink element context reference, and also tell it what function to call */
me->ccn_closure->data = me;
me->ccn_closure->p = new_interests;
me->timeouts = 0;
ccn_charbuf_append (filtName, me->name->buf, me->name->length);
/* This call will set up a handler for interests we expect to get from clients */
// hDump(DUMP_ADDR(filtName->buf), DUMP_SIZE(filtName->length));
ccn_set_interest_filter (me->ccn, filtName, me->ccn_closure);
GST_DEBUG ("CCNxSink event: interest filter registered\n");
/* Some debugging information */
temp->length = 0;
ccn_uri_append (temp, me->name->buf, me->name->length, TRUE);
GST_DEBUG ("CCNxSink event: using uri: %s\n", ccn_charbuf_as_string (temp));
/* Now that the interest is registered, we loop around waiting for something to do */
/* We pass control to ccnx for a while so it can work with any incoming or outgoing data */
/* and then we check our fifo queue for work to do. That's about it! */
/* We check to see if any problems have caused our ccnd connection to fail, and we reconnect */
while (res >= 0) {
GST_DEBUG ("CCNxSink event: *** looping");
res = ccn_run (me->ccn, 50);
check_fifo (me);
if (res < 0 && ccn_get_connection_fd (me->ccn) == -1) {
GST_DEBUG ("CCNxSink event: need to reconnect...");
/* Try reconnecting, after a bit of delay */
msleep ((30 + (getpid () % 30)) * 1000);
res = ccn_connect (me->ccn, ccndHost ());
}
}
GST_DEBUG ("CCNxSink event: *** event thread ending");
}
开发者ID:Emat12,项目名称:gstreamer-ccnx,代码行数:62,代码来源:ccnsink.c
示例11: fprintf
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);
}
}
开发者ID:FreshLeaf8865,项目名称:mumble,代码行数:52,代码来源:media_pro.cpp
示例12: ccn_charbuf_create
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;
}
开发者ID:FreshLeaf8865,项目名称:mumble,代码行数:49,代码来源:media_pro.cpp
示例13: ccn_proxy_init
struct ccn_proxy *
ccn_proxy_init(const char *filter_uri,
const char *prefix_uri)
{
struct ccn_proxy *proxy = calloc(1, sizeof(struct ccn_proxy));
struct ccn_buf_decoder decoder;
struct ccn_buf_decoder *d = &decoder;
int res;
DEBUG_PRINT("IN %d %s\n", __LINE__, __func__);
/* Convert URI to name this proxy is responsible for */
proxy->prefix = ccn_charbuf_create();
res = ccn_name_from_uri(proxy->prefix, prefix_uri);
if (res < 0) {
DEBUG_PRINT("ABORT %d %s bad ccn URI: %s\n", __LINE__, __func__, prefix_uri);
abort();
}
d = ccn_buf_decoder_start(d, proxy->prefix->buf, proxy->prefix->length);
proxy->prefix_comps = ccn_indexbuf_create();
proxy->prefix_ncomps = ccn_parse_Name(d, proxy->prefix_comps);
proxy->filter = ccn_charbuf_create();
res = ccn_name_from_uri(proxy->filter, filter_uri);
if (res < 0) {
DEBUG_PRINT("ABORT %d %s bad ccn URI: %s\n", __LINE__, __func__, filter_uri);
abort();
}
/* Initialization should be done by ccn_proxy_connect() */
proxy->handle_name = ccn_charbuf_create();
ccn_charbuf_append_string(proxy->handle_name, "in/outb");
DEBUG_PRINT("OUT %d %s\n", __LINE__, __func__);
return(proxy);
}
开发者ID:chris-wood,项目名称:ANDANAv2,代码行数:48,代码来源:proxy.c
示例14: sync_cb
int
sync_cb(struct ccns_handle *h,
struct ccn_charbuf *lhash,
struct ccn_charbuf *rhash,
struct ccn_charbuf *name)
{
char *hexL;
char *hexR;
struct ccn_charbuf *uri = ccn_charbuf_create();
ccn_uri_append(uri, name->buf, name->length, 1);
if (lhash == NULL || lhash->length == 0) {
hexL = strdup("none");
} else
hexL = hex_string(lhash->buf, lhash->length);
if (rhash == NULL || rhash->length == 0) {
hexR = strdup("none");
} else
hexR = hex_string(rhash->buf, rhash->length);
printf("%s %s %s\n", ccn_charbuf_as_string(uri), hexL, hexR);
fflush(stdout);
free(hexL);
free(hexR);
ccn_charbuf_destroy(&uri);
return(0);
}
开发者ID:ZeningQu,项目名称:Egal,代码行数:25,代码来源:ccnsyncwatch.c
示例15: slice_parse
/*
* 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);
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:64,代码来源:sync_api.c
示例16: ccnr_msg
/**
* 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;
}
开发者ID:ZeningQu,项目名称:Egal,代码行数:40,代码来源:ccnr_msg.c
示例17: r_io_record_fd
/**
* 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);
}
开发者ID:IthacaDream,项目名称:ccnx,代码行数:34,代码来源:ccnr_io.c
示例18: ccn_charbuf_duplicate
static struct ccn_charbuf *
ccn_charbuf_duplicate(struct ccn_charbuf *c)
{
struct ccn_charbuf *ans = ccn_charbuf_create();
ccn_charbuf_append(ans, c->buf, c->length);
return(ans);
}
开发者ID:RazortoothRTC,项目名称:ccnx,代码行数:7,代码来源:ccn_traverse.c
示例19: ccnd_msg
/**
* 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;
}
开发者ID:wjz,项目名称:ccnx,代码行数:41,代码来源:ccnd_msg.c
示例20: post_face_notice
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);
}
开发者ID:GabrielLiz,项目名称:ccnx,代码行数:28,代码来源:ccnr_internal_client.c
注:本文中的ccn_charbuf_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论