//------------------------------------------------------------------------------------------------- unsigned Configuration::get_all_sessions(vector<const XmlElement *>& target, const Connection::Role role) const { for (vector<const XmlElement *>::const_iterator itr(_allsessions.begin()); itr != _allsessions.end(); ++itr) if (role == Connection::cn_unknown || get_role(*itr) == role) target.push_back(*itr); return target.size(); }
/** * Get statistics regarding a policy's roles. * If this function is given a name, it will attempt to * get statistics about a particular role; otherwise * the function get statistics about all of the policy's roles. * * @param name Reference to an role's name; if NULL, * all roles will be considered * @param policydb Reference to a policy * * @return 0 on success, < 0 on error. */ static PyObject* get_roles(const char *name, const apol_policy_t * policydb) { const qpol_role_t *role_datum = NULL; qpol_iterator_t *iter = NULL; qpol_policy_t *q = apol_policy_get_qpol(policydb); int error = 0; int rt; PyObject *obj; PyObject *list = PyList_New(0); if (!list) goto err; if (name != NULL) { if (qpol_policy_get_role_by_name(q, name, &role_datum)) { errno = EINVAL; goto err; } obj = get_role(role_datum, policydb); rt = py_append_obj(list, obj); Py_DECREF(obj); if (rt) goto err; } else { if (qpol_policy_get_role_iter(q, &iter)) goto err; for (; !qpol_iterator_end(iter); qpol_iterator_next(iter)) { if (qpol_iterator_get_item(iter, (void **)&role_datum)) goto err; obj = get_role(role_datum, policydb); rt = py_append_obj(list, obj); Py_DECREF(obj); if (rt) goto err; } qpol_iterator_destroy(&iter); } goto cleanup; err: error = errno; PyErr_SetString(PyExc_RuntimeError,strerror(errno)); py_decref(list); list = NULL; cleanup: qpol_iterator_destroy(&iter); errno = error; return list; }
static uint8_t *save_role(uint8_t *_p) { uint8_t *p = _p; uint8_t data = (get_role() == SEEDER); write_byte(p, data); ++p; return p; }
static uint8_t *check_role(uint8_t *_p) { uint8_t *p = _p; uint8_t crole = eeprom_read_byte(p); ++p; if(crole != get_role()) error_state(); return p; }
void save_data() { uint8_t *p = START_EEPROM; p = save_id(p); p = save_role(p); p = save_neighs(p); p = save_seeders(p); if(get_role() == SEEDER) p = save_refs(p); uint8_t *cp = START_EEPROM; cp = check_id(cp); cp = check_role(cp); cp = check_neighs(cp); cp = check_seeders(cp); if(get_role() == SEEDER) cp = check_refs(cp); }
void get_role(long childId, IAccessible *pAccessible, char *itemText) { long role ; if (get_role(childId, pAccessible, &role) == S_OK) { int roleTextMax = 255 ; LPTSTR pRoleText = new TCHAR[roleTextMax] ; GetRoleText(role, pRoleText, roleTextMax) ; int lenSzRoleText = 255 ; char *pszRoleText = new char[lenSzRoleText] ; WideCharToMultiByte(CP_ACP, 0, pRoleText, wcslen(pRoleText) + 1, pszRoleText, lenSzRoleText, NULL, NULL) ; sprintf(itemText, "0x%x, %s", role, pszRoleText) ; } }
void TestPeerLogicSyncServer::on_connect () { if (socket ().needs_handshake ()) { if (failure (socket ().handshake (to_handshake_type (get_role ()), error ()))) return; } { boost::asio::streambuf buf (5); std::size_t const amount = boost::asio::read_until ( socket (), buf, "hello", error ()); if (failure (error ())) return; if (unexpected (amount == 5, error ())) return; if (unexpected (buf.size () == 5, error ())) return; } { std::size_t const amount = boost::asio::write ( socket (), boost::asio::buffer ("goodbye", 7), error ()); if (failure (error ())) return; if (unexpected (amount == 7, error ())) return; } if (socket ().needs_handshake ()) { if (failure (socket ().shutdown (error ()), true)) return; } if (failure (socket ().shutdown (Socket::shutdown_both, error ()))) return; if (failure (socket ().close (error ()))) return; }
int on_rtc_alarm_int_transmission() { if(get_role() == CLIENT || get_role() == SERVER || get_role() == FAILED) return 0; if(get_role() == SEARCHING || get_role() == CONNECTING) { message_type_t message; if(get_role() == SEARCHING) message = MES_HELLO; else if (get_role() == CONNECTING) message = MES_ACK; transmit_message(message); } return 0; }
void establish_connection_transmission() { if(get_role() == CLIENT || get_role() == SERVER || get_role() == FAILED) return; if(get_ticks() % 60 == 0) { if(get_role() == SEARCHING || get_role() == CONNECTING) { message_type_t message; if(get_role() == SEARCHING) message = MES_HELLO; else if (get_role() == CONNECTING) message = MES_ACK; transmit_message(message); } else if(get_role() == CONNECTED) {} } }
void walk_tree(IAccessible *pAccessible, char **pColumnHeaderNames, long *pColumnHeadersCount) { HRESULT hr ; long childCount ; hr = pAccessible->get_accChildCount(&childCount) ; if (FAILED(hr) || childCount == 0) return ; VARIANT *pChildVariants = new VARIANT[childCount] ; long childrenFound ; hr = AccessibleChildren(pAccessible, 0, childCount, pChildVariants, &childrenFound) ; if (FAILED(hr)) return ; for (int i=1; i < childrenFound + 1; i++) { VARIANT vChild = pChildVariants[i] ; if (vChild.vt == VT_DISPATCH) { IDispatch *pDispatch = vChild.pdispVal ; IAccessible *pChildAccessible = NULL ; hr = pDispatch->QueryInterface(IID_IAccessible, (void**) &pChildAccessible) ; if (hr == S_OK) { walk_tree(pChildAccessible, pColumnHeaderNames, pColumnHeadersCount) ; pChildAccessible->Release() ; } pDispatch->Release() ; } else { long role ; get_role(i, pAccessible, &role) ; if (role == 0x19) { if (pColumnHeaderNames == NULL) { *pColumnHeadersCount = *pColumnHeadersCount + 1 ; } else { char *headerName = (char *)malloc(sizeof(char) * BUFFER_SIZE) ; get_name(i, pAccessible, headerName) ; pColumnHeaderNames[i - 1] = headerName ; } } } } }
void TestPeerLogicSyncClient::on_connect () { { // pre-handshake hook is optional on_pre_handshake (); if (failure (error ())) return ; } if (socket ().requires_handshake ()) { if (failure (socket ().handshake (to_handshake_type (get_role ()), error ()))) return; } { std::size_t const amount = boost::asio::write ( socket (), boost::asio::buffer ("hello", 5), error ()); if (failure (error ())) return; if (unexpected (amount == 5, error ())) return; } { char data [7]; size_t const amount = boost::asio::read ( socket (), boost::asio::buffer (data, 7), error ()); if (failure (error ())) return; if (unexpected (amount == 7, error ())) return; if (unexpected (memcmp (&data, "goodbye", 7) == 0, error ())) return; } // Wait for 1 byte which should never come. Instead, // the server should close its end and we will get eof { char data [1]; boost::asio::read (socket (), boost::asio::buffer (data, 1), error ()); if (error () == boost::asio::error::eof) { error () = error_code (); } else if (unexpected (failure (error ()), error ())) { return; } } if (socket ().requires_handshake ()) { if (failure (socket ().shutdown (error ()), true)) return; } if (failure (socket ().shutdown (Socket::shutdown_both, error ()))) return; if (failure (socket ().close (error ()))) return; }
void test_wlan_add(int argc, char **argv) { struct wlan_network network; int ret = 0; int arg = 1; struct { unsigned ssid:1; unsigned bssid:1; unsigned channel:1; unsigned address:2; unsigned security:1; unsigned role:1; } info; memset(&info, 0, sizeof(info)); memset(&network, 0, sizeof(struct wlan_network)); if (argc < 4) { dump_wlan_add_usage(); wmprintf("Error: invalid number of arguments\r\n"); return; } if (strlen(argv[arg]) >= WLAN_NETWORK_NAME_MAX_LENGTH) { wmprintf("Error: network name too long\r\n"); return; } memcpy(network.name, argv[arg], strlen(argv[arg])); arg++; info.address = ADDR_TYPE_DHCP; do { if (!info.ssid && string_equal("ssid", argv[arg])) { if (strlen(argv[arg + 1]) > IEEEtypes_SSID_SIZE) { wmprintf("Error: SSID is too long\r\n"); return; } memcpy(network.ssid, argv[arg + 1], strlen(argv[arg + 1])); arg += 2; info.ssid = 1; } else if (!info.bssid && string_equal("bssid", argv[arg])) { ret = get_mac(argv[arg + 1], network.bssid, ':'); if (ret) { wmprintf("Error: invalid BSSID argument" "\r\n"); return; } arg += 2; info.bssid = 1; } else if (!info.channel && string_equal("channel", argv[arg])) { if (arg + 1 >= argc || get_uint(argv[arg + 1], &network.channel, strlen(argv[arg + 1]))) { wmprintf("Error: invalid channel" " argument\n"); return; } arg += 2; info.channel = 1; } else if (!strncmp(argv[arg], "ip:", 3)) { ret = get_address(argv[arg], &network.address); if (ret) { wmprintf("Error: invalid address" " argument\n"); return; } arg++; info.address = ADDR_TYPE_STATIC; } else if (!info.security && string_equal("wep", argv[arg])) { ret = get_security(argc - arg - 1, (char **)(argv + arg + 1), WLAN_SECURITY_WEP_OPEN, &network.security); if (ret) { wmprintf("Error: invalid WEP security" " argument\r\n"); return; } arg += 3; info.security++; } else if (!info.security && string_equal("wpa", argv[arg])) { ret = get_security(argc - arg - 1, argv + arg + 1, WLAN_SECURITY_WPA, &network.security); if (ret) { wmprintf("Error: invalid WPA security" " argument\r\n"); return; } arg += 2; info.security++; } else if (!info.security && string_equal("wpa2", argv[arg])) { ret = get_security(argc - arg - 1, argv + arg + 1, WLAN_SECURITY_WPA2, &network.security); if (ret) { wmprintf("Error: invalid WPA2 security" " argument\r\n"); return; } arg += 2; info.security++; } else if (!info.role && string_equal("role", argv[arg])) { if (arg + 1 >= argc || get_role(argv[arg + 1], &network.role)) { wmprintf("Error: invalid wireless" " network role\r\n"); return; } arg += 2; info.role++; } else if (!strncmp(argv[arg], "autoip", 6)) { info.address = ADDR_TYPE_LLA; arg++; } else { dump_wlan_add_usage(); wmprintf("Error: argument %d is invalid\r\n", arg); return; } } while (arg < argc); if (!info.ssid && !info.bssid) { dump_wlan_add_usage(); wmprintf("Error: specify at least the SSID or BSSID\r\n"); return; } network.address.addr_type = info.address; ret = wlan_add_network(&network); switch (ret) { case WLAN_ERROR_NONE: wmprintf("Added \"%s\"\r\n", network.name); break; case WLAN_ERROR_PARAM: wmprintf("Error: that network already exists\r\n"); break; case WLAN_ERROR_NOMEM: wmprintf("Error: network list is full\r\n"); break; case WLAN_ERROR_STATE: wmprintf("Error: can't add networks in this state\r\n"); break; default: wmprintf("Error: unable to add network for unknown" " reason\r\n"); break; } }
int mp_lobby() { int failure = 0; if((set_com1_irq_set(generic_ser_subscribe_int_tx_rx(COM1))) < 0) {//subscribe interrupts printf("mp_lobby(): generic_ser_subscribe_int_tx_rx() failed \n"); failure = 1; } if(SET_COMMUNICATION_PARAM()) { printf("ser_set() failed\n"); return 1; } initialize_lobby_buttons(); set_role(SEARCHING); lobby_state = NOT_READY; enable_per_second_alarm(on_rtc_alarm_int_transmission); if(im_message_log != NULL) { size_t del_i; for(del_i = 0 ; del_i < size(im_message_log); del_i++) { free(*(char**)at(im_message_log, del_i)); } delete_vector_t(im_message_log); } im_message_log = new_vector_t(sizeof(char*)); memset(current_im, 0, sizeof(char)*IM_MESSAGE_MAX); current_im_index = 0; draw_im_index = 0; int wait = 0; function_to_call = NULL; continue_condition = true; fade_condition = false; darken = FADE_MAX; int ipc_status; message msg; int r; set_program_player2name((char*)malloc(sizeof(char)*MAX_PLAYER_NAME_LENGTH+1)); if(get_program_playername2() == NULL) return 1; memset(get_program_playername2(),0,sizeof(char)*MAX_PLAYER_NAME_LENGTH+1); size_t next_char_index = 0; char last_char = 0; if(!failure){ do{ /* Get a request message. */ if ( (r = driver_receive(ANY, &msg, &ipc_status)) != 0 ) { printf("driver_receive failed with: %d", r); continue; } if (is_ipc_notify(ipc_status)) { /* received notification */ switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: /* hardware interrupt notification */ if (msg.NOTIFY_ARG & get_com1_irq_set()) { /* subscribed interrupt */ if(ser_ih(COM1)) failure = 1; } if (msg.NOTIFY_ARG & get_kbd_irq_set()){ /* subscribed kbd interrupt */ kbd_int_handler(); if(get_scancode() == ESC_BREAK) { lobby_state = NOT_READY; fade_condition = true; transmit_message(MES_BYE); } if(get_role() == SERVER || get_role() == CLIENT) { if(get_scancode() == ENTER_MAKE && current_im_index != 0) { current_im_index = 0; transmit_protocol(current_im, TYPE_STRING, strlen(current_im)+1); char* temp = (char*) calloc(IM_MESSAGE_MAX + 4,1); strcpy(temp, "me: "); strcat(temp,current_im); push_back(im_message_log, &temp); memset(current_im, 0, IM_MESSAGE_MAX); memset(transmission_message,0,IM_MESSAGE_MAX+4); } else { int action; action = process_input(get_scancode(), &last_char); if(action == CHAR_RECEIVED) { if(current_im_index < IM_MESSAGE_MAX -1) { current_im[current_im_index] = last_char; current_im_index++; } } else if(action == BACKSPACE_MAKE) { if(current_im_index > 0) { current_im_index--; current_im[current_im_index] = '\0'; } } } } } if (msg.NOTIFY_ARG & get_rtc_irq_set()) { /* subscribed timer interrupt */ if(rtc_ih()) failure = 1; getDateString(get_date_str_ptr()); } if(msg.NOTIFY_ARG & get_timer_irq_set()){ timer_int_handler(); mp_lobby_render(); //establish_connection_transmission(); } if (msg.NOTIFY_ARG & get_mouse_irq_set()) { /* subscribed timer interrupt */ mouse_int_handler(); } break; default: break; /* no other notifications expected: do nothing */ } } else { } establish_connection_reception(); if(mouse_is_updated()) { assign_mouse(get_previous_mouse(), get_mouse()); assign_mouse(get_mouse(), get_mouse_state()); if(get_role() == SERVER || get_role() == CLIENT) lobby_mouse_event(get_previous_mouse(), get_mouse()); move_cursor(get_cursor(), get_mouse()->coords); } } while(continue_condition); } if(im_message_log != NULL) { size_t del_i; for(del_i = 0 ; del_i < size(im_message_log); del_i++) { free(*(char**)at(im_message_log, del_i)); } delete_vector_t(im_message_log); im_message_log = NULL; } if(generic_ser_unsubscribe_int_tx_rx(COM1)) {//unsubscribe interrupts printf("ser_int_receive(): generic_ser_unsubscribe_int() failed \n"); failure = 1; } disable_per_second_alarm(); continue_condition = true; fade_condition = false; darken = FADE_MAX; return 0; }
int mp_lobby_render() { memcpy(get_program_secondary_buf(),get_background()->color,get_vram_size()); printgr_shade_centered(get_program_secondary_buf(),"Lobby",get_v_res()/2-200, 0.75,0xFFFF,5,5, .1, 8); printgr_shade(get_program_secondary_buf(),get_program_playername(),10, get_v_res()- get_line_space(2), 0.75,0xFFFF,5,5, .1, 2); if(*get_date_str_ptr() != NULL) printgr_shade_centered(get_program_secondary_buf(),*get_date_str_ptr(),0, 0.75,0xFFFF,5,5, .1, 1); if(get_role() == SEARCHING) { if(get_ticks() % 120 < 30) printgr_shade_centered(get_program_secondary_buf(),"Searching",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7); else if(get_ticks() % 120 < 60) printgr_shade_centered(get_program_secondary_buf(),"Searching.",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7); else if(get_ticks() % 120 < 90) printgr_shade_centered(get_program_secondary_buf(),"Searching..",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7); else printgr_shade_centered(get_program_secondary_buf(),"Searching...",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7); } else if(get_role() == FAILED) { printgr_shade_centered(get_program_secondary_buf(),"Connection Failed",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7); printgr_shade_centered(get_program_secondary_buf(),"Player Names must not be the same",get_v_res()/2+100, 0.75,0xFFFF,5,5, .1, 7); } if(get_role() == CLIENT || get_role() == SERVER) { strcpy(opponentmessage, "Opponent: "); strcat(opponentmessage, get_program_playername2()); printgr_shade_centered(get_program_secondary_buf(),opponentmessage,get_v_res()/2 +200, 0.75,0xFFFF,5,5, .1, 5); draw_cursor(get_program_secondary_buf(),get_cursor()); size_t i; if(lobby_state == PLAYER2_READY) { lobby_buttons[0]->text = "Play"; lobby_buttons[0]->trans = 0.9; } else if(lobby_state == PLAYER1_READY) { lobby_buttons[0]->text = "Unready"; lobby_buttons[0]->trans = 0.6; } else if(lobby_state == BOTH_READY) { lobby_buttons[0]->text = "Launching"; lobby_buttons[0]->trans = 0.9; } else { lobby_buttons[0]->text = "Ready"; lobby_buttons[0]->trans = 0.9; } lobby_buttons[0]->width = get_string_width(lobby_buttons[0]->text, lobby_buttons[0]->size); lobby_buttons[0]->pos.x = get_h_res()/2- lobby_buttons[0]->width/2; for(i = 0; i < NUM_LOBBY_BUTTONS; i++) { draw_button_t_centered(lobby_buttons[i]); } for(i = 0; i < size(im_message_log) && i < 20; ++i) { if(**(char**)at(im_message_log,size(im_message_log)-i-1) == 'm') printgr_shade(get_program_secondary_buf(),*(char**)at(im_message_log, size(im_message_log)-i-1),20,get_v_res()-100-(i+1)*20, .75,RGB(0,63,16),5,5, .1, 2); else printgr_shade(get_program_secondary_buf(),*(char**)at(im_message_log, size(im_message_log)-i-1),20,get_v_res()-100-(i+1)*20, .75,0xFFFF,5,5, .1, 2); } printgr_shade(get_program_secondary_buf(),">",10,get_v_res()-100, 0.75,0xFFFF,5,5, .1, 2); printgr_shade(get_program_secondary_buf(),current_im,20,get_v_res()-100, 0.75,0xFFFF,5,5, .1, 2); } if(darken > 0) darken_buf(get_program_secondary_buf(),darken); if(darken > 0 && !fade_condition) { darken-= FADE_RATE; } if(fade_condition) { if(darken <= 127) { darken += FADE_RATE; } else { if(lobby_state == BOTH_READY) { mp_game(); fade_condition = false; lobby_state = NOT_READY; } else continue_condition = false; } } copy_video_buffer(get_program_video_mem(), get_program_secondary_buf()); return 0; }
void establish_connection_reception() { if(get_role() == SEARCHING || get_role() == CONNECTING) { message_type_t received = 0; signal_type_t received_signal_type; size_t received_size = 0; if(receive_protocol(&received,&received_signal_type, &received_size) == 0) { if(received == MES_HELLO && get_role()== SEARCHING) { transmit_message(MES_ACK); set_role(CONNECTING); } else if(received == MES_ACK && (get_role() == CONNECTING||get_role() == SEARCHING)) { transmit_message(MES_ACK); set_role(CONNECTED); transmit_protocol(get_program_playername(), TYPE_STRING, strlen(get_program_playername())); transmit_protocol(get_programinitialtime_ptr(), TYPE_INT, sizeof(int)); } } } else if(get_role() == CONNECTED) { message_type_t received = 0; signal_type_t received_signal_type; size_t received_size = 0; if(receive_protocol(get_program_playername2(),&received_signal_type, &received_size) == 0) { if(received_signal_type == TYPE_STRING) { strcat(opponentmessage, get_program_playername2()); if(strcmp(get_program_playername(), get_program_playername2()) == 0) set_role(FAILED); else if(strcmp(get_program_playername(), get_program_playername2()) < 0) { set_role(SERVER); } else set_role(CLIENT); } } } else { char received[100]; memset(received, 0, 100); signal_type_t received_signal_type; size_t received_size = 0; if(receive_protocol(received,&received_signal_type, &received_size) == 0) { if(*(unsigned long*)received == MES_BYE) { set_role(SEARCHING); memset(get_program_playername2(),0,sizeof(char)*MAX_PLAYER_NAME_LENGTH+1); if(im_message_log != NULL) { size_t del_i; for(del_i = 0 ; del_i < size(im_message_log); del_i++) { free(*(char**)at(im_message_log, del_i)); } clear(im_message_log); } } else if(received_signal_type == TYPE_INT) { set_player2time( *(unsigned long*)received); if(get_role() == SERVER) srand(*get_programinitialtime_ptr()); else srand(get_player2time()); } else if(*(unsigned long*)received == MES_READY) { if(lobby_state == NOT_READY) lobby_state = PLAYER2_READY; else if(lobby_state == PLAYER1_READY) { lobby_state = BOTH_READY; fade_condition = true; } } else if(*(unsigned long*)received == MES_UNREADY) { if(lobby_state == PLAYER2_READY) { lobby_state = NOT_READY; } else if(lobby_state == BOTH_READY) { lobby_state = PLAYER1_READY; fade_condition = false; } } else if(received_signal_type == TYPE_STRING) { char* temp = (char*) calloc(IM_MESSAGE_MAX + 5,1); strcpy(temp, "you: "); strcat(temp,received); push_back(im_message_log, &temp); } } } }