diff --git a/ccnl-core.c b/ccnl-core.c index e4491b628932..63ee2d96f022 100644 --- a/ccnl-core.c +++ b/ccnl-core.c @@ -58,10 +58,10 @@ ccnl_content_serve_pending(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c); struct ccnl_content_s* ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c); -static struct ccnl_interest_s* +static struct ccnl_interest_s* ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i); -static struct ccnl_interest_s* +static struct ccnl_interest_s* ccnl_interest_remove_continue_computations(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i); // ---------------------------------------------------------------------- @@ -81,13 +81,13 @@ ccnl_buf_new(void *data, int len) } #endif -#define buf_dup(B) (B) ? ccnl_buf_new(B->data, B->datalen) : NULL -#define buf_equal(X,Y) ((X) && (Y) && (X->datalen==Y->datalen) &&\ - !memcmp(X->data,Y->data,X->datalen)) +#define buf_dup(B) (B) ? ccnl_buf_new(B->data, B->datalen) : NULL +#define buf_equal(X,Y) ((X) && (Y) && (X->datalen==Y->datalen) &&\ + !memcmp(X->data,Y->data,X->datalen)) int ccnl_prefix_cmp(struct ccnl_prefix_s *name, unsigned char *md, - struct ccnl_prefix_s *p, int mode) + struct ccnl_prefix_s *p, int mode) /* returns -1 if no match at all (all modes) or exact match failed returns 0 if full match (CMP_EXACT) returns n>0 for matched components (CMP_MATCH, CMP_LONGEST) */ @@ -96,20 +96,20 @@ ccnl_prefix_cmp(struct ccnl_prefix_s *name, unsigned char *md, unsigned char *comp; if (mode == CMP_EXACT && nlen != p->compcnt) - goto done; + goto done; for (i = 0; i < nlen && i < p->compcnt; i++) { - comp = i < name->compcnt ? name->comp[i] : md; - clen = i < name->compcnt ? name->complen[i] : 32; // SHA256_DIGEST_LEN - if (clen != p->complen[i] || memcmp(comp, p->comp[i], p->complen[i])) { - rc = mode == CMP_EXACT ? -1 : i; - goto done; - } + comp = i < name->compcnt ? name->comp[i] : md; + clen = i < name->compcnt ? name->complen[i] : 32; // SHA256_DIGEST_LEN + if (clen != p->complen[i] || memcmp(comp, p->comp[i], p->complen[i])) { + rc = mode == CMP_EXACT ? -1 : i; + goto done; + } } rc = (mode == CMP_EXACT) ? 0 : i; done: DEBUGMSG(49, "ccnl_prefix_cmp (mode=%d, nlen=%d, plen=%d, %d), name=%s prefix=%s: %d (%p)\n", - mode, nlen, p->compcnt, name->compcnt, - ccnl_prefix_to_path(name), ccnl_prefix_to_path(p), rc, md); + mode, nlen, p->compcnt, name->compcnt, + ccnl_prefix_to_path(name), ccnl_prefix_to_path(p), rc, md); return rc; } @@ -122,28 +122,28 @@ int ccnl_addr_cmp(sockunion *s1, sockunion *s2) { if (s1->sa.sa_family != s2->sa.sa_family) - return -1; + return -1; switch (s1->sa.sa_family) { #ifdef USE_ETHERNET - case AF_PACKET: - return memcmp(s1->eth.sll_addr, s2->eth.sll_addr, ETH_ALEN); + case AF_PACKET: + return memcmp(s1->eth.sll_addr, s2->eth.sll_addr, ETH_ALEN); #endif - case AF_INET: - return s1->ip4.sin_addr.s_addr == s2->ip4.sin_addr.s_addr && - s1->ip4.sin_port == s2->ip4.sin_port ? 0 : -1; + case AF_INET: + return s1->ip4.sin_addr.s_addr == s2->ip4.sin_addr.s_addr && + s1->ip4.sin_port == s2->ip4.sin_port ? 0 : -1; #ifdef USE_UNIXSOCKET - case AF_UNIX: - return strcmp(s1->ux.sun_path, s2->ux.sun_path); + case AF_UNIX: + return strcmp(s1->ux.sun_path, s2->ux.sun_path); #endif - default: - break; + default: + break; } return -1; } struct ccnl_face_s* ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, - struct sockaddr *sa, int addrlen) + struct sockaddr *sa, int addrlen) // sa==NULL means: local(=in memory) client, search for existing ifndx being -1 // sa!=NULL && ifndx==-1: search suitable interface for given sa_family // sa!=NULL && ifndx!=-1: use this (incoming) interface for outgoing @@ -151,51 +151,51 @@ ccnl_get_face_or_create(struct ccnl_relay_s *ccnl, int ifndx, static int seqno, i; struct ccnl_face_s *f; DEBUGMSG(10, "ccnl_get_face_or_create src=%s\n", - sa ? ccnl_addr2ascii((sockunion*)sa) : "(local)"); + sa ? ccnl_addr2ascii((sockunion*)sa) : "(local)"); for (f = ccnl->faces; f; f = f->next) { - if (!sa) { - if (f->ifndx == -1) - return f; - continue; - } - if (ifndx != -1 && !ccnl_addr_cmp(&f->peer, (sockunion*)sa)) { - f->last_used = CCNL_NOW(); - return f; - } + if (!sa) { + if (f->ifndx == -1) + return f; + continue; + } + if (ifndx != -1 && !ccnl_addr_cmp(&f->peer, (sockunion*)sa)) { + f->last_used = CCNL_NOW(); + return f; + } } if (sa && ifndx == -1) { - for (i = 0; i < ccnl->ifcount; i++) { - if (sa->sa_family != ccnl->ifs[i].addr.sa.sa_family) - continue; - ifndx = i; - break; - } - if (ifndx == -1) // no suitable interface found - return NULL; + for (i = 0; i < ccnl->ifcount; i++) { + if (sa->sa_family != ccnl->ifs[i].addr.sa.sa_family) + continue; + ifndx = i; + break; + } + if (ifndx == -1) // no suitable interface found + return NULL; } DEBUGMSG(99, " found suitable interface %d for %s\n", ifndx, - sa ? ccnl_addr2ascii((sockunion*)sa) : "(local)"); + sa ? ccnl_addr2ascii((sockunion*)sa) : "(local)"); f = (struct ccnl_face_s *) ccnl_calloc(1, sizeof(struct ccnl_face_s)); if (!f) - return NULL; + return NULL; f->faceid = ++seqno; f->ifndx = ifndx; if (ifndx >= 0) { - if (ccnl->defaultFaceScheduler) - f->sched = ccnl->defaultFaceScheduler(ccnl, - (void(*)(void*,void*))ccnl_face_CTS); - if (ccnl->ifs[ifndx].reflect) f->flags |= CCNL_FACE_FLAGS_REFLECT; - if (ccnl->ifs[ifndx].fwdalli) f->flags |= CCNL_FACE_FLAGS_FWDALLI; + if (ccnl->defaultFaceScheduler) + f->sched = ccnl->defaultFaceScheduler(ccnl, + (void(*)(void*,void*))ccnl_face_CTS); + if (ccnl->ifs[ifndx].reflect) f->flags |= CCNL_FACE_FLAGS_REFLECT; + if (ccnl->ifs[ifndx].fwdalli) f->flags |= CCNL_FACE_FLAGS_FWDALLI; } if (sa) - memcpy(&f->peer, sa, addrlen); + memcpy(&f->peer, sa, addrlen); else // local client - f->ifndx = -1; + f->ifndx = -1; f->last_used = CCNL_NOW(); DBL_LINKED_LIST_ADD(ccnl->faces, f); return f; @@ -213,35 +213,35 @@ ccnl_face_remove(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) ccnl_frag_destroy(f->frag); for (pit = ccnl->pit; pit; ) { - struct ccnl_pendint_s **ppend, *pend; - if (pit->from == f) - pit->from = NULL; - for (ppend = &pit->pending; *ppend;) { - if ((*ppend)->face == f) { - pend = *ppend; - *ppend = pend->next; - ccnl_free(pend); - } else - ppend = &(*ppend)->next; - } - if (pit->pending) - pit = pit->next; - else - pit = ccnl_interest_remove_continue_computations(ccnl, pit); + struct ccnl_pendint_s **ppend, *pend; + if (pit->from == f) + pit->from = NULL; + for (ppend = &pit->pending; *ppend;) { + if ((*ppend)->face == f) { + pend = *ppend; + *ppend = pend->next; + ccnl_free(pend); + } else + ppend = &(*ppend)->next; + } + if (pit->pending) + pit = pit->next; + else + pit = ccnl_interest_remove_continue_computations(ccnl, pit); } for (ppfwd = &ccnl->fib; *ppfwd;) { - if ((*ppfwd)->face == f) { - struct ccnl_forward_s *pfwd = *ppfwd; - free_prefix(pfwd->prefix); - *ppfwd = pfwd->next; - ccnl_free(pfwd); - } else - ppfwd = &(*ppfwd)->next; + if ((*ppfwd)->face == f) { + struct ccnl_forward_s *pfwd = *ppfwd; + free_prefix(pfwd->prefix); + *ppfwd = pfwd->next; + ccnl_free(pfwd); + } else + ppfwd = &(*ppfwd)->next; } while (f->outq) { - struct ccnl_buf_s *tmp = f->outq->next; - ccnl_free(f->outq); - f->outq = tmp; + struct ccnl_buf_s *tmp = f->outq->next; + ccnl_free(f->outq); + f->outq = tmp; } f2 = f->next; DBL_LINKED_LIST_REMOVE(ccnl->faces, f); @@ -257,8 +257,8 @@ ccnl_interface_cleanup(struct ccnl_if_s *i) ccnl_sched_destroy(i->sched); for (j = 0; j < i->qlen; j++) { - struct ccnl_txrequest_s *r = i->queue + (i->qfront+j)%CCNL_MAX_IF_QLEN; - ccnl_free(r->buf); + struct ccnl_txrequest_s *r = i->queue + (i->qfront+j)%CCNL_MAX_IF_QLEN; + ccnl_free(r->buf); } ccnl_close_socket(i->sock); } @@ -273,10 +273,10 @@ ccnl_interface_CTS(void *aux1, void *aux2) struct ccnl_if_s *ifc = (struct ccnl_if_s *)aux2; struct ccnl_txrequest_s *r, req; DEBUGMSG(25, "ccnl_interface_CTS interface=%p, qlen=%d, sched=%p\n", - (void*)ifc, ifc->qlen, (void*)ifc->sched); + (void*)ifc, ifc->qlen, (void*)ifc->sched); if (ifc->qlen <= 0) - return; + return; r = ifc->queue + ifc->qfront; memcpy(&req, r, sizeof(req)); ifc->qfront = (ifc->qfront + 1) % CCNL_MAX_IF_QLEN; @@ -286,30 +286,30 @@ ccnl_interface_CTS(void *aux1, void *aux2) #ifdef USE_SCHEDULER ccnl_sched_CTS_done(ifc->sched, 1, req.buf->datalen); if (req.txdone) - req.txdone(req.txdone_face, 1, req.buf->datalen); + req.txdone(req.txdone_face, 1, req.buf->datalen); #endif ccnl_free(req.buf); } void ccnl_interface_enqueue(void (tx_done)(void*, int, int), struct ccnl_face_s *f, - struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, - struct ccnl_buf_s *buf, sockunion *dest) + struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, + struct ccnl_buf_s *buf, sockunion *dest) { struct ccnl_txrequest_s *r; DEBUGMSG(9, "ccnl_interface_enqueue interface=%p buf=%p len=%d (qlen=%d)\n", - (void*)ifc, (void*)buf, buf->datalen, ifc->qlen); + (void*)ifc, (void*)buf, buf->datalen, ifc->qlen); if (ifc->qlen >= CCNL_MAX_IF_QLEN) { - DEBUGMSG(2, " DROPPING buf=%p\n", (void*)buf); - ccnl_free(buf); - return; + DEBUGMSG(2, " DROPPING buf=%p\n", (void*)buf); + ccnl_free(buf); + return; } r = ifc->queue + ((ifc->qfront + ifc->qlen) % CCNL_MAX_IF_QLEN); r->buf = buf; memcpy(&r->dst, dest, sizeof(sockunion)); - r->txdone = tx_done; - r->txdone_face = f; + r->txdone = tx_done; + r->txdone_face = f; ifc->qlen++; #ifdef USE_SCHEDULER @@ -324,14 +324,14 @@ ccnl_face_dequeue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) { struct ccnl_buf_s *pkt; DEBUGMSG(20, "ccnl_face_dequeue face=%p (id=%d.%d)\n", - (void *) f, ccnl->id, f->faceid); + (void *) f, ccnl->id, f->faceid); if (!f->outq) - return NULL; + return NULL; pkt = f->outq; f->outq = pkt->next; if (!pkt->next) - f->outqend = NULL; + f->outqend = NULL; pkt->next = NULL; return pkt; } @@ -354,62 +354,62 @@ ccnl_face_CTS(struct ccnl_relay_s *ccnl, struct ccnl_face_s *f) DEBUGMSG(99, "ccnl_face_CTS face=%p sched=%p\n", (void*)f, (void*)f->sched); if (!f->frag || f->frag->protocol == CCNL_FRAG_NONE) { - buf = ccnl_face_dequeue(ccnl, f); - if (buf) - ccnl_interface_enqueue(ccnl_face_CTS_done, f, - ccnl, ccnl->ifs + f->ifndx, buf, &f->peer); + buf = ccnl_face_dequeue(ccnl, f); + if (buf) + ccnl_interface_enqueue(ccnl_face_CTS_done, f, + ccnl, ccnl->ifs + f->ifndx, buf, &f->peer); } #ifdef USE_FRAG else { - sockunion dst; - int ifndx = f->ifndx; - buf = ccnl_frag_getnext(f->frag, &ifndx, &dst); - if (!buf) { - buf = ccnl_face_dequeue(ccnl, f); - ccnl_frag_reset(f->frag, buf, f->ifndx, &f->peer); - buf = ccnl_frag_getnext(f->frag, &ifndx, &dst); - } - if (buf) { - ccnl_interface_enqueue(ccnl_face_CTS_done, f, - ccnl, ccnl->ifs + ifndx, buf, &dst); + sockunion dst; + int ifndx = f->ifndx; + buf = ccnl_frag_getnext(f->frag, &ifndx, &dst); + if (!buf) { + buf = ccnl_face_dequeue(ccnl, f); + ccnl_frag_reset(f->frag, buf, f->ifndx, &f->peer); + buf = ccnl_frag_getnext(f->frag, &ifndx, &dst); + } + if (buf) { + ccnl_interface_enqueue(ccnl_face_CTS_done, f, + ccnl, ccnl->ifs + ifndx, buf, &dst); #ifndef USE_SCHEDULER - ccnl_face_CTS(ccnl, f); // loop to push more fragments + ccnl_face_CTS(ccnl, f); // loop to push more fragments #endif - } + } } #endif } int ccnl_face_enqueue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *to, - struct ccnl_buf_s *buf) + struct ccnl_buf_s *buf) { struct ccnl_buf_s *msg; DEBUGMSG(20, "ccnl_face_enqueue face=%p (id=%d.%d) buf=%p len=%d\n", - (void*) to, ccnl->id, to->faceid, (void*) buf, buf->datalen); + (void*) to, ccnl->id, to->faceid, (void*) buf, buf->datalen); for (msg = to->outq; msg; msg = msg->next) // already in the queue? - if (buf_equal(msg, buf)) { - DEBUGMSG(31, " not enqueued because already there\n"); - ccnl_free(buf); - return -1; - } + if (buf_equal(msg, buf)) { + DEBUGMSG(31, " not enqueued because already there\n"); + ccnl_free(buf); + return -1; + } buf->next = NULL; if (to->outqend) - to->outqend->next = buf; + to->outqend->next = buf; else - to->outq = buf; + to->outq = buf; to->outqend = buf; #ifdef USE_SCHEDULER if (to->sched) { #ifdef USE_FRAG - int len, cnt = ccnl_frag_getfragcount(to->frag, buf->datalen, &len); + int len, cnt = ccnl_frag_getfragcount(to->frag, buf->datalen, &len); #else - int len = buf->datalen, cnt = 1; + int len = buf->datalen, cnt = 1; #endif - ccnl_sched_RTS(to->sched, cnt, len, ccnl, to); + ccnl_sched_RTS(to->sched, cnt, len, ccnl, to); } else - ccnl_face_CTS(ccnl, to); + ccnl_face_CTS(ccnl, to); #else ccnl_face_CTS(ccnl, to); #endif @@ -422,12 +422,12 @@ ccnl_face_enqueue(struct ccnl_relay_s *ccnl, struct ccnl_face_s *to, struct ccnl_interest_s* ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from, - char suite, - struct ccnl_buf_s **pkt, struct ccnl_prefix_s **prefix, - int minsuffix, int maxsuffix) + char suite, + struct ccnl_buf_s **pkt, struct ccnl_prefix_s **prefix, + int minsuffix, int maxsuffix) { struct ccnl_interest_s *i = (struct ccnl_interest_s *) ccnl_calloc(1, - sizeof(struct ccnl_interest_s)); + sizeof(struct ccnl_interest_s)); DEBUGMSG(99, "ccnl_new_interest\n"); if (!i){ @@ -443,15 +443,15 @@ ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from, switch (suite) { #ifdef USE_SUITE_CCNB case CCNL_SUITE_CCNB: - i->details.ccnb.minsuffix = minsuffix; - i->details.ccnb.maxsuffix = maxsuffix; - break; + i->details.ccnb.minsuffix = minsuffix; + i->details.ccnb.maxsuffix = maxsuffix; + break; #endif #ifdef USE_SUITE_NDNTLV case CCNL_SUITE_NDNTLV: - i->details.ndntlv.minsuffix = minsuffix; - i->details.ndntlv.maxsuffix = maxsuffix; - break; + i->details.ndntlv.minsuffix = minsuffix; + i->details.ndntlv.maxsuffix = maxsuffix; + break; #endif } @@ -462,29 +462,29 @@ ccnl_interest_new(struct ccnl_relay_s *ccnl, struct ccnl_face_s *from, int ccnl_interest_append_pending(struct ccnl_interest_s *i, - struct ccnl_face_s *from) + struct ccnl_face_s *from) { struct ccnl_pendint_s *pi, *last = NULL; DEBUGMSG(99, "ccnl_append_pending\n"); for (pi = i->pending; pi; pi = pi->next) { // check whether already listed - if (pi->face == from) { - DEBUGMSG(40, " we found a matching interest, updating time\n"); - pi->last_used = CCNL_NOW(); - return 0; - } - last = pi; + if (pi->face == from) { + DEBUGMSG(40, " we found a matching interest, updating time\n"); + pi->last_used = CCNL_NOW(); + return 0; + } + last = pi; } pi = (struct ccnl_pendint_s *) ccnl_calloc(1,sizeof(struct ccnl_pendint_s)); DEBUGMSG(40, " appending a new pendint entry %p\n", (void *) pi); if (!pi) - return -1; + return -1; pi->face = from; pi->last_used = CCNL_NOW(); if (last) - last->next = pi; + last->next = pi; else - i->pending = pi; + i->pending = pi; return 0; } @@ -549,7 +549,7 @@ ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i) } fprintf(stderr, "\n"); while (i->pending) { - struct ccnl_pendint_s *tmp = i->pending->next; \ + struct ccnl_pendint_s *tmp = i->pending->next; \ ccnl_free(i->pending); i->pending = tmp; } @@ -570,8 +570,8 @@ ccnl_interest_remove(struct ccnl_relay_s *ccnl, struct ccnl_interest_s *i) } struct ccnl_interest_s* -ccnl_interest_remove_continue_computations(struct ccnl_relay_s *ccnl, - struct ccnl_interest_s *i){ +ccnl_interest_remove_continue_computations(struct ccnl_relay_s *ccnl, + struct ccnl_interest_s *i){ struct ccnl_interest_s *interest; int faceid = 0; DEBUGMSG(99, "ccnl_interest_remove_continue_computations()\n"); @@ -601,11 +601,11 @@ ccnl_interest_remove_continue_computations(struct ccnl_relay_s *ccnl, int ccnl_i_prefixof_c(struct ccnl_prefix_s *prefix, - int minsuffix, int maxsuffix, struct ccnl_content_s *c) + int minsuffix, int maxsuffix, struct ccnl_content_s *c) { unsigned char *md; DEBUGMSG(99, "ccnl_i_prefixof_c prefix=%s min=%d max=%d\n", - ccnl_prefix_to_path(prefix), minsuffix, maxsuffix); + ccnl_prefix_to_path(prefix), minsuffix, maxsuffix); // CONFORM: we do prefix match, honour min. and maxsuffix, // and check the PublisherPublicKeyDigest if present @@ -615,8 +615,8 @@ ccnl_i_prefixof_c(struct ccnl_prefix_s *prefix, // >> CCNL does not honour the exclusion filtering if ( (prefix->compcnt + minsuffix) > (c->name->compcnt + 1) || - (prefix->compcnt + maxsuffix) < (c->name->compcnt + 1) ) - return 0; + (prefix->compcnt + maxsuffix) < (c->name->compcnt + 1) ) + return 0; md = prefix->compcnt - c->name->compcnt == 1 ? compute_ccnx_digest(c->pkt) : NULL; return ccnl_prefix_cmp(c->name, md, prefix, CMP_MATCH) == prefix->compcnt; @@ -624,8 +624,8 @@ ccnl_i_prefixof_c(struct ccnl_prefix_s *prefix, struct ccnl_content_s* ccnl_content_new(struct ccnl_relay_s *ccnl, char suite, struct ccnl_buf_s **pkt, - struct ccnl_prefix_s **prefix, struct ccnl_buf_s **ppk, - unsigned char *content, int contlen) + struct ccnl_prefix_s **prefix, struct ccnl_buf_s **ppk, + unsigned char *content, int contlen) { struct ccnl_content_s *c; DEBUGMSG(99, "ccnl_content_new <%s>\n", @@ -640,15 +640,15 @@ ccnl_content_new(struct ccnl_relay_s *ccnl, char suite, struct ccnl_buf_s **pkt, c->pkt = *pkt; *pkt = NULL; c->name = *prefix; *prefix = NULL; if (ppk) { - switch (suite) { + switch (suite) { #ifdef USE_SUITE_CCNB - case CCNL_SUITE_CCNB: c->details.ccnb.ppkd = *ppk; break; + case CCNL_SUITE_CCNB: c->details.ccnb.ppkd = *ppk; break; #endif #ifdef USE_SUITE_NDNTLV - case CCNL_SUITE_NDNTLV: c->details.ndntlv.ppkl = *ppk; break; + case CCNL_SUITE_NDNTLV: c->details.ndntlv.ppkl = *ppk; break; #endif - } - *ppk = NULL; + } + *ppk = NULL; } return c; } @@ -682,15 +682,15 @@ ccnl_content_add2cache(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c) } #endif if (ccnl->max_cache_entries > 0 && - ccnl->contentcnt >= ccnl->max_cache_entries) { // remove oldest content - struct ccnl_content_s *c2; - int age = 0; - for (c2 = ccnl->contents; c2; c2 = c2->next) - if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) && - ((age == 0) || c2->last_used < age)) - age = c2->last_used; - if (c2) - ccnl_content_remove(ccnl, c2); + ccnl->contentcnt >= ccnl->max_cache_entries) { // remove oldest content + struct ccnl_content_s *c2; + int age = 0; + for (c2 = ccnl->contents; c2; c2 = c2->next) + if (!(c2->flags & CCNL_CONTENT_FLAGS_STATIC) && + ((age == 0) || c2->last_used < age)) + age = c2->last_used; + if (c2) + ccnl_content_remove(ccnl, c2); } DBL_LINKED_LIST_ADD(ccnl->contents, c); ccnl->contentcnt++; @@ -709,7 +709,7 @@ ccnl_content_serve_pending(struct ccnl_relay_s *ccnl, struct ccnl_content_s *c) DEBUGMSG(99, "ccnl_content_serve_pending\n"); for (f = ccnl->faces; f; f = f->next){ - f->flags &= ~CCNL_FACE_FLAGS_SERVED; // reply on a face only once + f->flags &= ~CCNL_FACE_FLAGS_SERVED; // reply on a face only once } for (i = ccnl->pit; i;) { struct ccnl_pendint_s *pi; @@ -782,38 +782,38 @@ ccnl_do_ageing(void *ptr, void *dummy) DEBUGMSG(999, "ccnl_do_ageing %d\n", (int)t); while (c) { - if ((c->last_used + CCNL_CONTENT_TIMEOUT) <= t && - !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) - c = ccnl_content_remove(relay, c); - else - c = c->next; + if ((c->last_used + CCNL_CONTENT_TIMEOUT) <= t && + !(c->flags & CCNL_CONTENT_FLAGS_STATIC)) + c = ccnl_content_remove(relay, c); + else + c = c->next; } while (i) { // CONFORM: "Entries in the PIT MUST timeout rather - // than being held indefinitely." - if ((i->last_used + CCNL_INTEREST_TIMEOUT) <= t || - i->retries > CCNL_MAX_INTEREST_RETRANSMIT){ + // than being held indefinitely." + if ((i->last_used + CCNL_INTEREST_TIMEOUT) <= t || + i->retries > CCNL_MAX_INTEREST_RETRANSMIT){ i = ccnl_interest_remove_continue_computations(relay, i); } - else { - // CONFORM: "A node MUST retransmit Interest Messages - // periodically for pending PIT entries." - DEBUGMSG(7, " retransmit %d <%s>\n", i->retries, ccnl_prefix_to_path(i->prefix)); + else { + // CONFORM: "A node MUST retransmit Interest Messages + // periodically for pending PIT entries." + DEBUGMSG(7, " retransmit %d <%s>\n", i->retries, ccnl_prefix_to_path(i->prefix)); #ifdef CCNL_NFN - if(i->propagate) ccnl_interest_propagate(relay, i); + if(i->propagate) ccnl_interest_propagate(relay, i); #else ccnl_interest_propagate(relay, i); #endif - i->retries++; - i = i->next; - } + i->retries++; + i = i->next; + } } while (f) { - if (!(f->flags & CCNL_FACE_FLAGS_STATIC) && + if (!(f->flags & CCNL_FACE_FLAGS_STATIC) && (f->last_used + CCNL_FACE_TIMEOUT) <= t){ - f = ccnl_face_remove(relay, f); + f = ccnl_face_remove(relay, f); } - else - f = f->next; + else + f = f->next; } } @@ -825,19 +825,19 @@ ccnl_nonce_find_or_append(struct ccnl_relay_s *ccnl, struct ccnl_buf_s *nonce) DEBUGMSG(99, "ccnl_nonce_find_or_append\n"); for (n = ccnl->nonces, i = 0; n; n = n->next, i++) { - if (buf_equal(n, nonce)) - return -1; - if (n->next) - n2 = n; + if (buf_equal(n, nonce)) + return -1; + if (n->next) + n2 = n; } n = ccnl_buf_new(nonce->data, nonce->datalen); if (n) { - n->next = ccnl->nonces; - ccnl->nonces = n; - if (i >= CCNL_MAX_NONCES && n2) { - ccnl_free(n2->next); - n2->next = 0; - } + n->next = ccnl->nonces; + ccnl->nonces = n; + if (i >= CCNL_MAX_NONCES && n2) { + ccnl_free(n2->next); + n2->next = 0; + } } return 0; } @@ -849,18 +849,18 @@ ccnl_core_cleanup(struct ccnl_relay_s *ccnl) DEBUGMSG(99, "ccnl_core_cleanup %p\n", (void *) ccnl); while (ccnl->pit) - ccnl_interest_remove(ccnl, ccnl->pit); + ccnl_interest_remove(ccnl, ccnl->pit); while (ccnl->faces) - ccnl_face_remove(ccnl, ccnl->faces); // also removes all FWD entries + ccnl_face_remove(ccnl, ccnl->faces); // also removes all FWD entries while (ccnl->contents) - ccnl_content_remove(ccnl, ccnl->contents); + ccnl_content_remove(ccnl, ccnl->contents); while (ccnl->nonces) { - struct ccnl_buf_s *tmp = ccnl->nonces->next; - ccnl_free(ccnl->nonces); - ccnl->nonces = tmp; + struct ccnl_buf_s *tmp = ccnl->nonces->next; + ccnl_free(ccnl->nonces); + ccnl->nonces = tmp; } for (k = 0; k < ccnl->ifcount; k++) - ccnl_interface_cleanup(ccnl->ifs + k); + ccnl_interface_cleanup(ccnl->ifs + k); } // ---------------------------------------------------------------------- @@ -880,20 +880,20 @@ ccnl_pkt2suite(unsigned char *data, int len) { #ifdef USE_SUITE_CCNB if (*data == 0x01 || *data == 0x04) - return CCNL_SUITE_CCNB; + return CCNL_SUITE_CCNB; #endif #ifdef USE_SUITE_CCNTLV if (data[0] == 0 && len > 1) { - if (data[1] == CCNX_TLV_TL_Interest || - data[1] == CCNX_TLV_TL_Object) - return CCNL_SUITE_CCNTLV; + if (data[1] == CCNX_TLV_TL_Interest || + data[1] == CCNX_TLV_TL_Object) + return CCNL_SUITE_CCNTLV; } #endif #ifdef USE_SUITE_NDNTLV if (*data == 0x05 || *data == 0x06) - return CCNL_SUITE_NDNTLV; + return CCNL_SUITE_NDNTLV; #endif return -1; @@ -901,7 +901,7 @@ ccnl_pkt2suite(unsigned char *data, int len) void ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data, - int datalen, struct sockaddr *sa, int addrlen) + int datalen, struct sockaddr *sa, int addrlen) { struct ccnl_face_s *from; DEBUGMSG(14, "ccnl_core_RX ifndx=%d, %d bytes\n", ifndx, datalen); @@ -912,20 +912,20 @@ ccnl_core_RX(struct ccnl_relay_s *relay, int ifndx, unsigned char *data, switch (ccnl_pkt2suite(data, datalen)) { #ifdef USE_SUITE_CCNB case CCNL_SUITE_CCNB: - ccnl_RX_ccnb(relay, from, &data, &datalen); break; + ccnl_RX_ccnb(relay, from, &data, &datalen); break; #endif #ifdef USE_SUITE_CCNTLV case CCNL_SUITE_CCNTLV: - ccnl_RX_ccntlv(relay, from, &data, &datalen); break; + ccnl_RX_ccntlv(relay, from, &data, &datalen); break; #endif #ifdef USE_SUITE_NDNTLV case CCNL_SUITE_NDNTLV: - ccnl_RX_ndntlv(relay, from, &data, &datalen); break; + ccnl_RX_ndntlv(relay, from, &data, &datalen); break; #endif default: - DEBUGMSG(6, "?unknown packet? ccnl_core_RX ifndx=%d, %d bytes %d\n", - ifndx, datalen, *data); - break; + DEBUGMSG(6, "?unknown packet? ccnl_core_RX ifndx=%d, %d bytes %d\n", + ifndx, datalen, *data); + break; } } diff --git a/krivine.c b/krivine.c index 025e500c7400..7bc52531e558 100644 --- a/krivine.c +++ b/krivine.c @@ -27,14 +27,14 @@ new_closure(char *term, struct environment_s *env){ return ret; } -void +void push_to_stack(struct stack_s **top, void *content, int type){ struct stack_s *h = malloc(sizeof(struct stack_s)); if(top != NULL && *top != NULL){ h->next = *top; }else{ - h->next = NULL; - } + h->next = NULL; + } h->content = content; h->type = type; *top = h; @@ -47,7 +47,7 @@ pop_from_stack(struct stack_s **top){ if( *top != NULL){ struct stack_s *h = *top; res = h; - *top = h->next; + *top = h->next; return res; } return NULL; @@ -97,17 +97,17 @@ pop_or_resolve_from_result_stack(struct ccnl_relay_s *ccnl, struct configuration return elm; } -void +void print_environment(struct environment_s *env){ struct environment_s *e; printf("Environment address is: %p\n", (void *)env); int num = 0; for(e = env; e; e = e->next){ - printf("Element %d %s %p\n", num++, e->name, e->element); + printf("Element %d %s %p\n", num++, e->name, e->element); } } -void +void print_result_stack(struct stack_s *stack){ struct stack_s *s; int num = 0; @@ -116,19 +116,19 @@ print_result_stack(struct stack_s *stack){ } } -void +void print_argument_stack(struct stack_s *stack){ struct stack_s *s; int num = 0; for(s = stack; s; s = s->next){ struct closure_s *c = s->content; - printf("Element %d %s\n ---Env: \n", num++, c->term); - print_environment(c->env); - printf("--End Env\n"); + printf("Element %d %s\n ---Env: \n", num++, c->term); + print_environment(c->env); + printf("--End Env\n"); } } -void +void add_to_environment(struct environment_s **env, char *name, void *element){ struct environment_s *newelement = malloc(sizeof(struct environment_s)); newelement->name = name; @@ -145,9 +145,9 @@ void * search_in_environment(struct environment_s *env, char *name){ struct environment_s *envelement; for(envelement = env; envelement; envelement = envelement->next){ - if(!strcmp(name, envelement->name)){ - return envelement->element; - } + if(!strcmp(name, envelement->name)){ + return envelement->element; + } } return NULL; } @@ -171,11 +171,11 @@ parse_var(char **cpp) p = *cpp; while (*p && (isalnum(*p) || *p == '_' || *p == '=' || *p == '/')) - p++; + p++; len = p - *cpp; p = malloc(len+1); if (!p) - return 0; + return 0; memcpy(p, *cpp, len); p[len] = '\0'; *cpp += len; @@ -194,46 +194,46 @@ parseKRIVINE(int lev, char **cp) struct term_s *t = 0, *s, *u; while (**cp) { - while (isspace(**cp)) - *cp += 1; - -// printf("parseKRIVINE %d %s\n", lev, *cp); - - if (**cp == ')') - return t; - if (**cp == '(') { - *cp += 1; - s = parseKRIVINE(lev+1, cp); - if (!s) - return 0; - if (**cp != ')') { - printf("parseKRIVINE error: missing )\n"); - return 0; - } else - *cp += 1; - } else if (**cp == LAMBDA) { - *cp += 1; - s = calloc(1, sizeof(*s)); - s->v = parse_var(cp); - s->m = parseKRIVINE(lev+1, cp); -// printKRIVINE(dummybuf, s->m, 0); -// printf(" after lambda: /%s %s --> <%s>\n", s->v, dummybuf, *cp); - } else { - s = calloc(1, sizeof(*s)); - s->v = parse_var(cp); -// printf(" var: <%s>\n", s->v); - } - if (t) { -// printKRIVINE(dummybuf, t, 0); -// printf(" old term: <%s>\n", dummybuf); - u = calloc(1, sizeof(*u)); - u->m = t; - u->n = s; - t = u; - } else - t = s; -// printKRIVINE(dummybuf, t, 0); -// printf(" new term: <%s>\n", dummybuf); + while (isspace(**cp)) + *cp += 1; + +// printf("parseKRIVINE %d %s\n", lev, *cp); + + if (**cp == ')') + return t; + if (**cp == '(') { + *cp += 1; + s = parseKRIVINE(lev+1, cp); + if (!s) + return 0; + if (**cp != ')') { + printf("parseKRIVINE error: missing )\n"); + return 0; + } else + *cp += 1; + } else if (**cp == LAMBDA) { + *cp += 1; + s = calloc(1, sizeof(*s)); + s->v = parse_var(cp); + s->m = parseKRIVINE(lev+1, cp); +// printKRIVINE(dummybuf, s->m, 0); +// printf(" after lambda: /%s %s --> <%s>\n", s->v, dummybuf, *cp); + } else { + s = calloc(1, sizeof(*s)); + s->v = parse_var(cp); +// printf(" var: <%s>\n", s->v); + } + if (t) { +// printKRIVINE(dummybuf, t, 0); +// printf(" old term: <%s>\n", dummybuf); + u = calloc(1, sizeof(*u)); + u->m = t; + u->n = s; + t = u; + } else + t = s; +// printKRIVINE(dummybuf, t, 0); +// printf(" new term: <%s>\n", dummybuf); } // printKRIVINE(dummybuf, t, 0); // printf(" we return <%s>\n", dummybuf); @@ -246,17 +246,17 @@ printKRIVINE(char *cfg, struct term_s *t, char last) int len = 0; if (t->v && t->m) { // Lambda (sequence) - len += sprintf(cfg + len, "(%c%s", LAMBDA, t->v); - len += printKRIVINE(cfg + len, t->m, 'a'); - len += sprintf(cfg + len, ")"); - return len; + len += sprintf(cfg + len, "(%c%s", LAMBDA, t->v); + len += printKRIVINE(cfg + len, t->m, 'a'); + len += sprintf(cfg + len, ")"); + return len; } if (t->v) { // (single) variable - if (isalnum(last)) - len += sprintf(cfg + len, " %s", t->v); - else - len += sprintf(cfg + len, "%s", t->v); - return len; + if (isalnum(last)) + len += sprintf(cfg + len, " %s", t->v); + else + len += sprintf(cfg + len, "%s", t->v); + return len; } // application (sequence) #ifdef CORRECT_PARENTHESES @@ -266,22 +266,22 @@ printKRIVINE(char *cfg, struct term_s *t, char last) len += sprintf(cfg + len, ")"); #else if (t->n->v && !t->n->m) { - len += printKRIVINE(cfg + len, t->m, last); - len += printKRIVINE(cfg + len, t->n, 'a'); + len += printKRIVINE(cfg + len, t->m, last); + len += printKRIVINE(cfg + len, t->n, 'a'); } else { - len += printKRIVINE(cfg + len, t->m, last); - len += sprintf(cfg + len, " ("); - len += printKRIVINE(cfg + len, t->n, '('); - len += sprintf(cfg + len, ")"); + len += printKRIVINE(cfg + len, t->m, last); + len += sprintf(cfg + len, " ("); + len += printKRIVINE(cfg + len, t->n, '('); + len += sprintf(cfg + len, ")"); } #endif return len; } int iscontent(char *cp){ - if(cp[0] == '/') - return 1; - return 0; + if(cp[0] == '/') + return 1; + return 0; } //------------------------------------------------------------ @@ -326,7 +326,7 @@ int choose_parameter(struct configuration_s *config){ if(h1->type == STACK_TYPE_INT) i2 = *(int*)h2->content;\ }while(0) ; //------------------------------------------------------------ - + struct ccnl_prefix_s * create_namecomps(struct ccnl_relay_s *ccnl, struct configuration_s *config, int parameter_number, int thunk_request, struct ccnl_prefix_s *prefix) @@ -344,8 +344,8 @@ create_namecomps(struct ccnl_relay_s *ccnl, struct configuration_s *config, int } char* -ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, - int thunk_request, int *num_of_required_thunks, +ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, + int thunk_request, int *num_of_required_thunks, int *halt, char *dummybuf, int *restart) { struct term_s *t; @@ -353,11 +353,11 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, int len; char *prog = config->prog; memset(dummybuf, 0, 2000); - + //pop closure if (!prog || strlen(prog) == 0) { if(config->result_stack){ - return config->result_stack->content; + return config->result_stack->content; } DEBUGMSG(2, "no result returned\n"); return NULL; @@ -397,7 +397,7 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, cp = pending-1; else cp = prog + strlen(prog) - 1; - len = cp - p; + len = cp - p; cp = malloc(len); memcpy(cp, p+1, len-1); cp[len-1] = '\0'; @@ -407,11 +407,11 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, char v[500], *c; int len; c = strchr(cp+12, ')'); if (!c) goto normal; - len = c - (cp+12); - memcpy(v, cp+12, len); - v[len] = '\0'; - struct closure_s *closure = search_in_environment(config->env, v); - if(!closure) goto normal; + len = c - (cp+12); + memcpy(v, cp+12, len); + v[len] = '\0'; + struct closure_s *closure = search_in_environment(config->env, v); + if(!closure) goto normal; if(!strcmp(closure->term, cp)){ DEBUGMSG(2, "** detected tail recursion case %s\n", closure->term); }else{ @@ -421,7 +421,7 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, else{ struct closure_s *closure; normal: - closure = new_closure(cp, config->env); + closure = new_closure(cp, config->env); //configuration->env = NULL;//FIXME new environment? push_to_stack(&config->argument_stack, closure, STACK_TYPE_CLOSURE); } @@ -429,27 +429,27 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, cp = pending + 1; } else{ - printf("** not implemented %d\n", __LINE__); + printf("** not implemented %d\n", __LINE__); } return cp; } if (!strncmp(prog, "GRAB(", 5)) { char *v; if (pending) - v = pending-1; - else - v = prog + strlen(prog) - 1; - len = v - p; - v = malloc(len); - memcpy(v, p+1, len-1); - v[len-1] = '\0'; - DEBUGMSG(2, "---to do: grab <%s>\n", v); + v = pending-1; + else + v = prog + strlen(prog) - 1; + len = v - p; + v = malloc(len); + memcpy(v, p+1, len-1); + v[len-1] = '\0'; + DEBUGMSG(2, "---to do: grab <%s>\n", v); struct stack_s *stack = pop_from_stack(&config->argument_stack); struct closure_s *closure = (struct closure_s *) stack->content; - add_to_environment(&config->env, v, closure); + add_to_environment(&config->env, v, closure); - if(pending) + if(pending) pending++; return pending; } @@ -465,21 +465,21 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, }else{ sprintf(dummybuf, "%s", code); } - config->env = closure->env; //set environment from closure + config->env = closure->env; //set environment from closure return strdup(dummybuf); } if (!strncmp(prog, "RESOLVENAME(", 12)) { - char res[1000]; - memset(res,0,sizeof(res)); + char res[1000]; + memset(res,0,sizeof(res)); if (pending) - cp = pending-1; - else - cp = prog + strlen(prog) - 1; + cp = pending-1; + else + cp = prog + strlen(prog) - 1; len = cp - p; cp = malloc(len); - memcpy(cp, p+1, len-1); - cp[len-1] = '\0'; - DEBUGMSG(2, "---to do: resolveNAME <%s>\n", cp); + memcpy(cp, p+1, len-1); + cp[len-1] = '\0'; + DEBUGMSG(2, "---to do: resolveNAME <%s>\n", cp); //function definition if(!strncmp(cp, "let", 3)){ @@ -496,37 +496,37 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, pendinglength = strlen(res+end) + strlen("RESOLVENAME()"); h = strchr(cp, '='); namelength = h - cp; - - + + lambda_expr = malloc(strlen(h)); name = malloc(namelength); pending = malloc(pendinglength); - + memset(pending, 0, pendinglength); memset(name, 0, namelength); memset(lambda_expr, 0, strlen(h)); - + sprintf(pending, "RESOLVENAME(%s)", res+end+7); //add 7 to overcome endlet - + memcpy(name, cp+3, namelength-3); //copy name without let and endlet trim(name); - + lambdalen = strlen(h)-strlen(pending)+11-6; memcpy(lambda_expr, h+1, lambdalen); //copy lambda expression without = trim(lambda_expr); resolveterm = malloc(strlen("RESOLVENAME()")+strlen(lambda_expr)); sprintf(resolveterm, "RESOLVENAME(%s)", lambda_expr); - + struct closure_s *cl = new_closure(resolveterm, NULL); add_to_environment(&config->env, name, cl); - + return pending; } - + //check if term can be made available, if yes enter it as a var - //try with searching in global env for an added term! + //try with searching in global env for an added term! t = parseKRIVINE(0, &cp); - if (term_is_var(t)) { + if (term_is_var(t)) { char *end = 0; cp = t->v; if (isdigit(*cp)) { @@ -539,7 +539,7 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, if(end){ push_to_stack(&config->result_stack, integer, STACK_TYPE_INT); } - } + } else if(iscontent(cp)){ // is content... DEBUGMSG(99, "VAR IS CONTENT: %s\n", cp); @@ -560,45 +560,45 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, } return strdup(res); } - if (term_is_lambda(t)) { + if (term_is_lambda(t)) { char *var; - var = t->v; - printKRIVINE(dummybuf, t->m, 0); - cp = strdup(dummybuf); + var = t->v; + printKRIVINE(dummybuf, t->m, 0); + cp = strdup(dummybuf); if (pending) - sprintf(res, "GRAB(%s);RESOLVENAME(%s)%s", var, cp, pending); - else - sprintf(res, "GRAB(%s);RESOLVENAME(%s)", var, cp); - free(cp); + sprintf(res, "GRAB(%s);RESOLVENAME(%s)%s", var, cp, pending); + else + sprintf(res, "GRAB(%s);RESOLVENAME(%s)", var, cp); + free(cp); return strdup(res); } if (term_is_app(t)) { printKRIVINE(dummybuf, t->n, 0); - p = strdup(dummybuf); - printKRIVINE(dummybuf, t->m, 0); - cp = strdup(dummybuf); - + p = strdup(dummybuf); + printKRIVINE(dummybuf, t->m, 0); + cp = strdup(dummybuf); + if (pending) - sprintf(res, "CLOSURE(RESOLVENAME(%s));RESOLVENAME(%s)%s", p, cp, pending); - else - sprintf(res, "CLOSURE(RESOLVENAME(%s));RESOLVENAME(%s)", p, cp); - + sprintf(res, "CLOSURE(RESOLVENAME(%s));RESOLVENAME(%s)%s", p, cp, pending); + else + sprintf(res, "CLOSURE(RESOLVENAME(%s));RESOLVENAME(%s)", p, cp); + return strdup(res); } } if (!strncmp(prog, "OP_CMPEQ_CHURCH", 15)) { - int i1, i2, acc; + int i1, i2, acc; char res[1000]; - memset(res, 0, sizeof(res)); - DEBUGMSG(2, "---to do: OP_CMPEQ <%s>/<%s>\n", cp, pending); - pop2int(); - acc = i1 == i2; + memset(res, 0, sizeof(res)); + DEBUGMSG(2, "---to do: OP_CMPEQ <%s>/<%s>\n", cp, pending); + pop2int(); + acc = i1 == i2; cp = acc ? "@x@y x" : "@x@y y"; if (pending) - sprintf(res, "RESOLVENAME(%s)%s", cp, pending); - else - sprintf(res, "RESOLVENAME(%s)", cp); - return strdup(res); + sprintf(res, "RESOLVENAME(%s)%s", cp, pending); + else + sprintf(res, "RESOLVENAME(%s)", cp); + return strdup(res); } if (!strncmp(prog, "OP_CMPLEQ_CHURCH", 16)) { int i1, i2, acc; @@ -615,21 +615,21 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, return strdup(res); } if (!strncmp(prog, "OP_CMPEQ", 8)) { - int i1, i2, acc; + int i1, i2, acc; char res[1000]; - memset(res, 0, sizeof(res)); + memset(res, 0, sizeof(res)); DEBUGMSG(2, "---to do: OP_CMPEQ<%s>\n", pending); - pop2int(); - acc = i1 == i2; + pop2int(); + acc = i1 == i2; if(acc) cp = "1"; else cp = "0"; if (pending) - sprintf(res, "RESOLVENAME(%s)%s", cp, pending); - else - sprintf(res, "RESOLVENAME(%s)", cp); - return strdup(res); + sprintf(res, "RESOLVENAME(%s)%s", cp, pending); + else + sprintf(res, "RESOLVENAME(%s)", cp); + return strdup(res); } if (!strncmp(prog, "OP_CMPLEQ", 9)) { int i1, i2, acc; @@ -734,7 +734,7 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, int local_search = 0; if(*restart) { *restart = 0; - local_search = 1; + local_search = 1; goto recontinue; } DEBUGMSG(2, "---to do: OP_FOX <%s>\n", prog+7); @@ -744,7 +744,7 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, DEBUGMSG(99, "NUM OF PARAMS: %d\n", config->fox_state->num_of_params); int i; config->fox_state->params = malloc(sizeof(struct ccnl_prefix_s *) * config->fox_state->num_of_params); - + for(i = 0; i < config->fox_state->num_of_params; ++i){ //pop parameter from stack //config->fox_state->params[i] = pop_or_resolve_from_result_stack(ccnl, config, restart); config->fox_state->params[i] = pop_from_stack(&config->result_stack); @@ -851,13 +851,13 @@ ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, DEBUGMSG(99, "Created a mapping %s - %s\n", ccnl_prefix_to_path2(mapping->key), ccnl_prefix_to_path2(mapping->value)); } } - } + } DEBUGMSG(99, "Pending: %s\n", pending+1); return pending+1; } - + if(!strncmp(prog, "halt", 4)){ - *halt = 1; + *halt = 1; return pending; } @@ -886,14 +886,14 @@ setup_global_environment(struct environment_s **env){ closure = new_closure("RESOLVENAME(@expr@yes@no(expr yes no))", NULL); add_to_environment(env, "ifelse_church", closure); - + //Operator on integer numbers closure = new_closure("CLOSURE(OP_CMPEQ);RESOLVENAME(@op(@x(@y x y op)))", NULL); add_to_environment(env, "eq", closure); closure = new_closure("CLOSURE(OP_CMPLEQ);RESOLVENAME(@op(@x(@y x y op)))", NULL); add_to_environment(env, "leq", closure); - + closure = new_closure("CLOSURE(OP_IFELSE);RESOLVENAME(@op(@x x op));TAILAPPLY", NULL); add_to_environment(env, "ifelse", closure); @@ -902,7 +902,7 @@ setup_global_environment(struct environment_s **env){ closure = new_closure("CLOSURE(OP_SUB);RESOLVENAME(@op(@x(@y x y op)));TAILAPPLY", NULL); add_to_environment(env, "sub", closure); - + closure = new_closure("CLOSURE(OP_MULT);RESOLVENAME(@op(@x(@y x y op)));TAILAPPLY", NULL); add_to_environment(env, "mult", closure); @@ -915,7 +915,7 @@ Krivine_reduction(struct ccnl_relay_s *ccnl, char *expression, int thunk_request int start_locally, int num_of_required_thunks, struct configuration_s **config, struct ccnl_prefix_s *prefix, int suite){ DEBUGMSG(99, "Krivine_reduction()\n"); - int steps = 0; + int steps = 0; int halt = 0; int restart = 1; int len = strlen("CLOSURE(halt);RESOLVENAME()") + strlen(expression); @@ -940,9 +940,9 @@ Krivine_reduction(struct ccnl_relay_s *ccnl, char *expression, int thunk_request DEBUGMSG(99, "Prog: %s\n", (*config)->prog); while ((*config)->prog && !halt && (*config)->prog != 1){ - steps++; - DEBUGMSG(1, "Step %d: %s\n", steps, (*config)->prog); - (*config)->prog = ZAM_term(ccnl, (*config), (*config)->fox_state->thunk_request, + steps++; + DEBUGMSG(1, "Step %d: %s\n", steps, (*config)->prog); + (*config)->prog = ZAM_term(ccnl, (*config), (*config)->fox_state->thunk_request, &(*config)->fox_state->num_of_required_thunks, &halt, dummybuf, &restart); } if(halt < 0){ //HALT < 0 means pause computation