void polish_varnum_interpret(program *prog, player *user, polish_stack *pol_stack) { ////////////////////////// Testing static int first_pass = 0; if(first_pass == 0){ set_up_test("Polish Varnum Interpret Suite", "Test of polish_varnum_interpret()", test_polish_varnum_interpret); ++first_pass; } ////////////////////////// if(user -> constant_checker == on){ push_to_stack(pol_stack, user -> current_constant); } else if(user -> variable_checker == on){ check_variable(user); push_to_stack(pol_stack, user -> variable_values[ user -> current_variable ]); } }
void polish_varnum_interpret(program *prog, player *user, polish_stack *pol_stack) { if(user -> constant_checker == on){ push_to_stack(pol_stack, user -> current_constant); } else if(user -> variable_checker == on){ check_variable(user); push_to_stack(pol_stack, user -> variable_values[ user -> current_variable ]); } }
char* op_builtin_ifelse(struct ccnl_relay_s *ccnl, struct configuration_s *config, int *restart, int *halt, char *prog, char *pending, struct stack_s **stack) { struct stack_s *h; int i1=0; DEBUGMSG(DEBUG, "---to do: OP_IFELSE <%s>\n", prog+10); h = pop_or_resolve_from_result_stack(ccnl, config); if (!h) { *halt = -1; return ccnl_strdup(prog); } if (h->type != STACK_TYPE_INT) { DEBUGMSG(WARNING, "ifelse requires int as condition"); ccnl_nfn_freeStack(h); return NULL; } i1 = *(int *)h->content; if (i1) { struct stack_s *stack = pop_from_stack(&config->argument_stack); DEBUGMSG(DEBUG, "Execute if\n"); pop_from_stack(&config->argument_stack); push_to_stack(&config->argument_stack, stack->content, STACK_TYPE_CLOSURE); } else { DEBUGMSG(DEBUG, "Execute else\n"); pop_from_stack(&config->argument_stack); } return ccnl_strdup(pending); }
char* op_builtin_add(struct ccnl_relay_s *ccnl, struct configuration_s *config, int *restart, int *halt, char *prog, char *pending, struct stack_s **stack) { int i1=0, i2=0, *h; DEBUGMSG(DEBUG, "---to do: OP_ADD <%s> pending: %s\n", prog+7, pending); pop2int(); h = ccnl_malloc(sizeof(int)); *h = i1 + i2; push_to_stack(stack, h, STACK_TYPE_INT); return pending ? ccnl_strdup(pending) : NULL; }
char* op_builtin_find(struct ccnl_relay_s *ccnl, struct configuration_s *config, int *restart, int *halt, char *prog, char *pending, struct stack_s **stack) { int local_search = 0; struct stack_s *h; char *cp = NULL; struct ccnl_prefix_s *prefix; struct ccnl_content_s *c = NULL; if (*restart) { DEBUGMSG(DEBUG, "---to do: OP_FIND restart\n"); *restart = 0; local_search = 1; } else { DEBUGMSG(DEBUG, "---to do: OP_FIND <%s> <%s>\n", prog+7, pending); h = pop_from_stack(&config->result_stack); // if (h->type != STACK_TYPE_PREFIX) ... config->fox_state->num_of_params = 1; config->fox_state->params = ccnl_malloc(sizeof(struct ccnl_stack_s *)); config->fox_state->params[0] = h; config->fox_state->it_routable_param = 0; } prefix = config->fox_state->params[0]->content; //check if result is now available //loop by reentering (with local_search) after timeout of the interest... DEBUGMSG(DEBUG, "FIND: Checking if result was received\n"); c = ccnl_nfn_local_content_search(ccnl, config, prefix); if (!c) { struct ccnl_prefix_s *copy; struct ccnl_interest_s *interest; if (local_search) { DEBUGMSG(INFO, "FIND: no content\n"); return NULL; } //Result not in cache, search over the network // struct ccnl_interest_s *interest = mkInterestObject(ccnl, config, prefix); copy = ccnl_prefix_dup(prefix); interest = ccnl_nfn_query2interest(ccnl, ©, config); DEBUGMSG(DEBUG, "FIND: sending new interest from Face ID: %d\n", interest->from->faceid); if (interest) ccnl_interest_propagate(ccnl, interest); //wait for content, return current program to continue later *halt = -1; //set halt to -1 for async computations return ccnl_strdup(prog); } DEBUGMSG(INFO, "FIND: result was found ---> handle it (%s), prog=%s, pending=%s\n", ccnl_prefix_to_path(prefix), prog, pending); #ifdef USE_NACK /* if (!strncmp((char*)c->content, ":NACK", 5)) { DEBUGMSG(DEBUG, "NACK RECEIVED, going to next parameter\n"); ++config->fox_state->it_routable_param; return prog ? ccnl_strdup(prog) : NULL; } */ #endif prefix = ccnl_prefix_dup(prefix); push_to_stack(&config->result_stack, prefix, STACK_TYPE_PREFIX); if (pending) { DEBUGMSG(DEBUG, "Pending: %s\n", pending); cp = ccnl_strdup(pending); } return cp; }
char* op_builtin_nstrans(struct ccnl_relay_s *ccnl, struct configuration_s *config, int *restart, int *halt, char *prog, char *pending, struct stack_s **stack) { char *cp = NULL; struct stack_s *s1, *s2; DEBUGMSG(DEBUG, "---to do: OP_NSTRANS\n"); s1 = pop_or_resolve_from_result_stack(ccnl, config); if (!s1) { *halt = -1; return prog; } s2 = pop_or_resolve_from_result_stack(ccnl, config); if (!s2) { ccnl_nfn_freeStack(s1); *halt = -1; return prog; } if (s2->type == STACK_TYPE_CONST && s1->type == STACK_TYPE_PREFIX) { struct ccnl_prefix_s *p = (struct ccnl_prefix_s*) s1->content; struct const_s *con = (struct const_s *) s2->content; int suite = -1; DEBUGMSG(DEBUG, " original packet format: %s\n", con->str); if (!strcmp(con->str, "ccnb")) suite = CCNL_SUITE_CCNB; else if (!strcmp(con->str, "ccnx2014")) suite = CCNL_SUITE_CCNTLV; else if (!strcmp(con->str, "ndn2013")) suite = CCNL_SUITE_NDNTLV; if (suite < 0) goto out; DEBUGMSG(DEBUG, " >> changing PREFIX suite from %d to %d\n", p->suite, suite); p->nfnflags = 0; p->suite = suite; push_to_stack(stack, s1->content, STACK_TYPE_PREFIX); ccnl_free(s1); s1 = NULL; if (pending) { cp = ccnl_malloc(strlen(pending)+1); strcpy(cp, pending); } } else { out: *halt = -1; cp = prog; } if (s1) ccnl_nfn_freeStack(s1); ccnl_nfn_freeStack(s2); return cp; }
void WrapperCreator::create_function_wrapper(Class* _class, Function* function) { if(function->type == Function::DESTRUCTOR) assert(false); std::string ns_prefix; if(selected_namespace != "") ns_prefix = selected_namespace + "::"; if(function->type == Function::CONSTRUCTOR) function->name = "constructor"; out << "static int "; if(_class != 0) { out << _class->name << "_"; } out << function->name << "_wrapper(HSQUIRRELVM vm)\n" << "{\n"; // avoid warning... if(_class == 0 && function->parameters.empty() && function->return_type.is_void() && function->type != Function::CONSTRUCTOR) { out << ind << "(void) vm;\n"; } // retrieve pointer to class instance if(_class != 0 && function->type != Function::CONSTRUCTOR) { out << ind << ns_prefix << _class->name << "* _this;\n"; out << ind << "if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {\n"; out << ind << ind << "sq_throwerror(vm, _SC(\"'" << function->name << "' called without instance\"));\n"; out << ind << ind << "return SQ_ERROR;\n"; out << ind << "}\n"; } // custom function? if(function->custom) { if(function->type != Function::FUNCTION) throw std::runtime_error( "custom not allow constructor+destructor yet"); if(function->return_type.atomic_type != &BasicType::INT) throw std::runtime_error("custom function has to return int"); if(function->parameters.size() != 1) throw std::runtime_error( "custom function must have 1 HSQUIRRELVM parameter"); out << ind << "return "; if(_class != 0) out << "_this->"; else out << ns_prefix; out << function->name << "(vm);\n"; out << "}\n"; out << "\n"; return; } // declare and retrieve arguments int i = 0; int arg_offset = 2; for(std::vector<Parameter>::iterator p = function->parameters.begin(); p != function->parameters.end(); ++p) { if(i == 0 && p->type.atomic_type == HSQUIRRELVMType::instance()) { out << ind << "HSQUIRRELVM arg0 = vm;\n"; arg_offset--; } else { char argname[64]; snprintf(argname, sizeof(argname), "arg%d", i); prepare_argument(p->type, i + arg_offset, argname); } ++i; } // call function out << ind << "\n"; out << ind << "try {\n"; out << ind << ind; if(!function->return_type.is_void()) { function->return_type.write_c_type(out); out << " return_value = "; } if(_class != 0) { if(function->type == Function::CONSTRUCTOR) { out << ns_prefix << _class->name << "* _this = new " << ns_prefix; } else { out << "_this->"; } } else { out << ns_prefix; } if(function->type == Function::CONSTRUCTOR) { out << _class->name << "("; } else { out << function->name << "("; } for(size_t i = 0; i < function->parameters.size(); ++i) { if(i != 0) out << ", "; out << "arg" << i; } out << ");\n"; if(function->type == Function::CONSTRUCTOR) { out << ind << "if(SQ_FAILED(sq_setinstanceup(vm, 1, _this))) {\n"; out << ind << ind << "sq_throwerror(vm, _SC(\"Couldn't setup instance of '" << _class->name << "' class\"));\n"; out << ind << ind << "return SQ_ERROR;\n"; out << ind << "}\n"; out << ind << "sq_setreleasehook(vm, 1, " << _class->name << "_release_hook);\n"; } out << ind << "\n"; // push return value back on stack and return if(function->suspend) { if(!function->return_type.is_void()) { std::stringstream msg; msg << "Function '" << function->name << "' declared as suspend" << " but has a return value."; throw std::runtime_error(msg.str()); } out << ind << ind << "return sq_suspendvm(vm);\n"; } else if(function->return_type.is_void()) { out << ind << ind << "return 0;\n"; } else { push_to_stack(function->return_type, "return_value"); out << ind << ind << "return 1;\n"; } out << ind << "\n"; out << ind << "} catch(std::exception& e) {\n"; out << ind << ind << "sq_throwerror(vm, e.what());\n"; out << ind << ind << "return SQ_ERROR;\n"; out << ind << "} catch(...) {\n"; out << ind << ind << "sq_throwerror(vm, _SC(\"Unexpected exception while executing function '" << function->name << "'\"));\n"; out << ind << ind << "return SQ_ERROR;\n"; out << ind << "}\n"; out << ind << "\n"; out << "}\n"; out << "\n"; }
// executes a ZAM instruction, returns the term to continue working on char* ZAM_term(struct ccnl_relay_s *ccnl, struct configuration_s *config, int *halt, char *dummybuf, int *restart) { // struct ccnl_lambdaTerm_s *t; // char *pending, *p, *cp, *prog = config->prog; // int len; char *prog = config->prog; struct builtin_s *bp; char *arg, *contd; int tok; //pop closure if (!prog || strlen(prog) == 0) { if (config->result_stack) { prog = ccnl_malloc(strlen((char*)config->result_stack->content)+1); strcpy(prog, config->result_stack->content); return prog; } DEBUGMSG(DEBUG, "no result returned\n"); return NULL; } tok = ZAM_nextToken(prog, &arg, &contd); // TODO: count opening/closing parentheses when hunting for ';' ? /* pending = strchr(prog, ';'); p = strchr(prog, '('); */ switch (tok) { case ZAM_ACCESS: { struct closure_s *closure = search_in_environment(config->env, arg); DEBUGMSG(DEBUG, "---to do: access <%s>\n", arg); if (!closure) { // TODO: is the following needed? Above search should have // visited global_dict, already! closure = search_in_environment(config->global_dict, arg); if (!closure) { DEBUGMSG(WARNING, "?? could not lookup var %s\n", arg); ccnl_free(arg); return NULL; } } ccnl_free(arg); closure = new_closure(ccnl_strdup(closure->term), closure->env); push_to_stack(&config->argument_stack, closure, STACK_TYPE_CLOSURE); return ccnl_strdup(contd); } case ZAM_APPLY: { struct stack_s *fct = pop_from_stack(&config->argument_stack); struct stack_s *par = pop_from_stack(&config->argument_stack); struct closure_s *fclosure, *aclosure; char *code; DEBUGMSG(DEBUG, "---to do: apply\n"); if (!fct || !par) return NULL; fclosure = (struct closure_s *) fct->content; aclosure = (struct closure_s *) par->content; if (!fclosure || !aclosure) return NULL; ccnl_free(fct); ccnl_free(par); code = aclosure->term; if (config->env) ccnl_nfn_releaseEnvironment(&config->env); config->env = aclosure->env; ccnl_free(aclosure); push_to_stack(&config->argument_stack, fclosure, STACK_TYPE_CLOSURE); if (contd) sprintf(dummybuf, "%s;%s", code, contd); else strcat(dummybuf, code); ccnl_free(code); return ccnl_strdup(dummybuf); } case ZAM_CALL: { struct stack_s *h = pop_or_resolve_from_result_stack(ccnl, config); int i, offset, num_params = *(int *)h->content; char name[5]; DEBUGMSG(DEBUG, "---to do: CALL <%s>\n", arg); ccnl_free(h->content); ccnl_free(h); sprintf(dummybuf, "CLOSURE(FOX);RESOLVENAME(@op("); // ... @x(@y y x 2 op)));TAILAPPLY"; offset = strlen(dummybuf); for (i = 0; i < num_params; ++i) { sprintf(name, "x%d", i); offset += sprintf(dummybuf+offset, "@%s(", name); } for (i = num_params - 1; i >= 0; --i) { sprintf(name, "x%d", i); offset += sprintf(dummybuf+offset, " %s", name); } offset += sprintf(dummybuf + offset, " %d", num_params); offset += sprintf(dummybuf+offset, " op"); for (i = 0; i < num_params+2; ++i) offset += sprintf(dummybuf + offset, ")"); if (contd) sprintf(dummybuf + offset, ";%s", contd); return ccnl_strdup(dummybuf); } case ZAM_CLOSURE: { struct closure_s *closure; DEBUGMSG(DEBUG, "---to do: closure <%s> (contd=%s)\n", arg, contd); if (!config->argument_stack && !strncmp(arg, "RESOLVENAME(", 12)) { char v[500], *c; int len; c = strchr(arg+12, ')'); if (!c) goto normal; len = c - (arg+12); memcpy(v, arg+12, len); v[len] = '\0'; closure = search_in_environment(config->env, v); if (!closure) goto normal; if (!strcmp(closure->term, arg)) { DEBUGMSG(WARNING, "** detected tail recursion case %s/%s\n", closure->term, arg); } else goto normal; } else { normal: closure = new_closure(arg, config->env); //configuration->env = NULL;//FIXME new environment? push_to_stack(&config->argument_stack, closure, STACK_TYPE_CLOSURE); arg = NULL; } if (contd) { ccnl_free(arg); return ccnl_strdup(contd); } DEBUGMSG(ERROR, "** not implemented, see line %d\n", __LINE__); return arg; } case ZAM_FOX: return ZAM_fox(ccnl, config, restart, halt, prog, arg, contd); case ZAM_GRAB: { struct stack_s *stack = pop_from_stack(&config->argument_stack); DEBUGMSG(DEBUG, "---to do: grab <%s>\n", arg); add_to_environment(&config->env, arg, stack->content); ccnl_free(stack); return ccnl_strdup(contd); } case ZAM_HALT: ccnl_nfn_freeStack(config->argument_stack); //ccnl_nfn_freeStack(config->result_stack); config->argument_stack = /*config->result_stack =*/ NULL; *halt = 1; return ccnl_strdup(contd); case ZAM_RESOLVENAME: return ZAM_resolvename(config, dummybuf, arg, contd); case ZAM_TAILAPPLY: { struct stack_s *stack = pop_from_stack(&config->argument_stack); struct closure_s *closure = (struct closure_s *) stack->content; char *code = closure->term; DEBUGMSG(DEBUG, "---to do: tailapply\n"); ccnl_free(stack); if (contd) //build new term sprintf(dummybuf, "%s;%s", code, contd); else strcpy(dummybuf, code); if (config->env) ccnl_nfn_releaseEnvironment(&config->env); config->env = closure->env; //set environment from closure ccnl_free(code); ccnl_free(closure); return ccnl_strdup(dummybuf); } case ZAM_UNKNOWN: break; default: DEBUGMSG(DEBUG, "builtin: %s (%s/%s)\n", bifs[-tok - 1].name, prog, contd); return bifs[-tok - 1].fct(ccnl, config, restart, halt, prog, contd, &config->result_stack); } ccnl_free(arg); // iterate through all extension operations for (bp = op_extensions; bp; bp = bp->next) if (!strncmp(prog, bp->name, strlen(bp->name))) return (bp->fct)(ccnl, config, restart, halt, prog, contd, &config->result_stack); DEBUGMSG(INFO, "unknown (built-in) command <%s>\n", prog); return NULL; }
char* ZAM_resolvename(struct configuration_s *config, char *dummybuf, char *arg, char *contd) { struct ccnl_lambdaTerm_s *t; char res[1000], *cp = arg; int len; DEBUGMSG(DEBUG, "---to do: resolveNAME <%s>\n", arg); //function definition if (!strncmp(cp, "let", 3)) { int i, end = 0, cp2len, namelength, lambdalen; char *h, *cp2, *name, *lambda_expr, *resolveterm; DEBUGMSG(DEBUG, " fct definition: %s\n", cp); strcpy(res, cp+3); for (i = 0; i < strlen(res); ++i) { if (!strncmp(res+i, "endlet", 6)) { end = i; break; } } cp2len = strlen(res+end) + strlen("RESOLVENAME()"); h = strchr(cp, '='); namelength = h - cp; lambda_expr = ccnl_malloc(strlen(h)); name = ccnl_malloc(namelength); cp2 = ccnl_malloc(cp2len); memset(cp2, 0, cp2len); memset(name, 0, namelength); memset(lambda_expr, 0, strlen(h)); sprintf(cp2, "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(cp2)+11-6; memcpy(lambda_expr, h+1, lambdalen); //copy lambda expression without = trim(lambda_expr); resolveterm = ccnl_malloc(strlen("RESOLVENAME()")+strlen(lambda_expr)); sprintf(resolveterm, "RESOLVENAME(%s)", lambda_expr); add_to_environment(&config->env, name, new_closure(resolveterm, NULL)); ccnl_free(cp); return strdup(contd); } //check if term can be made available, if yes enter it as a var //try with searching in global env for an added term! t = ccnl_lambdaStrToTerm(0, &cp, NULL); ccnl_free(arg); if (term_is_var(t)) { char *end = 0; cp = t->v; if (isdigit(*cp)) { // is disgit... int *integer = ccnl_malloc(sizeof(int)); *integer = strtol(cp, &end, 0); if (end && *end) end = 0; if (end) push_to_stack(&config->result_stack, integer, STACK_TYPE_INT); else ccnl_free(integer); } else if (*cp == '\'') { // quoted name (constant) //determine size struct const_s *con = ccnl_nfn_krivine_str2const(cp); push_to_stack(&config->result_stack, con, STACK_TYPE_CONST); end = (char*)1; } else if (iscontentname(cp)) { // is content... struct ccnl_prefix_s *prefix; prefix = ccnl_URItoPrefix(cp, config->suite, NULL, NULL); push_to_stack(&config->result_stack, prefix, STACK_TYPE_PREFIX); end = (char*)1; } if (end) { if (contd) sprintf(res, "TAILAPPLY;%s", contd); else sprintf(res, "TAILAPPLY"); } else { if (contd) sprintf(res, "ACCESS(%s);TAILAPPLY;%s", t->v, contd); else sprintf(res, "ACCESS(%s);TAILAPPLY", t->v); } ccnl_lambdaFreeTerm(t); return ccnl_strdup(res); } if (term_is_lambda(t)) { char *var; var = t->v; ccnl_lambdaTermToStr(dummybuf, t->m, 0); if (contd) sprintf(res, "GRAB(%s);RESOLVENAME(%s);%s", var, dummybuf, contd); else sprintf(res, "GRAB(%s);RESOLVENAME(%s)", var, dummybuf); ccnl_lambdaFreeTerm(t); return ccnl_strdup(res); } if (term_is_app(t)) { ccnl_lambdaTermToStr(dummybuf, t->n, 0); len = sprintf(res, "CLOSURE(RESOLVENAME(%s));", dummybuf); ccnl_lambdaTermToStr(dummybuf, t->m, 0); len += sprintf(res+len, "RESOLVENAME(%s)", dummybuf); if (contd) len += sprintf(res+len, ";%s", contd); ccnl_lambdaFreeTerm(t); return ccnl_strdup(res); } return NULL; }
char* ZAM_fox(struct ccnl_relay_s *ccnl, struct configuration_s *config, int *restart, int *halt, char *prog, char *arg, char *contd) { int local_search = 0, i; int parameter_number = 0; struct ccnl_content_s *c = NULL; struct ccnl_prefix_s *pref; struct ccnl_interest_s *interest; DEBUGMSG(DEBUG, "---to do: FOX <%s>\n", arg); ccnl_free(arg); if (*restart) { *restart = 0; local_search = 1; goto recontinue; } { struct stack_s *h; h = pop_or_resolve_from_result_stack(ccnl, config); assert(h); //TODO CHECK IF INT config->fox_state->num_of_params = *(int*)h->content; h->next = NULL; ccnl_nfn_freeStack(h); } DEBUGMSG(DEBUG, "NUM OF PARAMS: %d\n", config->fox_state->num_of_params); config->fox_state->params = ccnl_malloc(sizeof(struct ccnl_stack_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_from_stack(&config->result_stack); switch (config->fox_state->params[i]->type) { case STACK_TYPE_INT: DEBUGMSG(DEBUG, " info: Parameter %d %d\n", i, *(int *)config->fox_state->params[i]->content); break; case STACK_TYPE_PREFIX: DEBUGMSG(DEBUG, " info: Parameter %d %s\n", i, ccnl_prefix_to_path((struct ccnl_prefix_s*) config->fox_state->params[i]->content)); break; default: break; } } //as long as there is a routable parameter: try to find a result config->fox_state->it_routable_param = 0; //check if last result is now available recontinue: //loop by reentering after timeout of the interest... if (local_search) { DEBUGMSG(DEBUG, "Checking if result was received\n"); parameter_number = choose_parameter(config); pref = create_namecomps(ccnl, config, parameter_number, config->fox_state->params[parameter_number]->content); // search for a result c = ccnl_nfn_local_content_search(ccnl, config, pref); set_propagate_of_interests_to_1(ccnl, pref); free_prefix(pref); //TODO Check? //TODO remove interest here? if (c) { DEBUGMSG(DEBUG, "Result was found\n"); DEBUGMSG_CFWD(INFO, "data after result was found %.*s\n", c->pkt->contlen, c->pkt->content); goto handlecontent; } } //result was not delivered --> choose next parameter ++config->fox_state->it_routable_param; parameter_number = choose_parameter(config); if (parameter_number < 0) //no more parameter --> no result found, can try a local computation goto local_compute; // create new prefix with name components!!!! pref = create_namecomps(ccnl, config, parameter_number, config->fox_state->params[parameter_number]->content); c = ccnl_nfn_local_content_search(ccnl, config, pref); if (c) { free_prefix(pref); goto handlecontent; } // Result not in cache, search over the network // pref2 = ccnl_prefix_dup(pref); interest = ccnl_nfn_query2interest(ccnl, &pref, config); if (pref) free_prefix(pref); if (interest) { ccnl_interest_propagate(ccnl, interest); DEBUGMSG(DEBUG, " new interest's face is %d\n", interest->from->faceid); } // wait for content, return current program to continue later *halt = -1; //set halt to -1 for async computations return ccnl_strdup(prog); local_compute: if (config->local_done) return NULL; config->local_done = 1; pref = ccnl_nfnprefix_mkComputePrefix(config, config->suite); DEBUGMSG(DEBUG, "Prefix local computation: %s\n", ccnl_prefix_to_path(pref)); interest = ccnl_nfn_query2interest(ccnl, &pref, config); if (pref) free_prefix(pref); if (interest) ccnl_interest_propagate(ccnl, interest); handlecontent: //if result was found ---> handle it if (c) { #ifdef USE_NACK if (!strncmp((char*)c->pkt->content, ":NACK", 5)) { DEBUGMSG(DEBUG, "NACK RECEIVED, going to next parameter\n"); ++config->fox_state->it_routable_param; return prog ? ccnl_strdup(prog) : NULL; } #endif int isANumber = 1, i = 0; for(i = 0; i < c->pkt->contlen; ++i){ if(!isdigit(c->pkt->content[i])){ isANumber = 0; break; } } if (isANumber){ int *integer = ccnl_malloc(sizeof(int)); *integer = strtol((char*)c->pkt->content, 0, 0); push_to_stack(&config->result_stack, integer, STACK_TYPE_INT); } else { struct prefix_mapping_s *mapping; struct ccnl_prefix_s *name = create_prefix_for_content_on_result_stack(ccnl, config); push_to_stack(&config->result_stack, name, STACK_TYPE_PREFIX); mapping = ccnl_malloc(sizeof(struct prefix_mapping_s)); mapping->key = ccnl_prefix_dup(name); //TODO COPY mapping->value = ccnl_prefix_dup(c->pkt->pfx); DBL_LINKED_LIST_ADD(config->fox_state->prefix_mapping, mapping); DEBUGMSG(DEBUG, "Created a mapping %s - %s\n", ccnl_prefix_to_path(mapping->key), ccnl_prefix_to_path(mapping->value)); } } DEBUGMSG(DEBUG, " FOX continuation: %s\n", contd); return ccnl_strdup(contd); }