int get_conf_data (lua_State *L) { lua_newtable(L); int i = 1; for (auto it = confirmations.begin(); it != confirmations.end(); ++it) { Lua::Push(L, i++); lua_newtable(L); table_set(L, "id", it->first); table_set(L, "enabled", it->second->is_enabled()); lua_settable(L, -3); } return 1; }
obj * create_str(char * str, int len){ obj* o = init_obj(); o->type = 's'; o->hash = str_hash(str, len); String * s = malloc(sizeof(String) + len); MEM_ERROR_CHECK(s) s->len = len; strncpy(s->string, str, len); table_set(o->dict, m_add, str_add); table_set(o->dict, m_iadd, str_add); o->data = s; return o; }
int get_ids (lua_State *L) { lua_newtable(L); for (auto it = confirmations.begin(); it != confirmations.end(); ++it) table_set(L, it->first, true); return 1; }
static obj * create_str_concat(String * str1, String * str2){ obj* o = init_obj(); o->type = 's'; int new_len = str1->len + str2->len; String * s = malloc(sizeof(String) + new_len); MEM_ERROR_CHECK(s) s->len = new_len; strncpy(s->string, str1->string, str1->len); strncat(s->string, str2->string, str2->len); table_set(o->dict, m_add, str_add); table_set(o->dict, m_iadd, str_add); o->hash = str_hash(s->string, new_len); o->data = s; return o; }
static value make_table(cstlist csts, fncode fn) { struct table *t = alloc_table(DEF_TABLE_SIZE); GCPRO1(t); for (; csts; csts = csts->next) table_set(t, csts->cst->u.constpair->cst1->u.string, make_constant(csts->cst->u.constpair->cst2, FALSE, fn), NULL); table_foreach(t, protect_symbol); SET_READONLY(t); GCPOP(1); return t; }
static void scan_table(fd_set *t, table f) { u64 b = (void *)t; unsigned int i; for (i = 0 ; i <(FDSIZE/64); i++) { descriptor d; while ((d = ffsll(b[i]))) { d = (d-1) + (64*i); FD_CLR(d, t); thunk handler =(thunk)table_find(f, (void *)(unsigned long)d); table_set(f, (void *)(unsigned long)d, 0); apply(handler); } } }
/** * Resize the hash table. This will use round the desired size up to the next * power of two. Existing nodes will be redistributed across the new array. */ static table_error_t _table_nodes_resize(table_t * const table, const int32_t additional) { table_node_t * const old_nodes = table->nodes; const int32_t old_size = 1 << table->nodes_size_log; int32_t new_size = _table_nodes_count(table) + additional; int32_t i; // Allocate a new node array for the table if (new_size == 0) { table->nodes_size_log = 0; table->nodes = _dummy_node_ptr; } else { int32_t new_size_log = _ceil_log2(new_size); if (new_size_log > MAX_SIZE_BITS) { return TABLE_ERROR_OVERFLOW; } new_size = 1 << new_size_log; table->nodes_size_log = new_size_log; table->nodes = _table_nodes_alloc(new_size); if (table->nodes == NULL) { return TABLE_ERROR_MEMORY; } } table->inactive_node = &table->nodes[new_size]; // Copy the old nodes into the new table if (old_nodes != NULL && old_nodes != _dummy_node_ptr) { for (i = old_size - 1; i >= 0; --i) { table_node_t *old = &old_nodes[i]; if (old->active) { table_set(table, old->key, old->value); } } _table_nodes_free(old_nodes); } return TABLE_ERROR_NONE; }
obj * create_num(int num){ obj * o = init_obj(); o->type = 'n'; o->integer = num; o->hash = (int)num; table_set(o->dict, m_add, num_add); table_set(o->dict, m_sub, num_sub); table_set(o->dict, m_mul, num_mul); table_set(o->dict, m_div, num_div); table_set(o->dict, m_mod, num_mod); table_set(o->dict, m_pow, num_pow); table_set(o->dict, m_iadd, num_add); table_set(o->dict, m_isub, num_sub); table_set(o->dict, m_imul, num_mul); table_set(o->dict, m_idiv, num_div); table_set(o->dict, m_imod, num_mod); table_set(o->dict, m_ipow, num_pow); table_set(o->dict, m_eq, num_eq); table_set(o->dict, m_neq, num_neq); table_set(o->dict, m_gt, num_gt); table_set(o->dict, m_lt, num_lt); table_set(o->dict, m_gte, num_gte); table_set(o->dict, m_lte, num_lte); table_set(o->dict, m_neg, num_neg); table_set(o->dict, m_pos, num_pos); return o; }
static void str_obj_add_table(obj * o){ table_set(o->dict, m_add, str_add); table_set(o->dict, m_iadd, str_add); }
void register_read_handler(descriptor d, thunk t) { table_set(read_handlers, (void *)(unsigned long)d, t); }
PHPAPI void _php3_Header(char *strHeader) { char *r; #if APACHE char *rr = NULL; char *temp = NULL; long myuid = 0L; char temp2[32]; #endif TLS_VARS; for(r=strHeader;*r;r++) {} for(--r;r>=strHeader;--r) if(isspace(*r)) *r='\0'; else break; if (GLOBAL(php3_HeaderPrinted) == 1) { php3_error(E_WARNING, "Cannot add more header information - the header was already sent " "(header information may be added only before any output is generated from the script - " "check for text or whitespace outside PHP tags, or calls to functions that output text)"); return; /* too late, already sent */ } #if APACHE /* * Not entirely sure this is the right way to support the header * command in the Apache module. Comments? */ r = strchr(strHeader, ':'); if (r) { *r = '\0'; if (!strcasecmp(strHeader, "Content-type")) { if (*(r + 1) == ' ') GLOBAL(php3_rqst)->content_type = pstrdup(GLOBAL(php3_rqst)->pool,r + 2); else GLOBAL(php3_rqst)->content_type = pstrdup(GLOBAL(php3_rqst)->pool,r + 1); GLOBAL(cont_type) = (char *)GLOBAL(php3_rqst)->content_type; } else { if (*(r + 1) == ' ') rr = r + 2; else rr = r + 1; if (php3_ini.safe_mode && (!strcasecmp(strHeader, "WWW-authenticate"))) { myuid = _php3_getuid(); sprintf(temp2, "realm=\"%ld ", myuid); /* SAFE */ temp = _php3_regreplace("realm=\"", temp2, rr, 1, 0); if (!strcmp(temp, rr)) { sprintf(temp2, "realm=%ld", myuid); /* SAFE */ temp = _php3_regreplace("realm=", temp2, rr, 1, 0); if (!strcmp(temp, rr)) { sprintf(temp2, " realm=%ld", myuid); /* SAFE */ temp = _php3_regreplace("$", temp2, rr, 0, 0); } } table_set(GLOBAL(php3_rqst)->headers_out, strHeader, temp); } else table_set(GLOBAL(php3_rqst)->headers_out, strHeader, rr); } if (!strcasecmp(strHeader, "location")) { GLOBAL(php3_rqst)->status = REDIRECT; } *r = ':'; GLOBAL(php3_HeaderPrinted) = 2; } if (!strncasecmp(strHeader, "http/", 5)) { if (strlen(strHeader) > 9) { GLOBAL(php3_rqst)->status = atoi(&((strHeader)[9])); } /* Use a pstrdup here to get the memory straight from Apache's per-request pool to * avoid having our own memory manager complain about this memory not being freed * because it really shouldn't be freed until the end of the request and it isn't * easy for us to figure out when we allocated it vs. when something else might have. */ GLOBAL(php3_rqst)->status_line = pstrdup(GLOBAL(php3_rqst)->pool,&((strHeader)[9])); } #else r = strchr(strHeader, ':'); if (r) { *r = '\0'; if (!strcasecmp(strHeader, "Content-type")) { if (GLOBAL(cont_type)) efree(GLOBAL(cont_type)); GLOBAL(cont_type) = estrdup(r + 1); #if 0 /*WIN32|WINNT / *M$ does us again*/ if (!strcmp(GLOBAL(cont_type)," text/html")){ *r=':'; PUTS(arg1->value.str.val); PUTS("\015\012"); } #endif } else { *r = ':'; #if USE_SAPI { char *tempstr=emalloc(strlen(strHeader)+2); sprintf(tempstr,"%s\015\012",tempstr); GLOBAL(sapi_rqst)->header(GLOBAL(sapi_rqst)->scid,tempstr); efree(tempstr); } #else /* CGI BINARY or FHTTPD */ #if FHTTPD php3_fhttpd_puts_header(strHeader); php3_fhttpd_puts_header("\r\n"); #else PUTS(strHeader); PUTS("\015\012"); #endif #endif/* end if SAPI */ } } else { #if USE_SAPI { char *tempstr=emalloc(strlen(strHeader)+2); sprintf(tempstr,"%s\015\012",tempstr); GLOBAL(sapi_rqst)->header(GLOBAL(sapi_rqst)->scid,tempstr); efree(tempstr); } #else /* CGI BINARY or FHTTPD */ #if FHTTPD php3_fhttpd_puts_header(strHeader); php3_fhttpd_puts_header("\r\n"); #else PUTS(strHeader); PUTS("\015\012"); #endif #endif /* endif SAPI */ } #endif }
int cp_stage_1(cp_stage1* data, ruint_t* process_num) { int error = 0; *process_num = 0; proc_t* cp = get_current_process(); temp_proc_t* tp = malloc(sizeof(temp_proc_t)); if (tp == NULL) { goto handle_mem_error; } proc_t* process = malloc(sizeof(proc_t)); if (process == NULL) { goto handle_mem_error; } memset(process, 0, sizeof(proc_t)); tp->cstate = CP1; tp->process = process; process->__ob_lock = 0; process->process_list.data = process; if (data->privilege && cp->pprocess) process->pprocess = true; else process->pprocess = false; process->fds = create_array(); if (process->fds == NULL) { goto handle_mem_error; } process->threads = create_array(); if (process->fds == NULL) { destroy_array(process->fds); goto handle_mem_error; } process->mem_maps = NULL; process->proc_random = rg_create_random_generator(get_unix_time()); process->parent = NULL; if (data->parent) process->parent = cp; if (data->priority < 0) { process->priority = cp->priority; } else if (data->priority > 4) { error = EINVAL; goto handle_mem_error; } else process->priority = data->priority; process->futexes = create_uint64_table(); if (process->futexes == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->pq_input_buffer = create_queue_static(__message_getter); if (process->input_buffer == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->blocked_wait_messages = create_list_static(__message_getter); if (process->blocked_wait_messages == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } process->temp_processes = create_list_static(__process_get_function); if (process->blocked_wait_messages == NULL) { error = ENOMEM_INTERNAL; goto handle_mem_error; } proc_spinlock_lock(&__proclist_lock); process->proc_id = ++process_id_num; proc_spinlock_unlock(&__proclist_lock); proc_spinlock_lock(&__proclist_lock2); if (table_set(temp_processes, (void*)process->proc_id, tp)) { proc_spinlock_unlock(&__proclist_lock2); error = ENOMEM_INTERNAL; goto handle_mem_error; } list_push_right(cp->temp_processes, process); proc_spinlock_unlock(&__proclist_lock2); return 0; handle_mem_error: if (tp != NULL) free(tp); if (process != NULL) { if (process->fds != NULL) destroy_array(process->fds); if (process->threads != NULL) destroy_array(process->threads); if (process->futexes != NULL) destroy_table(process->futexes); if (process->input_buffer != NULL) free_queue(process->input_buffer); if (process->pq_input_buffer != NULL) free_queue(process->pq_input_buffer); if (process->blocked_wait_messages != NULL) free_list(process->blocked_wait_messages); if (process->temp_processes != NULL) free_list(process->temp_processes); free(process); } return error; }