// called from root // To check up presence of data which have come from a network void as_xmlsock::advance(float delta_time) { assert(m_ns); if (m_ns->is_readable()) { gameswf::tu_string str; m_ns->read_line(&str, XML_MAXDATASIZE, XML_TIMEOUT); // If the connection has been gracefully closed, // the size of return value is zero if (str.size() == 0) { close(); as_value function; if (get_member("onClose", &function)) { as_environment env(get_player()); call_method(function, &env, as_value(), 0, env.get_top_index()); } } else { as_value function; if (get_member("onData", &function)) { as_environment env(get_player()); env.push(str); call_method(function, &env, as_value(), 1, env.get_top_index()); } } } }
int Msm::epoll_closefd_before(string action, int fd, string id) { // send response MsmRespMsg msg(id, action); msg.send_msg(fd); if (action == "login") return 0; if (get_member(id) == NULL || (get_member(id)->is_offline())) { MsmReqMsg msg(id, "close", "user not login"); msg.send_msg(fd); LOG(LOG_ERROR, "%s not log in.", id.c_str()); if (epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &ev) == -1) { LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", fd, strerror(errno)); return errno; } close(fd); LOG(LOG_INFO, "close sockfd: %d", fd); return -1; } return 0; }
as_object* as_object::find_target(const as_value& target) // Find the object referenced by the given target. { if (target.is_string() == false) { return target.to_object(); } const tu_string& path = target.to_tu_string(); if (path.length() == 0) { return this; } as_value val; as_object* tar = NULL; // absolute path ? if (*path.c_str() == '/') { return m_player->get_root_movie()->find_target(path.c_str() + 1); } const char* slash = strchr(path.c_str(), '/'); if (slash == NULL) { slash = strchr(path.c_str(), '.'); if (slash) { if (slash[1] == '.') { slash = NULL; } } } if (slash) { tu_string name(path.c_str(), int(slash - path.c_str())); get_member(name, &val); tar = val.to_object(); if (tar) { return tar->find_target(slash + 1); } } else { get_member(path, &val); tar = val.to_object(); } if (tar == NULL) { log_error("can't find target %s\n", path.c_str()); } return tar; }
tid_t idaapi merge_types(qvector<qstring> types_to_merge, qstring type_name) { tid_t struct_type_id = BADADDR; std::set<ea_t> offsets; if (types_to_merge.size() != 0) { struct_type_id = add_struc(BADADDR, type_name.c_str()); if (struct_type_id != 0 || struct_type_id != BADADDR) { struc_t * struc = get_struc(struct_type_id); if (struc != NULL) { qvector<qstring>::iterator types_iter; for (types_iter = types_to_merge.begin(); types_iter != types_to_merge.end(); types_iter++) { tid_t type_id = get_struc_id((*types_iter).c_str()); if (type_id != BADADDR) { struc_t * struc_type = get_struc(type_id); if (struc_type != NULL) { // enumerate members for (ea_t offset = get_struc_first_offset(struc_type); offset != BADADDR; offset = get_struc_next_offset(struc_type, offset)) { member_t * member_info = get_member(struc_type, offset); if (member_info != NULL) { if (offsets.count(member_info->soff) == 0) { qstring member_name = get_member_name2(member_info->id); asize_t member_size = get_member_size(member_info); if (member_name.find("vftbl_", 0) != -1) { tinfo_t tif; if (get_member_tinfo2(member_info, &tif)) { add_struc_member(struc, member_name.c_str(), member_info->soff, dwrdflag(), NULL, member_size); member_t * membr = get_member(struc, member_info->soff); if (membr != NULL) { set_member_tinfo2(struc, membr, 0, tif, SET_MEMTI_COMPATIBLE); } } } else { add_struc_member(struc, member_name.c_str(), member_info->soff, member_info->flag, NULL, member_size); } offsets.insert(member_info->soff); } } } } } } } } } return struct_type_id; }
tid_t idaapi merge_types(const qvector<qstring>& types_to_merge, const qstring& type_name) { tid_t struct_type_id = BADADDR; if (types_to_merge.empty()) return struct_type_id; std::set<ea_t> offsets; struct_type_id = add_struc(BADADDR, type_name.c_str()); if (struct_type_id == BADADDR) return struct_type_id; struc_t * struc = get_struc(struct_type_id); if (!struc) return struct_type_id; for (auto types_iter = types_to_merge.begin(), end = types_to_merge.end(); types_iter != end; ++types_iter) { struc_t * struc_type = get_struc(get_struc_id(types_iter->c_str())); if (!struc_type) continue; // enumerate members for ( ea_t offset = get_struc_first_offset(struc_type) ; offset != BADADDR ; offset = get_struc_next_offset(struc_type, offset)) { member_t * member_info = get_member(struc_type, offset); if (!member_info) continue; if (offsets.count(member_info->soff) == 0) { qstring member_name = get_member_name(member_info->id); asize_t member_size = get_member_size(member_info); if (member_name.find("vftbl_", 0) != -1) { tinfo_t tif; if (get_member_tinfo(&tif, member_info)) { add_struc_member(struc, member_name.c_str(), member_info->soff, dword_flag(), NULL, member_size); if (member_t * membr = get_member(struc, member_info->soff)) { set_member_tinfo(struc, membr, 0, tif, SET_MEMTI_COMPATIBLE); } } } else { add_struc_member(struc, member_name.c_str(), member_info->soff, member_info->flag, NULL, member_size); } offsets.insert(member_info->soff); } } } return struct_type_id; }
int Msm::epoll_closefd_after(string action, int fd, string id) { if (get_member(id) && get_member(id)->get_sockfd() != fd) { if (epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &ev) == -1) { LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", fd, strerror(errno)); return errno; } close(fd); LOG(LOG_INFO, "close sockfd: %d", fd); return -1; } return 0; }
bool idaapi check_subtype(const VTBL_info_t &vtbl_info, const qstring &subtype_name) { bool bResult = false; qstring search_str; search_str.sprnt("_%p", vtbl_info.ea_begin); tid_t type_id = get_struc_id(subtype_name.c_str()); if (type_id != BADADDR) { struc_t * struc_type = get_struc(type_id); if (struc_type != NULL) { // enumerate members for (ea_t offset = get_struc_first_offset(struc_type); offset != BADADDR; offset = get_struc_next_offset(struc_type, offset)) { member_t * member_info = get_member(struc_type, offset); if (member_info != NULL) { qstring member_name = get_member_name2(member_info->id); if (member_name.find(search_str, 0) != -1) { bResult = true; break; } } } } } return bResult; }
/* Parse call to builtin symbol __builtin_va_start, which is the result of * calling va_start(arg, s). Return type depends on second input argument. */ static struct block *parse__builtin_va_start(struct block *block) { const struct typetree *type; struct symbol *sym; struct token param; int is_invalid; consume('('); block = assignment_expression(block); consume(','); param = consume(IDENTIFIER); sym = sym_lookup(&ns_ident, param.strval); type = ¤t_func()->symbol->type; is_invalid = !sym || sym->depth != 1 || !is_function(type); is_invalid = is_invalid || !nmembers(type) || strcmp( get_member(type, nmembers(type) - 1)->name, param.strval); if (is_invalid) { error("Second parameter of va_start must be last function argument."); exit(1); } consume(')'); block->expr = eval__builtin_va_start(block, block->expr); return block; }
static Cute eval_for( Cute p, Cute env ) { Cute id = N_for_id(p); Cute iter = eval( N_for_iter(p), env ); Cute next = get_member( iter, H_id( "__next__" ), true ); Cute args = H_list(); H_list_append( args, iter ); Cute val = H_call_func( next, args, env ); eval( H_assign( id, val ), env ); while ( to_c_cond( val ) ) { eval( N_for_block(p), env ); if ( l_return ) return l_ret_val; val = H_call_func( next, args, env ); eval( H_assign( id, val ), env ); } return H_None; }
void as_netstream::advance(float delta_time) { stream_event ev; while(m_event.pop(&ev)) { // printf("pop status: %s %s\n", ev.level.c_str(), ev.code.c_str()); // keep this alive during execution! gc_ptr<as_object> this_ptr(this); as_value function; if (get_member("onStatus", &function)) { gc_ptr<as_object> infoObject = new as_object(get_player()); infoObject->set_member("level", s_netstream_event_level[ev.level].c_str()); infoObject->set_member("code", s_netstream_event_code[ev.code].c_str()); as_environment env(get_player()); env.push(infoObject.get_ptr()); call_method(function, &env, this, 1, env.get_top_index()); } if (ev.code == playStop || ev.code == playStreamNotFound) { get_root()->remove_listener(this); } } }
/** Handle incoming SR (Sender Report) packet */ static void handle_incoming_sr(struct rtcp_sess *sess, const struct rtcp_msg *msg) { struct rtp_member *mbr; uint32_t i; mbr = get_member(sess, msg->r.sr.ssrc); if (!mbr) { DEBUG_WARNING("0x%08x: could not add member\n", msg->r.sr.ssrc); return; } if (mbr->s) { /* Save time when SR was received */ mbr->s->sr_recv = tmr_jiffies(); /* Save NTP timestamp from SR */ mbr->s->last_sr.hi = msg->r.sr.ntp_sec; mbr->s->last_sr.lo = msg->r.sr.ntp_frac; mbr->s->rtp_ts = msg->r.sr.rtp_ts; mbr->s->psent = msg->r.sr.psent; mbr->s->osent = msg->r.sr.osent; } for (i=0; i<msg->hdr.count; i++) handle_rr_block(sess, mbr, &msg->r.sr.rrv[i]); }
bool sprite_instance::can_handle_mouse_event() // Return true if we have any mouse event handlers. { static const tu_stringi FN_NAMES[] = { "onKeyPress", "onRelease", "onDragOver", "onDragOut", "onPress", "onReleaseOutside", "onRollout", "onRollover", }; if (is_enabled()) { for (size_t i = 0; i < TU_ARRAYSIZE(FN_NAMES); i++) { as_value dummy; if (get_member(FN_NAMES[i], &dummy)) { return true; } } } return false; }
// 1.user not in meeting // 2.user in meeting and not is admin -->set offline // 3.user in meeting and is admin --> destroy meeting int Msm::logout(string id) { if (!have_member(id)) { LOG(LOG_ERROR, "%s not login.", id.c_str()); return -1; } Member *m = get_member(id); int fd = m->get_sockfd(); if (fd != -1) { if (epoll_ctl(epollfd, EPOLL_CTL_DEL, fd, &ev) == -1) { LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", fd, strerror(errno)); } close(fd); m->set_sockfd(-1); LOG(LOG_INFO, "close sockfd: %d", fd); } if (m->get_meeting() != NULL) { if (m->get_meeting()->get_admin() == id) { destroy_meeting(m->get_meeting()->get_id()); } else { m->set_offline(); } } return unregister_member(id); }
nn_fuzzy_set nn_fuzzy_set::crossover() { nn_fuzzy_set result; reset_position(); while (!end_of_set()) { if(get_membership() == 0.5) result.add_new(get_member(),get_membership()); next_member(); } return result; }
void as_array::pop(as_value* val) // Removes the last element from an array and returns the value of that element. { assert(val); as_value index(size() - 1); if (get_member(index.to_tu_stringi(), val)) { erase(index.to_tu_stringi()); } }
nn_fuzzy_set nn_fuzzy_set::strong_alpha_cut(double alpha) { nn_fuzzy_set result; reset_position(); while (!end_of_set()) { if(get_membership() > alpha) result.add_new(get_member(),get_membership()); next_member(); } return result; }
nn_fuzzy_set nn_fuzzy_set::support() { nn_fuzzy_set result; reset_position(); while (!end_of_set()) { if(get_membership() > 0) result.add_new(get_member(),get_membership()); next_member(); } return result; }
/* Extract a single optional/required or multiple repeated sub messages from native php types into the given protobuf message. Allocates memory for the created messages */ int message_proto (const ProtobufCMessage* message, const ProtobufCFieldDescriptor* field, zval** val) { if (Z_TYPE_PP(val) != IS_ARRAY) return 1; const void* member = get_member(message, field); unsigned int* quantifier = get_quantifier(message, field); ProtobufCMessageDescriptor* descriptor = (ProtobufCMessageDescriptor*)field->descriptor; if (field->label == PROTOBUF_C_LABEL_REQUIRED) { ProtobufCMessage* base = emalloc(descriptor->sizeof_message); protobuf_c_message_init(descriptor, base); php_message(base, val[0]); memcpy((void*)member, (void*)&base, sizeof(void*)); } else if (field->label == PROTOBUF_C_LABEL_REPEATED) { HashPosition pos; HashTable* hash_table = Z_ARRVAL_PP(val); size_t* num_elements = emalloc(sizeof(size_t)); num_elements[0] = (size_t)zend_hash_num_elements(hash_table); zval** data; char* key; int i, key_len, curr = 0; long index; void** values = emalloc(sizeof(void*) * *num_elements); zend_hash_internal_pointer_reset_ex(hash_table, &pos); for (;; zend_hash_move_forward_ex(hash_table, &pos)) { zend_hash_get_current_data_ex(hash_table, (void**)&data, &pos); i = zend_hash_get_current_key_ex(hash_table, &key, &key_len, &index, 0, &pos); if (i == HASH_KEY_NON_EXISTANT) { break; } void* curr_value = emalloc(descriptor->sizeof_message); protobuf_c_message_init(descriptor, curr_value); php_message((ProtobufCMessage*)curr_value, data[0]); values[curr] = curr_value; curr++; } memcpy((void*)member, (void*)&values, sizeof(void*)); memcpy((void*)quantifier, (void*)num_elements, sizeof(void*)); } return 0; }
/* Extract uint32_t values from the given zval** and write them into the given protobuf message pointer. handle optional/required/repeated */ int uint32_proto (const ProtobufCMessage* message, const ProtobufCFieldDescriptor* field, zval** val) { uint32_t* member = (uint32_t*)get_member(message, field); unsigned int* quantifier = get_quantifier(message, field); if (field->label == PROTOBUF_C_LABEL_REQUIRED || field->label == PROTOBUF_C_LABEL_OPTIONAL) { if (Z_TYPE_PP(val) == IS_LONG) *member = (uint32_t)Z_LVAL_PP(val); else if (Z_TYPE_PP(val) == IS_DOUBLE) *member = (uint32_t)Z_DVAL_PP(val); else return 1; if (field->label == PROTOBUF_C_LABEL_OPTIONAL) *quantifier = 1; } else if (field->label == PROTOBUF_C_LABEL_REPEATED) { if (Z_TYPE_PP(val) != IS_ARRAY) return 1; HashPosition pos; HashTable* hash_table = Z_ARRVAL_PP(val); size_t num_elements = (size_t)zend_hash_num_elements(hash_table); zval** data; char* key; int i, key_len, curr = 0; long index; uint32_t* values = emalloc(sizeof(uint32_t) * num_elements); zend_hash_internal_pointer_reset_ex(hash_table, &pos); for (;; zend_hash_move_forward_ex(hash_table, &pos)) { zend_hash_get_current_data_ex(hash_table, (void**)&data, &pos); i = zend_hash_get_current_key_ex(hash_table, &key, &key_len, &index, 0, &pos); if (i == HASH_KEY_NON_EXISTANT) break; if (Z_TYPE_PP(data) == IS_LONG) values[curr++] = (uint32_t)(Z_LVAL_PP(data)); else if (Z_TYPE_PP(data) == IS_DOUBLE) values[curr++] = (uint32_t)(Z_DVAL_PP(data)); } *quantifier = num_elements; memcpy((void*)member, (void*)&values, sizeof(void*)); } return 0; }
static Cute eval_op_ref( Cute p, Cute env ) { Cute obj_id = N_op_left(p); Cute obj; if ( H_frame_lookup( env, obj_id, &obj ) == H_False ) error( "not found object [%s]", H_id_to_str( obj_id ) ); Cute member_id = N_op_right(p); return get_member( obj, member_id, true ); }
/** Handle incoming RR (Receiver Report) packet */ static void handle_incoming_rr(struct rtcp_sess *sess, const struct rtcp_msg *msg) { struct rtp_member *mbr; uint32_t i; mbr = get_member(sess, msg->r.rr.ssrc); if (!mbr) return; for (i=0; i<msg->hdr.count; i++) handle_rr_block(sess, mbr, &msg->r.rr.rrv[i]); }
static void add_button_proc(struct menu_item *item, void *data) { struct item_data *item_data = data; uint32_t address = 0x80000000; enum watch_type type = WATCH_TYPE_U8; if (item_data->members.size > 0) { struct member_data *member_data = get_member(item_data, item_data->members.size - 1); struct menu_item *last_watch = menu_userwatch_watch(member_data->userwatch); address = menu_watch_get_address(last_watch); type = menu_watch_get_type(last_watch); } add_member(item_data, address, type, item_data->members.size, 1, 0, 0, 0); }
static int remove_member(struct item_data *data, int position) { if (position < 0 || position >= data->members.size) return 0; menu_navigate_top(data->imenu, MENU_NAVIGATE_DOWN); --data->add_button->y; #ifndef WIIVC --data->import_button->y; #endif for (int i = position + 1; i < data->members.size; ++i) { struct member_data *member_data = get_member(data, i); --member_data->index; --member_data->member->y; } struct member_data *member_data = get_member(data, position); struct menu_item *watch = menu_userwatch_watch(member_data->userwatch); menu_item_remove(watch); member_data->anchor_button->data = NULL; menu_item_remove(member_data->member); vector_erase(&data->members, position, 1); free(member_data); return 1; }
int _json_parse_compound_start(struct parse_state_t *ps, enum context_id_t p) { int err = -1; struct context_t *c = ps->context; const char *member = get_member(c); struct context_t *c_pushed; void *data = NULL; struct json_cb_t *cb = NULL; if (!c->vtbl) err = 0; else if (c->vtbl->new_obj_cb && p == context_obj) { err = (c->vtbl->new_obj_cb)(c->data, member, &data, &cb); } else if (c->vtbl->new_array_cb && p == context_array) { err = (c->vtbl->new_array_cb)(c->data, member, &data, &cb); } if (err) { wrong_type_compound(ps, p); } if (!err && cb) { c_pushed = _json_context_push(c, p, cb, data); } else { c_pushed = _json_context_push_null(c, p); } if (c_pushed) ps->context = c_pushed; else { // TODO: // -handle no mem } return err; }
void enum_members3(struc_t *st) { asize_t ofs = get_struc_first_offset(st); ssize_t m_idx; char buf[MAXSTR]; while ((m_idx = get_next_member_idx(st, ofs)) != BADADDR) { member_t *mem = get_member(st, ofs); get_member_name(mem->id, buf, sizeof(buf)); msg("name=%s idx=%a ; ofs=%a\n", buf, m_idx, ofs); ofs += mem->eoff; } }
void *cinv_structure_instance_getvalue(CInvContext *context, CInvStructure *structure, void *instance, const char *name) { int sz, offset, is_struct; char *ptr = instance; offset = get_member(context, structure, name, &sz, &is_struct); if (offset == -1) return NULL; ptr += offset; context_clear_error(context); return ptr; }
// 1. user login first // 2. old user not in meeting and online --> send msg to he and replace he // 3. old user not in meeting and offline --> replace he and online // 4. old user in meeting and is not admin and online --> send msg to // he and replace he and send meeting info to new user and online and // into meeting and tell other user // 5. old user in meeting and is admin and online --> same 4 // 6. old user in meeting and is not admin and offline --> 4 (don't // send msg to he) // 7. old user in meeting and is admin and offline --> same 4(dont't // sned msg to he) int Msm::login(string id, string name, int sockfd) { Member *m = new Member(id, name); Meeting *meeting = NULL; if (have_member(id)) { Member *m_old = get_member(id); m->set_volum(m_old->get_volum()); m->set_status(m_old->get_status()); // close old sockfd int old_fd; old_fd = m_old->get_sockfd(); // send msg to old user if (m_old->is_online()) { MsmReqMsg msg(id, "close", "duplicate user"); msg.send_msg(old_fd); } #if 1 if (old_fd != -1 && old_fd != sockfd) { if (epoll_ctl(epollfd, EPOLL_CTL_DEL, old_fd, &ev) == -1) { LOG(LOG_ERROR, "epoll_ctl del %d failed: %s", old_fd, strerror(errno)); return errno; } close(old_fd); m_old->set_sockfd(-1); LOG(LOG_INFO, "close sockfd: %d", old_fd); } #endif // delete old user in meeting meeting = m_old->get_meeting(); if (meeting != NULL) { meeting->del_member(m_old); } // delete struct old user logout(m_old->get_id()); } register_member(m); m->set_sockfd(sockfd); m->set_online(); if (meeting != NULL) { /// TODO: send meeting info to user meeting->add_member(m); } LOG(LOG_DEBUG, "%s login", id.c_str()); return 0; }
void watchlist_store(struct menu_item *item) { struct item_data *data = item->data; settings->n_watches = data->members.size; for (int i = 0; i < data->members.size; ++i) { struct member_data *member_data = get_member(data, i); struct menu_item *watch = menu_userwatch_watch(member_data->userwatch); settings->watch_address[i] = menu_watch_get_address(watch); settings->watch_x[i] = member_data->x; settings->watch_y[i] = member_data->y; settings->watch_info[i].type = menu_watch_get_type(watch); settings->watch_info[i].anchored = member_data->anchored; settings->watch_info[i].position_set = member_data->position_set; } }
/* properly NULL an optional field. */ static void null_field (const ProtobufCMessage* message, const ProtobufCFieldDescriptor* field) { if (field->label == PROTOBUF_C_LABEL_OPTIONAL) { protobuf_c_boolean* has = get_quantifier(message, field); *has = 0; } else if (field->label == PROTOBUF_C_LABEL_REPEATED) { size_t* quantifier = get_quantifier(message, field); *quantifier = 0; } if (field->type == PROTOBUF_C_TYPE_STRING) { const char** member = get_member(message, field); *member = NULL; } }
static void validate_member_expression(pTHX_ const MemberInfo *pmi, const char *member, const char *type) { MemberInfo mi, mi2; const char *failed_type; assert(pmi != NULL); assert(member != NULL); if (pmi->parent == NULL) { Perl_croak(aTHX_ "Cannot use member expression '%s' as Dimension tag" " for '%s' when not within a compound type", member, type); } mi.type.ptr = pmi->parent; mi.type.tflags = ((Struct *) pmi->parent)->tflags; mi.pDecl = NULL; mi.level = 0; (void) get_member(aTHX_ &mi, member, &mi2, CBC_GM_ACCEPT_DOTLESS_MEMBER | CBC_GM_REJECT_OUT_OF_BOUNDS_INDEX | CBC_GM_REJECT_OFFSET); failed_type = check_allowed_types_string(&mi2, ALLOW_BASIC_TYPES); if (failed_type) { Perl_croak(aTHX_ "Cannot use %s in member '%s' to determine a dimension for '%s'", failed_type, member, type); } if (mi2.offset + (int)mi2.size > pmi->offset) { const char *where; if (mi2.offset == pmi->offset) where = "located at same offset as"; else if (mi2.offset < pmi->offset) where = "overlapping with"; else where = "located behind"; Perl_croak(aTHX_ "Cannot use member '%s' %s '%s' in layout" " to determine a dimension", member, where, type); } }