void f_assemble_class() { array_t *arr = copy_array( sp->u.arr ); pop_stack(); push_refed_array(arr); sp->type = T_CLASS; }
void handle_getdir(struct request *req, int val){ aiob *aio = req->aio; close(aio->aio_fildes); val = aio_return(aio); array_t *ret = allocate_empty_array(val); int i; if(val > -1) { struct linux_dirent *de = (struct linux_dirent *)aio->aio_buf; for(i=0; ((char *)de) - (char *)(aio->aio_buf) < val; i++) { svalue_t *vp = &(ret->item[i]); vp->type = T_STRING; vp->subtype = STRING_MALLOC; //printf("%s ", de->d_name); vp->u.string = string_copy(de->d_name, "encode_stat"); de = (struct linux_dirent *)(((char *)de) + de->d_reclen); } } ret = RESIZE_ARRAY(ret, i); ret->size = i; push_refed_array(ret); set_eval(max_cost); safe_call_efun_callback(req->fun, 1); }
void handle_getdir(struct request *req){ int val = req->ret; if(val>MAX_ARRAY_SIZE) val = MAX_ARRAY_SIZE; array_t *ret = allocate_empty_array(val); int i=0; if(val > 0) { struct linux_dirent *de = (struct linux_dirent *)req->buf; for(i=0; i<MAX_ARRAY_SIZE && ((char *)de) - (char *)(req->buf) < val; i++) { svalue_t *vp = &(ret->item[i]); vp->type = T_STRING; vp->subtype = STRING_MALLOC; vp->u.string = string_copy(de->d_name, "encode_stat"); de = (struct linux_dirent *)(((char *)de) + de->d_reclen); } } ret = resize_array(ret, i); ret->size = i; push_refed_array(ret); FREE((void *)req->buf); set_eval(max_cost); safe_call_efun_callback(req->fun, 1); }
void c_foreach P3(int, flags, int, idx1, int, idx2) { IF_DEBUG(stack_in_use_as_temporary++); if (flags & 4) { CHECK_TYPES(sp, T_MAPPING, 2, F_FOREACH); push_refed_array(mapping_indices(sp->u.map)); (++sp)->type = T_NUMBER; sp->u.lvalue = (sp-1)->u.arr->item; sp->subtype = (sp-1)->u.arr->size; (++sp)->type = T_LVALUE; if (flags & 2) sp->u.lvalue = ¤t_object->variables[idx1 + variable_index_offset]; else sp->u.lvalue = fp + idx1; } else if (sp->type == T_STRING) { (++sp)->type = T_NUMBER; sp->u.lvalue_byte = (unsigned char *)((sp-1)->u.string); sp->subtype = SVALUE_STRLEN(sp - 1); } else { CHECK_TYPES(sp, T_ARRAY, 2, F_FOREACH); (++sp)->type = T_NUMBER; sp->u.lvalue = (sp-1)->u.arr->item; sp->subtype = (sp-1)->u.arr->size; } (++sp)->type = T_LVALUE; if (flags & 1) sp->u.lvalue = ¤t_object->variables[idx2 + variable_index_offset]; else sp->u.lvalue = fp + idx2; }
void f_pcre_extract(void) { pcre_t *run; array_t *ret; run = CALLOCATE(1, pcre_t, TAG_TEMPORARY, "f_pcre_extract : run"); assign_svalue_no_free(&run->pattern, sp); run->subject = (sp - 1)->u.string; run->s_length = SVALUE_STRLEN(sp - 1); run->ovector = NULL; run->ovecsize = 0; if(pcre_magic(run) < 0) { error("PCRE compilation failed at offset %d: %s\n", run->erroffset, run->error); pop_2_elems(); pcre_free_memory(run); return; } /* Pop the 2 arguments from the stack */ if (run->rc < 0) /* No match. could do handling of matching errors if wanted */ { pop_2_elems(); pcre_free_memory(run); push_refed_array(&the_null_array); return; } else if (run->rc > (run->ovecsize/3 - 1)) { pop_2_elems(); pcre_free_memory(run); error("Too many substrings.\n"); return; } ret = pcre_get_substrings(run); pop_2_elems(); push_refed_array(ret); pcre_free_memory(run); return; }
void c_foreach(int flags, int idx1, int idx2) { IF_DEBUG(stack_in_use_as_temporary++); if (flags & FOREACH_MAPPING) { CHECK_TYPES(sp, T_MAPPING, 2, F_FOREACH); push_refed_array(mapping_indices(sp->u.map)); STACK_INC; sp->type = T_NUMBER; sp->u.lvalue = (sp-1)->u.arr->item; sp->subtype = (sp-1)->u.arr->size; STACK_INC; sp->type = T_LVALUE; if (flags & FOREACH_LEFT_GLOBAL) { sp->u.lvalue = ¤t_object->variables[idx1 + variable_index_offset]; } else { sp->u.lvalue = fp + idx1; } } else if (sp->type == T_STRING) { STACK_INC; sp->type = T_NUMBER; sp->u.lvalue_byte = (unsigned char *)((sp-1)->u.string); sp->subtype = SVALUE_STRLEN(sp - 1); } else { CHECK_TYPES(sp, T_ARRAY, 2, F_FOREACH); STACK_INC; sp->type = T_NUMBER; sp->u.lvalue = (sp-1)->u.arr->item; sp->subtype = (sp-1)->u.arr->size; } if (flags & FOREACH_RIGHT_GLOBAL) { STACK_INC; sp->type = T_LVALUE; sp->u.lvalue = ¤t_object->variables[idx2 + variable_index_offset]; } else if (flags & FOREACH_REF) { ref_t *ref = make_ref(); svalue_t *loc = fp + idx2; /* foreach guarantees our target remains valid */ ref->lvalue = 0; ref->sv.type = T_NUMBER; STACK_INC; sp->type = T_REF; sp->u.ref = ref; DEBUG_CHECK(loc->type != T_NUMBER && loc->type != T_REF, "Somehow a reference in foreach acquired a value before coming into scope"); loc->type = T_REF; loc->u.ref = ref; ref->ref++; } else { STACK_INC; sp->type = T_LVALUE; sp->u.lvalue = fp + idx2; } }
void f_disassemble_class() { array_t *arr; if( sp->type != T_CLASS ) error( "Argument to disassemble_class() not a class.\n" ); arr = copy_array( sp->u.arr ); pop_stack(); push_refed_array(arr); }
void f_shuffle() { svalue_t *sv = sp - st_num_arg + 1; if (sv->type == T_ARRAY && sv->u.arr) { shuffle(sv->u.arr); } else { push_refed_array(&the_null_array); } }
void f_id_matrix (void) { array_t *matrix; int i; matrix = allocate_empty_array(16); for (i = 0; i < 16; i++) { matrix->item[i].type = T_REAL; matrix->item[i].u.real = identity[i]; } push_refed_array(matrix); }
void f_named_livings() { int i; int nob; #ifdef F_SET_HIDE int apply_valid_hide, display_hidden = 0; #endif object_t *ob, **obtab; array_t *vec; nob = 0; #ifdef F_SET_HIDE apply_valid_hide = 1; #endif obtab = CALLOCATE(max_array_size, object_t *, TAG_TEMPORARY, "named_livings"); for (i = 0; i < CFG_LIVING_HASH_SIZE; i++) { for (ob = hashed_living[i]; ob; ob = ob->next_hashed_living) { if (!(ob->flags & O_ENABLE_COMMANDS)) continue; #ifdef F_SET_HIDE if (ob->flags & O_HIDDEN) { if (apply_valid_hide) { apply_valid_hide = 0; display_hidden = valid_hide(current_object); } if (!display_hidden) continue; } #endif if (nob == max_array_size) break; obtab[nob++] = ob; } } vec = allocate_empty_array(nob); while (--nob >= 0) { vec->item[nob].type = T_OBJECT; vec->item[nob].u.ob = obtab[nob]; add_ref(obtab[nob], "livings"); } FREE(obtab); push_refed_array(vec); }
/* valid_database * * Calls APPLY_VALID_DATABASE in the master object to provide some * security on which objects can tweak your database (we don't want * people doing "DELETE * FROM *" or equivalent for us) */ svalue_t *valid_database (const char * action, array_t * info) { svalue_t *ret; /* * Call valid_database(object ob, string action, mixed *info) * * Return: string - password for access * int - 1 for no password, accept, 0 deny */ push_object(current_object); push_constant_string(action); push_refed_array(info); ret = apply_master_ob(APPLY_VALID_DATABASE, 3); if (ret && (ret == (svalue_t *)-1 || (ret->type == T_STRING || (ret->type == T_NUMBER && ret->u.number)))) return ret; error("Database security violation attempted\n"); }
void f_destructed_objects (void) { int i; array_t *ret; object_t *ob; ret = allocate_empty_array(tot_dangling_object); ob = obj_list_dangling; for (i = 0; i < tot_dangling_object; i++) { ret->item[i].type = T_ARRAY; ret->item[i].u.arr = allocate_empty_array(2); ret->item[i].u.arr->item[0].type = T_STRING; ret->item[i].u.arr->item[0].subtype = STRING_SHARED; ret->item[i].u.arr->item[0].u.string = make_shared_string(ob->obname); ret->item[i].u.arr->item[1].type = T_NUMBER; ret->item[i].u.arr->item[1].u.number = ob->ref; ob = ob->next_all; } push_refed_array(ret); }
/* * check permission */ int check_valid_socket (const char * const what, int fd, object_t * owner, const char * const addr, int port) { array_t *info; svalue_t *mret; info = allocate_empty_array(4); info->item[0].type = T_NUMBER; info->item[0].u.number = fd; assign_socket_owner(&info->item[1], owner); info->item[2].type = T_STRING; info->item[2].subtype = STRING_SHARED; info->item[2].u.string = make_shared_string(addr); info->item[3].type = T_NUMBER; info->item[3].u.number = port; push_object(current_object); push_constant_string(what); push_refed_array(info); mret = apply_master_ob(APPLY_VALID_SOCKET, 3); return MASTER_APPROVED(mret); }
void f_socket_status (void) { array_t *info; int i; if (st_num_arg) { info = socket_status(sp->u.number); if (!info) { sp->u.number = 0; } else { sp->type = T_ARRAY; sp->u.arr = info; } } else { info = allocate_empty_array(max_lpc_socks); for (i = 0; i < max_lpc_socks; i++) { info->item[i].type = T_ARRAY; info->item[i].u.arr = socket_status(i); } push_refed_array(info); } }
void f_commands (void) { push_refed_array(commands(current_object)); }
//string pcre_replace_callback(string, string, function) void f_pcre_replace_callback(void) { int num_arg = st_num_arg, i; char *ret; pcre_t *run; svalue_t *arg; array_t *arr, *r; function_to_call_t ftc; arg = sp - num_arg + 1; run = CALLOCATE(1, pcre_t, TAG_TEMPORARY, "f_pcre_replace: run"); run->ovector = NULL; run->ovecsize = 0; run->subject = arg->u.string; assign_svalue_no_free(&run->pattern, (arg + 1)); run->s_length = SVALUE_STRLEN(arg); if(pcre_magic(run) < 0) { pcre_free_memory(run); error("PCRE compilation failed at offset %d: %s\n", run->erroffset, run->error); } if (run->rc < 0) /* No match. could do handling of matching errors if wanted */ { pop_n_elems(num_arg-1); pcre_free_memory(run); return; } if (run->rc > (run->ovecsize/3-1)) { pcre_free_memory(run); error("Too many substrings.\n"); } arr = pcre_get_substrings(run); if(arg[2].type == T_FUNCTION || arg[2].type == T_STRING) process_efun_callback(2, &ftc, F_PCRE_REPLACE_CALLBACK); else {// 0 pcre_free_memory(run); error("Illegal third argument (0) to pcre_replace_callback"); } r = allocate_array(run->rc - 1); //can't use the empty variant in case we error below push_refed_array(r); push_refed_array(arr); error_context_t econ; if (!save_context(&econ)){ pcre_free_memory(run); error("context stack full!\n"); } if (SETJMP(econ.context)) { restore_context(&econ); /* condition was restored to where it was when we came in */ pcre_free_memory(run); pop_context(&econ); error("error in callback!\n"); } for (i = 0; i < run->rc - 1; i++) { svalue_t *v; push_svalue(arr->item + i); push_number(i); v = call_efun_callback(&ftc, 2); /* Mimic behaviour of map(string, function) when function pointer returns null, ie return the input. */ if (v && v->type == T_STRING && v->u.string != NULL) assign_svalue_no_free(&r->item[i], v); else assign_svalue_no_free(&r->item[i], &arr->item[i]); } pop_context(&econ); ret = pcre_get_replace(run, r); pop_n_elems(num_arg+2); //refed arrays push_malloced_string(ret); pcre_free_memory(run); return; }
void f_livings (void) { push_refed_array(livings()); }